libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xtooltip.c File Reference
#include "xtooltip.h"
#include "xtooltip_private.h"
Include dependency graph for xtooltip.c:

Go to the source code of this file.

Functions

void tooltip_set_text (Widget_t *w, const char *label)
 tooltip_set_text - set a (new) text to a tooltip for Widget_t More...
 
void add_tooltip (Widget_t *w, const char *label)
 add_tooltip - add a tooltip to Widget_t More...
 
Widget_tcreate_tooltip (Widget_t *parent, int width, int height)
 create_tooltip - create a tooltip for a Widget_t More...
 

Function Documentation

◆ add_tooltip()

void add_tooltip ( Widget_t w,
const char *  label 
)

add_tooltip - add a tooltip to Widget_t

Parameters
*w- pointer to the Widget_t request the tooltip
*label- the tooltip text
Returns
void

Definition at line 41 of file xtooltip.c.

41  {
42  Widget_t *wid = create_tooltip(w, 25, 25);
43  wid->label = label;
44  _get_width(wid);
45 }

References _get_width(), create_tooltip(), and Widget_t::label.

◆ create_tooltip()

Widget_t* create_tooltip ( Widget_t parent,
int  width,
int  height 
)

create_tooltip - create a tooltip for a Widget_t

Parameters
*parent- pointer to the Widget_t the tooltip should pop over
width- define the width of the tooltip
height- define the height of the tooltip
Returns
Widget_t* - pointer to the Widget_t button struct

Definition at line 47 of file xtooltip.c.

47  {
48 
49  int x1, y1;
50  Window child;
51  XTranslateCoordinates( parent->app->dpy, parent->widget, DefaultRootWindow(parent->app->dpy), 0, 0, &x1, &y1, &child );
52  Widget_t *wid = create_window(parent->app, DefaultRootWindow(parent->app->dpy), x1+10, y1+10, width, height);
53 
54  XSetWindowAttributes attributes;
55  attributes.override_redirect = True;
56  XChangeWindowAttributes(parent->app->dpy, wid->widget, CWOverrideRedirect, &attributes);
57 
58  Atom window_type = XInternAtom(wid->app->dpy, "_NET_WM_WINDOW_TYPE", False);
59  Atom window_type_tooltip = XInternAtom(wid->app->dpy, "_NET_WM_WINDOW_TYPE_TOOLTIP", False);
60  XChangeProperty(wid->app->dpy, wid->widget, window_type,
61  XA_ATOM, 32, PropModeReplace, (unsigned char *) &window_type_tooltip,1 );
62 
63  Atom window_state = XInternAtom(wid->app->dpy, "_NET_WM_STATE", False);
64  Atom window_state_modal = XInternAtom(wid->app->dpy, "_NET_WM_STATE_MODAL", False);
65  XChangeProperty(wid->app->dpy, wid->widget, window_state,
66  XA_ATOM, 32, PropModeReplace, (unsigned char *) &window_state_modal, 1);
67 
68  XSetTransientForHint(parent->app->dpy,wid->widget,parent->widget);
69  wid->flags &= ~USE_TRANSPARENCY;
71  wid->flags |= IS_TOOLTIP;
72  parent->flags |= HAS_TOOLTIP;
73  wid->scale.gravity = NONE;
74  childlist_add_child(parent->childlist, wid);
75  return wid;
76 }

References _draw_tooltip(), Widget_t::app, Widget_t::childlist, childlist_add_child(), create_window(), Xputty::dpy, Func_t::expose_callback, Widget_t::flags, Widget_t::func, Resize_t::gravity, HAS_TOOLTIP, IS_TOOLTIP, NONE, Widget_t::scale, USE_TRANSPARENCY, and Widget_t::widget.

◆ 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

Parameters
*w- pointer to the Widget_t request the tooltip
*label- the tooltip text
Returns
void

Definition at line 25 of file xtooltip.c.

25  {
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 }

References _get_width(), add_tooltip(), Widget_t::childlist, Childlist_t::childs, Childlist_t::elem, Widget_t::flags, IS_TOOLTIP, and Widget_t::label.

HAS_TOOLTIP
@ HAS_TOOLTIP
Definition: xwidget.h:249
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
NONE
@ NONE
Definition: xwidget.h:173
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
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
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
_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
add_tooltip
void add_tooltip(Widget_t *w, const char *label)
add_tooltip - add a tooltip to Widget_t
Definition: xtooltip.c:41
Widget_t::flags
long long flags
Definition: xwidget.h:324
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
USE_TRANSPARENCY
@ USE_TRANSPARENCY
Definition: xwidget.h:243
Widget_t::widget
Window widget
Definition: xwidget.h:302
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
Widget_t::childlist
Childlist_t * childlist
Definition: xwidget.h:336
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:145
IS_TOOLTIP
@ IS_TOOLTIP
Definition: xwidget.h:241
Childlist_t::elem
int elem
Definition: xchildlist.h:57
Widget_t::func
Func_t func
Definition: xwidget.h:310
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
Widget_t::label
const char * label
Definition: xwidget.h:326
_draw_tooltip
void _draw_tooltip(void *w_, void *user_data)
_draw_tooltip - draw tooltip on expose call
Definition: xtooltip_private.c:32