]> Dogcows Code - chaz/tint2/blobdiff - src/tooltip/tooltip.c
Center the tooltip correctly when the text changes while the tooltip is visible
[chaz/tint2] / src / tooltip / tooltip.c
index 11b7f3b06dd1f006b580b04e1f7b47224692c4b9..d703a2ed17706071cacf6fe55049f2097d5982ff 100644 (file)
@@ -27,7 +27,7 @@
 #include "panel.h"
 #include "timer.h"
 
-static int x, y, width, height;
+static int x_original, y_original, x, y, width, height;
 
 // the next functions are helper functions for tooltip handling
 void start_show_timeout();
@@ -75,10 +75,11 @@ void init_tooltip()
 }
 
 
-void tooltip_trigger_show(Area* area, Panel* p, int x_root, int y_root)
+void tooltip_trigger_show(Area* area, Panel* p, XEvent *e)
 {
-       x = x_root;
-       y = y_root;
+       // Position the tooltip in the center of the area
+       x = x_original = area->posx + area->width / 2 + e->xmotion.x_root - e->xmotion.x;
+       y = y_original = area->posy + area->height / 2 + e->xmotion.y_root - e->xmotion.y;
        g_tooltip.panel = p;
        if (g_tooltip.mapped && g_tooltip.area != area) {
                tooltip_copy_text(area);
@@ -93,10 +94,10 @@ void tooltip_trigger_show(Area* area, Panel* p, int x_root, int y_root)
 
 void tooltip_show(void* arg)
 {
-  int mx, my;
-  Window w;
-  XTranslateCoordinates( server.dsp, server.root_win, g_tooltip.panel->main_win, x, y, &mx, &my, &w);
-  Area* area = click_area(g_tooltip.panel, mx, my);
+       int mx, my;
+       Window w;
+       XTranslateCoordinates( server.dsp, server.root_win, g_tooltip.panel->main_win, x, y, &mx, &my, &w);
+       Area* area = click_area(g_tooltip.panel, mx, my);
        stop_tooltip_timeout();
        if (!g_tooltip.mapped && area->_get_tooltip_text) {
                tooltip_copy_text(area);
@@ -123,6 +124,9 @@ void tooltip_update_geometry()
        width = 2*g_tooltip.bg->border.width + 2*g_tooltip.paddingx + r2.width;
        height = 2*g_tooltip.bg->border.width + 2*g_tooltip.paddingy + r2.height;
 
+       x = x_original;
+       y = y_original;
+
        Panel* panel = g_tooltip.panel;
        if (panel_horizontal && panel_position & BOTTOM)
                y = panel->posy-height;
@@ -133,6 +137,9 @@ void tooltip_update_geometry()
        else
                x = panel->posx - width;
 
+       if (!panel_horizontal)
+               y -= height/2;
+
        g_object_unref(layout);
        cairo_destroy(c);
        cairo_surface_destroy(cs);
@@ -231,7 +238,7 @@ void tooltip_update()
        pango_layout_get_pixel_extents(layout, &r1, &r2);
        pango_layout_set_width(layout, width*PANGO_SCALE);
        pango_layout_set_height(layout, height*PANGO_SCALE);
-       pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE);
+       pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
        // I do not know why this is the right way, but with the below cairo_move_to it seems to be centered (horiz. and vert.)
        cairo_move_to(c, -r1.x/2+g_tooltip.bg->border.width+g_tooltip.paddingx, -r1.y/2+g_tooltip.bg->border.width+g_tooltip.paddingy);
        pango_cairo_show_layout (c, layout);
This page took 0.022264 seconds and 4 git commands to generate.