]> Dogcows Code - chaz/openbox/blob - openbox/menuframe.c
make the default screen-edge resistance 20 (double what it is for windows)
[chaz/openbox] / openbox / menuframe.c
1 #include "menuframe.h"
2 #include "client.h"
3 #include "menu.h"
4 #include "screen.h"
5 #include "grab.h"
6 #include "openbox.h"
7 #include "render/theme.h"
8
9 #define PADDING 2
10 #define SEPARATOR_HEIGHT 3
11
12 #define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
13 LeaveWindowMask)
14 #define TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
15 #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
16 ButtonPressMask | ButtonReleaseMask)
17
18 GList *menu_frame_visible;
19
20 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
21 ObMenuFrame *frame);
22 static void menu_entry_frame_free(ObMenuEntryFrame *self);
23 static void menu_frame_render(ObMenuFrame *self);
24 static void menu_frame_update(ObMenuFrame *self);
25
26 static Window createWindow(Window parent, unsigned long mask,
27 XSetWindowAttributes *attrib)
28 {
29 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
30 RrDepth(ob_rr_inst), InputOutput,
31 RrVisual(ob_rr_inst), mask, attrib);
32
33 }
34
35 ObMenuFrame* menu_frame_new(ObMenu *menu, ObClient *client)
36 {
37 ObMenuFrame *self;
38 XSetWindowAttributes attr;
39
40 self = g_new0(ObMenuFrame, 1);
41 self->type = Window_Menu;
42 self->menu = menu;
43 self->selected = NULL;
44 self->show_title = TRUE;
45 self->client = client;
46
47 attr.event_mask = FRAME_EVENTMASK;
48 self->window = createWindow(RootWindow(ob_display, ob_screen),
49 CWEventMask, &attr);
50 attr.event_mask = TITLE_EVENTMASK;
51 self->title = createWindow(self->window, CWEventMask, &attr);
52 self->items = createWindow(self->window, 0, NULL);
53
54 XMapWindow(ob_display, self->items);
55
56 self->a_title = RrAppearanceCopy(ob_rr_theme->a_menu_title);
57 self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);
58
59 stacking_add(MENU_AS_WINDOW(self));
60
61 return self;
62 }
63
64 void menu_frame_free(ObMenuFrame *self)
65 {
66 if (self) {
67 while (self->entries) {
68 menu_entry_frame_free(self->entries->data);
69 self->entries = g_list_delete_link(self->entries, self->entries);
70 }
71
72 stacking_remove(MENU_AS_WINDOW(self));
73
74 XDestroyWindow(ob_display, self->items);
75 XDestroyWindow(ob_display, self->title);
76 XDestroyWindow(ob_display, self->window);
77
78 RrAppearanceFree(self->a_items);
79 RrAppearanceFree(self->a_title);
80
81 g_free(self);
82 }
83 }
84
85 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
86 ObMenuFrame *frame)
87 {
88 ObMenuEntryFrame *self;
89 XSetWindowAttributes attr;
90
91 self = g_new0(ObMenuEntryFrame, 1);
92 self->entry = entry;
93 self->frame = frame;
94
95 attr.event_mask = ENTRY_EVENTMASK;
96 self->window = createWindow(self->frame->items, CWEventMask, &attr);
97 self->text = createWindow(self->window, 0, NULL);
98 if (entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR) {
99 self->icon = createWindow(self->window, 0, NULL);
100 self->bullet = createWindow(self->window, 0, NULL);
101 }
102
103 XMapWindow(ob_display, self->window);
104 XMapWindow(ob_display, self->text);
105
106 self->a_normal = RrAppearanceCopy(ob_rr_theme->a_menu_normal);
107 self->a_disabled = RrAppearanceCopy(ob_rr_theme->a_menu_disabled);
108 self->a_selected = RrAppearanceCopy(ob_rr_theme->a_menu_selected);
109
110 if (entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) {
111 self->a_separator = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
112 self->a_separator->texture[0].type = RR_TEXTURE_LINE_ART;
113 } else {
114 self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
115 self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
116 self->a_mask = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
117 self->a_mask->texture[0].type = RR_TEXTURE_MASK;
118 self->a_bullet_normal =
119 RrAppearanceCopy(ob_rr_theme->a_menu_bullet_normal);
120 self->a_bullet_selected =
121 RrAppearanceCopy(ob_rr_theme->a_menu_bullet_selected);
122 }
123
124 self->a_text_normal =
125 RrAppearanceCopy(ob_rr_theme->a_menu_text_normal);
126 self->a_text_disabled =
127 RrAppearanceCopy(ob_rr_theme->a_menu_text_disabled);
128 self->a_text_selected =
129 RrAppearanceCopy(ob_rr_theme->a_menu_text_selected);
130
131 return self;
132 }
133
134 static void menu_entry_frame_free(ObMenuEntryFrame *self)
135 {
136 if (self) {
137 XDestroyWindow(ob_display, self->text);
138 XDestroyWindow(ob_display, self->window);
139 if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR) {
140 XDestroyWindow(ob_display, self->icon);
141 XDestroyWindow(ob_display, self->bullet);
142 }
143
144 RrAppearanceFree(self->a_normal);
145 RrAppearanceFree(self->a_disabled);
146 RrAppearanceFree(self->a_selected);
147
148 RrAppearanceFree(self->a_separator);
149 RrAppearanceFree(self->a_icon);
150 RrAppearanceFree(self->a_mask);
151 RrAppearanceFree(self->a_text_normal);
152 RrAppearanceFree(self->a_text_disabled);
153 RrAppearanceFree(self->a_text_selected);
154 RrAppearanceFree(self->a_bullet_normal);
155 RrAppearanceFree(self->a_bullet_selected);
156
157 g_free(self);
158 }
159 }
160
161 void menu_frame_move(ObMenuFrame *self, gint x, gint y)
162 {
163 RECT_SET_POINT(self->area, x, y);
164 XMoveWindow(ob_display, self->window, self->area.x, self->area.y);
165 }
166
167 void menu_frame_move_on_screen(ObMenuFrame *self)
168 {
169 Rect *a;
170 guint i;
171 gint dx = 0, dy = 0;
172
173 for (i = 0; i < screen_num_monitors; ++i) {
174 a = screen_physical_area_monitor(i);
175 if (RECT_INTERSECTS_RECT(*a, self->area))
176 break;
177 }
178 if (a) a = screen_physical_area_monitor(0);
179
180 dx = MIN(0, (a->x + a->width) - (self->area.x + self->area.width));
181 dy = MIN(0, (a->y + a->height) - (self->area.y + self->area.height));
182 if (!dx) dx = MAX(0, a->x - self->area.x);
183 if (!dy) dy = MAX(0, a->y - self->area.y);
184
185 if (dx || dy) {
186 ObMenuFrame *f;
187
188 for (f = self; f; f = f->parent)
189 menu_frame_move(f, f->area.x + dx, f->area.y + dy);
190 for (f = self->child; f; f = f->child)
191 menu_frame_move(f, f->area.x + dx, f->area.y + dy);
192 XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy);
193 }
194 }
195
196 static void menu_entry_frame_render(ObMenuEntryFrame *self)
197 {
198 RrAppearance *item_a, *text_a;
199 gint th; /* temp */
200 ObMenu *sub;
201
202 item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
203 !self->entry->data.normal.enabled) ?
204 self->a_disabled :
205 (self == self->frame->selected ?
206 self->a_selected :
207 self->a_normal));
208 switch (self->entry->type) {
209 case OB_MENU_ENTRY_TYPE_NORMAL:
210 case OB_MENU_ENTRY_TYPE_SUBMENU:
211 th = self->frame->item_h;
212 break;
213 case OB_MENU_ENTRY_TYPE_SEPARATOR:
214 th = SEPARATOR_HEIGHT + 2*PADDING;
215 break;
216 }
217 RECT_SET_SIZE(self->area, self->frame->inner_w, th);
218 XResizeWindow(ob_display, self->window,
219 self->area.width, self->area.height);
220 item_a->surface.parent = self->frame->a_items;
221 item_a->surface.parentx = self->area.x;
222 item_a->surface.parenty = self->area.y;
223 RrPaint(item_a, self->window, self->area.width, self->area.height);
224
225 text_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
226 !self->entry->data.normal.enabled) ?
227 self->a_text_disabled :
228 (self == self->frame->selected ?
229 self->a_text_selected :
230 self->a_text_normal));
231 switch (self->entry->type) {
232 case OB_MENU_ENTRY_TYPE_NORMAL:
233 text_a->texture[0].data.text.string = self->entry->data.normal.label;
234 break;
235 case OB_MENU_ENTRY_TYPE_SUBMENU:
236 sub = self->entry->data.submenu.submenu;
237 text_a->texture[0].data.text.string = sub ? sub->title : "";
238 break;
239 case OB_MENU_ENTRY_TYPE_SEPARATOR:
240 break;
241 }
242
243 switch (self->entry->type) {
244 case OB_MENU_ENTRY_TYPE_NORMAL:
245 XMoveResizeWindow(ob_display, self->text,
246 self->frame->text_x, PADDING,
247 self->frame->text_w,
248 self->frame->item_h - 2*PADDING);
249 text_a->surface.parent = item_a;
250 text_a->surface.parentx = self->frame->text_x;
251 text_a->surface.parenty = PADDING;
252 RrPaint(text_a, self->text, self->frame->text_w,
253 self->frame->item_h - 2*PADDING);
254 break;
255 case OB_MENU_ENTRY_TYPE_SUBMENU:
256 XMoveResizeWindow(ob_display, self->text,
257 self->frame->text_x, PADDING,
258 self->frame->text_w - self->frame->item_h,
259 self->frame->item_h - 2*PADDING);
260 text_a->surface.parent = item_a;
261 text_a->surface.parentx = self->frame->text_x;
262 text_a->surface.parenty = PADDING;
263 RrPaint(text_a, self->text, self->frame->text_w - self->frame->item_h,
264 self->frame->item_h - 2*PADDING);
265 break;
266 case OB_MENU_ENTRY_TYPE_SEPARATOR:
267 XMoveResizeWindow(ob_display, self->text, PADDING, PADDING,
268 self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
269 self->a_separator->surface.parent = item_a;
270 self->a_separator->surface.parentx = PADDING;
271 self->a_separator->surface.parenty = PADDING;
272 self->a_separator->texture[0].data.lineart.color =
273 text_a->texture[0].data.text.color;
274 self->a_separator->texture[0].data.lineart.x1 = 2*PADDING;
275 self->a_separator->texture[0].data.lineart.y1 = SEPARATOR_HEIGHT / 2;
276 self->a_separator->texture[0].data.lineart.x2 =
277 self->area.width - 4*PADDING;
278 self->a_separator->texture[0].data.lineart.y2 = SEPARATOR_HEIGHT / 2;
279 RrPaint(self->a_separator, self->text,
280 self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
281 break;
282 }
283
284 if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR &&
285 self->entry->data.normal.icon_data)
286 {
287 XMoveResizeWindow(ob_display, self->icon, PADDING, 0,
288 self->frame->item_h,
289 self->frame->item_h);
290 self->a_icon->texture[0].data.rgba.width =
291 self->entry->data.normal.icon_width;
292 self->a_icon->texture[0].data.rgba.height =
293 self->entry->data.normal.icon_height;
294 self->a_icon->texture[0].data.rgba.data =
295 self->entry->data.normal.icon_data;
296 self->a_icon->surface.parent = item_a;
297 self->a_icon->surface.parentx = PADDING;
298 self->a_icon->surface.parenty = 0;
299 RrPaint(self->a_icon, self->icon,
300 self->frame->item_h, self->frame->item_h);
301 XMapWindow(ob_display, self->icon);
302 } else if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR &&
303 self->entry->data.normal.mask)
304 {
305 RrColor *c;
306
307 XMoveResizeWindow(ob_display, self->icon, PADDING, 0,
308 self->frame->item_h,
309 self->frame->item_h);
310 self->a_mask->texture[0].data.mask.mask =
311 self->entry->data.normal.mask;
312
313 c = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
314 !self->entry->data.normal.enabled) ?
315 self->entry->data.normal.mask_disabled_color :
316 (self == self->frame->selected ?
317 self->entry->data.normal.mask_selected_color :
318 self->entry->data.normal.mask_normal_color));
319 self->a_mask->texture[0].data.mask.color = c;
320
321 self->a_mask->surface.parent = item_a;
322 self->a_mask->surface.parentx = PADDING;
323 self->a_mask->surface.parenty = 0;
324 RrPaint(self->a_mask, self->icon,
325 self->frame->item_h, self->frame->item_h);
326 XMapWindow(ob_display, self->icon);
327 } else
328 XUnmapWindow(ob_display, self->icon);
329
330 if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
331 RrAppearance *bullet_a;
332 XMoveResizeWindow(ob_display, self->bullet,
333 self->frame->text_x + self->frame->text_w
334 - self->frame->item_h + PADDING, PADDING,
335 self->frame->item_h - 2*PADDING,
336 self->frame->item_h - 2*PADDING);
337 bullet_a = (self == self->frame->selected ?
338 self->a_bullet_selected :
339 self->a_bullet_normal);
340 bullet_a->surface.parent = item_a;
341 bullet_a->surface.parentx =
342 self->frame->text_x + self->frame->text_w - self->frame->item_h
343 + PADDING;
344 bullet_a->surface.parenty = PADDING;
345 RrPaint(bullet_a, self->bullet,
346 self->frame->item_h - 2*PADDING,
347 self->frame->item_h - 2*PADDING);
348 XMapWindow(ob_display, self->bullet);
349 } else
350 XUnmapWindow(ob_display, self->bullet);
351 }
352
353 static void menu_frame_render(ObMenuFrame *self)
354 {
355 gint w = 0, h = 0;
356 gint allitems_h = 0;
357 gint tw, th; /* temps */
358 GList *it;
359 gboolean has_icon = FALSE;
360 ObMenu *sub;
361
362 XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->bwidth);
363 XSetWindowBorder(ob_display, self->window,
364 RrColorPixel(ob_rr_theme->b_color));
365
366 if (!self->parent && self->show_title) {
367 XMoveWindow(ob_display, self->title,
368 -ob_rr_theme->bwidth, h - ob_rr_theme->bwidth);
369
370 self->a_title->texture[0].data.text.string = self->menu->title;
371 RrMinsize(self->a_title, &tw, &th);
372 tw += 2*PADDING;
373 th += 2*PADDING;
374 w = MAX(w, tw);
375 h += (self->title_h = th + ob_rr_theme->bwidth);
376
377 XSetWindowBorderWidth(ob_display, self->title, ob_rr_theme->bwidth);
378 XSetWindowBorder(ob_display, self->title,
379 RrColorPixel(ob_rr_theme->b_color));
380 }
381
382 XMoveWindow(ob_display, self->items, 0, h);
383
384 if (self->entries) {
385 ObMenuEntryFrame *e = self->entries->data;
386 e->a_text_normal->texture[0].data.text.string = "";
387 RrMinsize(e->a_text_normal, &tw, &th);
388 tw += 2*PADDING;
389 th += 2*PADDING;
390 self->item_h = th;
391 } else
392 self->item_h = 0;
393
394 for (it = self->entries; it; it = g_list_next(it)) {
395 RrAppearance *text_a;
396 ObMenuEntryFrame *e = it->data;
397
398 RECT_SET_POINT(e->area, 0, allitems_h);
399 XMoveWindow(ob_display, e->window, 0, e->area.y);
400
401 text_a = ((e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
402 !e->entry->data.normal.enabled) ?
403 e->a_text_disabled :
404 (e == self->selected ?
405 e->a_text_selected :
406 e->a_text_normal));
407 switch (e->entry->type) {
408 case OB_MENU_ENTRY_TYPE_NORMAL:
409 text_a->texture[0].data.text.string = e->entry->data.normal.label;
410 RrMinsize(text_a, &tw, &th);
411
412 if (e->entry->data.normal.icon_data ||
413 e->entry->data.normal.mask)
414 has_icon = TRUE;
415 break;
416 case OB_MENU_ENTRY_TYPE_SUBMENU:
417 sub = e->entry->data.submenu.submenu;
418 text_a->texture[0].data.text.string = sub ? sub->title : "";
419 RrMinsize(text_a, &tw, &th);
420
421 if (e->entry->data.normal.icon_data ||
422 e->entry->data.normal.mask)
423 has_icon = TRUE;
424
425 tw += self->item_h - PADDING;
426 break;
427 case OB_MENU_ENTRY_TYPE_SEPARATOR:
428 tw = 0;
429 th = SEPARATOR_HEIGHT;
430 break;
431 }
432 tw += 2*PADDING;
433 th += 2*PADDING;
434 w = MAX(w, tw);
435 h += th;
436 allitems_h += th;
437 }
438
439 self->text_x = PADDING;
440 self->text_w = w;
441
442 if (self->entries) {
443 if (has_icon) {
444 w += self->item_h + PADDING;
445 self->text_x += self->item_h + PADDING;
446 }
447 }
448
449 if (!w) w = 10;
450 if (!allitems_h) {
451 allitems_h = 3;
452 h += 3;
453 }
454
455 XResizeWindow(ob_display, self->window, w, h);
456 XResizeWindow(ob_display, self->items, w, allitems_h);
457
458 self->inner_w = w;
459
460 if (!self->parent && self->show_title) {
461 XResizeWindow(ob_display, self->title,
462 w, self->title_h - ob_rr_theme->bwidth);
463 RrPaint(self->a_title, self->title,
464 w, self->title_h - ob_rr_theme->bwidth);
465 XMapWindow(ob_display, self->title);
466 } else
467 XUnmapWindow(ob_display, self->title);
468
469 RrPaint(self->a_items, self->items, w, allitems_h);
470
471 for (it = self->entries; it; it = g_list_next(it))
472 menu_entry_frame_render(it->data);
473
474 w += ob_rr_theme->bwidth * 2;
475 h += ob_rr_theme->bwidth * 2;
476
477 RECT_SET_SIZE(self->area, w, h);
478 }
479
480 static void menu_frame_update(ObMenuFrame *self)
481 {
482 GList *mit, *fit;
483
484 menu_pipe_execute(self->menu);
485 menu_find_submenus(self->menu);
486
487 self->selected = NULL;
488
489 for (mit = self->menu->entries, fit = self->entries; mit && fit;
490 mit = g_list_next(mit), fit = g_list_next(fit))
491 {
492 ObMenuEntryFrame *f = fit->data;
493 f->entry = mit->data;
494 }
495
496 while (mit) {
497 ObMenuEntryFrame *e = menu_entry_frame_new(mit->data, self);
498 self->entries = g_list_append(self->entries, e);
499 mit = g_list_next(mit);
500 }
501
502 while (fit) {
503 GList *n = g_list_next(fit);
504 menu_entry_frame_free(fit->data);
505 self->entries = g_list_delete_link(self->entries, fit);
506 fit = n;
507 }
508
509 menu_frame_render(self);
510 }
511
512 void menu_frame_show(ObMenuFrame *self, ObMenuFrame *parent)
513 {
514 GList *it;
515
516 if (g_list_find(menu_frame_visible, self))
517 return;
518
519 if (parent) {
520 if (parent->child)
521 menu_frame_hide(parent->child);
522 parent->child = self;
523 }
524 self->parent = parent;
525
526 if (menu_frame_visible == NULL) {
527 /* no menus shown yet */
528 grab_pointer(TRUE, None);
529 grab_keyboard(TRUE);
530 }
531
532 /* determine if the underlying menu is already visible */
533 for (it = menu_frame_visible; it; it = g_list_next(it)) {
534 ObMenuFrame *f = it->data;
535 if (f->menu == self->menu)
536 break;
537 }
538 if (!it) {
539 if (self->menu->update_func)
540 self->menu->update_func(self, self->menu->data);
541 }
542
543 menu_frame_visible = g_list_prepend(menu_frame_visible, self);
544 menu_frame_update(self);
545
546 menu_frame_move_on_screen(self);
547
548 XMapWindow(ob_display, self->window);
549 }
550
551 void menu_frame_hide(ObMenuFrame *self)
552 {
553 GList *it = g_list_find(menu_frame_visible, self);
554
555 if (!it)
556 return;
557
558 if (self->child)
559 menu_frame_hide(self->child);
560
561 if (self->parent)
562 self->parent->child = NULL;
563 self->parent = NULL;
564
565 menu_frame_visible = g_list_delete_link(menu_frame_visible, it);
566
567 if (menu_frame_visible == NULL) {
568 /* last menu shown */
569 grab_pointer(FALSE, None);
570 grab_keyboard(FALSE);
571 }
572
573 XUnmapWindow(ob_display, self->window);
574
575 menu_frame_free(self);
576 }
577
578 void menu_frame_hide_all()
579 {
580 GList *it = g_list_last(menu_frame_visible);
581 if (it)
582 menu_frame_hide(it->data);
583 }
584
585 void menu_frame_hide_all_client(ObClient *client)
586 {
587 GList *it = g_list_last(menu_frame_visible);
588 if (it) {
589 ObMenuFrame *f = it->data;
590 if (f->client == client)
591 menu_frame_hide(f);
592 }
593 }
594
595
596 ObMenuFrame* menu_frame_under(gint x, gint y)
597 {
598 ObMenuFrame *ret = NULL;
599 GList *it;
600
601 for (it = menu_frame_visible; it; it = g_list_next(it)) {
602 ObMenuFrame *f = it->data;
603
604 if (RECT_CONTAINS(f->area, x, y)) {
605 ret = f;
606 break;
607 }
608 }
609 return ret;
610 }
611
612 ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y)
613 {
614 ObMenuFrame *frame;
615 ObMenuEntryFrame *ret = NULL;
616 GList *it;
617
618 if ((frame = menu_frame_under(x, y))) {
619 x -= ob_rr_theme->bwidth + frame->area.x;
620 y -= frame->title_h + ob_rr_theme->bwidth + frame->area.y;
621
622 for (it = frame->entries; it; it = g_list_next(it)) {
623 ObMenuEntryFrame *e = it->data;
624
625 if (RECT_CONTAINS(e->area, x, y)) {
626 ret = e;
627 break;
628 }
629 }
630 }
631 return ret;
632 }
633
634 void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry)
635 {
636 ObMenuEntryFrame *old = self->selected;
637 ObMenuFrame *oldchild = self->child;
638
639 if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR)
640 entry = old;
641
642 if (old == entry) return;
643
644 self->selected = entry;
645
646 if (old)
647 menu_entry_frame_render(old);
648 if (oldchild)
649 menu_frame_hide(oldchild);
650
651 if (self->selected) {
652 menu_entry_frame_render(self->selected);
653
654 if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
655 menu_entry_frame_show_submenu(self->selected);
656 }
657 }
658
659 void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
660 {
661 ObMenuFrame *f;
662
663 if (!self->entry->data.submenu.submenu) return;
664
665 f = menu_frame_new(self->entry->data.submenu.submenu,
666 self->frame->client);
667 menu_frame_move(f,
668 self->frame->area.x + self->frame->area.width
669 - ob_rr_theme->menu_overlap - ob_rr_theme->bwidth,
670 self->frame->area.y + self->frame->title_h +
671 self->area.y + ob_rr_theme->menu_overlap);
672 menu_frame_show(f, self->frame);
673 }
674
675 void menu_entry_frame_execute(ObMenuEntryFrame *self, gboolean hide)
676 {
677 if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
678 self->entry->data.normal.enabled)
679 {
680 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
681 gets freed */
682 ObMenuEntry *entry = self->entry;
683 ObMenuExecuteFunc func = self->frame->menu->execute_func;
684 gpointer data = self->frame->menu->data;
685 GSList *acts = self->entry->data.normal.actions;
686 ObClient *client = self->frame->client;
687
688 /* release grabs before executing the shit */
689 if (hide)
690 menu_frame_hide_all();
691
692 if (func)
693 func(entry, data);
694 else {
695 GSList *it;
696
697 for (it = acts; it; it = g_slist_next(it))
698 {
699 ObAction *act = it->data;
700 act->data.any.c = client;
701
702 if (act->func == action_moveresize)
703 screen_pointer_pos(&act->data.moveresize.x,
704 &act->data.moveresize.y);
705
706 if (!(act->func == action_cycle_windows ||
707 act->func == action_desktop_dir ||
708 act->func == action_send_to_desktop_dir ||
709 act->func == action_showmenu))
710 {
711 act->func(&act->data);
712 }
713 }
714 }
715 }
716 }
717
718 void menu_frame_select_previous(ObMenuFrame *self)
719 {
720 GList *it = NULL, *start;
721
722 if (self->entries) {
723 start = it = g_list_find(self->entries, self->selected);
724 while (TRUE) {
725 ObMenuEntryFrame *e;
726
727 it = it ? g_list_previous(it) : g_list_last(self->entries);
728 if (it == start)
729 break;
730
731 if (it) {
732 e = it->data;
733 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
734 break;
735 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
736 e->entry->data.normal.enabled)
737 break;
738 }
739 }
740 }
741 menu_frame_select(self, it ? it->data : NULL);
742 }
743
744 void menu_frame_select_next(ObMenuFrame *self)
745 {
746 GList *it = NULL, *start;
747
748 if (self->entries) {
749 start = it = g_list_find(self->entries, self->selected);
750 while (TRUE) {
751 ObMenuEntryFrame *e;
752
753 it = it ? g_list_next(it) : self->entries;
754 if (it == start)
755 break;
756
757 if (it) {
758 e = it->data;
759 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
760 break;
761 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
762 e->entry->data.normal.enabled)
763 break;
764 }
765 }
766 }
767 menu_frame_select(self, it ? it->data : NULL);
768 }
This page took 0.072357 seconds and 4 git commands to generate.