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
);
405 h
+= (self
->title_h
= th
+ ob_rr_theme
->bwidth
);
407 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
408 XSetWindowBorder(ob_display
, self
->title
,
409 RrColorPixel(ob_rr_theme
->b_color
));
412 XMoveWindow(ob_display
, self
->items
, 0, h
);
414 STRUT_SET(self
->item_margin
, 0, 0, 0, 0);
417 ObMenuEntryFrame
*e
= self
->entries
->data
;
420 e
->a_text_normal
->texture
[0].data
.text
.string
= "";
421 RrMinsize(e
->a_text_normal
, &tw
, &th
);
426 RrMargins(e
->a_normal
, &l
, &t
, &r
, &b
);
427 STRUT_SET(self
->item_margin
,
428 MAX(self
->item_margin
.left
, l
),
429 MAX(self
->item_margin
.top
, t
),
430 MAX(self
->item_margin
.right
, r
),
431 MAX(self
->item_margin
.bottom
, b
));
432 RrMargins(e
->a_selected
, &l
, &t
, &r
, &b
);
433 STRUT_SET(self
->item_margin
,
434 MAX(self
->item_margin
.left
, l
),
435 MAX(self
->item_margin
.top
, t
),
436 MAX(self
->item_margin
.right
, r
),
437 MAX(self
->item_margin
.bottom
, b
));
438 RrMargins(e
->a_disabled
, &l
, &t
, &r
, &b
);
439 STRUT_SET(self
->item_margin
,
440 MAX(self
->item_margin
.left
, l
),
441 MAX(self
->item_margin
.top
, t
),
442 MAX(self
->item_margin
.right
, r
),
443 MAX(self
->item_margin
.bottom
, b
));
447 for (it
= self
->entries
; it
; it
= g_list_next(it
)) {
448 RrAppearance
*text_a
;
449 ObMenuEntryFrame
*e
= it
->data
;
451 RECT_SET_POINT(e
->area
, 0, allitems_h
);
452 XMoveWindow(ob_display
, e
->window
, 0, e
->area
.y
);
454 text_a
= ((e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
455 !e
->entry
->data
.normal
.enabled
) ?
457 (e
== self
->selected
?
460 switch (e
->entry
->type
) {
461 case OB_MENU_ENTRY_TYPE_NORMAL
:
462 text_a
->texture
[0].data
.text
.string
= e
->entry
->data
.normal
.label
;
463 RrMinsize(text_a
, &tw
, &th
);
464 tw
= MIN(tw
, MAX_MENU_WIDTH
);
466 if (e
->entry
->data
.normal
.icon_data
||
467 e
->entry
->data
.normal
.mask
)
470 case OB_MENU_ENTRY_TYPE_SUBMENU
:
471 sub
= e
->entry
->data
.submenu
.submenu
;
472 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
473 RrMinsize(text_a
, &tw
, &th
);
474 tw
= MIN(tw
, MAX_MENU_WIDTH
);
476 if (e
->entry
->data
.normal
.icon_data
||
477 e
->entry
->data
.normal
.mask
)
480 tw
+= self
->item_h
- PADDING
;
482 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
484 th
= SEPARATOR_HEIGHT
;
494 self
->text_x
= PADDING
;
499 w
+= self
->item_h
+ PADDING
;
500 self
->text_x
+= self
->item_h
+ PADDING
;
510 XResizeWindow(ob_display
, self
->window
, w
, h
);
511 XResizeWindow(ob_display
, self
->items
, w
, allitems_h
);
515 if (!self
->parent
&& self
->show_title
) {
516 XResizeWindow(ob_display
, self
->title
,
517 w
, self
->title_h
- ob_rr_theme
->bwidth
);
518 RrPaint(self
->a_title
, self
->title
,
519 w
, self
->title_h
- ob_rr_theme
->bwidth
);
520 XMapWindow(ob_display
, self
->title
);
522 XUnmapWindow(ob_display
, self
->title
);
524 RrPaint(self
->a_items
, self
->items
, w
, allitems_h
);
526 for (it
= self
->entries
; it
; it
= g_list_next(it
))
527 menu_entry_frame_render(it
->data
);
529 w
+= ob_rr_theme
->bwidth
* 2;
530 h
+= ob_rr_theme
->bwidth
* 2;
532 RECT_SET_SIZE(self
->area
, w
, h
);
537 static void menu_frame_update(ObMenuFrame
*self
)
541 menu_pipe_execute(self
->menu
);
542 menu_find_submenus(self
->menu
);
544 self
->selected
= NULL
;
546 for (mit
= self
->menu
->entries
, fit
= self
->entries
; mit
&& fit
;
547 mit
= g_list_next(mit
), fit
= g_list_next(fit
))
549 ObMenuEntryFrame
*f
= fit
->data
;
550 f
->entry
= mit
->data
;
554 ObMenuEntryFrame
*e
= menu_entry_frame_new(mit
->data
, self
);
555 self
->entries
= g_list_append(self
->entries
, e
);
556 mit
= g_list_next(mit
);
560 GList
*n
= g_list_next(fit
);
561 menu_entry_frame_free(fit
->data
);
562 self
->entries
= g_list_delete_link(self
->entries
, fit
);
566 menu_frame_render(self
);
569 void menu_frame_show(ObMenuFrame
*self
, ObMenuFrame
*parent
)
573 if (g_list_find(menu_frame_visible
, self
))
578 menu_frame_hide(parent
->child
);
579 parent
->child
= self
;
581 self
->parent
= parent
;
583 if (menu_frame_visible
== NULL
) {
584 /* no menus shown yet */
585 grab_pointer(TRUE
, OB_CURSOR_NONE
);
589 /* determine if the underlying menu is already visible */
590 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
591 ObMenuFrame
*f
= it
->data
;
592 if (f
->menu
== self
->menu
)
596 if (self
->menu
->update_func
)
597 self
->menu
->update_func(self
, self
->menu
->data
);
600 menu_frame_visible
= g_list_prepend(menu_frame_visible
, self
);
601 menu_frame_update(self
);
603 menu_frame_move_on_screen(self
);
605 XMapWindow(ob_display
, self
->window
);
608 void menu_frame_hide(ObMenuFrame
*self
)
610 GList
*it
= g_list_find(menu_frame_visible
, self
);
616 menu_frame_hide(self
->child
);
619 self
->parent
->child
= NULL
;
622 menu_frame_visible
= g_list_delete_link(menu_frame_visible
, it
);
624 if (menu_frame_visible
== NULL
) {
625 /* last menu shown */
626 grab_pointer(FALSE
, OB_CURSOR_NONE
);
627 grab_keyboard(FALSE
);
630 XUnmapWindow(ob_display
, self
->window
);
632 menu_frame_free(self
);
635 void menu_frame_hide_all()
637 GList
*it
= g_list_last(menu_frame_visible
);
639 menu_frame_hide(it
->data
);
642 void menu_frame_hide_all_client(ObClient
*client
)
644 GList
*it
= g_list_last(menu_frame_visible
);
646 ObMenuFrame
*f
= it
->data
;
647 if (f
->client
== client
)
653 ObMenuFrame
* menu_frame_under(gint x
, gint y
)
655 ObMenuFrame
*ret
= NULL
;
658 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
659 ObMenuFrame
*f
= it
->data
;
661 if (RECT_CONTAINS(f
->area
, x
, y
)) {
669 ObMenuEntryFrame
* menu_entry_frame_under(gint x
, gint y
)
672 ObMenuEntryFrame
*ret
= NULL
;
675 if ((frame
= menu_frame_under(x
, y
))) {
676 x
-= ob_rr_theme
->bwidth
+ frame
->area
.x
;
677 y
-= frame
->title_h
+ ob_rr_theme
->bwidth
+ frame
->area
.y
;
679 for (it
= frame
->entries
; it
; it
= g_list_next(it
)) {
680 ObMenuEntryFrame
*e
= it
->data
;
682 if (RECT_CONTAINS(e
->area
, x
, y
)) {
691 void menu_frame_select(ObMenuFrame
*self
, ObMenuEntryFrame
*entry
)
693 ObMenuEntryFrame
*old
= self
->selected
;
694 ObMenuFrame
*oldchild
= self
->child
;
696 if (entry
&& entry
->entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
)
699 if (old
== entry
) return;
701 self
->selected
= entry
;
704 menu_entry_frame_render(old
);
706 menu_frame_hide(oldchild
);
708 if (self
->selected
) {
709 menu_entry_frame_render(self
->selected
);
711 if (self
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
712 menu_entry_frame_show_submenu(self
->selected
);
716 void menu_entry_frame_show_submenu(ObMenuEntryFrame
*self
)
720 if (!self
->entry
->data
.submenu
.submenu
) return;
722 f
= menu_frame_new(self
->entry
->data
.submenu
.submenu
,
723 self
->frame
->client
);
725 self
->frame
->area
.x
+ self
->frame
->area
.width
726 - ob_rr_theme
->menu_overlap
- ob_rr_theme
->bwidth
,
727 self
->frame
->area
.y
+ self
->frame
->title_h
+
728 self
->area
.y
+ ob_rr_theme
->menu_overlap
);
729 menu_frame_show(f
, self
->frame
);
732 void menu_entry_frame_execute(ObMenuEntryFrame
*self
, guint state
)
734 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
735 self
->entry
->data
.normal
.enabled
)
737 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
739 ObMenuEntry
*entry
= self
->entry
;
740 ObMenuExecuteFunc func
= self
->frame
->menu
->execute_func
;
741 gpointer data
= self
->frame
->menu
->data
;
742 GSList
*acts
= self
->entry
->data
.normal
.actions
;
743 ObClient
*client
= self
->frame
->client
;
745 /* release grabs before executing the shit */
746 if (!(state
& ControlMask
))
747 menu_frame_hide_all();
750 func(entry
, state
, data
);
754 for (it
= acts
; it
; it
= g_slist_next(it
))
755 action_run(it
->data
, client
, state
);
760 void menu_frame_select_previous(ObMenuFrame
*self
)
762 GList
*it
= NULL
, *start
;
765 start
= it
= g_list_find(self
->entries
, self
->selected
);
769 it
= it
? g_list_previous(it
) : g_list_last(self
->entries
);
775 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
777 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
778 e
->entry
->data
.normal
.enabled
)
783 menu_frame_select(self
, it
? it
->data
: NULL
);
786 void menu_frame_select_next(ObMenuFrame
*self
)
788 GList
*it
= NULL
, *start
;
791 start
= it
= g_list_find(self
->entries
, self
->selected
);
795 it
= it
? g_list_next(it
) : self
->entries
;
801 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
803 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
804 e
->entry
->data
.normal
.enabled
)
809 menu_frame_select(self
, it
? it
->data
: NULL
);