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