]> Dogcows Code - chaz/tint2/blobdiff - src/panel.c
cleanup code
[chaz/tint2] / src / panel.c
index c8c945eea244d03a3f7d31a7a8a5b13222594512..6a98a26191aaf43ad2efc13daa1b5f3d4b8c019a 100644 (file)
@@ -58,6 +58,7 @@ int panel_autohide_show_timeout;
 int panel_autohide_hide_timeout;
 int panel_autohide_height;
 int panel_strut_policy;
+char *panel_items_order;
 
 int  max_tick_urgent;
 
@@ -79,6 +80,7 @@ void default_panel()
        task_dragged = 0;
        panel_horizontal = 1;
        panel_position = CENTER;
+       panel_items_order = 0;
        panel_autohide = 0;
        panel_autohide_show_timeout = 0;
        panel_autohide_hide_timeout = 0;
@@ -87,7 +89,7 @@ void default_panel()
        panel_dock = 0;  // default not in the dock
        panel_layer = BOTTOM_LAYER;  // default is bottom layer
        wm_menu = 0;
-       max_tick_urgent = 7;
+       max_tick_urgent = 14;
        backgrounds = g_array_new(0, 0, sizeof(Background));
 
        memset(&panel_config, 0, sizeof(Panel));
@@ -115,6 +117,7 @@ void cleanup_panel()
                if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
        }
 
+       if (panel_items_order) g_free(panel_items_order);
        if (panel1) free(panel1);
        if (backgrounds)
                g_array_free(backgrounds, 1);
@@ -123,7 +126,7 @@ void cleanup_panel()
 
 void init_panel()
 {
-       int i;
+       int i, k;
        Panel *p;
 
        if (panel_config.monitor > (server.nb_monitor-1)) {
@@ -134,10 +137,12 @@ void init_panel()
 
        init_tooltip();
        init_systray();
+       init_launcher();
        init_clock();
 #ifdef ENABLE_BATTERY
        init_battery();
 #endif
+       init_taskbar();
 
        // number of panels (one monitor or 'all' monitors)
        if (panel_config.monitor >= 0)
@@ -156,32 +161,37 @@ void init_panel()
 
                if (panel_config.monitor < 0)
                        p->monitor = i;
+               if ( p->area.bg == 0 )
+                       p->area.bg = &g_array_index(backgrounds, Background, 0);
                p->area.parent = p;
                p->area.panel = p;
                p->area.on_screen = 1;
                p->area.resize = 1;
-               p->area._resize = resize_panel;
+               p->area.size_mode = SIZE_BY_LAYOUT;
+               p->area._resize = resize_by_layout;
                p->g_taskbar.area.parent = p;
                p->g_taskbar.area.panel = p;
                p->g_task.area.panel = p;
                init_panel_size_and_position(p);
-               // add childs
-               if (clock_enabled) {
-                       init_clock_panel(p);
-                       p->area.list = g_slist_append(p->area.list, &p->clock);
-               }
+               // add childs according to panel_items
+               for (k=0 ; k < strlen(panel_items_order) ; k++) {
+                       if (panel_items_order[k] == 'L') 
+                               init_launcher_panel(p);
+                       if (panel_items_order[k] == 'T')
+                               init_taskbar_panel(p);
 #ifdef ENABLE_BATTERY
-               if (battery_enabled) {
-                       init_battery_panel(p);
-                       p->area.list = g_slist_append(p->area.list, &p->battery);
-               }
+                       if (panel_items_order[k] == 'B')
+                               init_battery_panel(p);
 #endif
-               // systray only on first panel
-               if (systray.area.on_screen && i == 0) {
-                       init_systray_panel(p);
-                       p->area.list = g_slist_append(p->area.list, &systray);
-                       refresh_systray = 1;
+                       if (panel_items_order[k] == 'S') {
+                               // TODO : check systray is only on 1 panel
+                               init_systray_panel(p);
+                               refresh_systray = 1;
+                       }
+                       if (panel_items_order[k] == 'C')
+                               init_clock_panel(p);
                }
+               set_panel_items_order(p);
 
                // catch some events
                XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 };
@@ -209,11 +219,10 @@ void init_panel()
 
                if (panel_autohide)
                        add_timeout(panel_autohide_hide_timeout, 0, autohide_hide, p);
+               
+               visible_taskbar(p);
        }
 
-       panel_refresh = 1;
-       init_taskbar();
-       visible_object();
        task_refresh_tasklist();
        active_task();
 }
@@ -293,107 +302,6 @@ void init_panel_size_and_position(Panel *panel)
 }
 
 
-void resize_panel(void *obj)
-{
-       Panel *panel = (Panel*)obj;
-
-       if (panel_horizontal) {
-               int taskbar_width, modulo_width = 0;
-
-               taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.bg->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.bg->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.bg->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.bg->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 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;
-               }
-       }
-}
-
-
-void visible_object()
-{
-       Panel *panel;
-       int i, j;
-
-       for (i=0 ; i < nb_panel ; i++) {
-               panel = &panel1[i];
-
-               Taskbar *taskbar;
-               for (j=0 ; j < panel->nb_desktop ; j++) {
-                       taskbar = &panel->taskbar[j];
-                       if (panel_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) {
-                               // SINGLE_DESKTOP and not current desktop
-                               taskbar->area.on_screen = 0;
-                       }
-                       else {
-                               taskbar->area.on_screen = 1;
-                       }
-               }
-       }
-       panel_refresh = 1;
-}
-
 void update_strut(Panel* p)
 {
        if (panel_strut_policy == STRUT_NONE) {
@@ -449,6 +357,37 @@ void update_strut(Panel* p)
 }
 
 
+void set_panel_items_order(Panel *p)
+{
+       int k, j;
+       
+       if (p->area.list) {
+               g_slist_free(p->area.list);
+               p->area.list = 0;
+       }
+
+       for (k=0 ; k < strlen(panel_items_order) ; k++) {
+               if (panel_items_order[k] == 'L') 
+                       p->area.list = g_slist_append(p->area.list, &p->launcher);
+               if (panel_items_order[k] == 'T') {
+                       for (j=0 ; j < p->nb_desktop ; j++)
+                               p->area.list = g_slist_append(p->area.list, &p->taskbar[j]);
+               }
+#ifdef ENABLE_BATTERY
+               if (panel_items_order[k] == 'B') 
+                       p->area.list = g_slist_append(p->area.list, &p->battery);
+#endif
+               if (panel_items_order[k] == 'S') {
+                       // TODO : check systray is only on 1 panel
+                       p->area.list = g_slist_append(p->area.list, &systray);
+               }
+               if (panel_items_order[k] == 'C')
+                       p->area.list = g_slist_append(p->area.list, &p->clock);
+       }
+       init_rendering(&p->area, 0);
+}
+
+
 void set_panel_properties(Panel *p)
 {
        XStoreName (server.dsp, p->main_win, "tint2");
@@ -493,7 +432,7 @@ void set_panel_properties(Panel *p)
        XChangeProperty(server.dsp, p->main_win, server.atom._MOTIF_WM_HINTS, server.atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) prop, 5);
 
        // XdndAware - Register for Xdnd events
-       int version=5;
+       Atom version=4;
        XChangeProperty(server.dsp, p->main_win, server.atom.XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1);
 
        update_strut(p);
@@ -563,12 +502,14 @@ void set_panel_background(Panel *p)
        }
 
        // redraw panel's object
+       //p->area.redraw = 1;
        GSList *l0;
        Area *a;
        for (l0 = p->area.list; l0 ; l0 = l0->next) {
                a = l0->data;
                set_redraw(a);
        }
+       
        // reset task 'state_pix'
        int i;
        Taskbar *tskbar;
@@ -645,6 +586,43 @@ Task *click_task (Panel *panel, int x, int y)
 }
 
 
+Launcher *click_launcher (Panel *panel, int x, int y)
+{
+       Launcher *launcher = &panel->launcher;
+       
+       if (panel_horizontal) {
+               if (launcher->area.on_screen && x >= launcher->area.posx && x <= (launcher->area.posx + launcher->area.width))
+                       return launcher;
+       }
+       else {
+               if (launcher->area.on_screen && y >= launcher->area.posy && y <= (launcher->area.posy + launcher->area.height))
+                       return launcher;
+       }
+       return NULL;
+}
+
+
+LauncherIcon *click_launcher_icon (Panel *panel, int x, int y)
+{
+       GSList *l0;
+       Launcher *launcher;
+
+       //printf("Click x=%d y=%d\n", x, y);
+       if ( (launcher = click_launcher(panel, x, y)) ) {
+               LauncherIcon *icon;
+               for (l0 = launcher->list_icons; l0 ; l0 = l0->next) {
+                       icon = l0->data;
+                       if (x >= (launcher->area.posx + icon->x) && x <= (launcher->area.posx + icon->x + icon->icon_size) &&
+                               y >= (launcher->area.posy + icon->y) && y <= (launcher->area.posy + icon->y + icon->icon_size)) {
+                               //printf("Hit rect x=%d y=%d xmax=%d ymax=%d\n", launcher->area.posx + icon->x, launcher->area.posy + icon->y, launcher->area.posx + icon->x + icon->width, launcher->area.posy + icon->y + icon->height);
+                               return icon;
+                       }
+               }
+       }
+       return NULL;
+}
+
+
 int click_padding(Panel *panel, int x, int y)
 {
        if (panel_horizontal) {
This page took 0.027886 seconds and 4 git commands to generate.