X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fpanel.c;h=52ae61b6096e43131edd28a0c90772f4fd8bd4e5;hb=71d6d4f99d476ea747069aa236eadeab30249c7f;hp=e6d747f05fa277e66609b0720af94c4c04e5c78a;hpb=a674c17fb45a554e27981ea630e51b832a9b8d6f;p=chaz%2Ftint2 diff --git a/src/panel.c b/src/panel.c index e6d747f..52ae61b 100644 --- a/src/panel.c +++ b/src/panel.c @@ -52,8 +52,7 @@ 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 @@ -71,6 +70,13 @@ 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); @@ -80,30 +86,32 @@ void init_panel() } } - // 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; - if (nb_panel < old_nb_panel) { - // freed old panels - for (i=nb_panel ; i < old_nb_panel ; i++) { - if (panel1[i].main_win) - XDestroyWindow(server.dsp, panel1[i].main_win); + // 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; } - new_panel = realloc(panel1, nb_panel * sizeof(Panel)); } - else if (nb_panel > old_nb_panel) { + + // alloc & init new panel + Window old_win; + if (nb_panel != old_nb_panel) new_panel = realloc(panel1, nb_panel * sizeof(Panel)); - // init new panel - for (i=old_nb_panel ; i < nb_panel ; i++) { - memcpy(&new_panel[i], &panel_config, 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 desktop %d\n", nb_panel, server.nb_desktop); for (i=0 ; i < nb_panel ; i++) { @@ -121,12 +129,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); } @@ -135,44 +143,37 @@ 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 panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height); - - // 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("old panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height); 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); } } panel1 = new_panel; panel_refresh = 1; - refresh_systray = 1; init_taskbar(); visible_object(); task_refresh_tasklist(); + active_task(); } @@ -181,25 +182,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; } @@ -240,15 +238,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++) { @@ -268,6 +265,11 @@ void cleanup_panel() if (panel1) free(panel1); panel1 = 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; + } } @@ -388,6 +390,38 @@ 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 long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; if (panel_horizontal) { @@ -422,44 +456,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); } @@ -509,3 +512,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; +}