]> Dogcows Code - chaz/tint2/blobdiff - src/panel.c
fixed segfault
[chaz/tint2] / src / panel.c
index e202f816950ac80dbdbb9601ce5f7910596cf4d2..0a43d7f833d6f8cbb2acbe7b9002616923e3f028 100644 (file)
@@ -38,15 +38,20 @@ int mouse_middle;
 int mouse_right;
 int mouse_scroll_up;
 int mouse_scroll_down;
+int mouse_tilt_left;
+int mouse_tilt_right;
 
 int panel_mode;
 int wm_menu;
 int panel_position;
+int panel_horizontal;
 int panel_refresh;
 
 Task *task_active;
 Task *task_drag;
 Task *task_urgent;
+int  tick_urgent;
+int  max_tick_urgent;
 
 Panel *panel1 = 0;
 int  nb_panel;
@@ -73,29 +78,45 @@ void init_panel()
                // add childs
           if (p->clock.area.on_screen)
                        p->area.list = g_slist_append(p->area.list, &p->clock);
+#ifdef ENABLE_BATTERY
                if (p->battery.area.on_screen)
                        p->area.list = g_slist_append(p->area.list, &p->battery);
-          if (systray.area.on_screen && i == 0) {
-               // systray only on first panel
+#endif
+       // systray only on first panel
+          if (systray.area.on_screen && i == 0)
                        p->area.list = g_slist_append(p->area.list, &systray);
-               }
-
-               // detect panel size
-               if (p->pourcentx)
-                       p->area.width = (float)server.monitor[p->monitor].width * p->initial_width / 100;
-               else
-                       p->area.width = p->initial_width;
-               if (p->pourcenty)
-                       p->area.height = (float)server.monitor[p->monitor].height * p->initial_height / 100;
-               else
-                       p->area.height = p->initial_height;
 
                // full width mode
-               if (!p->area.width)
-                       p->area.width = server.monitor[p->monitor].width;
+               if (!p->initial_width) {
+                       p->initial_width = 100;
+                       p->pourcentx = 1;
+               }
 
-               if (p->area.pix.border.rounded > p->area.height/2)
-                       p->area.pix.border.rounded = p->area.height/2;
+               // detect panel size
+               if (panel_horizontal) {
+                       if (p->pourcentx)
+                               p->area.width = (float)server.monitor[p->monitor].width * p->initial_width / 100;
+                       else
+                               p->area.width = p->initial_width;
+                       if (p->pourcenty)
+                               p->area.height = (float)server.monitor[p->monitor].height * p->initial_height / 100;
+                       else
+                               p->area.height = p->initial_height;
+                       if (p->area.pix.border.rounded > p->area.height/2)
+                               p->area.pix.border.rounded = p->area.height/2;
+               }
+               else {
+                       if (p->pourcentx)
+                               p->area.height = (float)server.monitor[p->monitor].height * p->initial_width / 100;
+                       else
+                               p->area.height = p->initial_width;
+                       if (p->pourcenty)
+                               p->area.width = (float)server.monitor[p->monitor].width * p->initial_height / 100;
+                       else
+                               p->area.width = p->initial_height;
+                       if (p->area.pix.border.rounded > p->area.width/2)
+                               p->area.pix.border.rounded = p->area.width/2;
+               }
 
                /* panel position determined here */
                if (panel_position & LEFT) {
@@ -106,23 +127,28 @@ void init_panel()
                                p->posx = server.monitor[p->monitor].x + server.monitor[p->monitor].width - p->area.width - p->marginx;
                        }
                        else {
-                               p->posx = server.monitor[p->monitor].x + ((server.monitor[p->monitor].width - p->area.width) / 2);
+                               if (panel_horizontal)
+                                       p->posx = server.monitor[p->monitor].x + ((server.monitor[p->monitor].width - p->area.width) / 2);
+                               else
+                                       p->posx = server.monitor[p->monitor].x + p->marginx;
                        }
                }
                if (panel_position & TOP) {
                        p->posy = server.monitor[p->monitor].y + p->marginy;
                }
                else {
-                       p->posy = server.monitor[p->monitor].y + server.monitor[p->monitor].height - p->area.height - p->marginy;
+                       if (panel_position & BOTTOM) {
+                               p->posy = server.monitor[p->monitor].y + server.monitor[p->monitor].height - p->area.height - p->marginy;
+                       }
+                       else {
+                               p->posy = server.monitor[p->monitor].y + ((server.monitor[p->monitor].height - p->area.height) / 2);
+                       }
                }
+               // printf("panel : posx %d, posy %d, width %d, height %d\n", p->posx, p->posy, p->area.width, p->area.height);
 
                // Catch some events
                XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, ExposureMask|ButtonPressMask|ButtonReleaseMask, NoEventMask, False, 0, 0 };
-
-               // XCreateWindow(display, parent, x, y, w, h, border, depth, class, visual, mask, attrib)
-               // main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
                if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
-               //win = XCreateWindow (server.dsp, server.root_win, p->posx+p->area.paddingxlr, p->posy, p->area.width-(2*p->area.paddingxlr), p->area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att);
                p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att);
 
                set_panel_properties(p);
@@ -177,43 +203,78 @@ void cleanup_panel()
 void resize_panel(void *obj)
 {
    Panel *panel = (Panel*)obj;
-   int taskbar_width, modulo_width, taskbar_on_screen;
-
-   taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width);
-   if (panel->clock.area.on_screen && panel->clock.area.width)
-      taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
-       if (panel->battery.area.on_screen && panel->battery.area.width)
-               taskbar_width -= (panel->battery.area.width + panel->area.paddingx);
-   // TODO : systray only on first panel. search better implementation !
-   if (systray.area.on_screen && systray.area.width && panel == &panel1[0])
-       taskbar_width -= (systray.area.width + panel->area.paddingx);
-
-   if (panel_mode == MULTI_DESKTOP) {
-               taskbar_on_screen = panel->nb_desktop;
-               int width = taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx);
-          taskbar_width = width / taskbar_on_screen;
-      modulo_width = width % taskbar_on_screen;
-       }
-   else {
-               taskbar_on_screen = 1;
-      modulo_width = 0;
+
+       if (panel_horizontal) {
+          int taskbar_width, modulo_width = 0;
+
+               taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width);
+               if (panel->clock.area.on_screen && panel->clock.area.width)
+                       taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
+       #ifdef ENABLE_BATTERY
+               if (panel->battery.area.on_screen && panel->battery.area.width)
+                       taskbar_width -= (panel->battery.area.width + panel->area.paddingx);
+       #endif
+               // TODO : systray only on first panel. search better implementation !
+               if (systray.area.on_screen && systray.area.width && panel == &panel1[0])
+                       taskbar_width -= (systray.area.width + panel->area.paddingx);
+
+               if (panel_mode == MULTI_DESKTOP) {
+                       int width = taskbar_width - ((panel->nb_desktop-1) * panel->area.paddingx);
+                       taskbar_width = width / panel->nb_desktop;
+                       modulo_width = width % panel->nb_desktop;
+               }
+
+               // change posx and width for all taskbar
+               int i, posx;
+               posx = panel->area.pix.border.width + panel->area.paddingxlr;
+               for (i=0 ; i < panel->nb_desktop ; i++) {
+                       panel->taskbar[i].area.posx = posx;
+                       panel->taskbar[i].area.width = taskbar_width;
+                       panel->taskbar[i].area.resize = 1;
+                       if (modulo_width) {
+                               panel->taskbar[i].area.width++;
+                               modulo_width--;
+                       }
+                       //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
+                       if (panel_mode == MULTI_DESKTOP)
+                               posx += panel->taskbar[i].area.width + panel->area.paddingx;
+               }
        }
+       else {
+          int taskbar_height, modulo_height = 0;
+               int i, posy;
+
+               taskbar_height = panel->area.height - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width);
+               if (panel->clock.area.on_screen && panel->clock.area.height)
+                       taskbar_height -= (panel->clock.area.height + panel->area.paddingx);
+       #ifdef ENABLE_BATTERY
+               if (panel->battery.area.on_screen && panel->battery.area.height)
+                       taskbar_height -= (panel->battery.area.height + panel->area.paddingx);
+       #endif
+               // TODO : systray only on first panel. search better implementation !
+               if (systray.area.on_screen && systray.area.height && panel == &panel1[0])
+                       taskbar_height -= (systray.area.height + panel->area.paddingx);
+
+               posy = panel->area.height - panel->area.pix.border.width - panel->area.paddingxlr - taskbar_height;
+               if (panel_mode == MULTI_DESKTOP) {
+                       int height = taskbar_height - ((panel->nb_desktop-1) * panel->area.paddingx);
+                       taskbar_height = height / panel->nb_desktop;
+                       modulo_height = height % panel->nb_desktop;
+               }
 
-       // change posx and width for all taskbar
-   int i, posx;
-       posx = panel->area.pix.border.width + panel->area.paddingxlr;
-   for (i=0 ; i < panel->nb_desktop ; i++) {
-      panel->taskbar[i].area.posx = posx;
-      panel->taskbar[i].area.width = taskbar_width;
-      panel->taskbar[i].area.resize = 1;
-      if (modulo_width) {
-         panel->taskbar[i].area.width++;
-         modulo_width--;
-      }
-               //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
-      if (panel_mode == MULTI_DESKTOP)
-       posx += panel->taskbar[i].area.width + panel->area.paddingx;
-   }
+               // change posy and height for all taskbar
+               for (i=0 ; i < panel->nb_desktop ; i++) {
+                       panel->taskbar[i].area.posy = posy;
+                       panel->taskbar[i].area.height = taskbar_height;
+                       panel->taskbar[i].area.resize = 1;
+                       if (modulo_height) {
+                               panel->taskbar[i].area.height++;
+                               modulo_height--;
+                       }
+                       if (panel_mode == MULTI_DESKTOP)
+                               posy += panel->taskbar[i].area.height + panel->area.paddingx;
+               }
+       }
 }
 
 
@@ -229,7 +290,7 @@ void visible_object()
                for (j=0 ; j < panel->nb_desktop ; j++) {
                        taskbar = &panel->taskbar[j];
                        if (panel_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) {
-                               // (SINGLE_DESKTOP or SINGLE_MONITOR) and not current desktop
+                               // SINGLE_DESKTOP and not current desktop
                                taskbar->area.on_screen = 0;
                        }
                        else {
@@ -254,29 +315,45 @@ void set_panel_properties(Panel *p)
    }
 
    // Dock
-   //long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
-   //XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
+   long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
+   XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
 
    // Reserved space
    long   struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-   if (panel_position & TOP) {
-      struts[2] = p->area.height + p->marginy;
-      struts[8] = p->posx;
-      // p->area.width - 1 allowed full screen on monitor 2
-      struts[9] = p->posx + p->area.width - 1;
-   }
-   else {
-      struts[3] = p->area.height + p->marginy;
-      struts[10] = p->posx;
-      // p->area.width - 1 allowed full screen on monitor 2
-      struts[11] = p->posx + p->area.width - 1;
-   }
+       if (panel_horizontal) {
+               if (panel_position & TOP) {
+                       struts[2] = p->area.height + p->marginy;
+                       struts[8] = p->posx;
+                       // p->area.width - 1 allowed full screen on monitor 2
+                       struts[9] = p->posx + p->area.width - 1;
+               }
+               else {
+                       struts[3] = p->area.height + p->marginy;
+                       struts[10] = p->posx;
+                       // p->area.width - 1 allowed full screen on monitor 2
+                       struts[11] = p->posx + p->area.width - 1;
+               }
+       }
+       else {
+               if (panel_position & LEFT) {
+                       struts[0] = p->area.width + p->marginx;
+                       struts[4] = p->posy;
+                       // p->area.width - 1 allowed full screen on monitor 2
+                       struts[5] = p->posy + p->area.height - 1;
+               }
+               else {
+                       struts[1] = p->area.width + p->marginx;
+                       struts[6] = p->posy;
+                       // p->area.width - 1 allowed full screen on monitor 2
+                       struts[7] = p->posy + p->area.height - 1;
+               }
+       }
    // Old specification : fluxbox need _NET_WM_STRUT.
    XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4);
    XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);
 
    // Sticky and below other window
-   long val = 0xFFFFFFFF;
+   val = 0xFFFFFFFF;
    XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
    Atom state[4];
    state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
This page took 0.027051 seconds and 4 git commands to generate.