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
= wTextWidth(scr
->menu_title_font
->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
= scr
->menu_entry_font
->height
+ 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
= wTextWidth(scr
->menu_entry_font
->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
= wTextWidth(scr
->menu_entry_font
->font
, 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 wDrawString(win
, scr
->menu_entry_font
,
796 textGC
, x
, 3+y
+scr
->menu_entry_font
->y
, entry
->text
,
797 strlen(entry
->text
));
799 if (entry
->cascade
>=0) {
800 /* draw the cascade indicator */
801 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
802 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
803 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
807 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
812 switch (entry
->flags
.indicator_type
) {
814 indicator
= scr
->menu_check_indicator
;
817 indicator
= scr
->menu_mini_indicator
;
820 indicator
= scr
->menu_hide_indicator
;
823 indicator
= scr
->menu_shade_indicator
;
827 indicator
= scr
->menu_radio_indicator
;
831 iw
= indicator
->width
;
832 ih
= indicator
->height
;
833 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
834 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
836 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
838 XSetForeground(dpy
, scr
->copy_gc
, scr
->mtext_pixel
);
839 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
841 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
842 iw, ih, 5, y+(h-ih)/2);
844 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
847 /* draw right text */
849 if (entry
->rtext
&& entry
->cascade
<0) {
850 tw
= wTextWidth(scr
->menu_entry_font
->font
, entry
->rtext
,
851 strlen(entry
->rtext
));
853 wDrawString(win
, scr
->menu_entry_font
, textGC
, w
-6-tw
,
854 3+y
+scr
->menu_entry_font
->y
, entry
->rtext
,
855 strlen(entry
->rtext
));
861 move_menus(WMenu
*menu
, int x
, int y
)
863 while (menu
->parent
) {
866 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
867 y
-= menu
->selected_entry
*menu
->entry_height
;
870 wMenuMove(menu
, x
, y
, True
);
874 makeVisible(WMenu
*menu
)
876 WScreen
*scr
= menu
->frame
->screen_ptr
;
877 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
879 if (menu
->entry_no
<0) return;
882 y1
= menu
->frame_y
+menu
->frame
->top_width
883 + menu
->selected_entry
*menu
->entry_height
;
884 x2
= x1
+ MENUW(menu
);
885 y2
= y1
+ menu
->entry_height
;
894 } else if (x2
>= scr
->scr_width
) {
895 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
902 } else if (y2
>= scr
->scr_height
) {
903 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
907 new_y
= new_y
- menu
->frame
->top_width
908 - menu
->selected_entry
*menu
->entry_height
;
909 move_menus(menu
, new_x
, new_y
);
914 check_key(WMenu
*menu
, XKeyEvent
*event
)
919 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
922 ch
= toupper(buffer
[0]);
924 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
927 for (i
=s
; i
<menu
->entry_no
; i
++) {
928 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
932 /* no match. Retry from start, if previous started from a selected entry */
942 keyboardMenu(WMenu
*menu
)
945 KeySym ksym
=NoSymbol
;
949 int old_pos_x
= menu
->frame_x
;
950 int old_pos_y
= menu
->frame_y
;
951 int new_x
= old_pos_x
, new_y
= old_pos_y
;
952 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
953 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
955 if (menu
->flags
.editing
)
959 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
960 GrabModeAsync
, CurrentTime
);
962 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
963 new_y
= scr_height
- menu
->frame
->top_width
;
965 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
966 new_x
= scr_width
-MENUW(menu
)-1;
968 move_menus(menu
, new_x
, new_y
);
970 while (!done
&& menu
->flags
.mapped
) {
971 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
972 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
973 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
974 |SubstructureNotifyMask
, &event
);
976 switch (event
.type
) {
978 ksym
= XLookupKeysym(&event
.xkey
, 0);
986 selectEntry(menu
, 0);
992 selectEntry(menu
, menu
->entry_no
-1);
1001 if (menu
->selected_entry
<= 0)
1002 selectEntry(menu
, menu
->entry_no
-1);
1004 selectEntry(menu
, menu
->selected_entry
-1);
1009 #ifdef ARROWLESS_KBD
1013 if (menu
->selected_entry
<0)
1014 selectEntry(menu
, 0);
1015 else if (menu
->selected_entry
== menu
->entry_no
-1)
1016 selectEntry(menu
, 0);
1017 else if (menu
->selected_entry
< menu
->entry_no
-1)
1018 selectEntry(menu
, menu
->selected_entry
+1);
1023 #ifdef ARROWLESS_KBD
1027 if (menu
->selected_entry
>=0) {
1029 entry
= menu
->entries
[menu
->selected_entry
];
1031 if (entry
->cascade
>= 0 && menu
->cascades
1032 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1034 XUngrabKeyboard(dpy
, CurrentTime
);
1036 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1037 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1040 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1041 GrabModeAsync
, GrabModeAsync
,
1048 #ifdef ARROWLESS_KBD
1052 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1053 selectEntry(menu
, -1);
1054 move_menus(menu
, old_pos_x
, old_pos_y
);
1064 index
= check_key(menu
, &event
.xkey
);
1066 selectEntry(menu
, index
);
1072 if (event
.type
==ButtonPress
)
1075 WMHandleEvent(&event
);
1079 XUngrabKeyboard(dpy
, CurrentTime
);
1081 if (done
==2 && menu
->selected_entry
>=0) {
1082 entry
= menu
->entries
[menu
->selected_entry
];
1087 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1088 && entry
->cascade
< 0) {
1089 #if (MENU_BLINK_COUNT > 0)
1090 int sel
= menu
->selected_entry
;
1093 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1094 paintEntry(menu
, sel
, False
);
1096 wusleep(MENU_BLINK_DELAY
);
1097 paintEntry(menu
, sel
, True
);
1099 wusleep(MENU_BLINK_DELAY
);
1102 selectEntry(menu
, -1);
1104 if (!menu
->flags
.buttoned
) {
1106 move_menus(menu
, old_pos_x
, old_pos_y
);
1110 (*entry
->callback
)(menu
, entry
);
1112 if (!menu
->flags
.buttoned
) {
1114 move_menus(menu
, old_pos_x
, old_pos_y
);
1116 selectEntry(menu
, -1);
1120 /* returns True if returning from a submenu to a parent menu,
1121 * False if exiting from menu */
1127 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1129 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1130 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1132 if (!menu
->flags
.realized
) {
1133 menu
->flags
.realized
=1;
1136 if (!menu
->flags
.mapped
) {
1137 if (wPreferences
.wrap_menus
) {
1140 if (x
+MENUW(menu
) > scr_width
)
1141 x
= scr_width
- MENUW(menu
);
1142 if (y
+MENUH(menu
) > scr_height
)
1143 y
= scr_height
- MENUH(menu
);
1146 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1149 XMapWindow(dpy
, menu
->frame
->core
->window
);
1150 wRaiseFrame(menu
->frame
->core
);
1151 menu
->flags
.mapped
= 1;
1153 selectEntry(menu
, 0);
1162 wMenuMap(WMenu
*menu
)
1164 if (!menu
->flags
.realized
) {
1165 menu
->flags
.realized
=1;
1168 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1169 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1170 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1171 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1173 XMapWindow(dpy
, menu
->frame
->core
->window
);
1174 wRaiseFrame(menu
->frame
->core
);
1175 menu
->flags
.mapped
= 1;
1180 wMenuUnmap(WMenu
*menu
)
1184 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1185 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1186 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1188 menu
->flags
.buttoned
= 0;
1189 menu
->flags
.mapped
= 0;
1190 menu
->flags
.open_to_left
= 0;
1192 for (i
=0; i
<menu
->cascade_no
; i
++) {
1193 if (menu
->cascades
[i
]!=NULL
1194 && menu
->cascades
[i
]->flags
.mapped
1195 && !menu
->cascades
[i
]->flags
.buttoned
) {
1197 wMenuUnmap(menu
->cascades
[i
]);
1200 menu
->selected_entry
= -1;
1206 wMenuPaint(WMenu
*menu
)
1210 if (!menu
->flags
.mapped
) {
1215 for (i
=0; i
<menu
->entry_no
; i
++) {
1216 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1222 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1224 if (index
>=menu
->entry_no
) return;
1225 menu
->entries
[index
]->flags
.enabled
=enable
;
1226 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1227 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1231 /* ====================================================================== */
1235 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1239 WObjDescriptor
*desc
;
1245 menu
->flags
.editing
= 1;
1247 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1248 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1250 wTextPutText(text
, entry
->text
);
1251 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1252 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1254 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1255 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1256 wwarning("could not grab keyboard");
1259 wSetFocusTo(menu
->frame
->screen_ptr
,
1260 menu
->frame
->screen_ptr
->focused_window
);
1265 while (!done
&& !text
->done
) {
1267 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1269 WMNextEvent(dpy
, &event
);
1271 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1272 (XPointer
*)&desc
)==XCNOENT
)
1275 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1277 (*desc
->handle_anything
)(desc
, &event
);
1280 switch (event
.type
) {
1282 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1286 WMHandleEvent(&event
);
1292 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1294 wSetFocusTo(menu
->frame
->screen_ptr
,
1295 menu
->frame
->screen_ptr
->focused_window
);
1298 t
= wTextGetText(text
);
1299 /* if !t, the user has canceled editing */
1303 entry
->text
= wstrdup(t
);
1305 menu
->flags
.realized
= 0;
1309 XUngrabKeyboard(dpy
, CurrentTime
);
1311 if (t
&& menu
->on_edit
)
1312 (*menu
->on_edit
)(menu
, entry
);
1314 menu
->flags
.editing
= 0;
1316 if (!menu
->flags
.realized
)
1322 selectEntry(WMenu
*menu
, int entry_no
)
1328 if (menu
->entries
==NULL
)
1331 if (entry_no
>= menu
->entry_no
)
1334 old_entry
= menu
->selected_entry
;
1335 menu
->selected_entry
= entry_no
;
1337 if (old_entry
!=entry_no
) {
1339 /* unselect previous entry */
1341 paintEntry(menu
, old_entry
, False
);
1342 entry
= menu
->entries
[old_entry
];
1345 if (entry
->cascade
>=0 && menu
->cascades
) {
1346 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1347 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1353 menu
->selected_entry
= -1;
1356 entry
= menu
->entries
[entry_no
];
1358 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1359 /* Callback for when the submenu is opened.
1361 submenu
= menu
->cascades
[entry
->cascade
];
1362 if (submenu
&& submenu
->flags
.brother
)
1363 submenu
= submenu
->brother
;
1365 if (entry
->callback
) {
1366 /* Only call the callback if the submenu is not yet mapped.
1368 if (menu
->flags
.brother
) {
1369 if (!submenu
|| !submenu
->flags
.mapped
)
1370 (*entry
->callback
)(menu
->brother
, entry
);
1372 if (!submenu
|| !submenu
->flags
.buttoned
)
1373 (*entry
->callback
)(menu
, entry
);
1377 /* the submenu menu might have changed */
1378 submenu
= menu
->cascades
[entry
->cascade
];
1381 if (!submenu
->flags
.mapped
) {
1384 if (!submenu
->flags
.realized
)
1385 wMenuRealize(submenu
);
1386 if (wPreferences
.wrap_menus
) {
1387 if (menu
->flags
.open_to_left
)
1388 submenu
->flags
.open_to_left
= 1;
1390 if (submenu
->flags
.open_to_left
) {
1391 x
= menu
->frame_x
- MENUW(submenu
);
1394 submenu
->flags
.open_to_left
= 0;
1397 x
= menu
->frame_x
+ MENUW(menu
);
1399 if (x
+ MENUW(submenu
)
1400 >= menu
->frame
->screen_ptr
->scr_width
) {
1402 x
= menu
->frame_x
- MENUW(submenu
);
1403 submenu
->flags
.open_to_left
= 1;
1407 x
= menu
->frame_x
+ MENUW(menu
);
1410 if (wPreferences
.align_menus
) {
1413 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1414 if (menu
->flags
.titled
)
1415 y
+= menu
->frame
->top_width
;
1416 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1417 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1420 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1421 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1426 paintEntry(menu
, entry_no
, True
);
1432 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1435 WObjDescriptor
*desc
;
1436 Window root_ret
, win
, junk_win
;
1440 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1443 if (win
==None
) return NULL
;
1445 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1448 if (desc
->parent_type
== WCLASS_MENU
) {
1449 menu
= (WMenu
*)desc
->parent
;
1450 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1451 x_ret
, y_ret
, &junk_win
);
1461 closeCascade(WMenu
*menu
)
1463 WMenu
*parent
=menu
->parent
;
1465 if (menu
->flags
.brother
1466 || (!menu
->flags
.buttoned
1467 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1469 selectEntry(menu
, -1);
1471 #if (MENU_BLINK_DELAY > 2)
1472 wusleep(MENU_BLINK_DELAY
/2);
1476 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1477 || parent
->flags
.brother
)
1478 && !parent
->flags
.buttoned
) {
1479 selectEntry(parent
, -1);
1481 parent
= parent
->parent
;
1484 selectEntry(parent
, -1);
1490 closeBrotherCascadesOf(WMenu
*menu
)
1495 for (i
=0; i
<menu
->cascade_no
; i
++) {
1496 if (menu
->cascades
[i
]->flags
.brother
) {
1497 tmp
= menu
->cascades
[i
];
1499 tmp
= menu
->cascades
[i
]->brother
;
1501 if (tmp
->flags
.mapped
) {
1502 selectEntry(tmp
->parent
, -1);
1503 closeBrotherCascadesOf(tmp
);
1510 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1514 parentMenu(WMenu
*menu
)
1519 if (menu
->flags
.buttoned
)
1522 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1523 parent
= menu
->parent
;
1524 if (parent
->selected_entry
< 0)
1526 entry
= parent
->entries
[parent
->selected_entry
];
1527 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1528 parent
->cascades
[entry
->cascade
] != menu
)
1531 if (menu
->flags
.buttoned
)
1541 * Will raise the passed menu, if submenu = 0
1542 * If submenu > 0 will also raise all mapped submenus
1543 * until the first buttoned one
1544 * If submenu < 0 will also raise all mapped parent menus
1545 * until the first buttoned one
1549 raiseMenus(WMenu
*menu
, int submenus
)
1556 wRaiseFrame(menu
->frame
->core
);
1558 if (submenus
>0 && menu
->selected_entry
>=0) {
1559 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1560 if (i
>=0 && menu
->cascades
) {
1561 submenu
= menu
->cascades
[i
];
1562 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1563 raiseMenus(submenu
, submenus
);
1566 if (submenus
<0 && !menu
->flags
.buttoned
&&
1567 menu
->parent
&& menu
->parent
->flags
.mapped
)
1568 raiseMenus(menu
->parent
, submenus
);
1573 wMenuUnderPointer(WScreen
*screen
)
1575 WObjDescriptor
*desc
;
1576 Window root_ret
, win
;
1580 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1581 &dummy
, &dummy
, &mask
);
1583 if (win
==None
) return NULL
;
1585 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1588 if (desc
->parent_type
== WCLASS_MENU
)
1589 return (WMenu
*)desc
->parent
;
1595 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
1599 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1601 Window root_ret
, win
;
1605 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1610 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1612 WScreen
*scr
= menu
->menu
->screen_ptr
;
1613 int menuX1
= menu
->frame_x
;
1614 int menuY1
= menu
->frame_y
;
1615 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1616 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1617 int screenW
= scr
->scr_width
;
1618 int screenH
= scr
->scr_height
;
1624 getPointerPosition(scr
, &xroot
, &yroot
);
1627 if (xroot
<= 1 && menuX1
< 0) {
1628 /* scroll to the right */
1629 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX1
));
1631 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1632 /* scroll to the left */
1633 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1638 *hamount
= -*hamount
;
1641 if (yroot
<= 1 && menuY1
< 0) {
1643 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY1
));
1645 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1647 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1649 *vamount
= -*vamount
;
1655 dragScrollMenuCallback(void *data
)
1657 WMenu
*menu
= (WMenu
*)data
;
1658 WScreen
*scr
= menu
->menu
->screen_ptr
;
1659 WMenu
*parent
= parentMenu(menu
);
1660 int hamount
, vamount
;
1662 int newSelectedEntry
;
1664 getScrollAmount(menu
, &hamount
, &vamount
);
1667 if (hamount
!= 0 || vamount
!= 0) {
1668 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1669 parent
->frame_y
+ vamount
, True
);
1670 if (findMenu(scr
, &x
, &y
)) {
1671 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1672 selectEntry(menu
, newSelectedEntry
);
1674 /* Pointer fell outside of menu. If the selected entry is
1675 * not a submenu, unselect it */
1676 if (menu
->selected_entry
>= 0
1677 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1678 selectEntry(menu
, -1);
1679 newSelectedEntry
= 0;
1682 /* paranoid check */
1683 if (newSelectedEntry
>= 0) {
1684 /* keep scrolling */
1685 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1686 dragScrollMenuCallback
, menu
);
1691 /* don't need to scroll anymore */
1693 if (findMenu(scr
, &x
, &y
)) {
1694 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1695 selectEntry(menu
, newSelectedEntry
);
1702 scrollMenuCallback(void *data
)
1704 WMenu
*menu
= (WMenu
*)data
;
1705 WMenu
*parent
= parentMenu(menu
);
1706 int hamount
= 0; /* amount to scroll */
1709 getScrollAmount(menu
, &hamount
, &vamount
);
1711 if (hamount
!= 0 || vamount
!= 0) {
1712 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1713 parent
->frame_y
+ vamount
, True
);
1715 /* keep scrolling */
1716 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1717 scrollMenuCallback
, menu
);
1719 /* don't need to scroll anymore */
1726 #define MENU_SCROLL_BORDER 5
1729 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1731 int menuX1
= menu
->frame_x
;
1732 int menuY1
= menu
->frame_y
;
1733 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1734 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1735 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1736 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1739 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1740 || y
> scrYe
-MENU_SCROLL_BORDER
))
1742 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1743 || x
> scrXe
-MENU_SCROLL_BORDER
))
1750 typedef struct _delay
{
1758 _leaving(_delay
*dl
)
1760 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1761 dl
->menu
->jump_back
=NULL
;
1762 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1768 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1771 WMenu
*omenu
= parentMenu(menu
);
1772 WScreen
*scr
= menu
->frame
->screen_ptr
;
1775 int old_frame_x
= omenu
->frame_x
;
1776 int old_frame_y
= omenu
->frame_y
;
1780 puts("Entering menu Scroll");
1783 if (omenu
->jump_back
)
1784 WMDeleteTimerWithClientData(omenu
->jump_back
);
1787 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1788 || omenu
->flags
.app_menu
) {
1792 if (!wPreferences
.wrap_menus
)
1793 raiseMenus(omenu
, True
);
1795 raiseMenus(menu
, False
);
1798 scrollMenuCallback(menu
);
1801 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1803 WMNextEvent(dpy
, &ev
);
1808 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1809 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1811 /* on_border is != 0 if the pointer is between the menu
1812 * and the screen border and is close enough to the border */
1813 on_border
= isPointNearBoder(menu
, x
, y
);
1815 smenu
= wMenuUnderPointer(scr
);
1817 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1822 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1823 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1824 on_border
= on_x_edge
|| on_y_edge
;
1826 if (!on_border
&& !jump_back
) {
1831 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1832 WMDeleteTimerHandler(menu
->timer
);
1840 scrollMenuCallback(menu
);
1843 /* True if we push on title, or drag the omenu to other position */
1844 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1845 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1846 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1847 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1849 smenu
= wMenuUnderPointer(scr
);
1850 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1852 else if (smenu
==omenu
&& on_title
) {
1866 WMDeleteTimerHandler(menu
->timer
);
1872 if (!omenu
->jump_back
) {
1873 delayer
=wmalloc(sizeof(_delay
));
1874 delayer
->menu
=omenu
;
1875 delayer
->ox
=old_frame_x
;
1876 delayer
->oy
=old_frame_y
;
1877 omenu
->jump_back
=delayer
;
1878 scr
->flags
.jump_back_pending
= 1;
1880 else delayer
= omenu
->jump_back
;
1881 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1886 puts("Leaving menu Scroll");
1893 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1895 wMenuPaint(desc
->parent
);
1899 int *delayed_select
;
1906 delaySelection(void *data
)
1908 delay_data
*d
= (delay_data
*)data
;
1914 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1915 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1916 entry_no
= getEntryAt(menu
, x
, y
);
1917 selectEntry(menu
, entry_no
);
1919 if (d
->delayed_select
)
1920 *(d
->delayed_select
) = 0;
1925 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1927 XButtonEvent
*bev
= &event
->xbutton
;
1928 WMenu
*menu
= desc
->parent
;
1930 WScreen
*scr
=menu
->frame
->screen_ptr
;
1931 WMenuEntry
*entry
=NULL
;
1933 int close_on_exit
=0;
1935 int delayed_select
= 0;
1939 int old_frame_x
= 0;
1940 int old_frame_y
= 0;
1941 delay_data d_data
= {NULL
, NULL
, NULL
};
1943 if (!wPreferences
.wrap_menus
) {
1944 smenu
= parentMenu(menu
);
1945 old_frame_x
= smenu
->frame_x
;
1946 old_frame_y
= smenu
->frame_y
;
1947 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1948 /* This is true if the menu was launched with right click on root window */
1950 d_data
.delayed_select
= &delayed_select
;
1952 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1953 delaySelection
, &d_data
);
1956 wRaiseFrame(menu
->frame
->core
);
1958 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1960 smenu
= findMenu(scr
, &x
, &y
);
1968 if (menu
->flags
.editing
) {
1971 entry_no
= getEntryAt(menu
, x
, y
);
1973 entry
= menu
->entries
[entry_no
];
1975 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1976 && entry
->flags
.editable
) {
1977 editEntry(smenu
, entry
);
1979 } else if (bev
->state
& ControlMask
) {
1983 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1984 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1986 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1987 menu
->selected_entry
!=entry_no
) {
1988 wMenuUnmap(submenu
);
1990 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1991 selectEntry(menu
, entry_no
);
1992 } else if (!submenu
->flags
.buttoned
) {
1993 selectEntry(menu
, -1);
1996 } else if (!delayed_select
) {
1997 selectEntry(menu
, entry_no
);
2000 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2002 dragScrollMenuCallback(menu
);
2006 prevx
= bev
->x_root
;
2007 prevy
= bev
->y_root
;
2011 XAllowEvents(dpy
, SyncPointer
, CurrentTime
);
2013 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2014 |ButtonPressMask
, &ev
);
2017 smenu
= findMenu(scr
, &x
, &y
);
2019 if (smenu
== NULL
) {
2020 /* moved mouse out of menu */
2022 if (!delayed_select
&& d_data
.magic
) {
2023 WMDeleteTimerHandler(d_data
.magic
);
2024 d_data
.magic
= NULL
;
2027 || (menu
->selected_entry
>=0
2028 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2029 prevx
= ev
.xmotion
.x_root
;
2030 prevy
= ev
.xmotion
.y_root
;
2034 selectEntry(menu
, -1);
2036 prevx
= ev
.xmotion
.x_root
;
2037 prevy
= ev
.xmotion
.y_root
;
2039 } else if (menu
&& menu
!=smenu
2040 && (menu
->selected_entry
<0
2041 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2042 selectEntry(menu
, -1);
2044 if (!delayed_select
&& d_data
.magic
) {
2045 WMDeleteTimerHandler(d_data
.magic
);
2046 d_data
.magic
= NULL
;
2050 /* hysteresis for item selection */
2052 /* check if the motion was to the side, indicating that
2053 * the user may want to cross to a submenu */
2054 if (!delayed_select
&& menu
) {
2056 Bool moved_to_submenu
;/* moved to direction of submenu */
2058 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2060 moved_to_submenu
= False
;
2061 if (dx
> 0 /* if moved enough to the side */
2062 /* maybe a open submenu */
2063 && menu
->selected_entry
>=0
2064 /* moving to the right direction */
2065 && (wPreferences
.align_menus
2066 || ev
.xmotion
.y_root
>= prevy
)) {
2069 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2071 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2072 if (prevx
< ev
.xmotion
.x_root
)
2073 moved_to_submenu
= True
;
2075 if (prevx
> ev
.xmotion
.x_root
)
2076 moved_to_submenu
= True
;
2082 if (menu
!= smenu
) {
2084 WMDeleteTimerHandler(d_data
.magic
);
2086 d_data
.magic
= NULL
;
2087 } else if (moved_to_submenu
) {
2088 /* while we are moving, postpone the selection */
2090 WMDeleteTimerHandler(d_data
.magic
);
2092 d_data
.delayed_select
= NULL
;
2094 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2097 prevx
= ev
.xmotion
.x_root
;
2098 prevy
= ev
.xmotion
.y_root
;
2102 WMDeleteTimerHandler(d_data
.magic
);
2103 d_data
.magic
= NULL
;
2107 prevx
= ev
.xmotion
.x_root
;
2108 prevy
= ev
.xmotion
.y_root
;
2110 /* pointer crossed menus */
2111 if (menu
&& menu
->timer
) {
2112 WMDeleteTimerHandler(menu
->timer
);
2116 dragScrollMenuCallback(smenu
);
2120 dragScrollMenuCallback(menu
);
2122 if (!delayed_select
) {
2123 entry_no
= getEntryAt(menu
, x
, y
);
2125 entry
= menu
->entries
[entry_no
];
2126 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2128 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2129 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2130 && menu
->selected_entry
!=entry_no
) {
2131 wMenuUnmap(submenu
);
2135 selectEntry(menu
, entry_no
);
2143 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2153 if (menu
&& menu
->timer
) {
2154 WMDeleteTimerHandler(menu
->timer
);
2157 if (d_data
.magic
!=NULL
)
2158 WMDeleteTimerHandler(d_data
.magic
);
2160 if (menu
&& menu
->selected_entry
>=0) {
2161 entry
= menu
->entries
[menu
->selected_entry
];
2162 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2163 && entry
->cascade
< 0) {
2164 /* blink and erase menu selection */
2165 #if (MENU_BLINK_DELAY > 0)
2166 int sel
= menu
->selected_entry
;
2169 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2170 paintEntry(menu
, sel
, False
);
2172 wusleep(MENU_BLINK_DELAY
);
2173 paintEntry(menu
, sel
, True
);
2175 wusleep(MENU_BLINK_DELAY
);
2178 /* unmap the menu, it's parents and call the callback */
2179 if (!menu
->flags
.buttoned
&&
2180 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2183 selectEntry(menu
, -1);
2185 (*entry
->callback
)(menu
, entry
);
2187 /* If the user double clicks an entry, the entry will
2188 * be executed twice, which is not good for things like
2189 * the root menu. So, ignore any clicks that were generated
2190 * while the entry was being executed */
2191 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2193 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2194 selectEntry(menu
, -1);
2196 if (entry
->cascade
>=0 && menu
->cascades
2197 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2198 selectEntry(menu
, -1);
2203 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2204 closeCascade(desc
->parent
);
2206 /* close the cascade windows that should not remain opened */
2207 closeBrotherCascadesOf(desc
->parent
);
2209 if (!wPreferences
.wrap_menus
)
2210 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2215 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2224 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2226 if (submenus
>0 && menu
->selected_entry
>=0) {
2227 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2229 if (i
>=0 && menu
->cascades
) {
2230 submenu
= menu
->cascades
[i
];
2231 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
2232 if (wPreferences
.align_menus
) {
2233 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2235 wMenuMove(submenu
, x
+ MENUW(menu
),
2236 y
+ submenu
->entry_height
*menu
->selected_entry
,
2241 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2242 !menu
->parent
->flags
.buttoned
) {
2243 if (wPreferences
.align_menus
) {
2244 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2246 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2247 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2255 changeMenuLevels(WMenu
*menu
, int lower
)
2260 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2262 wRaiseFrame(menu
->frame
->core
);
2263 menu
->flags
.lowered
= 0;
2265 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2266 wLowerFrame(menu
->frame
->core
);
2267 menu
->flags
.lowered
= 1;
2269 for (i
=0; i
<menu
->cascade_no
; i
++) {
2270 if (menu
->cascades
[i
]
2271 && !menu
->cascades
[i
]->flags
.buttoned
2272 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2273 changeMenuLevels(menu
->cascades
[i
], lower
);
2281 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2286 if (event
->xbutton
.state
& MOD_MASK
) {
2287 if (menu
->flags
.lowered
) {
2292 changeMenuLevels(menu
, lower
);
2298 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2303 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2304 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2309 printf("Moving menu\n");
2312 /* can't touch the menu copy */
2313 if (menu
->flags
.brother
)
2316 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2319 if (event
->xbutton
.state
& MOD_MASK
) {
2320 wLowerFrame(menu
->frame
->core
);
2323 wRaiseFrame(menu
->frame
->core
);
2328 /* lower/raise all submenus */
2330 if (tmp
->selected_entry
>=0 && tmp
->cascades
2331 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2332 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2333 if (!tmp
|| !tmp
->flags
.mapped
)
2336 wLowerFrame(tmp
->frame
->core
);
2338 wRaiseFrame(tmp
->frame
->core
);
2344 /* tear off the menu if it's a root menu or a cascade
2346 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2347 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2348 menu
->flags
.buttoned
=1;
2349 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2351 /* turn off selected menu entry in parent menu */
2352 selectEntry(menu
->parent
, -1);
2354 /* make parent map the copy in place of the original */
2355 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2356 if (menu
->parent
->cascades
[i
] == menu
) {
2357 menu
->parent
->cascades
[i
] = menu
->brother
;
2366 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2367 |ExposureMask
, &ev
);
2371 x
+= ev
.xmotion
.x_root
- dx
;
2372 y
+= ev
.xmotion
.y_root
- dy
;
2373 dx
= ev
.xmotion
.x_root
;
2374 dy
= ev
.xmotion
.y_root
;
2375 wMenuMove(menu
, x
, y
, True
);
2377 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2378 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2380 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2381 ButtonMotionMask
|ButtonReleaseMask
2383 GrabModeAsync
, GrabModeAsync
, None
,
2384 wCursor
[WCUR_MOVE
], CurrentTime
);
2393 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2396 printf("End menu move\n");
2398 XUngrabPointer(dpy
, CurrentTime
);
2409 *----------------------------------------------------------------------
2411 * Handles mouse click on the close button of menus. The menu is
2412 * closed when the button is clicked.
2415 * The closed menu is reinserted at it's parent menus
2417 *----------------------------------------------------------------------
2420 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2422 WMenu
*menu
= (WMenu
*)data
;
2423 WMenu
*parent
= menu
->parent
;
2427 for (i
=0; i
<parent
->cascade_no
; i
++) {
2428 /* find the entry that points to the copy */
2429 if (parent
->cascades
[i
] == menu
->brother
) {
2430 /* make it point to the original */
2431 parent
->cascades
[i
] = menu
;
2432 menu
->parent
= parent
;
2442 wMenuSaveState(WScreen
*scr
)
2444 proplist_t menus
, key
, value
;
2449 menus
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
2452 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2453 sprintf(buffer
, "%i,%i", scr
->switch_menu
->frame_x
,
2454 scr
->switch_menu
->frame_y
);
2455 key
= PLMakeString("SwitchMenu");
2456 value
= PLMakeString(buffer
);
2457 PLInsertDictionaryEntry(menus
, key
, value
);
2463 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2467 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2468 sprintf(buffer
, "%i,%i", scr
->workspace_menu
->frame_x
,
2469 scr
->workspace_menu
->frame_y
);
2470 key
= PLMakeString("WorkspaceMenu");
2471 value
= PLMakeString(buffer
);
2472 PLInsertDictionaryEntry(menus
, key
, value
);
2479 key
= PLMakeString("Menus");
2480 PLInsertDictionaryEntry(scr
->session_state
, key
, menus
);
2490 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2495 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2498 len
= strlen(menu
->frame
->title
);
2503 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2508 strcat(buffer
, "\\");
2509 strcat(buffer
, menu
->frame
->title
);
2515 saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
)
2517 proplist_t key
, value
;
2518 int save_menus
= 0, i
;
2523 if (menu
->flags
.brother
)
2524 menu
= menu
->brother
;
2526 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2528 sprintf(buffer
, "%i,%i", menu
->frame_x
, menu
->frame_y
);
2529 value
= PLMakeString(buffer
);
2532 ok
= getMenuPath(menu
, buffer
, 510);
2535 key
= PLMakeString(buffer
);
2536 PLInsertDictionaryEntry(menus
, key
, value
);
2544 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2545 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2554 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2558 restoreMenu(WScreen
*scr
, proplist_t menu
, int which
)
2561 WMenu
*pmenu
= NULL
;
2566 if (!PLIsString(menu
)) {
2567 COMPLAIN("Position");
2571 if (sscanf(PLGetString(menu
), "%i,%i", &x
, &y
)!=2)
2572 COMPLAIN("Position");
2575 if (which
& WSS_SWITCHMENU
) {
2576 OpenSwitchMenu(scr
, x
, y
, False
);
2577 pmenu
= scr
->switch_menu
;
2582 int width
= MENUW(pmenu
);
2583 int height
= MENUH(pmenu
);
2585 x
= (x
< -width
) ? 0 : x
;
2586 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2587 y
= (y
< 0) ? 0 : y
;
2588 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2589 wMenuMove(pmenu
, x
, y
, True
);
2590 pmenu
->flags
.buttoned
= 1;
2591 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2600 restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
)
2602 proplist_t key
, entry
;
2606 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2609 sprintf(buffer
, "%s\\%s", path
, menu
->frame
->title
);
2610 key
= PLMakeString(buffer
);
2611 entry
= PLGetDictionaryEntry(menus
, key
);
2614 if (entry
&& PLIsString(entry
)) {
2616 if (sscanf(PLGetString(entry
), "%i,%i", &x
, &y
) != 2)
2617 COMPLAIN("Position");
2619 if (!menu
->flags
.mapped
) {
2620 int width
= MENUW(menu
);
2621 int height
= MENUH(menu
);
2623 wMenuMapAt(menu
, x
, y
, False
);
2626 /* make parent map the copy in place of the original */
2627 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2628 if (menu
->parent
->cascades
[i
] == menu
) {
2629 menu
->parent
->cascades
[i
] = menu
->brother
;
2634 x
= (x
< -width
) ? 0 : x
;
2635 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2636 y
= (y
< 0) ? 0 : y
;
2637 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2638 wMenuMove(menu
, x
, y
, True
);
2639 menu
->flags
.buttoned
= 1;
2640 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2647 for (i
=0; i
<menu
->cascade_no
; i
++) {
2648 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2658 wMenuRestoreState(WScreen
*scr
)
2660 proplist_t menus
, menu
, key
, skey
;
2662 key
= PLMakeString("Menus");
2663 menus
= PLGetDictionaryEntry(scr
->session_state
, key
);
2671 skey
= PLMakeString("SwitchMenu");
2672 menu
= PLGetDictionaryEntry(menus
, skey
);
2673 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2676 if (!scr
->root_menu
) {
2677 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2678 wMenuUnmap(scr
->root_menu
);
2680 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2688 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2690 WMenu
*menu
, *parent
;
2694 if (!scr
->root_menu
) {
2695 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2696 wMenuUnmap(scr
->root_menu
);
2699 menu
= scr
->workspace_menu
;
2701 if (menu
->flags
.mapped
) {
2702 if (!menu
->flags
.buttoned
) {
2704 parent
= menu
->parent
;
2705 if (parent
&& parent
->selected_entry
>= 0) {
2706 entry
= parent
->entries
[parent
->selected_entry
];
2707 if (parent
->cascades
[entry
->cascade
] == menu
) {
2708 selectEntry(parent
, -1);
2709 wMenuMapAt(menu
, x
, y
, False
);
2713 wRaiseFrame(menu
->frame
->core
);
2714 wMenuMapCopyAt(menu
, x
, y
);
2717 wMenuMapAt(menu
, x
, y
, False
);