libxputty
0.1
Loading...
Searching...
No Matches
xputty
widgets
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
25
void
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
41
void
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
47
Widget_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);
52
os_set_window_attrb
(wid);
53
os_set_transient_for_hint
(parent, wid);
54
wid->
flags
&= ~USE_TRANSPARENCY;
55
wid->
func
.
expose_callback
=
_draw_tooltip
;
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
}
Childlist_t::childs
Widget_t ** childs
Definition
xchildlist.h:51
Childlist_t::elem
int elem
Definition
xchildlist.h:57
Func_t::expose_callback
xevfunc expose_callback
Definition
xwidget.h:85
Resize_t::gravity
Gravity gravity
Definition
xwidget.h:347
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition
xwidget.h:457
Widget_t::scale
Resize_t scale
Definition
xwidget.h:525
Widget_t::widget
Window widget
Definition
xwidget.h:469
Widget_t::childlist
Childlist_t * childlist
Definition
xwidget.h:499
Widget_t::flags
long long flags
Definition
xwidget.h:461
Widget_t::label
const char * label
Definition
xwidget.h:463
Widget_t::func
Func_t func
Definition
xwidget.h:481
Widget_t::app
Xputty * app
Definition
xwidget.h:465
childlist_add_child
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
tooltip_set_text
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
create_tooltip
Widget_t * create_tooltip(Widget_t *parent, int width, int height)
create_tooltip - create a tooltip for a Widget_t
Definition
xtooltip.c:47
add_tooltip
void add_tooltip(Widget_t *w, const char *label)
add_tooltip - add a tooltip to Widget_t
Definition
xtooltip.c:41
xtooltip.h
xtooltip_private.h
_get_width
void _get_width(Widget_t *w)
_get_width - get the width of a tooltip text and resize the tooltip widget to match the size
Definition
xtooltip_private.c:25
_draw_tooltip
void _draw_tooltip(void *w_, void *user_data)
_draw_tooltip - draw tooltip on expose call
Definition
xtooltip_private.c:32
os_get_root_window
Window os_get_root_window(Xputty *main, int flag)
os_get_root_window - get a pointer to the root window (desktop)
Definition
xwidget-linux.c:69
os_translate_coords
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
Definition
xwidget-linux.c:73
os_set_transient_for_hint
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,...
Definition
xwidget-linux.c:771
os_set_window_attrb
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
Definition
xwidget-linux.c:755
create_window
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
@ NONE
Definition
xwidget.h:328
IS_TOOLTIP
@ IS_TOOLTIP
Definition
xwidget.h:396
IS_WIDGET
@ IS_WIDGET
Definition
xwidget.h:388
HAS_TOOLTIP
@ HAS_TOOLTIP
Definition
xwidget.h:404
Generated by
1.9.8