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

Go to the source code of this file.

Functions

void _get_width (Widget_t *w)
 _get_width - get the width of a tooltip text and resize the tooltip widget to match the size More...
 
void _draw_tooltip (void *w_, void *user_data)
 _draw_tooltip - draw tooltip on expose call More...
 

Function Documentation

◆ _draw_tooltip()

void _draw_tooltip ( void *  w_,
void *  user_data 
)

_draw_tooltip - draw tooltip on expose call

Parameters
*w_- the tooltip to draw
*user_data- attached user_data
Returns
void

show label

Definition at line 32 of file xtooltip_private.c.

32  {
33  Widget_t *w = (Widget_t*)w_;
34  if (!w) return;
35  XWindowAttributes attrs;
36  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
37  if (attrs.map_state != IsViewable) return;
38  int width = attrs.width;
39  int height = attrs.height;
41  cairo_paint (w->crb);
42  cairo_text_extents_t extents;
43  /** show label **/
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 }

References Widget_t::app, Resize_t::ascale, Widget_t::crb, Xputty::dpy, get_color_state(), Widget_t::label, Xputty::normal_font, Widget_t::scale, use_bg_color_scheme(), use_text_color_scheme(), and Widget_t::widget.

◆ _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

Parameters
*w- the tooltip Widget_t
Returns
void

Definition at line 25 of file xtooltip_private.c.

25  {
26  cairo_text_extents_t extents;
27  cairo_set_font_size (w->crb, 12);
28  cairo_text_extents(w->crb,w->label , &extents);
29  XResizeWindow (w->app->dpy, w->widget, max(1, (int)extents.width+40), 25);
30 }

References Widget_t::app, Widget_t::crb, Xputty::dpy, Widget_t::label, max, and Widget_t::widget.

use_text_color_scheme
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:199
get_color_state
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:155
Xputty::normal_font
int normal_font
Definition: xputty.h:191
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
use_bg_color_scheme
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:185
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
Resize_t::ascale
float ascale
Definition: xwidget.h:214
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
max
#define max(x, y)
max - set a minimal value (x) as return value
Definition: xputty.h:86
Widget_t::label
const char * label
Definition: xwidget.h:326