X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fpanel.c;h=9754de79ee22b9585ed9eff799c2f8e21dec2b29;hb=928fc258ac46f2cc098f714921c028351b07ec31;hp=662c6c5d1f5406e85ce4fafaf5d1efe7e9dc263a;hpb=f3e92f7e3626e3992efff2b55a08a938af38efff;p=chaz%2Ftint2 diff --git a/src/panel.c b/src/panel.c index 662c6c5..9754de7 100644 --- a/src/panel.c +++ b/src/panel.c @@ -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 = strdup("LTBSC"); // Default order : Launcher, Taskbar, Battery, Systray, Clock panel_autohide = 0; panel_autohide_show_timeout = 0; panel_autohide_hide_timeout = 0; @@ -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); @@ -139,6 +142,7 @@ void init_panel() #ifdef ENABLE_BATTERY init_battery(); #endif + init_taskbar(); // number of panels (one monitor or 'all' monitors) if (panel_config.monitor >= 0) @@ -163,32 +167,14 @@ void init_panel() p->area.panel = p; p->area.on_screen = 1; p->area.resize = 1; + p->area.size_mode = SIZE_BY_LAYOUT; p->area._resize = resize_panel; 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); - } -#ifdef ENABLE_BATTERY - if (battery_enabled) { - init_battery_panel(p); - p->area.list = g_slist_append(p->area.list, &p->battery); - } -#endif - if (launcher_enabled) { - init_launcher_panel(p); - p->area.list = g_slist_append(p->area.list, &p->launcher); - } - // 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; - } + // add childs according to panel_items + set_panel_items(p); // catch some events XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 }; @@ -219,7 +205,6 @@ void init_panel() } panel_refresh = 1; - init_taskbar(); visible_object(); task_refresh_tasklist(); active_task(); @@ -300,31 +285,36 @@ void init_panel_size_and_position(Panel *panel) } -void resize_panel(void *obj) +int 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); - if (panel->launcher.area.on_screen && panel->launcher.area.width) - taskbar_width -= (panel->launcher.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; + int size, nb_by_content=0, nb_by_layout=0; + Area *a = (Area*)obj; + int paddingx = a->paddingx;; + + if (panel_horizontal) { + // detect free size for SIZE_BY_LAYOUT's Area + size = a->width - (2 * a->paddingxlr) - (2 * a->bg->border.width); + GSList *l; + for (l = ((Area*)obj)->list ; l ; l = l->next) { + a = (Area*)l->data; + if (a->on_screen && a->width && a->size_mode == SIZE_BY_CONTENT) { + size -= a->width; + nb_by_content++; + } + if (a->on_screen && a->size_mode == SIZE_BY_LAYOUT) + nb_by_layout++; + } + if (nb_by_content+nb_by_layout) + size -= ((nb_by_content+nb_by_layout-1) * paddingx); + //printf("resize_panel : size_panel %d, size_layout %d\n", panel->area.width, size); + + int width=0, modulo=0; + if (nb_by_layout) { + width = size / nb_by_layout; + modulo = size % nb_by_layout; } + //printf(" content %d, layout %d, width %d, modulo %d\n", nb_by_content, nb_by_layout, width, modulo); // change posx and width for all taskbar int i, posx; @@ -333,56 +323,55 @@ void resize_panel(void *obj) posx += (panel->launcher.area.width + panel->area.paddingx); 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.width = width; panel->taskbar[i].area.resize = 1; - if (modulo_width) { + if (modulo) { panel->taskbar[i].area.width++; - modulo_width--; + modulo--; } + //printf(" width %d\n", panel->taskbar[i].area.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; + // detect free size for SIZE_BY_LAYOUT's Area + size = a->height - (2 * a->paddingxlr) - (2 * a->bg->border.width); + GSList *l; + for (l = ((Area*)obj)->list ; l ; l = l->next) { + a = (Area*)l->data; + if (a->on_screen && a->height && a->size_mode == SIZE_BY_CONTENT) { + size -= a->height; + nb_by_content++; + } + if (a->on_screen && a->size_mode == SIZE_BY_LAYOUT) + nb_by_layout++; + } + if (nb_by_content+nb_by_layout) + size -= ((nb_by_content+nb_by_layout-1) * paddingx); - 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); - if (panel->launcher.area.on_screen && panel->launcher.area.height) - taskbar_height -= (panel->launcher.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->launcher.area.on_screen && panel->launcher.area.height) - posy -= (panel->launcher.area.height + panel->area.paddingx); - 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; + int width=0, modulo=0; + if (nb_by_layout) { + width = size / nb_by_layout; + modulo = size % nb_by_layout; } // change posy and height for all taskbar + int i, posy; 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.height = width; panel->taskbar[i].area.resize = 1; - if (modulo_height) { + if (modulo) { panel->taskbar[i].area.height++; - modulo_height--; + modulo--; } if (panel_mode == MULTI_DESKTOP) posy += panel->taskbar[i].area.height + panel->area.paddingx; } } + return 0; } @@ -464,6 +453,45 @@ void update_strut(Panel* p) } +void set_panel_items(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') { + init_launcher_panel(p); + p->area.list = g_slist_append(p->area.list, &p->launcher); + } + if (panel_items_order[k] == 'T') { + init_taskbar_panel(p); + 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') { + init_battery_panel(p); + 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 + init_systray_panel(p); + refresh_systray = 1; + p->area.list = g_slist_append(p->area.list, &systray); + } + if (panel_items_order[k] == 'C') { + init_clock_panel(p); + p->area.list = g_slist_append(p->area.list, &p->clock); + } + } +} + + void set_panel_properties(Panel *p) { XStoreName (server.dsp, p->main_win, "tint2"); @@ -508,7 +536,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 - long 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); @@ -578,12 +606,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; @@ -686,8 +716,8 @@ LauncherIcon *click_launcher_icon (Panel *panel, int x, int 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->width) && - y >= (launcher->area.posy + icon->y) && y <= (launcher->area.posy + icon->y + icon->height)) { + 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; }