1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 menuframe.c for the Openbox window manager
4 Copyright (c) 2004 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"
26 #include "render/theme.h"
29 #define SEPARATOR_HEIGHT 3
30 #define MAX_MENU_WIDTH 400
32 #define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
34 #define TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
35 #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
36 ButtonPressMask | ButtonReleaseMask)
38 GList
*menu_frame_visible
;
40 static ObMenuEntryFrame
* menu_entry_frame_new(ObMenuEntry
*entry
,
42 static void menu_entry_frame_free(ObMenuEntryFrame
*self
);
43 static void menu_frame_render(ObMenuFrame
*self
);
44 static void menu_frame_update(ObMenuFrame
*self
);
46 static Window
createWindow(Window parent
, gulong mask
,
47 XSetWindowAttributes
*attrib
)
49 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
50 RrDepth(ob_rr_inst
), InputOutput
,
51 RrVisual(ob_rr_inst
), mask
, attrib
);
54 ObMenuFrame
* menu_frame_new(ObMenu
*menu
, ObClient
*client
)
57 XSetWindowAttributes attr
;
59 self
= g_new0(ObMenuFrame
, 1);
60 self
->type
= Window_Menu
;
62 self
->selected
= NULL
;
63 self
->show_title
= TRUE
;
64 self
->client
= client
;
66 attr
.event_mask
= FRAME_EVENTMASK
;
67 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
),
69 attr
.event_mask
= TITLE_EVENTMASK
;
70 self
->title
= createWindow(self
->window
, CWEventMask
, &attr
);
71 self
->items
= createWindow(self
->window
, 0, NULL
);
73 XMapWindow(ob_display
, self
->items
);
75 self
->a_title
= RrAppearanceCopy(ob_rr_theme
->a_menu_title
);
76 self
->a_items
= RrAppearanceCopy(ob_rr_theme
->a_menu
);
78 stacking_add(MENU_AS_WINDOW(self
));
83 void menu_frame_free(ObMenuFrame
*self
)
86 while (self
->entries
) {
87 menu_entry_frame_free(self
->entries
->data
);
88 self
->entries
= g_list_delete_link(self
->entries
, self
->entries
);
91 stacking_remove(MENU_AS_WINDOW(self
));
93 XDestroyWindow(ob_display
, self
->items
);
94 XDestroyWindow(ob_display
, self
->title
);
95 XDestroyWindow(ob_display
, self
->window
);
97 RrAppearanceFree(self
->a_items
);
98 RrAppearanceFree(self
->a_title
);
104 static ObMenuEntryFrame
* menu_entry_frame_new(ObMenuEntry
*entry
,
107 ObMenuEntryFrame
*self
;
108 XSetWindowAttributes attr
;
110 self
= g_new0(ObMenuEntryFrame
, 1);
114 attr
.event_mask
= ENTRY_EVENTMASK
;
115 self
->window
= createWindow(self
->frame
->items
, CWEventMask
, &attr
);
116 self
->text
= createWindow(self
->window
, 0, NULL
);
117 if (entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
) {
118 self
->icon
= createWindow(self
->window
, 0, NULL
);
119 self
->bullet
= createWindow(self
->window
, 0, NULL
);
122 XMapWindow(ob_display
, self
->window
);
123 XMapWindow(ob_display
, self
->text
);
125 self
->a_normal
= RrAppearanceCopy(ob_rr_theme
->a_menu_normal
);
126 self
->a_disabled
= RrAppearanceCopy(ob_rr_theme
->a_menu_disabled
);
127 self
->a_selected
= RrAppearanceCopy(ob_rr_theme
->a_menu_selected
);
129 if (entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
) {
130 self
->a_separator
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
131 self
->a_separator
->texture
[0].type
= RR_TEXTURE_LINE_ART
;
133 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
134 self
->a_icon
->texture
[0].type
= RR_TEXTURE_RGBA
;
135 self
->a_mask
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
136 self
->a_mask
->texture
[0].type
= RR_TEXTURE_MASK
;
137 self
->a_bullet_normal
=
138 RrAppearanceCopy(ob_rr_theme
->a_menu_bullet_normal
);
139 self
->a_bullet_selected
=
140 RrAppearanceCopy(ob_rr_theme
->a_menu_bullet_selected
);
143 self
->a_text_normal
=
144 RrAppearanceCopy(ob_rr_theme
->a_menu_text_normal
);
145 self
->a_text_disabled
=
146 RrAppearanceCopy(ob_rr_theme
->a_menu_text_disabled
);
147 self
->a_text_selected
=
148 RrAppearanceCopy(ob_rr_theme
->a_menu_text_selected
);
153 static void menu_entry_frame_free(ObMenuEntryFrame
*self
)
156 XDestroyWindow(ob_display
, self
->text
);
157 XDestroyWindow(ob_display
, self
->window
);
158 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
) {
159 XDestroyWindow(ob_display
, self
->icon
);
160 XDestroyWindow(ob_display
, self
->bullet
);
163 RrAppearanceFree(self
->a_normal
);
164 RrAppearanceFree(self
->a_disabled
);
165 RrAppearanceFree(self
->a_selected
);
167 RrAppearanceFree(self
->a_separator
);
168 RrAppearanceFree(self
->a_icon
);
169 RrAppearanceFree(self
->a_mask
);
170 RrAppearanceFree(self
->a_text_normal
);
171 RrAppearanceFree(self
->a_text_disabled
);
172 RrAppearanceFree(self
->a_text_selected
);
173 RrAppearanceFree(self
->a_bullet_normal
);
174 RrAppearanceFree(self
->a_bullet_selected
);
180 void menu_frame_move(ObMenuFrame
*self
, gint x
, gint y
)
182 RECT_SET_POINT(self
->area
, x
, y
);
183 XMoveWindow(ob_display
, self
->window
, self
->area
.x
, self
->area
.y
);
186 void menu_frame_move_on_screen(ObMenuFrame
*self
)
193 for (i
= 0; i
< screen_num_monitors
; ++i
) {
194 a
= screen_physical_area_monitor(i
);
195 if (RECT_INTERSECTS_RECT(*a
, self
->area
))
198 if (!a
) a
= screen_physical_area_monitor(0);
200 half
= g_list_length(self
->entries
) / 2;
201 pos
= g_list_index(self
->entries
, self
->selected
);
203 /* if in the bottom half then check this shit first, will keep the bottom
204 edge of the menu visible */
206 dx
= MAX(dx
, a
->x
- self
->area
.x
);
207 dy
= MAX(dy
, a
->y
- self
->area
.y
);
209 dx
= MIN(dx
, (a
->x
+ a
->width
) - (self
->area
.x
+ self
->area
.width
));
210 dy
= MIN(dy
, (a
->y
+ a
->height
) - (self
->area
.y
+ self
->area
.height
));
211 /* if in the top half then check this shit last, will keep the top
212 edge of the menu visible */
214 dx
= MAX(dx
, a
->x
- self
->area
.x
);
215 dy
= MAX(dy
, a
->y
- self
->area
.y
);
221 /* move the current menu frame to fit, but dont touch parents yet */
222 menu_frame_move(self
, self
->area
.x
+ dx
, self
->area
.y
+ dy
);
223 if (!config_menu_xorstyle
)
224 dy
= 0; /* if we want to be like xor, move parents in y- *
225 * and x-direction, otherwise just in x-dir */
226 for (f
= self
->parent
; f
; f
= f
->parent
)
227 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
228 for (f
= self
->child
; f
; f
= f
->child
)
229 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
230 if (config_menu_warppointer
)
231 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
235 static void menu_entry_frame_render(ObMenuEntryFrame
*self
)
237 RrAppearance
*item_a
, *text_a
;
240 ObMenuFrame
*frame
= self
->frame
;
242 item_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
243 !self
->entry
->data
.normal
.enabled
) ?
245 (self
== self
->frame
->selected
?
248 switch (self
->entry
->type
) {
249 case OB_MENU_ENTRY_TYPE_NORMAL
:
250 case OB_MENU_ENTRY_TYPE_SUBMENU
:
251 th
= self
->frame
->item_h
;
253 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
254 th
= SEPARATOR_HEIGHT
+ 2*PADDING
;
257 RECT_SET_SIZE(self
->area
, self
->frame
->inner_w
, th
);
258 XResizeWindow(ob_display
, self
->window
,
259 self
->area
.width
, self
->area
.height
);
260 item_a
->surface
.parent
= self
->frame
->a_items
;
261 item_a
->surface
.parentx
= self
->area
.x
;
262 item_a
->surface
.parenty
= self
->area
.y
;
263 RrPaint(item_a
, self
->window
, self
->area
.width
, self
->area
.height
);
265 text_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
266 !self
->entry
->data
.normal
.enabled
) ?
267 self
->a_text_disabled
:
268 (self
== self
->frame
->selected
?
269 self
->a_text_selected
:
270 self
->a_text_normal
));
271 switch (self
->entry
->type
) {
272 case OB_MENU_ENTRY_TYPE_NORMAL
:
273 text_a
->texture
[0].data
.text
.string
= self
->entry
->data
.normal
.label
;
275 case OB_MENU_ENTRY_TYPE_SUBMENU
:
276 sub
= self
->entry
->data
.submenu
.submenu
;
277 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
279 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
283 switch (self
->entry
->type
) {
284 case OB_MENU_ENTRY_TYPE_NORMAL
:
285 XMoveResizeWindow(ob_display
, self
->text
,
286 self
->frame
->text_x
, PADDING
,
288 self
->frame
->item_h
- 2*PADDING
);
289 text_a
->surface
.parent
= item_a
;
290 text_a
->surface
.parentx
= self
->frame
->text_x
;
291 text_a
->surface
.parenty
= PADDING
;
292 RrPaint(text_a
, self
->text
, self
->frame
->text_w
,
293 self
->frame
->item_h
- 2*PADDING
);
295 case OB_MENU_ENTRY_TYPE_SUBMENU
:
296 XMoveResizeWindow(ob_display
, self
->text
,
297 self
->frame
->text_x
, PADDING
,
298 self
->frame
->text_w
- self
->frame
->item_h
,
299 self
->frame
->item_h
- 2*PADDING
);
300 text_a
->surface
.parent
= item_a
;
301 text_a
->surface
.parentx
= self
->frame
->text_x
;
302 text_a
->surface
.parenty
= PADDING
;
303 RrPaint(text_a
, self
->text
, self
->frame
->text_w
- self
->frame
->item_h
,
304 self
->frame
->item_h
- 2*PADDING
);
306 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
307 XMoveResizeWindow(ob_display
, self
->text
, PADDING
, PADDING
,
308 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
309 self
->a_separator
->surface
.parent
= item_a
;
310 self
->a_separator
->surface
.parentx
= PADDING
;
311 self
->a_separator
->surface
.parenty
= PADDING
;
312 self
->a_separator
->texture
[0].data
.lineart
.color
=
313 text_a
->texture
[0].data
.text
.color
;
314 self
->a_separator
->texture
[0].data
.lineart
.x1
= 2*PADDING
;
315 self
->a_separator
->texture
[0].data
.lineart
.y1
= SEPARATOR_HEIGHT
/ 2;
316 self
->a_separator
->texture
[0].data
.lineart
.x2
=
317 self
->area
.width
- 4*PADDING
;
318 self
->a_separator
->texture
[0].data
.lineart
.y2
= SEPARATOR_HEIGHT
/ 2;
319 RrPaint(self
->a_separator
, self
->text
,
320 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
324 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
325 self
->entry
->data
.normal
.icon_data
)
327 XMoveResizeWindow(ob_display
, self
->icon
,
328 PADDING
, frame
->item_margin
.top
,
329 self
->frame
->item_h
- frame
->item_margin
.top
330 - frame
->item_margin
.bottom
,
331 self
->frame
->item_h
- frame
->item_margin
.top
332 - frame
->item_margin
.bottom
);
333 self
->a_icon
->texture
[0].data
.rgba
.width
=
334 self
->entry
->data
.normal
.icon_width
;
335 self
->a_icon
->texture
[0].data
.rgba
.height
=
336 self
->entry
->data
.normal
.icon_height
;
337 self
->a_icon
->texture
[0].data
.rgba
.data
=
338 self
->entry
->data
.normal
.icon_data
;
339 self
->a_icon
->surface
.parent
= item_a
;
340 self
->a_icon
->surface
.parentx
= PADDING
;
341 self
->a_icon
->surface
.parenty
= frame
->item_margin
.top
;
342 RrPaint(self
->a_icon
, self
->icon
,
343 self
->frame
->item_h
- frame
->item_margin
.top
344 - frame
->item_margin
.bottom
,
345 self
->frame
->item_h
- frame
->item_margin
.top
346 - frame
->item_margin
.bottom
);
347 XMapWindow(ob_display
, self
->icon
);
348 } else if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
349 self
->entry
->data
.normal
.mask
)
353 XMoveResizeWindow(ob_display
, self
->icon
,
354 PADDING
, frame
->item_margin
.top
,
355 self
->frame
->item_h
- frame
->item_margin
.top
356 - frame
->item_margin
.bottom
,
357 self
->frame
->item_h
- frame
->item_margin
.top
358 - frame
->item_margin
.bottom
);
359 self
->a_mask
->texture
[0].data
.mask
.mask
=
360 self
->entry
->data
.normal
.mask
;
362 c
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
363 !self
->entry
->data
.normal
.enabled
) ?
364 self
->entry
->data
.normal
.mask_disabled_color
:
365 (self
== self
->frame
->selected
?
366 self
->entry
->data
.normal
.mask_selected_color
:
367 self
->entry
->data
.normal
.mask_normal_color
));
368 self
->a_mask
->texture
[0].data
.mask
.color
= c
;
370 self
->a_mask
->surface
.parent
= item_a
;
371 self
->a_mask
->surface
.parentx
= PADDING
;
372 self
->a_mask
->surface
.parenty
= frame
->item_margin
.top
;
373 RrPaint(self
->a_mask
, self
->icon
,
374 self
->frame
->item_h
- frame
->item_margin
.top
375 - frame
->item_margin
.bottom
,
376 self
->frame
->item_h
- frame
->item_margin
.top
377 - frame
->item_margin
.bottom
);
378 XMapWindow(ob_display
, self
->icon
);
380 XUnmapWindow(ob_display
, self
->icon
);
382 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
) {
383 RrAppearance
*bullet_a
;
384 XMoveResizeWindow(ob_display
, self
->bullet
,
385 self
->frame
->text_x
+ self
->frame
->text_w
386 - self
->frame
->item_h
+ PADDING
, PADDING
,
387 self
->frame
->item_h
- 2*PADDING
,
388 self
->frame
->item_h
- 2*PADDING
);
389 bullet_a
= (self
== self
->frame
->selected
?
390 self
->a_bullet_selected
:
391 self
->a_bullet_normal
);
392 bullet_a
->surface
.parent
= item_a
;
393 bullet_a
->surface
.parentx
=
394 self
->frame
->text_x
+ self
->frame
->text_w
- self
->frame
->item_h
396 bullet_a
->surface
.parenty
= PADDING
;
397 RrPaint(bullet_a
, self
->bullet
,
398 self
->frame
->item_h
- 2*PADDING
,
399 self
->frame
->item_h
- 2*PADDING
);
400 XMapWindow(ob_display
, self
->bullet
);
402 XUnmapWindow(ob_display
, self
->bullet
);
407 static void menu_frame_render(ObMenuFrame
*self
)
411 gint tw
, th
; /* temps */
413 gboolean has_icon
= FALSE
;
416 XSetWindowBorderWidth(ob_display
, self
->window
, ob_rr_theme
->bwidth
);
417 XSetWindowBorder(ob_display
, self
->window
,
418 RrColorPixel(ob_rr_theme
->b_color
));
420 if (!self
->parent
&& self
->show_title
) {
421 XMoveWindow(ob_display
, self
->title
,
422 -ob_rr_theme
->bwidth
, h
- ob_rr_theme
->bwidth
);
424 self
->a_title
->texture
[0].data
.text
.string
= self
->menu
->title
;
425 RrMinsize(self
->a_title
, &tw
, &th
);
426 tw
= MIN(tw
, MAX_MENU_WIDTH
) + ob_rr_theme
->padding
* 2;
429 th
= ob_rr_theme
->menu_title_height
;
430 h
+= (self
->title_h
= th
+ ob_rr_theme
->bwidth
);
432 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
433 XSetWindowBorder(ob_display
, self
->title
,
434 RrColorPixel(ob_rr_theme
->b_color
));
437 XMoveWindow(ob_display
, self
->items
, 0, h
);
439 STRUT_SET(self
->item_margin
, 0, 0, 0, 0);
442 ObMenuEntryFrame
*e
= self
->entries
->data
;
445 e
->a_text_normal
->texture
[0].data
.text
.string
= "";
446 RrMinsize(e
->a_text_normal
, &tw
, &th
);
451 RrMargins(e
->a_normal
, &l
, &t
, &r
, &b
);
452 STRUT_SET(self
->item_margin
,
453 MAX(self
->item_margin
.left
, l
),
454 MAX(self
->item_margin
.top
, t
),
455 MAX(self
->item_margin
.right
, r
),
456 MAX(self
->item_margin
.bottom
, b
));
457 RrMargins(e
->a_selected
, &l
, &t
, &r
, &b
);
458 STRUT_SET(self
->item_margin
,
459 MAX(self
->item_margin
.left
, l
),
460 MAX(self
->item_margin
.top
, t
),
461 MAX(self
->item_margin
.right
, r
),
462 MAX(self
->item_margin
.bottom
, b
));
463 RrMargins(e
->a_disabled
, &l
, &t
, &r
, &b
);
464 STRUT_SET(self
->item_margin
,
465 MAX(self
->item_margin
.left
, l
),
466 MAX(self
->item_margin
.top
, t
),
467 MAX(self
->item_margin
.right
, r
),
468 MAX(self
->item_margin
.bottom
, b
));
472 for (it
= self
->entries
; it
; it
= g_list_next(it
)) {
473 RrAppearance
*text_a
;
474 ObMenuEntryFrame
*e
= it
->data
;
476 RECT_SET_POINT(e
->area
, 0, allitems_h
);
477 XMoveWindow(ob_display
, e
->window
, 0, e
->area
.y
);
479 text_a
= ((e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
480 !e
->entry
->data
.normal
.enabled
) ?
482 (e
== self
->selected
?
485 switch (e
->entry
->type
) {
486 case OB_MENU_ENTRY_TYPE_NORMAL
:
487 text_a
->texture
[0].data
.text
.string
= e
->entry
->data
.normal
.label
;
488 RrMinsize(text_a
, &tw
, &th
);
489 tw
= MIN(tw
, MAX_MENU_WIDTH
);
491 if (e
->entry
->data
.normal
.icon_data
||
492 e
->entry
->data
.normal
.mask
)
495 case OB_MENU_ENTRY_TYPE_SUBMENU
:
496 sub
= e
->entry
->data
.submenu
.submenu
;
497 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
498 RrMinsize(text_a
, &tw
, &th
);
499 tw
= MIN(tw
, MAX_MENU_WIDTH
);
501 if (e
->entry
->data
.normal
.icon_data
||
502 e
->entry
->data
.normal
.mask
)
505 tw
+= self
->item_h
- PADDING
;
507 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
509 th
= SEPARATOR_HEIGHT
;
519 self
->text_x
= PADDING
;
524 w
+= self
->item_h
+ PADDING
;
525 self
->text_x
+= self
->item_h
+ PADDING
;
535 XResizeWindow(ob_display
, self
->window
, w
, h
);
536 XResizeWindow(ob_display
, self
->items
, w
, allitems_h
);
540 if (!self
->parent
&& self
->show_title
) {
541 XResizeWindow(ob_display
, self
->title
,
542 w
, self
->title_h
- ob_rr_theme
->bwidth
);
543 RrPaint(self
->a_title
, self
->title
,
544 w
, self
->title_h
- ob_rr_theme
->bwidth
);
545 XMapWindow(ob_display
, self
->title
);
547 XUnmapWindow(ob_display
, self
->title
);
549 RrPaint(self
->a_items
, self
->items
, w
, allitems_h
);
551 for (it
= self
->entries
; it
; it
= g_list_next(it
))
552 menu_entry_frame_render(it
->data
);
554 w
+= ob_rr_theme
->bwidth
* 2;
555 h
+= ob_rr_theme
->bwidth
* 2;
557 RECT_SET_SIZE(self
->area
, w
, h
);
562 static void menu_frame_update(ObMenuFrame
*self
)
566 menu_pipe_execute(self
->menu
);
567 menu_find_submenus(self
->menu
);
569 self
->selected
= NULL
;
571 for (mit
= self
->menu
->entries
, fit
= self
->entries
; mit
&& fit
;
572 mit
= g_list_next(mit
), fit
= g_list_next(fit
))
574 ObMenuEntryFrame
*f
= fit
->data
;
575 f
->entry
= mit
->data
;
579 ObMenuEntryFrame
*e
= menu_entry_frame_new(mit
->data
, self
);
580 self
->entries
= g_list_append(self
->entries
, e
);
581 mit
= g_list_next(mit
);
585 GList
*n
= g_list_next(fit
);
586 menu_entry_frame_free(fit
->data
);
587 self
->entries
= g_list_delete_link(self
->entries
, fit
);
591 menu_frame_render(self
);
594 gboolean
menu_frame_show(ObMenuFrame
*self
, ObMenuFrame
*parent
)
598 if (g_list_find(menu_frame_visible
, self
))
601 if (menu_frame_visible
== NULL
) {
602 /* no menus shown yet */
603 if (!grab_pointer(TRUE
, OB_CURSOR_NONE
))
605 if (!grab_keyboard(TRUE
)) {
606 grab_pointer(FALSE
, OB_CURSOR_NONE
);
613 menu_frame_hide(parent
->child
);
614 parent
->child
= self
;
616 self
->parent
= parent
;
618 /* determine if the underlying menu is already visible */
619 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
620 ObMenuFrame
*f
= it
->data
;
621 if (f
->menu
== self
->menu
)
625 if (self
->menu
->update_func
)
626 self
->menu
->update_func(self
, self
->menu
->data
);
629 menu_frame_update(self
);
631 menu_frame_visible
= g_list_prepend(menu_frame_visible
, self
);
633 menu_frame_move_on_screen(self
);
635 XMapWindow(ob_display
, self
->window
);
640 void menu_frame_hide(ObMenuFrame
*self
)
642 GList
*it
= g_list_find(menu_frame_visible
, self
);
648 menu_frame_hide(self
->child
);
651 self
->parent
->child
= NULL
;
654 menu_frame_visible
= g_list_delete_link(menu_frame_visible
, it
);
656 if (menu_frame_visible
== NULL
) {
657 /* last menu shown */
658 grab_pointer(FALSE
, OB_CURSOR_NONE
);
659 grab_keyboard(FALSE
);
662 XUnmapWindow(ob_display
, self
->window
);
664 menu_frame_free(self
);
667 void menu_frame_hide_all()
669 GList
*it
= g_list_last(menu_frame_visible
);
671 menu_frame_hide(it
->data
);
674 void menu_frame_hide_all_client(ObClient
*client
)
676 GList
*it
= g_list_last(menu_frame_visible
);
678 ObMenuFrame
*f
= it
->data
;
679 if (f
->client
== client
)
685 ObMenuFrame
* menu_frame_under(gint x
, gint y
)
687 ObMenuFrame
*ret
= NULL
;
690 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
691 ObMenuFrame
*f
= it
->data
;
693 if (RECT_CONTAINS(f
->area
, x
, y
)) {
701 ObMenuEntryFrame
* menu_entry_frame_under(gint x
, gint y
)
704 ObMenuEntryFrame
*ret
= NULL
;
707 if ((frame
= menu_frame_under(x
, y
))) {
708 x
-= ob_rr_theme
->bwidth
+ frame
->area
.x
;
709 y
-= frame
->title_h
+ ob_rr_theme
->bwidth
+ frame
->area
.y
;
711 for (it
= frame
->entries
; it
; it
= g_list_next(it
)) {
712 ObMenuEntryFrame
*e
= it
->data
;
714 if (RECT_CONTAINS(e
->area
, x
, y
)) {
723 void menu_frame_select(ObMenuFrame
*self
, ObMenuEntryFrame
*entry
)
725 ObMenuEntryFrame
*old
= self
->selected
;
726 ObMenuFrame
*oldchild
= self
->child
;
728 if (entry
&& entry
->entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
)
731 if (old
== entry
) return;
733 self
->selected
= entry
;
736 menu_entry_frame_render(old
);
738 menu_frame_hide(oldchild
);
740 if (self
->selected
) {
741 menu_entry_frame_render(self
->selected
);
743 if (self
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
744 menu_entry_frame_show_submenu(self
->selected
);
748 void menu_entry_frame_show_submenu(ObMenuEntryFrame
*self
)
752 if (!self
->entry
->data
.submenu
.submenu
) return;
754 f
= menu_frame_new(self
->entry
->data
.submenu
.submenu
,
755 self
->frame
->client
);
757 self
->frame
->area
.x
+ self
->frame
->area
.width
758 - ob_rr_theme
->menu_overlap
- ob_rr_theme
->bwidth
,
759 self
->frame
->area
.y
+ self
->frame
->title_h
+
760 self
->area
.y
+ ob_rr_theme
->menu_overlap
);
761 menu_frame_show(f
, self
->frame
);
764 void menu_entry_frame_execute(ObMenuEntryFrame
*self
, guint state
)
766 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
767 self
->entry
->data
.normal
.enabled
)
769 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
771 ObMenuEntry
*entry
= self
->entry
;
772 ObMenuExecuteFunc func
= self
->frame
->menu
->execute_func
;
773 gpointer data
= self
->frame
->menu
->data
;
774 GSList
*acts
= self
->entry
->data
.normal
.actions
;
775 ObClient
*client
= self
->frame
->client
;
777 /* release grabs before executing the shit */
778 if (!(state
& ControlMask
))
779 menu_frame_hide_all();
782 func(entry
, state
, data
);
784 action_run(acts
, client
, state
);
788 void menu_frame_select_previous(ObMenuFrame
*self
)
790 GList
*it
= NULL
, *start
;
793 start
= it
= g_list_find(self
->entries
, self
->selected
);
797 it
= it
? g_list_previous(it
) : g_list_last(self
->entries
);
803 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
805 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
806 e
->entry
->data
.normal
.enabled
)
811 menu_frame_select(self
, it
? it
->data
: NULL
);
814 void menu_frame_select_next(ObMenuFrame
*self
)
816 GList
*it
= NULL
, *start
;
819 start
= it
= g_list_find(self
->entries
, self
->selected
);
823 it
= it
? g_list_next(it
) : self
->entries
;
829 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
831 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
832 e
->entry
->data
.normal
.enabled
)
837 menu_frame_select(self
, it
? it
->data
: NULL
);