1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
#include <glib.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
#include "theme.h"
void widget_init ( widget *widget , const char *name, const char *class_name )
{
widget->name = g_strdup(name);
widget->class_name = g_strdup(class_name);
widget->pad = (Padding){ {0, PW_PX}, {0, PW_PX}, {0, PW_PX}, {0, PW_PX}};
widget->pad = rofi_theme_get_padding (widget->class_name, widget->name, NULL, "padding", widget->pad);
}
void widget_set_state ( widget *widget, const char *state )
{
widget->state = state;
}
int widget_intersect ( const widget *widget, int x, int y )
{
if ( widget == NULL ) {
return FALSE;
}
if ( x >= ( widget->x ) && x < ( widget->x + widget->w ) ) {
if ( y >= ( widget->y ) && y < ( widget->y + widget->h ) ) {
return TRUE;
}
}
return FALSE;
}
void widget_resize ( widget *widget, short w, short h )
{
if ( widget != NULL ) {
if ( widget->resize != NULL ) {
if ( widget->w != w || widget->h != h ) {
widget->resize ( widget, w, h );
}
}
else {
widget->w = w;
widget->h = h;
}
}
}
void widget_move ( widget *widget, short x, short y )
{
if ( widget != NULL ) {
widget->x = x;
widget->y = y;
}
}
gboolean widget_enabled ( widget *widget )
{
if ( widget != NULL ) {
return widget->enabled;
}
return FALSE;
}
void widget_enable ( widget *widget )
{
if ( widget && !widget->enabled ) {
widget->enabled = TRUE;
widget_update ( widget );
widget_update ( widget->parent );
}
}
void widget_disable ( widget *widget )
{
if ( widget && widget->enabled ) {
widget->enabled = FALSE;
widget_update ( widget );
widget_update ( widget->parent );
}
}
void widget_draw ( widget *widget, cairo_t *d )
{
// Check if enabled and if draw is implemented.
if ( widget && widget->enabled && widget->draw ) {
// Store current state.
cairo_save ( d );
// Define a clipmask so we won't draw outside out widget.
cairo_rectangle ( d, widget->x, widget->y, widget->w, widget->h );
cairo_clip ( d );
rofi_theme_get_color ( widget->class_name, widget->name, widget->state, "background", d );
cairo_paint( d ) ;
// Set new x/y possition.
cairo_translate ( d, widget->x, widget->y );
widget->draw ( widget, d );
widget->need_redraw = FALSE;
cairo_restore ( d );
}
}
void widget_free ( widget *wid )
{
if ( wid ) {
if ( wid->name ) {
g_free ( wid->name );
}
if ( wid->class_name ) {
g_free( wid->class_name );
}
if ( wid->free ) {
wid->free ( wid );
}
}
}
int widget_get_height ( widget *widget )
{
if ( widget ) {
if ( widget->get_height ) {
return widget->get_height ( widget );
}
return widget->h;
}
return 0;
}
int widget_get_width ( widget *widget )
{
if ( widget ) {
if ( widget->get_width ) {
return widget->get_width ( widget );
}
return widget->w;
}
return 0;
}
int widget_get_x_pos ( widget *widget )
{
if ( widget ) {
return widget->x;
}
return 0;
}
int widget_get_y_pos ( widget *widget )
{
if ( widget ) {
return widget->y;
}
return 0;
}
void widget_update ( widget *widget )
{
// When (desired )size of widget changes.
if ( widget ) {
if ( widget->update ) {
widget->update ( widget );
}
}
}
void widget_queue_redraw ( widget *wid )
{
if ( wid ) {
widget *iter = wid;
// Find toplevel widget.
while ( iter->parent != NULL ) {
iter->need_redraw = TRUE;
iter = iter->parent;
}
iter->need_redraw = TRUE;
}
}
gboolean widget_need_redraw ( widget *wid )
{
if ( wid && wid->enabled ) {
return wid->need_redraw;
}
return FALSE;
}
gboolean widget_clicked ( widget *wid, xcb_button_press_event_t *xbe )
{
if ( wid && wid->clicked ) {
return wid->clicked ( wid, xbe, wid->clicked_cb_data );
}
return FALSE;
}
void widget_set_clicked_handler ( widget *wid, widget_clicked_cb cb, void *udata )
{
if ( wid ) {
wid->clicked = cb;
wid->clicked_cb_data = udata;
}
}
gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
{
if ( wid && wid->motion_notify ) {
wid->motion_notify ( wid, xme );
}
return FALSE;
}
void widget_set_name ( widget *wid, const char *name )
{
if ( wid->name ) {
g_free(wid);
}
wid->name = g_strdup ( name );
}
// External
double textbox_get_estimated_char_width ( void );
int widget_padding_get_left ( const widget *wid )
{
if ( wid->pad.left.type == PW_EM ){
return wid->pad.left.distance*textbox_get_estimated_char_width();
}
return wid->pad.left.distance;
}
int widget_padding_get_right ( const widget *wid )
{
if ( wid->pad.right.type == PW_EM ){
return wid->pad.right.distance*textbox_get_estimated_char_width();
}
return wid->pad.right.distance;
}
int widget_padding_get_top ( const widget *wid )
{
if ( wid->pad.top.
|