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"
27 #include "render/theme.h"
30 #define SEPARATOR_HEIGHT 3
31 #define MAX_MENU_WIDTH 400
33 #define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
35 #define TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
36 #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
37 ButtonPressMask | ButtonReleaseMask)
39 GList
*menu_frame_visible
;
41 static ObMenuEntryFrame
* menu_entry_frame_new(ObMenuEntry
*entry
,
43 static void menu_entry_frame_free(ObMenuEntryFrame
*self
);
44 static void menu_frame_render(ObMenuFrame
*self
);
45 static void menu_frame_update(ObMenuFrame
*self
);
47 static Window
createWindow(Window parent
, gulong mask
,
48 XSetWindowAttributes
*attrib
)
50 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
51 RrDepth(ob_rr_inst
), InputOutput
,
52 RrVisual(ob_rr_inst
), mask
, attrib
);
55 ObMenuFrame
* menu_frame_new(ObMenu
*menu
, ObClient
*client
)
58 XSetWindowAttributes attr
;
60 self
= g_new0(ObMenuFrame
, 1);
61 self
->type
= Window_Menu
;
63 self
->selected
= NULL
;
64 self
->show_title
= TRUE
;
65 self
->client
= client
;
67 attr
.event_mask
= FRAME_EVENTMASK
;
68 self
->window
= createWindow(RootWindow(ob_display
, ob_screen
),
70 attr
.event_mask
= TITLE_EVENTMASK
;
71 self
->title
= createWindow(self
->window
, CWEventMask
, &attr
);
72 self
->items
= createWindow(self
->window
, 0, NULL
);
74 XMapWindow(ob_display
, self
->items
);
76 self
->a_title
= RrAppearanceCopy(ob_rr_theme
->a_menu_title
);
77 self
->a_items
= RrAppearanceCopy(ob_rr_theme
->a_menu
);
79 stacking_add(MENU_AS_WINDOW(self
));
84 void menu_frame_free(ObMenuFrame
*self
)
87 while (self
->entries
) {
88 menu_entry_frame_free(self
->entries
->data
);
89 self
->entries
= g_list_delete_link(self
->entries
, self
->entries
);
92 stacking_remove(MENU_AS_WINDOW(self
));
94 XDestroyWindow(ob_display
, self
->items
);
95 XDestroyWindow(ob_display
, self
->title
);
96 XDestroyWindow(ob_display
, self
->window
);
98 RrAppearanceFree(self
->a_items
);
99 RrAppearanceFree(self
->a_title
);
105 static ObMenuEntryFrame
* menu_entry_frame_new(ObMenuEntry
*entry
,
108 ObMenuEntryFrame
*self
;
109 XSetWindowAttributes attr
;
111 self
= g_new0(ObMenuEntryFrame
, 1);
115 attr
.event_mask
= ENTRY_EVENTMASK
;
116 self
->window
= createWindow(self
->frame
->items
, CWEventMask
, &attr
);
117 self
->text
= createWindow(self
->window
, 0, NULL
);
118 if (entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
) {
119 self
->icon
= createWindow(self
->window
, 0, NULL
);
120 self
->bullet
= createWindow(self
->window
, 0, NULL
);
123 XMapWindow(ob_display
, self
->window
);
124 XMapWindow(ob_display
, self
->text
);
126 self
->a_normal
= RrAppearanceCopy(ob_rr_theme
->a_menu_normal
);
127 self
->a_disabled
= RrAppearanceCopy(ob_rr_theme
->a_menu_disabled
);
128 self
->a_selected
= RrAppearanceCopy(ob_rr_theme
->a_menu_selected
);
130 if (entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
) {
131 self
->a_separator
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
132 self
->a_separator
->texture
[0].type
= RR_TEXTURE_LINE_ART
;
134 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
135 self
->a_icon
->texture
[0].type
= RR_TEXTURE_RGBA
;
136 self
->a_mask
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
137 self
->a_mask
->texture
[0].type
= RR_TEXTURE_MASK
;
138 self
->a_bullet_normal
=
139 RrAppearanceCopy(ob_rr_theme
->a_menu_bullet_normal
);
140 self
->a_bullet_selected
=
141 RrAppearanceCopy(ob_rr_theme
->a_menu_bullet_selected
);
144 self
->a_text_normal
=
145 RrAppearanceCopy(ob_rr_theme
->a_menu_text_normal
);
146 self
->a_text_disabled
=
147 RrAppearanceCopy(ob_rr_theme
->a_menu_text_disabled
);
148 self
->a_text_selected
=
149 RrAppearanceCopy(ob_rr_theme
->a_menu_text_selected
);
154 static void menu_entry_frame_free(ObMenuEntryFrame
*self
)
157 XDestroyWindow(ob_display
, self
->text
);
158 XDestroyWindow(ob_display
, self
->window
);
159 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
) {
160 XDestroyWindow(ob_display
, self
->icon
);
161 XDestroyWindow(ob_display
, self
->bullet
);
164 RrAppearanceFree(self
->a_normal
);
165 RrAppearanceFree(self
->a_disabled
);
166 RrAppearanceFree(self
->a_selected
);
168 RrAppearanceFree(self
->a_separator
);
169 RrAppearanceFree(self
->a_icon
);
170 RrAppearanceFree(self
->a_mask
);
171 RrAppearanceFree(self
->a_text_normal
);
172 RrAppearanceFree(self
->a_text_disabled
);
173 RrAppearanceFree(self
->a_text_selected
);
174 RrAppearanceFree(self
->a_bullet_normal
);
175 RrAppearanceFree(self
->a_bullet_selected
);
181 void menu_frame_move(ObMenuFrame
*self
, gint x
, gint y
)
183 RECT_SET_POINT(self
->area
, x
, y
);
184 XMoveWindow(ob_display
, self
->window
, self
->area
.x
, self
->area
.y
);
187 void menu_frame_move_on_screen(ObMenuFrame
*self
)
194 for (i
= 0; i
< screen_num_monitors
; ++i
) {
195 a
= screen_physical_area_monitor(i
);
196 if (RECT_INTERSECTS_RECT(*a
, self
->area
))
199 if (!a
) a
= screen_physical_area_monitor(0);
201 half
= g_list_length(self
->entries
) / 2;
202 pos
= g_list_index(self
->entries
, self
->selected
);
204 /* if in the bottom half then check this shit first, will keep the bottom
205 edge of the menu visible */
207 dx
= MAX(dx
, a
->x
- self
->area
.x
);
208 dy
= MAX(dy
, a
->y
- self
->area
.y
);
210 dx
= MIN(dx
, (a
->x
+ a
->width
) - (self
->area
.x
+ self
->area
.width
));
211 dy
= MIN(dy
, (a
->y
+ a
->height
) - (self
->area
.y
+ self
->area
.height
));
212 /* if in the top half then check this shit last, will keep the top
213 edge of the menu visible */
215 dx
= MAX(dx
, a
->x
- self
->area
.x
);
216 dy
= MAX(dy
, a
->y
- self
->area
.y
);
222 /* move the current menu frame to fit, but dont touch parents yet */
223 menu_frame_move(self
, self
->area
.x
+ dx
, self
->area
.y
+ dy
);
224 if (!config_menu_xorstyle
)
225 dy
= 0; /* if we want to be like xor, move parents in y- *
226 * and x-direction, otherwise just in x-dir */
227 for (f
= self
->parent
; f
; f
= f
->parent
)
228 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
229 for (f
= self
->child
; f
; f
= f
->child
)
230 menu_frame_move(f
, f
->area
.x
+ dx
, f
->area
.y
+ dy
);
231 if (config_menu_warppointer
)
232 XWarpPointer(ob_display
, None
, None
, 0, 0, 0, 0, dx
, dy
);
236 static void menu_entry_frame_render(ObMenuEntryFrame
*self
)
238 RrAppearance
*item_a
, *text_a
;
241 ObMenuFrame
*frame
= self
->frame
;
243 item_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
244 !self
->entry
->data
.normal
.enabled
) ?
246 (self
== self
->frame
->selected
?
249 switch (self
->entry
->type
) {
250 case OB_MENU_ENTRY_TYPE_NORMAL
:
251 case OB_MENU_ENTRY_TYPE_SUBMENU
:
252 th
= self
->frame
->item_h
;
254 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
255 th
= SEPARATOR_HEIGHT
+ 2*PADDING
;
258 RECT_SET_SIZE(self
->area
, self
->frame
->inner_w
, th
);
259 XResizeWindow(ob_display
, self
->window
,
260 self
->area
.width
, self
->area
.height
);
261 item_a
->surface
.parent
= self
->frame
->a_items
;
262 item_a
->surface
.parentx
= self
->area
.x
;
263 item_a
->surface
.parenty
= self
->area
.y
;
264 RrPaint(item_a
, self
->window
, self
->area
.width
, self
->area
.height
);
266 text_a
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
267 !self
->entry
->data
.normal
.enabled
) ?
268 self
->a_text_disabled
:
269 (self
== self
->frame
->selected
?
270 self
->a_text_selected
:
271 self
->a_text_normal
));
272 switch (self
->entry
->type
) {
273 case OB_MENU_ENTRY_TYPE_NORMAL
:
274 text_a
->texture
[0].data
.text
.string
= self
->entry
->data
.normal
.label
;
276 case OB_MENU_ENTRY_TYPE_SUBMENU
:
277 sub
= self
->entry
->data
.submenu
.submenu
;
278 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
280 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
284 switch (self
->entry
->type
) {
285 case OB_MENU_ENTRY_TYPE_NORMAL
:
286 XMoveResizeWindow(ob_display
, self
->text
,
287 self
->frame
->text_x
, PADDING
,
289 self
->frame
->item_h
- 2*PADDING
);
290 text_a
->surface
.parent
= item_a
;
291 text_a
->surface
.parentx
= self
->frame
->text_x
;
292 text_a
->surface
.parenty
= PADDING
;
293 RrPaint(text_a
, self
->text
, self
->frame
->text_w
,
294 self
->frame
->item_h
- 2*PADDING
);
296 case OB_MENU_ENTRY_TYPE_SUBMENU
:
297 XMoveResizeWindow(ob_display
, self
->text
,
298 self
->frame
->text_x
, PADDING
,
299 self
->frame
->text_w
- self
->frame
->item_h
,
300 self
->frame
->item_h
- 2*PADDING
);
301 text_a
->surface
.parent
= item_a
;
302 text_a
->surface
.parentx
= self
->frame
->text_x
;
303 text_a
->surface
.parenty
= PADDING
;
304 RrPaint(text_a
, self
->text
, self
->frame
->text_w
- self
->frame
->item_h
,
305 self
->frame
->item_h
- 2*PADDING
);
307 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
308 XMoveResizeWindow(ob_display
, self
->text
, PADDING
, PADDING
,
309 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
310 self
->a_separator
->surface
.parent
= item_a
;
311 self
->a_separator
->surface
.parentx
= PADDING
;
312 self
->a_separator
->surface
.parenty
= PADDING
;
313 self
->a_separator
->texture
[0].data
.lineart
.color
=
314 text_a
->texture
[0].data
.text
.color
;
315 self
->a_separator
->texture
[0].data
.lineart
.x1
= 2*PADDING
;
316 self
->a_separator
->texture
[0].data
.lineart
.y1
= SEPARATOR_HEIGHT
/ 2;
317 self
->a_separator
->texture
[0].data
.lineart
.x2
=
318 self
->area
.width
- 4*PADDING
;
319 self
->a_separator
->texture
[0].data
.lineart
.y2
= SEPARATOR_HEIGHT
/ 2;
320 RrPaint(self
->a_separator
, self
->text
,
321 self
->area
.width
- 2*PADDING
, SEPARATOR_HEIGHT
);
325 if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
326 self
->entry
->data
.normal
.icon_data
)
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_icon
->texture
[0].data
.rgba
.width
=
335 self
->entry
->data
.normal
.icon_width
;
336 self
->a_icon
->texture
[0].data
.rgba
.height
=
337 self
->entry
->data
.normal
.icon_height
;
338 self
->a_icon
->texture
[0].data
.rgba
.data
=
339 self
->entry
->data
.normal
.icon_data
;
340 self
->a_icon
->surface
.parent
= item_a
;
341 self
->a_icon
->surface
.parentx
= PADDING
;
342 self
->a_icon
->surface
.parenty
= frame
->item_margin
.top
;
343 RrPaint(self
->a_icon
, self
->icon
,
344 self
->frame
->item_h
- frame
->item_margin
.top
345 - frame
->item_margin
.bottom
,
346 self
->frame
->item_h
- frame
->item_margin
.top
347 - frame
->item_margin
.bottom
);
348 XMapWindow(ob_display
, self
->icon
);
349 } else if (self
->entry
->type
!= OB_MENU_ENTRY_TYPE_SEPARATOR
&&
350 self
->entry
->data
.normal
.mask
)
354 XMoveResizeWindow(ob_display
, self
->icon
,
355 PADDING
, frame
->item_margin
.top
,
356 self
->frame
->item_h
- frame
->item_margin
.top
357 - frame
->item_margin
.bottom
,
358 self
->frame
->item_h
- frame
->item_margin
.top
359 - frame
->item_margin
.bottom
);
360 self
->a_mask
->texture
[0].data
.mask
.mask
=
361 self
->entry
->data
.normal
.mask
;
363 c
= ((self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
364 !self
->entry
->data
.normal
.enabled
) ?
365 self
->entry
->data
.normal
.mask_disabled_color
:
366 (self
== self
->frame
->selected
?
367 self
->entry
->data
.normal
.mask_selected_color
:
368 self
->entry
->data
.normal
.mask_normal_color
));
369 self
->a_mask
->texture
[0].data
.mask
.color
= c
;
371 self
->a_mask
->surface
.parent
= item_a
;
372 self
->a_mask
->surface
.parentx
= PADDING
;
373 self
->a_mask
->surface
.parenty
= frame
->item_margin
.top
;
374 RrPaint(self
->a_mask
, self
->icon
,
375 self
->frame
->item_h
- frame
->item_margin
.top
376 - frame
->item_margin
.bottom
,
377 self
->frame
->item_h
- frame
->item_margin
.top
378 - frame
->item_margin
.bottom
);
379 XMapWindow(ob_display
, self
->icon
);
381 XUnmapWindow(ob_display
, self
->icon
);
383 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
) {
384 RrAppearance
*bullet_a
;
385 XMoveResizeWindow(ob_display
, self
->bullet
,
386 self
->frame
->text_x
+ self
->frame
->text_w
387 - self
->frame
->item_h
+ PADDING
, PADDING
,
388 self
->frame
->item_h
- 2*PADDING
,
389 self
->frame
->item_h
- 2*PADDING
);
390 bullet_a
= (self
== self
->frame
->selected
?
391 self
->a_bullet_selected
:
392 self
->a_bullet_normal
);
393 bullet_a
->surface
.parent
= item_a
;
394 bullet_a
->surface
.parentx
=
395 self
->frame
->text_x
+ self
->frame
->text_w
- self
->frame
->item_h
397 bullet_a
->surface
.parenty
= PADDING
;
398 RrPaint(bullet_a
, self
->bullet
,
399 self
->frame
->item_h
- 2*PADDING
,
400 self
->frame
->item_h
- 2*PADDING
);
401 XMapWindow(ob_display
, self
->bullet
);
403 XUnmapWindow(ob_display
, self
->bullet
);
408 static void menu_frame_render(ObMenuFrame
*self
)
412 gint tw
, th
; /* temps */
414 gboolean has_icon
= FALSE
;
417 XSetWindowBorderWidth(ob_display
, self
->window
, ob_rr_theme
->bwidth
);
418 XSetWindowBorder(ob_display
, self
->window
,
419 RrColorPixel(ob_rr_theme
->b_color
));
421 if (!self
->parent
&& self
->show_title
) {
422 XMoveWindow(ob_display
, self
->title
,
423 -ob_rr_theme
->bwidth
, h
- ob_rr_theme
->bwidth
);
425 self
->a_title
->texture
[0].data
.text
.string
= self
->menu
->title
;
426 RrMinsize(self
->a_title
, &tw
, &th
);
427 tw
= MIN(tw
, MAX_MENU_WIDTH
) + ob_rr_theme
->padding
* 2;
430 th
= ob_rr_theme
->menu_title_height
;
431 h
+= (self
->title_h
= th
+ ob_rr_theme
->bwidth
);
433 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
434 XSetWindowBorder(ob_display
, self
->title
,
435 RrColorPixel(ob_rr_theme
->b_color
));
438 XMoveWindow(ob_display
, self
->items
, 0, h
);
440 STRUT_SET(self
->item_margin
, 0, 0, 0, 0);
443 ObMenuEntryFrame
*e
= self
->entries
->data
;
446 e
->a_text_normal
->texture
[0].data
.text
.string
= "";
447 RrMinsize(e
->a_text_normal
, &tw
, &th
);
452 RrMargins(e
->a_normal
, &l
, &t
, &r
, &b
);
453 STRUT_SET(self
->item_margin
,
454 MAX(self
->item_margin
.left
, l
),
455 MAX(self
->item_margin
.top
, t
),
456 MAX(self
->item_margin
.right
, r
),
457 MAX(self
->item_margin
.bottom
, b
));
458 RrMargins(e
->a_selected
, &l
, &t
, &r
, &b
);
459 STRUT_SET(self
->item_margin
,
460 MAX(self
->item_margin
.left
, l
),
461 MAX(self
->item_margin
.top
, t
),
462 MAX(self
->item_margin
.right
, r
),
463 MAX(self
->item_margin
.bottom
, b
));
464 RrMargins(e
->a_disabled
, &l
, &t
, &r
, &b
);
465 STRUT_SET(self
->item_margin
,
466 MAX(self
->item_margin
.left
, l
),
467 MAX(self
->item_margin
.top
, t
),
468 MAX(self
->item_margin
.right
, r
),
469 MAX(self
->item_margin
.bottom
, b
));
473 for (it
= self
->entries
; it
; it
= g_list_next(it
)) {
474 RrAppearance
*text_a
;
475 ObMenuEntryFrame
*e
= it
->data
;
477 RECT_SET_POINT(e
->area
, 0, allitems_h
);
478 XMoveWindow(ob_display
, e
->window
, 0, e
->area
.y
);
480 text_a
= ((e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
481 !e
->entry
->data
.normal
.enabled
) ?
483 (e
== self
->selected
?
486 switch (e
->entry
->type
) {
487 case OB_MENU_ENTRY_TYPE_NORMAL
:
488 text_a
->texture
[0].data
.text
.string
= e
->entry
->data
.normal
.label
;
489 RrMinsize(text_a
, &tw
, &th
);
490 tw
= MIN(tw
, MAX_MENU_WIDTH
);
492 if (e
->entry
->data
.normal
.icon_data
||
493 e
->entry
->data
.normal
.mask
)
496 case OB_MENU_ENTRY_TYPE_SUBMENU
:
497 sub
= e
->entry
->data
.submenu
.submenu
;
498 text_a
->texture
[0].data
.text
.string
= sub
? sub
->title
: "";
499 RrMinsize(text_a
, &tw
, &th
);
500 tw
= MIN(tw
, MAX_MENU_WIDTH
);
502 if (e
->entry
->data
.normal
.icon_data
||
503 e
->entry
->data
.normal
.mask
)
506 tw
+= self
->item_h
- PADDING
;
508 case OB_MENU_ENTRY_TYPE_SEPARATOR
:
510 th
= SEPARATOR_HEIGHT
;
520 self
->text_x
= PADDING
;
525 w
+= self
->item_h
+ PADDING
;
526 self
->text_x
+= self
->item_h
+ PADDING
;
536 XResizeWindow(ob_display
, self
->window
, w
, h
);
537 XResizeWindow(ob_display
, self
->items
, w
, allitems_h
);
541 if (!self
->parent
&& self
->show_title
) {
542 XResizeWindow(ob_display
, self
->title
,
543 w
, self
->title_h
- ob_rr_theme
->bwidth
);
544 RrPaint(self
->a_title
, self
->title
,
545 w
, self
->title_h
- ob_rr_theme
->bwidth
);
546 XMapWindow(ob_display
, self
->title
);
548 XUnmapWindow(ob_display
, self
->title
);
550 RrPaint(self
->a_items
, self
->items
, w
, allitems_h
);
552 for (it
= self
->entries
; it
; it
= g_list_next(it
))
553 menu_entry_frame_render(it
->data
);
555 w
+= ob_rr_theme
->bwidth
* 2;
556 h
+= ob_rr_theme
->bwidth
* 2;
558 RECT_SET_SIZE(self
->area
, w
, h
);
563 static void menu_frame_update(ObMenuFrame
*self
)
567 menu_pipe_execute(self
->menu
);
568 menu_find_submenus(self
->menu
);
570 self
->selected
= NULL
;
572 for (mit
= self
->menu
->entries
, fit
= self
->entries
; mit
&& fit
;
573 mit
= g_list_next(mit
), fit
= g_list_next(fit
))
575 ObMenuEntryFrame
*f
= fit
->data
;
576 f
->entry
= mit
->data
;
580 ObMenuEntryFrame
*e
= menu_entry_frame_new(mit
->data
, self
);
581 self
->entries
= g_list_append(self
->entries
, e
);
582 mit
= g_list_next(mit
);
586 GList
*n
= g_list_next(fit
);
587 menu_entry_frame_free(fit
->data
);
588 self
->entries
= g_list_delete_link(self
->entries
, fit
);
592 menu_frame_render(self
);
595 gboolean
menu_frame_show(ObMenuFrame
*self
, ObMenuFrame
*parent
)
599 if (g_list_find(menu_frame_visible
, self
))
602 if (menu_frame_visible
== NULL
) {
603 /* no menus shown yet */
604 if (!grab_pointer(TRUE
, OB_CURSOR_NONE
))
606 if (!grab_keyboard(TRUE
)) {
607 grab_pointer(FALSE
, OB_CURSOR_NONE
);
614 menu_frame_hide(parent
->child
);
615 parent
->child
= self
;
617 self
->parent
= parent
;
619 /* determine if the underlying menu is already visible */
620 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
621 ObMenuFrame
*f
= it
->data
;
622 if (f
->menu
== self
->menu
)
626 if (self
->menu
->update_func
)
627 self
->menu
->update_func(self
, self
->menu
->data
);
630 menu_frame_update(self
);
632 menu_frame_visible
= g_list_prepend(menu_frame_visible
, self
);
634 menu_frame_move_on_screen(self
);
636 XMapWindow(ob_display
, self
->window
);
641 void menu_frame_hide(ObMenuFrame
*self
)
643 GList
*it
= g_list_find(menu_frame_visible
, self
);
649 menu_frame_hide(self
->child
);
652 self
->parent
->child
= NULL
;
655 menu_frame_visible
= g_list_delete_link(menu_frame_visible
, it
);
657 if (menu_frame_visible
== NULL
) {
658 /* last menu shown */
659 grab_pointer(FALSE
, OB_CURSOR_NONE
);
660 grab_keyboard(FALSE
);
663 XUnmapWindow(ob_display
, self
->window
);
665 menu_frame_free(self
);
668 void menu_frame_hide_all()
670 GList
*it
= g_list_last(menu_frame_visible
);
672 menu_frame_hide(it
->data
);
675 void menu_frame_hide_all_client(ObClient
*client
)
677 GList
*it
= g_list_last(menu_frame_visible
);
679 ObMenuFrame
*f
= it
->data
;
680 if (f
->client
== client
)
686 ObMenuFrame
* menu_frame_under(gint x
, gint y
)
688 ObMenuFrame
*ret
= NULL
;
691 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
692 ObMenuFrame
*f
= it
->data
;
694 if (RECT_CONTAINS(f
->area
, x
, y
)) {
702 ObMenuEntryFrame
* menu_entry_frame_under(gint x
, gint y
)
705 ObMenuEntryFrame
*ret
= NULL
;
708 if ((frame
= menu_frame_under(x
, y
))) {
709 x
-= ob_rr_theme
->bwidth
+ frame
->area
.x
;
710 y
-= frame
->title_h
+ ob_rr_theme
->bwidth
+ frame
->area
.y
;
712 for (it
= frame
->entries
; it
; it
= g_list_next(it
)) {
713 ObMenuEntryFrame
*e
= it
->data
;
715 if (RECT_CONTAINS(e
->area
, x
, y
)) {
724 void menu_frame_select(ObMenuFrame
*self
, ObMenuEntryFrame
*entry
)
726 ObMenuEntryFrame
*old
= self
->selected
;
727 ObMenuFrame
*oldchild
= self
->child
;
729 if (entry
&& entry
->entry
->type
== OB_MENU_ENTRY_TYPE_SEPARATOR
)
732 if (old
== entry
) return;
734 self
->selected
= entry
;
737 menu_entry_frame_render(old
);
739 menu_frame_hide(oldchild
);
741 if (self
->selected
) {
742 menu_entry_frame_render(self
->selected
);
744 if (self
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
745 menu_entry_frame_show_submenu(self
->selected
);
749 void menu_entry_frame_show_submenu(ObMenuEntryFrame
*self
)
753 if (!self
->entry
->data
.submenu
.submenu
) return;
755 f
= menu_frame_new(self
->entry
->data
.submenu
.submenu
,
756 self
->frame
->client
);
758 self
->frame
->area
.x
+ self
->frame
->area
.width
759 - ob_rr_theme
->menu_overlap
- ob_rr_theme
->bwidth
,
760 self
->frame
->area
.y
+ self
->frame
->title_h
+
761 self
->area
.y
+ ob_rr_theme
->menu_overlap
);
762 menu_frame_show(f
, self
->frame
);
765 void menu_entry_frame_execute(ObMenuEntryFrame
*self
, guint state
)
767 if (self
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
768 self
->entry
->data
.normal
.enabled
)
770 /* grab all this shizzle, cuz when the menu gets hidden, 'self'
772 ObMenuEntry
*entry
= self
->entry
;
773 ObMenuExecuteFunc func
= self
->frame
->menu
->execute_func
;
774 gpointer data
= self
->frame
->menu
->data
;
775 GSList
*acts
= self
->entry
->data
.normal
.actions
;
776 ObClient
*client
= self
->frame
->client
;
778 /* release grabs before executing the shit */
779 if (!(state
& ControlMask
))
780 menu_frame_hide_all();
783 func(entry
, state
, data
);
785 action_run(acts
, client
, state
);
789 void menu_frame_select_previous(ObMenuFrame
*self
)
791 GList
*it
= NULL
, *start
;
794 start
= it
= g_list_find(self
->entries
, self
->selected
);
798 it
= it
? g_list_previous(it
) : g_list_last(self
->entries
);
804 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
806 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
807 e
->entry
->data
.normal
.enabled
)
812 menu_frame_select(self
, it
? it
->data
: NULL
);
815 void menu_frame_select_next(ObMenuFrame
*self
)
817 GList
*it
= NULL
, *start
;
820 start
= it
= g_list_find(self
->entries
, self
->selected
);
824 it
= it
? g_list_next(it
) : self
->entries
;
830 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
832 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
833 e
->entry
->data
.normal
.enabled
)
838 menu_frame_select(self
, it
? it
->data
: NULL
);