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>
35 #include "WindowMaker.h"
45 /****** Global Variables ******/
47 extern Cursor wCursor
[WCUR_LAST
];
49 extern XContext wWinContext
;
51 extern WPreferences wPreferences
;
53 #define MOD_MASK wPreferences.modifier_mask
55 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
56 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
60 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
61 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
64 /***** Local Stuff ******/
69 } menuScrollParameters
[5] = {
70 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
71 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
72 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
73 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
74 {MENU_SCROLL_STEPS_U
, MENU_SCROLL_DELAY_U
}};
77 static void menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
78 static void menuExpose(WObjDescriptor
*desc
, XEvent
*event
);
80 static void menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
81 static void menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
83 static void menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
85 static void updateTexture(WMenu
*menu
);
88 static int saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
);
89 static int restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
);
92 static void selectEntry(WMenu
*menu
, int entry_no
);
93 static void closeCascade(WMenu
*menu
);
96 /****** Notification Observers ******/
99 appearanceObserver(void *self
, WMNotification
*notif
)
101 WMenu
*menu
= (WMenu
*)self
;
102 int flags
= (int)WMGetNotificationClientData(notif
);
104 if (!menu
->flags
.realized
)
107 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
108 if (flags
& WFontSettings
) {
109 menu
->flags
.realized
= 0;
112 if (flags
& WTextureSettings
) {
113 if (!menu
->flags
.brother
)
116 if (flags
& (WTextureSettings
|WColorSettings
)) {
119 } else if (menu
->flags
.titled
) {
121 if (flags
& WFontSettings
) {
122 menu
->flags
.realized
= 0;
125 if (flags
& WTextureSettings
) {
126 menu
->frame
->flags
.need_texture_remake
= 1;
128 if (flags
& (WColorSettings
|WTextureSettings
)) {
129 wFrameWindowPaint(menu
->frame
);
134 /************************************/
138 *----------------------------------------------------------------------
140 * Creates a new empty menu with the specified title. If main_menu
141 * is True, the created menu will be a main menu, which has some special
142 * properties such as being placed over other normal menus.
143 * If title is NULL, the menu will have no titlebar.
147 *----------------------------------------------------------------------
150 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
153 static int brother
=0;
156 menu
= wmalloc(sizeof(WMenu
));
158 memset(menu
, 0, sizeof(WMenu
));
160 #ifdef SINGLE_MENULEVEL
161 tmp
= WMSubmenuLevel
;
163 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
166 flags
= WFF_SINGLE_STATE
;
168 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
169 menu
->flags
.titled
= 1;
172 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, flags
,
173 screen
->menu_title_texture
, NULL
,
174 screen
->menu_title_pixel
, &screen
->menu_title_gc
,
175 &screen
->menu_title_font
);
177 menu
->frame
->core
->descriptor
.parent
= menu
;
178 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
179 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
181 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
184 menu
->frame
->title
= wstrdup(title
);
187 menu
->frame
->flags
.justification
= WTJ_LEFT
;
189 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
192 menu
->alloced_entries
= 0;
193 menu
->selected_entry
= -1;
194 menu
->entries
= NULL
;
196 menu
->frame_x
= screen
->app_menu_x
;
197 menu
->frame_y
= screen
->app_menu_y
;
199 menu
->frame
->child
= menu
;
201 menu
->flags
.lowered
= 0;
205 /* setup object descriptors */
206 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
207 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
210 menu
->frame
->on_click_right
= menuCloseClick
;
213 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
214 menu
->frame
->core
->width
, 10);
216 menu
->menu
->descriptor
.parent
= menu
;
217 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
218 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
219 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
221 menu
->menu_texture_data
= None
;
223 XMapWindow(dpy
, menu
->menu
->window
);
229 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
231 menu
->brother
->flags
.brother
= 1;
232 menu
->brother
->brother
= menu
;
234 WMAddNotificationObserver(appearanceObserver
, menu
,
235 WNMenuAppearanceSettingsChanged
, menu
);
237 WMAddNotificationObserver(appearanceObserver
, menu
,
238 WNMenuTitleAppearanceSettingsChanged
, menu
);
248 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
252 menu
= wMenuCreate(screen
, title
, main_menu
);
255 menu
->flags
.app_menu
= 1;
256 menu
->brother
->flags
.app_menu
= 1;
264 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
268 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
269 menu
->entries
[i
]->order
++;
270 menu
->entries
[i
+1] = menu
->entries
[i
];
272 menu
->entries
[index
] = entry
;
277 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
278 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
285 printf("Passed NULL as menu parameter to wMenuAddCallback() \n");
290 assert(menu
->flags
.brother
==0);
291 menu
->flags
.realized
= 0;
292 menu
->brother
->flags
.realized
= 0;
294 /* reallocate array if it's too small */
295 if (menu
->entry_no
>= menu
->alloced_entries
) {
298 puts("doing wrealloc()");
300 tmp
= wrealloc(menu
->entries
,
301 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
303 wwarning(_("wrealloc() failed while trying to add menu item"));
308 menu
->alloced_entries
+= 5;
310 menu
->brother
->entries
= tmp
;
311 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
313 entry
= wmalloc(sizeof(WMenuEntry
));
314 memset(entry
, 0, sizeof(WMenuEntry
));
315 entry
->flags
.enabled
= 1;
316 entry
->text
= wstrdup(text
);
318 entry
->clientdata
= clientdata
;
319 entry
->callback
= callback
;
320 if (index
<0 || index
>=menu
->entry_no
) {
321 entry
->order
= menu
->entry_no
;
322 menu
->entries
[menu
->entry_no
] = entry
;
324 entry
->order
= index
;
325 insertEntry(menu
, entry
, index
);
329 menu
->brother
->entry_no
= menu
->entry_no
;
337 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
339 WMenu
*brother
= menu
->brother
;
342 assert(menu
->flags
.brother
==0);
344 if (entry
->cascade
>=0) {
345 menu
->flags
.realized
= 0;
346 brother
->flags
.realized
= 0;
349 cascade
->parent
= menu
;
351 cascade
->brother
->parent
= brother
;
354 for (i
=0; i
<menu
->cascade_no
; i
++) {
355 if (menu
->cascades
[i
]==NULL
) {
356 menu
->cascades
[i
] = cascade
;
357 brother
->cascades
[i
] = cascade
->brother
;
364 entry
->cascade
= menu
->cascade_no
;
366 menu
->cascades
= wrealloc(menu
->cascades
,
367 sizeof(WMenu
)*(menu
->cascade_no
+1));
368 menu
->cascades
[menu
->cascade_no
++] = cascade
;
371 brother
->cascades
= wrealloc(brother
->cascades
,
372 sizeof(WMenu
)*(brother
->cascade_no
+1));
373 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
377 if (menu
->flags
.lowered
) {
379 cascade
->flags
.lowered
= 1;
380 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
382 cascade
->brother
->flags
.lowered
= 1;
383 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
386 if (!menu
->flags
.realized
)
392 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
394 assert(menu
->flags
.brother
==0);
396 /* destroy cascade menu */
397 if (entry
->cascade
>=0 && menu
->cascades
398 && menu
->cascades
[entry
->cascade
]!=NULL
) {
400 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
402 menu
->cascades
[entry
->cascade
] = NULL
;
403 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
411 wMenuRemoveItem(WMenu
*menu
, int index
)
415 if (menu
->flags
.brother
) {
416 wMenuRemoveItem(menu
->brother
, index
);
420 if (index
>=menu
->entry_no
) return;
422 /* destroy cascade menu */
423 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
425 /* destroy unshared data */
427 if (menu
->entries
[index
]->text
)
428 free(menu
->entries
[index
]->text
);
430 if (menu
->entries
[index
]->rtext
)
431 free(menu
->entries
[index
]->rtext
);
433 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
434 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
436 free(menu
->entries
[index
]);
438 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
439 menu
->entries
[i
+1]->order
--;
440 menu
->entries
[i
]=menu
->entries
[i
+1];
443 menu
->brother
->entry_no
--;
448 renderTexture(WMenu
*menu
)
456 WScreen
*scr
= menu
->menu
->screen_ptr
;
457 WTexture
*texture
= scr
->menu_item_texture
;
459 if (wPreferences
.menu_style
== MS_NORMAL
) {
460 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
461 menu
->entry_height
, WREL_MENUENTRY
);
463 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
464 menu
->menu
->height
+1, WREL_MENUENTRY
);
467 wwarning(_("could not render texture: %s"),
468 RMessageForError(RErrorCode
));
473 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
475 light
.red
= light
.green
= light
.blue
= 80;
478 dark
.red
= dark
.green
= dark
.blue
= 0;
481 mid
.red
= mid
.green
= mid
.blue
= 40;
483 for (i
= 1; i
< menu
->entry_no
; i
++) {
484 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
485 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
487 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
488 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
490 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
491 menu
->menu
->width
-1, i
*menu
->entry_height
,
495 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
496 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
505 updateTexture(WMenu
*menu
)
507 WScreen
*scr
= menu
->menu
->screen_ptr
;
509 /* setup background texture */
510 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
511 if (!menu
->flags
.brother
) {
512 FREE_PIXMAP(menu
->menu_texture_data
);
514 menu
->menu_texture_data
= renderTexture(menu
);
516 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
517 menu
->menu_texture_data
);
518 XClearWindow(dpy
, menu
->menu
->window
);
520 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
521 menu
->menu_texture_data
);
522 XClearWindow(dpy
, menu
->brother
->menu
->window
);
525 XSetWindowBackground(dpy
, menu
->menu
->window
,
526 scr
->menu_item_texture
->any
.color
.pixel
);
527 XClearWindow(dpy
, menu
->menu
->window
);
533 wMenuRealize(WMenu
*menu
)
536 int width
, rwidth
, mrwidth
, mwidth
;
537 int theight
, twidth
, eheight
;
538 WScreen
*scr
= menu
->frame
->screen_ptr
;
539 static int brother_done
=0;
544 wMenuRealize(menu
->brother
);
548 flags
= WFF_SINGLE_STATE
;
549 if (menu
->flags
.titled
)
550 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
552 wFrameWindowUpdateBorders(menu
->frame
, flags
);
554 if (menu
->flags
.titled
) {
555 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
556 strlen(menu
->frame
->title
));
557 theight
= menu
->frame
->top_width
;
558 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
563 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6;
564 menu
->entry_height
= eheight
;
567 for (i
=0; i
<menu
->entry_no
; i
++) {
570 /* search widest text */
571 text
= menu
->entries
[i
]->text
;
572 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
574 if (menu
->entries
[i
]->flags
.indicator
) {
575 width
+= MENU_INDICATOR_SPACE
;
581 /* search widest text on right */
582 text
= menu
->entries
[i
]->rtext
;
584 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
586 else if (menu
->entries
[i
]->cascade
>=0)
591 if (rwidth
> mrwidth
)
600 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
602 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
603 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
608 menu
->flags
.realized
= 1;
610 if (menu
->flags
.mapped
)
612 if (menu
->brother
->flags
.mapped
)
613 wMenuPaint(menu
->brother
);
618 wMenuDestroy(WMenu
*menu
, int recurse
)
622 WMRemoveNotificationObserver(menu
);
624 /* remove any pending timers */
626 WMDeleteTimerHandler(menu
->timer
);
629 /* call destroy handler */
630 if (menu
->on_destroy
)
631 (*menu
->on_destroy
)(menu
);
633 /* Destroy items if this menu own them. If this is the "brother" menu,
634 * leave them alone as it is shared by them.
636 if (!menu
->flags
.brother
) {
637 for (i
=0; i
<menu
->entry_no
; i
++) {
639 free(menu
->entries
[i
]->text
);
641 if (menu
->entries
[i
]->rtext
)
642 free(menu
->entries
[i
]->rtext
);
645 if (menu
->entries
[i
]->instances
){
646 PLRelease(menu
->entries
[i
]->instances
);
648 #endif /* USER_MENU */
650 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
651 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
653 free(menu
->entries
[i
]);
657 for (i
=0; i
<menu
->cascade_no
; i
++) {
658 if (menu
->cascades
[i
]) {
659 if (menu
->cascades
[i
]->flags
.brother
)
660 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
662 wMenuDestroy(menu
->cascades
[i
], recurse
);
672 FREE_PIXMAP(menu
->menu_texture_data
);
675 free(menu
->cascades
);
677 wCoreDestroy(menu
->menu
);
678 wFrameWindowDestroy(menu
->frame
);
680 /* destroy copy of this menu */
681 if (!menu
->flags
.brother
&& menu
->brother
)
682 wMenuDestroy(menu
->brother
, False
);
694 drawFrame(WScreen
*scr
, Window win
, int y
, int w
, int h
, int type
)
700 segs
[i
].x1
= segs
[i
].x2
= w
-1;
702 segs
[i
].y2
= y
+ h
- 1;
704 if (type
!= F_TOP
&& type
!= F_NONE
) {
706 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
710 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
716 segs
[i
].y2
= y
+ h
- 1;
718 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
725 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
727 if (type
!= F_TOP
&& type
!= F_NONE
)
728 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
734 paintEntry(WMenu
*menu
, int index
, int selected
)
738 GC light
, dim
, dark
, textGC
;
739 WScreen
*scr
=menu
->frame
->screen_ptr
;
740 Window win
= menu
->menu
->window
;
741 WMenuEntry
*entry
=menu
->entries
[index
];
743 if (!menu
->flags
.realized
) return;
744 h
= menu
->entry_height
;
745 w
= menu
->menu
->width
;
748 light
= scr
->menu_item_auxtexture
->light_gc
;
749 dim
= scr
->menu_item_auxtexture
->dim_gc
;
750 dark
= scr
->menu_item_auxtexture
->dark_gc
;
752 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
755 else if (index
== menu
->entry_no
- 1)
763 /* paint background */
765 XSetForeground(dpy
, scr
->select_menu_gc
, scr
->select_pixel
);
766 XFillRectangle(dpy
, win
, scr
->select_menu_gc
, 1, y
+1, w
-2, h
-3);
767 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
768 drawFrame(scr
, win
, y
, w
, h
, type
);
770 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
771 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
773 drawFrame(scr
, win
, y
, w
, h
, type
);
775 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
780 textGC
= scr
->select_menu_gc
;
781 if (entry
->flags
.enabled
)
782 XSetForeground(dpy
, textGC
, scr
->select_text_pixel
);
784 XSetForeground(dpy
, textGC
, scr
->dtext_pixel
);
785 } else if (!entry
->flags
.enabled
) {
786 textGC
= scr
->disabled_menu_entry_gc
;
788 textGC
= scr
->menu_entry_gc
;
792 if (entry
->flags
.indicator
)
793 x
+= MENU_INDICATOR_SPACE
+ 2;
795 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
,
796 x
, 3 + y
, entry
->text
, strlen(entry
->text
));
798 if (entry
->cascade
>=0) {
799 /* draw the cascade indicator */
800 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
801 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
802 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
806 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
811 switch (entry
->flags
.indicator_type
) {
813 indicator
= scr
->menu_check_indicator
;
816 indicator
= scr
->menu_mini_indicator
;
819 indicator
= scr
->menu_hide_indicator
;
822 indicator
= scr
->menu_shade_indicator
;
826 indicator
= scr
->menu_radio_indicator
;
830 iw
= indicator
->width
;
831 ih
= indicator
->height
;
832 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
833 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
835 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
837 XSetForeground(dpy
, scr
->copy_gc
, scr
->mtext_pixel
);
838 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
840 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
841 iw, ih, 5, y+(h-ih)/2);
843 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
846 /* draw right text */
848 if (entry
->rtext
&& entry
->cascade
<0) {
849 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
850 strlen(entry
->rtext
));
852 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
, w
-6-tw
,
853 y
+ 3, entry
->rtext
, strlen(entry
->rtext
));
859 move_menus(WMenu
*menu
, int x
, int y
)
861 while (menu
->parent
) {
864 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
865 y
-= menu
->selected_entry
*menu
->entry_height
;
868 wMenuMove(menu
, x
, y
, True
);
872 makeVisible(WMenu
*menu
)
874 WScreen
*scr
= menu
->frame
->screen_ptr
;
875 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
877 if (menu
->entry_no
<0) return;
880 y1
= menu
->frame_y
+menu
->frame
->top_width
881 + menu
->selected_entry
*menu
->entry_height
;
882 x2
= x1
+ MENUW(menu
);
883 y2
= y1
+ menu
->entry_height
;
892 } else if (x2
>= scr
->scr_width
) {
893 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
900 } else if (y2
>= scr
->scr_height
) {
901 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
905 new_y
= new_y
- menu
->frame
->top_width
906 - menu
->selected_entry
*menu
->entry_height
;
907 move_menus(menu
, new_x
, new_y
);
912 check_key(WMenu
*menu
, XKeyEvent
*event
)
917 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
920 ch
= toupper(buffer
[0]);
922 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
925 for (i
=s
; i
<menu
->entry_no
; i
++) {
926 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
930 /* no match. Retry from start, if previous started from a selected entry */
940 keyboardMenu(WMenu
*menu
)
943 KeySym ksym
=NoSymbol
;
947 int old_pos_x
= menu
->frame_x
;
948 int old_pos_y
= menu
->frame_y
;
949 int new_x
= old_pos_x
, new_y
= old_pos_y
;
950 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
951 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
953 if (menu
->flags
.editing
)
957 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
958 GrabModeAsync
, CurrentTime
);
960 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
961 new_y
= scr_height
- menu
->frame
->top_width
;
963 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
964 new_x
= scr_width
-MENUW(menu
)-1;
966 move_menus(menu
, new_x
, new_y
);
968 while (!done
&& menu
->flags
.mapped
) {
969 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
970 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
971 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
972 |SubstructureNotifyMask
, &event
);
974 switch (event
.type
) {
976 ksym
= XLookupKeysym(&event
.xkey
, 0);
984 selectEntry(menu
, 0);
990 selectEntry(menu
, menu
->entry_no
-1);
999 if (menu
->selected_entry
<= 0)
1000 selectEntry(menu
, menu
->entry_no
-1);
1002 selectEntry(menu
, menu
->selected_entry
-1);
1007 #ifdef ARROWLESS_KBD
1011 if (menu
->selected_entry
<0)
1012 selectEntry(menu
, 0);
1013 else if (menu
->selected_entry
== menu
->entry_no
-1)
1014 selectEntry(menu
, 0);
1015 else if (menu
->selected_entry
< menu
->entry_no
-1)
1016 selectEntry(menu
, menu
->selected_entry
+1);
1021 #ifdef ARROWLESS_KBD
1025 if (menu
->selected_entry
>=0) {
1027 entry
= menu
->entries
[menu
->selected_entry
];
1029 if (entry
->cascade
>= 0 && menu
->cascades
1030 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1032 XUngrabKeyboard(dpy
, CurrentTime
);
1034 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1035 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1038 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1039 GrabModeAsync
, GrabModeAsync
,
1046 #ifdef ARROWLESS_KBD
1050 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1051 selectEntry(menu
, -1);
1052 move_menus(menu
, old_pos_x
, old_pos_y
);
1062 index
= check_key(menu
, &event
.xkey
);
1064 selectEntry(menu
, index
);
1070 if (event
.type
==ButtonPress
)
1073 WMHandleEvent(&event
);
1077 XUngrabKeyboard(dpy
, CurrentTime
);
1079 if (done
==2 && menu
->selected_entry
>=0) {
1080 entry
= menu
->entries
[menu
->selected_entry
];
1085 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1086 && entry
->cascade
< 0) {
1087 #if (MENU_BLINK_COUNT > 0)
1088 int sel
= menu
->selected_entry
;
1091 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1092 paintEntry(menu
, sel
, False
);
1094 wusleep(MENU_BLINK_DELAY
);
1095 paintEntry(menu
, sel
, True
);
1097 wusleep(MENU_BLINK_DELAY
);
1100 selectEntry(menu
, -1);
1102 if (!menu
->flags
.buttoned
) {
1104 move_menus(menu
, old_pos_x
, old_pos_y
);
1108 (*entry
->callback
)(menu
, entry
);
1110 if (!menu
->flags
.buttoned
) {
1112 move_menus(menu
, old_pos_x
, old_pos_y
);
1114 selectEntry(menu
, -1);
1118 /* returns True if returning from a submenu to a parent menu,
1119 * False if exiting from menu */
1125 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1127 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1128 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1130 if (!menu
->flags
.realized
) {
1131 menu
->flags
.realized
=1;
1134 if (!menu
->flags
.mapped
) {
1135 if (wPreferences
.wrap_menus
) {
1138 if (x
+MENUW(menu
) > scr_width
)
1139 x
= scr_width
- MENUW(menu
);
1140 if (y
+MENUH(menu
) > scr_height
)
1141 y
= scr_height
- MENUH(menu
);
1144 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1147 XMapWindow(dpy
, menu
->frame
->core
->window
);
1148 wRaiseFrame(menu
->frame
->core
);
1149 menu
->flags
.mapped
= 1;
1151 selectEntry(menu
, 0);
1160 wMenuMap(WMenu
*menu
)
1162 if (!menu
->flags
.realized
) {
1163 menu
->flags
.realized
=1;
1166 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1167 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1168 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1169 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1171 XMapWindow(dpy
, menu
->frame
->core
->window
);
1172 wRaiseFrame(menu
->frame
->core
);
1173 menu
->flags
.mapped
= 1;
1178 wMenuUnmap(WMenu
*menu
)
1182 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1183 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1184 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1186 menu
->flags
.buttoned
= 0;
1187 menu
->flags
.mapped
= 0;
1188 menu
->flags
.open_to_left
= 0;
1190 for (i
=0; i
<menu
->cascade_no
; i
++) {
1191 if (menu
->cascades
[i
]!=NULL
1192 && menu
->cascades
[i
]->flags
.mapped
1193 && !menu
->cascades
[i
]->flags
.buttoned
) {
1195 wMenuUnmap(menu
->cascades
[i
]);
1198 menu
->selected_entry
= -1;
1204 wMenuPaint(WMenu
*menu
)
1208 if (!menu
->flags
.mapped
) {
1213 for (i
=0; i
<menu
->entry_no
; i
++) {
1214 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1220 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1222 if (index
>=menu
->entry_no
) return;
1223 menu
->entries
[index
]->flags
.enabled
=enable
;
1224 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1225 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1229 /* ====================================================================== */
1233 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1237 WObjDescriptor
*desc
;
1243 menu
->flags
.editing
= 1;
1245 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1246 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1248 wTextPutText(text
, entry
->text
);
1249 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1250 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1252 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1253 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1254 wwarning("could not grab keyboard");
1257 wSetFocusTo(menu
->frame
->screen_ptr
,
1258 menu
->frame
->screen_ptr
->focused_window
);
1263 while (!done
&& !text
->done
) {
1265 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1267 WMNextEvent(dpy
, &event
);
1269 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1270 (XPointer
*)&desc
)==XCNOENT
)
1273 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1275 (*desc
->handle_anything
)(desc
, &event
);
1278 switch (event
.type
) {
1280 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1284 WMHandleEvent(&event
);
1290 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1292 wSetFocusTo(menu
->frame
->screen_ptr
,
1293 menu
->frame
->screen_ptr
->focused_window
);
1296 t
= wTextGetText(text
);
1297 /* if !t, the user has canceled editing */
1301 entry
->text
= wstrdup(t
);
1303 menu
->flags
.realized
= 0;
1307 XUngrabKeyboard(dpy
, CurrentTime
);
1309 if (t
&& menu
->on_edit
)
1310 (*menu
->on_edit
)(menu
, entry
);
1312 menu
->flags
.editing
= 0;
1314 if (!menu
->flags
.realized
)
1320 selectEntry(WMenu
*menu
, int entry_no
)
1326 if (menu
->entries
==NULL
)
1329 if (entry_no
>= menu
->entry_no
)
1332 old_entry
= menu
->selected_entry
;
1333 menu
->selected_entry
= entry_no
;
1335 if (old_entry
!=entry_no
) {
1337 /* unselect previous entry */
1339 paintEntry(menu
, old_entry
, False
);
1340 entry
= menu
->entries
[old_entry
];
1343 if (entry
->cascade
>=0 && menu
->cascades
) {
1344 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1345 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1351 menu
->selected_entry
= -1;
1354 entry
= menu
->entries
[entry_no
];
1356 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1357 /* Callback for when the submenu is opened.
1359 submenu
= menu
->cascades
[entry
->cascade
];
1360 if (submenu
&& submenu
->flags
.brother
)
1361 submenu
= submenu
->brother
;
1363 if (entry
->callback
) {
1364 /* Only call the callback if the submenu is not yet mapped.
1366 if (menu
->flags
.brother
) {
1367 if (!submenu
|| !submenu
->flags
.mapped
)
1368 (*entry
->callback
)(menu
->brother
, entry
);
1370 if (!submenu
|| !submenu
->flags
.buttoned
)
1371 (*entry
->callback
)(menu
, entry
);
1375 /* the submenu menu might have changed */
1376 submenu
= menu
->cascades
[entry
->cascade
];
1379 if (!submenu
->flags
.mapped
) {
1382 if (!submenu
->flags
.realized
)
1383 wMenuRealize(submenu
);
1384 if (wPreferences
.wrap_menus
) {
1385 if (menu
->flags
.open_to_left
)
1386 submenu
->flags
.open_to_left
= 1;
1388 if (submenu
->flags
.open_to_left
) {
1389 x
= menu
->frame_x
- MENUW(submenu
);
1392 submenu
->flags
.open_to_left
= 0;
1395 x
= menu
->frame_x
+ MENUW(menu
);
1397 if (x
+ MENUW(submenu
)
1398 >= menu
->frame
->screen_ptr
->scr_width
) {
1400 x
= menu
->frame_x
- MENUW(submenu
);
1401 submenu
->flags
.open_to_left
= 1;
1405 x
= menu
->frame_x
+ MENUW(menu
);
1408 if (wPreferences
.align_menus
) {
1411 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1412 if (menu
->flags
.titled
)
1413 y
+= menu
->frame
->top_width
;
1414 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1415 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1418 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1419 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1424 paintEntry(menu
, entry_no
, True
);
1430 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1433 WObjDescriptor
*desc
;
1434 Window root_ret
, win
, junk_win
;
1438 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1441 if (win
==None
) return NULL
;
1443 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1446 if (desc
->parent_type
== WCLASS_MENU
) {
1447 menu
= (WMenu
*)desc
->parent
;
1448 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1449 x_ret
, y_ret
, &junk_win
);
1459 closeCascade(WMenu
*menu
)
1461 WMenu
*parent
=menu
->parent
;
1463 if (menu
->flags
.brother
1464 || (!menu
->flags
.buttoned
1465 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1467 selectEntry(menu
, -1);
1469 #if (MENU_BLINK_DELAY > 2)
1470 wusleep(MENU_BLINK_DELAY
/2);
1474 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1475 || parent
->flags
.brother
)
1476 && !parent
->flags
.buttoned
) {
1477 selectEntry(parent
, -1);
1479 parent
= parent
->parent
;
1482 selectEntry(parent
, -1);
1488 closeBrotherCascadesOf(WMenu
*menu
)
1493 for (i
=0; i
<menu
->cascade_no
; i
++) {
1494 if (menu
->cascades
[i
]->flags
.brother
) {
1495 tmp
= menu
->cascades
[i
];
1497 tmp
= menu
->cascades
[i
]->brother
;
1499 if (tmp
->flags
.mapped
) {
1500 selectEntry(tmp
->parent
, -1);
1501 closeBrotherCascadesOf(tmp
);
1508 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1512 parentMenu(WMenu
*menu
)
1517 if (menu
->flags
.buttoned
)
1520 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1521 parent
= menu
->parent
;
1522 if (parent
->selected_entry
< 0)
1524 entry
= parent
->entries
[parent
->selected_entry
];
1525 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1526 parent
->cascades
[entry
->cascade
] != menu
)
1529 if (menu
->flags
.buttoned
)
1539 * Will raise the passed menu, if submenu = 0
1540 * If submenu > 0 will also raise all mapped submenus
1541 * until the first buttoned one
1542 * If submenu < 0 will also raise all mapped parent menus
1543 * until the first buttoned one
1547 raiseMenus(WMenu
*menu
, int submenus
)
1554 wRaiseFrame(menu
->frame
->core
);
1556 if (submenus
>0 && menu
->selected_entry
>=0) {
1557 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1558 if (i
>=0 && menu
->cascades
) {
1559 submenu
= menu
->cascades
[i
];
1560 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1561 raiseMenus(submenu
, submenus
);
1564 if (submenus
<0 && !menu
->flags
.buttoned
&&
1565 menu
->parent
&& menu
->parent
->flags
.mapped
)
1566 raiseMenus(menu
->parent
, submenus
);
1571 wMenuUnderPointer(WScreen
*screen
)
1573 WObjDescriptor
*desc
;
1574 Window root_ret
, win
;
1578 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1579 &dummy
, &dummy
, &mask
);
1581 if (win
==None
) return NULL
;
1583 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1586 if (desc
->parent_type
== WCLASS_MENU
)
1587 return (WMenu
*)desc
->parent
;
1593 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
1597 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1599 Window root_ret
, win
;
1603 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1608 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1610 WScreen
*scr
= menu
->menu
->screen_ptr
;
1611 int menuX1
= menu
->frame_x
;
1612 int menuY1
= menu
->frame_y
;
1613 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1614 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1615 int screenW
= scr
->scr_width
;
1616 int screenH
= scr
->scr_height
;
1622 getPointerPosition(scr
, &xroot
, &yroot
);
1625 if (xroot
<= 1 && menuX1
< 0) {
1626 /* scroll to the right */
1627 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX1
));
1629 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1630 /* scroll to the left */
1631 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1636 *hamount
= -*hamount
;
1639 if (yroot
<= 1 && menuY1
< 0) {
1641 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY1
));
1643 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1645 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1647 *vamount
= -*vamount
;
1653 dragScrollMenuCallback(void *data
)
1655 WMenu
*menu
= (WMenu
*)data
;
1656 WScreen
*scr
= menu
->menu
->screen_ptr
;
1657 WMenu
*parent
= parentMenu(menu
);
1658 int hamount
, vamount
;
1660 int newSelectedEntry
;
1662 getScrollAmount(menu
, &hamount
, &vamount
);
1665 if (hamount
!= 0 || vamount
!= 0) {
1666 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1667 parent
->frame_y
+ vamount
, True
);
1668 if (findMenu(scr
, &x
, &y
)) {
1669 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1670 selectEntry(menu
, newSelectedEntry
);
1672 /* Pointer fell outside of menu. If the selected entry is
1673 * not a submenu, unselect it */
1674 if (menu
->selected_entry
>= 0
1675 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1676 selectEntry(menu
, -1);
1677 newSelectedEntry
= 0;
1680 /* paranoid check */
1681 if (newSelectedEntry
>= 0) {
1682 /* keep scrolling */
1683 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1684 dragScrollMenuCallback
, menu
);
1689 /* don't need to scroll anymore */
1691 if (findMenu(scr
, &x
, &y
)) {
1692 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1693 selectEntry(menu
, newSelectedEntry
);
1700 scrollMenuCallback(void *data
)
1702 WMenu
*menu
= (WMenu
*)data
;
1703 WMenu
*parent
= parentMenu(menu
);
1704 int hamount
= 0; /* amount to scroll */
1707 getScrollAmount(menu
, &hamount
, &vamount
);
1709 if (hamount
!= 0 || vamount
!= 0) {
1710 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1711 parent
->frame_y
+ vamount
, True
);
1713 /* keep scrolling */
1714 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1715 scrollMenuCallback
, menu
);
1717 /* don't need to scroll anymore */
1724 #define MENU_SCROLL_BORDER 5
1727 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1729 int menuX1
= menu
->frame_x
;
1730 int menuY1
= menu
->frame_y
;
1731 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1732 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1733 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1734 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1737 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1738 || y
> scrYe
-MENU_SCROLL_BORDER
))
1740 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1741 || x
> scrXe
-MENU_SCROLL_BORDER
))
1748 typedef struct _delay
{
1756 _leaving(_delay
*dl
)
1758 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1759 dl
->menu
->jump_back
=NULL
;
1760 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1766 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1769 WMenu
*omenu
= parentMenu(menu
);
1770 WScreen
*scr
= menu
->frame
->screen_ptr
;
1773 int old_frame_x
= omenu
->frame_x
;
1774 int old_frame_y
= omenu
->frame_y
;
1778 puts("Entering menu Scroll");
1781 if (omenu
->jump_back
)
1782 WMDeleteTimerWithClientData(omenu
->jump_back
);
1785 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1786 || omenu
->flags
.app_menu
) {
1790 if (!wPreferences
.wrap_menus
)
1791 raiseMenus(omenu
, True
);
1793 raiseMenus(menu
, False
);
1796 scrollMenuCallback(menu
);
1799 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1801 WMNextEvent(dpy
, &ev
);
1806 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1807 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1809 /* on_border is != 0 if the pointer is between the menu
1810 * and the screen border and is close enough to the border */
1811 on_border
= isPointNearBoder(menu
, x
, y
);
1813 smenu
= wMenuUnderPointer(scr
);
1815 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1820 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1821 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1822 on_border
= on_x_edge
|| on_y_edge
;
1824 if (!on_border
&& !jump_back
) {
1829 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1830 WMDeleteTimerHandler(menu
->timer
);
1838 scrollMenuCallback(menu
);
1841 /* True if we push on title, or drag the omenu to other position */
1842 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1843 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1844 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1845 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1847 smenu
= wMenuUnderPointer(scr
);
1848 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1850 else if (smenu
==omenu
&& on_title
) {
1864 WMDeleteTimerHandler(menu
->timer
);
1870 if (!omenu
->jump_back
) {
1871 delayer
=wmalloc(sizeof(_delay
));
1872 delayer
->menu
=omenu
;
1873 delayer
->ox
=old_frame_x
;
1874 delayer
->oy
=old_frame_y
;
1875 omenu
->jump_back
=delayer
;
1876 scr
->flags
.jump_back_pending
= 1;
1878 else delayer
= omenu
->jump_back
;
1879 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1884 puts("Leaving menu Scroll");
1891 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1893 wMenuPaint(desc
->parent
);
1897 int *delayed_select
;
1904 delaySelection(void *data
)
1906 delay_data
*d
= (delay_data
*)data
;
1912 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1913 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1914 entry_no
= getEntryAt(menu
, x
, y
);
1915 selectEntry(menu
, entry_no
);
1917 if (d
->delayed_select
)
1918 *(d
->delayed_select
) = 0;
1923 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1925 XButtonEvent
*bev
= &event
->xbutton
;
1926 WMenu
*menu
= desc
->parent
;
1928 WScreen
*scr
=menu
->frame
->screen_ptr
;
1929 WMenuEntry
*entry
=NULL
;
1931 int close_on_exit
=0;
1933 int delayed_select
= 0;
1937 int old_frame_x
= 0;
1938 int old_frame_y
= 0;
1939 delay_data d_data
= {NULL
, NULL
, NULL
};
1941 if (!wPreferences
.wrap_menus
) {
1942 smenu
= parentMenu(menu
);
1943 old_frame_x
= smenu
->frame_x
;
1944 old_frame_y
= smenu
->frame_y
;
1945 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1946 /* This is true if the menu was launched with right click on root window */
1948 d_data
.delayed_select
= &delayed_select
;
1950 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1951 delaySelection
, &d_data
);
1954 wRaiseFrame(menu
->frame
->core
);
1956 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1958 smenu
= findMenu(scr
, &x
, &y
);
1966 if (menu
->flags
.editing
) {
1969 entry_no
= getEntryAt(menu
, x
, y
);
1971 entry
= menu
->entries
[entry_no
];
1973 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1974 && entry
->flags
.editable
) {
1975 editEntry(smenu
, entry
);
1977 } else if (bev
->state
& ControlMask
) {
1981 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1982 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1984 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1985 menu
->selected_entry
!=entry_no
) {
1986 wMenuUnmap(submenu
);
1988 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1989 selectEntry(menu
, entry_no
);
1990 } else if (!submenu
->flags
.buttoned
) {
1991 selectEntry(menu
, -1);
1994 } else if (!delayed_select
) {
1995 selectEntry(menu
, entry_no
);
1998 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2000 dragScrollMenuCallback(menu
);
2004 prevx
= bev
->x_root
;
2005 prevy
= bev
->y_root
;
2009 XAllowEvents(dpy
, SyncPointer
, CurrentTime
);
2011 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2012 |ButtonPressMask
, &ev
);
2015 smenu
= findMenu(scr
, &x
, &y
);
2017 if (smenu
== NULL
) {
2018 /* moved mouse out of menu */
2020 if (!delayed_select
&& d_data
.magic
) {
2021 WMDeleteTimerHandler(d_data
.magic
);
2022 d_data
.magic
= NULL
;
2025 || (menu
->selected_entry
>=0
2026 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2027 prevx
= ev
.xmotion
.x_root
;
2028 prevy
= ev
.xmotion
.y_root
;
2032 selectEntry(menu
, -1);
2034 prevx
= ev
.xmotion
.x_root
;
2035 prevy
= ev
.xmotion
.y_root
;
2037 } else if (menu
&& menu
!=smenu
2038 && (menu
->selected_entry
<0
2039 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2040 selectEntry(menu
, -1);
2042 if (!delayed_select
&& d_data
.magic
) {
2043 WMDeleteTimerHandler(d_data
.magic
);
2044 d_data
.magic
= NULL
;
2048 /* hysteresis for item selection */
2050 /* check if the motion was to the side, indicating that
2051 * the user may want to cross to a submenu */
2052 if (!delayed_select
&& menu
) {
2054 Bool moved_to_submenu
;/* moved to direction of submenu */
2056 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2058 moved_to_submenu
= False
;
2059 if (dx
> 0 /* if moved enough to the side */
2060 /* maybe a open submenu */
2061 && menu
->selected_entry
>=0
2062 /* moving to the right direction */
2063 && (wPreferences
.align_menus
2064 || ev
.xmotion
.y_root
>= prevy
)) {
2067 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2069 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2070 if (prevx
< ev
.xmotion
.x_root
)
2071 moved_to_submenu
= True
;
2073 if (prevx
> ev
.xmotion
.x_root
)
2074 moved_to_submenu
= True
;
2080 if (menu
!= smenu
) {
2082 WMDeleteTimerHandler(d_data
.magic
);
2084 d_data
.magic
= NULL
;
2085 } else if (moved_to_submenu
) {
2086 /* while we are moving, postpone the selection */
2088 WMDeleteTimerHandler(d_data
.magic
);
2090 d_data
.delayed_select
= NULL
;
2092 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2095 prevx
= ev
.xmotion
.x_root
;
2096 prevy
= ev
.xmotion
.y_root
;
2100 WMDeleteTimerHandler(d_data
.magic
);
2101 d_data
.magic
= NULL
;
2105 prevx
= ev
.xmotion
.x_root
;
2106 prevy
= ev
.xmotion
.y_root
;
2108 /* pointer crossed menus */
2109 if (menu
&& menu
->timer
) {
2110 WMDeleteTimerHandler(menu
->timer
);
2114 dragScrollMenuCallback(smenu
);
2118 dragScrollMenuCallback(menu
);
2120 if (!delayed_select
) {
2121 entry_no
= getEntryAt(menu
, x
, y
);
2123 entry
= menu
->entries
[entry_no
];
2124 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2126 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2127 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2128 && menu
->selected_entry
!=entry_no
) {
2129 wMenuUnmap(submenu
);
2133 selectEntry(menu
, entry_no
);
2141 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2151 if (menu
&& menu
->timer
) {
2152 WMDeleteTimerHandler(menu
->timer
);
2155 if (d_data
.magic
!=NULL
)
2156 WMDeleteTimerHandler(d_data
.magic
);
2158 if (menu
&& menu
->selected_entry
>=0) {
2159 entry
= menu
->entries
[menu
->selected_entry
];
2160 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2161 && entry
->cascade
< 0) {
2162 /* blink and erase menu selection */
2163 #if (MENU_BLINK_DELAY > 0)
2164 int sel
= menu
->selected_entry
;
2167 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2168 paintEntry(menu
, sel
, False
);
2170 wusleep(MENU_BLINK_DELAY
);
2171 paintEntry(menu
, sel
, True
);
2173 wusleep(MENU_BLINK_DELAY
);
2176 /* unmap the menu, it's parents and call the callback */
2177 if (!menu
->flags
.buttoned
&&
2178 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2181 selectEntry(menu
, -1);
2183 (*entry
->callback
)(menu
, entry
);
2185 /* If the user double clicks an entry, the entry will
2186 * be executed twice, which is not good for things like
2187 * the root menu. So, ignore any clicks that were generated
2188 * while the entry was being executed */
2189 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2191 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2192 selectEntry(menu
, -1);
2194 if (entry
->cascade
>=0 && menu
->cascades
2195 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2196 selectEntry(menu
, -1);
2201 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2202 closeCascade(desc
->parent
);
2204 /* close the cascade windows that should not remain opened */
2205 closeBrotherCascadesOf(desc
->parent
);
2207 if (!wPreferences
.wrap_menus
)
2208 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2213 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2222 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2224 if (submenus
>0 && menu
->selected_entry
>=0) {
2225 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2227 if (i
>=0 && menu
->cascades
) {
2228 submenu
= menu
->cascades
[i
];
2229 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
2230 if (wPreferences
.align_menus
) {
2231 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2233 wMenuMove(submenu
, x
+ MENUW(menu
),
2234 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
;
2307 printf("Moving menu\n");
2310 /* can't touch the menu copy */
2311 if (menu
->flags
.brother
)
2314 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2317 if (event
->xbutton
.state
& MOD_MASK
) {
2318 wLowerFrame(menu
->frame
->core
);
2321 wRaiseFrame(menu
->frame
->core
);
2326 /* lower/raise all submenus */
2328 if (tmp
->selected_entry
>=0 && tmp
->cascades
2329 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2330 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2331 if (!tmp
|| !tmp
->flags
.mapped
)
2334 wLowerFrame(tmp
->frame
->core
);
2336 wRaiseFrame(tmp
->frame
->core
);
2342 /* tear off the menu if it's a root menu or a cascade
2344 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2345 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2346 menu
->flags
.buttoned
=1;
2347 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2349 /* turn off selected menu entry in parent menu */
2350 selectEntry(menu
->parent
, -1);
2352 /* make parent map the copy in place of the original */
2353 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2354 if (menu
->parent
->cascades
[i
] == menu
) {
2355 menu
->parent
->cascades
[i
] = menu
->brother
;
2364 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2365 |ExposureMask
, &ev
);
2369 x
+= ev
.xmotion
.x_root
- dx
;
2370 y
+= ev
.xmotion
.y_root
- dy
;
2371 dx
= ev
.xmotion
.x_root
;
2372 dy
= ev
.xmotion
.y_root
;
2373 wMenuMove(menu
, x
, y
, True
);
2375 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2376 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2378 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2379 ButtonMotionMask
|ButtonReleaseMask
2381 GrabModeAsync
, GrabModeAsync
, None
,
2382 wCursor
[WCUR_MOVE
], CurrentTime
);
2391 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2394 printf("End menu move\n");
2396 XUngrabPointer(dpy
, CurrentTime
);
2407 *----------------------------------------------------------------------
2409 * Handles mouse click on the close button of menus. The menu is
2410 * closed when the button is clicked.
2413 * The closed menu is reinserted at it's parent menus
2415 *----------------------------------------------------------------------
2418 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2420 WMenu
*menu
= (WMenu
*)data
;
2421 WMenu
*parent
= menu
->parent
;
2425 for (i
=0; i
<parent
->cascade_no
; i
++) {
2426 /* find the entry that points to the copy */
2427 if (parent
->cascades
[i
] == menu
->brother
) {
2428 /* make it point to the original */
2429 parent
->cascades
[i
] = menu
;
2430 menu
->parent
= parent
;
2440 wMenuSaveState(WScreen
*scr
)
2442 proplist_t menus
, key
, value
;
2447 menus
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
2450 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2451 sprintf(buffer
, "%i,%i", scr
->switch_menu
->frame_x
,
2452 scr
->switch_menu
->frame_y
);
2453 key
= PLMakeString("SwitchMenu");
2454 value
= PLMakeString(buffer
);
2455 PLInsertDictionaryEntry(menus
, key
, value
);
2461 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2465 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2466 sprintf(buffer
, "%i,%i", scr
->workspace_menu
->frame_x
,
2467 scr
->workspace_menu
->frame_y
);
2468 key
= PLMakeString("WorkspaceMenu");
2469 value
= PLMakeString(buffer
);
2470 PLInsertDictionaryEntry(menus
, key
, value
);
2477 key
= PLMakeString("Menus");
2478 PLInsertDictionaryEntry(scr
->session_state
, key
, menus
);
2488 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2493 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2496 len
= strlen(menu
->frame
->title
);
2501 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2506 strcat(buffer
, "\\");
2507 strcat(buffer
, menu
->frame
->title
);
2513 saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
)
2515 proplist_t key
, value
;
2516 int save_menus
= 0, i
;
2521 if (menu
->flags
.brother
)
2522 menu
= menu
->brother
;
2524 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2526 sprintf(buffer
, "%i,%i", menu
->frame_x
, menu
->frame_y
);
2527 value
= PLMakeString(buffer
);
2530 ok
= getMenuPath(menu
, buffer
, 510);
2533 key
= PLMakeString(buffer
);
2534 PLInsertDictionaryEntry(menus
, key
, value
);
2542 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2543 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2552 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2556 restoreMenu(WScreen
*scr
, proplist_t menu
, int which
)
2559 WMenu
*pmenu
= NULL
;
2564 if (!PLIsString(menu
)) {
2565 COMPLAIN("Position");
2569 if (sscanf(PLGetString(menu
), "%i,%i", &x
, &y
)!=2)
2570 COMPLAIN("Position");
2573 if (which
& WSS_SWITCHMENU
) {
2574 OpenSwitchMenu(scr
, x
, y
, False
);
2575 pmenu
= scr
->switch_menu
;
2580 int width
= MENUW(pmenu
);
2581 int height
= MENUH(pmenu
);
2583 x
= (x
< -width
) ? 0 : x
;
2584 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2585 y
= (y
< 0) ? 0 : y
;
2586 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2587 wMenuMove(pmenu
, x
, y
, True
);
2588 pmenu
->flags
.buttoned
= 1;
2589 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2598 restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
)
2600 proplist_t key
, entry
;
2604 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2607 sprintf(buffer
, "%s\\%s", path
, menu
->frame
->title
);
2608 key
= PLMakeString(buffer
);
2609 entry
= PLGetDictionaryEntry(menus
, key
);
2612 if (entry
&& PLIsString(entry
)) {
2614 if (sscanf(PLGetString(entry
), "%i,%i", &x
, &y
) != 2)
2615 COMPLAIN("Position");
2617 if (!menu
->flags
.mapped
) {
2618 int width
= MENUW(menu
);
2619 int height
= MENUH(menu
);
2621 wMenuMapAt(menu
, x
, y
, False
);
2624 /* make parent map the copy in place of the original */
2625 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2626 if (menu
->parent
->cascades
[i
] == menu
) {
2627 menu
->parent
->cascades
[i
] = menu
->brother
;
2632 x
= (x
< -width
) ? 0 : x
;
2633 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2634 y
= (y
< 0) ? 0 : y
;
2635 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2636 wMenuMove(menu
, x
, y
, True
);
2637 menu
->flags
.buttoned
= 1;
2638 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2645 for (i
=0; i
<menu
->cascade_no
; i
++) {
2646 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2656 wMenuRestoreState(WScreen
*scr
)
2658 proplist_t menus
, menu
, key
, skey
;
2660 key
= PLMakeString("Menus");
2661 menus
= PLGetDictionaryEntry(scr
->session_state
, key
);
2669 skey
= PLMakeString("SwitchMenu");
2670 menu
= PLGetDictionaryEntry(menus
, skey
);
2671 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2674 if (!scr
->root_menu
) {
2675 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2676 wMenuUnmap(scr
->root_menu
);
2678 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2686 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2688 WMenu
*menu
, *parent
;
2692 if (!scr
->root_menu
) {
2693 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2694 wMenuUnmap(scr
->root_menu
);
2697 menu
= scr
->workspace_menu
;
2699 if (menu
->flags
.mapped
) {
2700 if (!menu
->flags
.buttoned
) {
2702 parent
= menu
->parent
;
2703 if (parent
&& parent
->selected_entry
>= 0) {
2704 entry
= parent
->entries
[parent
->selected_entry
];
2705 if (parent
->cascades
[entry
->cascade
] == menu
) {
2706 selectEntry(parent
, -1);
2707 wMenuMapAt(menu
, x
, y
, False
);
2711 wRaiseFrame(menu
->frame
->core
);
2712 wMenuMapCopyAt(menu
, x
, y
);
2715 wMenuMapAt(menu
, x
, y
, False
);