Cleanup indentation with clang-format and changed a few variable names
This commit is contained in:
@@ -37,15 +37,14 @@ void stop_tooltip_timeout();
|
||||
|
||||
Tooltip g_tooltip;
|
||||
|
||||
|
||||
void default_tooltip()
|
||||
{
|
||||
// give the tooltip some reasonable default values
|
||||
memset(&g_tooltip, 0, sizeof(Tooltip));
|
||||
|
||||
g_tooltip.font_color.rgb[0] = 1;
|
||||
g_tooltip.font_color.rgb[1] = 1;
|
||||
g_tooltip.font_color.rgb[2] = 1;
|
||||
g_tooltip.font_color.rgb[0] = 1;
|
||||
g_tooltip.font_color.rgb[1] = 1;
|
||||
g_tooltip.font_color.rgb[2] = 1;
|
||||
g_tooltip.font_color.alpha = 1;
|
||||
just_shown = 0;
|
||||
}
|
||||
@@ -62,12 +61,11 @@ void cleanup_tooltip()
|
||||
g_tooltip.font_desc = NULL;
|
||||
}
|
||||
|
||||
|
||||
void init_tooltip()
|
||||
{
|
||||
if (!g_tooltip.font_desc)
|
||||
g_tooltip.font_desc = pango_font_description_from_string(DEFAULT_FONT);
|
||||
if (g_tooltip.bg == 0)
|
||||
if (!g_tooltip.bg)
|
||||
g_tooltip.bg = &g_array_index(backgrounds, Background, 0);
|
||||
|
||||
XSetWindowAttributes attr;
|
||||
@@ -76,14 +74,14 @@ void init_tooltip()
|
||||
attr.colormap = server.colormap;
|
||||
attr.background_pixel = 0;
|
||||
attr.border_pixel = 0;
|
||||
unsigned long mask = CWEventMask|CWColormap|CWBorderPixel|CWBackPixel|CWOverrideRedirect;
|
||||
unsigned long mask = CWEventMask | CWColormap | CWBorderPixel | CWBackPixel | CWOverrideRedirect;
|
||||
if (g_tooltip.window)
|
||||
XDestroyWindow(server.dsp, g_tooltip.window);
|
||||
g_tooltip.window = XCreateWindow(server.dsp, server.root_win, 0, 0, 100, 20, 0, server.depth, InputOutput, server.visual, mask, &attr);
|
||||
g_tooltip.window =
|
||||
XCreateWindow(server.dsp, server.root_win, 0, 0, 100, 20, 0, server.depth, InputOutput, server.visual, mask, &attr);
|
||||
}
|
||||
|
||||
|
||||
void tooltip_trigger_show(Area* area, Panel* p, XEvent *e)
|
||||
void tooltip_trigger_show(Area *area, Panel *p, XEvent *e)
|
||||
{
|
||||
// Position the tooltip in the center of the area
|
||||
x = area->posx + MIN(area->width / 3, 22) + e->xmotion.x_root - e->xmotion.x;
|
||||
@@ -94,19 +92,17 @@ void tooltip_trigger_show(Area* area, Panel* p, XEvent *e)
|
||||
tooltip_copy_text(area);
|
||||
tooltip_update();
|
||||
stop_tooltip_timeout();
|
||||
}
|
||||
else if (!g_tooltip.mapped) {
|
||||
} else if (!g_tooltip.mapped) {
|
||||
start_show_timeout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void tooltip_show(void* arg)
|
||||
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;
|
||||
XTranslateCoordinates(server.dsp, server.root_win, g_tooltip.panel->main_win, x, y, &mx, &my, &w);
|
||||
Area *area;
|
||||
area = click_area(g_tooltip.panel, mx, my);
|
||||
if (!g_tooltip.mapped && area->_get_tooltip_text) {
|
||||
tooltip_copy_text(area);
|
||||
@@ -117,12 +113,11 @@ void tooltip_show(void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void tooltip_update_geometry()
|
||||
{
|
||||
cairo_surface_t *cs;
|
||||
cairo_t *c;
|
||||
PangoLayout* layout;
|
||||
PangoLayout *layout;
|
||||
cs = cairo_xlib_surface_create(server.dsp, g_tooltip.window, server.visual, width, height);
|
||||
c = cairo_create(cs);
|
||||
layout = pango_cairo_create_layout(c);
|
||||
@@ -130,12 +125,12 @@ void tooltip_update_geometry()
|
||||
pango_layout_set_text(layout, g_tooltip.tooltip_text, -1);
|
||||
PangoRectangle r1, r2;
|
||||
pango_layout_get_pixel_extents(layout, &r1, &r2);
|
||||
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;
|
||||
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;
|
||||
|
||||
Panel* panel = g_tooltip.panel;
|
||||
Panel *panel = g_tooltip.panel;
|
||||
if (panel_horizontal && panel_position & BOTTOM)
|
||||
y = panel->posy-height;
|
||||
y = panel->posy - height;
|
||||
else if (panel_horizontal && panel_position & TOP)
|
||||
y = panel->posy + panel->area.height;
|
||||
else if (panel_position & LEFT)
|
||||
@@ -148,51 +143,50 @@ void tooltip_update_geometry()
|
||||
cairo_surface_destroy(cs);
|
||||
}
|
||||
|
||||
|
||||
void tooltip_adjust_geometry()
|
||||
{
|
||||
// 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.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>=server.monitor[panel->monitor].x && y>=server.monitor[panel->monitor].y )
|
||||
return; // no adjustment needed
|
||||
if (x + width <= screen_width && y + height <= screen_height && x >= server.monitor[panel->monitor].x &&
|
||||
y >= server.monitor[panel->monitor].y)
|
||||
return; // no adjustment needed
|
||||
|
||||
if (panel_horizontal) {
|
||||
min_x=0;
|
||||
max_width=server.monitor[panel->monitor].width;
|
||||
max_height=server.monitor[panel->monitor].height-panel->area.height;
|
||||
min_x = 0;
|
||||
max_width = server.monitor[panel->monitor].width;
|
||||
max_height = server.monitor[panel->monitor].height - panel->area.height;
|
||||
if (panel_position & BOTTOM)
|
||||
min_y=0;
|
||||
min_y = 0;
|
||||
else
|
||||
min_y=panel->area.height;
|
||||
}
|
||||
else {
|
||||
max_width=server.monitor[panel->monitor].width-panel->area.width;
|
||||
min_y=0;
|
||||
max_height=server.monitor[panel->monitor].height;
|
||||
min_y = panel->area.height;
|
||||
} else {
|
||||
max_width = server.monitor[panel->monitor].width - panel->area.width;
|
||||
min_y = 0;
|
||||
max_height = server.monitor[panel->monitor].height;
|
||||
if (panel_position & LEFT)
|
||||
min_x=panel->area.width;
|
||||
min_x = panel->area.width;
|
||||
else
|
||||
min_x=0;
|
||||
min_x = 0;
|
||||
}
|
||||
|
||||
if (x+width > server.monitor[panel->monitor].x + server.monitor[panel->monitor].width)
|
||||
if (x + width > server.monitor[panel->monitor].x + server.monitor[panel->monitor].width)
|
||||
x = server.monitor[panel->monitor].x + server.monitor[panel->monitor].width - width;
|
||||
if ( y+height > server.monitor[panel->monitor].y + server.monitor[panel->monitor].height)
|
||||
if (y + height > server.monitor[panel->monitor].y + server.monitor[panel->monitor].height)
|
||||
y = server.monitor[panel->monitor].y + server.monitor[panel->monitor].height - height;
|
||||
|
||||
if (x<min_x)
|
||||
x=min_x;
|
||||
if (width>max_width)
|
||||
if (x < min_x)
|
||||
x = min_x;
|
||||
if (width > max_width)
|
||||
width = max_width;
|
||||
if (y<min_y)
|
||||
y=min_y;
|
||||
if (height>max_height)
|
||||
height=max_height;
|
||||
if (y < min_y)
|
||||
y = min_y;
|
||||
if (height > max_height)
|
||||
height = max_height;
|
||||
}
|
||||
|
||||
void tooltip_update()
|
||||
@@ -205,7 +199,7 @@ void tooltip_update()
|
||||
tooltip_update_geometry();
|
||||
if (just_shown) {
|
||||
if (!panel_horizontal)
|
||||
y -= height/2; // center vertically
|
||||
y -= height / 2; // center vertically
|
||||
just_shown = 0;
|
||||
}
|
||||
tooltip_adjust_geometry();
|
||||
@@ -214,65 +208,62 @@ void tooltip_update()
|
||||
// Stuff for drawing the tooltip
|
||||
cairo_surface_t *cs;
|
||||
cairo_t *c;
|
||||
PangoLayout* layout;
|
||||
PangoLayout *layout;
|
||||
cs = cairo_xlib_surface_create(server.dsp, g_tooltip.window, server.visual, width, height);
|
||||
c = cairo_create(cs);
|
||||
Color bc = g_tooltip.bg->fill_color;
|
||||
Color bc = g_tooltip.bg->fill_color;
|
||||
Border b = g_tooltip.bg->border;
|
||||
if (server.real_transparency) {
|
||||
clear_pixmap(g_tooltip.window, 0, 0, width, height);
|
||||
draw_rect(c, b.width, b.width, width-2*b.width, height-2*b.width, b.radius-b.width/1.571);
|
||||
cairo_set_source_rgba(c, bc.rgb[0], bc.rgb[1], bc.rgb[2], bc.alpha);
|
||||
}
|
||||
else {
|
||||
draw_rect(c, b.width, b.width, width - 2 * b.width, height - 2 * b.width, b.radius - b.width / 1.571);
|
||||
cairo_set_source_rgba(c, bc.rgb[0], bc.rgb[1], bc.rgb[2], bc.alpha);
|
||||
} else {
|
||||
cairo_rectangle(c, 0., 0, width, height);
|
||||
cairo_set_source_rgb(c, bc.rgb[0], bc.rgb[1], bc.rgb[2]);
|
||||
cairo_set_source_rgb(c, bc.rgb[0], bc.rgb[1], bc.rgb[2]);
|
||||
}
|
||||
cairo_fill(c);
|
||||
cairo_set_line_width(c, b.width);
|
||||
if (server.real_transparency)
|
||||
draw_rect(c, b.width/2.0, b.width/2.0, width - b.width, height - b.width, b.radius);
|
||||
draw_rect(c, b.width / 2.0, b.width / 2.0, width - b.width, height - b.width, b.radius);
|
||||
else
|
||||
cairo_rectangle(c, b.width/2.0, b.width/2.0, width-b.width, height-b.width);
|
||||
cairo_set_source_rgba(c, b.color.rgb[0], b.color.rgb[1], b.color.rgb[2], b.color.alpha);
|
||||
cairo_rectangle(c, b.width / 2.0, b.width / 2.0, width - b.width, height - b.width);
|
||||
cairo_set_source_rgba(c, b.color.rgb[0], b.color.rgb[1], b.color.rgb[2], b.color.alpha);
|
||||
cairo_stroke(c);
|
||||
|
||||
Color fc = g_tooltip.font_color;
|
||||
cairo_set_source_rgba(c, fc.rgb[0], fc.rgb[1], fc.rgb[2], fc.alpha);
|
||||
cairo_set_source_rgba(c, fc.rgb[0], fc.rgb[1], fc.rgb[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.tooltip_text, -1);
|
||||
PangoRectangle r1, r2;
|
||||
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_width(layout, width * PANGO_SCALE);
|
||||
pango_layout_set_height(layout, height * PANGO_SCALE);
|
||||
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.)
|
||||
// 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 + 1 + g_tooltip.bg->border.width + g_tooltip.paddingy);
|
||||
pango_cairo_show_layout (c, layout);
|
||||
-r1.x / 2 + g_tooltip.bg->border.width + g_tooltip.paddingx,
|
||||
-r1.y / 2 + 1 + g_tooltip.bg->border.width + g_tooltip.paddingy);
|
||||
pango_cairo_show_layout(c, layout);
|
||||
|
||||
g_object_unref (layout);
|
||||
cairo_destroy (c);
|
||||
cairo_surface_destroy (cs);
|
||||
g_object_unref(layout);
|
||||
cairo_destroy(c);
|
||||
cairo_surface_destroy(cs);
|
||||
}
|
||||
|
||||
|
||||
void tooltip_trigger_hide()
|
||||
{
|
||||
if (g_tooltip.mapped) {
|
||||
tooltip_copy_text(0);
|
||||
start_hide_timeout();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// tooltip not visible yet, but maybe a timeout is still pending
|
||||
stop_tooltip_timeout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void tooltip_hide(void* arg)
|
||||
void tooltip_hide(void *arg)
|
||||
{
|
||||
if (g_tooltip.mapped) {
|
||||
g_tooltip.mapped = False;
|
||||
@@ -281,26 +272,22 @@ void tooltip_hide(void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void start_show_timeout()
|
||||
{
|
||||
change_timeout(&g_tooltip.timeout, g_tooltip.show_timeout_msec, 0, tooltip_show, 0);
|
||||
}
|
||||
|
||||
|
||||
void start_hide_timeout()
|
||||
{
|
||||
change_timeout(&g_tooltip.timeout, g_tooltip.hide_timeout_msec, 0, tooltip_hide, 0);
|
||||
}
|
||||
|
||||
|
||||
void stop_tooltip_timeout()
|
||||
{
|
||||
stop_timeout(g_tooltip.timeout);
|
||||
}
|
||||
|
||||
|
||||
void tooltip_copy_text(Area* area)
|
||||
void tooltip_copy_text(Area *area)
|
||||
{
|
||||
free(g_tooltip.tooltip_text);
|
||||
if (area && area->_get_tooltip_text)
|
||||
|
||||
Reference in New Issue
Block a user