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
)
174 for (i
= 0; i
< screen_num_monitors
; ++i
) {
175 a
= screen_physical_area_monitor(i
);
176 if (RECT_INTERSECTS_RECT(*a
, self
->area
))
179 if (!a
) a
= screen_physical_area_monitor(0);
181 half
= g_list_length(self
->entries
) / 2;
182 pos
= g_list_index(self
->entries
, self
->selected
);
184 /* if in the bottom half then check this shit first, will keep the bottom
185 edge of the menu visible */
187 dx
= MAX(dx
, a
->x
- self
->area
.x
);
188 dy
= MAX(dy
, a
->y
- self
->area
.y
);
190 dx
= MIN(dx
, (a
->x
+ a
->width
) - (self
->area
.x
+ self
->area
.width
));
191 dy
= MIN(dy
, (a
->y
+ a
->height
) - (self
->area
.y
+ self
->area
.height
));
192 /* if in the top half then check this shit last, will keep the top
193 edge of the menu visible */
195 dx
= MAX(dx
, a
->x
- self
->area
.x
);
196 dy
= MAX(dy
, a
->y
- self
->area
.y
);
202 for (f
= self
; f
; f
= f
->parent
)
203 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
204 for (f
= self
->child
; f
; f
= f
->child
)
205 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
206 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
210 static void menu_entry_frame_render(ObMenuEntryFrame
*self
)
212 RrAppearance
*item_a
, *text_a
;
215 ObMenuFrame
*frame
= self
->frame
;
217 item_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
218 !self
->entry
->data
.normal
.enabled
) ?
220 (self
== self
->frame
->selected
?
223 switch (self
->entry
->type
) {
224 case OB_MENU_ENTRY_TYPE_NORMAL
:
225 case OB_MENU_ENTRY_TYPE_SUBMENU
:
226 th
= self
->frame
->item_h
;
228 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
229 th
= SEPARATOR_HEIGHT
+ 2*PADDING
;
232 RECT_SET_SIZE(self
->area
, self
->frame
->inner_w
, th
);
233 XResizeWindow(ob_display
, self
->window
,
234 self
->area
.width
, self
->area
.height
);
235 item_a
->surface
.parent
= self
->frame
->a_items
;
236 item_a
->surface
.parentx
= self
->area
.x
;
237 item_a
->surface
.parenty
= self
->area
.y
;
238 RrPaint(item_a
, self
->window
, self
->area
.width
, self
->area
.height
);
240 text_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
241 !self
->entry
->data
.normal
.enabled
) ?
242 self
->a_text_disabled
:
243 (self
== self
->frame
->selected
?
244 self
->a_text_selected
:
245 self
->a_text_normal
));
246 switch (self
->entry
->type
) {
247 case OB_MENU_ENTRY_TYPE_NORMAL
:
248 text_a
->texture
[0].data
.text
.string
= self
->entry
->data
.normal
.label
;
250 case OB_MENU_ENTRY_TYPE_SUBMENU
:
251 sub
= self
->entry
->data
.submenu
.submenu
;
252 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
254 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
258 switch (self
->entry
->type
) {
259 case OB_MENU_ENTRY_TYPE_NORMAL
:
260 XMoveResizeWindow(ob_display
, self
->text
,
261 self
->frame
->text_x
, PADDING
,
263 self
->frame
->item_h
- 2*PADDING
);
264 text_a
->surface
.parent
= item_a
;
265 text_a
->surface
.parentx
= self
->frame
->text_x
;
266 text_a
->surface
.parenty
= PADDING
;
267 RrPaint(text_a
, self
->text
, self
->frame
->text_w
,
268 self
->frame
->item_h
- 2*PADDING
);
270 case OB_MENU_ENTRY_TYPE_SUBMENU
:
271 XMoveResizeWindow(ob_display
, self
->text
,
272 self
->frame
->text_x
, PADDING
,
273 self
->frame
->text_w
- self
->frame
->item_h
,
274 self
->frame
->item_h
- 2*PADDING
);
275 text_a
->surface
.parent
= item_a
;
276 text_a
->surface
.parentx
= self
->frame
->text_x
;
277 text_a
->surface
.parenty
= PADDING
;
278 RrPaint(text_a
, self
->text
, self
->frame
->text_w
- self
->frame
->item_h
,
279 self
->frame
->item_h
- 2*PADDING
);
281 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
282 XMoveResizeWindow(ob_display
, self
->text
, PADDING
, PADDING
,
283 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
284 self
->a_separator
->surface
.parent
= item_a
;
285 self
->a_separator
->surface
.parentx
= PADDING
;
286 self
->a_separator
->surface
.parenty
= PADDING
;
287 self
->a_separator
->texture
[0].data
.lineart
.color
=
288 text_a
->texture
[0].data
.text
.color
;
289 self
->a_separator
->texture
[0].data
.lineart
.x1
= 2*PADDING
;
290 self
->a_separator
->texture
[0].data
.lineart
.y1
= SEPARATOR_HEIGHT
/ 2;
291 self
->a_separator
->texture
[0].data
.lineart
.x2
=
292 self
->area
.width
- 4*PADDING
;
293 self
->a_separator
->texture
[0].data
.lineart
.y2
= SEPARATOR_HEIGHT
/ 2;
294 RrPaint(self
->a_separator
, self
->text
,
295 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
299 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
300 self
->entry
->data
.normal
.icon_data
)
302 XMoveResizeWindow(ob_display
, self
->icon
,
303 PADDING
, frame
->item_margin
.top
,
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 self
->a_icon
->texture
[0].data
.rgba
.width
=
309 self
->entry
->data
.normal
.icon_width
;
310 self
->a_icon
->texture
[0].data
.rgba
.height
=
311 self
->entry
->data
.normal
.icon_height
;
312 self
->a_icon
->texture
[0].data
.rgba
.data
=
313 self
->entry
->data
.normal
.icon_data
;
314 self
->a_icon
->surface
.parent
= item_a
;
315 self
->a_icon
->surface
.parentx
= PADDING
;
316 self
->a_icon
->surface
.parenty
= frame
->item_margin
.top
;
317 RrPaint(self
->a_icon
, self
->icon
,
318 self
->frame
->item_h
- frame
->item_margin
.top
319 - frame
->item_margin
.bottom
,
320 self
->frame
->item_h
- frame
->item_margin
.top
321 - frame
->item_margin
.bottom
);
322 XMapWindow(ob_display
, self
->icon
);
323 } else if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
324 self
->entry
->data
.normal
.mask
)
328 XMoveResizeWindow(ob_display
, self
->icon
,
329 PADDING
, frame
->item_margin
.top
,
330 self
->frame
->item_h
- frame
->item_margin
.top
331 - frame
->item_margin
.bottom
,
332 self
->frame
->item_h
- frame
->item_margin
.top
333 - frame
->item_margin
.bottom
);
334 self
->a_mask
->texture
[0].data
.mask
.mask
=
335 self
->entry
->data
.normal
.mask
;
337 c
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
338 !self
->entry
->data
.normal
.enabled
) ?
339 self
->entry
->data
.normal
.mask_disabled_color
:
340 (self
== self
->frame
->selected
?
341 self
->entry
->data
.normal
.mask_selected_color
:
342 self
->entry
->data
.normal
.mask_normal_color
));
343 self
->a_mask
->texture
[0].data
.mask
.color
= c
;
345 self
->a_mask
->surface
.parent
= item_a
;
346 self
->a_mask
->surface
.parentx
= PADDING
;
347 self
->a_mask
->surface
.parenty
= frame
->item_margin
.top
;
348 RrPaint(self
->a_mask
, self
->icon
,
349 self
->frame
->item_h
- frame
->item_margin
.top
350 - frame
->item_margin
.bottom
,
351 self
->frame
->item_h
- frame
->item_margin
.top
352 - frame
->item_margin
.bottom
);
353 XMapWindow(ob_display
, self
->icon
);
355 XUnmapWindow(ob_display
, self
->icon
);
357 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
) {
358 RrAppearance
*bullet_a
;
359 XMoveResizeWindow(ob_display
, self
->bullet
,
360 self
->frame
->text_x
+ self
->frame
->text_w
361 - self
->frame
->item_h
+ PADDING
, PADDING
,
362 self
->frame
->item_h
- 2*PADDING
,
363 self
->frame
->item_h
- 2*PADDING
);
364 bullet_a
= (self
== self
->frame
->selected
?
365 self
->a_bullet_selected
:
366 self
->a_bullet_normal
);
367 bullet_a
->surface
.parent
= item_a
;
368 bullet_a
->surface
.parentx
=
369 self
->frame
->text_x
+ self
->frame
->text_w
- self
->frame
->item_h
371 bullet_a
->surface
.parenty
= PADDING
;
372 RrPaint(bullet_a
, self
->bullet
,
373 self
->frame
->item_h
- 2*PADDING
,
374 self
->frame
->item_h
- 2*PADDING
);
375 XMapWindow(ob_display
, self
->bullet
);
377 XUnmapWindow(ob_display
, self
->bullet
);
382 static void menu_frame_render(ObMenuFrame
*self
)
386 gint tw
, th
; /* temps */
388 gboolean has_icon
= FALSE
;
391 XSetWindowBorderWidth(ob_display
, self
->window
, ob_rr_theme
->bwidth
);
392 XSetWindowBorder(ob_display
, self
->window
,
393 RrColorPixel(ob_rr_theme
->b_color
));
395 if (!self
->parent
&& self
->show_title
) {
396 XMoveWindow(ob_display
, self
->title
,
397 -ob_rr_theme
->bwidth
, h
- ob_rr_theme
->bwidth
);
399 self
->a_title
->texture
[0].data
.text
.string
= self
->menu
->title
;
400 RrMinsize(self
->a_title
, &tw
, &th
);
401 tw
= MIN(tw
, MAX_MENU_WIDTH
);
403 h
+= (self
->title_h
= th
+ ob_rr_theme
->bwidth
);
405 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
406 XSetWindowBorder(ob_display
, self
->title
,
407 RrColorPixel(ob_rr_theme
->b_color
));
410 XMoveWindow(ob_display
, self
->items
, 0, h
);
412 STRUT_SET(self
->item_margin
, 0, 0, 0, 0);
415 ObMenuEntryFrame
*e
= self
->entries
->data
;
418 e
->a_text_normal
->texture
[0].data
.text
.string
= "";
419 RrMinsize(e
->a_text_normal
, &tw
, &th
);
424 RrMargins(e
->a_normal
, &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
));
430 RrMargins(e
->a_selected
, &l
, &t
, &r
, &b
);
431 STRUT_SET(self
->item_margin
,
432 MAX(self
->item_margin
.left
, l
),
433 MAX(self
->item_margin
.top
, t
),
434 MAX(self
->item_margin
.right
, r
),
435 MAX(self
->item_margin
.bottom
, b
));
436 RrMargins(e
->a_disabled
, &l
, &t
, &r
, &b
);
437 STRUT_SET(self
->item_margin
,
438 MAX(self
->item_margin
.left
, l
),
439 MAX(self
->item_margin
.top
, t
),
440 MAX(self
->item_margin
.right
, r
),
441 MAX(self
->item_margin
.bottom
, b
));
445 for (it
= self
->entries
; it
; it
= g_list_next(it
)) {
446 RrAppearance
*text_a
;
447 ObMenuEntryFrame
*e
= it
->data
;
449 RECT_SET_POINT(e
->area
, 0, allitems_h
);
450 XMoveWindow(ob_display
, e
->window
, 0, e
->area
.y
);
452 text_a
= ((e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
453 !e
->entry
->data
.normal
.enabled
) ?
455 (e
== self
->selected
?
458 switch (e
->entry
->type
) {
459 case OB_MENU_ENTRY_TYPE_NORMAL
:
460 text_a
->texture
[0].data
.text
.string
= e
->entry
->data
.normal
.label
;
461 RrMinsize(text_a
, &tw
, &th
);
462 tw
= MIN(tw
, MAX_MENU_WIDTH
);
464 if (e
->entry
->data
.normal
.icon_data
||
465 e
->entry
->data
.normal
.mask
)
468 case OB_MENU_ENTRY_TYPE_SUBMENU
:
469 sub
= e
->entry
->data
.submenu
.submenu
;
470 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
471 RrMinsize(text_a
, &tw
, &th
);
472 tw
= MIN(tw
, MAX_MENU_WIDTH
);
474 if (e
->entry
->data
.normal
.icon_data
||
475 e
->entry
->data
.normal
.mask
)
478 tw
+= self
->item_h
- PADDING
;
480 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
482 th
= SEPARATOR_HEIGHT
;
492 self
->text_x
= PADDING
;
497 w
+= self
->item_h
+ PADDING
;
498 self
->text_x
+= self
->item_h
+ PADDING
;
508 XResizeWindow(ob_display
, self
->window
, w
, h
);
509 XResizeWindow(ob_display
, self
->items
, w
, allitems_h
);
513 if (!self
->parent
&& self
->show_title
) {
514 XResizeWindow(ob_display
, self
->title
,
515 w
, self
->title_h
- ob_rr_theme
->bwidth
);
516 RrPaint(self
->a_title
, self
->title
,
517 w
, self
->title_h
- ob_rr_theme
->bwidth
);
518 XMapWindow(ob_display
, self
->title
);
520 XUnmapWindow(ob_display
, self
->title
);
522 RrPaint(self
->a_items
, self
->items
, w
, allitems_h
);
524 for (it
= self
->entries
; it
; it
= g_list_next(it
))
525 menu_entry_frame_render(it
->data
);
527 w
+= ob_rr_theme
->bwidth
* 2;
528 h
+= ob_rr_theme
->bwidth
* 2;
530 RECT_SET_SIZE(self
->area
, w
, h
);
535 static void menu_frame_update(ObMenuFrame
*self
)
539 menu_pipe_execute(self
->menu
);
540 menu_find_submenus(self
->menu
);
542 self
->selected
= NULL
;
544 for (mit
= self
->menu
->entries
, fit
= self
->entries
; mit
&& fit
;
545 mit
= g_list_next(mit
), fit
= g_list_next(fit
))
547 ObMenuEntryFrame
*f
= fit
->data
;
548 f
->entry
= mit
->data
;
552 ObMenuEntryFrame
*e
= menu_entry_frame_new(mit
->data
, self
);
553 self
->entries
= g_list_append(self
->entries
, e
);
554 mit
= g_list_next(mit
);
558 GList
*n
= g_list_next(fit
);
559 menu_entry_frame_free(fit
->data
);
560 self
->entries
= g_list_delete_link(self
->entries
, fit
);
564 menu_frame_render(self
);
567 void menu_frame_show(ObMenuFrame
*self
, ObMenuFrame
*parent
)
571 if (g_list_find(menu_frame_visible
, self
))
576 menu_frame_hide(parent
->child
);
577 parent
->child
= self
;
579 self
->parent
= parent
;
581 if (menu_frame_visible
== NULL
) {
582 /* no menus shown yet */
583 grab_pointer(TRUE
, OB_CURSOR_NONE
);
587 /* determine if the underlying menu is already visible */
588 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
589 ObMenuFrame
*f
= it
->data
;
590 if (f
->menu
== self
->menu
)
594 if (self
->menu
->update_func
)
595 self
->menu
->update_func(self
, self
->menu
->data
);
598 menu_frame_update(self
);
600 menu_frame_visible
= g_list_prepend(menu_frame_visible
, self
);
602 menu_frame_move_on_screen(self
);
604 XMapWindow(ob_display
, self
->window
);
607 void menu_frame_hide(ObMenuFrame
*self
)
609 GList
*it
= g_list_find(menu_frame_visible
, self
);
615 menu_frame_hide(self
->child
);
618 self
->parent
->child
= NULL
;
621 menu_frame_visible
= g_list_delete_link(menu_frame_visible
, it
);
623 if (menu_frame_visible
== NULL
) {
624 /* last menu shown */
625 grab_pointer(FALSE
, OB_CURSOR_NONE
);
626 grab_keyboard(FALSE
);
629 XUnmapWindow(ob_display
, self
->window
);
631 menu_frame_free(self
);
634 void menu_frame_hide_all()
636 GList
*it
= g_list_last(menu_frame_visible
);
638 menu_frame_hide(it
->data
);
641 void menu_frame_hide_all_client(ObClient
*client
)
643 GList
*it
= g_list_last(menu_frame_visible
);
645 ObMenuFrame
*f
= it
->data
;
646 if (f
->client
== client
)
652 ObMenuFrame
* menu_frame_under(gint x
, gint y
)
654 ObMenuFrame
*ret
= NULL
;
657 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
658 ObMenuFrame
*f
= it
->data
;
660 if (RECT_CONTAINS(f
->area
, x
, y
)) {
668 ObMenuEntryFrame
* menu_entry_frame_under(gint x
, gint y
)
671 ObMenuEntryFrame
*ret
= NULL
;
674 if ((frame
= menu_frame_under(x
, y
))) {
675 x
-= ob_rr_theme
->bwidth
+ frame
->area
.x
;
676 y
-= frame
->title_h
+ ob_rr_theme
->bwidth
+ frame
->area
.y
;
678 for (it
= frame
->entries
; it
; it
= g_list_next(it
)) {
679 ObMenuEntryFrame
*e
= it
->data
;
681 if (RECT_CONTAINS(e
->area
, x
, y
)) {
690 void menu_frame_select(ObMenuFrame
*self
, ObMenuEntryFrame
*entry
)
692 ObMenuEntryFrame
*old
= self
->selected
;
693 ObMenuFrame
*oldchild
= self
->child
;
695 if (entry
&& entry
->entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
)
698 if (old
== entry
) return;
700 self
->selected
= entry
;
703 menu_entry_frame_render(old
);
705 menu_frame_hide(oldchild
);
707 if (self
->selected
) {
708 menu_entry_frame_render(self
->selected
);
710 if (self
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
711 menu_entry_frame_show_submenu(self
->selected
);
715 void menu_entry_frame_show_submenu(ObMenuEntryFrame
*self
)
719 if (!self
->entry
->data
.submenu
.submenu
) return;
721 f
= menu_frame_new(self
->entry
->data
.submenu
.submenu
,
722 self
->frame
->client
);
724 self
->frame
->area
.x
+ self
->frame
->area
.width
725 - ob_rr_theme
->menu_overlap
- ob_rr_theme
->bwidth
,
726 self
->frame
->area
.y
+ self
->frame
->title_h
+
727 self
->area
.y
+ ob_rr_theme
->menu_overlap
);
728 menu_frame_show(f
, self
->frame
);
731 void menu_entry_frame_execute(ObMenuEntryFrame
*self
, guint state
)
733 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
734 self
->entry
->data
.normal
.enabled
)
736 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
738 ObMenuEntry
*entry
= self
->entry
;
739 ObMenuExecuteFunc func
= self
->frame
->menu
->execute_func
;
740 gpointer data
= self
->frame
->menu
->data
;
741 GSList
*acts
= self
->entry
->data
.normal
.actions
;
742 ObClient
*client
= self
->frame
->client
;
744 /* release grabs before executing the shit */
745 if (!(state
& ControlMask
))
746 menu_frame_hide_all();
749 func(entry
, state
, data
);
753 for (it
= acts
; it
; it
= g_slist_next(it
))
754 action_run(it
->data
, client
, state
);
759 void menu_frame_select_previous(ObMenuFrame
*self
)
761 GList
*it
= NULL
, *start
;
764 start
= it
= g_list_find(self
->entries
, self
->selected
);
768 it
= it
? g_list_previous(it
) : g_list_last(self
->entries
);
774 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
776 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
777 e
->entry
->data
.normal
.enabled
)
782 menu_frame_select(self
, it
? it
->data
: NULL
);
785 void menu_frame_select_next(ObMenuFrame
*self
)
787 GList
*it
= NULL
, *start
;
790 start
= it
= g_list_find(self
->entries
, self
->selected
);
794 it
= it
? g_list_next(it
) : self
->entries
;
800 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
802 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
803 e
->entry
->data
.normal
.enabled
)
808 menu_frame_select(self
, it
? it
->data
: NULL
);