X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fpanel.c;h=a5a62dd987aaea8a6129901d456938d1a2b868b5;hb=f4fb078b79ed585b0ea3f26092321fbc1844db09;hp=c28db61c73e08727b1d4285752188a92037eb9fa;hpb=3083e8006371cfb4a454b8bce92a682e4bb87e50;p=chaz%2Ftint2 diff --git a/src/panel.c b/src/panel.c index c28db61..a5a62dd 100644 --- a/src/panel.c +++ b/src/panel.c @@ -52,14 +52,13 @@ int panel_refresh; Task *task_active; Task *task_drag; -Task *task_urgent; -int tick_urgent; +GSList *urgent_list; int max_tick_urgent; // panel's initial config Panel panel_config; // panels (one panel per monitor) -Panel *panel1 = NULL; +Panel *panel1 = 0; int nb_panel = 0; Imlib_Image default_icon = NULL; @@ -71,38 +70,55 @@ 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; + } } - // alloc panels (one monitor or all monitors) + // number of panels old_nb_panel = nb_panel; if (panel_config.monitor >= 0) nb_panel = 1; else nb_panel = server.nb_monitor; - fprintf(stderr, "tint2 : nb monitor %d, nb desktop %d\n", nb_panel, server.nb_desktop); -/* if (nb_panel < old_nb_panel) { - // freed old panels - for (i=nb_panel ; i < old_nb_panel ; i++) { + // 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 (i >= old_nb_panel) { - // new panel - memcpy(p, &panel_config, sizeof(Panel)); - } - p->monitor = i; + if (panel_config.monitor < 0) + p->monitor = i; p->area.parent = p; p->area.panel = p; p->area.on_screen = 1; @@ -114,12 +130,12 @@ void init_panel() init_panel_size_and_position(p); // add childs - if (p->clock.area.on_screen) { + if (clock_enabled) { init_clock_panel(p); p->area.list = g_slist_append(p->area.list, &p->clock); } #ifdef ENABLE_BATTERY - if (p->battery.area.on_screen) { + if (battery_enabled) { init_battery_panel(p); p->area.list = g_slist_append(p->area.list, &p->battery); } @@ -128,35 +144,28 @@ void init_panel() if (systray.area.on_screen && i == 0) { init_systray_panel(p); p->area.list = g_slist_append(p->area.list, &systray); - } - - // full width mode - if (!p->initial_width) { - p->initial_width = 100; - p->pourcentx = 1; + refresh_systray = 1; } if (i >= old_nb_panel) { - // new panel - //printf("new window\n"); - - // Catch some events + // new panel : catch some events long event_mask = ExposureMask|ButtonPressMask|ButtonReleaseMask; if (g_tooltip.enabled) event_mask |= PointerMotionMask|LeaveWindowMask; XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, event_mask, NoEventMask, False, 0, 0 }; - if (p->main_win) XDestroyWindow(server.dsp, p->main_win); 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); - set_panel_background(p); - XMapWindow (server.dsp, p->main_win); } else { // old panel - //printf("move old window\n"); XMoveResizeWindow(server.dsp, p->main_win, p->posx, p->posy, p->area.width, p->area.height); - set_panel_background(p); + } + + //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); } } @@ -165,6 +174,7 @@ void init_panel() init_taskbar(); visible_object(); task_refresh_tasklist(); + active_task(); } @@ -173,25 +183,22 @@ 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->initial_width / 100; - else - panel->area.width = panel->initial_width; + 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->initial_height / 100; - else - panel->area.height = panel->initial_height; + 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->initial_width / 100; + panel->area.height = (float)server.monitor[panel->monitor].height * panel->area.width / 100; else - panel->area.height = panel->initial_width; + panel->area.height = panel->area.width; if (panel->pourcenty) - panel->area.width = (float)server.monitor[panel->monitor].width * panel->initial_height / 100; + panel->area.width = (float)server.monitor[panel->monitor].width * old_panel_height / 100; else - panel->area.width = panel->initial_height; + 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; } @@ -232,15 +239,14 @@ void cleanup_panel() task_active = 0; task_drag = 0; - task_urgent = 0; - cleanup_taskbar(); - - // font allocated once - if (panel1[0].g_task.font_desc) { - pango_font_description_free(panel1[0].g_task.font_desc); - panel1[0].g_task.font_desc = 0; + while (urgent_list) { + Task_urgent* t = urgent_list->data; + urgent_list = g_slist_remove(urgent_list, urgent_list->data); + free(t); } + cleanup_taskbar(); + int i; Panel *p; for (i=0 ; i < nb_panel ; i++) { @@ -258,8 +264,16 @@ void cleanup_panel() } } - if (panel1) free(panel1); - panel1 = 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; + } } @@ -380,17 +394,54 @@ void set_panel_properties(Panel *p) 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 = 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; + 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, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4); + + // Unfocusable + XWMHints wmhints; + if (panel_dock) { + // TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work) + 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; + 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; + 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; @@ -398,13 +449,13 @@ void set_panel_properties(Panel *p) } else { if (panel_position & LEFT) { - struts[0] = p->area.width + p->marginx; + 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; + 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; @@ -414,44 +465,13 @@ void set_panel_properties(Panel *p) 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 - 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; - 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, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4); - // 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); - - // Unfocusable - XWMHints wmhints; - if (panel_dock) { - // TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work) - 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); } @@ -501,3 +521,109 @@ Panel *get_panel(Window win) 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; +}