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
,
175 #ifdef DRAWSTRING_PLUGIN
178 &screen
->menu_title_gc
,
179 &screen
->menu_title_font
);
181 menu
->frame
->core
->descriptor
.parent
= menu
;
182 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
183 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
185 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
188 menu
->frame
->title
= wstrdup(title
);
191 menu
->frame
->flags
.justification
= WTJ_LEFT
;
193 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
196 menu
->alloced_entries
= 0;
197 menu
->selected_entry
= -1;
198 menu
->entries
= NULL
;
200 menu
->frame_x
= screen
->app_menu_x
;
201 menu
->frame_y
= screen
->app_menu_y
;
203 menu
->frame
->child
= menu
;
205 menu
->flags
.lowered
= 0;
209 /* setup object descriptors */
210 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
211 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
214 menu
->frame
->on_click_right
= menuCloseClick
;
217 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
218 menu
->frame
->core
->width
, 10);
220 menu
->menu
->descriptor
.parent
= menu
;
221 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
222 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
223 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
225 menu
->menu_texture_data
= None
;
227 XMapWindow(dpy
, menu
->menu
->window
);
233 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
235 menu
->brother
->flags
.brother
= 1;
236 menu
->brother
->brother
= menu
;
238 WMAddNotificationObserver(appearanceObserver
, menu
,
239 WNMenuAppearanceSettingsChanged
, menu
);
241 WMAddNotificationObserver(appearanceObserver
, menu
,
242 WNMenuTitleAppearanceSettingsChanged
, menu
);
252 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
256 menu
= wMenuCreate(screen
, title
, main_menu
);
259 menu
->flags
.app_menu
= 1;
260 menu
->brother
->flags
.app_menu
= 1;
268 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
272 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
273 menu
->entries
[i
]->order
++;
274 menu
->entries
[i
+1] = menu
->entries
[i
];
276 menu
->entries
[index
] = entry
;
281 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
282 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
289 dprintf("Passed NULL as menu parameter to wMenuAddCallback() \n");
294 assert(menu
->flags
.brother
==0);
295 menu
->flags
.realized
= 0;
296 menu
->brother
->flags
.realized
= 0;
298 /* reallocate array if it's too small */
299 if (menu
->entry_no
>= menu
->alloced_entries
) {
302 dputs("doing wrealloc()");
304 tmp
= wrealloc(menu
->entries
,
305 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
307 wwarning(_("wrealloc() failed while trying to add menu item"));
312 menu
->alloced_entries
+= 5;
314 menu
->brother
->entries
= tmp
;
315 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
317 entry
= wmalloc(sizeof(WMenuEntry
));
318 memset(entry
, 0, sizeof(WMenuEntry
));
319 entry
->flags
.enabled
= 1;
320 entry
->text
= wstrdup(text
);
322 entry
->clientdata
= clientdata
;
323 entry
->callback
= callback
;
324 if (index
<0 || index
>=menu
->entry_no
) {
325 entry
->order
= menu
->entry_no
;
326 menu
->entries
[menu
->entry_no
] = entry
;
328 entry
->order
= index
;
329 insertEntry(menu
, entry
, index
);
333 menu
->brother
->entry_no
= menu
->entry_no
;
341 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
343 WMenu
*brother
= menu
->brother
;
346 assert(menu
->flags
.brother
==0);
348 if (entry
->cascade
>=0) {
349 menu
->flags
.realized
= 0;
350 brother
->flags
.realized
= 0;
353 cascade
->parent
= menu
;
355 cascade
->brother
->parent
= brother
;
358 for (i
=0; i
<menu
->cascade_no
; i
++) {
359 if (menu
->cascades
[i
]==NULL
) {
360 menu
->cascades
[i
] = cascade
;
361 brother
->cascades
[i
] = cascade
->brother
;
368 entry
->cascade
= menu
->cascade_no
;
370 menu
->cascades
= wrealloc(menu
->cascades
,
371 sizeof(WMenu
)*(menu
->cascade_no
+1));
372 menu
->cascades
[menu
->cascade_no
++] = cascade
;
375 brother
->cascades
= wrealloc(brother
->cascades
,
376 sizeof(WMenu
)*(brother
->cascade_no
+1));
377 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
381 if (menu
->flags
.lowered
) {
383 cascade
->flags
.lowered
= 1;
384 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
386 cascade
->brother
->flags
.lowered
= 1;
387 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
390 if (!menu
->flags
.realized
)
396 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
398 assert(menu
->flags
.brother
==0);
400 /* destroy cascade menu */
401 if (entry
->cascade
>=0 && menu
->cascades
402 && menu
->cascades
[entry
->cascade
]!=NULL
) {
404 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
406 menu
->cascades
[entry
->cascade
] = NULL
;
407 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
415 wMenuRemoveItem(WMenu
*menu
, int index
)
419 if (menu
->flags
.brother
) {
420 wMenuRemoveItem(menu
->brother
, index
);
424 if (index
>=menu
->entry_no
) return;
426 /* destroy cascade menu */
427 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
429 /* destroy unshared data */
431 if (menu
->entries
[index
]->text
)
432 free(menu
->entries
[index
]->text
);
434 if (menu
->entries
[index
]->rtext
)
435 free(menu
->entries
[index
]->rtext
);
437 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
438 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
440 free(menu
->entries
[index
]);
442 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
443 menu
->entries
[i
+1]->order
--;
444 menu
->entries
[i
]=menu
->entries
[i
+1];
447 menu
->brother
->entry_no
--;
452 renderTexture(WMenu
*menu
)
460 WScreen
*scr
= menu
->menu
->screen_ptr
;
461 WTexture
*texture
= scr
->menu_item_texture
;
463 if (wPreferences
.menu_style
== MS_NORMAL
) {
464 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
465 menu
->entry_height
, WREL_MENUENTRY
);
467 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
468 menu
->menu
->height
+1, WREL_MENUENTRY
);
471 wwarning(_("could not render texture: %s"),
472 RMessageForError(RErrorCode
));
477 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
479 light
.red
= light
.green
= light
.blue
= 80;
482 dark
.red
= dark
.green
= dark
.blue
= 0;
485 mid
.red
= mid
.green
= mid
.blue
= 40;
487 for (i
= 1; i
< menu
->entry_no
; i
++) {
488 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
489 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
491 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
492 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
494 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
495 menu
->menu
->width
-1, i
*menu
->entry_height
,
499 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
500 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
509 updateTexture(WMenu
*menu
)
511 WScreen
*scr
= menu
->menu
->screen_ptr
;
513 /* setup background texture */
514 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
515 if (!menu
->flags
.brother
) {
516 FREE_PIXMAP(menu
->menu_texture_data
);
518 menu
->menu_texture_data
= renderTexture(menu
);
520 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
521 menu
->menu_texture_data
);
522 XClearWindow(dpy
, menu
->menu
->window
);
524 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
525 menu
->menu_texture_data
);
526 XClearWindow(dpy
, menu
->brother
->menu
->window
);
529 XSetWindowBackground(dpy
, menu
->menu
->window
,
530 scr
->menu_item_texture
->any
.color
.pixel
);
531 XClearWindow(dpy
, menu
->menu
->window
);
537 wMenuRealize(WMenu
*menu
)
540 int width
, rwidth
, mrwidth
, mwidth
;
541 int theight
, twidth
, eheight
;
542 WScreen
*scr
= menu
->frame
->screen_ptr
;
543 static int brother_done
=0;
548 wMenuRealize(menu
->brother
);
552 flags
= WFF_SINGLE_STATE
;
553 if (menu
->flags
.titled
)
554 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
556 wFrameWindowUpdateBorders(menu
->frame
, flags
);
558 if (menu
->flags
.titled
) {
559 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
560 strlen(menu
->frame
->title
));
561 theight
= menu
->frame
->top_width
;
562 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
567 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6;
568 menu
->entry_height
= eheight
;
571 for (i
=0; i
<menu
->entry_no
; i
++) {
574 /* search widest text */
575 text
= menu
->entries
[i
]->text
;
576 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
578 if (menu
->entries
[i
]->flags
.indicator
) {
579 width
+= MENU_INDICATOR_SPACE
;
585 /* search widest text on right */
586 text
= menu
->entries
[i
]->rtext
;
588 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
590 else if (menu
->entries
[i
]->cascade
>=0)
595 if (rwidth
> mrwidth
)
604 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
606 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
607 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
612 menu
->flags
.realized
= 1;
614 if (menu
->flags
.mapped
)
616 if (menu
->brother
->flags
.mapped
)
617 wMenuPaint(menu
->brother
);
622 wMenuDestroy(WMenu
*menu
, int recurse
)
626 WMRemoveNotificationObserver(menu
);
628 /* remove any pending timers */
630 WMDeleteTimerHandler(menu
->timer
);
633 /* call destroy handler */
634 if (menu
->on_destroy
)
635 (*menu
->on_destroy
)(menu
);
637 /* Destroy items if this menu own them. If this is the "brother" menu,
638 * leave them alone as it is shared by them.
640 if (!menu
->flags
.brother
) {
641 for (i
=0; i
<menu
->entry_no
; i
++) {
643 free(menu
->entries
[i
]->text
);
645 if (menu
->entries
[i
]->rtext
)
646 free(menu
->entries
[i
]->rtext
);
649 if (menu
->entries
[i
]->instances
){
650 PLRelease(menu
->entries
[i
]->instances
);
652 #endif /* USER_MENU */
654 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
655 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
657 free(menu
->entries
[i
]);
661 for (i
=0; i
<menu
->cascade_no
; i
++) {
662 if (menu
->cascades
[i
]) {
663 if (menu
->cascades
[i
]->flags
.brother
)
664 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
666 wMenuDestroy(menu
->cascades
[i
], recurse
);
676 FREE_PIXMAP(menu
->menu_texture_data
);
679 free(menu
->cascades
);
681 wCoreDestroy(menu
->menu
);
682 wFrameWindowDestroy(menu
->frame
);
684 /* destroy copy of this menu */
685 if (!menu
->flags
.brother
&& menu
->brother
)
686 wMenuDestroy(menu
->brother
, False
);
698 drawFrame(WScreen
*scr
, Window win
, int y
, int w
, int h
, int type
)
704 segs
[i
].x1
= segs
[i
].x2
= w
-1;
706 segs
[i
].y2
= y
+ h
- 1;
708 if (type
!= F_TOP
&& type
!= F_NONE
) {
710 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
714 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
720 segs
[i
].y2
= y
+ h
- 1;
722 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
729 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
731 if (type
!= F_TOP
&& type
!= F_NONE
)
732 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
738 paintEntry(WMenu
*menu
, int index
, int selected
)
742 GC light
, dim
, dark
, textGC
;
743 WScreen
*scr
=menu
->frame
->screen_ptr
;
744 Window win
= menu
->menu
->window
;
745 WMenuEntry
*entry
=menu
->entries
[index
];
747 if (!menu
->flags
.realized
) return;
748 h
= menu
->entry_height
;
749 w
= menu
->menu
->width
;
752 light
= scr
->menu_item_auxtexture
->light_gc
;
753 dim
= scr
->menu_item_auxtexture
->dim_gc
;
754 dark
= scr
->menu_item_auxtexture
->dark_gc
;
756 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
759 else if (index
== menu
->entry_no
- 1)
767 /* paint background */
769 XSetForeground(dpy
, scr
->select_menu_gc
, scr
->select_pixel
);
770 XFillRectangle(dpy
, win
, scr
->select_menu_gc
, 1, y
+1, w
-2, h
-3);
771 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
772 drawFrame(scr
, win
, y
, w
, h
, type
);
774 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
775 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
777 drawFrame(scr
, win
, y
, w
, h
, type
);
779 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
784 textGC
= scr
->select_menu_gc
;
785 if (entry
->flags
.enabled
)
786 XSetForeground(dpy
, textGC
, scr
->select_text_pixel
);
788 XSetForeground(dpy
, textGC
, scr
->dtext_pixel
);
789 } else if (!entry
->flags
.enabled
) {
790 textGC
= scr
->disabled_menu_entry_gc
;
792 textGC
= scr
->menu_entry_gc
;
796 if (entry
->flags
.indicator
)
797 x
+= MENU_INDICATOR_SPACE
+ 2;
799 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
,
800 x
, 3 + y
, entry
->text
, strlen(entry
->text
));
802 if (entry
->cascade
>=0) {
803 /* draw the cascade indicator */
804 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
805 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
806 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
810 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
815 switch (entry
->flags
.indicator_type
) {
817 indicator
= scr
->menu_check_indicator
;
820 indicator
= scr
->menu_mini_indicator
;
823 indicator
= scr
->menu_hide_indicator
;
826 indicator
= scr
->menu_shade_indicator
;
830 indicator
= scr
->menu_radio_indicator
;
834 iw
= indicator
->width
;
835 ih
= indicator
->height
;
836 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
837 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
839 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
841 XSetForeground(dpy
, scr
->copy_gc
, scr
->mtext_pixel
);
842 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
844 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
845 iw, ih, 5, y+(h-ih)/2);
847 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
850 /* draw right text */
852 if (entry
->rtext
&& entry
->cascade
<0) {
853 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
854 strlen(entry
->rtext
));
856 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
, w
-6-tw
,
857 y
+ 3, entry
->rtext
, strlen(entry
->rtext
));
863 move_menus(WMenu
*menu
, int x
, int y
)
865 while (menu
->parent
) {
868 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
869 y
-= menu
->selected_entry
*menu
->entry_height
;
872 wMenuMove(menu
, x
, y
, True
);
876 makeVisible(WMenu
*menu
)
878 WScreen
*scr
= menu
->frame
->screen_ptr
;
879 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
881 if (menu
->entry_no
<0) return;
884 y1
= menu
->frame_y
+menu
->frame
->top_width
885 + menu
->selected_entry
*menu
->entry_height
;
886 x2
= x1
+ MENUW(menu
);
887 y2
= y1
+ menu
->entry_height
;
896 } else if (x2
>= scr
->scr_width
) {
897 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
904 } else if (y2
>= scr
->scr_height
) {
905 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
909 new_y
= new_y
- menu
->frame
->top_width
910 - menu
->selected_entry
*menu
->entry_height
;
911 move_menus(menu
, new_x
, new_y
);
916 check_key(WMenu
*menu
, XKeyEvent
*event
)
921 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
924 ch
= toupper(buffer
[0]);
926 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
929 for (i
=s
; i
<menu
->entry_no
; i
++) {
930 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
934 /* no match. Retry from start, if previous started from a selected entry */
944 keyboardMenu(WMenu
*menu
)
947 KeySym ksym
=NoSymbol
;
951 int old_pos_x
= menu
->frame_x
;
952 int old_pos_y
= menu
->frame_y
;
953 int new_x
= old_pos_x
, new_y
= old_pos_y
;
954 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
955 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
957 if (menu
->flags
.editing
)
961 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
962 GrabModeAsync
, CurrentTime
);
964 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
965 new_y
= scr_height
- menu
->frame
->top_width
;
967 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
968 new_x
= scr_width
-MENUW(menu
)-1;
970 move_menus(menu
, new_x
, new_y
);
972 while (!done
&& menu
->flags
.mapped
) {
973 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
974 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
975 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
976 |SubstructureNotifyMask
, &event
);
978 switch (event
.type
) {
980 ksym
= XLookupKeysym(&event
.xkey
, 0);
988 selectEntry(menu
, 0);
994 selectEntry(menu
, menu
->entry_no
-1);
1003 if (menu
->selected_entry
<= 0)
1004 selectEntry(menu
, menu
->entry_no
-1);
1006 selectEntry(menu
, menu
->selected_entry
-1);
1011 #ifdef ARROWLESS_KBD
1015 if (menu
->selected_entry
<0)
1016 selectEntry(menu
, 0);
1017 else if (menu
->selected_entry
== menu
->entry_no
-1)
1018 selectEntry(menu
, 0);
1019 else if (menu
->selected_entry
< menu
->entry_no
-1)
1020 selectEntry(menu
, menu
->selected_entry
+1);
1025 #ifdef ARROWLESS_KBD
1029 if (menu
->selected_entry
>=0) {
1031 entry
= menu
->entries
[menu
->selected_entry
];
1033 if (entry
->cascade
>= 0 && menu
->cascades
1034 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1036 XUngrabKeyboard(dpy
, CurrentTime
);
1038 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1039 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1042 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1043 GrabModeAsync
, GrabModeAsync
,
1050 #ifdef ARROWLESS_KBD
1054 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1055 selectEntry(menu
, -1);
1056 move_menus(menu
, old_pos_x
, old_pos_y
);
1066 index
= check_key(menu
, &event
.xkey
);
1068 selectEntry(menu
, index
);
1074 if (event
.type
==ButtonPress
)
1077 WMHandleEvent(&event
);
1081 XUngrabKeyboard(dpy
, CurrentTime
);
1083 if (done
==2 && menu
->selected_entry
>=0) {
1084 entry
= menu
->entries
[menu
->selected_entry
];
1089 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1090 && entry
->cascade
< 0) {
1091 #if (MENU_BLINK_COUNT > 0)
1092 int sel
= menu
->selected_entry
;
1095 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1096 paintEntry(menu
, sel
, False
);
1098 wusleep(MENU_BLINK_DELAY
);
1099 paintEntry(menu
, sel
, True
);
1101 wusleep(MENU_BLINK_DELAY
);
1104 selectEntry(menu
, -1);
1106 if (!menu
->flags
.buttoned
) {
1108 move_menus(menu
, old_pos_x
, old_pos_y
);
1112 (*entry
->callback
)(menu
, entry
);
1114 if (!menu
->flags
.buttoned
) {
1116 move_menus(menu
, old_pos_x
, old_pos_y
);
1118 selectEntry(menu
, -1);
1122 /* returns True if returning from a submenu to a parent menu,
1123 * False if exiting from menu */
1129 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1131 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1132 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1134 if (!menu
->flags
.realized
) {
1135 menu
->flags
.realized
=1;
1138 if (!menu
->flags
.mapped
) {
1139 if (wPreferences
.wrap_menus
) {
1142 if (x
+MENUW(menu
) > scr_width
)
1143 x
= scr_width
- MENUW(menu
);
1144 if (y
+MENUH(menu
) > scr_height
)
1145 y
= scr_height
- MENUH(menu
);
1148 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1151 XMapWindow(dpy
, menu
->frame
->core
->window
);
1152 wRaiseFrame(menu
->frame
->core
);
1153 menu
->flags
.mapped
= 1;
1155 selectEntry(menu
, 0);
1164 wMenuMap(WMenu
*menu
)
1166 if (!menu
->flags
.realized
) {
1167 menu
->flags
.realized
=1;
1170 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1171 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1172 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1173 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1175 XMapWindow(dpy
, menu
->frame
->core
->window
);
1176 wRaiseFrame(menu
->frame
->core
);
1177 menu
->flags
.mapped
= 1;
1182 wMenuUnmap(WMenu
*menu
)
1186 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1187 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1188 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1190 menu
->flags
.buttoned
= 0;
1191 menu
->flags
.mapped
= 0;
1192 menu
->flags
.open_to_left
= 0;
1194 for (i
=0; i
<menu
->cascade_no
; i
++) {
1195 if (menu
->cascades
[i
]!=NULL
1196 && menu
->cascades
[i
]->flags
.mapped
1197 && !menu
->cascades
[i
]->flags
.buttoned
) {
1199 wMenuUnmap(menu
->cascades
[i
]);
1202 menu
->selected_entry
= -1;
1208 wMenuPaint(WMenu
*menu
)
1212 if (!menu
->flags
.mapped
) {
1217 for (i
=0; i
<menu
->entry_no
; i
++) {
1218 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1224 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1226 if (index
>=menu
->entry_no
) return;
1227 menu
->entries
[index
]->flags
.enabled
=enable
;
1228 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1229 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1233 /* ====================================================================== */
1237 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1241 WObjDescriptor
*desc
;
1247 menu
->flags
.editing
= 1;
1249 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1250 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1252 wTextPutText(text
, entry
->text
);
1253 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1254 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1256 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1257 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1258 wwarning("could not grab keyboard");
1261 wSetFocusTo(menu
->frame
->screen_ptr
,
1262 menu
->frame
->screen_ptr
->focused_window
);
1267 while (!done
&& !text
->done
) {
1269 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1271 WMNextEvent(dpy
, &event
);
1273 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1274 (XPointer
*)&desc
)==XCNOENT
)
1277 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1279 (*desc
->handle_anything
)(desc
, &event
);
1282 switch (event
.type
) {
1284 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1288 WMHandleEvent(&event
);
1294 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1296 wSetFocusTo(menu
->frame
->screen_ptr
,
1297 menu
->frame
->screen_ptr
->focused_window
);
1300 t
= wTextGetText(text
);
1301 /* if !t, the user has canceled editing */
1305 entry
->text
= wstrdup(t
);
1307 menu
->flags
.realized
= 0;
1311 XUngrabKeyboard(dpy
, CurrentTime
);
1313 if (t
&& menu
->on_edit
)
1314 (*menu
->on_edit
)(menu
, entry
);
1316 menu
->flags
.editing
= 0;
1318 if (!menu
->flags
.realized
)
1324 selectEntry(WMenu
*menu
, int entry_no
)
1330 if (menu
->entries
==NULL
)
1333 if (entry_no
>= menu
->entry_no
)
1336 old_entry
= menu
->selected_entry
;
1337 menu
->selected_entry
= entry_no
;
1339 if (old_entry
!=entry_no
) {
1341 /* unselect previous entry */
1343 paintEntry(menu
, old_entry
, False
);
1344 entry
= menu
->entries
[old_entry
];
1347 if (entry
->cascade
>=0 && menu
->cascades
) {
1348 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1349 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1355 menu
->selected_entry
= -1;
1358 entry
= menu
->entries
[entry_no
];
1360 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1361 /* Callback for when the submenu is opened.
1363 submenu
= menu
->cascades
[entry
->cascade
];
1364 if (submenu
&& submenu
->flags
.brother
)
1365 submenu
= submenu
->brother
;
1367 if (entry
->callback
) {
1368 /* Only call the callback if the submenu is not yet mapped.
1370 if (menu
->flags
.brother
) {
1371 if (!submenu
|| !submenu
->flags
.mapped
)
1372 (*entry
->callback
)(menu
->brother
, entry
);
1374 if (!submenu
|| !submenu
->flags
.buttoned
)
1375 (*entry
->callback
)(menu
, entry
);
1379 /* the submenu menu might have changed */
1380 submenu
= menu
->cascades
[entry
->cascade
];
1383 if (!submenu
->flags
.mapped
) {
1386 if (!submenu
->flags
.realized
)
1387 wMenuRealize(submenu
);
1388 if (wPreferences
.wrap_menus
) {
1389 if (menu
->flags
.open_to_left
)
1390 submenu
->flags
.open_to_left
= 1;
1392 if (submenu
->flags
.open_to_left
) {
1393 x
= menu
->frame_x
- MENUW(submenu
);
1396 submenu
->flags
.open_to_left
= 0;
1399 x
= menu
->frame_x
+ MENUW(menu
);
1401 if (x
+ MENUW(submenu
)
1402 >= menu
->frame
->screen_ptr
->scr_width
) {
1404 x
= menu
->frame_x
- MENUW(submenu
);
1405 submenu
->flags
.open_to_left
= 1;
1409 x
= menu
->frame_x
+ MENUW(menu
);
1412 if (wPreferences
.align_menus
) {
1415 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1416 if (menu
->flags
.titled
)
1417 y
+= menu
->frame
->top_width
;
1418 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1419 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1422 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1423 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1428 paintEntry(menu
, entry_no
, True
);
1434 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1437 WObjDescriptor
*desc
;
1438 Window root_ret
, win
, junk_win
;
1442 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1445 if (win
==None
) return NULL
;
1447 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1450 if (desc
->parent_type
== WCLASS_MENU
) {
1451 menu
= (WMenu
*)desc
->parent
;
1452 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1453 x_ret
, y_ret
, &junk_win
);
1463 closeCascade(WMenu
*menu
)
1465 WMenu
*parent
=menu
->parent
;
1467 if (menu
->flags
.brother
1468 || (!menu
->flags
.buttoned
1469 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1471 selectEntry(menu
, -1);
1473 #if (MENU_BLINK_DELAY > 2)
1474 wusleep(MENU_BLINK_DELAY
/2);
1478 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1479 || parent
->flags
.brother
)
1480 && !parent
->flags
.buttoned
) {
1481 selectEntry(parent
, -1);
1483 parent
= parent
->parent
;
1486 selectEntry(parent
, -1);
1492 closeBrotherCascadesOf(WMenu
*menu
)
1497 for (i
=0; i
<menu
->cascade_no
; i
++) {
1498 if (menu
->cascades
[i
]->flags
.brother
) {
1499 tmp
= menu
->cascades
[i
];
1501 tmp
= menu
->cascades
[i
]->brother
;
1503 if (tmp
->flags
.mapped
) {
1504 selectEntry(tmp
->parent
, -1);
1505 closeBrotherCascadesOf(tmp
);
1512 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1516 parentMenu(WMenu
*menu
)
1521 if (menu
->flags
.buttoned
)
1524 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1525 parent
= menu
->parent
;
1526 if (parent
->selected_entry
< 0)
1528 entry
= parent
->entries
[parent
->selected_entry
];
1529 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1530 parent
->cascades
[entry
->cascade
] != menu
)
1533 if (menu
->flags
.buttoned
)
1543 * Will raise the passed menu, if submenu = 0
1544 * If submenu > 0 will also raise all mapped submenus
1545 * until the first buttoned one
1546 * If submenu < 0 will also raise all mapped parent menus
1547 * until the first buttoned one
1551 raiseMenus(WMenu
*menu
, int submenus
)
1558 wRaiseFrame(menu
->frame
->core
);
1560 if (submenus
>0 && menu
->selected_entry
>=0) {
1561 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1562 if (i
>=0 && menu
->cascades
) {
1563 submenu
= menu
->cascades
[i
];
1564 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1565 raiseMenus(submenu
, submenus
);
1568 if (submenus
<0 && !menu
->flags
.buttoned
&&
1569 menu
->parent
&& menu
->parent
->flags
.mapped
)
1570 raiseMenus(menu
->parent
, submenus
);
1575 wMenuUnderPointer(WScreen
*screen
)
1577 WObjDescriptor
*desc
;
1578 Window root_ret
, win
;
1582 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1583 &dummy
, &dummy
, &mask
);
1585 if (win
==None
) return NULL
;
1587 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1590 if (desc
->parent_type
== WCLASS_MENU
)
1591 return (WMenu
*)desc
->parent
;
1597 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
1601 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1603 Window root_ret
, win
;
1607 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1612 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1614 WScreen
*scr
= menu
->menu
->screen_ptr
;
1615 int menuX1
= menu
->frame_x
;
1616 int menuY1
= menu
->frame_y
;
1617 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1618 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1619 int screenW
= scr
->scr_width
;
1620 int screenH
= scr
->scr_height
;
1626 getPointerPosition(scr
, &xroot
, &yroot
);
1629 if (xroot
<= 1 && menuX1
< 0) {
1630 /* scroll to the right */
1631 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX1
));
1633 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1634 /* scroll to the left */
1635 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1640 *hamount
= -*hamount
;
1643 if (yroot
<= 1 && menuY1
< 0) {
1645 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY1
));
1647 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1649 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1651 *vamount
= -*vamount
;
1657 dragScrollMenuCallback(void *data
)
1659 WMenu
*menu
= (WMenu
*)data
;
1660 WScreen
*scr
= menu
->menu
->screen_ptr
;
1661 WMenu
*parent
= parentMenu(menu
);
1662 int hamount
, vamount
;
1664 int newSelectedEntry
;
1666 getScrollAmount(menu
, &hamount
, &vamount
);
1669 if (hamount
!= 0 || vamount
!= 0) {
1670 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1671 parent
->frame_y
+ vamount
, True
);
1672 if (findMenu(scr
, &x
, &y
)) {
1673 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1674 selectEntry(menu
, newSelectedEntry
);
1676 /* Pointer fell outside of menu. If the selected entry is
1677 * not a submenu, unselect it */
1678 if (menu
->selected_entry
>= 0
1679 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1680 selectEntry(menu
, -1);
1681 newSelectedEntry
= 0;
1684 /* paranoid check */
1685 if (newSelectedEntry
>= 0) {
1686 /* keep scrolling */
1687 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1688 dragScrollMenuCallback
, menu
);
1693 /* don't need to scroll anymore */
1695 if (findMenu(scr
, &x
, &y
)) {
1696 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1697 selectEntry(menu
, newSelectedEntry
);
1704 scrollMenuCallback(void *data
)
1706 WMenu
*menu
= (WMenu
*)data
;
1707 WMenu
*parent
= parentMenu(menu
);
1708 int hamount
= 0; /* amount to scroll */
1711 getScrollAmount(menu
, &hamount
, &vamount
);
1713 if (hamount
!= 0 || vamount
!= 0) {
1714 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1715 parent
->frame_y
+ vamount
, True
);
1717 /* keep scrolling */
1718 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1719 scrollMenuCallback
, menu
);
1721 /* don't need to scroll anymore */
1728 #define MENU_SCROLL_BORDER 5
1731 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1733 int menuX1
= menu
->frame_x
;
1734 int menuY1
= menu
->frame_y
;
1735 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1736 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1737 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1738 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1741 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1742 || y
> scrYe
-MENU_SCROLL_BORDER
))
1744 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1745 || x
> scrXe
-MENU_SCROLL_BORDER
))
1752 typedef struct _delay
{
1760 _leaving(_delay
*dl
)
1762 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1763 dl
->menu
->jump_back
=NULL
;
1764 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1770 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1773 WMenu
*omenu
= parentMenu(menu
);
1774 WScreen
*scr
= menu
->frame
->screen_ptr
;
1777 int old_frame_x
= omenu
->frame_x
;
1778 int old_frame_y
= omenu
->frame_y
;
1782 dputs("Entering menu Scroll");
1785 if (omenu
->jump_back
)
1786 WMDeleteTimerWithClientData(omenu
->jump_back
);
1789 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1790 || omenu
->flags
.app_menu
) {
1794 if (!wPreferences
.wrap_menus
)
1795 raiseMenus(omenu
, True
);
1797 raiseMenus(menu
, False
);
1800 scrollMenuCallback(menu
);
1803 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1805 WMNextEvent(dpy
, &ev
);
1809 this um causes a nasty crash ugly ugh i dont see *why* we do this,
1810 everything seems fine without it. ( swivel )
1815 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1816 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1818 /* on_border is != 0 if the pointer is between the menu
1819 * and the screen border and is close enough to the border */
1820 on_border
= isPointNearBoder(menu
, x
, y
);
1822 smenu
= wMenuUnderPointer(scr
);
1824 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1829 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1830 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1831 on_border
= on_x_edge
|| on_y_edge
;
1833 if (!on_border
&& !jump_back
) {
1838 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1839 WMDeleteTimerHandler(menu
->timer
);
1847 scrollMenuCallback(menu
);
1850 /* True if we push on title, or drag the omenu to other position */
1851 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1852 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1853 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1854 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1856 smenu
= wMenuUnderPointer(scr
);
1857 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1859 else if (smenu
==omenu
&& on_title
) {
1873 WMDeleteTimerHandler(menu
->timer
);
1879 if (!omenu
->jump_back
) {
1880 delayer
=wmalloc(sizeof(_delay
));
1881 delayer
->menu
=omenu
;
1882 delayer
->ox
=old_frame_x
;
1883 delayer
->oy
=old_frame_y
;
1884 omenu
->jump_back
=delayer
;
1885 scr
->flags
.jump_back_pending
= 1;
1887 else delayer
= omenu
->jump_back
;
1888 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1893 dputs("Leaving menu Scroll");
1900 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1902 wMenuPaint(desc
->parent
);
1906 int *delayed_select
;
1913 delaySelection(void *data
)
1915 delay_data
*d
= (delay_data
*)data
;
1921 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1922 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1923 entry_no
= getEntryAt(menu
, x
, y
);
1924 selectEntry(menu
, entry_no
);
1926 if (d
->delayed_select
)
1927 *(d
->delayed_select
) = 0;
1932 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1934 XButtonEvent
*bev
= &event
->xbutton
;
1935 WMenu
*menu
= desc
->parent
;
1937 WScreen
*scr
=menu
->frame
->screen_ptr
;
1938 WMenuEntry
*entry
=NULL
;
1940 int close_on_exit
=0;
1942 int delayed_select
= 0;
1946 int old_frame_x
= 0;
1947 int old_frame_y
= 0;
1948 delay_data d_data
= {NULL
, NULL
, NULL
};
1950 if (!wPreferences
.wrap_menus
) {
1951 smenu
= parentMenu(menu
);
1952 old_frame_x
= smenu
->frame_x
;
1953 old_frame_y
= smenu
->frame_y
;
1954 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1955 /* This is true if the menu was launched with right click on root window */
1957 d_data
.delayed_select
= &delayed_select
;
1959 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1960 delaySelection
, &d_data
);
1963 wRaiseFrame(menu
->frame
->core
);
1965 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1967 smenu
= findMenu(scr
, &x
, &y
);
1975 if (menu
->flags
.editing
) {
1978 entry_no
= getEntryAt(menu
, x
, y
);
1980 entry
= menu
->entries
[entry_no
];
1982 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1983 && entry
->flags
.editable
) {
1984 editEntry(smenu
, entry
);
1986 } else if (bev
->state
& ControlMask
) {
1990 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1991 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1993 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1994 menu
->selected_entry
!=entry_no
) {
1995 wMenuUnmap(submenu
);
1997 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1998 selectEntry(menu
, entry_no
);
1999 } else if (!submenu
->flags
.buttoned
) {
2000 selectEntry(menu
, -1);
2003 } else if (!delayed_select
) {
2004 selectEntry(menu
, entry_no
);
2007 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2009 dragScrollMenuCallback(menu
);
2013 prevx
= bev
->x_root
;
2014 prevy
= bev
->y_root
;
2018 XAllowEvents(dpy
, SyncPointer
, CurrentTime
);
2020 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2021 |ButtonPressMask
, &ev
);
2024 smenu
= findMenu(scr
, &x
, &y
);
2026 if (smenu
== NULL
) {
2027 /* moved mouse out of menu */
2029 if (!delayed_select
&& d_data
.magic
) {
2030 WMDeleteTimerHandler(d_data
.magic
);
2031 d_data
.magic
= NULL
;
2034 || (menu
->selected_entry
>=0
2035 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2036 prevx
= ev
.xmotion
.x_root
;
2037 prevy
= ev
.xmotion
.y_root
;
2041 selectEntry(menu
, -1);
2043 prevx
= ev
.xmotion
.x_root
;
2044 prevy
= ev
.xmotion
.y_root
;
2046 } else if (menu
&& menu
!=smenu
2047 && (menu
->selected_entry
<0
2048 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2049 selectEntry(menu
, -1);
2051 if (!delayed_select
&& d_data
.magic
) {
2052 WMDeleteTimerHandler(d_data
.magic
);
2053 d_data
.magic
= NULL
;
2057 /* hysteresis for item selection */
2059 /* check if the motion was to the side, indicating that
2060 * the user may want to cross to a submenu */
2061 if (!delayed_select
&& menu
) {
2063 Bool moved_to_submenu
;/* moved to direction of submenu */
2065 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2067 moved_to_submenu
= False
;
2068 if (dx
> 0 /* if moved enough to the side */
2069 /* maybe a open submenu */
2070 && menu
->selected_entry
>=0
2071 /* moving to the right direction */
2072 && (wPreferences
.align_menus
2073 || ev
.xmotion
.y_root
>= prevy
)) {
2076 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2078 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2079 if (prevx
< ev
.xmotion
.x_root
)
2080 moved_to_submenu
= True
;
2082 if (prevx
> ev
.xmotion
.x_root
)
2083 moved_to_submenu
= True
;
2089 if (menu
!= smenu
) {
2091 WMDeleteTimerHandler(d_data
.magic
);
2093 d_data
.magic
= NULL
;
2094 } else if (moved_to_submenu
) {
2095 /* while we are moving, postpone the selection */
2097 WMDeleteTimerHandler(d_data
.magic
);
2099 d_data
.delayed_select
= NULL
;
2101 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2104 prevx
= ev
.xmotion
.x_root
;
2105 prevy
= ev
.xmotion
.y_root
;
2109 WMDeleteTimerHandler(d_data
.magic
);
2110 d_data
.magic
= NULL
;
2114 prevx
= ev
.xmotion
.x_root
;
2115 prevy
= ev
.xmotion
.y_root
;
2117 /* pointer crossed menus */
2118 if (menu
&& menu
->timer
) {
2119 WMDeleteTimerHandler(menu
->timer
);
2123 dragScrollMenuCallback(smenu
);
2127 dragScrollMenuCallback(menu
);
2129 if (!delayed_select
) {
2130 entry_no
= getEntryAt(menu
, x
, y
);
2132 entry
= menu
->entries
[entry_no
];
2133 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2135 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2136 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2137 && menu
->selected_entry
!=entry_no
) {
2138 wMenuUnmap(submenu
);
2142 selectEntry(menu
, entry_no
);
2150 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2160 if (menu
&& menu
->timer
) {
2161 WMDeleteTimerHandler(menu
->timer
);
2164 if (d_data
.magic
!=NULL
)
2165 WMDeleteTimerHandler(d_data
.magic
);
2167 if (menu
&& menu
->selected_entry
>=0) {
2168 entry
= menu
->entries
[menu
->selected_entry
];
2169 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2170 && entry
->cascade
< 0) {
2171 /* blink and erase menu selection */
2172 #if (MENU_BLINK_DELAY > 0)
2173 int sel
= menu
->selected_entry
;
2176 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2177 paintEntry(menu
, sel
, False
);
2179 wusleep(MENU_BLINK_DELAY
);
2180 paintEntry(menu
, sel
, True
);
2182 wusleep(MENU_BLINK_DELAY
);
2185 /* unmap the menu, it's parents and call the callback */
2186 if (!menu
->flags
.buttoned
&&
2187 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2190 selectEntry(menu
, -1);
2192 (*entry
->callback
)(menu
, entry
);
2194 /* If the user double clicks an entry, the entry will
2195 * be executed twice, which is not good for things like
2196 * the root menu. So, ignore any clicks that were generated
2197 * while the entry was being executed */
2198 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2200 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2201 selectEntry(menu
, -1);
2203 if (entry
->cascade
>=0 && menu
->cascades
2204 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2205 selectEntry(menu
, -1);
2210 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2211 closeCascade(desc
->parent
);
2213 /* close the cascade windows that should not remain opened */
2214 closeBrotherCascadesOf(desc
->parent
);
2216 if (!wPreferences
.wrap_menus
)
2217 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2222 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2231 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2233 if (submenus
>0 && menu
->selected_entry
>=0) {
2234 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2236 if (i
>=0 && menu
->cascades
) {
2237 submenu
= menu
->cascades
[i
];
2238 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2239 if (wPreferences
.align_menus
) {
2240 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2242 wMenuMove(submenu
, x
+ MENUW(menu
),
2243 y
+ submenu
->entry_height
*menu
->selected_entry
,
2249 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2250 !menu
->parent
->flags
.buttoned
) {
2251 if (wPreferences
.align_menus
) {
2252 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2254 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2255 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2263 changeMenuLevels(WMenu
*menu
, int lower
)
2268 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2270 wRaiseFrame(menu
->frame
->core
);
2271 menu
->flags
.lowered
= 0;
2273 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2274 wLowerFrame(menu
->frame
->core
);
2275 menu
->flags
.lowered
= 1;
2277 for (i
=0; i
<menu
->cascade_no
; i
++) {
2278 if (menu
->cascades
[i
]
2279 && !menu
->cascades
[i
]->flags
.buttoned
2280 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2281 changeMenuLevels(menu
->cascades
[i
], lower
);
2289 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2294 if (event
->xbutton
.state
& MOD_MASK
) {
2295 if (menu
->flags
.lowered
) {
2300 changeMenuLevels(menu
, lower
);
2306 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2311 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2312 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2317 dprintf("Moving menu\n");
2320 /* can't touch the menu copy */
2321 if (menu
->flags
.brother
)
2324 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2327 if (event
->xbutton
.state
& MOD_MASK
) {
2328 wLowerFrame(menu
->frame
->core
);
2331 wRaiseFrame(menu
->frame
->core
);
2336 /* lower/raise all submenus */
2338 if (tmp
->selected_entry
>=0 && tmp
->cascades
2339 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2340 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2341 if (!tmp
|| !tmp
->flags
.mapped
)
2344 wLowerFrame(tmp
->frame
->core
);
2346 wRaiseFrame(tmp
->frame
->core
);
2352 /* tear off the menu if it's a root menu or a cascade
2354 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2355 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2356 menu
->flags
.buttoned
=1;
2357 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2359 /* turn off selected menu entry in parent menu */
2360 selectEntry(menu
->parent
, -1);
2362 /* make parent map the copy in place of the original */
2363 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2364 if (menu
->parent
->cascades
[i
] == menu
) {
2365 menu
->parent
->cascades
[i
] = menu
->brother
;
2374 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2375 |ExposureMask
, &ev
);
2379 x
+= ev
.xmotion
.x_root
- dx
;
2380 y
+= ev
.xmotion
.y_root
- dy
;
2381 dx
= ev
.xmotion
.x_root
;
2382 dy
= ev
.xmotion
.y_root
;
2383 wMenuMove(menu
, x
, y
, True
);
2385 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2386 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2388 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2389 ButtonMotionMask
|ButtonReleaseMask
2391 GrabModeAsync
, GrabModeAsync
, None
,
2392 wCursor
[WCUR_MOVE
], CurrentTime
);
2401 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2404 dprintf("End menu move\n");
2406 XUngrabPointer(dpy
, CurrentTime
);
2417 *----------------------------------------------------------------------
2419 * Handles mouse click on the close button of menus. The menu is
2420 * closed when the button is clicked.
2423 * The closed menu is reinserted at it's parent menus
2425 *----------------------------------------------------------------------
2428 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2430 WMenu
*menu
= (WMenu
*)data
;
2431 WMenu
*parent
= menu
->parent
;
2435 for (i
=0; i
<parent
->cascade_no
; i
++) {
2436 /* find the entry that points to the copy */
2437 if (parent
->cascades
[i
] == menu
->brother
) {
2438 /* make it point to the original */
2439 parent
->cascades
[i
] = menu
;
2440 menu
->parent
= parent
;
2450 wMenuSaveState(WScreen
*scr
)
2452 proplist_t menus
, key
, value
;
2457 menus
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
2460 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2461 sprintf(buffer
, "%i,%i", scr
->switch_menu
->frame_x
,
2462 scr
->switch_menu
->frame_y
);
2463 key
= PLMakeString("SwitchMenu");
2464 value
= PLMakeString(buffer
);
2465 PLInsertDictionaryEntry(menus
, key
, value
);
2471 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2475 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2476 sprintf(buffer
, "%i,%i", scr
->workspace_menu
->frame_x
,
2477 scr
->workspace_menu
->frame_y
);
2478 key
= PLMakeString("WorkspaceMenu");
2479 value
= PLMakeString(buffer
);
2480 PLInsertDictionaryEntry(menus
, key
, value
);
2487 key
= PLMakeString("Menus");
2488 PLInsertDictionaryEntry(scr
->session_state
, key
, menus
);
2498 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2503 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2506 len
= strlen(menu
->frame
->title
);
2511 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2516 strcat(buffer
, "\\");
2517 strcat(buffer
, menu
->frame
->title
);
2523 saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
)
2525 proplist_t key
, value
;
2526 int save_menus
= 0, i
;
2531 if (menu
->flags
.brother
)
2532 menu
= menu
->brother
;
2534 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2536 sprintf(buffer
, "%i,%i", menu
->frame_x
, menu
->frame_y
);
2537 value
= PLMakeString(buffer
);
2540 ok
= getMenuPath(menu
, buffer
, 510);
2543 key
= PLMakeString(buffer
);
2544 PLInsertDictionaryEntry(menus
, key
, value
);
2552 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2553 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2562 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2566 restoreMenu(WScreen
*scr
, proplist_t menu
, int which
)
2569 WMenu
*pmenu
= NULL
;
2574 if (!PLIsString(menu
)) {
2575 COMPLAIN("Position");
2579 if (sscanf(PLGetString(menu
), "%i,%i", &x
, &y
)!=2)
2580 COMPLAIN("Position");
2583 if (which
& WSS_SWITCHMENU
) {
2584 OpenSwitchMenu(scr
, x
, y
, False
);
2585 pmenu
= scr
->switch_menu
;
2590 int width
= MENUW(pmenu
);
2591 int height
= MENUH(pmenu
);
2593 x
= (x
< -width
) ? 0 : x
;
2594 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2595 y
= (y
< 0) ? 0 : y
;
2596 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2597 wMenuMove(pmenu
, x
, y
, True
);
2598 pmenu
->flags
.buttoned
= 1;
2599 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2608 restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
)
2610 proplist_t key
, entry
;
2614 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2617 sprintf(buffer
, "%s\\%s", path
, menu
->frame
->title
);
2618 key
= PLMakeString(buffer
);
2619 entry
= PLGetDictionaryEntry(menus
, key
);
2622 if (entry
&& PLIsString(entry
)) {
2624 if (sscanf(PLGetString(entry
), "%i,%i", &x
, &y
) != 2)
2625 COMPLAIN("Position");
2627 if (!menu
->flags
.mapped
) {
2628 int width
= MENUW(menu
);
2629 int height
= MENUH(menu
);
2631 wMenuMapAt(menu
, x
, y
, False
);
2634 /* make parent map the copy in place of the original */
2635 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2636 if (menu
->parent
->cascades
[i
] == menu
) {
2637 menu
->parent
->cascades
[i
] = menu
->brother
;
2642 x
= (x
< -width
) ? 0 : x
;
2643 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2644 y
= (y
< 0) ? 0 : y
;
2645 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2646 wMenuMove(menu
, x
, y
, True
);
2647 menu
->flags
.buttoned
= 1;
2648 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2655 for (i
=0; i
<menu
->cascade_no
; i
++) {
2656 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2666 wMenuRestoreState(WScreen
*scr
)
2668 proplist_t menus
, menu
, key
, skey
;
2670 key
= PLMakeString("Menus");
2671 menus
= PLGetDictionaryEntry(scr
->session_state
, key
);
2679 skey
= PLMakeString("SwitchMenu");
2680 menu
= PLGetDictionaryEntry(menus
, skey
);
2681 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2684 if (!scr
->root_menu
) {
2685 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2686 wMenuUnmap(scr
->root_menu
);
2688 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2696 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2698 WMenu
*menu
, *parent
;
2702 if (!scr
->root_menu
) {
2703 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2704 wMenuUnmap(scr
->root_menu
);
2707 menu
= scr
->workspace_menu
;
2709 if (menu
->flags
.mapped
) {
2710 if (!menu
->flags
.buttoned
) {
2712 parent
= menu
->parent
;
2713 if (parent
&& parent
->selected_entry
>= 0) {
2714 entry
= parent
->entries
[parent
->selected_entry
];
2715 if (parent
->cascades
[entry
->cascade
] == menu
) {
2716 selectEntry(parent
, -1);
2717 wMenuMapAt(menu
, x
, y
, False
);
2721 wRaiseFrame(menu
->frame
->core
);
2722 wMenuMapCopyAt(menu
, x
, y
);
2725 wMenuMapAt(menu
, x
, y
, False
);