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 Ben 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 TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
37 #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
38 ButtonPressMask | ButtonReleaseMask)
40 GList *menu_frame_visible;
42 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
44 static void menu_entry_frame_free(ObMenuEntryFrame *self);
45 static void menu_frame_render(ObMenuFrame *self);
46 static void menu_frame_update(ObMenuFrame *self);
47 static gboolean menu_entry_frame_submenu_timeout(gpointer data);
49 static Window createWindow(Window parent, gulong mask,
50 XSetWindowAttributes *attrib)
52 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
53 RrDepth(ob_rr_inst), InputOutput,
54 RrVisual(ob_rr_inst), mask, attrib);
57 ObMenuFrame* menu_frame_new(ObMenu *menu, ObClient *client)
60 XSetWindowAttributes attr;
62 self = g_new0(ObMenuFrame, 1);
63 self->type = Window_Menu;
65 self->selected = NULL;
66 self->show_title = TRUE;
67 self->client = client;
68 self->direction_right = TRUE;
70 attr.event_mask = FRAME_EVENTMASK;
71 self->window = createWindow(RootWindow(ob_display, ob_screen),
73 attr.event_mask = TITLE_EVENTMASK;
74 self->title = createWindow(self->window, CWEventMask, &attr);
75 self->items = createWindow(self->window, 0, NULL);
77 XMapWindow(ob_display, self->items);
79 self->a_title = RrAppearanceCopy(ob_rr_theme->a_menu_title);
80 self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);
82 stacking_add(MENU_AS_WINDOW(self));
87 void menu_frame_free(ObMenuFrame *self)
90 while (self->entries) {
91 menu_entry_frame_free(self->entries->data);
92 self->entries = g_list_delete_link(self->entries, self->entries);
95 stacking_remove(MENU_AS_WINDOW(self));
97 XDestroyWindow(ob_display, self->items);
98 XDestroyWindow(ob_display, self->title);
99 XDestroyWindow(ob_display, self->window);
101 RrAppearanceFree(self->a_items);
102 RrAppearanceFree(self->a_title);
108 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
111 ObMenuEntryFrame *self;
112 XSetWindowAttributes attr;
114 self = g_new0(ObMenuEntryFrame, 1);
118 attr.event_mask = ENTRY_EVENTMASK;
119 self->window = createWindow(self->frame->items, CWEventMask, &attr);
120 self->text = createWindow(self->window, 0, NULL);
121 if (entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR) {
122 self->icon = createWindow(self->window, 0, NULL);
123 self->bullet = createWindow(self->window, 0, NULL);
126 XMapWindow(ob_display, self->window);
127 XMapWindow(ob_display, self->text);
129 self->a_normal = RrAppearanceCopy(ob_rr_theme->a_menu_normal);
130 self->a_disabled = RrAppearanceCopy(ob_rr_theme->a_menu_disabled);
131 self->a_selected = RrAppearanceCopy(ob_rr_theme->a_menu_selected);
133 if (entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) {
134 self->a_separator = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
135 self->a_separator->texture[0].type = RR_TEXTURE_LINE_ART;
137 self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
138 self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
139 self->a_mask = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
140 self->a_mask->texture[0].type = RR_TEXTURE_MASK;
141 self->a_bullet_normal =
142 RrAppearanceCopy(ob_rr_theme->a_menu_bullet_normal);
143 self->a_bullet_selected =
144 RrAppearanceCopy(ob_rr_theme->a_menu_bullet_selected);
147 self->a_text_normal =
148 RrAppearanceCopy(ob_rr_theme->a_menu_text_normal);
149 self->a_text_disabled =
150 RrAppearanceCopy(ob_rr_theme->a_menu_text_disabled);
151 self->a_text_selected =
152 RrAppearanceCopy(ob_rr_theme->a_menu_text_selected);
157 static void menu_entry_frame_free(ObMenuEntryFrame *self)
160 XDestroyWindow(ob_display, self->text);
161 XDestroyWindow(ob_display, self->window);
162 if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR) {
163 XDestroyWindow(ob_display, self->icon);
164 XDestroyWindow(ob_display, self->bullet);
167 RrAppearanceFree(self->a_normal);
168 RrAppearanceFree(self->a_disabled);
169 RrAppearanceFree(self->a_selected);
171 RrAppearanceFree(self->a_separator);
172 RrAppearanceFree(self->a_icon);
173 RrAppearanceFree(self->a_mask);
174 RrAppearanceFree(self->a_text_normal);
175 RrAppearanceFree(self->a_text_disabled);
176 RrAppearanceFree(self->a_text_selected);
177 RrAppearanceFree(self->a_bullet_normal);
178 RrAppearanceFree(self->a_bullet_selected);
184 void menu_frame_move(ObMenuFrame *self, gint x, gint y)
186 RECT_SET_POINT(self->area, x, y);
187 XMoveWindow(ob_display, self->window, self->area.x, self->area.y);
190 void menu_frame_place_topmenu(ObMenuFrame *self, gint x, gint y)
192 if (self->client && x < 0 && y < 0) {
193 x = self->client->frame->area.x + self->client->frame->size.left;
194 y = self->client->frame->area.y + self->client->frame->size.top;
196 if (config_menu_middle) {
197 x -= self->area.width / 2;
201 menu_frame_move(self, x, y);
204 void menu_frame_place_submenu(ObMenuFrame *self)
210 overlap = ob_rr_theme->menu_overlap;
211 bwidth = ob_rr_theme->mbwidth;
213 if (self->direction_right)
214 x = self->parent->area.x + self->parent->area.width - overlap - bwidth;
216 x = self->parent->area.x - self->area.width + overlap + bwidth;
218 y = self->parent->area.y + self->parent->title_h +
219 self->parent_entry->area.y;
220 if (config_menu_middle)
221 y -= (self->area.height - (bwidth * 2) - self->item_h) / 2;
225 menu_frame_move(self, x, y);
228 void menu_frame_move_on_screen(ObMenuFrame *self, gint *dx, gint *dy)
235 a = screen_physical_area_monitor(self->monitor);
237 half = g_list_length(self->entries) / 2;
238 pos = g_list_index(self->entries, self->selected);
240 /* if in the bottom half then check this stuff first, will keep the bottom
241 edge of the menu visible */
243 *dx = MAX(*dx, a->x - self->area.x);
244 *dy = MAX(*dy, a->y - self->area.y);
246 *dx = MIN(*dx, (a->x + a->width) - (self->area.x + self->area.width));
247 *dy = MIN(*dy, (a->y + a->height) - (self->area.y + self->area.height));
248 /* if in the top half then check this stuff last, will keep the top
249 edge of the menu visible */
251 *dx = MAX(*dx, a->x - self->area.x);
252 *dy = MAX(*dy, a->y - self->area.y);
256 static void menu_entry_frame_render(ObMenuEntryFrame *self)
258 RrAppearance *item_a, *text_a;
261 ObMenuFrame *frame = self->frame;
263 item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
264 !self->entry->data.normal.enabled) ?
266 (self == self->frame->selected ?
269 switch (self->entry->type) {
270 case OB_MENU_ENTRY_TYPE_NORMAL:
271 case OB_MENU_ENTRY_TYPE_SUBMENU:
272 th = self->frame->item_h;
274 case OB_MENU_ENTRY_TYPE_SEPARATOR:
275 th = SEPARATOR_HEIGHT + 2*PADDING;
278 g_assert_not_reached();
280 RECT_SET_SIZE(self->area, self->frame->inner_w, th);
281 XResizeWindow(ob_display, self->window,
282 self->area.width, self->area.height);
283 item_a->surface.parent = self->frame->a_items;
284 item_a->surface.parentx = self->area.x;
285 item_a->surface.parenty = self->area.y;
286 RrPaint(item_a, self->window, self->area.width, self->area.height);
288 text_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
289 !self->entry->data.normal.enabled) ?
290 self->a_text_disabled :
291 (self == self->frame->selected ?
292 self->a_text_selected :
293 self->a_text_normal));
294 switch (self->entry->type) {
295 case OB_MENU_ENTRY_TYPE_NORMAL:
296 text_a->texture[0].data.text.string = self->entry->data.normal.label;
298 case OB_MENU_ENTRY_TYPE_SUBMENU:
299 sub = self->entry->data.submenu.submenu;
300 text_a->texture[0].data.text.string = sub ? sub->title : "";
302 case OB_MENU_ENTRY_TYPE_SEPARATOR:
306 switch (self->entry->type) {
307 case OB_MENU_ENTRY_TYPE_NORMAL:
308 XMoveResizeWindow(ob_display, self->text,
309 self->frame->text_x, PADDING,
311 self->frame->item_h - 2*PADDING);
312 text_a->surface.parent = item_a;
313 text_a->surface.parentx = self->frame->text_x;
314 text_a->surface.parenty = PADDING;
315 RrPaint(text_a, self->text, self->frame->text_w,
316 self->frame->item_h - 2*PADDING);
318 case OB_MENU_ENTRY_TYPE_SUBMENU:
319 XMoveResizeWindow(ob_display, self->text,
320 self->frame->text_x, PADDING,
321 self->frame->text_w - self->frame->item_h,
322 self->frame->item_h - 2*PADDING);
323 text_a->surface.parent = item_a;
324 text_a->surface.parentx = self->frame->text_x;
325 text_a->surface.parenty = PADDING;
326 RrPaint(text_a, self->text, self->frame->text_w - self->frame->item_h,
327 self->frame->item_h - 2*PADDING);
329 case OB_MENU_ENTRY_TYPE_SEPARATOR:
330 XMoveResizeWindow(ob_display, self->text, PADDING, PADDING,
331 self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
332 self->a_separator->surface.parent = item_a;
333 self->a_separator->surface.parentx = PADDING;
334 self->a_separator->surface.parenty = PADDING;
335 self->a_separator->texture[0].data.lineart.color =
336 text_a->texture[0].data.text.color;
337 self->a_separator->texture[0].data.lineart.x1 = 2*PADDING;
338 self->a_separator->texture[0].data.lineart.y1 = SEPARATOR_HEIGHT / 2;
339 self->a_separator->texture[0].data.lineart.x2 =
340 self->area.width - 4*PADDING;
341 self->a_separator->texture[0].data.lineart.y2 = SEPARATOR_HEIGHT / 2;
342 RrPaint(self->a_separator, self->text,
343 self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
347 if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR &&
348 self->entry->data.normal.icon_data)
350 XMoveResizeWindow(ob_display, self->icon,
351 PADDING, frame->item_margin.top,
352 self->frame->item_h - frame->item_margin.top
353 - frame->item_margin.bottom,
354 self->frame->item_h - frame->item_margin.top
355 - frame->item_margin.bottom);
356 self->a_icon->texture[0].data.rgba.width =
357 self->entry->data.normal.icon_width;
358 self->a_icon->texture[0].data.rgba.height =
359 self->entry->data.normal.icon_height;
360 self->a_icon->texture[0].data.rgba.data =
361 self->entry->data.normal.icon_data;
362 self->a_icon->surface.parent = item_a;
363 self->a_icon->surface.parentx = PADDING;
364 self->a_icon->surface.parenty = frame->item_margin.top;
365 RrPaint(self->a_icon, self->icon,
366 self->frame->item_h - frame->item_margin.top
367 - frame->item_margin.bottom,
368 self->frame->item_h - frame->item_margin.top
369 - frame->item_margin.bottom);
370 XMapWindow(ob_display, self->icon);
371 } else if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR &&
372 self->entry->data.normal.mask)
376 XMoveResizeWindow(ob_display, self->icon,
377 PADDING, frame->item_margin.top,
378 self->frame->item_h - frame->item_margin.top
379 - frame->item_margin.bottom,
380 self->frame->item_h - frame->item_margin.top
381 - frame->item_margin.bottom);
382 self->a_mask->texture[0].data.mask.mask =
383 self->entry->data.normal.mask;
385 c = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
386 !self->entry->data.normal.enabled) ?
387 self->entry->data.normal.mask_disabled_color :
388 (self == self->frame->selected ?
389 self->entry->data.normal.mask_selected_color :
390 self->entry->data.normal.mask_normal_color));
391 self->a_mask->texture[0].data.mask.color = c;
393 self->a_mask->surface.parent = item_a;
394 self->a_mask->surface.parentx = PADDING;
395 self->a_mask->surface.parenty = frame->item_margin.top;
396 RrPaint(self->a_mask, self->icon,
397 self->frame->item_h - frame->item_margin.top
398 - frame->item_margin.bottom,
399 self->frame->item_h - frame->item_margin.top
400 - frame->item_margin.bottom);
401 XMapWindow(ob_display, self->icon);
403 XUnmapWindow(ob_display, self->icon);
405 if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
406 RrAppearance *bullet_a;
407 XMoveResizeWindow(ob_display, self->bullet,
408 self->frame->text_x + self->frame->text_w
409 - self->frame->item_h + PADDING, PADDING,
410 self->frame->item_h - 2*PADDING,
411 self->frame->item_h - 2*PADDING);
412 bullet_a = (self == self->frame->selected ?
413 self->a_bullet_selected :
414 self->a_bullet_normal);
415 bullet_a->surface.parent = item_a;
416 bullet_a->surface.parentx =
417 self->frame->text_x + self->frame->text_w - self->frame->item_h
419 bullet_a->surface.parenty = PADDING;
420 RrPaint(bullet_a, self->bullet,
421 self->frame->item_h - 2*PADDING,
422 self->frame->item_h - 2*PADDING);
423 XMapWindow(ob_display, self->bullet);
425 XUnmapWindow(ob_display, self->bullet);
430 static void menu_frame_render(ObMenuFrame *self)
434 gint tw, th; /* temps */
436 gboolean has_icon = FALSE;
439 XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->mbwidth);
440 XSetWindowBorder(ob_display, self->window,
441 RrColorPixel(ob_rr_theme->menu_b_color));
443 if (!self->parent && self->show_title) {
444 XMoveWindow(ob_display, self->title,
445 -ob_rr_theme->mbwidth, h - ob_rr_theme->mbwidth);
447 self->a_title->texture[0].data.text.string = self->menu->title;
448 RrMinsize(self->a_title, &tw, &th);
449 tw = MIN(tw, MAX_MENU_WIDTH) + ob_rr_theme->paddingx * 2;
452 th = ob_rr_theme->menu_title_height;
453 h += (self->title_h = th + ob_rr_theme->mbwidth);
455 XSetWindowBorderWidth(ob_display, self->title, ob_rr_theme->mbwidth);
456 XSetWindowBorder(ob_display, self->title,
457 RrColorPixel(ob_rr_theme->menu_b_color));
460 XMoveWindow(ob_display, self->items, 0, h);
462 STRUT_SET(self->item_margin, 0, 0, 0, 0);
465 ObMenuEntryFrame *e = self->entries->data;
468 e->a_text_normal->texture[0].data.text.string = "";
469 RrMinsize(e->a_text_normal, &tw, &th);
474 RrMargins(e->a_normal, &l, &t, &r, &b);
475 STRUT_SET(self->item_margin,
476 MAX(self->item_margin.left, l),
477 MAX(self->item_margin.top, t),
478 MAX(self->item_margin.right, r),
479 MAX(self->item_margin.bottom, b));
480 RrMargins(e->a_selected, &l, &t, &r, &b);
481 STRUT_SET(self->item_margin,
482 MAX(self->item_margin.left, l),
483 MAX(self->item_margin.top, t),
484 MAX(self->item_margin.right, r),
485 MAX(self->item_margin.bottom, b));
486 RrMargins(e->a_disabled, &l, &t, &r, &b);
487 STRUT_SET(self->item_margin,
488 MAX(self->item_margin.left, l),
489 MAX(self->item_margin.top, t),
490 MAX(self->item_margin.right, r),
491 MAX(self->item_margin.bottom, b));
495 for (it = self->entries; it; it = g_list_next(it)) {
496 RrAppearance *text_a;
497 ObMenuEntryFrame *e = it->data;
499 RECT_SET_POINT(e->area, 0, allitems_h);
500 XMoveWindow(ob_display, e->window, 0, e->area.y);
502 text_a = ((e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
503 !e->entry->data.normal.enabled) ?
505 (e == self->selected ?
508 switch (e->entry->type) {
509 case OB_MENU_ENTRY_TYPE_NORMAL:
510 text_a->texture[0].data.text.string = e->entry->data.normal.label;
511 RrMinsize(text_a, &tw, &th);
512 tw = MIN(tw, MAX_MENU_WIDTH);
514 if (e->entry->data.normal.icon_data ||
515 e->entry->data.normal.mask)
518 case OB_MENU_ENTRY_TYPE_SUBMENU:
519 sub = e->entry->data.submenu.submenu;
520 text_a->texture[0].data.text.string = sub ? sub->title : "";
521 RrMinsize(text_a, &tw, &th);
522 tw = MIN(tw, MAX_MENU_WIDTH);
524 if (e->entry->data.normal.icon_data ||
525 e->entry->data.normal.mask)
528 tw += self->item_h - PADDING;
530 case OB_MENU_ENTRY_TYPE_SEPARATOR:
532 th = SEPARATOR_HEIGHT;
542 self->text_x = PADDING;
547 w += self->item_h + PADDING;
548 self->text_x += self->item_h + PADDING;
558 XResizeWindow(ob_display, self->window, w, h);
559 XResizeWindow(ob_display, self->items, w, allitems_h);
563 if (!self->parent && self->show_title) {
564 XResizeWindow(ob_display, self->title,
565 w, self->title_h - ob_rr_theme->mbwidth);
566 RrPaint(self->a_title, self->title,
567 w, self->title_h - ob_rr_theme->mbwidth);
568 XMapWindow(ob_display, self->title);
570 XUnmapWindow(ob_display, self->title);
572 RrPaint(self->a_items, self->items, w, allitems_h);
574 for (it = self->entries; it; it = g_list_next(it))
575 menu_entry_frame_render(it->data);
577 w += ob_rr_theme->mbwidth * 2;
578 h += ob_rr_theme->mbwidth * 2;
580 RECT_SET_SIZE(self->area, w, h);
585 static void menu_frame_update(ObMenuFrame *self)
589 menu_pipe_execute(self->menu);
590 menu_find_submenus(self->menu);
592 self->selected = NULL;
594 for (mit = self->menu->entries, fit = self->entries; mit && fit;
595 mit = g_list_next(mit), fit = g_list_next(fit))
597 ObMenuEntryFrame *f = fit->data;
598 f->entry = mit->data;
602 ObMenuEntryFrame *e = menu_entry_frame_new(mit->data, self);
603 self->entries = g_list_append(self->entries, e);
604 mit = g_list_next(mit);
608 GList *n = g_list_next(fit);
609 menu_entry_frame_free(fit->data);
610 self->entries = g_list_delete_link(self->entries, fit);
614 menu_frame_render(self);
617 static gboolean menu_frame_is_visible(ObMenuFrame *self)
619 return !!(g_list_find(menu_frame_visible, self));
622 static gboolean menu_frame_show(ObMenuFrame *self)
626 if (menu_frame_visible == NULL) {
627 /* no menus shown yet */
628 if (!grab_pointer(TRUE, OB_CURSOR_NONE))
630 if (!grab_keyboard(TRUE)) {
631 grab_pointer(FALSE, OB_CURSOR_NONE);
636 /* determine if the underlying menu is already visible */
637 for (it = menu_frame_visible; it; it = g_list_next(it)) {
638 ObMenuFrame *f = it->data;
639 if (f->menu == self->menu)
643 if (self->menu->update_func)
644 self->menu->update_func(self, self->menu->data);
647 menu_frame_update(self);
649 menu_frame_visible = g_list_prepend(menu_frame_visible, self);
654 gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y)
659 if (menu_frame_is_visible(self))
661 if (!menu_frame_show(self))
664 menu_frame_place_topmenu(self, x, y);
666 /* find the monitor the menu is on */
667 for (i = 0; i < screen_num_monitors; ++i) {
668 Rect *a = screen_physical_area_monitor(i);
669 if (RECT_CONTAINS(*a, x, y)) {
675 menu_frame_move_on_screen(self, &dx, &dy);
676 menu_frame_move(self, self->area.x + dx, self->area.y + dy);
678 XMapWindow(ob_display, self->window);
683 gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent,
684 ObMenuEntryFrame *parent_entry)
688 if (menu_frame_is_visible(self))
691 self->monitor = parent->monitor;
692 self->parent = parent;
693 self->parent_entry = parent_entry;
695 /* set up parent's child to be us */
697 menu_frame_hide(parent->child);
698 parent->child = self;
700 if (!menu_frame_show(self))
703 menu_frame_place_submenu(self);
704 menu_frame_move_on_screen(self, &dx, &dy);
707 menu_frame_move(self, self->area.x, self->area.y + dy);
711 /* flip the direction in which we're placing submenus */
717 /* if it changed, then replace the menu on the opposite side,
718 and try keep it on the screen too */
719 if (dir != self->direction_right) {
720 self->direction_right = dir;
721 menu_frame_place_submenu(self);
722 menu_frame_move_on_screen(self, &dx, &dy);
723 menu_frame_move(self, self->area.x + dx, self->area.y + dy);
727 XMapWindow(ob_display, self->window);
732 void menu_frame_hide(ObMenuFrame *self)
734 GList *it = g_list_find(menu_frame_visible, self);
740 menu_frame_hide(self->child);
743 self->parent->child = NULL;
745 self->parent_entry = NULL;
747 menu_frame_visible = g_list_delete_link(menu_frame_visible, it);
749 if (menu_frame_visible == NULL) {
750 /* last menu shown */
751 grab_pointer(FALSE, OB_CURSOR_NONE);
752 grab_keyboard(FALSE);
755 XUnmapWindow(ob_display, self->window);
757 menu_frame_free(self);
760 void menu_frame_hide_all()
764 if (config_submenu_show_delay) {
765 /* remove any submenu open requests */
766 ob_main_loop_timeout_remove(ob_main_loop,
767 menu_entry_frame_submenu_timeout);
769 if ((it = g_list_last(menu_frame_visible)))
770 menu_frame_hide(it->data);
773 void menu_frame_hide_all_client(ObClient *client)
775 GList *it = g_list_last(menu_frame_visible);
777 ObMenuFrame *f = it->data;
778 if (f->client == client)
784 ObMenuFrame* menu_frame_under(gint x, gint y)
786 ObMenuFrame *ret = NULL;
789 for (it = menu_frame_visible; it; it = g_list_next(it)) {
790 ObMenuFrame *f = it->data;
792 if (RECT_CONTAINS(f->area, x, y)) {
800 ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y)
803 ObMenuEntryFrame *ret = NULL;
806 if ((frame = menu_frame_under(x, y))) {
807 x -= ob_rr_theme->mbwidth + frame->area.x;
808 y -= frame->title_h + ob_rr_theme->mbwidth + frame->area.y;
810 for (it = frame->entries; it; it = g_list_next(it)) {
811 ObMenuEntryFrame *e = it->data;
813 if (RECT_CONTAINS(e->area, x, y)) {
822 static gboolean menu_entry_frame_submenu_timeout(gpointer data)
824 menu_entry_frame_show_submenu((ObMenuEntryFrame*)data);
828 void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry)
830 ObMenuEntryFrame *old = self->selected;
831 ObMenuFrame *oldchild = self->child;
833 if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR)
836 if (old == entry) return;
838 if (config_submenu_show_delay) {
839 /* remove any submenu open requests */
840 ob_main_loop_timeout_remove(ob_main_loop,
841 menu_entry_frame_submenu_timeout);
844 self->selected = entry;
847 menu_entry_frame_render(old);
849 menu_frame_hide(oldchild);
851 if (self->selected) {
852 menu_entry_frame_render(self->selected);
854 if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
855 if (config_submenu_show_delay) {
856 /* initiate a new submenu open request */
857 ob_main_loop_timeout_add(ob_main_loop,
858 config_submenu_show_delay * 1000,
859 menu_entry_frame_submenu_timeout,
863 menu_entry_frame_show_submenu(self->selected);
869 void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
873 if (!self->entry->data.submenu.submenu) return;
875 f = menu_frame_new(self->entry->data.submenu.submenu,
876 self->frame->client);
877 /* pass our direction on to our child */
878 f->direction_right = self->frame->direction_right;
880 menu_frame_show_submenu(f, self->frame, self);
883 void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state, Time time)
885 if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
886 self->entry->data.normal.enabled)
888 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
890 ObMenuEntry *entry = self->entry;
891 ObMenuExecuteFunc func = self->frame->menu->execute_func;
892 gpointer data = self->frame->menu->data;
893 GSList *acts = self->entry->data.normal.actions;
894 ObClient *client = self->frame->client;
896 /* release grabs before executing the shit */
897 if (!(state & ControlMask))
898 menu_frame_hide_all();
901 func(entry, state, data, time);
903 action_run(acts, client, state, time);
907 void menu_frame_select_previous(ObMenuFrame *self)
909 GList *it = NULL, *start;
912 start = it = g_list_find(self->entries, self->selected);
916 it = it ? g_list_previous(it) : g_list_last(self->entries);
922 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
924 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
925 e->entry->data.normal.enabled)
930 menu_frame_select(self, it ? it->data : NULL);
933 void menu_frame_select_next(ObMenuFrame *self)
935 GList *it = NULL, *start;
938 start = it = g_list_find(self->entries, self->selected);
942 it = it ? g_list_next(it) : self->entries;
948 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
950 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
951 e->entry->data.normal.enabled)
956 menu_frame_select(self, it ? it->data : NULL);