all repos — tint2 @ 7fa58c0552d265c48706e4aaf5233054f487167a

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

*change* make tooltip more generous, and preparation for setting a tooltip on the clock



git-svn-id: http://tint2.googlecode.com/svn/trunk@271 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
Andreas.Fink85 Andreas.Fink85@121b4492-b84c-0410-8b4c-0d4edfb3f3cc
commit

7fa58c0552d265c48706e4aaf5233054f487167a

parent

d1e7d189bfb4497b67c83f6d0eb7cc1d0088cac5

M src/clock/clock.csrc/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;

@@ -54,6 +56,12 @@ for (i=0 ; i < nb_panel ; i++)

panel1[i].clock.area.resize = 1; } panel_refresh = 1; +} + + +const char* clock_get_tooltip(void* obj) +{ + return buf_tooltip; }

@@ -109,6 +117,11 @@

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 @@ if (time1_format)

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)
M src/panel.csrc/panel.c

@@ -512,3 +512,109 @@ }

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; +}
M src/panel.hsrc/panel.h

@@ -120,5 +120,10 @@

// detect witch panel Panel *get_panel(Window win); +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 -
M src/taskbar/task.csrc/taskbar/task.c

@@ -36,6 +36,13 @@ #include "timer.h"

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 @@ // hide ALLDESKTOP task on non-current desktop

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 @@

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);

@@ -158,12 +160,6 @@ Panel *panel = tsk->area.panel;

char *title, *name; 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)) {
M src/tint.csrc/tint.c

@@ -178,86 +178,6 @@ imlib_free_image();

} -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 @@

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;

@@ -809,7 +730,6 @@ case MapNotify:

if (e.xany.window == g_tooltip.window) tooltip_update(); break; - case PropertyNotify: event_property_notify(&e);
M src/tooltip/tooltip.csrc/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 @@ {

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 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_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 @@ cs = cairo_xlib_surface_create(server.dsp, g_tooltip.window, server.visual, width, height);

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 @@ // adjust coordinates and size to not go offscreen

// 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_update() { - if (!g_tooltip.task) { + if (!g_tooltip.area->_get_tooltip_text) { tooltip_hide(); return; }

@@ -224,7 +224,7 @@ config_color fc = g_tooltip.font_color;

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_trigger_hide(Tooltip* tooltip) { if (g_tooltip.mapped) { - g_tooltip.task = 0; + g_tooltip.area = 0; start_hide_timeout(); } else {
M src/tooltip/tooltip.hsrc/tooltip/tooltip.h

@@ -21,10 +21,12 @@

#include <sys/time.h> #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();
M src/util/area.hsrc/util/area.h

@@ -79,6 +79,7 @@ void (*_draw_foreground)(void *obj, cairo_t *c, int active);

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