libxputty 0.1
Loading...
Searching...
No Matches
xtooltip_private.c
Go to the documentation of this file.
1/*
2 * 0BSD
3 *
4 * BSD Zero Clause License
5 *
6 * Copyright (c) 2019 Hermann Meyer
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted.
10
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
21
22#include "xtooltip_private.h"
23
24
26 cairo_text_extents_t extents;
27 cairo_set_font_size (w->crb, 12);
28 cairo_text_extents(w->crb,w->label , &extents);
29 os_resize_window (w->app->dpy, w, max(1, (int)extents.width+40), 25);
30}
31
32void _draw_tooltip(void *w_, void* user_data) {
33 Widget_t *w = (Widget_t*)w_;
34 if (!w) return;
35 Metrics_t metrics;
36 os_get_window_metrics(w, &metrics);
37 int width = metrics.width;
38 int height = metrics.height;
39 if (!metrics.visible) return;
41 cairo_paint (w->crb);
42 cairo_text_extents_t extents;
45 cairo_set_font_size (w->crb, w->app->normal_font/w->scale.ascale);
46 cairo_text_extents(w->crb,w->label , &extents);
47
48 cairo_move_to (w->crb, (width-extents.width)/2., height+5 - extents.height );
49 cairo_show_text(w->crb, w->label);
50
51}
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
float ascale
Definition xwidget.h:369
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Resize_t scale
Definition xwidget.h:525
cairo_t * crb
Definition xwidget.h:489
const char * label
Definition xwidget.h:463
Xputty * app
Definition xwidget.h:465
int normal_font
Definition xputty.h:248
Display * dpy
Definition xputty.h:232
Color_state get_color_state(Widget_t *wid)
get_color_state - get the Color_state to use in relation to the Widget_t state
Definition xcolor.c:222
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
Definition xcolor.c:266
void use_bg_color_scheme(Widget_t *w, Color_state st)
use_bg_color_scheme - use background Colors to paint on Widget_t
Definition xcolor.c:252
void _get_width(Widget_t *w)
_get_width - get the width of a tooltip text and resize the tooltip widget to match the size
void _draw_tooltip(void *w_, void *user_data)
_draw_tooltip - draw tooltip on expose call
void os_get_window_metrics(Widget_t *w, Metrics_t *metrics)
os_get_window_metrics - Get the Merics_t struct related to a Widget_t
void os_resize_window(Display *dpy, Widget_t *w, int x, int y)
os_resize_window - Resize a Widget_t