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>
37 #include "WindowMaker.h"
47 /****** Global Variables ******/
49 extern Cursor wCursor
[WCUR_LAST
];
51 extern XContext wWinContext
;
53 extern WPreferences wPreferences
;
55 #define MOD_MASK wPreferences.modifier_mask
57 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
58 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
62 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
63 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
66 /***** Local Stuff ******/
71 } menuScrollParameters
[5] = {
72 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
73 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
74 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
75 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
76 {MENU_SCROLL_STEPS_U
, MENU_SCROLL_DELAY_U
}};
79 static void menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
80 static void menuExpose(WObjDescriptor
*desc
, XEvent
*event
);
82 static void menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
83 static void menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
85 static void menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
87 static void updateTexture(WMenu
*menu
);
90 static int saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
);
91 static int restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
);
94 static void selectEntry(WMenu
*menu
, int entry_no
);
95 static void closeCascade(WMenu
*menu
);
98 /****** Notification Observers ******/
101 appearanceObserver(void *self
, WMNotification
*notif
)
103 WMenu
*menu
= (WMenu
*)self
;
104 int flags
= (int)WMGetNotificationClientData(notif
);
106 if (!menu
->flags
.realized
)
109 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
110 if (flags
& WFontSettings
) {
111 menu
->flags
.realized
= 0;
114 if (flags
& WTextureSettings
) {
115 if (!menu
->flags
.brother
)
118 if (flags
& (WTextureSettings
|WColorSettings
)) {
121 } else if (menu
->flags
.titled
) {
123 if (flags
& WFontSettings
) {
124 menu
->flags
.realized
= 0;
127 if (flags
& WTextureSettings
) {
128 menu
->frame
->flags
.need_texture_remake
= 1;
130 if (flags
& (WColorSettings
|WTextureSettings
)) {
131 wFrameWindowPaint(menu
->frame
);
136 /************************************/
140 *----------------------------------------------------------------------
142 * Creates a new empty menu with the specified title. If main_menu
143 * is True, the created menu will be a main menu, which has some special
144 * properties such as being placed over other normal menus.
145 * If title is NULL, the menu will have no titlebar.
149 *----------------------------------------------------------------------
152 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
155 static int brother
=0;
158 menu
= wmalloc(sizeof(WMenu
));
160 memset(menu
, 0, sizeof(WMenu
));
162 #ifdef SINGLE_MENULEVEL
163 tmp
= WMSubmenuLevel
;
165 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
168 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
170 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
171 menu
->flags
.titled
= 1;
174 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
175 screen
->menu_title_texture
, NULL
,
176 screen
->menu_title_pixel
,
177 &screen
->menu_title_gc
,
178 &screen
->menu_title_font
);
180 menu
->frame
->core
->descriptor
.parent
= menu
;
181 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
182 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
184 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
187 menu
->frame
->title
= wstrdup(title
);
190 menu
->frame
->flags
.justification
= WTJ_LEFT
;
192 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
195 menu
->alloced_entries
= 0;
196 menu
->selected_entry
= -1;
197 menu
->entries
= NULL
;
199 menu
->frame_x
= screen
->app_menu_x
;
200 menu
->frame_y
= screen
->app_menu_y
;
202 menu
->frame
->child
= menu
;
204 menu
->flags
.lowered
= 0;
208 /* setup object descriptors */
209 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
210 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
213 menu
->frame
->on_click_right
= menuCloseClick
;
216 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
217 menu
->frame
->core
->width
, 10);
219 menu
->menu
->descriptor
.parent
= menu
;
220 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
221 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
222 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
224 menu
->menu_texture_data
= None
;
226 XMapWindow(dpy
, menu
->menu
->window
);
232 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
234 menu
->brother
->flags
.brother
= 1;
235 menu
->brother
->brother
= menu
;
237 WMAddNotificationObserver(appearanceObserver
, menu
,
238 WNMenuAppearanceSettingsChanged
, menu
);
240 WMAddNotificationObserver(appearanceObserver
, menu
,
241 WNMenuTitleAppearanceSettingsChanged
, menu
);
251 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
255 menu
= wMenuCreate(screen
, title
, main_menu
);
258 menu
->flags
.app_menu
= 1;
259 menu
->brother
->flags
.app_menu
= 1;
267 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
271 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
272 menu
->entries
[i
]->order
++;
273 menu
->entries
[i
+1] = menu
->entries
[i
];
275 menu
->entries
[index
] = entry
;
280 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
281 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
286 menu
->flags
.realized
= 0;
287 menu
->brother
->flags
.realized
= 0;
289 /* reallocate array if it's too small */
290 if (menu
->entry_no
>= menu
->alloced_entries
) {
293 tmp
= wrealloc(menu
->entries
,
294 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
297 menu
->alloced_entries
+= 5;
299 menu
->brother
->entries
= tmp
;
300 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
302 entry
= wmalloc(sizeof(WMenuEntry
));
303 memset(entry
, 0, sizeof(WMenuEntry
));
304 entry
->flags
.enabled
= 1;
305 entry
->text
= wstrdup(text
);
307 entry
->clientdata
= clientdata
;
308 entry
->callback
= callback
;
309 if (index
<0 || index
>=menu
->entry_no
) {
310 entry
->order
= menu
->entry_no
;
311 menu
->entries
[menu
->entry_no
] = entry
;
313 entry
->order
= index
;
314 insertEntry(menu
, entry
, index
);
318 menu
->brother
->entry_no
= menu
->entry_no
;
326 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
328 WMenu
*brother
= menu
->brother
;
331 assert(menu
->flags
.brother
==0);
333 if (entry
->cascade
>=0) {
334 menu
->flags
.realized
= 0;
335 brother
->flags
.realized
= 0;
338 cascade
->parent
= menu
;
340 cascade
->brother
->parent
= brother
;
343 for (i
=0; i
<menu
->cascade_no
; i
++) {
344 if (menu
->cascades
[i
]==NULL
) {
345 menu
->cascades
[i
] = cascade
;
346 brother
->cascades
[i
] = cascade
->brother
;
353 entry
->cascade
= menu
->cascade_no
;
355 menu
->cascades
= wrealloc(menu
->cascades
,
356 sizeof(WMenu
)*(menu
->cascade_no
+1));
357 menu
->cascades
[menu
->cascade_no
++] = cascade
;
360 brother
->cascades
= wrealloc(brother
->cascades
,
361 sizeof(WMenu
)*(brother
->cascade_no
+1));
362 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
366 if (menu
->flags
.lowered
) {
368 cascade
->flags
.lowered
= 1;
369 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
371 cascade
->brother
->flags
.lowered
= 1;
372 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
375 if (!menu
->flags
.realized
)
381 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
383 assert(menu
->flags
.brother
==0);
385 /* destroy cascade menu */
386 if (entry
->cascade
>=0 && menu
->cascades
387 && menu
->cascades
[entry
->cascade
]!=NULL
) {
389 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
391 menu
->cascades
[entry
->cascade
] = NULL
;
392 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
400 wMenuRemoveItem(WMenu
*menu
, int index
)
404 if (menu
->flags
.brother
) {
405 wMenuRemoveItem(menu
->brother
, index
);
409 if (index
>=menu
->entry_no
) return;
411 /* destroy cascade menu */
412 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
414 /* destroy unshared data */
416 if (menu
->entries
[index
]->text
)
417 wfree(menu
->entries
[index
]->text
);
419 if (menu
->entries
[index
]->rtext
)
420 wfree(menu
->entries
[index
]->rtext
);
422 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
423 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
425 wfree(menu
->entries
[index
]);
427 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
428 menu
->entries
[i
+1]->order
--;
429 menu
->entries
[i
]=menu
->entries
[i
+1];
432 menu
->brother
->entry_no
--;
437 renderTexture(WMenu
*menu
)
445 WScreen
*scr
= menu
->menu
->screen_ptr
;
446 WTexture
*texture
= scr
->menu_item_texture
;
448 if (wPreferences
.menu_style
== MS_NORMAL
) {
449 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
450 menu
->entry_height
, WREL_MENUENTRY
);
452 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
453 menu
->menu
->height
+1, WREL_MENUENTRY
);
456 wwarning(_("could not render texture: %s"),
457 RMessageForError(RErrorCode
));
462 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
464 light
.red
= light
.green
= light
.blue
= 80;
467 dark
.red
= dark
.green
= dark
.blue
= 0;
470 mid
.red
= mid
.green
= mid
.blue
= 40;
472 for (i
= 1; i
< menu
->entry_no
; i
++) {
473 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
474 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
476 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
477 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
479 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
480 menu
->menu
->width
-1, i
*menu
->entry_height
,
484 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
485 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
494 updateTexture(WMenu
*menu
)
496 WScreen
*scr
= menu
->menu
->screen_ptr
;
498 /* setup background texture */
499 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
500 if (!menu
->flags
.brother
) {
501 FREE_PIXMAP(menu
->menu_texture_data
);
503 menu
->menu_texture_data
= renderTexture(menu
);
505 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
506 menu
->menu_texture_data
);
507 XClearWindow(dpy
, menu
->menu
->window
);
509 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
510 menu
->menu_texture_data
);
511 XClearWindow(dpy
, menu
->brother
->menu
->window
);
514 XSetWindowBackground(dpy
, menu
->menu
->window
,
515 scr
->menu_item_texture
->any
.color
.pixel
);
516 XClearWindow(dpy
, menu
->menu
->window
);
522 wMenuRealize(WMenu
*menu
)
525 int width
, rwidth
, mrwidth
, mwidth
;
526 int theight
, twidth
, eheight
;
527 WScreen
*scr
= menu
->frame
->screen_ptr
;
528 static int brother_done
=0;
533 wMenuRealize(menu
->brother
);
537 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
538 if (menu
->flags
.titled
)
539 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
541 wFrameWindowUpdateBorders(menu
->frame
, flags
);
543 if (menu
->flags
.titled
) {
544 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
545 strlen(menu
->frame
->title
));
546 theight
= menu
->frame
->top_width
;
547 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
552 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
553 menu
->entry_height
= eheight
;
556 for (i
=0; i
<menu
->entry_no
; i
++) {
559 /* search widest text */
560 text
= menu
->entries
[i
]->text
;
561 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
563 if (menu
->entries
[i
]->flags
.indicator
) {
564 width
+= MENU_INDICATOR_SPACE
;
570 /* search widest text on right */
571 text
= menu
->entries
[i
]->rtext
;
573 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
575 else if (menu
->entries
[i
]->cascade
>=0)
580 if (rwidth
> mrwidth
)
589 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
591 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
592 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
597 menu
->flags
.realized
= 1;
599 if (menu
->flags
.mapped
)
601 if (menu
->brother
->flags
.mapped
)
602 wMenuPaint(menu
->brother
);
607 wMenuDestroy(WMenu
*menu
, int recurse
)
611 WMRemoveNotificationObserver(menu
);
613 /* remove any pending timers */
615 WMDeleteTimerHandler(menu
->timer
);
618 /* call destroy handler */
619 if (menu
->on_destroy
)
620 (*menu
->on_destroy
)(menu
);
622 /* Destroy items if this menu own them. If this is the "brother" menu,
623 * leave them alone as it is shared by them.
625 if (!menu
->flags
.brother
) {
626 for (i
=0; i
<menu
->entry_no
; i
++) {
628 wfree(menu
->entries
[i
]->text
);
630 if (menu
->entries
[i
]->rtext
)
631 wfree(menu
->entries
[i
]->rtext
);
634 if (menu
->entries
[i
]->instances
){
635 PLRelease(menu
->entries
[i
]->instances
);
637 #endif /* USER_MENU */
639 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
640 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
642 wfree(menu
->entries
[i
]);
646 for (i
=0; i
<menu
->cascade_no
; i
++) {
647 if (menu
->cascades
[i
]) {
648 if (menu
->cascades
[i
]->flags
.brother
)
649 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
651 wMenuDestroy(menu
->cascades
[i
], recurse
);
657 wfree(menu
->entries
);
661 FREE_PIXMAP(menu
->menu_texture_data
);
664 wfree(menu
->cascades
);
666 wCoreDestroy(menu
->menu
);
667 wFrameWindowDestroy(menu
->frame
);
669 /* destroy copy of this menu */
670 if (!menu
->flags
.brother
&& menu
->brother
)
671 wMenuDestroy(menu
->brother
, False
);
683 drawFrame(WScreen
*scr
, Drawable win
, int y
, int w
, int h
, int type
)
689 segs
[i
].x1
= segs
[i
].x2
= w
-1;
691 segs
[i
].y2
= y
+ h
- 1;
693 if (type
!= F_TOP
&& type
!= F_NONE
) {
695 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
699 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
705 segs
[i
].y2
= y
+ h
- 1;
707 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
714 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
716 if (type
!= F_TOP
&& type
!= F_NONE
)
717 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
723 paintEntry(WMenu
*menu
, int index
, int selected
)
727 GC light
, dim
, dark
, textGC
;
728 WScreen
*scr
=menu
->frame
->screen_ptr
;
729 Window win
= menu
->menu
->window
;
730 WMenuEntry
*entry
=menu
->entries
[index
];
732 if (!menu
->flags
.realized
) return;
733 h
= menu
->entry_height
;
734 w
= menu
->menu
->width
;
737 light
= scr
->menu_item_auxtexture
->light_gc
;
738 dim
= scr
->menu_item_auxtexture
->dim_gc
;
739 dark
= scr
->menu_item_auxtexture
->dark_gc
;
741 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
744 else if (index
== menu
->entry_no
- 1)
752 /* paint background */
754 XSetForeground(dpy
, scr
->select_menu_gc
, scr
->select_pixel
);
755 XFillRectangle(dpy
, win
, scr
->select_menu_gc
, 1, y
+1, w
-2, h
-3);
756 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
757 drawFrame(scr
, win
, y
, w
, h
, type
);
759 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
760 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
762 drawFrame(scr
, win
, y
, w
, h
, type
);
764 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
769 textGC
= scr
->select_menu_gc
;
770 if (entry
->flags
.enabled
)
771 XSetForeground(dpy
, textGC
, scr
->select_text_pixel
);
773 XSetForeground(dpy
, textGC
, scr
->dtext_pixel
);
774 } else if (!entry
->flags
.enabled
) {
775 textGC
= scr
->disabled_menu_entry_gc
;
777 textGC
= scr
->menu_entry_gc
;
781 if (entry
->flags
.indicator
)
782 x
+= MENU_INDICATOR_SPACE
+ 2;
784 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
,
785 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
787 if (entry
->cascade
>=0) {
788 /* draw the cascade indicator */
789 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
790 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
791 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
795 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
800 switch (entry
->flags
.indicator_type
) {
802 indicator
= scr
->menu_check_indicator
;
805 indicator
= scr
->menu_mini_indicator
;
808 indicator
= scr
->menu_hide_indicator
;
811 indicator
= scr
->menu_shade_indicator
;
815 indicator
= scr
->menu_radio_indicator
;
819 iw
= indicator
->width
;
820 ih
= indicator
->height
;
821 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
822 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
824 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
826 XSetForeground(dpy
, scr
->copy_gc
, scr
->mtext_pixel
);
827 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
829 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
830 iw, ih, 5, y+(h-ih)/2);
832 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
835 /* draw right text */
837 if (entry
->rtext
&& entry
->cascade
<0) {
839 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
840 strlen(entry
->rtext
));
841 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
, w
-6-tw
,
842 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
848 move_menus(WMenu
*menu
, int x
, int y
)
850 while (menu
->parent
) {
853 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
854 y
-= menu
->selected_entry
*menu
->entry_height
;
857 wMenuMove(menu
, x
, y
, True
);
861 makeVisible(WMenu
*menu
)
863 WScreen
*scr
= menu
->frame
->screen_ptr
;
864 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
866 if (menu
->entry_no
<0) return;
869 y1
= menu
->frame_y
+menu
->frame
->top_width
870 + menu
->selected_entry
*menu
->entry_height
;
871 x2
= x1
+ MENUW(menu
);
872 y2
= y1
+ menu
->entry_height
;
881 } else if (x2
>= scr
->scr_width
) {
882 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
889 } else if (y2
>= scr
->scr_height
) {
890 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
894 new_y
= new_y
- menu
->frame
->top_width
895 - menu
->selected_entry
*menu
->entry_height
;
896 move_menus(menu
, new_x
, new_y
);
901 check_key(WMenu
*menu
, XKeyEvent
*event
)
906 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
909 ch
= toupper(buffer
[0]);
911 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
914 for (i
=s
; i
<menu
->entry_no
; i
++) {
915 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
919 /* no match. Retry from start, if previous started from a selected entry */
929 keyboardMenu(WMenu
*menu
)
932 KeySym ksym
=NoSymbol
;
936 int old_pos_x
= menu
->frame_x
;
937 int old_pos_y
= menu
->frame_y
;
938 int new_x
= old_pos_x
, new_y
= old_pos_y
;
939 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
940 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
942 if (menu
->flags
.editing
)
946 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
947 GrabModeAsync
, CurrentTime
);
949 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
950 new_y
= scr_height
- menu
->frame
->top_width
;
952 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
953 new_x
= scr_width
-MENUW(menu
)-1;
955 move_menus(menu
, new_x
, new_y
);
957 while (!done
&& menu
->flags
.mapped
) {
958 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
959 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
960 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
961 |SubstructureNotifyMask
, &event
);
963 switch (event
.type
) {
965 ksym
= XLookupKeysym(&event
.xkey
, 0);
975 selectEntry(menu
, 0);
983 selectEntry(menu
, menu
->entry_no
-1);
994 if (menu
->selected_entry
<= 0)
995 selectEntry(menu
, menu
->entry_no
-1);
997 selectEntry(menu
, menu
->selected_entry
-1);
1002 #ifdef ARROWLESS_KBD
1008 if (menu
->selected_entry
<0)
1009 selectEntry(menu
, 0);
1010 else if (menu
->selected_entry
== menu
->entry_no
-1)
1011 selectEntry(menu
, 0);
1012 else if (menu
->selected_entry
< menu
->entry_no
-1)
1013 selectEntry(menu
, menu
->selected_entry
+1);
1018 #ifdef ARROWLESS_KBD
1024 if (menu
->selected_entry
>=0) {
1026 entry
= menu
->entries
[menu
->selected_entry
];
1028 if (entry
->cascade
>= 0 && menu
->cascades
1029 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1031 XUngrabKeyboard(dpy
, CurrentTime
);
1033 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1034 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1037 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1038 GrabModeAsync
, GrabModeAsync
,
1045 #ifdef ARROWLESS_KBD
1051 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1052 selectEntry(menu
, -1);
1053 move_menus(menu
, old_pos_x
, old_pos_y
);
1063 index
= check_key(menu
, &event
.xkey
);
1065 selectEntry(menu
, index
);
1071 if (event
.type
==ButtonPress
)
1074 WMHandleEvent(&event
);
1078 XUngrabKeyboard(dpy
, CurrentTime
);
1080 if (done
==2 && menu
->selected_entry
>=0) {
1081 entry
= menu
->entries
[menu
->selected_entry
];
1086 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1087 && entry
->cascade
< 0) {
1088 #if (MENU_BLINK_COUNT > 0)
1089 int sel
= menu
->selected_entry
;
1092 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1093 paintEntry(menu
, sel
, False
);
1095 wusleep(MENU_BLINK_DELAY
);
1096 paintEntry(menu
, sel
, True
);
1098 wusleep(MENU_BLINK_DELAY
);
1101 selectEntry(menu
, -1);
1103 if (!menu
->flags
.buttoned
) {
1105 move_menus(menu
, old_pos_x
, old_pos_y
);
1109 (*entry
->callback
)(menu
, entry
);
1111 if (!menu
->flags
.buttoned
) {
1113 move_menus(menu
, old_pos_x
, old_pos_y
);
1115 selectEntry(menu
, -1);
1119 /* returns True if returning from a submenu to a parent menu,
1120 * False if exiting from menu */
1126 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1128 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1129 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1131 if (!menu
->flags
.realized
) {
1132 menu
->flags
.realized
=1;
1135 if (!menu
->flags
.mapped
) {
1136 if (wPreferences
.wrap_menus
) {
1139 if (x
+MENUW(menu
) > scr_width
)
1140 x
= scr_width
- MENUW(menu
);
1141 if (y
+MENUH(menu
) > scr_height
)
1142 y
= scr_height
- MENUH(menu
);
1145 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1148 XMapWindow(dpy
, menu
->frame
->core
->window
);
1149 wRaiseFrame(menu
->frame
->core
);
1150 menu
->flags
.mapped
= 1;
1152 selectEntry(menu
, 0);
1161 wMenuMap(WMenu
*menu
)
1163 if (!menu
->flags
.realized
) {
1164 menu
->flags
.realized
=1;
1167 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1168 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1169 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1170 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1172 XMapWindow(dpy
, menu
->frame
->core
->window
);
1173 wRaiseFrame(menu
->frame
->core
);
1174 menu
->flags
.mapped
= 1;
1179 wMenuUnmap(WMenu
*menu
)
1183 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1184 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1185 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1187 menu
->flags
.buttoned
= 0;
1188 menu
->flags
.mapped
= 0;
1189 menu
->flags
.open_to_left
= 0;
1191 for (i
=0; i
<menu
->cascade_no
; i
++) {
1192 if (menu
->cascades
[i
]!=NULL
1193 && menu
->cascades
[i
]->flags
.mapped
1194 && !menu
->cascades
[i
]->flags
.buttoned
) {
1196 wMenuUnmap(menu
->cascades
[i
]);
1199 menu
->selected_entry
= -1;
1205 wMenuPaint(WMenu
*menu
)
1209 if (!menu
->flags
.mapped
) {
1214 for (i
=0; i
<menu
->entry_no
; i
++) {
1215 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1221 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1223 if (index
>=menu
->entry_no
) return;
1224 menu
->entries
[index
]->flags
.enabled
=enable
;
1225 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1226 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1230 /* ====================================================================== */
1234 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1238 WObjDescriptor
*desc
;
1244 menu
->flags
.editing
= 1;
1246 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1247 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1249 wTextPutText(text
, entry
->text
);
1250 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1251 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1253 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1254 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1255 wwarning("could not grab keyboard");
1258 wSetFocusTo(menu
->frame
->screen_ptr
,
1259 menu
->frame
->screen_ptr
->focused_window
);
1264 while (!done
&& !text
->done
) {
1266 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1268 WMNextEvent(dpy
, &event
);
1270 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1271 (XPointer
*)&desc
)==XCNOENT
)
1274 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1276 (*desc
->handle_anything
)(desc
, &event
);
1279 switch (event
.type
) {
1281 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1285 WMHandleEvent(&event
);
1291 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1293 wSetFocusTo(menu
->frame
->screen_ptr
,
1294 menu
->frame
->screen_ptr
->focused_window
);
1297 t
= wTextGetText(text
);
1298 /* if !t, the user has canceled editing */
1302 entry
->text
= wstrdup(t
);
1304 menu
->flags
.realized
= 0;
1308 XUngrabKeyboard(dpy
, CurrentTime
);
1310 if (t
&& menu
->on_edit
)
1311 (*menu
->on_edit
)(menu
, entry
);
1313 menu
->flags
.editing
= 0;
1315 if (!menu
->flags
.realized
)
1321 selectEntry(WMenu
*menu
, int entry_no
)
1327 if (menu
->entries
==NULL
)
1330 if (entry_no
>= menu
->entry_no
)
1333 old_entry
= menu
->selected_entry
;
1334 menu
->selected_entry
= entry_no
;
1336 if (old_entry
!=entry_no
) {
1338 /* unselect previous entry */
1340 paintEntry(menu
, old_entry
, False
);
1341 entry
= menu
->entries
[old_entry
];
1344 if (entry
->cascade
>=0 && menu
->cascades
) {
1345 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1346 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1352 menu
->selected_entry
= -1;
1355 entry
= menu
->entries
[entry_no
];
1357 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1358 /* Callback for when the submenu is opened.
1360 submenu
= menu
->cascades
[entry
->cascade
];
1361 if (submenu
&& submenu
->flags
.brother
)
1362 submenu
= submenu
->brother
;
1364 if (entry
->callback
) {
1365 /* Only call the callback if the submenu is not yet mapped.
1367 if (menu
->flags
.brother
) {
1368 if (!submenu
|| !submenu
->flags
.mapped
)
1369 (*entry
->callback
)(menu
->brother
, entry
);
1371 if (!submenu
|| !submenu
->flags
.buttoned
)
1372 (*entry
->callback
)(menu
, entry
);
1376 /* the submenu menu might have changed */
1377 submenu
= menu
->cascades
[entry
->cascade
];
1380 if (!submenu
->flags
.mapped
) {
1383 if (!submenu
->flags
.realized
)
1384 wMenuRealize(submenu
);
1385 if (wPreferences
.wrap_menus
) {
1386 if (menu
->flags
.open_to_left
)
1387 submenu
->flags
.open_to_left
= 1;
1389 if (submenu
->flags
.open_to_left
) {
1390 x
= menu
->frame_x
- MENUW(submenu
);
1393 submenu
->flags
.open_to_left
= 0;
1396 x
= menu
->frame_x
+ MENUW(menu
);
1398 if (x
+ MENUW(submenu
)
1399 >= menu
->frame
->screen_ptr
->scr_width
) {
1401 x
= menu
->frame_x
- MENUW(submenu
);
1402 submenu
->flags
.open_to_left
= 1;
1406 x
= menu
->frame_x
+ MENUW(menu
);
1409 if (wPreferences
.align_menus
) {
1412 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1413 if (menu
->flags
.titled
)
1414 y
+= menu
->frame
->top_width
;
1415 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1416 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1419 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1420 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1425 paintEntry(menu
, entry_no
, True
);
1431 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1434 WObjDescriptor
*desc
;
1435 Window root_ret
, win
, junk_win
;
1439 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1442 if (win
==None
) return NULL
;
1444 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1447 if (desc
->parent_type
== WCLASS_MENU
) {
1448 menu
= (WMenu
*)desc
->parent
;
1449 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1450 x_ret
, y_ret
, &junk_win
);
1460 closeCascade(WMenu
*menu
)
1462 WMenu
*parent
=menu
->parent
;
1464 if (menu
->flags
.brother
1465 || (!menu
->flags
.buttoned
1466 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1468 selectEntry(menu
, -1);
1470 #if (MENU_BLINK_DELAY > 2)
1471 wusleep(MENU_BLINK_DELAY
/2);
1475 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1476 || parent
->flags
.brother
)
1477 && !parent
->flags
.buttoned
) {
1478 selectEntry(parent
, -1);
1480 parent
= parent
->parent
;
1483 selectEntry(parent
, -1);
1489 closeBrotherCascadesOf(WMenu
*menu
)
1494 for (i
=0; i
<menu
->cascade_no
; i
++) {
1495 if (menu
->cascades
[i
]->flags
.brother
) {
1496 tmp
= menu
->cascades
[i
];
1498 tmp
= menu
->cascades
[i
]->brother
;
1500 if (tmp
->flags
.mapped
) {
1501 selectEntry(tmp
->parent
, -1);
1502 closeBrotherCascadesOf(tmp
);
1509 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1513 parentMenu(WMenu
*menu
)
1518 if (menu
->flags
.buttoned
)
1521 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1522 parent
= menu
->parent
;
1523 if (parent
->selected_entry
< 0)
1525 entry
= parent
->entries
[parent
->selected_entry
];
1526 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1527 parent
->cascades
[entry
->cascade
] != menu
)
1530 if (menu
->flags
.buttoned
)
1540 * Will raise the passed menu, if submenu = 0
1541 * If submenu > 0 will also raise all mapped submenus
1542 * until the first buttoned one
1543 * If submenu < 0 will also raise all mapped parent menus
1544 * until the first buttoned one
1548 raiseMenus(WMenu
*menu
, int submenus
)
1555 wRaiseFrame(menu
->frame
->core
);
1557 if (submenus
>0 && menu
->selected_entry
>=0) {
1558 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1559 if (i
>=0 && menu
->cascades
) {
1560 submenu
= menu
->cascades
[i
];
1561 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1562 raiseMenus(submenu
, submenus
);
1565 if (submenus
<0 && !menu
->flags
.buttoned
&&
1566 menu
->parent
&& menu
->parent
->flags
.mapped
)
1567 raiseMenus(menu
->parent
, submenus
);
1572 wMenuUnderPointer(WScreen
*screen
)
1574 WObjDescriptor
*desc
;
1575 Window root_ret
, win
;
1579 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1580 &dummy
, &dummy
, &mask
);
1582 if (win
==None
) return NULL
;
1584 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1587 if (desc
->parent_type
== WCLASS_MENU
)
1588 return (WMenu
*)desc
->parent
;
1596 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1598 Window root_ret
, win
;
1602 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1607 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1609 WScreen
*scr
= menu
->menu
->screen_ptr
;
1610 int menuX1
= menu
->frame_x
;
1611 int menuY1
= menu
->frame_y
;
1612 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1613 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1614 int screenW
= scr
->scr_width
;
1615 int screenH
= scr
->scr_height
;
1621 getPointerPosition(scr
, &xroot
, &yroot
);
1623 #ifdef VIRTUAL_DESKTOP
1624 if (wPreferences
.vedge_thickness
) {
1625 if (xroot
<= wPreferences
.vedge_thickness
+ 1 && menuX1
< wPreferences
.vedge_thickness
) {
1626 /* scroll to the right */
1627 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1629 } else if (xroot
>= screenW
-2-wPreferences
.vedge_thickness
&& menuX2
> screenW
-1-wPreferences
.vedge_thickness
) {
1630 /* scroll to the left */
1631 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1636 *hamount
= -*hamount
;
1641 if (xroot
<= 1 && menuX1
< 0) {
1642 /* scroll to the right */
1643 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1645 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1646 /* scroll to the left */
1647 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1652 *hamount
= -*hamount
;
1655 if (yroot
<= 1 && menuY1
< 0) {
1657 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1659 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1661 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1663 *vamount
= -*vamount
;
1669 dragScrollMenuCallback(void *data
)
1671 WMenu
*menu
= (WMenu
*)data
;
1672 WScreen
*scr
= menu
->menu
->screen_ptr
;
1673 WMenu
*parent
= parentMenu(menu
);
1674 int hamount
, vamount
;
1676 int newSelectedEntry
;
1678 getScrollAmount(menu
, &hamount
, &vamount
);
1681 if (hamount
!= 0 || vamount
!= 0) {
1682 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1683 parent
->frame_y
+ vamount
, True
);
1684 if (findMenu(scr
, &x
, &y
)) {
1685 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1686 selectEntry(menu
, newSelectedEntry
);
1688 /* Pointer fell outside of menu. If the selected entry is
1689 * not a submenu, unselect it */
1690 if (menu
->selected_entry
>= 0
1691 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1692 selectEntry(menu
, -1);
1693 newSelectedEntry
= 0;
1696 /* paranoid check */
1697 if (newSelectedEntry
>= 0) {
1698 /* keep scrolling */
1699 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1700 dragScrollMenuCallback
, menu
);
1705 /* don't need to scroll anymore */
1707 if (findMenu(scr
, &x
, &y
)) {
1708 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1709 selectEntry(menu
, newSelectedEntry
);
1716 scrollMenuCallback(void *data
)
1718 WMenu
*menu
= (WMenu
*)data
;
1719 WMenu
*parent
= parentMenu(menu
);
1720 int hamount
= 0; /* amount to scroll */
1723 getScrollAmount(menu
, &hamount
, &vamount
);
1725 if (hamount
!= 0 || vamount
!= 0) {
1726 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1727 parent
->frame_y
+ vamount
, True
);
1729 /* keep scrolling */
1730 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1731 scrollMenuCallback
, menu
);
1733 /* don't need to scroll anymore */
1740 #define MENU_SCROLL_BORDER 5
1743 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1745 int menuX1
= menu
->frame_x
;
1746 int menuY1
= menu
->frame_y
;
1747 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1748 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1749 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1750 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1753 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1754 || y
> scrYe
-MENU_SCROLL_BORDER
))
1756 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1757 || x
> scrXe
-MENU_SCROLL_BORDER
))
1764 typedef struct _delay
{
1772 _leaving(_delay
*dl
)
1774 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1775 dl
->menu
->jump_back
=NULL
;
1776 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1782 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1785 WMenu
*omenu
= parentMenu(menu
);
1786 WScreen
*scr
= menu
->frame
->screen_ptr
;
1789 int old_frame_x
= omenu
->frame_x
;
1790 int old_frame_y
= omenu
->frame_y
;
1793 if (omenu
->jump_back
)
1794 WMDeleteTimerWithClientData(omenu
->jump_back
);
1797 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1798 || omenu
->flags
.app_menu
) {
1802 if (!wPreferences
.wrap_menus
)
1803 raiseMenus(omenu
, True
);
1805 raiseMenus(menu
, False
);
1808 scrollMenuCallback(menu
);
1811 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1813 WMNextEvent(dpy
, &ev
);
1818 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1819 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1821 /* on_border is != 0 if the pointer is between the menu
1822 * and the screen border and is close enough to the border */
1823 on_border
= isPointNearBoder(menu
, x
, y
);
1825 smenu
= wMenuUnderPointer(scr
);
1827 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1832 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1833 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1834 on_border
= on_x_edge
|| on_y_edge
;
1836 if (!on_border
&& !jump_back
) {
1841 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1842 WMDeleteTimerHandler(menu
->timer
);
1850 scrollMenuCallback(menu
);
1853 /* True if we push on title, or drag the omenu to other position */
1854 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1855 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1856 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1857 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1859 smenu
= wMenuUnderPointer(scr
);
1860 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1862 else if (smenu
==omenu
&& on_title
) {
1876 WMDeleteTimerHandler(menu
->timer
);
1882 if (!omenu
->jump_back
) {
1883 delayer
=wmalloc(sizeof(_delay
));
1884 delayer
->menu
=omenu
;
1885 delayer
->ox
=old_frame_x
;
1886 delayer
->oy
=old_frame_y
;
1887 omenu
->jump_back
=delayer
;
1888 scr
->flags
.jump_back_pending
= 1;
1890 else delayer
= omenu
->jump_back
;
1891 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1898 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1900 wMenuPaint(desc
->parent
);
1904 int *delayed_select
;
1911 delaySelection(void *data
)
1913 delay_data
*d
= (delay_data
*)data
;
1919 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1920 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1921 entry_no
= getEntryAt(menu
, x
, y
);
1922 selectEntry(menu
, entry_no
);
1924 if (d
->delayed_select
)
1925 *(d
->delayed_select
) = 0;
1930 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1932 XButtonEvent
*bev
= &event
->xbutton
;
1933 WMenu
*menu
= desc
->parent
;
1935 WScreen
*scr
=menu
->frame
->screen_ptr
;
1936 WMenuEntry
*entry
=NULL
;
1938 int close_on_exit
=0;
1940 int delayed_select
= 0;
1944 int old_frame_x
= 0;
1945 int old_frame_y
= 0;
1946 delay_data d_data
= {NULL
, NULL
, NULL
};
1948 if (!wPreferences
.wrap_menus
) {
1949 smenu
= parentMenu(menu
);
1950 old_frame_x
= smenu
->frame_x
;
1951 old_frame_y
= smenu
->frame_y
;
1952 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1953 /* This is true if the menu was launched with right click on root window */
1955 d_data
.delayed_select
= &delayed_select
;
1957 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1958 delaySelection
, &d_data
);
1961 if (menu
->flags
.inside_handler
) {
1964 menu
->flags
.inside_handler
= 1;
1966 wRaiseFrame(menu
->frame
->core
);
1968 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1970 smenu
= findMenu(scr
, &x
, &y
);
1978 if (menu
->flags
.editing
) {
1981 entry_no
= getEntryAt(menu
, x
, y
);
1983 entry
= menu
->entries
[entry_no
];
1985 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1986 && entry
->flags
.editable
) {
1987 editEntry(smenu
, entry
);
1989 } else if (bev
->state
& ControlMask
) {
1993 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1994 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1996 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1997 menu
->selected_entry
!=entry_no
) {
1998 wMenuUnmap(submenu
);
2000 if (!submenu
->flags
.mapped
&& !delayed_select
) {
2001 selectEntry(menu
, entry_no
);
2002 } else if (!submenu
->flags
.buttoned
) {
2003 selectEntry(menu
, -1);
2006 } else if (!delayed_select
) {
2007 selectEntry(menu
, entry_no
);
2010 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2012 dragScrollMenuCallback(menu
);
2016 prevx
= bev
->x_root
;
2017 prevy
= bev
->y_root
;
2021 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2023 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2024 |ButtonPressMask
, &ev
);
2027 smenu
= findMenu(scr
, &x
, &y
);
2029 if (smenu
== NULL
) {
2030 /* moved mouse out of menu */
2032 if (!delayed_select
&& d_data
.magic
) {
2033 WMDeleteTimerHandler(d_data
.magic
);
2034 d_data
.magic
= NULL
;
2037 || (menu
->selected_entry
>=0
2038 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2039 prevx
= ev
.xmotion
.x_root
;
2040 prevy
= ev
.xmotion
.y_root
;
2044 selectEntry(menu
, -1);
2046 prevx
= ev
.xmotion
.x_root
;
2047 prevy
= ev
.xmotion
.y_root
;
2049 } else if (menu
&& menu
!=smenu
2050 && (menu
->selected_entry
<0
2051 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2052 selectEntry(menu
, -1);
2054 if (!delayed_select
&& d_data
.magic
) {
2055 WMDeleteTimerHandler(d_data
.magic
);
2056 d_data
.magic
= NULL
;
2060 /* hysteresis for item selection */
2062 /* check if the motion was to the side, indicating that
2063 * the user may want to cross to a submenu */
2064 if (!delayed_select
&& menu
) {
2066 Bool moved_to_submenu
;/* moved to direction of submenu */
2068 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2070 moved_to_submenu
= False
;
2071 if (dx
> 0 /* if moved enough to the side */
2072 /* maybe a open submenu */
2073 && menu
->selected_entry
>=0
2074 /* moving to the right direction */
2075 && (wPreferences
.align_menus
2076 || ev
.xmotion
.y_root
>= prevy
)) {
2079 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2081 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2082 if (prevx
< ev
.xmotion
.x_root
)
2083 moved_to_submenu
= True
;
2085 if (prevx
> ev
.xmotion
.x_root
)
2086 moved_to_submenu
= True
;
2092 if (menu
!= smenu
) {
2094 WMDeleteTimerHandler(d_data
.magic
);
2096 d_data
.magic
= NULL
;
2097 } else if (moved_to_submenu
) {
2098 /* while we are moving, postpone the selection */
2100 WMDeleteTimerHandler(d_data
.magic
);
2102 d_data
.delayed_select
= NULL
;
2104 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2107 prevx
= ev
.xmotion
.x_root
;
2108 prevy
= ev
.xmotion
.y_root
;
2112 WMDeleteTimerHandler(d_data
.magic
);
2113 d_data
.magic
= NULL
;
2117 prevx
= ev
.xmotion
.x_root
;
2118 prevy
= ev
.xmotion
.y_root
;
2120 /* pointer crossed menus */
2121 if (menu
&& menu
->timer
) {
2122 WMDeleteTimerHandler(menu
->timer
);
2126 dragScrollMenuCallback(smenu
);
2130 dragScrollMenuCallback(menu
);
2132 if (!delayed_select
) {
2133 entry_no
= getEntryAt(menu
, x
, y
);
2135 entry
= menu
->entries
[entry_no
];
2136 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2138 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2139 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2140 && menu
->selected_entry
!=entry_no
) {
2141 wMenuUnmap(submenu
);
2145 selectEntry(menu
, entry_no
);
2153 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2163 if (menu
&& menu
->timer
) {
2164 WMDeleteTimerHandler(menu
->timer
);
2167 if (d_data
.magic
!=NULL
)
2168 WMDeleteTimerHandler(d_data
.magic
);
2170 if (menu
&& menu
->selected_entry
>=0) {
2171 entry
= menu
->entries
[menu
->selected_entry
];
2172 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2173 && entry
->cascade
< 0) {
2174 /* blink and erase menu selection */
2175 #if (MENU_BLINK_DELAY > 0)
2176 int sel
= menu
->selected_entry
;
2179 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2180 paintEntry(menu
, sel
, False
);
2182 wusleep(MENU_BLINK_DELAY
);
2183 paintEntry(menu
, sel
, True
);
2185 wusleep(MENU_BLINK_DELAY
);
2188 /* unmap the menu, it's parents and call the callback */
2189 if (!menu
->flags
.buttoned
&&
2190 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2193 selectEntry(menu
, -1);
2195 (*entry
->callback
)(menu
, entry
);
2197 /* If the user double clicks an entry, the entry will
2198 * be executed twice, which is not good for things like
2199 * the root menu. So, ignore any clicks that were generated
2200 * while the entry was being executed */
2201 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2203 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2204 selectEntry(menu
, -1);
2206 if (entry
->cascade
>=0 && menu
->cascades
2207 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2208 selectEntry(menu
, -1);
2213 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2214 closeCascade(desc
->parent
);
2216 /* close the cascade windows that should not remain opened */
2217 closeBrotherCascadesOf(desc
->parent
);
2219 if (!wPreferences
.wrap_menus
)
2220 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2223 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2228 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2237 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2239 if (submenus
>0 && menu
->selected_entry
>=0) {
2240 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2242 if (i
>=0 && menu
->cascades
) {
2243 submenu
= menu
->cascades
[i
];
2244 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2245 if (wPreferences
.align_menus
) {
2246 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2248 wMenuMove(submenu
, x
+ MENUW(menu
),
2249 y
+ submenu
->entry_height
*menu
->selected_entry
,
2255 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2256 !menu
->parent
->flags
.buttoned
) {
2257 if (wPreferences
.align_menus
) {
2258 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2260 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2261 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2269 changeMenuLevels(WMenu
*menu
, int lower
)
2274 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2276 wRaiseFrame(menu
->frame
->core
);
2277 menu
->flags
.lowered
= 0;
2279 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2280 wLowerFrame(menu
->frame
->core
);
2281 menu
->flags
.lowered
= 1;
2283 for (i
=0; i
<menu
->cascade_no
; i
++) {
2284 if (menu
->cascades
[i
]
2285 && !menu
->cascades
[i
]->flags
.buttoned
2286 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2287 changeMenuLevels(menu
->cascades
[i
], lower
);
2295 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2300 if (event
->xbutton
.state
& MOD_MASK
) {
2301 if (menu
->flags
.lowered
) {
2306 changeMenuLevels(menu
, lower
);
2312 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2317 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2318 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2322 /* can't touch the menu copy */
2323 if (menu
->flags
.brother
)
2326 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2329 if (event
->xbutton
.state
& MOD_MASK
) {
2330 wLowerFrame(menu
->frame
->core
);
2333 wRaiseFrame(menu
->frame
->core
);
2338 /* lower/raise all submenus */
2340 if (tmp
->selected_entry
>=0 && tmp
->cascades
2341 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2342 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2343 if (!tmp
|| !tmp
->flags
.mapped
)
2346 wLowerFrame(tmp
->frame
->core
);
2348 wRaiseFrame(tmp
->frame
->core
);
2354 /* tear off the menu if it's a root menu or a cascade
2356 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2357 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2358 menu
->flags
.buttoned
=1;
2359 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2361 /* turn off selected menu entry in parent menu */
2362 selectEntry(menu
->parent
, -1);
2364 /* make parent map the copy in place of the original */
2365 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2366 if (menu
->parent
->cascades
[i
] == menu
) {
2367 menu
->parent
->cascades
[i
] = menu
->brother
;
2376 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2377 |ExposureMask
, &ev
);
2381 x
+= ev
.xmotion
.x_root
- dx
;
2382 y
+= ev
.xmotion
.y_root
- dy
;
2383 dx
= ev
.xmotion
.x_root
;
2384 dy
= ev
.xmotion
.y_root
;
2385 wMenuMove(menu
, x
, y
, True
);
2387 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2388 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2390 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2391 ButtonMotionMask
|ButtonReleaseMask
2393 GrabModeAsync
, GrabModeAsync
, None
,
2394 wCursor
[WCUR_MOVE
], CurrentTime
);
2403 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2405 XUngrabPointer(dpy
, CurrentTime
);
2416 *----------------------------------------------------------------------
2418 * Handles mouse click on the close button of menus. The menu is
2419 * closed when the button is clicked.
2422 * The closed menu is reinserted at it's parent menus
2424 *----------------------------------------------------------------------
2427 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2429 WMenu
*menu
= (WMenu
*)data
;
2430 WMenu
*parent
= menu
->parent
;
2434 for (i
=0; i
<parent
->cascade_no
; i
++) {
2435 /* find the entry that points to the copy */
2436 if (parent
->cascades
[i
] == menu
->brother
) {
2437 /* make it point to the original */
2438 parent
->cascades
[i
] = menu
;
2439 menu
->parent
= parent
;
2449 saveMenuInfo(proplist_t dict
, WMenu
*menu
, proplist_t key
)
2451 proplist_t value
, list
;
2454 sprintf(buffer
, "%i,%i", menu
->frame_x
, menu
->frame_y
);
2455 value
= PLMakeString(buffer
);
2456 list
= PLMakeArrayFromElements(value
, NULL
);
2457 if (menu
->flags
.lowered
)
2458 PLAppendArrayElement(list
, PLMakeString("lowered"));
2459 PLInsertDictionaryEntry(dict
, key
, list
);
2466 wMenuSaveState(WScreen
*scr
)
2468 proplist_t menus
, key
;
2471 menus
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
2474 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2475 key
= PLMakeString("SwitchMenu");
2476 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2481 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2485 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2486 key
= PLMakeString("WorkspaceMenu");
2487 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2493 key
= PLMakeString("Menus");
2494 PLInsertDictionaryEntry(scr
->session_state
, key
, menus
);
2504 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2509 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2512 len
= strlen(menu
->frame
->title
);
2517 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2522 strcat(buffer
, "\\");
2523 strcat(buffer
, menu
->frame
->title
);
2530 saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
)
2533 int save_menus
= 0, i
;
2538 if (menu
->flags
.brother
)
2539 menu
= menu
->brother
;
2541 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2544 ok
= getMenuPath(menu
, buffer
, 510);
2547 key
= PLMakeString(buffer
);
2548 saveMenuInfo(menus
, menu
, key
);
2555 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2556 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2565 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2569 getMenuInfo(proplist_t info
, int *x
, int *y
, Bool
*lowered
)
2575 if (PLIsArray(info
)) {
2577 pos
= PLGetArrayElement(info
, 0);
2578 flags
= PLGetArrayElement(info
, 1);
2579 if (flags
!= NULL
&& PLIsString(flags
) && PLGetString(flags
) != NULL
2580 && strcmp(PLGetString(flags
), "lowered") == 0) {
2587 if (pos
!= NULL
&& PLIsString(pos
)) {
2588 if (sscanf(PLGetString(pos
), "%i,%i", x
, y
)!=2)
2589 COMPLAIN("Position");
2591 COMPLAIN("(position, flags...)");
2600 restoreMenu(WScreen
*scr
, proplist_t menu
, int which
)
2603 Bool lowered
= False
;
2604 WMenu
*pmenu
= NULL
;
2609 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2614 if (which
& WSS_SWITCHMENU
) {
2615 OpenSwitchMenu(scr
, x
, y
, False
);
2616 pmenu
= scr
->switch_menu
;
2621 int width
= MENUW(pmenu
);
2622 int height
= MENUH(pmenu
);
2625 changeMenuLevels(pmenu
, True
);
2628 x
= (x
< -width
) ? 0 : x
;
2629 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2630 y
= (y
< 0) ? 0 : y
;
2631 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2632 wMenuMove(pmenu
, x
, y
, True
);
2633 pmenu
->flags
.buttoned
= 1;
2634 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2643 restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
)
2645 proplist_t key
, entry
;
2650 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2653 sprintf(buffer
, "%s\\%s", path
, menu
->frame
->title
);
2654 key
= PLMakeString(buffer
);
2655 entry
= PLGetDictionaryEntry(menus
, key
);
2658 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2660 if (!menu
->flags
.mapped
) {
2661 int width
= MENUW(menu
);
2662 int height
= MENUH(menu
);
2664 wMenuMapAt(menu
, x
, y
, False
);
2667 /* make parent map the copy in place of the original */
2668 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2669 if (menu
->parent
->cascades
[i
] == menu
) {
2670 menu
->parent
->cascades
[i
] = menu
->brother
;
2676 changeMenuLevels(menu
, True
);
2678 x
= (x
< -width
) ? 0 : x
;
2679 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2680 y
= (y
< 0) ? 0 : y
;
2681 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2682 wMenuMove(menu
, x
, y
, True
);
2683 menu
->flags
.buttoned
= 1;
2684 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2691 for (i
=0; i
<menu
->cascade_no
; i
++) {
2692 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2702 wMenuRestoreState(WScreen
*scr
)
2704 proplist_t menus
, menu
, key
, skey
;
2706 key
= PLMakeString("Menus");
2707 menus
= PLGetDictionaryEntry(scr
->session_state
, key
);
2715 skey
= PLMakeString("SwitchMenu");
2716 menu
= PLGetDictionaryEntry(menus
, skey
);
2718 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2721 if (!scr
->root_menu
) {
2722 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2723 wMenuUnmap(scr
->root_menu
);
2725 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2731 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2733 WMenu
*menu
, *parent
;
2737 if (!scr
->root_menu
) {
2738 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2739 wMenuUnmap(scr
->root_menu
);
2742 menu
= scr
->workspace_menu
;
2744 if (menu
->flags
.mapped
) {
2745 if (!menu
->flags
.buttoned
) {
2747 parent
= menu
->parent
;
2748 if (parent
&& parent
->selected_entry
>= 0) {
2749 entry
= parent
->entries
[parent
->selected_entry
];
2750 if (parent
->cascades
[entry
->cascade
] == menu
) {
2751 selectEntry(parent
, -1);
2752 wMenuMapAt(menu
, x
, y
, False
);
2756 wRaiseFrame(menu
->frame
->core
);
2757 wMenuMapCopyAt(menu
, x
, y
);
2760 wMenuMapAt(menu
, x
, y
, False
);