1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 menuframe.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
20 #include "menuframe.h"
28 #include "render/theme.h"
31 #define SEPARATOR_HEIGHT 3
32 #define MAX_MENU_WIDTH 400
34 #define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
36 #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
37 ButtonPressMask | ButtonReleaseMask)
39 GList *menu_frame_visible;
41 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
43 static void menu_entry_frame_free(ObMenuEntryFrame *self);
44 static void menu_frame_render(ObMenuFrame *self);
45 static void menu_frame_update(ObMenuFrame *self);
46 static gboolean menu_entry_frame_submenu_timeout(gpointer data);
48 static Window createWindow(Window parent, gulong mask,
49 XSetWindowAttributes *attrib)
51 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
52 RrDepth(ob_rr_inst), InputOutput,
53 RrVisual(ob_rr_inst), mask, attrib);
56 GHashTable *menu_frame_map;
58 void menu_frame_startup(gboolean reconfig)
62 menu_frame_map = g_hash_table_new(g_int_hash, g_int_equal);
65 void menu_frame_shutdown(gboolean reconfig)
69 g_hash_table_destroy(menu_frame_map);
72 ObMenuFrame* menu_frame_new(ObMenu *menu, ObClient *client)
75 XSetWindowAttributes attr;
77 self = g_new0(ObMenuFrame, 1);
78 self->type = Window_Menu;
80 self->selected = NULL;
81 self->client = client;
82 self->direction_right = TRUE;
84 attr.event_mask = FRAME_EVENTMASK;
85 self->window = createWindow(RootWindow(ob_display, ob_screen),
88 self->a_title = RrAppearanceCopy(ob_rr_theme->a_menu_title);
89 self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);
91 stacking_add(MENU_AS_WINDOW(self));
96 void menu_frame_free(ObMenuFrame *self)
99 while (self->entries) {
100 menu_entry_frame_free(self->entries->data);
101 self->entries = g_list_delete_link(self->entries, self->entries);
104 stacking_remove(MENU_AS_WINDOW(self));
106 XDestroyWindow(ob_display, self->window);
108 RrAppearanceFree(self->a_items);
109 RrAppearanceFree(self->a_title);
115 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
118 ObMenuEntryFrame *self;
119 XSetWindowAttributes attr;
121 self = g_new0(ObMenuEntryFrame, 1);
125 attr.event_mask = ENTRY_EVENTMASK;
126 self->window = createWindow(self->frame->window, CWEventMask, &attr);
127 self->text = createWindow(self->window, 0, NULL);
128 g_hash_table_insert(menu_frame_map, &self->window, self);
129 g_hash_table_insert(menu_frame_map, &self->text, self);
130 if (entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
131 self->icon = createWindow(self->window, 0, NULL);
132 g_hash_table_insert(menu_frame_map, &self->icon, self);
134 if (entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
135 self->bullet = createWindow(self->window, 0, NULL);
136 g_hash_table_insert(menu_frame_map, &self->bullet, self);
139 XMapWindow(ob_display, self->window);
140 XMapWindow(ob_display, self->text);
142 self->a_normal = RrAppearanceCopy(ob_rr_theme->a_menu_normal);
143 self->a_disabled = RrAppearanceCopy(ob_rr_theme->a_menu_disabled);
144 self->a_selected = RrAppearanceCopy(ob_rr_theme->a_menu_selected);
146 if (entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) {
147 self->a_separator = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
148 self->a_separator->texture[0].type = RR_TEXTURE_LINE_ART;
150 self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
151 self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
152 self->a_mask = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
153 self->a_mask->texture[0].type = RR_TEXTURE_MASK;
154 self->a_bullet_normal =
155 RrAppearanceCopy(ob_rr_theme->a_menu_bullet_normal);
156 self->a_bullet_selected =
157 RrAppearanceCopy(ob_rr_theme->a_menu_bullet_selected);
160 self->a_text_normal =
161 RrAppearanceCopy(ob_rr_theme->a_menu_text_normal);
162 self->a_text_disabled =
163 RrAppearanceCopy(ob_rr_theme->a_menu_text_disabled);
164 self->a_text_selected =
165 RrAppearanceCopy(ob_rr_theme->a_menu_text_selected);
170 static void menu_entry_frame_free(ObMenuEntryFrame *self)
173 XDestroyWindow(ob_display, self->text);
174 XDestroyWindow(ob_display, self->window);
175 g_hash_table_insert(menu_frame_map, &self->text, self);
176 g_hash_table_insert(menu_frame_map, &self->window, self);
177 if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
178 XDestroyWindow(ob_display, self->icon);
179 g_hash_table_insert(menu_frame_map, &self->icon, self);
181 if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
182 XDestroyWindow(ob_display, self->bullet);
183 g_hash_table_insert(menu_frame_map, &self->bullet, self);
186 RrAppearanceFree(self->a_normal);
187 RrAppearanceFree(self->a_disabled);
188 RrAppearanceFree(self->a_selected);
190 RrAppearanceFree(self->a_separator);
191 RrAppearanceFree(self->a_icon);
192 RrAppearanceFree(self->a_mask);
193 RrAppearanceFree(self->a_text_normal);
194 RrAppearanceFree(self->a_text_disabled);
195 RrAppearanceFree(self->a_text_selected);
196 RrAppearanceFree(self->a_bullet_normal);
197 RrAppearanceFree(self->a_bullet_selected);
203 void menu_frame_move(ObMenuFrame *self, gint x, gint y)
205 RECT_SET_POINT(self->area, x, y);
206 XMoveWindow(ob_display, self->window, self->area.x, self->area.y);
209 void menu_frame_place_topmenu(ObMenuFrame *self, gint x, gint y)
211 if (self->client && x < 0 && y < 0) {
212 x = self->client->frame->area.x + self->client->frame->size.left;
213 y = self->client->frame->area.y + self->client->frame->size.top;
215 if (config_menu_middle)
216 y -= self->area.height / 2;
218 menu_frame_move(self, x, y);
221 void menu_frame_place_submenu(ObMenuFrame *self)
227 overlap = ob_rr_theme->menu_overlap;
228 bwidth = ob_rr_theme->mbwidth;
230 if (self->direction_right)
231 x = self->parent->area.x + self->parent->area.width - overlap - bwidth;
233 x = self->parent->area.x - self->area.width + overlap + bwidth;
235 y = self->parent->area.y + self->parent_entry->area.y;
236 if (config_menu_middle)
237 y -= (self->area.height - (bwidth * 2) - self->item_h) / 2;
241 menu_frame_move(self, x, y);
244 void menu_frame_move_on_screen(ObMenuFrame *self, gint *dx, gint *dy)
251 a = screen_physical_area_monitor(self->monitor);
253 half = g_list_length(self->entries) / 2;
254 pos = g_list_index(self->entries, self->selected);
256 /* if in the bottom half then check this stuff first, will keep the bottom
257 edge of the menu visible */
259 *dx = MAX(*dx, a->x - self->area.x);
260 *dy = MAX(*dy, a->y - self->area.y);
262 *dx = MIN(*dx, (a->x + a->width) - (self->area.x + self->area.width));
263 *dy = MIN(*dy, (a->y + a->height) - (self->area.y + self->area.height));
264 /* if in the top half then check this stuff last, will keep the top
265 edge of the menu visible */
267 *dx = MAX(*dx, a->x - self->area.x);
268 *dy = MAX(*dy, a->y - self->area.y);
272 static void menu_entry_frame_render(ObMenuEntryFrame *self)
274 RrAppearance *item_a, *text_a;
277 ObMenuFrame *frame = self->frame;
279 switch (self->entry->type) {
280 case OB_MENU_ENTRY_TYPE_NORMAL:
281 case OB_MENU_ENTRY_TYPE_SUBMENU:
282 item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
283 !self->entry->data.normal.enabled) ?
285 (self == self->frame->selected ?
288 th = self->frame->item_h;
290 case OB_MENU_ENTRY_TYPE_SEPARATOR:
291 if (self->entry->data.separator.label) {
292 item_a = self->frame->a_title;
293 item_a->texture[0].data.text.string =
294 self->entry->data.separator.label;
295 th = self->frame->title_h;
297 item_a = self->a_normal;
298 th = SEPARATOR_HEIGHT + 2*PADDING;
302 g_assert_not_reached();
304 RECT_SET_SIZE(self->area, self->frame->inner_w, th);
305 XResizeWindow(ob_display, self->window,
306 self->area.width, self->area.height);
307 item_a->surface.parent = self->frame->a_items;
308 item_a->surface.parentx = self->area.x;
309 item_a->surface.parenty = self->area.y;
310 RrPaint(item_a, self->window, self->area.width, self->area.height);
312 switch (self->entry->type) {
313 case OB_MENU_ENTRY_TYPE_NORMAL:
314 text_a = (!self->entry->data.normal.enabled ?
315 self->a_text_disabled :
316 (self == self->frame->selected ?
317 self->a_text_selected :
318 self->a_text_normal));
319 text_a->texture[0].data.text.string = self->entry->data.normal.label;
321 case OB_MENU_ENTRY_TYPE_SUBMENU:
322 text_a = (self == self->frame->selected ?
323 self->a_text_selected :
324 self->a_text_normal);
325 sub = self->entry->data.submenu.submenu;
326 text_a->texture[0].data.text.string = sub ? sub->title : "";
328 case OB_MENU_ENTRY_TYPE_SEPARATOR:
329 text_a = self->a_text_normal;
333 switch (self->entry->type) {
334 case OB_MENU_ENTRY_TYPE_NORMAL:
335 XMoveResizeWindow(ob_display, self->text,
336 self->frame->text_x, PADDING,
338 self->frame->item_h - 2*PADDING);
339 text_a->surface.parent = item_a;
340 text_a->surface.parentx = self->frame->text_x;
341 text_a->surface.parenty = PADDING;
342 RrPaint(text_a, self->text, self->frame->text_w,
343 self->frame->item_h - 2*PADDING);
345 case OB_MENU_ENTRY_TYPE_SUBMENU:
346 XMoveResizeWindow(ob_display, self->text,
347 self->frame->text_x, PADDING,
348 self->frame->text_w - self->frame->item_h,
349 self->frame->item_h - 2*PADDING);
350 text_a->surface.parent = item_a;
351 text_a->surface.parentx = self->frame->text_x;
352 text_a->surface.parenty = PADDING;
353 RrPaint(text_a, self->text, self->frame->text_w - self->frame->item_h,
354 self->frame->item_h - 2*PADDING);
356 case OB_MENU_ENTRY_TYPE_SEPARATOR:
357 if (self->entry->data.separator.label == NULL) {
358 XMoveResizeWindow(ob_display, self->text, PADDING, PADDING,
359 self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
360 self->a_separator->surface.parent = item_a;
361 self->a_separator->surface.parentx = PADDING;
362 self->a_separator->surface.parenty = PADDING;
363 self->a_separator->texture[0].data.lineart.color =
364 text_a->texture[0].data.text.color;
365 self->a_separator->texture[0].data.lineart.x1 = 2*PADDING;
366 self->a_separator->texture[0].data.lineart.y1 = SEPARATOR_HEIGHT/2;
367 self->a_separator->texture[0].data.lineart.x2 =
368 self->area.width - 4*PADDING;
369 self->a_separator->texture[0].data.lineart.y2 = SEPARATOR_HEIGHT/2;
370 RrPaint(self->a_separator, self->text,
371 self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
376 if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
377 self->entry->data.normal.icon_data)
379 XMoveResizeWindow(ob_display, self->icon,
380 PADDING, frame->item_margin.top,
381 self->frame->item_h - frame->item_margin.top
382 - frame->item_margin.bottom,
383 self->frame->item_h - frame->item_margin.top
384 - frame->item_margin.bottom);
385 self->a_icon->texture[0].data.rgba.width =
386 self->entry->data.normal.icon_width;
387 self->a_icon->texture[0].data.rgba.height =
388 self->entry->data.normal.icon_height;
389 self->a_icon->texture[0].data.rgba.data =
390 self->entry->data.normal.icon_data;
391 self->a_icon->surface.parent = item_a;
392 self->a_icon->surface.parentx = PADDING;
393 self->a_icon->surface.parenty = frame->item_margin.top;
394 RrPaint(self->a_icon, self->icon,
395 self->frame->item_h - frame->item_margin.top
396 - frame->item_margin.bottom,
397 self->frame->item_h - frame->item_margin.top
398 - frame->item_margin.bottom);
399 XMapWindow(ob_display, self->icon);
400 } else if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
401 self->entry->data.normal.mask)
405 XMoveResizeWindow(ob_display, self->icon,
406 PADDING, frame->item_margin.top,
407 self->frame->item_h - frame->item_margin.top
408 - frame->item_margin.bottom,
409 self->frame->item_h - frame->item_margin.top
410 - frame->item_margin.bottom);
411 self->a_mask->texture[0].data.mask.mask =
412 self->entry->data.normal.mask;
414 c = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
415 !self->entry->data.normal.enabled) ?
416 self->entry->data.normal.mask_disabled_color :
417 (self == self->frame->selected ?
418 self->entry->data.normal.mask_selected_color :
419 self->entry->data.normal.mask_normal_color));
420 self->a_mask->texture[0].data.mask.color = c;
422 self->a_mask->surface.parent = item_a;
423 self->a_mask->surface.parentx = PADDING;
424 self->a_mask->surface.parenty = frame->item_margin.top;
425 RrPaint(self->a_mask, self->icon,
426 self->frame->item_h - frame->item_margin.top
427 - frame->item_margin.bottom,
428 self->frame->item_h - frame->item_margin.top
429 - frame->item_margin.bottom);
430 XMapWindow(ob_display, self->icon);
432 XUnmapWindow(ob_display, self->icon);
434 if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
435 RrAppearance *bullet_a;
436 XMoveResizeWindow(ob_display, self->bullet,
437 self->frame->text_x + self->frame->text_w
438 - self->frame->item_h + PADDING, PADDING,
439 self->frame->item_h - 2*PADDING,
440 self->frame->item_h - 2*PADDING);
441 bullet_a = (self == self->frame->selected ?
442 self->a_bullet_selected :
443 self->a_bullet_normal);
444 bullet_a->surface.parent = item_a;
445 bullet_a->surface.parentx =
446 self->frame->text_x + self->frame->text_w - self->frame->item_h
448 bullet_a->surface.parenty = PADDING;
449 RrPaint(bullet_a, self->bullet,
450 self->frame->item_h - 2*PADDING,
451 self->frame->item_h - 2*PADDING);
452 XMapWindow(ob_display, self->bullet);
454 XUnmapWindow(ob_display, self->bullet);
459 static void menu_frame_render(ObMenuFrame *self)
462 gint tw, th; /* temps */
464 gboolean has_icon = FALSE;
467 XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->mbwidth);
468 XSetWindowBorder(ob_display, self->window,
469 RrColorPixel(ob_rr_theme->menu_b_color));
471 /* find text dimensions */
473 STRUT_SET(self->item_margin, 0, 0, 0, 0);
476 ObMenuEntryFrame *e = self->entries->data;
479 e->a_text_normal->texture[0].data.text.string = "";
480 RrMinsize(e->a_text_normal, &tw, &th);
485 self->a_title->texture[0].data.text.string = "";
486 RrMinsize(self->a_title, &tw, &th);
491 RrMargins(e->a_normal, &l, &t, &r, &b);
492 STRUT_SET(self->item_margin,
493 MAX(self->item_margin.left, l),
494 MAX(self->item_margin.top, t),
495 MAX(self->item_margin.right, r),
496 MAX(self->item_margin.bottom, b));
497 RrMargins(e->a_selected, &l, &t, &r, &b);
498 STRUT_SET(self->item_margin,
499 MAX(self->item_margin.left, l),
500 MAX(self->item_margin.top, t),
501 MAX(self->item_margin.right, r),
502 MAX(self->item_margin.bottom, b));
503 RrMargins(e->a_disabled, &l, &t, &r, &b);
504 STRUT_SET(self->item_margin,
505 MAX(self->item_margin.left, l),
506 MAX(self->item_margin.top, t),
507 MAX(self->item_margin.right, r),
508 MAX(self->item_margin.bottom, b));
512 /* render the entries */
514 for (it = self->entries; it; it = g_list_next(it)) {
515 RrAppearance *text_a;
516 ObMenuEntryFrame *e = it->data;
518 RECT_SET_POINT(e->area, 0, h);
519 XMoveWindow(ob_display, e->window, 0, e->area.y);
521 text_a = ((e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
522 !e->entry->data.normal.enabled) ?
524 (e == self->selected ?
527 switch (e->entry->type) {
528 case OB_MENU_ENTRY_TYPE_NORMAL:
529 text_a->texture[0].data.text.string = e->entry->data.normal.label;
530 RrMinsize(text_a, &tw, &th);
531 tw = MIN(tw, MAX_MENU_WIDTH);
533 if (e->entry->data.normal.icon_data ||
534 e->entry->data.normal.mask)
537 case OB_MENU_ENTRY_TYPE_SUBMENU:
538 sub = e->entry->data.submenu.submenu;
539 text_a->texture[0].data.text.string = sub ? sub->title : "";
540 RrMinsize(text_a, &tw, &th);
541 tw = MIN(tw, MAX_MENU_WIDTH);
543 if (e->entry->data.normal.icon_data ||
544 e->entry->data.normal.mask)
547 tw += self->item_h - PADDING;
549 case OB_MENU_ENTRY_TYPE_SEPARATOR:
550 if (e->entry->data.separator.label != NULL) {
551 self->a_title->texture[0].data.text.string =
552 e->entry->data.separator.label;
553 RrMinsize(self->a_title, &tw, &th);
554 tw = MIN(tw, MAX_MENU_WIDTH);
557 th = SEPARATOR_HEIGHT;
567 self->text_x = PADDING;
572 w += self->item_h + PADDING;
573 self->text_x += self->item_h + PADDING;
580 XResizeWindow(ob_display, self->window, w, h);
584 RrPaint(self->a_items, self->window, w, h);
586 for (it = self->entries; it; it = g_list_next(it))
587 menu_entry_frame_render(it->data);
589 w += ob_rr_theme->mbwidth * 2;
590 h += ob_rr_theme->mbwidth * 2;
592 RECT_SET_SIZE(self->area, w, h);
597 static void menu_frame_update(ObMenuFrame *self)
601 menu_pipe_execute(self->menu);
602 menu_find_submenus(self->menu);
604 self->selected = NULL;
606 for (mit = self->menu->entries, fit = self->entries; mit && fit;
607 mit = g_list_next(mit), fit = g_list_next(fit))
609 ObMenuEntryFrame *f = fit->data;
610 f->entry = mit->data;
614 ObMenuEntryFrame *e = menu_entry_frame_new(mit->data, self);
615 self->entries = g_list_append(self->entries, e);
616 mit = g_list_next(mit);
620 GList *n = g_list_next(fit);
621 menu_entry_frame_free(fit->data);
622 self->entries = g_list_delete_link(self->entries, fit);
626 menu_frame_render(self);
629 static gboolean menu_frame_is_visible(ObMenuFrame *self)
631 return !!(g_list_find(menu_frame_visible, self));
634 static gboolean menu_frame_show(ObMenuFrame *self)
638 if (menu_frame_visible == NULL) {
639 /* no menus shown yet */
640 if (!grab_pointer(TRUE, OB_CURSOR_POINTER))
642 if (!grab_keyboard(TRUE)) {
643 grab_pointer(FALSE, OB_CURSOR_POINTER);
648 /* determine if the underlying menu is already visible */
649 for (it = menu_frame_visible; it; it = g_list_next(it)) {
650 ObMenuFrame *f = it->data;
651 if (f->menu == self->menu)
655 if (self->menu->update_func)
656 self->menu->update_func(self, self->menu->data);
659 menu_frame_update(self);
661 menu_frame_visible = g_list_prepend(menu_frame_visible, self);
666 gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y)
671 if (menu_frame_is_visible(self))
673 if (!menu_frame_show(self))
676 menu_frame_place_topmenu(self, x, y);
678 /* find the monitor the menu is on */
679 for (i = 0; i < screen_num_monitors; ++i) {
680 Rect *a = screen_physical_area_monitor(i);
681 if (RECT_CONTAINS(*a, x, y)) {
687 menu_frame_move_on_screen(self, &dx, &dy);
688 menu_frame_move(self, self->area.x + dx, self->area.y + dy);
690 XMapWindow(ob_display, self->window);
695 gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent,
696 ObMenuEntryFrame *parent_entry)
701 if (menu_frame_is_visible(self))
704 self->monitor = parent->monitor;
705 self->parent = parent;
706 self->parent_entry = parent_entry;
708 /* set up parent's child to be us */
710 menu_frame_hide(parent->child);
711 parent->child = self;
713 if (!menu_frame_show(self))
716 menu_frame_place_submenu(self);
717 menu_frame_move_on_screen(self, &dx, &dy);
720 menu_frame_move(self, self->area.x, self->area.y + dy);
724 /* flip the direction in which we're placing submenus */
730 /* if it changed, then replace the menu on the opposite side,
731 and try keep it on the screen too */
732 if (dir != self->direction_right) {
733 self->direction_right = dir;
734 menu_frame_place_submenu(self);
735 menu_frame_move_on_screen(self, &dx, &dy);
736 menu_frame_move(self, self->area.x + dx, self->area.y + dy);
740 XMapWindow(ob_display, self->window);
742 if (screen_pointer_pos(&dx, &dy) && (e = menu_entry_frame_under(dx, dy)) &&
749 void menu_frame_hide(ObMenuFrame *self)
751 GList *it = g_list_find(menu_frame_visible, self);
757 menu_frame_hide(self->child);
760 self->parent->child = NULL;
762 self->parent_entry = NULL;
764 menu_frame_visible = g_list_delete_link(menu_frame_visible, it);
766 if (menu_frame_visible == NULL) {
767 /* last menu shown */
768 grab_pointer(FALSE, OB_CURSOR_NONE);
769 grab_keyboard(FALSE);
772 XUnmapWindow(ob_display, self->window);
774 menu_frame_free(self);
777 void menu_frame_hide_all()
781 if (config_submenu_show_delay) {
782 /* remove any submenu open requests */
783 ob_main_loop_timeout_remove(ob_main_loop,
784 menu_entry_frame_submenu_timeout);
786 if ((it = g_list_last(menu_frame_visible)))
787 menu_frame_hide(it->data);
790 void menu_frame_hide_all_client(ObClient *client)
792 GList *it = g_list_last(menu_frame_visible);
794 ObMenuFrame *f = it->data;
795 if (f->client == client)
801 ObMenuFrame* menu_frame_under(gint x, gint y)
803 ObMenuFrame *ret = NULL;
806 for (it = menu_frame_visible; it; it = g_list_next(it)) {
807 ObMenuFrame *f = it->data;
809 if (RECT_CONTAINS(f->area, x, y)) {
817 ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y)
820 ObMenuEntryFrame *ret = NULL;
823 if ((frame = menu_frame_under(x, y))) {
824 x -= ob_rr_theme->mbwidth + frame->area.x;
825 y -= ob_rr_theme->mbwidth + frame->area.y;
827 for (it = frame->entries; it; it = g_list_next(it)) {
828 ObMenuEntryFrame *e = it->data;
830 if (RECT_CONTAINS(e->area, x, y)) {
839 static gboolean menu_entry_frame_submenu_timeout(gpointer data)
841 menu_entry_frame_show_submenu((ObMenuEntryFrame*)data);
845 void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry)
847 ObMenuEntryFrame *old = self->selected;
848 ObMenuFrame *oldchild = self->child;
850 if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR)
853 if (old == entry) return;
855 if (config_submenu_show_delay) {
856 /* remove any submenu open requests */
857 ob_main_loop_timeout_remove(ob_main_loop,
858 menu_entry_frame_submenu_timeout);
861 self->selected = entry;
864 menu_entry_frame_render(old);
866 menu_frame_hide(oldchild);
868 if (self->selected) {
869 menu_entry_frame_render(self->selected);
871 if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
872 if (config_submenu_show_delay) {
873 /* initiate a new submenu open request */
874 ob_main_loop_timeout_add(ob_main_loop,
875 config_submenu_show_delay * 1000,
876 menu_entry_frame_submenu_timeout,
880 menu_entry_frame_show_submenu(self->selected);
886 void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
890 if (!self->entry->data.submenu.submenu) return;
892 f = menu_frame_new(self->entry->data.submenu.submenu,
893 self->frame->client);
894 /* pass our direction on to our child */
895 f->direction_right = self->frame->direction_right;
897 menu_frame_show_submenu(f, self->frame, self);
900 void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state, Time time)
902 if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
903 self->entry->data.normal.enabled)
905 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
907 ObMenuEntry *entry = self->entry;
908 ObMenuExecuteFunc func = self->frame->menu->execute_func;
909 gpointer data = self->frame->menu->data;
910 GSList *acts = self->entry->data.normal.actions;
911 ObClient *client = self->frame->client;
913 /* release grabs before executing the shit */
914 if (!(state & ControlMask))
915 menu_frame_hide_all();
918 func(entry, state, data, time);
920 action_run(acts, client, state, time);
924 void menu_frame_select_previous(ObMenuFrame *self)
926 GList *it = NULL, *start;
929 start = it = g_list_find(self->entries, self->selected);
933 it = it ? g_list_previous(it) : g_list_last(self->entries);
939 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
941 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
942 e->entry->data.normal.enabled)
947 menu_frame_select(self, it ? it->data : NULL);
950 void menu_frame_select_next(ObMenuFrame *self)
952 GList *it = NULL, *start;
955 start = it = g_list_find(self->entries, self->selected);
959 it = it ? g_list_next(it) : self->entries;
965 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
967 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
968 e->entry->data.normal.enabled)
973 menu_frame_select(self, it ? it->data : NULL);