25
25
#include "stacking.h"
27
27
#include "screen.h"
29
#include "render/render.h"
30
#include "render/theme.h"
28
#include "obrender/render.h"
29
#include "obrender/theme.h"
32
31
ObPopup *popup_new(void)
34
33
XSetWindowAttributes attrib;
35
ObPopup *self = g_new0(ObPopup, 1);
34
ObPopup *self = g_slice_new0(ObPopup);
37
self->obwin.type = Window_Internal;
36
self->obwin.type = OB_WINDOW_CLASS_INTERNAL;
38
37
self->gravity = NorthWestGravity;
39
38
self->x = self->y = self->textw = self->h = 0;
40
self->a_bg = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg);
39
self->a_bg = RrAppearanceCopy(ob_rr_theme->osd_bg);
41
40
self->a_text = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
42
41
self->iconwm = self->iconhm = 1;
44
43
attrib.override_redirect = True;
45
self->bg = XCreateWindow(ob_display, RootWindow(ob_display, ob_screen),
44
self->bg = XCreateWindow(obt_display, obt_root(ob_screen),
46
45
0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
47
46
InputOutput, RrVisual(ob_rr_inst),
48
47
CWOverrideRedirect, &attrib);
50
self->text = XCreateWindow(ob_display, self->bg,
49
self->text = XCreateWindow(obt_display, self->bg,
51
50
0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
52
51
InputOutput, RrVisual(ob_rr_inst), 0, NULL);
54
XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->obwidth);
55
XSetWindowBorder(ob_display, self->bg,
53
XSetWindowBorderWidth(obt_display, self->bg, ob_rr_theme->obwidth);
54
XSetWindowBorder(obt_display, self->bg,
56
55
RrColorPixel(ob_rr_theme->osd_border_color));
58
XMapWindow(ob_display, self->text);
57
XMapWindow(obt_display, self->text);
60
59
stacking_add(INTERNAL_AS_WINDOW(self));
61
g_hash_table_insert(window_map, &self->bg, self);
60
window_add(&self->bg, INTERNAL_AS_WINDOW(self));
68
67
popup_hide(self); /* make sure it's not showing or is being delayed and
70
XDestroyWindow(ob_display, self->bg);
71
XDestroyWindow(ob_display, self->text);
69
XDestroyWindow(obt_display, self->bg);
70
XDestroyWindow(obt_display, self->text);
72
71
RrAppearanceFree(self->a_bg);
73
72
RrAppearanceFree(self->a_text);
74
g_hash_table_remove(window_map, &self->bg);
73
window_remove(self->bg);
75
74
stacking_remove(self);
75
g_slice_free(ObPopup, self);
144
143
ObPopup *self = data;
146
XMapWindow(ob_display, self->bg);
145
XMapWindow(obt_display, self->bg);
147
146
stacking_raise(INTERNAL_AS_WINDOW(self));
148
147
self->mapped = TRUE;
149
148
self->delay_mapped = FALSE;
149
self->delay_timer = 0;
151
151
return FALSE; /* don't repeat */
154
void popup_delay_show(ObPopup *self, gulong usec, gchar *text)
154
void popup_delay_show(ObPopup *self, gulong msec, gchar *text)
159
159
gint emptyx, emptyy; /* empty space between elements */
160
160
gint textx, texty, textw, texth;
161
161
gint iconx, icony, iconw, iconh;
164
gboolean hasicon = self->hasicon;
164
166
/* when there is no icon and the text is not parent relative, then
165
167
fill the whole dialog with the text appearance, don't use the bg at all
167
if (self->hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
169
if (hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
168
170
RrMargins(self->a_bg, &l, &t, &r, &b);
170
172
l = t = r = b = 0;
192
194
iconx = textx = l + ob_rr_theme->paddingx;
194
196
emptyx = l + r + ob_rr_theme->paddingx * 2;
196
198
iconw = texth * self->iconwm;
197
199
iconh = texth * self->iconhm;
198
200
textx += iconw + ob_rr_theme->paddingx;
200
202
emptyx += ob_rr_theme->paddingx; /* between the icon and text */
203
icony = (h - iconh - emptyy) / 2 + t + ob_rr_theme->paddingy;
204
207
texty = (h - texth - emptyy) / 2 + t + ob_rr_theme->paddingy;
205
icony = (h - iconh - emptyy) / 2 + t + ob_rr_theme->paddingy;
207
209
/* when there is no icon, then fill the whole dialog with the text
212
214
textx = texty = 0;
259
261
x=MAX(MIN(x, area->x+area->width-w),area->x);
260
262
y=MAX(MIN(y, area->y+area->height-h),area->y);
264
264
if (m == screen_num_monitors) {
265
265
RECT_SET(mon, x, y, w, h);
266
266
m = screen_find_monitor(&mon);
271
271
x=MAX(MIN(x, area->x+area->width-w),area->x);
272
272
y=MAX(MIN(y, area->y+area->height-h),area->y);
277
275
/* set the windows/appearances up */
278
XMoveResizeWindow(ob_display, self->bg, x, y, w, h);
276
XMoveResizeWindow(obt_display, self->bg, x, y, w, h);
279
277
/* when there is no icon and the text is not parent relative, then
280
278
fill the whole dialog with the text appearance, don't use the bg at all
282
if (self->hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
280
if (hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL)
283
281
RrPaint(self->a_bg, self->bg, w, h);
286
284
self->a_text->surface.parent = self->a_bg;
287
285
self->a_text->surface.parentx = textx;
288
286
self->a_text->surface.parenty = texty;
289
XMoveResizeWindow(ob_display, self->text, textx, texty, textw, texth);
287
XMoveResizeWindow(obt_display, self->text, textx, texty, textw, texth);
290
288
RrPaint(self->a_text, self->text, textw, texth);
294
292
self->draw_icon(iconx, icony, iconw, iconh, self->draw_icon_data);
296
294
/* do the actual showing */
297
295
if (!self->mapped) {
299
297
/* don't kill previous show timers */
300
298
if (!self->delay_mapped) {
301
ob_main_loop_timeout_add(ob_main_loop, usec,
302
popup_show_timeout, self,
303
g_direct_equal, NULL);
300
g_timeout_add(msec, popup_show_timeout, self);
304
301
self->delay_mapped = TRUE;
317
314
/* kill enter events cause by this unmapping */
318
315
ignore_start = event_start_ignore_all_enters();
320
XUnmapWindow(ob_display, self->bg);
317
XUnmapWindow(obt_display, self->bg);
321
318
self->mapped = FALSE;
323
320
event_end_ignore_all_enters(ignore_start);
324
321
} else if (self->delay_mapped) {
325
ob_main_loop_timeout_remove_data(ob_main_loop, popup_show_timeout, self, FALSE);
322
g_source_remove(self->delay_timer);
323
self->delay_timer = 0;
326
324
self->delay_mapped = FALSE;
334
332
self->a_icon->surface.parent = self->popup->a_bg;
335
333
self->a_icon->surface.parentx = x;
336
334
self->a_icon->surface.parenty = y;
337
XMoveResizeWindow(ob_display, self->icon, x, y, w, h);
335
XMoveResizeWindow(obt_display, self->icon, x, y, w, h);
338
336
RrPaint(self->a_icon, self->icon, w, h);
343
341
ObIconPopup *self;
345
self = g_new0(ObIconPopup, 1);
343
self = g_slice_new0(ObIconPopup);
346
344
self->popup = popup_new();
347
345
self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
348
self->icon = XCreateWindow(ob_display, self->popup->bg,
346
self->icon = XCreateWindow(obt_display, self->popup->bg,
350
348
RrDepth(ob_rr_inst), InputOutput,
351
349
RrVisual(ob_rr_inst), 0, NULL);
352
XMapWindow(ob_display, self->icon);
350
XMapWindow(obt_display, self->icon);
354
352
self->popup->hasicon = TRUE;
355
353
self->popup->draw_icon = icon_popup_draw_icon;
361
359
void icon_popup_free(ObIconPopup *self)
364
XDestroyWindow(ob_display, self->icon);
362
XDestroyWindow(obt_display, self->icon);
365
363
RrAppearanceFree(self->a_icon);
366
364
popup_free(self->popup);
365
g_slice_free(ObIconPopup, self);
371
void icon_popup_delay_show(ObIconPopup *self, gulong usec,
369
void icon_popup_delay_show(ObIconPopup *self, gulong msec,
372
370
gchar *text, RrImage *icon)
487
485
a->surface.parent = self->popup->a_bg;
488
486
a->surface.parentx = x + px;
489
487
a->surface.parenty = y + py;
490
XMoveResizeWindow(ob_display, self->wins[n],
488
XMoveResizeWindow(obt_display, self->wins[n],
491
489
x + px, y + py, eachw, eachh);
492
490
RrPaint(a, self->wins[n], eachw, eachh);
502
500
ObPagerPopup *self;
504
self = g_new(ObPagerPopup, 1);
502
self = g_slice_new(ObPagerPopup);
505
503
self->popup = popup_new();
508
506
self->wins = g_new(Window, self->desks);
509
self->hilight = RrAppearanceCopy(ob_rr_theme->osd_hilite_fg);
510
self->unhilight = RrAppearanceCopy(ob_rr_theme->osd_unhilite_fg);
507
self->hilight = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg);
508
self->unhilight = RrAppearanceCopy(ob_rr_theme->osd_unhilite_bg);
512
510
self->popup->hasicon = TRUE;
513
511
self->popup->draw_icon = pager_popup_draw_icon;
524
522
for (i = 0; i < self->desks; ++i)
525
XDestroyWindow(ob_display, self->wins[i]);
523
XDestroyWindow(obt_display, self->wins[i]);
526
524
g_free(self->wins);
527
525
RrAppearanceFree(self->hilight);
528
526
RrAppearanceFree(self->unhilight);
529
527
popup_free(self->popup);
528
g_slice_free(ObPagerPopup, self);
534
void pager_popup_delay_show(ObPagerPopup *self, gulong usec,
532
void pager_popup_delay_show(ObPagerPopup *self, gulong msec,
535
533
gchar *text, guint desk)
539
537
if (screen_num_desktops < self->desks)
540
538
for (i = screen_num_desktops; i < self->desks; ++i)
541
XDestroyWindow(ob_display, self->wins[i]);
539
XDestroyWindow(obt_display, self->wins[i]);
543
541
if (screen_num_desktops != self->desks)
544
542
self->wins = g_renew(Window, self->wins, screen_num_desktops);
550
548
attr.border_pixel =
551
549
RrColorPixel(ob_rr_theme->osd_border_color);
552
self->wins[i] = XCreateWindow(ob_display, self->popup->bg,
550
self->wins[i] = XCreateWindow(obt_display, self->popup->bg,
553
551
0, 0, 1, 1, ob_rr_theme->obwidth,
554
552
RrDepth(ob_rr_inst), InputOutput,
555
553
RrVisual(ob_rr_inst), CWBorderPixel,
557
XMapWindow(ob_display, self->wins[i]);
555
XMapWindow(obt_display, self->wins[i]);
560
558
self->desks = screen_num_desktops;
561
559
self->curdesk = desk;
563
popup_delay_show(self->popup, usec, text);
561
popup_delay_show(self->popup, msec, text);
566
564
void pager_popup_icon_size_multiplier(ObPagerPopup *self, guint wm, guint hm)