From: Andreas Fink Date: Mon, 16 Nov 2009 17:17:53 +0000 (+0000) Subject: *change* make tooltip more generous, and preparation for setting a tooltip on the... X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Ftint2;a=commitdiff_plain;h=2cccd91fa633d9bfefd46073981276cb29fda5e7 *change* make tooltip more generous, and preparation for setting a tooltip on the clock --- diff --git a/src/clock/clock.c b/src/clock/clock.c index 89bb250..200996e 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -35,6 +35,7 @@ char *time1_format=0; char *time2_format=0; +char *time_tooltip_format=0; char *clock_lclick_command=0; char *clock_rclick_command=0; struct timeval time_clock; @@ -42,6 +43,7 @@ PangoFontDescription *time1_font_desc=0; PangoFontDescription *time2_font_desc=0; static char buf_time[40]; static char buf_date[40]; +static char buf_tooltip[40]; int clock_enabled; @@ -57,6 +59,12 @@ void update_clocks() } +const char* clock_get_tooltip(void* obj) +{ + return buf_tooltip; +} + + void init_clock() { if(time1_format) { @@ -109,6 +117,11 @@ void init_clock_panel(void *p) clock->time1_posy -= ((date_height_ink + 2) / 2); clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2; } + + if (time_tooltip_format) { + clock->area._get_tooltip_text = clock_get_tooltip; + strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, localtime(&time_clock.tv_sec)); + } } @@ -123,6 +136,8 @@ void cleanup_clock() g_free(time1_format); if (time2_format) g_free(time2_format); + if (time_tooltip_format) + g_free(time_tooltip_format); if (clock_lclick_command) g_free(clock_lclick_command); if (clock_rclick_command) diff --git a/src/panel.c b/src/panel.c index 7b2fb1e..52ae61b 100644 --- a/src/panel.c +++ b/src/panel.c @@ -512,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; +} diff --git a/src/panel.h b/src/panel.h index 864074c..646d796 100644 --- a/src/panel.h +++ b/src/panel.h @@ -120,5 +120,10 @@ void set_panel_background(Panel *p); // detect witch panel Panel *get_panel(Window win); -#endif +Taskbar *click_taskbar (Panel *panel, int x, int y); +Task *click_task (Panel *panel, int x, int y); +int click_padding(Panel *panel, int x, int y); +int click_clock(Panel *panel, int x, int y); +Area* click_area(Panel *panel, int x, int y); +#endif diff --git a/src/taskbar/task.c b/src/taskbar/task.c index 4e85c94..0d69e15 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -36,6 +36,13 @@ static int urgent_timer = 0; +const char* task_get_tooltip(void* obj) +{ + Task* t = obj; + return t->title; +} + + Task *add_task (Window win) { if (!win) return 0; @@ -82,6 +89,7 @@ Task *add_task (Window win) new_tsk2->area.on_screen = 0; } new_tsk2->title = new_tsk.title; + new_tsk2->area._get_tooltip_text = task_get_tooltip; new_tsk2->icon = new_tsk.icon; new_tsk2->icon_active = new_tsk.icon_active; new_tsk2->icon_width = new_tsk.icon_width; @@ -102,12 +110,6 @@ void remove_task (Task *tsk) Window win = tsk->win; int desktop = tsk->desktop; - if (g_tooltip.task == tsk) { - tooltip_hide(); - alarm(0); - g_tooltip.task = 0; - } - // free title and icon just for the first task // even with task_on_all_desktop and with task_on_all_panel //printf("remove_task %s %d\n", tsk->title, tsk->desktop); @@ -159,12 +161,6 @@ void get_title(Task *tsk) if (!panel->g_task.text && !g_tooltip.enabled) return; - if (g_tooltip.task == tsk) { - tooltip_hide(); - alarm(0); - g_tooltip.task = 0; - } - name = server_get_property (tsk->win, server.atom._NET_WM_VISIBLE_NAME, server.atom.UTF8_STRING, 0); if (!name || !strlen(name)) { name = server_get_property (tsk->win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 0); diff --git a/src/tint.c b/src/tint.c index 9b10732..05d50f6 100644 --- a/src/tint.c +++ b/src/tint.c @@ -178,86 +178,6 @@ void get_snapshot(const char *path) } -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; -} - - void window_action (Task *tsk, int action) { if (!tsk) return; @@ -789,9 +709,10 @@ int main (int argc, char *argv[]) case MotionNotify: { if (!g_tooltip.enabled) break; Panel* panel = get_panel(e.xmotion.window); - Task* task = click_task(panel, e.xmotion.x, e.xmotion.y); - if (task) - tooltip_trigger_show(task, e.xmotion.x_root, e.xmotion.y_root); + Area* area = click_area(panel, e.xmotion.x, e.xmotion.y); + if (area->_get_tooltip_text) { + tooltip_trigger_show(area, panel, e.xmotion.x_root, e.xmotion.y_root); + } else tooltip_trigger_hide(); break; @@ -810,7 +731,6 @@ int main (int argc, char *argv[]) tooltip_update(); break; - case PropertyNotify: event_property_notify(&e); break; diff --git a/src/tooltip/tooltip.c b/src/tooltip/tooltip.c index e2f8a1d..61e21b5 100644 --- a/src/tooltip/tooltip.c +++ b/src/tooltip/tooltip.c @@ -34,7 +34,8 @@ void stop_timeouts(); // give the tooltip some reasonable default values Tooltip g_tooltip = { - .task = 0, + .area = 0, + .panel = 0, .window = 0, .show_timeout = { 0, 0 }, .hide_timeout = { 0, 0 }, @@ -73,9 +74,7 @@ void cleanup_tooltip() stop_timeouts(); tooltip_hide(); g_tooltip.enabled = False; - if (g_tooltip.task) { - g_tooltip.task = 0; - } + g_tooltip.area = 0; if (g_tooltip.window) { XDestroyWindow(server.dsp, g_tooltip.window); g_tooltip.window = 0; @@ -87,18 +86,17 @@ void cleanup_tooltip() } -void tooltip_trigger_show(Task* task, int x_root, int y_root) +void tooltip_trigger_show(Area* area, Panel* p, int x_root, int y_root) { x = x_root; y = y_root; - - if (g_tooltip.mapped && g_tooltip.task != task) { - g_tooltip.task = task; + g_tooltip.panel = p; + if (g_tooltip.mapped && g_tooltip.area != area) { + g_tooltip.area = area; tooltip_update(); stop_timeouts(); } else if (!g_tooltip.mapped) { - g_tooltip.task = task; start_show_timeout(); } } @@ -106,8 +104,10 @@ void tooltip_trigger_show(Task* task, int x_root, int y_root) void tooltip_show() { + Area* area = click_area(g_tooltip.panel, x, y); stop_timeouts(); - if (!g_tooltip.mapped) { + if (!g_tooltip.mapped && area->_get_tooltip_text) { + g_tooltip.area = area; g_tooltip.mapped = True; XMapWindow(server.dsp, g_tooltip.window); XFlush(server.dsp); @@ -124,13 +124,13 @@ void tooltip_update_geometry() c = cairo_create(cs); layout = pango_cairo_create_layout(c); pango_layout_set_font_description(layout, g_tooltip.font_desc); - pango_layout_set_text(layout, g_tooltip.task->title, -1); + pango_layout_set_text(layout, g_tooltip.area->_get_tooltip_text(g_tooltip.area), -1); PangoRectangle r1, r2; pango_layout_get_pixel_extents(layout, &r1, &r2); width = 2*g_tooltip.border.width + 2*g_tooltip.paddingx + r2.width; height = 2*g_tooltip.border.width + 2*g_tooltip.paddingy + r2.height; - Panel* panel = g_tooltip.task->area.panel; + Panel* panel = g_tooltip.panel; if (panel_horizontal && panel_position & BOTTOM) y = panel->posy-height; else if (panel_horizontal && panel_position & TOP) @@ -152,7 +152,7 @@ void tooltip_adjust_geometry() // it seems quite impossible that the height needs to be adjusted, but we do it anyway. int min_x, min_y, max_width, max_height; - Panel* panel = g_tooltip.task->area.panel; + Panel* panel = g_tooltip.panel; int screen_width = server.monitor[panel->monitor].x + server.monitor[panel->monitor].width; int screen_height = server.monitor[panel->monitor].y + server.monitor[panel->monitor].height; if ( x+width <= screen_width && y+height <= screen_height && x>=0 && y>=0) @@ -194,7 +194,7 @@ void tooltip_adjust_geometry() void tooltip_update() { - if (!g_tooltip.task) { + if (!g_tooltip.area->_get_tooltip_text) { tooltip_hide(); return; } @@ -224,7 +224,7 @@ void tooltip_update() cairo_set_source_rgba(c, fc.color[0], fc.color[1], fc.color[2], fc.alpha); layout = pango_cairo_create_layout(c); pango_layout_set_font_description(layout, g_tooltip.font_desc); - pango_layout_set_text(layout, g_tooltip.task->title, -1); + pango_layout_set_text(layout, g_tooltip.area->_get_tooltip_text(g_tooltip.area), -1); PangoRectangle r1, r2; pango_layout_get_pixel_extents(layout, &r1, &r2); pango_layout_set_width(layout, width*PANGO_SCALE); @@ -243,7 +243,7 @@ void tooltip_update() void tooltip_trigger_hide(Tooltip* tooltip) { if (g_tooltip.mapped) { - g_tooltip.task = 0; + g_tooltip.area = 0; start_hide_timeout(); } else { diff --git a/src/tooltip/tooltip.h b/src/tooltip/tooltip.h index 53f1256..462857b 100644 --- a/src/tooltip/tooltip.h +++ b/src/tooltip/tooltip.h @@ -21,10 +21,12 @@ #include #include "task.h" +#include "panel.h" typedef struct { - Task* task; + Area* area; + Panel* panel; Window window; struct timespec show_timeout; struct timespec hide_timeout; @@ -44,7 +46,7 @@ extern Tooltip g_tooltip; void init_tooltip(); void cleanup_tooltip(); -void tooltip_trigger_show(Task* task, int x, int y); +void tooltip_trigger_show(Area* area, Panel* p, int x, int y); void tooltip_show(); void tooltip_update(); void tooltip_trigger_hide(); diff --git a/src/util/area.h b/src/util/area.h index 52a8c49..5ddd0c3 100644 --- a/src/util/area.h +++ b/src/util/area.h @@ -79,6 +79,7 @@ typedef struct { void (*_resize)(void *obj); void (*_add_child)(void *obj); int (*_remove_child)(void *obj); + const char* (*_get_tooltip_text)(void *obj); } Area; @@ -101,6 +102,5 @@ void free_area (Area *a); // draw rounded rectangle void draw_rect(cairo_t *c, double x, double y, double w, double h, double r); - #endif