X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fpanel.c;h=8bb9f14a61292ce7e8159b14bd9572e727a6cf2e;hb=e8ee3c40c5d9f7f66a033e8492c34e282002e51d;hp=2e1c2283928f2dd69c4a7566cc0da531cdd27162;hpb=d1123a0ede12eb1126eb5eb932d9177de67d46c5;p=chaz%2Ftint2 diff --git a/src/panel.c b/src/panel.c index 2e1c228..8bb9f14 100644 --- a/src/panel.c +++ b/src/panel.c @@ -16,6 +16,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **************************************************************************/ +#include +#include +#include #include #include #include @@ -27,223 +30,611 @@ #include "window.h" #include "task.h" #include "panel.h" +#include "tooltip.h" -void visual_refresh () +int signal_pending; +// -------------------------------------------------- +// mouse events +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_dock=0; // default not in the dock +int panel_layer=BOTTOM_LAYER; // default is bottom layer +int panel_position; +int panel_horizontal; +int panel_refresh; + +Task *task_active; +Task *task_drag; +int max_tick_urgent; + +// panel's initial config +Panel panel_config; +// panels (one panel per monitor) +Panel *panel1 = 0; +int nb_panel = 0; + +Imlib_Image default_icon = NULL; + + + +void init_panel() +{ + int i, old_nb_panel; + Panel *new_panel, *p; + + init_tooltip(); + init_systray(); + init_clock(); +#ifdef ENABLE_BATTERY + init_battery(); +#endif + + cleanup_taskbar(); + for (i=0 ; i < nb_panel ; i++) { + free_area(&panel1[i].area); + if (panel1[i].temp_pmap) { + XFreePixmap(server.dsp, panel1[i].temp_pmap); + panel1[i].temp_pmap = 0; + } + } + + // number of panels + old_nb_panel = nb_panel; + if (panel_config.monitor >= 0) + nb_panel = 1; + else + nb_panel = server.nb_monitor; + + // freed old panels + for (i=nb_panel ; i < old_nb_panel ; i++) { + if (panel1[i].main_win) { + XDestroyWindow(server.dsp, panel1[i].main_win); + panel1[i].main_win = 0; + } + } + + // alloc & init new panel + Window old_win; + if (nb_panel != old_nb_panel) + new_panel = realloc(panel1, nb_panel * sizeof(Panel)); + else + new_panel = panel1; + for (i=0 ; i < nb_panel ; i++) { + old_win = new_panel[i].main_win; + memcpy(&new_panel[i], &panel_config, sizeof(Panel)); + new_panel[i].main_win = old_win; + } + + fprintf(stderr, "tint2 : nb monitor %d, nb monitor used %d, nb desktop %d\n", server.nb_monitor, nb_panel, server.nb_desktop); + for (i=0 ; i < nb_panel ; i++) { + p = &new_panel[i]; + + if (panel_config.monitor < 0) + p->monitor = i; + p->area.parent = p; + p->area.panel = p; + p->area.on_screen = 1; + p->area.resize = 1; + p->area._resize = resize_panel; + p->g_taskbar.parent = p; + p->g_taskbar.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 + // 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 (i >= old_nb_panel) { + // new panel : catch some events + long event_mask = ExposureMask|ButtonPressMask|ButtonReleaseMask; + if (g_tooltip.enabled) + event_mask |= PointerMotionMask|LeaveWindowMask; + XSetWindowAttributes att = { .event_mask=event_mask, .colormap=server.colormap, .background_pixel=0, .border_pixel=0 }; + unsigned long mask = CWEventMask|CWColormap|CWBackPixel|CWBorderPixel; + p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, server.visual, mask, &att); + } + else { + // old panel + XMoveResizeWindow(server.dsp, p->main_win, p->posx, p->posy, p->area.width, p->area.height); + } + + if (!server.gc) { + XGCValues gcv; + server.gc = XCreateGC(server.dsp, p->main_win, 0, &gcv); + } + //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height); + set_panel_properties(p); + set_panel_background(p); + if (i >= old_nb_panel) { + // map new panel + XMapWindow (server.dsp, p->main_win); + } + } + + panel1 = new_panel; + panel_refresh = 1; + init_taskbar(); + visible_object(); + task_refresh_tasklist(); + active_task(); +} + + +void init_panel_size_and_position(Panel *panel) +{ + // detect panel size + if (panel_horizontal) { + if (panel->pourcentx) + panel->area.width = (float)server.monitor[panel->monitor].width * panel->area.width / 100; + if (panel->pourcenty) + panel->area.height = (float)server.monitor[panel->monitor].height * panel->area.height / 100; + if (panel->area.pix.border.rounded > panel->area.height/2) + panel->area.pix.border.rounded = panel->area.height/2; + } + else { + int old_panel_height = panel->area.height; + if (panel->pourcentx) + panel->area.height = (float)server.monitor[panel->monitor].height * panel->area.width / 100; + else + panel->area.height = panel->area.width; + if (panel->pourcenty) + panel->area.width = (float)server.monitor[panel->monitor].width * old_panel_height / 100; + else + panel->area.width = old_panel_height; + if (panel->area.pix.border.rounded > panel->area.width/2) + panel->area.pix.border.rounded = panel->area.width/2; + } + + // panel position determined here + if (panel_position & LEFT) { + panel->posx = server.monitor[panel->monitor].x + panel->marginx; + } + else { + if (panel_position & RIGHT) { + panel->posx = server.monitor[panel->monitor].x + server.monitor[panel->monitor].width - panel->area.width - panel->marginx; + } + else { + if (panel_horizontal) + panel->posx = server.monitor[panel->monitor].x + ((server.monitor[panel->monitor].width - panel->area.width) / 2); + else + panel->posx = server.monitor[panel->monitor].x + panel->marginx; + } + } + if (panel_position & TOP) { + panel->posy = server.monitor[panel->monitor].y + panel->marginy; + } + else { + if (panel_position & BOTTOM) { + panel->posy = server.monitor[panel->monitor].y + server.monitor[panel->monitor].height - panel->area.height - panel->marginy; + } + else { + panel->posy = server.monitor[panel->monitor].y + ((server.monitor[panel->monitor].height - panel->area.height) / 2); + } + } + // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height); +} + + +void cleanup_panel() +{ + if (!panel1) return; + + task_active = 0; + task_drag = 0; + + cleanup_taskbar(); + + int i; + Panel *p; + for (i=0 ; i < nb_panel ; i++) { + p = &panel1[i]; + + free_area(&p->area); + + if (p->temp_pmap) { + XFreePixmap(server.dsp, p->temp_pmap); + p->temp_pmap = 0; + } + if (p->main_win) { + XDestroyWindow(server.dsp, p->main_win); + p->main_win = 0; + } + } + + if (panel1) { + free(panel1); + panel1 = 0; + nb_panel = 0; + } + + if (panel_config.g_task.font_desc) { + pango_font_description_free(panel_config.g_task.font_desc); + panel_config.g_task.font_desc = 0; + } +} + + +void resize_panel(void *obj) { - server_refresh_root_pixmap (); - - draw (&panel.area); - refresh (&panel.area); - -/* -pour version 0.7 -gestion du systray - positionnement et taille fixe du systray (objet systray) - détection des notifications (détection des icones, ajout a la liste) - ajouter la transparence des icones - gérer le redimentionnement des éléments - => voir si lon peut faire abstraction sur le positionnement des objets ? - sachant que certains objets (task, taskbar) on une taille définit par l'extérieur - et d'autres objets (clock, systray) on une taille définit par l'intérieur - -gestion du layout - voir le positionnement des taskbar, task et systray - définir panel_layout dans la configuration - comment gérer le multi panel avec des layouts différents - -vérifier le niveau d'abstraction du code - utiliser la fonction draw(obj) récurrente sur Taskbar, Task, Systray, Clock - est ce compatible avec l'affichage de la tache active et les changement de taille -> redessine le panel - -correction de bugs : - memory, segfault - background - remettre en place single_desktop avec nouveau layout - remettre en place multi_monitor avec nouveau layout - vérifier le changement de configuration - -pour version 0.8 -gestion du thème - voir la gestion du dégradé sur le bord et le fond (inkscape) - faut-il trois coordonnées de padding x, y, x inter-objects - -gestion du zoom - définir le zoom du panel - -*/ - - if (panel.clock.time1_format) { - if (panel.clock.area.redraw) - panel.refresh = 1; - if (draw (&panel.clock.area)) { - panel.clock.area.redraw = 1; - draw (&panel.clock.area); - resize_clock(); - resize_taskbar(); - redraw(&panel.area); - } - refresh (&panel.clock.area); - } - - // TODO: ne pas afficher les taskbar invisibles - //if (panel.mode != MULTI_DESKTOP && desktop != server.desktop) continue; - Task *tsk; - Taskbar *tskbar; - GSList *l0; - for (l0 = panel.area.list; l0 ; l0 = l0->next) { - tskbar = l0->data; - draw (&tskbar->area); - refresh (&tskbar->area); - - GSList *l1; - for (l1 = tskbar->area.list; l1 ; l1 = l1->next) { - tsk = l1->data; - draw(&tsk->area); - - if (tsk == panel.task_active) refresh (&tsk->area_active); - else refresh (&tsk->area); - } - } - - XCopyArea (server.dsp, server.pmap, window.main_win, server.gc, 0, 0, panel.area.width, panel.area.height, 0, 0); - XFlush(server.dsp); - panel.refresh = 0; + 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.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 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 set_panel_properties (Window win) +void visible_object() { - XStoreName (server.dsp, win, "tint2"); - - // TODO: check if the name is really needed for a panel/taskbar ? - gsize len; - gchar *name = g_locale_to_utf8("tint2", -1, NULL, &len, NULL); - if (name != NULL) { - XChangeProperty(server.dsp, win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 8, PropModeReplace, (unsigned char *) name, (int) len); - g_free(name); - } - - // Dock - long val = server.atom._NET_WM_WINDOW_TYPE_DOCK; - XChangeProperty (server.dsp, 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] = panel.area.height + panel.marginy; - struts[8] = server.posx; - struts[9] = server.posx + panel.area.width; - } - else { - struts[3] = panel.area.height + panel.marginy; - struts[10] = server.posx; - struts[11] = server.posx + panel.area.width; - } - XChangeProperty (server.dsp, win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12); - // Old specification - XChangeProperty (server.dsp, win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4); - - // Sticky and below other window - val = 0xFFFFFFFF; - XChangeProperty (server.dsp, 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; - state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR; - state[2] = server.atom._NET_WM_STATE_STICKY; - state[3] = server.atom._NET_WM_STATE_BELOW; - XChangeProperty (server.dsp, win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4); - - // Fixed position - XSizeHints size_hints; - size_hints.flags = PPosition; - XChangeProperty (server.dsp, win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32, PropModeReplace, (unsigned char *) &size_hints, sizeof (XSizeHints) / 4); - - // Unfocusable - XWMHints wmhints; - wmhints.flags = InputHint; - wmhints.input = False; - XChangeProperty (server.dsp, win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace, (unsigned char *) &wmhints, sizeof (XWMHints) / 4); + 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 window_draw_panel () +void set_panel_properties(Panel *p) { - Window win; - - /* panel position determined here */ - if (panel.position & LEFT) server.posx = server.monitor[panel.monitor].x + panel.marginx; - else { - if (panel.position & RIGHT) server.posx = server.monitor[panel.monitor].x + server.monitor[panel.monitor].width - panel.area.width - panel.marginx; - else server.posx = server.monitor[panel.monitor].x + ((server.monitor[panel.monitor].width - panel.area.width) / 2); - } - if (panel.position & TOP) server.posy = server.monitor[panel.monitor].y + panel.marginy; - else server.posy = server.monitor[panel.monitor].y + server.monitor[panel.monitor].height - panel.area.height - panel.marginy; - - /* 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) */ - if (window.main_win) XDestroyWindow(server.dsp, window.main_win); - win = XCreateWindow (server.dsp, server.root_win, server.posx, server.posy, panel.area.width, panel.area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att); - - set_panel_properties (win); - window.main_win = win; - - // replaced : server.gc = DefaultGC (server.dsp, 0); - if (server.gc) XFree(server.gc); - XGCValues gcValues; - server.gc = XCreateGC(server.dsp, win, (unsigned long) 0, &gcValues); - - XMapWindow (server.dsp, win); - XFlush (server.dsp); + XStoreName (server.dsp, p->main_win, "tint2"); + + gsize len; + gchar *name = g_locale_to_utf8("tint2", -1, NULL, &len, NULL); + if (name != NULL) { + XChangeProperty(server.dsp, p->main_win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 8, PropModeReplace, (unsigned char *) name, (int) len); + g_free(name); + } + + // 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); + + // Sticky and below other window + val = ALLDESKTOP; + 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; + state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR; + state[2] = server.atom._NET_WM_STATE_STICKY; + state[3] = panel_layer == BOTTOM_LAYER ? server.atom._NET_WM_STATE_BELOW : server.atom._NET_WM_STATE_ABOVE; + XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, panel_layer == NORMAL_LAYER ? 3 : 4); + + // Unfocusable + XWMHints wmhints; + if (panel_dock) { + wmhints.icon_window = wmhints.window_group = p->main_win; + wmhints.flags = StateHint | IconWindowHint; + wmhints.initial_state = WithdrawnState; + } + else { + wmhints.flags = InputHint; + wmhints.input = False; + } + XSetWMHints(server.dsp, p->main_win, &wmhints); + + // Undecorated + long prop[5] = { 2, 0, 0, 0, 0 }; + 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; + XChangeProperty(server.dsp, p->main_win, server.atom.XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1); + + // Reserved space + unsigned int d1, screen_width, screen_height; + Window d2; + int d3; + XGetGeometry(server.dsp, server.root_win, &d2, &d3, &d3, &screen_width, &screen_height, &d1, &d1); + Monitor monitor = server.monitor[p->monitor]; + long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + if (panel_horizontal) { + if (panel_position & TOP) { + struts[2] = p->area.height + p->marginy + monitor.y; + 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 + screen_height - monitor.y - monitor.height; + 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 + monitor.x; + 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 + screen_width - monitor.x - monitor.width; + 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); + + // Fixed position and non-resizable window + // Allow panel move and resize when tint2 reload config file + XSizeHints size_hints; + size_hints.flags = PPosition|PMinSize|PMaxSize; + size_hints.min_width = size_hints.max_width = p->area.width; + size_hints.min_height = size_hints.max_height = p->area.height; + XSetWMNormalHints(server.dsp, p->main_win, &size_hints); + + // Set WM_CLASS + XClassHint* classhint = XAllocClassHint(); + classhint->res_name = "tint2"; + classhint->res_class = "Tint2"; + XSetClassHint(server.dsp, p->main_win, classhint); + XFree(classhint); } -void resize_clock() +void set_panel_background(Panel *p) { - panel.clock.area.posx = panel.area.width - panel.clock.area.width - panel.area.paddingx - panel.area.border.width; + if (p->area.pix.pmap) XFreePixmap (server.dsp, p->area.pix.pmap); + p->area.pix.pmap = XCreatePixmap (server.dsp, server.root_win, p->area.width, p->area.height, server.depth); + + if (real_transparency) { + clear_pixmap(p->area.pix.pmap, 0, 0, p->area.width, p->area.height); + return; // no need for background pixmap, a transparent one is enough + } + + get_root_pixmap(); + + // copy background (server.root_pmap) in panel.area.pix.pmap + Window dummy; + int x, y; + XTranslateCoordinates(server.dsp, p->main_win, server.root_win, 0, 0, &x, &y, &dummy); + XSetTSOrigin(server.dsp, server.gc, -x, -y) ; + XFillRectangle(server.dsp, p->area.pix.pmap, server.gc, 0, 0, p->area.width, p->area.height); + + // draw background panel + cairo_surface_t *cs; + cairo_t *c; + cs = cairo_xlib_surface_create (server.dsp, p->area.pix.pmap, server.visual, p->area.width, p->area.height); + c = cairo_create (cs); + + draw_background(&p->area, c, 0); + + cairo_destroy (c); + cairo_surface_destroy (cs); + + // redraw panel's object + GSList *l0; + Area *a; + for (l0 = p->area.list; l0 ; l0 = l0->next) { + a = l0->data; + set_redraw(a); + } } -// initialise taskbar posx and width -void resize_taskbar() +Panel *get_panel(Window win) { - int taskbar_width, modulo_width, taskbar_on_screen; - - if (panel.mode == MULTI_DESKTOP) taskbar_on_screen = panel.nb_desktop; - else taskbar_on_screen = panel.nb_monitor; - - taskbar_width = panel.area.width - (2 * panel.area.paddingx) - (2 * panel.area.border.width); - if (panel.clock.time1_format) - taskbar_width -= (panel.clock.area.width + panel.area.paddingx); - taskbar_width = (taskbar_width - ((taskbar_on_screen-1) * panel.area.paddingx)) / taskbar_on_screen; - - if (taskbar_on_screen > 1) - modulo_width = (taskbar_width - ((taskbar_on_screen-1) * panel.area.paddingx)) % taskbar_on_screen; - else - modulo_width = 0; - - int posx, modulo, i; - Taskbar *tskbar; - GSList *l0; - for (i = 0, l0 = panel.area.list; l0 ; i++, l0 = l0->next) { - if ((i % taskbar_on_screen) == 0) { - posx = panel.area.border.width + panel.area.paddingx; - modulo = modulo_width; - } - else posx += taskbar_width + panel.area.paddingx; - - tskbar = l0->data; - tskbar->area.posx = posx; - tskbar->area.width = taskbar_width; - if (modulo) { - tskbar->area.width++; - modulo--; - } - - resize_tasks(tskbar); - } + int i; + for (i=0 ; i < nb_panel ; i++) { + if (panel1[i].main_win == win) { + return &panel1[i]; + } + } + return 0; } +Taskbar *click_taskbar (Panel *panel, int x, int y) +{ + Taskbar *tskbar; + int i; + + if (panel_horizontal) { + for (i=0; i < panel->nb_desktop ; i++) { + tskbar = &panel->taskbar[i]; + if (tskbar->area.on_screen && x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width)) + return tskbar; + } + } + else { + for (i=0; i < panel->nb_desktop ; i++) { + tskbar = &panel->taskbar[i]; + if (tskbar->area.on_screen && y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height)) + return tskbar; + } + } + return NULL; +} + + +Task *click_task (Panel *panel, int x, int y) +{ + GSList *l0; + Taskbar *tskbar; + + if ( (tskbar = click_taskbar(panel, x, y)) ) { + if (panel_horizontal) { + Task *tsk; + for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + tsk = l0->data; + if (tsk->area.on_screen && x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) { + return tsk; + } + } + } + else { + Task *tsk; + for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + tsk = l0->data; + if (tsk->area.on_screen && y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) { + return tsk; + } + } + } + } + return NULL; +} + + +int click_padding(Panel *panel, int x, int y) +{ + if (panel_horizontal) { + if (x < panel->area.paddingxlr || x > panel->area.width-panel->area.paddingxlr) + return 1; + } + else { + if (y < panel->area.paddingxlr || y > panel->area.height-panel->area.paddingxlr) + return 1; + } + return 0; +} + + +int click_clock(Panel *panel, int x, int y) +{ + Clock clk = panel->clock; + if (panel_horizontal) { + if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width)) + return TRUE; + } else { + if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height)) + return TRUE; + } + return FALSE; +} + + +Area* click_area(Panel *panel, int x, int y) +{ + Area* result = &panel->area; + Area* new_result = result; + do { + result = new_result; + GSList* it = result->list; + while (it) { + Area* a = it->data; + if (panel_horizontal) { + if (a->on_screen && x >= a->posx && x <= (a->posx + a->width)) { + new_result = a; + break; + } + } else { + if (a->on_screen && y >= a->posy && y <= (a->posy + a->height)) { + new_result = a; + break; + } + } + it = it->next; + } + } while (new_result != result); + return result; +}