1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1997, 1998 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
36 #include "WindowMaker.h"
46 /****** Global Variables ******/
48 extern Cursor wCursor
[WCUR_LAST
];
50 extern XContext wWinContext
;
52 extern WPreferences wPreferences
;
54 #define MOD_MASK wPreferences.modifier_mask
56 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
57 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
61 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
62 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
65 /***** Local Stuff ******/
70 } menuScrollParameters
[5] = {
71 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
72 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
73 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
74 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
75 {MENU_SCROLL_STEPS_U
, MENU_SCROLL_DELAY_U
}};
78 static void menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
79 static void menuExpose(WObjDescriptor
*desc
, XEvent
*event
);
81 static void menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
82 static void menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
84 static void menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
86 static void updateTexture(WMenu
*menu
);
89 static int saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
);
90 static int restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
);
93 static void selectEntry(WMenu
*menu
, int entry_no
);
94 static void closeCascade(WMenu
*menu
);
97 /****** Notification Observers ******/
100 appearanceObserver(void *self
, WMNotification
*notif
)
102 WMenu
*menu
= (WMenu
*)self
;
103 int flags
= (int)WMGetNotificationClientData(notif
);
105 if (!menu
->flags
.realized
)
108 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
109 if (flags
& WFontSettings
) {
110 menu
->flags
.realized
= 0;
113 if (flags
& WTextureSettings
) {
114 if (!menu
->flags
.brother
)
117 if (flags
& (WTextureSettings
|WColorSettings
)) {
120 } else if (menu
->flags
.titled
) {
122 if (flags
& WFontSettings
) {
123 menu
->flags
.realized
= 0;
126 if (flags
& WTextureSettings
) {
127 menu
->frame
->flags
.need_texture_remake
= 1;
129 if (flags
& (WColorSettings
|WTextureSettings
)) {
130 wFrameWindowPaint(menu
->frame
);
135 /************************************/
139 *----------------------------------------------------------------------
141 * Creates a new empty menu with the specified title. If main_menu
142 * is True, the created menu will be a main menu, which has some special
143 * properties such as being placed over other normal menus.
144 * If title is NULL, the menu will have no titlebar.
148 *----------------------------------------------------------------------
151 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
154 static int brother
=0;
157 menu
= wmalloc(sizeof(WMenu
));
159 memset(menu
, 0, sizeof(WMenu
));
161 #ifdef SINGLE_MENULEVEL
162 tmp
= WMSubmenuLevel
;
164 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
167 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
169 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
170 menu
->flags
.titled
= 1;
173 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
174 screen
->menu_title_texture
, NULL
,
175 screen
->menu_title_pixel
,
176 #ifdef DRAWSTRING_PLUGIN
179 &screen
->menu_title_gc
,
180 &screen
->menu_title_font
);
182 menu
->frame
->core
->descriptor
.parent
= menu
;
183 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
184 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
186 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
189 menu
->frame
->title
= wstrdup(title
);
192 menu
->frame
->flags
.justification
= WTJ_LEFT
;
194 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
197 menu
->alloced_entries
= 0;
198 menu
->selected_entry
= -1;
199 menu
->entries
= NULL
;
201 menu
->frame_x
= screen
->app_menu_x
;
202 menu
->frame_y
= screen
->app_menu_y
;
204 menu
->frame
->child
= menu
;
206 menu
->flags
.lowered
= 0;
210 /* setup object descriptors */
211 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
212 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
215 menu
->frame
->on_click_right
= menuCloseClick
;
218 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
219 menu
->frame
->core
->width
, 10);
221 menu
->menu
->descriptor
.parent
= menu
;
222 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
223 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
224 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
226 menu
->menu_texture_data
= None
;
228 XMapWindow(dpy
, menu
->menu
->window
);
234 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
236 menu
->brother
->flags
.brother
= 1;
237 menu
->brother
->brother
= menu
;
239 WMAddNotificationObserver(appearanceObserver
, menu
,
240 WNMenuAppearanceSettingsChanged
, menu
);
242 WMAddNotificationObserver(appearanceObserver
, menu
,
243 WNMenuTitleAppearanceSettingsChanged
, menu
);
253 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
257 menu
= wMenuCreate(screen
, title
, main_menu
);
260 menu
->flags
.app_menu
= 1;
261 menu
->brother
->flags
.app_menu
= 1;
269 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
273 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
274 menu
->entries
[i
]->order
++;
275 menu
->entries
[i
+1] = menu
->entries
[i
];
277 menu
->entries
[index
] = entry
;
282 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
283 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
288 menu
->flags
.realized
= 0;
289 menu
->brother
->flags
.realized
= 0;
291 /* reallocate array if it's too small */
292 if (menu
->entry_no
>= menu
->alloced_entries
) {
295 tmp
= wrealloc(menu
->entries
,
296 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
299 menu
->alloced_entries
+= 5;
301 menu
->brother
->entries
= tmp
;
302 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
304 entry
= wmalloc(sizeof(WMenuEntry
));
305 memset(entry
, 0, sizeof(WMenuEntry
));
306 entry
->flags
.enabled
= 1;
307 entry
->text
= wstrdup(text
);
309 entry
->clientdata
= clientdata
;
310 entry
->callback
= callback
;
311 if (index
<0 || index
>=menu
->entry_no
) {
312 entry
->order
= menu
->entry_no
;
313 menu
->entries
[menu
->entry_no
] = entry
;
315 entry
->order
= index
;
316 insertEntry(menu
, entry
, index
);
320 menu
->brother
->entry_no
= menu
->entry_no
;
328 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
330 WMenu
*brother
= menu
->brother
;
333 assert(menu
->flags
.brother
==0);
335 if (entry
->cascade
>=0) {
336 menu
->flags
.realized
= 0;
337 brother
->flags
.realized
= 0;
340 cascade
->parent
= menu
;
342 cascade
->brother
->parent
= brother
;
345 for (i
=0; i
<menu
->cascade_no
; i
++) {
346 if (menu
->cascades
[i
]==NULL
) {
347 menu
->cascades
[i
] = cascade
;
348 brother
->cascades
[i
] = cascade
->brother
;
355 entry
->cascade
= menu
->cascade_no
;
357 menu
->cascades
= wrealloc(menu
->cascades
,
358 sizeof(WMenu
)*(menu
->cascade_no
+1));
359 menu
->cascades
[menu
->cascade_no
++] = cascade
;
362 brother
->cascades
= wrealloc(brother
->cascades
,
363 sizeof(WMenu
)*(brother
->cascade_no
+1));
364 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
368 if (menu
->flags
.lowered
) {
370 cascade
->flags
.lowered
= 1;
371 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
373 cascade
->brother
->flags
.lowered
= 1;
374 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
377 if (!menu
->flags
.realized
)
383 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
385 assert(menu
->flags
.brother
==0);
387 /* destroy cascade menu */
388 if (entry
->cascade
>=0 && menu
->cascades
389 && menu
->cascades
[entry
->cascade
]!=NULL
) {
391 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
393 menu
->cascades
[entry
->cascade
] = NULL
;
394 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
402 wMenuRemoveItem(WMenu
*menu
, int index
)
406 if (menu
->flags
.brother
) {
407 wMenuRemoveItem(menu
->brother
, index
);
411 if (index
>=menu
->entry_no
) return;
413 /* destroy cascade menu */
414 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
416 /* destroy unshared data */
418 if (menu
->entries
[index
]->text
)
419 free(menu
->entries
[index
]->text
);
421 if (menu
->entries
[index
]->rtext
)
422 free(menu
->entries
[index
]->rtext
);
424 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
425 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
427 free(menu
->entries
[index
]);
429 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
430 menu
->entries
[i
+1]->order
--;
431 menu
->entries
[i
]=menu
->entries
[i
+1];
434 menu
->brother
->entry_no
--;
439 renderTexture(WMenu
*menu
)
447 WScreen
*scr
= menu
->menu
->screen_ptr
;
448 WTexture
*texture
= scr
->menu_item_texture
;
450 if (wPreferences
.menu_style
== MS_NORMAL
) {
451 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
452 menu
->entry_height
, WREL_MENUENTRY
);
454 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
455 menu
->menu
->height
+1, WREL_MENUENTRY
);
458 wwarning(_("could not render texture: %s"),
459 RMessageForError(RErrorCode
));
464 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
466 light
.red
= light
.green
= light
.blue
= 80;
469 dark
.red
= dark
.green
= dark
.blue
= 0;
472 mid
.red
= mid
.green
= mid
.blue
= 40;
474 for (i
= 1; i
< menu
->entry_no
; i
++) {
475 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
476 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
478 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
479 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
481 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
482 menu
->menu
->width
-1, i
*menu
->entry_height
,
486 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
487 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
496 updateTexture(WMenu
*menu
)
498 WScreen
*scr
= menu
->menu
->screen_ptr
;
500 /* setup background texture */
501 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
502 if (!menu
->flags
.brother
) {
503 FREE_PIXMAP(menu
->menu_texture_data
);
505 menu
->menu_texture_data
= renderTexture(menu
);
507 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
508 menu
->menu_texture_data
);
509 XClearWindow(dpy
, menu
->menu
->window
);
511 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
512 menu
->menu_texture_data
);
513 XClearWindow(dpy
, menu
->brother
->menu
->window
);
516 XSetWindowBackground(dpy
, menu
->menu
->window
,
517 scr
->menu_item_texture
->any
.color
.pixel
);
518 XClearWindow(dpy
, menu
->menu
->window
);
524 wMenuRealize(WMenu
*menu
)
527 int width
, rwidth
, mrwidth
, mwidth
;
528 int theight
, twidth
, eheight
;
529 WScreen
*scr
= menu
->frame
->screen_ptr
;
530 static int brother_done
=0;
535 wMenuRealize(menu
->brother
);
539 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
540 if (menu
->flags
.titled
)
541 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
543 wFrameWindowUpdateBorders(menu
->frame
, flags
);
545 if (menu
->flags
.titled
) {
546 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
547 strlen(menu
->frame
->title
));
548 theight
= menu
->frame
->top_width
;
549 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
554 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
555 menu
->entry_height
= eheight
;
558 for (i
=0; i
<menu
->entry_no
; i
++) {
561 /* search widest text */
562 text
= menu
->entries
[i
]->text
;
563 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
565 if (menu
->entries
[i
]->flags
.indicator
) {
566 width
+= MENU_INDICATOR_SPACE
;
572 /* search widest text on right */
573 text
= menu
->entries
[i
]->rtext
;
575 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
577 else if (menu
->entries
[i
]->cascade
>=0)
582 if (rwidth
> mrwidth
)
591 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
593 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
594 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
599 menu
->flags
.realized
= 1;
601 if (menu
->flags
.mapped
)
603 if (menu
->brother
->flags
.mapped
)
604 wMenuPaint(menu
->brother
);
609 wMenuDestroy(WMenu
*menu
, int recurse
)
613 WMRemoveNotificationObserver(menu
);
615 /* remove any pending timers */
617 WMDeleteTimerHandler(menu
->timer
);
620 /* call destroy handler */
621 if (menu
->on_destroy
)
622 (*menu
->on_destroy
)(menu
);
624 /* Destroy items if this menu own them. If this is the "brother" menu,
625 * leave them alone as it is shared by them.
627 if (!menu
->flags
.brother
) {
628 for (i
=0; i
<menu
->entry_no
; i
++) {
630 free(menu
->entries
[i
]->text
);
632 if (menu
->entries
[i
]->rtext
)
633 free(menu
->entries
[i
]->rtext
);
636 if (menu
->entries
[i
]->instances
){
637 PLRelease(menu
->entries
[i
]->instances
);
639 #endif /* USER_MENU */
641 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
642 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
644 free(menu
->entries
[i
]);
648 for (i
=0; i
<menu
->cascade_no
; i
++) {
649 if (menu
->cascades
[i
]) {
650 if (menu
->cascades
[i
]->flags
.brother
)
651 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
653 wMenuDestroy(menu
->cascades
[i
], recurse
);
663 FREE_PIXMAP(menu
->menu_texture_data
);
666 free(menu
->cascades
);
668 wCoreDestroy(menu
->menu
);
669 wFrameWindowDestroy(menu
->frame
);
671 /* destroy copy of this menu */
672 if (!menu
->flags
.brother
&& menu
->brother
)
673 wMenuDestroy(menu
->brother
, False
);
685 drawFrame(WScreen
*scr
, Window win
, int y
, int w
, int h
, int type
)
691 segs
[i
].x1
= segs
[i
].x2
= w
-1;
693 segs
[i
].y2
= y
+ h
- 1;
695 if (type
!= F_TOP
&& type
!= F_NONE
) {
697 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
701 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
707 segs
[i
].y2
= y
+ h
- 1;
709 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
716 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
718 if (type
!= F_TOP
&& type
!= F_NONE
)
719 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
725 paintEntry(WMenu
*menu
, int index
, int selected
)
729 GC light
, dim
, dark
, textGC
;
730 WScreen
*scr
=menu
->frame
->screen_ptr
;
731 Window win
= menu
->menu
->window
;
732 WMenuEntry
*entry
=menu
->entries
[index
];
734 if (!menu
->flags
.realized
) return;
735 h
= menu
->entry_height
;
736 w
= menu
->menu
->width
;
739 light
= scr
->menu_item_auxtexture
->light_gc
;
740 dim
= scr
->menu_item_auxtexture
->dim_gc
;
741 dark
= scr
->menu_item_auxtexture
->dark_gc
;
743 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
746 else if (index
== menu
->entry_no
- 1)
754 /* paint background */
756 XSetForeground(dpy
, scr
->select_menu_gc
, scr
->select_pixel
);
757 XFillRectangle(dpy
, win
, scr
->select_menu_gc
, 1, y
+1, w
-2, h
-3);
758 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
759 drawFrame(scr
, win
, y
, w
, h
, type
);
761 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
762 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
764 drawFrame(scr
, win
, y
, w
, h
, type
);
766 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
771 textGC
= scr
->select_menu_gc
;
772 if (entry
->flags
.enabled
)
773 XSetForeground(dpy
, textGC
, scr
->select_text_pixel
);
775 XSetForeground(dpy
, textGC
, scr
->dtext_pixel
);
776 } else if (!entry
->flags
.enabled
) {
777 textGC
= scr
->disabled_menu_entry_gc
;
779 textGC
= scr
->menu_entry_gc
;
783 if (entry
->flags
.indicator
)
784 x
+= MENU_INDICATOR_SPACE
+ 2;
786 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
,
787 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
789 if (entry
->cascade
>=0) {
790 /* draw the cascade indicator */
791 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
792 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
793 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
797 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
802 switch (entry
->flags
.indicator_type
) {
804 indicator
= scr
->menu_check_indicator
;
807 indicator
= scr
->menu_mini_indicator
;
810 indicator
= scr
->menu_hide_indicator
;
813 indicator
= scr
->menu_shade_indicator
;
817 indicator
= scr
->menu_radio_indicator
;
821 iw
= indicator
->width
;
822 ih
= indicator
->height
;
823 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
824 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
826 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
828 XSetForeground(dpy
, scr
->copy_gc
, scr
->mtext_pixel
);
829 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
831 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
832 iw, ih, 5, y+(h-ih)/2);
834 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
837 /* draw right text */
839 if (entry
->rtext
&& entry
->cascade
<0) {
840 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
841 strlen(entry
->rtext
));
843 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
, w
-6-tw
,
844 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
850 move_menus(WMenu
*menu
, int x
, int y
)
852 while (menu
->parent
) {
855 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
856 y
-= menu
->selected_entry
*menu
->entry_height
;
859 wMenuMove(menu
, x
, y
, True
);
863 makeVisible(WMenu
*menu
)
865 WScreen
*scr
= menu
->frame
->screen_ptr
;
866 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
868 if (menu
->entry_no
<0) return;
871 y1
= menu
->frame_y
+menu
->frame
->top_width
872 + menu
->selected_entry
*menu
->entry_height
;
873 x2
= x1
+ MENUW(menu
);
874 y2
= y1
+ menu
->entry_height
;
883 } else if (x2
>= scr
->scr_width
) {
884 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
891 } else if (y2
>= scr
->scr_height
) {
892 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
896 new_y
= new_y
- menu
->frame
->top_width
897 - menu
->selected_entry
*menu
->entry_height
;
898 move_menus(menu
, new_x
, new_y
);
903 check_key(WMenu
*menu
, XKeyEvent
*event
)
908 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
911 ch
= toupper(buffer
[0]);
913 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
916 for (i
=s
; i
<menu
->entry_no
; i
++) {
917 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
921 /* no match. Retry from start, if previous started from a selected entry */
931 keyboardMenu(WMenu
*menu
)
934 KeySym ksym
=NoSymbol
;
938 int old_pos_x
= menu
->frame_x
;
939 int old_pos_y
= menu
->frame_y
;
940 int new_x
= old_pos_x
, new_y
= old_pos_y
;
941 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
942 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
944 if (menu
->flags
.editing
)
948 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
949 GrabModeAsync
, CurrentTime
);
951 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
952 new_y
= scr_height
- menu
->frame
->top_width
;
954 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
955 new_x
= scr_width
-MENUW(menu
)-1;
957 move_menus(menu
, new_x
, new_y
);
959 while (!done
&& menu
->flags
.mapped
) {
960 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
961 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
962 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
963 |SubstructureNotifyMask
, &event
);
965 switch (event
.type
) {
967 ksym
= XLookupKeysym(&event
.xkey
, 0);
975 selectEntry(menu
, 0);
981 selectEntry(menu
, menu
->entry_no
-1);
990 if (menu
->selected_entry
<= 0)
991 selectEntry(menu
, menu
->entry_no
-1);
993 selectEntry(menu
, menu
->selected_entry
-1);
1002 if (menu
->selected_entry
<0)
1003 selectEntry(menu
, 0);
1004 else if (menu
->selected_entry
== menu
->entry_no
-1)
1005 selectEntry(menu
, 0);
1006 else if (menu
->selected_entry
< menu
->entry_no
-1)
1007 selectEntry(menu
, menu
->selected_entry
+1);
1012 #ifdef ARROWLESS_KBD
1016 if (menu
->selected_entry
>=0) {
1018 entry
= menu
->entries
[menu
->selected_entry
];
1020 if (entry
->cascade
>= 0 && menu
->cascades
1021 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1023 XUngrabKeyboard(dpy
, CurrentTime
);
1025 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1026 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1029 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1030 GrabModeAsync
, GrabModeAsync
,
1037 #ifdef ARROWLESS_KBD
1041 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1042 selectEntry(menu
, -1);
1043 move_menus(menu
, old_pos_x
, old_pos_y
);
1053 index
= check_key(menu
, &event
.xkey
);
1055 selectEntry(menu
, index
);
1061 if (event
.type
==ButtonPress
)
1064 WMHandleEvent(&event
);
1068 XUngrabKeyboard(dpy
, CurrentTime
);
1070 if (done
==2 && menu
->selected_entry
>=0) {
1071 entry
= menu
->entries
[menu
->selected_entry
];
1076 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1077 && entry
->cascade
< 0) {
1078 #if (MENU_BLINK_COUNT > 0)
1079 int sel
= menu
->selected_entry
;
1082 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1083 paintEntry(menu
, sel
, False
);
1085 wusleep(MENU_BLINK_DELAY
);
1086 paintEntry(menu
, sel
, True
);
1088 wusleep(MENU_BLINK_DELAY
);
1091 selectEntry(menu
, -1);
1093 if (!menu
->flags
.buttoned
) {
1095 move_menus(menu
, old_pos_x
, old_pos_y
);
1099 (*entry
->callback
)(menu
, entry
);
1101 if (!menu
->flags
.buttoned
) {
1103 move_menus(menu
, old_pos_x
, old_pos_y
);
1105 selectEntry(menu
, -1);
1109 /* returns True if returning from a submenu to a parent menu,
1110 * False if exiting from menu */
1116 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1118 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1119 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1121 if (!menu
->flags
.realized
) {
1122 menu
->flags
.realized
=1;
1125 if (!menu
->flags
.mapped
) {
1126 if (wPreferences
.wrap_menus
) {
1129 if (x
+MENUW(menu
) > scr_width
)
1130 x
= scr_width
- MENUW(menu
);
1131 if (y
+MENUH(menu
) > scr_height
)
1132 y
= scr_height
- MENUH(menu
);
1135 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1138 XMapWindow(dpy
, menu
->frame
->core
->window
);
1139 wRaiseFrame(menu
->frame
->core
);
1140 menu
->flags
.mapped
= 1;
1142 selectEntry(menu
, 0);
1151 wMenuMap(WMenu
*menu
)
1153 if (!menu
->flags
.realized
) {
1154 menu
->flags
.realized
=1;
1157 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1158 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1159 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1160 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1162 XMapWindow(dpy
, menu
->frame
->core
->window
);
1163 wRaiseFrame(menu
->frame
->core
);
1164 menu
->flags
.mapped
= 1;
1169 wMenuUnmap(WMenu
*menu
)
1173 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1174 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1175 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1177 menu
->flags
.buttoned
= 0;
1178 menu
->flags
.mapped
= 0;
1179 menu
->flags
.open_to_left
= 0;
1181 for (i
=0; i
<menu
->cascade_no
; i
++) {
1182 if (menu
->cascades
[i
]!=NULL
1183 && menu
->cascades
[i
]->flags
.mapped
1184 && !menu
->cascades
[i
]->flags
.buttoned
) {
1186 wMenuUnmap(menu
->cascades
[i
]);
1189 menu
->selected_entry
= -1;
1195 wMenuPaint(WMenu
*menu
)
1199 if (!menu
->flags
.mapped
) {
1204 for (i
=0; i
<menu
->entry_no
; i
++) {
1205 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1211 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1213 if (index
>=menu
->entry_no
) return;
1214 menu
->entries
[index
]->flags
.enabled
=enable
;
1215 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1216 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1220 /* ====================================================================== */
1224 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1228 WObjDescriptor
*desc
;
1234 menu
->flags
.editing
= 1;
1236 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1237 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1239 wTextPutText(text
, entry
->text
);
1240 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1241 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1243 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1244 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1245 wwarning("could not grab keyboard");
1248 wSetFocusTo(menu
->frame
->screen_ptr
,
1249 menu
->frame
->screen_ptr
->focused_window
);
1254 while (!done
&& !text
->done
) {
1256 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1258 WMNextEvent(dpy
, &event
);
1260 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1261 (XPointer
*)&desc
)==XCNOENT
)
1264 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1266 (*desc
->handle_anything
)(desc
, &event
);
1269 switch (event
.type
) {
1271 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1275 WMHandleEvent(&event
);
1281 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1283 wSetFocusTo(menu
->frame
->screen_ptr
,
1284 menu
->frame
->screen_ptr
->focused_window
);
1287 t
= wTextGetText(text
);
1288 /* if !t, the user has canceled editing */
1292 entry
->text
= wstrdup(t
);
1294 menu
->flags
.realized
= 0;
1298 XUngrabKeyboard(dpy
, CurrentTime
);
1300 if (t
&& menu
->on_edit
)
1301 (*menu
->on_edit
)(menu
, entry
);
1303 menu
->flags
.editing
= 0;
1305 if (!menu
->flags
.realized
)
1311 selectEntry(WMenu
*menu
, int entry_no
)
1317 if (menu
->entries
==NULL
)
1320 if (entry_no
>= menu
->entry_no
)
1323 old_entry
= menu
->selected_entry
;
1324 menu
->selected_entry
= entry_no
;
1326 if (old_entry
!=entry_no
) {
1328 /* unselect previous entry */
1330 paintEntry(menu
, old_entry
, False
);
1331 entry
= menu
->entries
[old_entry
];
1334 if (entry
->cascade
>=0 && menu
->cascades
) {
1335 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1336 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1342 menu
->selected_entry
= -1;
1345 entry
= menu
->entries
[entry_no
];
1347 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1348 /* Callback for when the submenu is opened.
1350 submenu
= menu
->cascades
[entry
->cascade
];
1351 if (submenu
&& submenu
->flags
.brother
)
1352 submenu
= submenu
->brother
;
1354 if (entry
->callback
) {
1355 /* Only call the callback if the submenu is not yet mapped.
1357 if (menu
->flags
.brother
) {
1358 if (!submenu
|| !submenu
->flags
.mapped
)
1359 (*entry
->callback
)(menu
->brother
, entry
);
1361 if (!submenu
|| !submenu
->flags
.buttoned
)
1362 (*entry
->callback
)(menu
, entry
);
1366 /* the submenu menu might have changed */
1367 submenu
= menu
->cascades
[entry
->cascade
];
1370 if (!submenu
->flags
.mapped
) {
1373 if (!submenu
->flags
.realized
)
1374 wMenuRealize(submenu
);
1375 if (wPreferences
.wrap_menus
) {
1376 if (menu
->flags
.open_to_left
)
1377 submenu
->flags
.open_to_left
= 1;
1379 if (submenu
->flags
.open_to_left
) {
1380 x
= menu
->frame_x
- MENUW(submenu
);
1383 submenu
->flags
.open_to_left
= 0;
1386 x
= menu
->frame_x
+ MENUW(menu
);
1388 if (x
+ MENUW(submenu
)
1389 >= menu
->frame
->screen_ptr
->scr_width
) {
1391 x
= menu
->frame_x
- MENUW(submenu
);
1392 submenu
->flags
.open_to_left
= 1;
1396 x
= menu
->frame_x
+ MENUW(menu
);
1399 if (wPreferences
.align_menus
) {
1402 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1403 if (menu
->flags
.titled
)
1404 y
+= menu
->frame
->top_width
;
1405 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1406 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1409 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1410 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1415 paintEntry(menu
, entry_no
, True
);
1421 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1424 WObjDescriptor
*desc
;
1425 Window root_ret
, win
, junk_win
;
1429 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1432 if (win
==None
) return NULL
;
1434 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1437 if (desc
->parent_type
== WCLASS_MENU
) {
1438 menu
= (WMenu
*)desc
->parent
;
1439 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1440 x_ret
, y_ret
, &junk_win
);
1450 closeCascade(WMenu
*menu
)
1452 WMenu
*parent
=menu
->parent
;
1454 if (menu
->flags
.brother
1455 || (!menu
->flags
.buttoned
1456 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1458 selectEntry(menu
, -1);
1460 #if (MENU_BLINK_DELAY > 2)
1461 wusleep(MENU_BLINK_DELAY
/2);
1465 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1466 || parent
->flags
.brother
)
1467 && !parent
->flags
.buttoned
) {
1468 selectEntry(parent
, -1);
1470 parent
= parent
->parent
;
1473 selectEntry(parent
, -1);
1479 closeBrotherCascadesOf(WMenu
*menu
)
1484 for (i
=0; i
<menu
->cascade_no
; i
++) {
1485 if (menu
->cascades
[i
]->flags
.brother
) {
1486 tmp
= menu
->cascades
[i
];
1488 tmp
= menu
->cascades
[i
]->brother
;
1490 if (tmp
->flags
.mapped
) {
1491 selectEntry(tmp
->parent
, -1);
1492 closeBrotherCascadesOf(tmp
);
1499 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1503 parentMenu(WMenu
*menu
)
1508 if (menu
->flags
.buttoned
)
1511 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1512 parent
= menu
->parent
;
1513 if (parent
->selected_entry
< 0)
1515 entry
= parent
->entries
[parent
->selected_entry
];
1516 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1517 parent
->cascades
[entry
->cascade
] != menu
)
1520 if (menu
->flags
.buttoned
)
1530 * Will raise the passed menu, if submenu = 0
1531 * If submenu > 0 will also raise all mapped submenus
1532 * until the first buttoned one
1533 * If submenu < 0 will also raise all mapped parent menus
1534 * until the first buttoned one
1538 raiseMenus(WMenu
*menu
, int submenus
)
1545 wRaiseFrame(menu
->frame
->core
);
1547 if (submenus
>0 && menu
->selected_entry
>=0) {
1548 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1549 if (i
>=0 && menu
->cascades
) {
1550 submenu
= menu
->cascades
[i
];
1551 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1552 raiseMenus(submenu
, submenus
);
1555 if (submenus
<0 && !menu
->flags
.buttoned
&&
1556 menu
->parent
&& menu
->parent
->flags
.mapped
)
1557 raiseMenus(menu
->parent
, submenus
);
1562 wMenuUnderPointer(WScreen
*screen
)
1564 WObjDescriptor
*desc
;
1565 Window root_ret
, win
;
1569 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1570 &dummy
, &dummy
, &mask
);
1572 if (win
==None
) return NULL
;
1574 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1577 if (desc
->parent_type
== WCLASS_MENU
)
1578 return (WMenu
*)desc
->parent
;
1584 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
1588 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1590 Window root_ret
, win
;
1594 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1599 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1601 WScreen
*scr
= menu
->menu
->screen_ptr
;
1602 int menuX1
= menu
->frame_x
;
1603 int menuY1
= menu
->frame_y
;
1604 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1605 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1606 int screenW
= scr
->scr_width
;
1607 int screenH
= scr
->scr_height
;
1613 getPointerPosition(scr
, &xroot
, &yroot
);
1615 #ifdef VIRTUAL_DESKTOP
1616 if (wPreferences
.vedge_thickness
) {
1617 if (xroot
<= wPreferences
.vedge_thickness
+ 1 && menuX1
< wPreferences
.vedge_thickness
) {
1618 /* scroll to the right */
1619 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX1
));
1621 } else if (xroot
>= screenW
-2-wPreferences
.vedge_thickness
&& menuX2
> screenW
-1-wPreferences
.vedge_thickness
) {
1622 /* scroll to the left */
1623 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1628 *hamount
= -*hamount
;
1633 if (xroot
<= 1 && menuX1
< 0) {
1634 /* scroll to the right */
1635 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX1
));
1637 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1638 /* scroll to the left */
1639 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1644 *hamount
= -*hamount
;
1647 if (yroot
<= 1 && menuY1
< 0) {
1649 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY1
));
1651 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1653 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1655 *vamount
= -*vamount
;
1661 dragScrollMenuCallback(void *data
)
1663 WMenu
*menu
= (WMenu
*)data
;
1664 WScreen
*scr
= menu
->menu
->screen_ptr
;
1665 WMenu
*parent
= parentMenu(menu
);
1666 int hamount
, vamount
;
1668 int newSelectedEntry
;
1670 getScrollAmount(menu
, &hamount
, &vamount
);
1673 if (hamount
!= 0 || vamount
!= 0) {
1674 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1675 parent
->frame_y
+ vamount
, True
);
1676 if (findMenu(scr
, &x
, &y
)) {
1677 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1678 selectEntry(menu
, newSelectedEntry
);
1680 /* Pointer fell outside of menu. If the selected entry is
1681 * not a submenu, unselect it */
1682 if (menu
->selected_entry
>= 0
1683 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1684 selectEntry(menu
, -1);
1685 newSelectedEntry
= 0;
1688 /* paranoid check */
1689 if (newSelectedEntry
>= 0) {
1690 /* keep scrolling */
1691 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1692 dragScrollMenuCallback
, menu
);
1697 /* don't need to scroll anymore */
1699 if (findMenu(scr
, &x
, &y
)) {
1700 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1701 selectEntry(menu
, newSelectedEntry
);
1708 scrollMenuCallback(void *data
)
1710 WMenu
*menu
= (WMenu
*)data
;
1711 WMenu
*parent
= parentMenu(menu
);
1712 int hamount
= 0; /* amount to scroll */
1715 getScrollAmount(menu
, &hamount
, &vamount
);
1717 if (hamount
!= 0 || vamount
!= 0) {
1718 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1719 parent
->frame_y
+ vamount
, True
);
1721 /* keep scrolling */
1722 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1723 scrollMenuCallback
, menu
);
1725 /* don't need to scroll anymore */
1732 #define MENU_SCROLL_BORDER 5
1735 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1737 int menuX1
= menu
->frame_x
;
1738 int menuY1
= menu
->frame_y
;
1739 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1740 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1741 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1742 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1745 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1746 || y
> scrYe
-MENU_SCROLL_BORDER
))
1748 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1749 || x
> scrXe
-MENU_SCROLL_BORDER
))
1756 typedef struct _delay
{
1764 _leaving(_delay
*dl
)
1766 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1767 dl
->menu
->jump_back
=NULL
;
1768 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1774 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1777 WMenu
*omenu
= parentMenu(menu
);
1778 WScreen
*scr
= menu
->frame
->screen_ptr
;
1781 int old_frame_x
= omenu
->frame_x
;
1782 int old_frame_y
= omenu
->frame_y
;
1785 if (omenu
->jump_back
)
1786 WMDeleteTimerWithClientData(omenu
->jump_back
);
1789 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1790 || omenu
->flags
.app_menu
) {
1794 if (!wPreferences
.wrap_menus
)
1795 raiseMenus(omenu
, True
);
1797 raiseMenus(menu
, False
);
1800 scrollMenuCallback(menu
);
1803 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1805 WMNextEvent(dpy
, &ev
);
1810 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1811 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1813 /* on_border is != 0 if the pointer is between the menu
1814 * and the screen border and is close enough to the border */
1815 on_border
= isPointNearBoder(menu
, x
, y
);
1817 smenu
= wMenuUnderPointer(scr
);
1819 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1824 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1825 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1826 on_border
= on_x_edge
|| on_y_edge
;
1828 if (!on_border
&& !jump_back
) {
1833 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1834 WMDeleteTimerHandler(menu
->timer
);
1842 scrollMenuCallback(menu
);
1845 /* True if we push on title, or drag the omenu to other position */
1846 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1847 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1848 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1849 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1851 smenu
= wMenuUnderPointer(scr
);
1852 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1854 else if (smenu
==omenu
&& on_title
) {
1868 WMDeleteTimerHandler(menu
->timer
);
1874 if (!omenu
->jump_back
) {
1875 delayer
=wmalloc(sizeof(_delay
));
1876 delayer
->menu
=omenu
;
1877 delayer
->ox
=old_frame_x
;
1878 delayer
->oy
=old_frame_y
;
1879 omenu
->jump_back
=delayer
;
1880 scr
->flags
.jump_back_pending
= 1;
1882 else delayer
= omenu
->jump_back
;
1883 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1890 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1892 wMenuPaint(desc
->parent
);
1896 int *delayed_select
;
1903 delaySelection(void *data
)
1905 delay_data
*d
= (delay_data
*)data
;
1911 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1912 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1913 entry_no
= getEntryAt(menu
, x
, y
);
1914 selectEntry(menu
, entry_no
);
1916 if (d
->delayed_select
)
1917 *(d
->delayed_select
) = 0;
1922 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1924 XButtonEvent
*bev
= &event
->xbutton
;
1925 WMenu
*menu
= desc
->parent
;
1927 WScreen
*scr
=menu
->frame
->screen_ptr
;
1928 WMenuEntry
*entry
=NULL
;
1930 int close_on_exit
=0;
1932 int delayed_select
= 0;
1936 int old_frame_x
= 0;
1937 int old_frame_y
= 0;
1938 delay_data d_data
= {NULL
, NULL
, NULL
};
1940 if (!wPreferences
.wrap_menus
) {
1941 smenu
= parentMenu(menu
);
1942 old_frame_x
= smenu
->frame_x
;
1943 old_frame_y
= smenu
->frame_y
;
1944 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1945 /* This is true if the menu was launched with right click on root window */
1947 d_data
.delayed_select
= &delayed_select
;
1949 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1950 delaySelection
, &d_data
);
1953 wRaiseFrame(menu
->frame
->core
);
1955 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1957 smenu
= findMenu(scr
, &x
, &y
);
1965 if (menu
->flags
.editing
) {
1968 entry_no
= getEntryAt(menu
, x
, y
);
1970 entry
= menu
->entries
[entry_no
];
1972 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1973 && entry
->flags
.editable
) {
1974 editEntry(smenu
, entry
);
1976 } else if (bev
->state
& ControlMask
) {
1980 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1981 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1983 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1984 menu
->selected_entry
!=entry_no
) {
1985 wMenuUnmap(submenu
);
1987 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1988 selectEntry(menu
, entry_no
);
1989 } else if (!submenu
->flags
.buttoned
) {
1990 selectEntry(menu
, -1);
1993 } else if (!delayed_select
) {
1994 selectEntry(menu
, entry_no
);
1997 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
1999 dragScrollMenuCallback(menu
);
2003 prevx
= bev
->x_root
;
2004 prevy
= bev
->y_root
;
2008 XAllowEvents(dpy
, SyncPointer
, CurrentTime
);
2010 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2011 |ButtonPressMask
, &ev
);
2014 smenu
= findMenu(scr
, &x
, &y
);
2016 if (smenu
== NULL
) {
2017 /* moved mouse out of menu */
2019 if (!delayed_select
&& d_data
.magic
) {
2020 WMDeleteTimerHandler(d_data
.magic
);
2021 d_data
.magic
= NULL
;
2024 || (menu
->selected_entry
>=0
2025 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2026 prevx
= ev
.xmotion
.x_root
;
2027 prevy
= ev
.xmotion
.y_root
;
2031 selectEntry(menu
, -1);
2033 prevx
= ev
.xmotion
.x_root
;
2034 prevy
= ev
.xmotion
.y_root
;
2036 } else if (menu
&& menu
!=smenu
2037 && (menu
->selected_entry
<0
2038 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2039 selectEntry(menu
, -1);
2041 if (!delayed_select
&& d_data
.magic
) {
2042 WMDeleteTimerHandler(d_data
.magic
);
2043 d_data
.magic
= NULL
;
2047 /* hysteresis for item selection */
2049 /* check if the motion was to the side, indicating that
2050 * the user may want to cross to a submenu */
2051 if (!delayed_select
&& menu
) {
2053 Bool moved_to_submenu
;/* moved to direction of submenu */
2055 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2057 moved_to_submenu
= False
;
2058 if (dx
> 0 /* if moved enough to the side */
2059 /* maybe a open submenu */
2060 && menu
->selected_entry
>=0
2061 /* moving to the right direction */
2062 && (wPreferences
.align_menus
2063 || ev
.xmotion
.y_root
>= prevy
)) {
2066 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2068 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2069 if (prevx
< ev
.xmotion
.x_root
)
2070 moved_to_submenu
= True
;
2072 if (prevx
> ev
.xmotion
.x_root
)
2073 moved_to_submenu
= True
;
2079 if (menu
!= smenu
) {
2081 WMDeleteTimerHandler(d_data
.magic
);
2083 d_data
.magic
= NULL
;
2084 } else if (moved_to_submenu
) {
2085 /* while we are moving, postpone the selection */
2087 WMDeleteTimerHandler(d_data
.magic
);
2089 d_data
.delayed_select
= NULL
;
2091 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2094 prevx
= ev
.xmotion
.x_root
;
2095 prevy
= ev
.xmotion
.y_root
;
2099 WMDeleteTimerHandler(d_data
.magic
);
2100 d_data
.magic
= NULL
;
2104 prevx
= ev
.xmotion
.x_root
;
2105 prevy
= ev
.xmotion
.y_root
;
2107 /* pointer crossed menus */
2108 if (menu
&& menu
->timer
) {
2109 WMDeleteTimerHandler(menu
->timer
);
2113 dragScrollMenuCallback(smenu
);
2117 dragScrollMenuCallback(menu
);
2119 if (!delayed_select
) {
2120 entry_no
= getEntryAt(menu
, x
, y
);
2122 entry
= menu
->entries
[entry_no
];
2123 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2125 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2126 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2127 && menu
->selected_entry
!=entry_no
) {
2128 wMenuUnmap(submenu
);
2132 selectEntry(menu
, entry_no
);
2140 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2150 if (menu
&& menu
->timer
) {
2151 WMDeleteTimerHandler(menu
->timer
);
2154 if (d_data
.magic
!=NULL
)
2155 WMDeleteTimerHandler(d_data
.magic
);
2157 if (menu
&& menu
->selected_entry
>=0) {
2158 entry
= menu
->entries
[menu
->selected_entry
];
2159 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2160 && entry
->cascade
< 0) {
2161 /* blink and erase menu selection */
2162 #if (MENU_BLINK_DELAY > 0)
2163 int sel
= menu
->selected_entry
;
2166 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2167 paintEntry(menu
, sel
, False
);
2169 wusleep(MENU_BLINK_DELAY
);
2170 paintEntry(menu
, sel
, True
);
2172 wusleep(MENU_BLINK_DELAY
);
2175 /* unmap the menu, it's parents and call the callback */
2176 if (!menu
->flags
.buttoned
&&
2177 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2180 selectEntry(menu
, -1);
2182 (*entry
->callback
)(menu
, entry
);
2184 /* If the user double clicks an entry, the entry will
2185 * be executed twice, which is not good for things like
2186 * the root menu. So, ignore any clicks that were generated
2187 * while the entry was being executed */
2188 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2190 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2191 selectEntry(menu
, -1);
2193 if (entry
->cascade
>=0 && menu
->cascades
2194 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2195 selectEntry(menu
, -1);
2200 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2201 closeCascade(desc
->parent
);
2203 /* close the cascade windows that should not remain opened */
2204 closeBrotherCascadesOf(desc
->parent
);
2206 if (!wPreferences
.wrap_menus
)
2207 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2212 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2221 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2223 if (submenus
>0 && menu
->selected_entry
>=0) {
2224 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2226 if (i
>=0 && menu
->cascades
) {
2227 submenu
= menu
->cascades
[i
];
2228 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2229 if (wPreferences
.align_menus
) {
2230 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2232 wMenuMove(submenu
, x
+ MENUW(menu
),
2233 y
+ submenu
->entry_height
*menu
->selected_entry
,
2239 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2240 !menu
->parent
->flags
.buttoned
) {
2241 if (wPreferences
.align_menus
) {
2242 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2244 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2245 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2253 changeMenuLevels(WMenu
*menu
, int lower
)
2258 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2260 wRaiseFrame(menu
->frame
->core
);
2261 menu
->flags
.lowered
= 0;
2263 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2264 wLowerFrame(menu
->frame
->core
);
2265 menu
->flags
.lowered
= 1;
2267 for (i
=0; i
<menu
->cascade_no
; i
++) {
2268 if (menu
->cascades
[i
]
2269 && !menu
->cascades
[i
]->flags
.buttoned
2270 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2271 changeMenuLevels(menu
->cascades
[i
], lower
);
2279 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2284 if (event
->xbutton
.state
& MOD_MASK
) {
2285 if (menu
->flags
.lowered
) {
2290 changeMenuLevels(menu
, lower
);
2296 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2301 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2302 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2306 /* can't touch the menu copy */
2307 if (menu
->flags
.brother
)
2310 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2313 if (event
->xbutton
.state
& MOD_MASK
) {
2314 wLowerFrame(menu
->frame
->core
);
2317 wRaiseFrame(menu
->frame
->core
);
2322 /* lower/raise all submenus */
2324 if (tmp
->selected_entry
>=0 && tmp
->cascades
2325 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2326 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2327 if (!tmp
|| !tmp
->flags
.mapped
)
2330 wLowerFrame(tmp
->frame
->core
);
2332 wRaiseFrame(tmp
->frame
->core
);
2338 /* tear off the menu if it's a root menu or a cascade
2340 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2341 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2342 menu
->flags
.buttoned
=1;
2343 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2345 /* turn off selected menu entry in parent menu */
2346 selectEntry(menu
->parent
, -1);
2348 /* make parent map the copy in place of the original */
2349 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2350 if (menu
->parent
->cascades
[i
] == menu
) {
2351 menu
->parent
->cascades
[i
] = menu
->brother
;
2360 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2361 |ExposureMask
, &ev
);
2365 x
+= ev
.xmotion
.x_root
- dx
;
2366 y
+= ev
.xmotion
.y_root
- dy
;
2367 dx
= ev
.xmotion
.x_root
;
2368 dy
= ev
.xmotion
.y_root
;
2369 wMenuMove(menu
, x
, y
, True
);
2371 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2372 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2374 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2375 ButtonMotionMask
|ButtonReleaseMask
2377 GrabModeAsync
, GrabModeAsync
, None
,
2378 wCursor
[WCUR_MOVE
], CurrentTime
);
2387 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2389 XUngrabPointer(dpy
, CurrentTime
);
2400 *----------------------------------------------------------------------
2402 * Handles mouse click on the close button of menus. The menu is
2403 * closed when the button is clicked.
2406 * The closed menu is reinserted at it's parent menus
2408 *----------------------------------------------------------------------
2411 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2413 WMenu
*menu
= (WMenu
*)data
;
2414 WMenu
*parent
= menu
->parent
;
2418 for (i
=0; i
<parent
->cascade_no
; i
++) {
2419 /* find the entry that points to the copy */
2420 if (parent
->cascades
[i
] == menu
->brother
) {
2421 /* make it point to the original */
2422 parent
->cascades
[i
] = menu
;
2423 menu
->parent
= parent
;
2433 wMenuSaveState(WScreen
*scr
)
2435 proplist_t menus
, key
, value
;
2440 menus
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
2443 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2444 sprintf(buffer
, "%i,%i", scr
->switch_menu
->frame_x
,
2445 scr
->switch_menu
->frame_y
);
2446 key
= PLMakeString("SwitchMenu");
2447 value
= PLMakeString(buffer
);
2448 PLInsertDictionaryEntry(menus
, key
, value
);
2454 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2458 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2459 sprintf(buffer
, "%i,%i", scr
->workspace_menu
->frame_x
,
2460 scr
->workspace_menu
->frame_y
);
2461 key
= PLMakeString("WorkspaceMenu");
2462 value
= PLMakeString(buffer
);
2463 PLInsertDictionaryEntry(menus
, key
, value
);
2470 key
= PLMakeString("Menus");
2471 PLInsertDictionaryEntry(scr
->session_state
, key
, menus
);
2481 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2486 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2489 len
= strlen(menu
->frame
->title
);
2494 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2499 strcat(buffer
, "\\");
2500 strcat(buffer
, menu
->frame
->title
);
2506 saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
)
2508 proplist_t key
, value
;
2509 int save_menus
= 0, i
;
2514 if (menu
->flags
.brother
)
2515 menu
= menu
->brother
;
2517 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2519 sprintf(buffer
, "%i,%i", menu
->frame_x
, menu
->frame_y
);
2520 value
= PLMakeString(buffer
);
2523 ok
= getMenuPath(menu
, buffer
, 510);
2526 key
= PLMakeString(buffer
);
2527 PLInsertDictionaryEntry(menus
, key
, value
);
2535 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2536 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2545 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2549 restoreMenu(WScreen
*scr
, proplist_t menu
, int which
)
2552 WMenu
*pmenu
= NULL
;
2557 if (!PLIsString(menu
)) {
2558 COMPLAIN("Position");
2562 if (sscanf(PLGetString(menu
), "%i,%i", &x
, &y
)!=2)
2563 COMPLAIN("Position");
2566 if (which
& WSS_SWITCHMENU
) {
2567 OpenSwitchMenu(scr
, x
, y
, False
);
2568 pmenu
= scr
->switch_menu
;
2573 int width
= MENUW(pmenu
);
2574 int height
= MENUH(pmenu
);
2576 x
= (x
< -width
) ? 0 : x
;
2577 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2578 y
= (y
< 0) ? 0 : y
;
2579 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2580 wMenuMove(pmenu
, x
, y
, True
);
2581 pmenu
->flags
.buttoned
= 1;
2582 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2591 restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
)
2593 proplist_t key
, entry
;
2597 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2600 sprintf(buffer
, "%s\\%s", path
, menu
->frame
->title
);
2601 key
= PLMakeString(buffer
);
2602 entry
= PLGetDictionaryEntry(menus
, key
);
2605 if (entry
&& PLIsString(entry
)) {
2607 if (sscanf(PLGetString(entry
), "%i,%i", &x
, &y
) != 2)
2608 COMPLAIN("Position");
2610 if (!menu
->flags
.mapped
) {
2611 int width
= MENUW(menu
);
2612 int height
= MENUH(menu
);
2614 wMenuMapAt(menu
, x
, y
, False
);
2617 /* make parent map the copy in place of the original */
2618 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2619 if (menu
->parent
->cascades
[i
] == menu
) {
2620 menu
->parent
->cascades
[i
] = menu
->brother
;
2625 x
= (x
< -width
) ? 0 : x
;
2626 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2627 y
= (y
< 0) ? 0 : y
;
2628 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2629 wMenuMove(menu
, x
, y
, True
);
2630 menu
->flags
.buttoned
= 1;
2631 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2638 for (i
=0; i
<menu
->cascade_no
; i
++) {
2639 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2649 wMenuRestoreState(WScreen
*scr
)
2651 proplist_t menus
, menu
, key
, skey
;
2653 key
= PLMakeString("Menus");
2654 menus
= PLGetDictionaryEntry(scr
->session_state
, key
);
2662 skey
= PLMakeString("SwitchMenu");
2663 menu
= PLGetDictionaryEntry(menus
, skey
);
2664 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2667 if (!scr
->root_menu
) {
2668 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2669 wMenuUnmap(scr
->root_menu
);
2671 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2679 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2681 WMenu
*menu
, *parent
;
2685 if (!scr
->root_menu
) {
2686 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2687 wMenuUnmap(scr
->root_menu
);
2690 menu
= scr
->workspace_menu
;
2692 if (menu
->flags
.mapped
) {
2693 if (!menu
->flags
.buttoned
) {
2695 parent
= menu
->parent
;
2696 if (parent
&& parent
->selected_entry
>= 0) {
2697 entry
= parent
->entries
[parent
->selected_entry
];
2698 if (parent
->cascades
[entry
->cascade
] == menu
) {
2699 selectEntry(parent
, -1);
2700 wMenuMapAt(menu
, x
, y
, False
);
2704 wRaiseFrame(menu
->frame
->core
);
2705 wMenuMapCopyAt(menu
, x
, y
);
2708 wMenuMapAt(menu
, x
, y
, False
);