libxputty 0.1
Loading...
Searching...
No Matches
xtooltip.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.h"
23#include "xtooltip_private.h"
24
25void tooltip_set_text(Widget_t *w, const char* label) {
26 Widget_t *wid = NULL;
27 bool is_tooltip = false;
28 int i = 0;
29 for(;i<w->childlist->elem;i++) {
30 wid = w->childlist->childs[i];
31 if (wid->flags & IS_TOOLTIP) {
32 wid->label = label;
33 _get_width(wid);
34 is_tooltip = true;
35 break;
36 }
37 }
38 if (!is_tooltip) add_tooltip(w, label);
39}
40
41void add_tooltip(Widget_t *w, const char* label) {
42 Widget_t *wid = create_tooltip(w, 25, 25);
43 wid->label = label;
44 _get_width(wid);
45}
46
47Widget_t* create_tooltip(Widget_t *parent, int width, int height) {
48
49 int x1, y1;
50 os_translate_coords(parent, parent->widget, os_get_root_window(parent->app, IS_WIDGET), 0, 0, &x1, &y1);
51 Widget_t *wid = create_window(parent->app, os_get_root_window(parent->app, IS_WIDGET), x1+10, y1+10, width, height);
53 os_set_transient_for_hint(parent, wid);
54 wid->flags &= ~USE_TRANSPARENCY;
56 wid->flags |= IS_TOOLTIP;
57 parent->flags |= HAS_TOOLTIP;
58 wid->scale.gravity = NONE;
59 childlist_add_child(parent->childlist, wid);
60 return wid;
61}
Widget_t ** childs
Definition xchildlist.h:51
xevfunc expose_callback
Definition xwidget.h:85
Gravity gravity
Definition xwidget.h:347
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Resize_t scale
Definition xwidget.h:525
Window widget
Definition xwidget.h:469
Childlist_t * childlist
Definition xwidget.h:499
long long flags
Definition xwidget.h:461
const char * label
Definition xwidget.h:463
Func_t func
Definition xwidget.h:481
Xputty * app
Definition xwidget.h:465
void childlist_add_child(Childlist_t *childlist, Widget_t *child)
childlist_add_child - internal use to add a child to the Childlist_t You usually didn't need to cal...
Definition xchildlist.c:42
void tooltip_set_text(Widget_t *w, const char *label)
tooltip_set_text - set a (new) text to a tooltip for Widget_t
Definition xtooltip.c:25
Widget_t * create_tooltip(Widget_t *parent, int width, int height)
create_tooltip - create a tooltip for a Widget_t
Definition xtooltip.c:47
void add_tooltip(Widget_t *w, const char *label)
add_tooltip - add a tooltip to Widget_t
Definition xtooltip.c:41
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
Window os_get_root_window(Xputty *main, int flag)
os_get_root_window - get a pointer to the root window (desktop)
void os_translate_coords(Widget_t *w, Window from_window, Window to_window, int from_x, int from_y, int *to_x, int *to_y)
os_translate_coords - get x,y related to destination Window
void os_set_transient_for_hint(Widget_t *parent, Widget_t *w)
os_set_ transient_for_hint - set a Widget_t transient to a other Widget_t only work on linux,...
void os_set_window_attrb(Widget_t *w)
os_set_window_attrb - set the attribute mask to a Widget_t only work on linux, stub on Windows
Widget_t * create_window(Xputty *app, Window win, int x, int y, int width, int height)
*create_window - create a Window You need to create as least minimun one Window to get started....
Definition xwidget.c:163
@ NONE
Definition xwidget.h:328
@ IS_TOOLTIP
Definition xwidget.h:396
@ IS_WIDGET
Definition xwidget.h:388
@ HAS_TOOLTIP
Definition xwidget.h:404