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
);
366 static void menu_frame_render(ObMenuFrame
*self
)
370 gint tw
, th
; /* temps */
372 gboolean has_icon
= FALSE
;
375 XSetWindowBorderWidth(ob_display
, self
->window
, ob_rr_theme
->bwidth
);
376 XSetWindowBorder(ob_display
, self
->window
,
377 RrColorPixel(ob_rr_theme
->b_color
));
379 if (!self
->parent
&& self
->show_title
) {
380 XMoveWindow(ob_display
, self
->title
,
381 -ob_rr_theme
->bwidth
, h
- ob_rr_theme
->bwidth
);
383 self
->a_title
->texture
[0].data
.text
.string
= self
->menu
->title
;
384 RrMinsize(self
->a_title
, &tw
, &th
);
385 tw
= MIN(tw
, MAX_MENU_WIDTH
);
389 h
+= (self
->title_h
= th
+ ob_rr_theme
->bwidth
);
391 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
392 XSetWindowBorder(ob_display
, self
->title
,
393 RrColorPixel(ob_rr_theme
->b_color
));
396 XMoveWindow(ob_display
, self
->items
, 0, h
);
398 STRUT_SET(self
->item_margin
, 0, 0, 0, 0);
401 ObMenuEntryFrame
*e
= self
->entries
->data
;
404 e
->a_text_normal
->texture
[0].data
.text
.string
= "";
405 RrMinsize(e
->a_text_normal
, &tw
, &th
);
410 RrMargins(e
->a_normal
, &l
, &t
, &r
, &b
);
411 STRUT_SET(self
->item_margin
,
412 MAX(self
->item_margin
.left
, l
),
413 MAX(self
->item_margin
.top
, t
),
414 MAX(self
->item_margin
.right
, r
),
415 MAX(self
->item_margin
.bottom
, b
));
416 RrMargins(e
->a_selected
, &l
, &t
, &r
, &b
);
417 STRUT_SET(self
->item_margin
,
418 MAX(self
->item_margin
.left
, l
),
419 MAX(self
->item_margin
.top
, t
),
420 MAX(self
->item_margin
.right
, r
),
421 MAX(self
->item_margin
.bottom
, b
));
422 RrMargins(e
->a_disabled
, &l
, &t
, &r
, &b
);
423 STRUT_SET(self
->item_margin
,
424 MAX(self
->item_margin
.left
, l
),
425 MAX(self
->item_margin
.top
, t
),
426 MAX(self
->item_margin
.right
, r
),
427 MAX(self
->item_margin
.bottom
, b
));
431 for (it
= self
->entries
; it
; it
= g_list_next(it
)) {
432 RrAppearance
*text_a
;
433 ObMenuEntryFrame
*e
= it
->data
;
435 RECT_SET_POINT(e
->area
, 0, allitems_h
);
436 XMoveWindow(ob_display
, e
->window
, 0, e
->area
.y
);
438 text_a
= ((e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
439 !e
->entry
->data
.normal
.enabled
) ?
441 (e
== self
->selected
?
444 switch (e
->entry
->type
) {
445 case OB_MENU_ENTRY_TYPE_NORMAL
:
446 text_a
->texture
[0].data
.text
.string
= e
->entry
->data
.normal
.label
;
447 RrMinsize(text_a
, &tw
, &th
);
448 tw
= MIN(tw
, MAX_MENU_WIDTH
);
450 if (e
->entry
->data
.normal
.icon_data
||
451 e
->entry
->data
.normal
.mask
)
454 case OB_MENU_ENTRY_TYPE_SUBMENU
:
455 sub
= e
->entry
->data
.submenu
.submenu
;
456 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
457 RrMinsize(text_a
, &tw
, &th
);
458 tw
= MIN(tw
, MAX_MENU_WIDTH
);
460 if (e
->entry
->data
.normal
.icon_data
||
461 e
->entry
->data
.normal
.mask
)
464 tw
+= self
->item_h
- PADDING
;
466 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
468 th
= SEPARATOR_HEIGHT
;
478 self
->text_x
= PADDING
;
483 w
+= self
->item_h
+ PADDING
;
484 self
->text_x
+= self
->item_h
+ PADDING
;
494 XResizeWindow(ob_display
, self
->window
, w
, h
);
495 XResizeWindow(ob_display
, self
->items
, w
, allitems_h
);
499 if (!self
->parent
&& self
->show_title
) {
500 XResizeWindow(ob_display
, self
->title
,
501 w
, self
->title_h
- ob_rr_theme
->bwidth
);
502 RrPaint(self
->a_title
, self
->title
,
503 w
, self
->title_h
- ob_rr_theme
->bwidth
);
504 XMapWindow(ob_display
, self
->title
);
506 XUnmapWindow(ob_display
, self
->title
);
508 RrPaint(self
->a_items
, self
->items
, w
, allitems_h
);
510 for (it
= self
->entries
; it
; it
= g_list_next(it
))
511 menu_entry_frame_render(it
->data
);
513 w
+= ob_rr_theme
->bwidth
* 2;
514 h
+= ob_rr_theme
->bwidth
* 2;
516 RECT_SET_SIZE(self
->area
, w
, h
);
519 static void menu_frame_update(ObMenuFrame
*self
)
523 menu_pipe_execute(self
->menu
);
524 menu_find_submenus(self
->menu
);
526 self
->selected
= NULL
;
528 for (mit
= self
->menu
->entries
, fit
= self
->entries
; mit
&& fit
;
529 mit
= g_list_next(mit
), fit
= g_list_next(fit
))
531 ObMenuEntryFrame
*f
= fit
->data
;
532 f
->entry
= mit
->data
;
536 ObMenuEntryFrame
*e
= menu_entry_frame_new(mit
->data
, self
);
537 self
->entries
= g_list_append(self
->entries
, e
);
538 mit
= g_list_next(mit
);
542 GList
*n
= g_list_next(fit
);
543 menu_entry_frame_free(fit
->data
);
544 self
->entries
= g_list_delete_link(self
->entries
, fit
);
548 menu_frame_render(self
);
551 void menu_frame_show(ObMenuFrame
*self
, ObMenuFrame
*parent
)
555 if (g_list_find(menu_frame_visible
, self
))
560 menu_frame_hide(parent
->child
);
561 parent
->child
= self
;
563 self
->parent
= parent
;
565 if (menu_frame_visible
== NULL
) {
566 /* no menus shown yet */
567 grab_pointer(TRUE
, OB_CURSOR_NONE
);
571 /* determine if the underlying menu is already visible */
572 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
573 ObMenuFrame
*f
= it
->data
;
574 if (f
->menu
== self
->menu
)
578 if (self
->menu
->update_func
)
579 self
->menu
->update_func(self
, self
->menu
->data
);
582 menu_frame_visible
= g_list_prepend(menu_frame_visible
, self
);
583 menu_frame_update(self
);
585 menu_frame_move_on_screen(self
);
587 XMapWindow(ob_display
, self
->window
);
590 void menu_frame_hide(ObMenuFrame
*self
)
592 GList
*it
= g_list_find(menu_frame_visible
, self
);
598 menu_frame_hide(self
->child
);
601 self
->parent
->child
= NULL
;
604 menu_frame_visible
= g_list_delete_link(menu_frame_visible
, it
);
606 if (menu_frame_visible
== NULL
) {
607 /* last menu shown */
608 grab_pointer(FALSE
, OB_CURSOR_NONE
);
609 grab_keyboard(FALSE
);
612 XUnmapWindow(ob_display
, self
->window
);
614 menu_frame_free(self
);
617 void menu_frame_hide_all()
619 GList
*it
= g_list_last(menu_frame_visible
);
621 menu_frame_hide(it
->data
);
624 void menu_frame_hide_all_client(ObClient
*client
)
626 GList
*it
= g_list_last(menu_frame_visible
);
628 ObMenuFrame
*f
= it
->data
;
629 if (f
->client
== client
)
635 ObMenuFrame
* menu_frame_under(gint x
, gint y
)
637 ObMenuFrame
*ret
= NULL
;
640 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
641 ObMenuFrame
*f
= it
->data
;
643 if (RECT_CONTAINS(f
->area
, x
, y
)) {
651 ObMenuEntryFrame
* menu_entry_frame_under(gint x
, gint y
)
654 ObMenuEntryFrame
*ret
= NULL
;
657 if ((frame
= menu_frame_under(x
, y
))) {
658 x
-= ob_rr_theme
->bwidth
+ frame
->area
.x
;
659 y
-= frame
->title_h
+ ob_rr_theme
->bwidth
+ frame
->area
.y
;
661 for (it
= frame
->entries
; it
; it
= g_list_next(it
)) {
662 ObMenuEntryFrame
*e
= it
->data
;
664 if (RECT_CONTAINS(e
->area
, x
, y
)) {
673 void menu_frame_select(ObMenuFrame
*self
, ObMenuEntryFrame
*entry
)
675 ObMenuEntryFrame
*old
= self
->selected
;
676 ObMenuFrame
*oldchild
= self
->child
;
678 if (entry
&& entry
->entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
)
681 if (old
== entry
) return;
683 self
->selected
= entry
;
686 menu_entry_frame_render(old
);
688 menu_frame_hide(oldchild
);
690 if (self
->selected
) {
691 menu_entry_frame_render(self
->selected
);
693 if (self
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
694 menu_entry_frame_show_submenu(self
->selected
);
698 void menu_entry_frame_show_submenu(ObMenuEntryFrame
*self
)
702 if (!self
->entry
->data
.submenu
.submenu
) return;
704 f
= menu_frame_new(self
->entry
->data
.submenu
.submenu
,
705 self
->frame
->client
);
707 self
->frame
->area
.x
+ self
->frame
->area
.width
708 - ob_rr_theme
->menu_overlap
- ob_rr_theme
->bwidth
,
709 self
->frame
->area
.y
+ self
->frame
->title_h
+
710 self
->area
.y
+ ob_rr_theme
->menu_overlap
);
711 menu_frame_show(f
, self
->frame
);
714 void menu_entry_frame_execute(ObMenuEntryFrame
*self
, gboolean hide
)
716 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
717 self
->entry
->data
.normal
.enabled
)
719 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
721 ObMenuEntry
*entry
= self
->entry
;
722 ObMenuExecuteFunc func
= self
->frame
->menu
->execute_func
;
723 gpointer data
= self
->frame
->menu
->data
;
724 GSList
*acts
= self
->entry
->data
.normal
.actions
;
725 ObClient
*client
= self
->frame
->client
;
727 /* release grabs before executing the shit */
729 menu_frame_hide_all();
736 for (it
= acts
; it
; it
= g_slist_next(it
))
738 ObAction
*act
= it
->data
;
739 act
->data
.any
.c
= client
;
741 if (act
->func
== action_moveresize
)
742 screen_pointer_pos(&act
->data
.moveresize
.x
,
743 &act
->data
.moveresize
.y
);
745 if (!(act
->func
== action_cycle_windows
||
746 act
->func
== action_desktop_dir
||
747 act
->func
== action_send_to_desktop_dir
||
748 act
->func
== action_showmenu
))
750 act
->func(&act
->data
);
757 void menu_frame_select_previous(ObMenuFrame
*self
)
759 GList
*it
= NULL
, *start
;
762 start
= it
= g_list_find(self
->entries
, self
->selected
);
766 it
= it
? g_list_previous(it
) : g_list_last(self
->entries
);
772 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
774 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
775 e
->entry
->data
.normal
.enabled
)
780 menu_frame_select(self
, it
? it
->data
: NULL
);
783 void menu_frame_select_next(ObMenuFrame
*self
)
785 GList
*it
= NULL
, *start
;
788 start
= it
= g_list_find(self
->entries
, self
->selected
);
792 it
= it
? g_list_next(it
) : self
->entries
;
798 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
800 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
801 e
->entry
->data
.normal
.enabled
)
806 menu_frame_select(self
, it
? it
->data
: NULL
);