X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fpanel.c;h=ee3e27df6bb6042eca449152538c98cf102ce962;hb=be465e9a323ee71d7a6ab71040a117d3d64db813;hp=c6c706ef5d8186fd0441646dc24406e0e19a8016;hpb=0fae0eb881c82e304878bc47b0462b3caed05ed7;p=chaz%2Ftint2 diff --git a/src/panel.c b/src/panel.c index c6c706e..ee3e27d 100644 --- a/src/panel.c +++ b/src/panel.c @@ -52,14 +52,12 @@ int panel_refresh; Task *task_active; Task *task_drag; -Task *task_urgent; -int tick_urgent; 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,6 +69,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); @@ -107,11 +112,12 @@ void init_panel() new_panel[i].main_win = old_win; } - fprintf(stderr, "tint2 : nb monitor %d, nb desktop %d\n", nb_panel, server.nb_desktop); + 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]; - p->monitor = i; + if (panel_config.monitor < 0) + p->monitor = i; p->area.parent = p; p->area.panel = p; p->area.on_screen = 1; @@ -123,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); } @@ -137,6 +143,7 @@ void init_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) { @@ -144,15 +151,22 @@ void init_panel() 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); + 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; + if (real_transparency) + server.gc = XCreateGC(server.dsp, p->main_win, 0, &gcv); + else + server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)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); @@ -164,7 +178,6 @@ void init_panel() panel1 = new_panel; panel_refresh = 1; - refresh_systray = 1; init_taskbar(); visible_object(); task_refresh_tasklist(); @@ -233,14 +246,8 @@ 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; - } + cleanup_taskbar(); int i; Panel *p; @@ -259,8 +266,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; + } } @@ -414,16 +429,21 @@ void set_panel_properties(Panel *p) 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; @@ -431,13 +451,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; @@ -454,16 +474,35 @@ void set_panel_properties(Panel *p) 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 set_panel_background(Panel *p) { - get_root_pixmap(); - 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) { + cairo_surface_t *tmp = cairo_xlib_surface_create (server.dsp, p->area.pix.pmap, server.visual, p->area.width, p->area.height); + cairo_t *cr = cairo_create(tmp); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_rectangle(cr, 0, 0, p->area.width, p->area.height); + cairo_set_source_rgba(cr, 1, 1, 1, 0); + cairo_paint (cr); + cairo_destroy (cr); + cairo_surface_destroy (tmp); + return; + } + + get_root_pixmap(); + // copy background (server.root_pmap) in panel.area.pix.pmap Window dummy; int x, y; @@ -503,3 +542,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; +}