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
;
69 attr
.event_mask
= FRAME_EVENTMASK
;
70 attr
.save_under
= True
;
71 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
),
72 CWEventMask
| CWSaveUnder
, &attr
);
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_move_on_screen(ObMenuFrame
*self
)
196 a
= screen_physical_area_monitor(self
->monitor
);
198 half
= g_list_length(self
->entries
) / 2;
199 pos
= g_list_index(self
->entries
, self
->selected
);
201 /* if in the bottom half then check this shit first, will keep the bottom
202 edge of the menu visible */
204 dx
= MAX(dx
, a
->x
- self
->area
.x
);
205 dy
= MAX(dy
, a
->y
- self
->area
.y
);
207 dx
= MIN(dx
, (a
->x
+ a
->width
) - (self
->area
.x
+ self
->area
.width
));
208 dy
= MIN(dy
, (a
->y
+ a
->height
) - (self
->area
.y
+ self
->area
.height
));
209 /* if in the top half then check this shit last, will keep the top
210 edge of the menu visible */
212 dx
= MAX(dx
, a
->x
- self
->area
.x
);
213 dy
= MAX(dy
, a
->y
- self
->area
.y
);
219 /* move the current menu frame to fit, but dont touch parents yet */
220 menu_frame_move(self
, self
->area
.x
+ dx
, self
->area
.y
+ dy
);
221 if (!config_menu_xorstyle
)
222 dy
= 0; /* if we want to be like xor, move parents in y- *
223 * and x-direction, otherwise just in x-dir */
224 for (f
= self
->parent
; f
; f
= f
->parent
)
225 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
226 for (f
= self
->child
; f
; f
= f
->child
)
227 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
228 if (config_menu_warppointer
)
229 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
233 static void menu_entry_frame_render(ObMenuEntryFrame
*self
)
235 RrAppearance
*item_a
, *text_a
;
238 ObMenuFrame
*frame
= self
->frame
;
240 item_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
241 !self
->entry
->data
.normal
.enabled
) ?
243 (self
== self
->frame
->selected
?
246 switch (self
->entry
->type
) {
247 case OB_MENU_ENTRY_TYPE_NORMAL
:
248 case OB_MENU_ENTRY_TYPE_SUBMENU
:
249 th
= self
->frame
->item_h
;
251 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
252 th
= SEPARATOR_HEIGHT
+ 2*PADDING
;
255 RECT_SET_SIZE(self
->area
, self
->frame
->inner_w
, th
);
256 XResizeWindow(ob_display
, self
->window
,
257 self
->area
.width
, self
->area
.height
);
258 item_a
->surface
.parent
= self
->frame
->a_items
;
259 item_a
->surface
.parentx
= self
->area
.x
;
260 item_a
->surface
.parenty
= self
->area
.y
;
261 RrPaint(item_a
, self
->window
, self
->area
.width
, self
->area
.height
);
263 text_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
264 !self
->entry
->data
.normal
.enabled
) ?
265 self
->a_text_disabled
:
266 (self
== self
->frame
->selected
?
267 self
->a_text_selected
:
268 self
->a_text_normal
));
269 switch (self
->entry
->type
) {
270 case OB_MENU_ENTRY_TYPE_NORMAL
:
271 text_a
->texture
[0].data
.text
.string
= self
->entry
->data
.normal
.label
;
273 case OB_MENU_ENTRY_TYPE_SUBMENU
:
274 sub
= self
->entry
->data
.submenu
.submenu
;
275 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
277 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
281 switch (self
->entry
->type
) {
282 case OB_MENU_ENTRY_TYPE_NORMAL
:
283 XMoveResizeWindow(ob_display
, self
->text
,
284 self
->frame
->text_x
, PADDING
,
286 self
->frame
->item_h
- 2*PADDING
);
287 text_a
->surface
.parent
= item_a
;
288 text_a
->surface
.parentx
= self
->frame
->text_x
;
289 text_a
->surface
.parenty
= PADDING
;
290 RrPaint(text_a
, self
->text
, self
->frame
->text_w
,
291 self
->frame
->item_h
- 2*PADDING
);
293 case OB_MENU_ENTRY_TYPE_SUBMENU
:
294 XMoveResizeWindow(ob_display
, self
->text
,
295 self
->frame
->text_x
, PADDING
,
296 self
->frame
->text_w
- self
->frame
->item_h
,
297 self
->frame
->item_h
- 2*PADDING
);
298 text_a
->surface
.parent
= item_a
;
299 text_a
->surface
.parentx
= self
->frame
->text_x
;
300 text_a
->surface
.parenty
= PADDING
;
301 RrPaint(text_a
, self
->text
, self
->frame
->text_w
- self
->frame
->item_h
,
302 self
->frame
->item_h
- 2*PADDING
);
304 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
305 XMoveResizeWindow(ob_display
, self
->text
, PADDING
, PADDING
,
306 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
307 self
->a_separator
->surface
.parent
= item_a
;
308 self
->a_separator
->surface
.parentx
= PADDING
;
309 self
->a_separator
->surface
.parenty
= PADDING
;
310 self
->a_separator
->texture
[0].data
.lineart
.color
=
311 text_a
->texture
[0].data
.text
.color
;
312 self
->a_separator
->texture
[0].data
.lineart
.x1
= 2*PADDING
;
313 self
->a_separator
->texture
[0].data
.lineart
.y1
= SEPARATOR_HEIGHT
/ 2;
314 self
->a_separator
->texture
[0].data
.lineart
.x2
=
315 self
->area
.width
- 4*PADDING
;
316 self
->a_separator
->texture
[0].data
.lineart
.y2
= SEPARATOR_HEIGHT
/ 2;
317 RrPaint(self
->a_separator
, self
->text
,
318 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
322 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
323 self
->entry
->data
.normal
.icon_data
)
325 XMoveResizeWindow(ob_display
, self
->icon
,
326 PADDING
, frame
->item_margin
.top
,
327 self
->frame
->item_h
- frame
->item_margin
.top
328 - frame
->item_margin
.bottom
,
329 self
->frame
->item_h
- frame
->item_margin
.top
330 - frame
->item_margin
.bottom
);
331 self
->a_icon
->texture
[0].data
.rgba
.width
=
332 self
->entry
->data
.normal
.icon_width
;
333 self
->a_icon
->texture
[0].data
.rgba
.height
=
334 self
->entry
->data
.normal
.icon_height
;
335 self
->a_icon
->texture
[0].data
.rgba
.data
=
336 self
->entry
->data
.normal
.icon_data
;
337 self
->a_icon
->surface
.parent
= item_a
;
338 self
->a_icon
->surface
.parentx
= PADDING
;
339 self
->a_icon
->surface
.parenty
= frame
->item_margin
.top
;
340 RrPaint(self
->a_icon
, self
->icon
,
341 self
->frame
->item_h
- frame
->item_margin
.top
342 - frame
->item_margin
.bottom
,
343 self
->frame
->item_h
- frame
->item_margin
.top
344 - frame
->item_margin
.bottom
);
345 XMapWindow(ob_display
, self
->icon
);
346 } else if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
347 self
->entry
->data
.normal
.mask
)
351 XMoveResizeWindow(ob_display
, self
->icon
,
352 PADDING
, frame
->item_margin
.top
,
353 self
->frame
->item_h
- frame
->item_margin
.top
354 - frame
->item_margin
.bottom
,
355 self
->frame
->item_h
- frame
->item_margin
.top
356 - frame
->item_margin
.bottom
);
357 self
->a_mask
->texture
[0].data
.mask
.mask
=
358 self
->entry
->data
.normal
.mask
;
360 c
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
361 !self
->entry
->data
.normal
.enabled
) ?
362 self
->entry
->data
.normal
.mask_disabled_color
:
363 (self
== self
->frame
->selected
?
364 self
->entry
->data
.normal
.mask_selected_color
:
365 self
->entry
->data
.normal
.mask_normal_color
));
366 self
->a_mask
->texture
[0].data
.mask
.color
= c
;
368 self
->a_mask
->surface
.parent
= item_a
;
369 self
->a_mask
->surface
.parentx
= PADDING
;
370 self
->a_mask
->surface
.parenty
= frame
->item_margin
.top
;
371 RrPaint(self
->a_mask
, self
->icon
,
372 self
->frame
->item_h
- frame
->item_margin
.top
373 - frame
->item_margin
.bottom
,
374 self
->frame
->item_h
- frame
->item_margin
.top
375 - frame
->item_margin
.bottom
);
376 XMapWindow(ob_display
, self
->icon
);
378 XUnmapWindow(ob_display
, self
->icon
);
380 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
) {
381 RrAppearance
*bullet_a
;
382 XMoveResizeWindow(ob_display
, self
->bullet
,
383 self
->frame
->text_x
+ self
->frame
->text_w
384 - self
->frame
->item_h
+ PADDING
, PADDING
,
385 self
->frame
->item_h
- 2*PADDING
,
386 self
->frame
->item_h
- 2*PADDING
);
387 bullet_a
= (self
== self
->frame
->selected
?
388 self
->a_bullet_selected
:
389 self
->a_bullet_normal
);
390 bullet_a
->surface
.parent
= item_a
;
391 bullet_a
->surface
.parentx
=
392 self
->frame
->text_x
+ self
->frame
->text_w
- self
->frame
->item_h
394 bullet_a
->surface
.parenty
= PADDING
;
395 RrPaint(bullet_a
, self
->bullet
,
396 self
->frame
->item_h
- 2*PADDING
,
397 self
->frame
->item_h
- 2*PADDING
);
398 XMapWindow(ob_display
, self
->bullet
);
400 XUnmapWindow(ob_display
, self
->bullet
);
405 static void menu_frame_render(ObMenuFrame
*self
)
409 gint tw
, th
; /* temps */
411 gboolean has_icon
= FALSE
;
414 XSetWindowBorderWidth(ob_display
, self
->window
, ob_rr_theme
->bwidth
);
415 XSetWindowBorder(ob_display
, self
->window
,
416 RrColorPixel(ob_rr_theme
->b_color
));
418 if (!self
->parent
&& self
->show_title
) {
419 XMoveWindow(ob_display
, self
->title
,
420 -ob_rr_theme
->bwidth
, h
- ob_rr_theme
->bwidth
);
422 self
->a_title
->texture
[0].data
.text
.string
= self
->menu
->title
;
423 RrMinsize(self
->a_title
, &tw
, &th
);
424 tw
= MIN(tw
, MAX_MENU_WIDTH
) + ob_rr_theme
->padding
* 2;
427 th
= ob_rr_theme
->menu_title_height
;
428 h
+= (self
->title_h
= th
+ ob_rr_theme
->bwidth
);
430 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
431 XSetWindowBorder(ob_display
, self
->title
,
432 RrColorPixel(ob_rr_theme
->b_color
));
435 XMoveWindow(ob_display
, self
->items
, 0, h
);
437 STRUT_SET(self
->item_margin
, 0, 0, 0, 0);
440 ObMenuEntryFrame
*e
= self
->entries
->data
;
443 e
->a_text_normal
->texture
[0].data
.text
.string
= "";
444 RrMinsize(e
->a_text_normal
, &tw
, &th
);
449 RrMargins(e
->a_normal
, &l
, &t
, &r
, &b
);
450 STRUT_SET(self
->item_margin
,
451 MAX(self
->item_margin
.left
, l
),
452 MAX(self
->item_margin
.top
, t
),
453 MAX(self
->item_margin
.right
, r
),
454 MAX(self
->item_margin
.bottom
, b
));
455 RrMargins(e
->a_selected
, &l
, &t
, &r
, &b
);
456 STRUT_SET(self
->item_margin
,
457 MAX(self
->item_margin
.left
, l
),
458 MAX(self
->item_margin
.top
, t
),
459 MAX(self
->item_margin
.right
, r
),
460 MAX(self
->item_margin
.bottom
, b
));
461 RrMargins(e
->a_disabled
, &l
, &t
, &r
, &b
);
462 STRUT_SET(self
->item_margin
,
463 MAX(self
->item_margin
.left
, l
),
464 MAX(self
->item_margin
.top
, t
),
465 MAX(self
->item_margin
.right
, r
),
466 MAX(self
->item_margin
.bottom
, b
));
470 for (it
= self
->entries
; it
; it
= g_list_next(it
)) {
471 RrAppearance
*text_a
;
472 ObMenuEntryFrame
*e
= it
->data
;
474 RECT_SET_POINT(e
->area
, 0, allitems_h
);
475 XMoveWindow(ob_display
, e
->window
, 0, e
->area
.y
);
477 text_a
= ((e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
478 !e
->entry
->data
.normal
.enabled
) ?
480 (e
== self
->selected
?
483 switch (e
->entry
->type
) {
484 case OB_MENU_ENTRY_TYPE_NORMAL
:
485 text_a
->texture
[0].data
.text
.string
= e
->entry
->data
.normal
.label
;
486 RrMinsize(text_a
, &tw
, &th
);
487 tw
= MIN(tw
, MAX_MENU_WIDTH
);
489 if (e
->entry
->data
.normal
.icon_data
||
490 e
->entry
->data
.normal
.mask
)
493 case OB_MENU_ENTRY_TYPE_SUBMENU
:
494 sub
= e
->entry
->data
.submenu
.submenu
;
495 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
496 RrMinsize(text_a
, &tw
, &th
);
497 tw
= MIN(tw
, MAX_MENU_WIDTH
);
499 if (e
->entry
->data
.normal
.icon_data
||
500 e
->entry
->data
.normal
.mask
)
503 tw
+= self
->item_h
- PADDING
;
505 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
507 th
= SEPARATOR_HEIGHT
;
517 self
->text_x
= PADDING
;
522 w
+= self
->item_h
+ PADDING
;
523 self
->text_x
+= self
->item_h
+ PADDING
;
533 XResizeWindow(ob_display
, self
->window
, w
, h
);
534 XResizeWindow(ob_display
, self
->items
, w
, allitems_h
);
538 if (!self
->parent
&& self
->show_title
) {
539 XResizeWindow(ob_display
, self
->title
,
540 w
, self
->title_h
- ob_rr_theme
->bwidth
);
541 RrPaint(self
->a_title
, self
->title
,
542 w
, self
->title_h
- ob_rr_theme
->bwidth
);
543 XMapWindow(ob_display
, self
->title
);
545 XUnmapWindow(ob_display
, self
->title
);
547 RrPaint(self
->a_items
, self
->items
, w
, allitems_h
);
549 for (it
= self
->entries
; it
; it
= g_list_next(it
))
550 menu_entry_frame_render(it
->data
);
552 w
+= ob_rr_theme
->bwidth
* 2;
553 h
+= ob_rr_theme
->bwidth
* 2;
555 RECT_SET_SIZE(self
->area
, w
, h
);
560 static void menu_frame_update(ObMenuFrame
*self
)
564 menu_pipe_execute(self
->menu
);
565 menu_find_submenus(self
->menu
);
567 self
->selected
= NULL
;
569 for (mit
= self
->menu
->entries
, fit
= self
->entries
; mit
&& fit
;
570 mit
= g_list_next(mit
), fit
= g_list_next(fit
))
572 ObMenuEntryFrame
*f
= fit
->data
;
573 f
->entry
= mit
->data
;
577 ObMenuEntryFrame
*e
= menu_entry_frame_new(mit
->data
, self
);
578 self
->entries
= g_list_append(self
->entries
, e
);
579 mit
= g_list_next(mit
);
583 GList
*n
= g_list_next(fit
);
584 menu_entry_frame_free(fit
->data
);
585 self
->entries
= g_list_delete_link(self
->entries
, fit
);
589 menu_frame_render(self
);
592 gboolean
menu_frame_show(ObMenuFrame
*self
, ObMenuFrame
*parent
)
596 if (g_list_find(menu_frame_visible
, self
))
599 if (menu_frame_visible
== NULL
) {
600 /* no menus shown yet */
601 if (!grab_pointer(TRUE
, OB_CURSOR_NONE
))
603 if (!grab_keyboard(TRUE
)) {
604 grab_pointer(FALSE
, OB_CURSOR_NONE
);
610 self
->monitor
= parent
->monitor
;
612 menu_frame_hide(parent
->child
);
613 parent
->child
= self
;
615 self
->parent
= parent
;
617 /* determine if the underlying menu is already visible */
618 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
619 ObMenuFrame
*f
= it
->data
;
620 if (f
->menu
== self
->menu
)
624 if (self
->menu
->update_func
)
625 self
->menu
->update_func(self
, self
->menu
->data
);
628 menu_frame_update(self
);
630 menu_frame_visible
= g_list_prepend(menu_frame_visible
, self
);
632 if (config_menu_middle
) {
634 menu_frame_move(self
, self
->area
.x
, self
->area
.y
635 - self
->area
.height
/2
637 else if (self
->show_title
)
638 menu_frame_move(self
, self
->area
.x
- self
->area
.width
/2,
639 self
->area
.y
- self
->title_h
*3/4);
642 menu_frame_move_on_screen(self
);
644 XMapWindow(ob_display
, self
->window
);
649 void menu_frame_hide(ObMenuFrame
*self
)
651 GList
*it
= g_list_find(menu_frame_visible
, self
);
657 menu_frame_hide(self
->child
);
660 self
->parent
->child
= NULL
;
663 menu_frame_visible
= g_list_delete_link(menu_frame_visible
, it
);
665 if (menu_frame_visible
== NULL
) {
666 /* last menu shown */
667 grab_pointer(FALSE
, OB_CURSOR_NONE
);
668 grab_keyboard(FALSE
);
671 XUnmapWindow(ob_display
, self
->window
);
673 menu_frame_free(self
);
676 void menu_frame_hide_all()
678 if (config_submenu_show_delay
) {
679 /* remove any submenu open requests */
680 ob_main_loop_timeout_remove(ob_main_loop
,
681 menu_entry_frame_submenu_timeout
);
683 GList
*it
= g_list_last(menu_frame_visible
);
685 menu_frame_hide(it
->data
);
688 void menu_frame_hide_all_client(ObClient
*client
)
690 GList
*it
= g_list_last(menu_frame_visible
);
692 ObMenuFrame
*f
= it
->data
;
693 if (f
->client
== client
)
699 ObMenuFrame
* menu_frame_under(gint x
, gint y
)
701 ObMenuFrame
*ret
= NULL
;
704 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
705 ObMenuFrame
*f
= it
->data
;
707 if (RECT_CONTAINS(f
->area
, x
, y
)) {
715 ObMenuEntryFrame
* menu_entry_frame_under(gint x
, gint y
)
718 ObMenuEntryFrame
*ret
= NULL
;
721 if ((frame
= menu_frame_under(x
, y
))) {
722 x
-= ob_rr_theme
->bwidth
+ frame
->area
.x
;
723 y
-= frame
->title_h
+ ob_rr_theme
->bwidth
+ frame
->area
.y
;
725 for (it
= frame
->entries
; it
; it
= g_list_next(it
)) {
726 ObMenuEntryFrame
*e
= it
->data
;
728 if (RECT_CONTAINS(e
->area
, x
, y
)) {
737 static gboolean
menu_entry_frame_submenu_timeout(gpointer data
)
739 menu_entry_frame_show_submenu((ObMenuEntryFrame
*)data
);
743 void menu_frame_select(ObMenuFrame
*self
, ObMenuEntryFrame
*entry
)
745 ObMenuEntryFrame
*old
= self
->selected
;
746 ObMenuFrame
*oldchild
= self
->child
;
748 if (entry
&& entry
->entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
)
751 if (old
== entry
) return;
753 if (config_submenu_show_delay
) {
754 /* remove any submenu open requests */
755 ob_main_loop_timeout_remove(ob_main_loop
,
756 menu_entry_frame_submenu_timeout
);
759 self
->selected
= entry
;
762 menu_entry_frame_render(old
);
764 menu_frame_hide(oldchild
);
766 if (self
->selected
) {
767 menu_entry_frame_render(self
->selected
);
769 if (self
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
) {
770 if (config_submenu_show_delay
) {
771 /* initiate a new submenu open request */
772 ob_main_loop_timeout_add(ob_main_loop
,
773 config_submenu_show_delay
* 1000,
774 menu_entry_frame_submenu_timeout
,
778 menu_entry_frame_show_submenu(self
->selected
);
784 void menu_entry_frame_show_submenu(ObMenuEntryFrame
*self
)
788 if (!self
->entry
->data
.submenu
.submenu
) return;
790 f
= menu_frame_new(self
->entry
->data
.submenu
.submenu
,
791 self
->frame
->client
);
794 + self
->frame
->area
.width
795 - ob_rr_theme
->menu_overlap
796 - ob_rr_theme
->bwidth
,
798 + self
->frame
->title_h
800 + (config_menu_middle
? 1 : ob_rr_theme
->menu_overlap
));
801 menu_frame_show(f
, self
->frame
);
804 void menu_entry_frame_execute(ObMenuEntryFrame
*self
, guint state
)
806 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
807 self
->entry
->data
.normal
.enabled
)
809 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
811 ObMenuEntry
*entry
= self
->entry
;
812 ObMenuExecuteFunc func
= self
->frame
->menu
->execute_func
;
813 gpointer data
= self
->frame
->menu
->data
;
814 GSList
*acts
= self
->entry
->data
.normal
.actions
;
815 ObClient
*client
= self
->frame
->client
;
817 /* release grabs before executing the shit */
818 if (!(state
& ControlMask
))
819 menu_frame_hide_all();
822 func(entry
, state
, data
);
824 action_run(acts
, client
, state
);
828 void menu_frame_select_previous(ObMenuFrame
*self
)
830 GList
*it
= NULL
, *start
;
833 start
= it
= g_list_find(self
->entries
, self
->selected
);
837 it
= it
? g_list_previous(it
) : g_list_last(self
->entries
);
843 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
845 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
846 e
->entry
->data
.normal
.enabled
)
851 menu_frame_select(self
, it
? it
->data
: NULL
);
854 void menu_frame_select_next(ObMenuFrame
*self
)
856 GList
*it
= NULL
, *start
;
859 start
= it
= g_list_find(self
->entries
, self
->selected
);
863 it
= it
? g_list_next(it
) : self
->entries
;
869 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
871 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
872 e
->entry
->data
.normal
.enabled
)
877 menu_frame_select(self
, it
? it
->data
: NULL
);