]> Dogcows Code - chaz/tint2/commitdiff
*change* make tooltip more generous, and preparation for setting a tooltip on the...
authorAndreas Fink <andreas.fink85@googlemail.com>
Mon, 16 Nov 2009 17:17:53 +0000 (17:17 +0000)
committerAndreas Fink <andreas.fink85@googlemail.com>
Mon, 16 Nov 2009 17:17:53 +0000 (17:17 +0000)
src/clock/clock.c
src/panel.c
src/panel.h
src/taskbar/task.c
src/tint.c
src/tooltip/tooltip.c
src/tooltip/tooltip.h
src/util/area.h

index 89bb250e8575ef3af7650813c2e4670b053acba9..200996ebd4263c3d95516930cbc7bde578380cd4 100644 (file)
@@ -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)
index 7b2fb1ec6529f921baacf2f8ed07c443d46bc429..52ae61b6096e43131edd28a0c90772f4fd8bd4e5 100644 (file)
@@ -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;
+}
index 864074cbd139a3d2e74f6e1048500e4f7820d3c1..646d79671b156ea0eb3a76c5aa2cde860bebc51d 100644 (file)
@@ -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
index 4e85c9450e8e47ef99c6e2d996db4994955c2013..0d69e1536d8e52ed623a1c59f2a122ce7ac5113a 100644 (file)
 
 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);
index 9b10732694603585bca70406aa9a00d63ca25787..05d50f67c14e085d3c4ec6117c8ab29b77045d07 100644 (file)
@@ -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;
index e2f8a1d02f626f75367e3b44057c81bae7868c22..61e21b50b1381a64f842c7c53db1f2c28555efbb 100644 (file)
@@ -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 {
index 53f1256a7015849909459f4e6c1960d01574dd12..462857bc95775e621c143770837c2a5808b7dfda 100644 (file)
 #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();
index 52a8c492492b0126fbff39b5928a60b3ff38d74f..5ddd0c3a95e773ba72814c2e05d33cb3195ce78b 100644 (file)
@@ -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
 
This page took 0.038265 seconds and 4 git commands to generate.