7 #include "render/theme.h"
10 #define SEPARATOR_HEIGHT 3
11 #define MAX_MENU_WIDTH 400
13 #define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
15 #define TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
16 #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
17 ButtonPressMask | ButtonReleaseMask)
19 GList
*menu_frame_visible
;
21 static ObMenuEntryFrame
* menu_entry_frame_new(ObMenuEntry
*entry
,
23 static void menu_entry_frame_free(ObMenuEntryFrame
*self
);
24 static void menu_frame_render(ObMenuFrame
*self
);
25 static void menu_frame_update(ObMenuFrame
*self
);
27 static Window
createWindow(Window parent
, unsigned long mask
,
28 XSetWindowAttributes
*attrib
)
30 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
31 RrDepth(ob_rr_inst
), InputOutput
,
32 RrVisual(ob_rr_inst
), mask
, attrib
);
35 ObMenuFrame
* menu_frame_new(ObMenu
*menu
, ObClient
*client
)
38 XSetWindowAttributes attr
;
40 self
= g_new0(ObMenuFrame
, 1);
41 self
->type
= Window_Menu
;
43 self
->selected
= NULL
;
44 self
->show_title
= TRUE
;
45 self
->client
= client
;
47 attr
.event_mask
= FRAME_EVENTMASK
;
48 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
),
50 attr
.event_mask
= TITLE_EVENTMASK
;
51 self
->title
= createWindow(self
->window
, CWEventMask
, &attr
);
52 self
->items
= createWindow(self
->window
, 0, NULL
);
54 XMapWindow(ob_display
, self
->items
);
56 self
->a_title
= RrAppearanceCopy(ob_rr_theme
->a_menu_title
);
57 self
->a_items
= RrAppearanceCopy(ob_rr_theme
->a_menu
);
59 stacking_add(MENU_AS_WINDOW(self
));
64 void menu_frame_free(ObMenuFrame
*self
)
67 while (self
->entries
) {
68 menu_entry_frame_free(self
->entries
->data
);
69 self
->entries
= g_list_delete_link(self
->entries
, self
->entries
);
72 stacking_remove(MENU_AS_WINDOW(self
));
74 XDestroyWindow(ob_display
, self
->items
);
75 XDestroyWindow(ob_display
, self
->title
);
76 XDestroyWindow(ob_display
, self
->window
);
78 RrAppearanceFree(self
->a_items
);
79 RrAppearanceFree(self
->a_title
);
85 static ObMenuEntryFrame
* menu_entry_frame_new(ObMenuEntry
*entry
,
88 ObMenuEntryFrame
*self
;
89 XSetWindowAttributes attr
;
91 self
= g_new0(ObMenuEntryFrame
, 1);
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
);
103 XMapWindow(ob_display
, self
->window
);
104 XMapWindow(ob_display
, self
->text
);
106 self
->a_normal
= RrAppearanceCopy(ob_rr_theme
->a_menu_normal
);
107 self
->a_disabled
= RrAppearanceCopy(ob_rr_theme
->a_menu_disabled
);
108 self
->a_selected
= RrAppearanceCopy(ob_rr_theme
->a_menu_selected
);
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
;
114 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
115 self
->a_icon
->texture
[0].type
= RR_TEXTURE_RGBA
;
116 self
->a_mask
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
117 self
->a_mask
->texture
[0].type
= RR_TEXTURE_MASK
;
118 self
->a_bullet_normal
=
119 RrAppearanceCopy(ob_rr_theme
->a_menu_bullet_normal
);
120 self
->a_bullet_selected
=
121 RrAppearanceCopy(ob_rr_theme
->a_menu_bullet_selected
);
124 self
->a_text_normal
=
125 RrAppearanceCopy(ob_rr_theme
->a_menu_text_normal
);
126 self
->a_text_disabled
=
127 RrAppearanceCopy(ob_rr_theme
->a_menu_text_disabled
);
128 self
->a_text_selected
=
129 RrAppearanceCopy(ob_rr_theme
->a_menu_text_selected
);
134 static void menu_entry_frame_free(ObMenuEntryFrame
*self
)
137 XDestroyWindow(ob_display
, self
->text
);
138 XDestroyWindow(ob_display
, self
->window
);
139 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
) {
140 XDestroyWindow(ob_display
, self
->icon
);
141 XDestroyWindow(ob_display
, self
->bullet
);
144 RrAppearanceFree(self
->a_normal
);
145 RrAppearanceFree(self
->a_disabled
);
146 RrAppearanceFree(self
->a_selected
);
148 RrAppearanceFree(self
->a_separator
);
149 RrAppearanceFree(self
->a_icon
);
150 RrAppearanceFree(self
->a_mask
);
151 RrAppearanceFree(self
->a_text_normal
);
152 RrAppearanceFree(self
->a_text_disabled
);
153 RrAppearanceFree(self
->a_text_selected
);
154 RrAppearanceFree(self
->a_bullet_normal
);
155 RrAppearanceFree(self
->a_bullet_selected
);
161 void menu_frame_move(ObMenuFrame
*self
, gint x
, gint y
)
163 RECT_SET_POINT(self
->area
, x
, y
);
164 XMoveWindow(ob_display
, self
->window
, self
->area
.x
, self
->area
.y
);
167 void menu_frame_move_on_screen(ObMenuFrame
*self
)
173 for (i
= 0; i
< screen_num_monitors
; ++i
) {
174 a
= screen_physical_area_monitor(i
);
175 if (RECT_INTERSECTS_RECT(*a
, self
->area
))
178 if (!a
) a
= screen_physical_area_monitor(0);
180 dx
= MIN(0, (a
->x
+ a
->width
) - (self
->area
.x
+ self
->area
.width
));
181 dy
= MIN(0, (a
->y
+ a
->height
) - (self
->area
.y
+ self
->area
.height
));
182 if (!dx
) dx
= MAX(0, a
->x
- self
->area
.x
);
183 if (!dy
) dy
= MAX(0, a
->y
- self
->area
.y
);
188 for (f
= self
; f
; f
= f
->parent
)
189 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
190 for (f
= self
->child
; f
; f
= f
->child
)
191 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
192 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
196 static void menu_entry_frame_render(ObMenuEntryFrame
*self
)
198 RrAppearance
*item_a
, *text_a
;
201 ObMenuFrame
*frame
= self
->frame
;
203 item_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
204 !self
->entry
->data
.normal
.enabled
) ?
206 (self
== self
->frame
->selected
?
209 switch (self
->entry
->type
) {
210 case OB_MENU_ENTRY_TYPE_NORMAL
:
211 case OB_MENU_ENTRY_TYPE_SUBMENU
:
212 th
= self
->frame
->item_h
;
214 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
215 th
= SEPARATOR_HEIGHT
+ 2*PADDING
;
218 RECT_SET_SIZE(self
->area
, self
->frame
->inner_w
, th
);
219 XResizeWindow(ob_display
, self
->window
,
220 self
->area
.width
, self
->area
.height
);
221 item_a
->surface
.parent
= self
->frame
->a_items
;
222 item_a
->surface
.parentx
= self
->area
.x
;
223 item_a
->surface
.parenty
= self
->area
.y
;
224 RrPaint(item_a
, self
->window
, self
->area
.width
, self
->area
.height
);
226 text_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
227 !self
->entry
->data
.normal
.enabled
) ?
228 self
->a_text_disabled
:
229 (self
== self
->frame
->selected
?
230 self
->a_text_selected
:
231 self
->a_text_normal
));
232 switch (self
->entry
->type
) {
233 case OB_MENU_ENTRY_TYPE_NORMAL
:
234 text_a
->texture
[0].data
.text
.string
= self
->entry
->data
.normal
.label
;
236 case OB_MENU_ENTRY_TYPE_SUBMENU
:
237 sub
= self
->entry
->data
.submenu
.submenu
;
238 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
240 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
244 switch (self
->entry
->type
) {
245 case OB_MENU_ENTRY_TYPE_NORMAL
:
246 XMoveResizeWindow(ob_display
, self
->text
,
247 self
->frame
->text_x
, PADDING
,
249 self
->frame
->item_h
- 2*PADDING
);
250 text_a
->surface
.parent
= item_a
;
251 text_a
->surface
.parentx
= self
->frame
->text_x
;
252 text_a
->surface
.parenty
= PADDING
;
253 RrPaint(text_a
, self
->text
, self
->frame
->text_w
,
254 self
->frame
->item_h
- 2*PADDING
);
256 case OB_MENU_ENTRY_TYPE_SUBMENU
:
257 XMoveResizeWindow(ob_display
, self
->text
,
258 self
->frame
->text_x
, PADDING
,
259 self
->frame
->text_w
- self
->frame
->item_h
,
260 self
->frame
->item_h
- 2*PADDING
);
261 text_a
->surface
.parent
= item_a
;
262 text_a
->surface
.parentx
= self
->frame
->text_x
;
263 text_a
->surface
.parenty
= PADDING
;
264 RrPaint(text_a
, self
->text
, self
->frame
->text_w
- self
->frame
->item_h
,
265 self
->frame
->item_h
- 2*PADDING
);
267 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
268 XMoveResizeWindow(ob_display
, self
->text
, PADDING
, PADDING
,
269 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
270 self
->a_separator
->surface
.parent
= item_a
;
271 self
->a_separator
->surface
.parentx
= PADDING
;
272 self
->a_separator
->surface
.parenty
= PADDING
;
273 self
->a_separator
->texture
[0].data
.lineart
.color
=
274 text_a
->texture
[0].data
.text
.color
;
275 self
->a_separator
->texture
[0].data
.lineart
.x1
= 2*PADDING
;
276 self
->a_separator
->texture
[0].data
.lineart
.y1
= SEPARATOR_HEIGHT
/ 2;
277 self
->a_separator
->texture
[0].data
.lineart
.x2
=
278 self
->area
.width
- 4*PADDING
;
279 self
->a_separator
->texture
[0].data
.lineart
.y2
= SEPARATOR_HEIGHT
/ 2;
280 RrPaint(self
->a_separator
, self
->text
,
281 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
285 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
286 self
->entry
->data
.normal
.icon_data
)
288 XMoveResizeWindow(ob_display
, self
->icon
,
289 PADDING
, frame
->item_margin
.top
,
290 self
->frame
->item_h
- frame
->item_margin
.top
291 - frame
->item_margin
.bottom
,
292 self
->frame
->item_h
- frame
->item_margin
.top
293 - frame
->item_margin
.bottom
);
294 self
->a_icon
->texture
[0].data
.rgba
.width
=
295 self
->entry
->data
.normal
.icon_width
;
296 self
->a_icon
->texture
[0].data
.rgba
.height
=
297 self
->entry
->data
.normal
.icon_height
;
298 self
->a_icon
->texture
[0].data
.rgba
.data
=
299 self
->entry
->data
.normal
.icon_data
;
300 self
->a_icon
->surface
.parent
= item_a
;
301 self
->a_icon
->surface
.parentx
= PADDING
;
302 self
->a_icon
->surface
.parenty
= frame
->item_margin
.top
;
303 RrPaint(self
->a_icon
, self
->icon
,
304 self
->frame
->item_h
- frame
->item_margin
.top
305 - frame
->item_margin
.bottom
,
306 self
->frame
->item_h
- frame
->item_margin
.top
307 - frame
->item_margin
.bottom
);
308 XMapWindow(ob_display
, self
->icon
);
309 } else if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
310 self
->entry
->data
.normal
.mask
)
314 XMoveResizeWindow(ob_display
, self
->icon
,
315 PADDING
, frame
->item_margin
.top
,
316 self
->frame
->item_h
- frame
->item_margin
.top
317 - frame
->item_margin
.bottom
,
318 self
->frame
->item_h
- frame
->item_margin
.top
319 - frame
->item_margin
.bottom
);
320 self
->a_mask
->texture
[0].data
.mask
.mask
=
321 self
->entry
->data
.normal
.mask
;
323 c
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
324 !self
->entry
->data
.normal
.enabled
) ?
325 self
->entry
->data
.normal
.mask_disabled_color
:
326 (self
== self
->frame
->selected
?
327 self
->entry
->data
.normal
.mask_selected_color
:
328 self
->entry
->data
.normal
.mask_normal_color
));
329 self
->a_mask
->texture
[0].data
.mask
.color
= c
;
331 self
->a_mask
->surface
.parent
= item_a
;
332 self
->a_mask
->surface
.parentx
= PADDING
;
333 self
->a_mask
->surface
.parenty
= frame
->item_margin
.top
;
334 RrPaint(self
->a_mask
, self
->icon
,
335 self
->frame
->item_h
- frame
->item_margin
.top
336 - frame
->item_margin
.bottom
,
337 self
->frame
->item_h
- frame
->item_margin
.top
338 - frame
->item_margin
.bottom
);
339 XMapWindow(ob_display
, self
->icon
);
341 XUnmapWindow(ob_display
, self
->icon
);
343 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
) {
344 RrAppearance
*bullet_a
;
345 XMoveResizeWindow(ob_display
, self
->bullet
,
346 self
->frame
->text_x
+ self
->frame
->text_w
347 - self
->frame
->item_h
+ PADDING
, PADDING
,
348 self
->frame
->item_h
- 2*PADDING
,
349 self
->frame
->item_h
- 2*PADDING
);
350 bullet_a
= (self
== self
->frame
->selected
?
351 self
->a_bullet_selected
:
352 self
->a_bullet_normal
);
353 bullet_a
->surface
.parent
= item_a
;
354 bullet_a
->surface
.parentx
=
355 self
->frame
->text_x
+ self
->frame
->text_w
- self
->frame
->item_h
357 bullet_a
->surface
.parenty
= PADDING
;
358 RrPaint(bullet_a
, self
->bullet
,
359 self
->frame
->item_h
- 2*PADDING
,
360 self
->frame
->item_h
- 2*PADDING
);
361 XMapWindow(ob_display
, self
->bullet
);
363 XUnmapWindow(ob_display
, self
->bullet
);
368 static void menu_frame_render(ObMenuFrame
*self
)
372 gint tw
, th
; /* temps */
374 gboolean has_icon
= FALSE
;
377 XSetWindowBorderWidth(ob_display
, self
->window
, ob_rr_theme
->bwidth
);
378 XSetWindowBorder(ob_display
, self
->window
,
379 RrColorPixel(ob_rr_theme
->b_color
));
381 if (!self
->parent
&& self
->show_title
) {
382 XMoveWindow(ob_display
, self
->title
,
383 -ob_rr_theme
->bwidth
, h
- ob_rr_theme
->bwidth
);
385 self
->a_title
->texture
[0].data
.text
.string
= self
->menu
->title
;
386 RrMinsize(self
->a_title
, &tw
, &th
);
387 tw
= MIN(tw
, MAX_MENU_WIDTH
);
391 h
+= (self
->title_h
= th
+ ob_rr_theme
->bwidth
);
393 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
394 XSetWindowBorder(ob_display
, self
->title
,
395 RrColorPixel(ob_rr_theme
->b_color
));
398 XMoveWindow(ob_display
, self
->items
, 0, h
);
400 STRUT_SET(self
->item_margin
, 0, 0, 0, 0);
403 ObMenuEntryFrame
*e
= self
->entries
->data
;
406 e
->a_text_normal
->texture
[0].data
.text
.string
= "";
407 RrMinsize(e
->a_text_normal
, &tw
, &th
);
412 RrMargins(e
->a_normal
, &l
, &t
, &r
, &b
);
413 STRUT_SET(self
->item_margin
,
414 MAX(self
->item_margin
.left
, l
),
415 MAX(self
->item_margin
.top
, t
),
416 MAX(self
->item_margin
.right
, r
),
417 MAX(self
->item_margin
.bottom
, b
));
418 RrMargins(e
->a_selected
, &l
, &t
, &r
, &b
);
419 STRUT_SET(self
->item_margin
,
420 MAX(self
->item_margin
.left
, l
),
421 MAX(self
->item_margin
.top
, t
),
422 MAX(self
->item_margin
.right
, r
),
423 MAX(self
->item_margin
.bottom
, b
));
424 RrMargins(e
->a_disabled
, &l
, &t
, &r
, &b
);
425 STRUT_SET(self
->item_margin
,
426 MAX(self
->item_margin
.left
, l
),
427 MAX(self
->item_margin
.top
, t
),
428 MAX(self
->item_margin
.right
, r
),
429 MAX(self
->item_margin
.bottom
, b
));
433 for (it
= self
->entries
; it
; it
= g_list_next(it
)) {
434 RrAppearance
*text_a
;
435 ObMenuEntryFrame
*e
= it
->data
;
437 RECT_SET_POINT(e
->area
, 0, allitems_h
);
438 XMoveWindow(ob_display
, e
->window
, 0, e
->area
.y
);
440 text_a
= ((e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
441 !e
->entry
->data
.normal
.enabled
) ?
443 (e
== self
->selected
?
446 switch (e
->entry
->type
) {
447 case OB_MENU_ENTRY_TYPE_NORMAL
:
448 text_a
->texture
[0].data
.text
.string
= e
->entry
->data
.normal
.label
;
449 RrMinsize(text_a
, &tw
, &th
);
450 tw
= MIN(tw
, MAX_MENU_WIDTH
);
452 if (e
->entry
->data
.normal
.icon_data
||
453 e
->entry
->data
.normal
.mask
)
456 case OB_MENU_ENTRY_TYPE_SUBMENU
:
457 sub
= e
->entry
->data
.submenu
.submenu
;
458 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
459 RrMinsize(text_a
, &tw
, &th
);
460 tw
= MIN(tw
, MAX_MENU_WIDTH
);
462 if (e
->entry
->data
.normal
.icon_data
||
463 e
->entry
->data
.normal
.mask
)
466 tw
+= self
->item_h
- PADDING
;
468 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
470 th
= SEPARATOR_HEIGHT
;
480 self
->text_x
= PADDING
;
485 w
+= self
->item_h
+ PADDING
;
486 self
->text_x
+= self
->item_h
+ PADDING
;
496 XResizeWindow(ob_display
, self
->window
, w
, h
);
497 XResizeWindow(ob_display
, self
->items
, w
, allitems_h
);
501 if (!self
->parent
&& self
->show_title
) {
502 XResizeWindow(ob_display
, self
->title
,
503 w
, self
->title_h
- ob_rr_theme
->bwidth
);
504 RrPaint(self
->a_title
, self
->title
,
505 w
, self
->title_h
- ob_rr_theme
->bwidth
);
506 XMapWindow(ob_display
, self
->title
);
508 XUnmapWindow(ob_display
, self
->title
);
510 RrPaint(self
->a_items
, self
->items
, w
, allitems_h
);
512 for (it
= self
->entries
; it
; it
= g_list_next(it
))
513 menu_entry_frame_render(it
->data
);
515 w
+= ob_rr_theme
->bwidth
* 2;
516 h
+= ob_rr_theme
->bwidth
* 2;
518 RECT_SET_SIZE(self
->area
, w
, h
);
523 static void menu_frame_update(ObMenuFrame
*self
)
527 menu_pipe_execute(self
->menu
);
528 menu_find_submenus(self
->menu
);
530 self
->selected
= NULL
;
532 for (mit
= self
->menu
->entries
, fit
= self
->entries
; mit
&& fit
;
533 mit
= g_list_next(mit
), fit
= g_list_next(fit
))
535 ObMenuEntryFrame
*f
= fit
->data
;
536 f
->entry
= mit
->data
;
540 ObMenuEntryFrame
*e
= menu_entry_frame_new(mit
->data
, self
);
541 self
->entries
= g_list_append(self
->entries
, e
);
542 mit
= g_list_next(mit
);
546 GList
*n
= g_list_next(fit
);
547 menu_entry_frame_free(fit
->data
);
548 self
->entries
= g_list_delete_link(self
->entries
, fit
);
552 menu_frame_render(self
);
555 void menu_frame_show(ObMenuFrame
*self
, ObMenuFrame
*parent
)
559 if (g_list_find(menu_frame_visible
, self
))
564 menu_frame_hide(parent
->child
);
565 parent
->child
= self
;
567 self
->parent
= parent
;
569 if (menu_frame_visible
== NULL
) {
570 /* no menus shown yet */
571 grab_pointer(TRUE
, OB_CURSOR_NONE
);
575 /* determine if the underlying menu is already visible */
576 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
577 ObMenuFrame
*f
= it
->data
;
578 if (f
->menu
== self
->menu
)
582 if (self
->menu
->update_func
)
583 self
->menu
->update_func(self
, self
->menu
->data
);
586 menu_frame_visible
= g_list_prepend(menu_frame_visible
, self
);
587 menu_frame_update(self
);
589 menu_frame_move_on_screen(self
);
591 XMapWindow(ob_display
, self
->window
);
594 void menu_frame_hide(ObMenuFrame
*self
)
596 GList
*it
= g_list_find(menu_frame_visible
, self
);
602 menu_frame_hide(self
->child
);
605 self
->parent
->child
= NULL
;
608 menu_frame_visible
= g_list_delete_link(menu_frame_visible
, it
);
610 if (menu_frame_visible
== NULL
) {
611 /* last menu shown */
612 grab_pointer(FALSE
, OB_CURSOR_NONE
);
613 grab_keyboard(FALSE
);
616 XUnmapWindow(ob_display
, self
->window
);
618 menu_frame_free(self
);
621 void menu_frame_hide_all()
623 GList
*it
= g_list_last(menu_frame_visible
);
625 menu_frame_hide(it
->data
);
628 void menu_frame_hide_all_client(ObClient
*client
)
630 GList
*it
= g_list_last(menu_frame_visible
);
632 ObMenuFrame
*f
= it
->data
;
633 if (f
->client
== client
)
639 ObMenuFrame
* menu_frame_under(gint x
, gint y
)
641 ObMenuFrame
*ret
= NULL
;
644 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
645 ObMenuFrame
*f
= it
->data
;
647 if (RECT_CONTAINS(f
->area
, x
, y
)) {
655 ObMenuEntryFrame
* menu_entry_frame_under(gint x
, gint y
)
658 ObMenuEntryFrame
*ret
= NULL
;
661 if ((frame
= menu_frame_under(x
, y
))) {
662 x
-= ob_rr_theme
->bwidth
+ frame
->area
.x
;
663 y
-= frame
->title_h
+ ob_rr_theme
->bwidth
+ frame
->area
.y
;
665 for (it
= frame
->entries
; it
; it
= g_list_next(it
)) {
666 ObMenuEntryFrame
*e
= it
->data
;
668 if (RECT_CONTAINS(e
->area
, x
, y
)) {
677 void menu_frame_select(ObMenuFrame
*self
, ObMenuEntryFrame
*entry
)
679 ObMenuEntryFrame
*old
= self
->selected
;
680 ObMenuFrame
*oldchild
= self
->child
;
682 if (entry
&& entry
->entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
)
685 if (old
== entry
) return;
687 self
->selected
= entry
;
690 menu_entry_frame_render(old
);
692 menu_frame_hide(oldchild
);
694 if (self
->selected
) {
695 menu_entry_frame_render(self
->selected
);
697 if (self
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
698 menu_entry_frame_show_submenu(self
->selected
);
702 void menu_entry_frame_show_submenu(ObMenuEntryFrame
*self
)
706 if (!self
->entry
->data
.submenu
.submenu
) return;
708 f
= menu_frame_new(self
->entry
->data
.submenu
.submenu
,
709 self
->frame
->client
);
711 self
->frame
->area
.x
+ self
->frame
->area
.width
712 - ob_rr_theme
->menu_overlap
- ob_rr_theme
->bwidth
,
713 self
->frame
->area
.y
+ self
->frame
->title_h
+
714 self
->area
.y
+ ob_rr_theme
->menu_overlap
);
715 menu_frame_show(f
, self
->frame
);
718 void menu_entry_frame_execute(ObMenuEntryFrame
*self
, guint state
)
720 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
721 self
->entry
->data
.normal
.enabled
)
723 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
725 ObMenuEntry
*entry
= self
->entry
;
726 ObMenuExecuteFunc func
= self
->frame
->menu
->execute_func
;
727 gpointer data
= self
->frame
->menu
->data
;
728 GSList
*acts
= self
->entry
->data
.normal
.actions
;
729 ObClient
*client
= self
->frame
->client
;
731 /* release grabs before executing the shit */
732 if (!(state
& ControlMask
))
733 menu_frame_hide_all();
736 func(entry
, state
, data
);
740 for (it
= acts
; it
; it
= g_slist_next(it
))
741 action_run(it
->data
, client
, state
);
746 void menu_frame_select_previous(ObMenuFrame
*self
)
748 GList
*it
= NULL
, *start
;
751 start
= it
= g_list_find(self
->entries
, self
->selected
);
755 it
= it
? g_list_previous(it
) : g_list_last(self
->entries
);
761 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
763 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
764 e
->entry
->data
.normal
.enabled
)
769 menu_frame_select(self
, it
? it
->data
: NULL
);
772 void menu_frame_select_next(ObMenuFrame
*self
)
774 GList
*it
= NULL
, *start
;
777 start
= it
= g_list_find(self
->entries
, self
->selected
);
781 it
= it
? g_list_next(it
) : self
->entries
;
787 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
789 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
790 e
->entry
->data
.normal
.enabled
)
795 menu_frame_select(self
, it
? it
->data
: NULL
);