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