1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
27 #include <X11/keysym.h>
35 #include "WindowMaker.h"
43 #include "workspace.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
60 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
61 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
63 /***** Local Stuff ******/
65 #define WSS_ROOTMENU (1<<0)
66 #define WSS_SWITCHMENU (1<<1)
67 #define WSS_WSMENU (1<<2)
72 } menuScrollParameters
[5] = {
74 MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
}, {
75 MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
}, {
76 MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
}, {
77 MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
}, {
78 MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
80 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
81 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
);
84 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
85 static void updateTexture(WMenu
* menu
);
86 static int saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
);
87 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
);
88 static void selectEntry(WMenu
* menu
, int entry_no
);
89 static void closeCascade(WMenu
* menu
);
91 /****** Notification Observers ******/
93 static void appearanceObserver(void *self
, WMNotification
* notif
)
95 WMenu
*menu
= (WMenu
*) self
;
96 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
98 if (!menu
->flags
.realized
)
101 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
102 if (flags
& WFontSettings
) {
103 menu
->flags
.realized
= 0;
106 if (flags
& WTextureSettings
) {
107 if (!menu
->flags
.brother
)
110 if (flags
& (WTextureSettings
| WColorSettings
)) {
113 } else if (menu
->flags
.titled
) {
115 if (flags
& WFontSettings
) {
116 menu
->flags
.realized
= 0;
119 if (flags
& WTextureSettings
) {
120 menu
->frame
->flags
.need_texture_remake
= 1;
122 if (flags
& (WColorSettings
| WTextureSettings
)) {
123 wFrameWindowPaint(menu
->frame
);
128 /************************************/
131 *----------------------------------------------------------------------
133 * Creates a new empty menu with the specified title. If main_menu
134 * is True, the created menu will be a main menu, which has some special
135 * properties such as being placed over other normal menus.
136 * If title is NULL, the menu will have no titlebar.
140 *----------------------------------------------------------------------
142 WMenu
*wMenuCreate(WScreen
* screen
, char *title
, int main_menu
)
145 static int brother
= 0;
148 menu
= wmalloc(sizeof(WMenu
));
150 #ifdef SINGLE_MENULEVEL
151 tmp
= WMSubmenuLevel
;
153 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
156 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
158 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
159 menu
->flags
.titled
= 1;
162 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
,
163 &wPreferences
.menu_title_min_height
,
164 &wPreferences
.menu_title_max_height
,
166 screen
->menu_title_texture
, NULL
,
167 screen
->menu_title_color
, &screen
->menu_title_font
);
169 menu
->frame
->core
->descriptor
.parent
= menu
;
170 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
171 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
173 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
176 menu
->frame
->title
= wstrdup(title
);
179 menu
->frame
->flags
.justification
= WTJ_LEFT
;
181 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
184 menu
->alloced_entries
= 0;
185 menu
->selected_entry
= -1;
186 menu
->entries
= NULL
;
188 menu
->frame_x
= screen
->app_menu_x
;
189 menu
->frame_y
= screen
->app_menu_y
;
191 menu
->frame
->child
= menu
;
193 menu
->flags
.lowered
= 0;
197 /* setup object descriptors */
198 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
199 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
202 menu
->frame
->on_click_right
= menuCloseClick
;
204 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
, menu
->frame
->core
->width
, 10);
206 menu
->menu
->descriptor
.parent
= menu
;
207 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
208 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
209 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
211 menu
->menu_texture_data
= None
;
213 XMapWindow(dpy
, menu
->menu
->window
);
219 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
221 menu
->brother
->flags
.brother
= 1;
222 menu
->brother
->brother
= menu
;
224 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuAppearanceSettingsChanged
, menu
);
226 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuTitleAppearanceSettingsChanged
, menu
);
231 WMenu
*wMenuCreateForApp(WScreen
* screen
, char *title
, int main_menu
)
235 menu
= wMenuCreate(screen
, title
, main_menu
);
238 menu
->flags
.app_menu
= 1;
239 menu
->brother
->flags
.app_menu
= 1;
244 static void insertEntry(WMenu
* menu
, WMenuEntry
* entry
, int index
)
248 for (i
= menu
->entry_no
- 1; i
>= index
; i
--) {
249 menu
->entries
[i
]->order
++;
250 menu
->entries
[i
+ 1] = menu
->entries
[i
];
252 menu
->entries
[index
] = entry
;
255 WMenuEntry
*wMenuInsertCallback(WMenu
* menu
, int index
, char *text
,
256 void (*callback
) (WMenu
* menu
, WMenuEntry
* entry
), void *clientdata
)
260 menu
->flags
.realized
= 0;
261 menu
->brother
->flags
.realized
= 0;
263 /* reallocate array if it's too small */
264 if (menu
->entry_no
>= menu
->alloced_entries
) {
267 tmp
= wrealloc(menu
->entries
, sizeof(WMenuEntry
) * (menu
->alloced_entries
+ 5));
270 menu
->alloced_entries
+= 5;
272 menu
->brother
->entries
= tmp
;
273 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
275 entry
= wmalloc(sizeof(WMenuEntry
));
276 entry
->flags
.enabled
= 1;
277 entry
->text
= wstrdup(text
);
279 entry
->clientdata
= clientdata
;
280 entry
->callback
= callback
;
281 if (index
< 0 || index
>= menu
->entry_no
) {
282 entry
->order
= menu
->entry_no
;
283 menu
->entries
[menu
->entry_no
] = entry
;
285 entry
->order
= index
;
286 insertEntry(menu
, entry
, index
);
290 menu
->brother
->entry_no
= menu
->entry_no
;
295 void wMenuEntrySetCascade(WMenu
* menu
, WMenuEntry
* entry
, WMenu
* cascade
)
297 WMenu
*brother
= menu
->brother
;
300 assert(menu
->flags
.brother
== 0);
302 if (entry
->cascade
>= 0) {
303 menu
->flags
.realized
= 0;
304 brother
->flags
.realized
= 0;
307 cascade
->parent
= menu
;
309 cascade
->brother
->parent
= brother
;
312 for (i
= 0; i
< menu
->cascade_no
; i
++) {
313 if (menu
->cascades
[i
] == NULL
) {
314 menu
->cascades
[i
] = cascade
;
315 brother
->cascades
[i
] = cascade
->brother
;
322 entry
->cascade
= menu
->cascade_no
;
324 menu
->cascades
= wrealloc(menu
->cascades
, sizeof(WMenu
) * (menu
->cascade_no
+ 1));
325 menu
->cascades
[menu
->cascade_no
++] = cascade
;
327 brother
->cascades
= wrealloc(brother
->cascades
, sizeof(WMenu
) * (brother
->cascade_no
+ 1));
328 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
331 if (menu
->flags
.lowered
) {
333 cascade
->flags
.lowered
= 1;
334 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
336 cascade
->brother
->flags
.lowered
= 1;
337 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
340 if (!menu
->flags
.realized
)
344 void wMenuEntryRemoveCascade(WMenu
* menu
, WMenuEntry
* entry
)
346 assert(menu
->flags
.brother
== 0);
348 /* destroy cascade menu */
349 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
] != NULL
) {
351 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
353 menu
->cascades
[entry
->cascade
] = NULL
;
354 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
360 void wMenuRemoveItem(WMenu
* menu
, int index
)
364 if (menu
->flags
.brother
) {
365 wMenuRemoveItem(menu
->brother
, index
);
369 if (index
>= menu
->entry_no
)
372 /* destroy cascade menu */
373 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
375 /* destroy unshared data */
377 if (menu
->entries
[index
]->text
)
378 wfree(menu
->entries
[index
]->text
);
380 if (menu
->entries
[index
]->rtext
)
381 wfree(menu
->entries
[index
]->rtext
);
383 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
384 (*menu
->entries
[index
]->free_cdata
) (menu
->entries
[index
]->clientdata
);
386 wfree(menu
->entries
[index
]);
388 for (i
= index
; i
< menu
->entry_no
- 1; i
++) {
389 menu
->entries
[i
+ 1]->order
--;
390 menu
->entries
[i
] = menu
->entries
[i
+ 1];
393 menu
->brother
->entry_no
--;
396 static Pixmap
renderTexture(WMenu
* menu
)
404 WScreen
*scr
= menu
->menu
->screen_ptr
;
405 WTexture
*texture
= scr
->menu_item_texture
;
407 if (wPreferences
.menu_style
== MS_NORMAL
) {
408 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->entry_height
, WREL_MENUENTRY
);
410 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->menu
->height
+ 1, WREL_MENUENTRY
);
413 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode
));
418 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
420 light
.red
= light
.green
= light
.blue
= 80;
423 dark
.red
= dark
.green
= dark
.blue
= 0;
426 mid
.red
= mid
.green
= mid
.blue
= 40;
428 for (i
= 1; i
< menu
->entry_no
; i
++) {
429 ROperateLine(img
, RSubtractOperation
, 0, i
* menu
->entry_height
- 2,
430 menu
->menu
->width
- 1, i
* menu
->entry_height
- 2, &mid
);
432 RDrawLine(img
, 0, i
* menu
->entry_height
- 1,
433 menu
->menu
->width
- 1, i
* menu
->entry_height
- 1, &dark
);
435 ROperateLine(img
, RAddOperation
, 0, i
* menu
->entry_height
,
436 menu
->menu
->width
- 1, i
* menu
->entry_height
, &light
);
439 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
440 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
447 static void updateTexture(WMenu
* menu
)
449 WScreen
*scr
= menu
->menu
->screen_ptr
;
451 /* setup background texture */
452 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
453 if (!menu
->flags
.brother
) {
454 FREE_PIXMAP(menu
->menu_texture_data
);
456 menu
->menu_texture_data
= renderTexture(menu
);
458 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
, menu
->menu_texture_data
);
459 XClearWindow(dpy
, menu
->menu
->window
);
461 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
, menu
->menu_texture_data
);
462 XClearWindow(dpy
, menu
->brother
->menu
->window
);
465 XSetWindowBackground(dpy
, menu
->menu
->window
, scr
->menu_item_texture
->any
.color
.pixel
);
466 XClearWindow(dpy
, menu
->menu
->window
);
470 void wMenuRealize(WMenu
* menu
)
473 int width
, rwidth
, mrwidth
, mwidth
;
474 int theight
, twidth
, eheight
;
475 WScreen
*scr
= menu
->frame
->screen_ptr
;
476 static int brother_done
= 0;
481 wMenuRealize(menu
->brother
);
485 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
486 if (menu
->flags
.titled
)
487 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
489 wFrameWindowUpdateBorders(menu
->frame
, flags
);
491 if (menu
->flags
.titled
) {
492 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
, strlen(menu
->frame
->title
));
493 theight
= menu
->frame
->top_width
;
494 twidth
+= theight
+ (wPreferences
.new_style
== TS_NEW
? 16 : 8);
499 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
500 menu
->entry_height
= eheight
;
503 for (i
= 0; i
< menu
->entry_no
; i
++) {
506 /* search widest text */
507 text
= menu
->entries
[i
]->text
;
508 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
)) + 10;
510 if (menu
->entries
[i
]->flags
.indicator
) {
511 width
+= MENU_INDICATOR_SPACE
;
517 /* search widest text on right */
518 text
= menu
->entries
[i
]->rtext
;
520 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
522 else if (menu
->entries
[i
]->cascade
>= 0)
527 if (rwidth
> mrwidth
)
535 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
* eheight
- 1);
537 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
* eheight
- 1
538 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
542 menu
->flags
.realized
= 1;
544 if (menu
->flags
.mapped
)
546 if (menu
->brother
->flags
.mapped
)
547 wMenuPaint(menu
->brother
);
550 void wMenuDestroy(WMenu
* menu
, int recurse
)
554 WMRemoveNotificationObserver(menu
);
556 /* remove any pending timers */
558 WMDeleteTimerHandler(menu
->timer
);
561 /* call destroy handler */
562 if (menu
->on_destroy
)
563 (*menu
->on_destroy
) (menu
);
565 /* Destroy items if this menu own them. If this is the "brother" menu,
566 * leave them alone as it is shared by them.
568 if (!menu
->flags
.brother
) {
569 for (i
= 0; i
< menu
->entry_no
; i
++) {
571 wfree(menu
->entries
[i
]->text
);
573 if (menu
->entries
[i
]->rtext
)
574 wfree(menu
->entries
[i
]->rtext
);
577 if (menu
->entries
[i
]->instances
) {
578 WMReleasePropList(menu
->entries
[i
]->instances
);
580 #endif /* USER_MENU */
582 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
583 (*menu
->entries
[i
]->free_cdata
) (menu
->entries
[i
]->clientdata
);
585 wfree(menu
->entries
[i
]);
589 for (i
= 0; i
< menu
->cascade_no
; i
++) {
590 if (menu
->cascades
[i
]) {
591 if (menu
->cascades
[i
]->flags
.brother
)
592 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
594 wMenuDestroy(menu
->cascades
[i
], recurse
);
600 wfree(menu
->entries
);
604 FREE_PIXMAP(menu
->menu_texture_data
);
607 wfree(menu
->cascades
);
609 wCoreDestroy(menu
->menu
);
610 wFrameWindowDestroy(menu
->frame
);
612 /* destroy copy of this menu */
613 if (!menu
->flags
.brother
&& menu
->brother
)
614 wMenuDestroy(menu
->brother
, False
);
624 static void drawFrame(WScreen
* scr
, Drawable win
, int y
, int w
, int h
, int type
)
630 segs
[i
].x1
= segs
[i
].x2
= w
- 1;
632 segs
[i
].y2
= y
+ h
- 1;
634 if (type
!= F_TOP
&& type
!= F_NONE
) {
636 segs
[i
].y1
= segs
[i
].y2
= y
+ h
- 2;
640 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
646 segs
[i
].y2
= y
+ h
- 1;
648 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
655 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
657 if (type
!= F_TOP
&& type
!= F_NONE
)
658 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+ h
- 1, w
- 1, y
+ h
- 1);
661 static void paintEntry(WMenu
* menu
, int index
, int selected
)
663 WScreen
*scr
= menu
->frame
->screen_ptr
;
664 Window win
= menu
->menu
->window
;
665 WMenuEntry
*entry
= menu
->entries
[index
];
671 if (!menu
->flags
.realized
)
673 h
= menu
->entry_height
;
674 w
= menu
->menu
->width
;
677 light
= scr
->menu_item_auxtexture
->light_gc
;
678 dim
= scr
->menu_item_auxtexture
->dim_gc
;
679 dark
= scr
->menu_item_auxtexture
->dark_gc
;
681 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
684 else if (index
== menu
->entry_no
- 1)
692 /* paint background */
694 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+ 1, w
- 2, h
- 3);
695 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
696 drawFrame(scr
, win
, y
, w
, h
, type
);
698 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
699 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
701 drawFrame(scr
, win
, y
, w
, h
, type
);
703 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
708 if (entry
->flags
.enabled
)
709 color
= scr
->select_text_color
;
711 color
= scr
->dtext_color
;
712 } else if (!entry
->flags
.enabled
) {
713 color
= scr
->dtext_color
;
715 color
= scr
->mtext_color
;
719 if (entry
->flags
.indicator
)
720 x
+= MENU_INDICATOR_SPACE
+ 2;
722 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
723 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
725 if (entry
->cascade
>= 0) {
726 /* draw the cascade indicator */
727 XDrawLine(dpy
, win
, dim
, w
- 11, y
+ 6, w
- 6, y
+ h
/ 2 - 1);
728 XDrawLine(dpy
, win
, light
, w
- 11, y
+ h
- 8, w
- 6, y
+ h
/ 2 - 1);
729 XDrawLine(dpy
, win
, dark
, w
- 12, y
+ 6, w
- 12, y
+ h
- 8);
733 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
737 switch (entry
->flags
.indicator_type
) {
739 indicator
= scr
->menu_check_indicator
;
742 indicator
= scr
->menu_mini_indicator
;
745 indicator
= scr
->menu_hide_indicator
;
748 indicator
= scr
->menu_shade_indicator
;
752 indicator
= scr
->menu_radio_indicator
;
756 iw
= indicator
->width
;
757 ih
= indicator
->height
;
758 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
759 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2);
761 if (entry
->flags
.enabled
) {
762 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
764 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
767 if (entry
->flags
.enabled
) {
768 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
770 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
773 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2, iw
, ih
);
775 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
776 iw, ih, 5, y+(h-ih)/2);
778 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
781 /* draw right text */
783 if (entry
->rtext
&& entry
->cascade
< 0) {
784 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
, strlen(entry
->rtext
));
786 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
- 6 - tw
,
787 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
791 static void move_menus(WMenu
* menu
, int x
, int y
)
793 while (menu
->parent
) {
796 if (!wPreferences
.align_menus
&& menu
->selected_entry
>= 0) {
797 y
-= menu
->selected_entry
* menu
->entry_height
;
800 wMenuMove(menu
, x
, y
, True
);
803 static void makeVisible(WMenu
* menu
)
805 WScreen
*scr
= menu
->frame
->screen_ptr
;
806 int x1
, y1
, x2
, y2
, new_x
, new_y
;
807 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
809 if (menu
->entry_no
< 0)
813 y1
= menu
->frame_y
+ menu
->frame
->top_width
+ menu
->selected_entry
* menu
->entry_height
;
814 x2
= x1
+ MENUW(menu
);
815 y2
= y1
+ menu
->entry_height
;
820 if (x1
< rect
.pos
.x
) {
822 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
823 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
826 if (y1
< rect
.pos
.y
) {
828 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
829 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
832 new_y
= new_y
- menu
->frame
->top_width
- menu
->selected_entry
* menu
->entry_height
;
833 move_menus(menu
, new_x
, new_y
);
836 static int check_key(WMenu
* menu
, XKeyEvent
* event
)
841 if (XLookupString(event
, buffer
, 32, NULL
, NULL
) < 1)
844 ch
= toupper(buffer
[0]);
846 s
= (menu
->selected_entry
>= 0 ? menu
->selected_entry
+ 1 : 0);
849 for (i
= s
; i
< menu
->entry_no
; i
++) {
850 if (ch
== toupper(menu
->entries
[i
]->text
[0])) {
854 /* no match. Retry from start, if previous started from a selected entry */
862 static int keyboardMenu(WMenu
* menu
)
865 KeySym ksym
= NoSymbol
;
869 int old_pos_x
= menu
->frame_x
;
870 int old_pos_y
= menu
->frame_y
;
871 int new_x
= old_pos_x
, new_y
= old_pos_y
;
872 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
873 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
875 if (menu
->flags
.editing
)
878 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
880 if (menu
->frame_y
+ menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
881 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
883 if (menu
->frame_x
+ MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
884 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
886 move_menus(menu
, new_x
, new_y
);
888 while (!done
&& menu
->flags
.mapped
) {
889 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
890 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonPressMask
891 | ButtonReleaseMask
| KeyPressMask
| KeyReleaseMask
| SubstructureNotifyMask
, &event
);
893 switch (event
.type
) {
895 ksym
= XLookupKeysym(&event
.xkey
, 0);
896 if (wPreferences
.vi_key_menus
) {
925 selectEntry(menu
, 0);
933 selectEntry(menu
, menu
->entry_no
- 1);
941 if (menu
->selected_entry
<= 0)
942 selectEntry(menu
, menu
->entry_no
- 1);
944 selectEntry(menu
, menu
->selected_entry
- 1);
952 if (menu
->selected_entry
< 0)
953 selectEntry(menu
, 0);
954 else if (menu
->selected_entry
== menu
->entry_no
- 1)
955 selectEntry(menu
, 0);
956 else if (menu
->selected_entry
< menu
->entry_no
- 1)
957 selectEntry(menu
, menu
->selected_entry
+ 1);
965 if (menu
->selected_entry
>= 0) {
967 entry
= menu
->entries
[menu
->selected_entry
];
969 if (entry
->cascade
>= 0 && menu
->cascades
970 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
972 XUngrabKeyboard(dpy
, CurrentTime
);
974 selectEntry(menu
->cascades
[entry
->cascade
], 0);
975 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
978 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
979 GrabModeAsync
, GrabModeAsync
, CurrentTime
);
988 if (menu
->parent
!= NULL
&& menu
->parent
->selected_entry
>= 0) {
989 selectEntry(menu
, -1);
990 move_menus(menu
, old_pos_x
, old_pos_y
);
1003 index
= check_key(menu
, &event
.xkey
);
1005 selectEntry(menu
, index
);
1011 if (event
.type
== ButtonPress
)
1014 WMHandleEvent(&event
);
1018 XUngrabKeyboard(dpy
, CurrentTime
);
1020 if (done
== 2 && menu
->selected_entry
>= 0) {
1021 entry
= menu
->entries
[menu
->selected_entry
];
1026 if (entry
&& entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1027 #if (MENU_BLINK_COUNT > 0)
1028 int sel
= menu
->selected_entry
;
1031 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1032 paintEntry(menu
, sel
, False
);
1034 wusleep(MENU_BLINK_DELAY
);
1035 paintEntry(menu
, sel
, True
);
1037 wusleep(MENU_BLINK_DELAY
);
1040 selectEntry(menu
, -1);
1042 if (!menu
->flags
.buttoned
) {
1044 move_menus(menu
, old_pos_x
, old_pos_y
);
1048 (*entry
->callback
) (menu
, entry
);
1050 if (!menu
->flags
.buttoned
) {
1052 move_menus(menu
, old_pos_x
, old_pos_y
);
1054 selectEntry(menu
, -1);
1057 /* returns True if returning from a submenu to a parent menu,
1058 * False if exiting from menu */
1062 void wMenuMapAt(WMenu
* menu
, int x
, int y
, int keyboard
)
1064 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1065 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1067 if (!menu
->flags
.realized
) {
1068 menu
->flags
.realized
= 1;
1071 if (!menu
->flags
.mapped
) {
1072 if (wPreferences
.wrap_menus
) {
1077 if (x
+ MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1078 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1079 if (y
+ MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1080 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1083 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1086 XMapWindow(dpy
, menu
->frame
->core
->window
);
1087 wRaiseFrame(menu
->frame
->core
);
1088 menu
->flags
.mapped
= 1;
1090 selectEntry(menu
, 0);
1097 void wMenuMap(WMenu
* menu
)
1099 if (!menu
->flags
.realized
) {
1100 menu
->flags
.realized
= 1;
1103 if (menu
->flags
.app_menu
&& menu
->parent
== NULL
) {
1104 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1105 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1106 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1108 XMapWindow(dpy
, menu
->frame
->core
->window
);
1109 wRaiseFrame(menu
->frame
->core
);
1110 menu
->flags
.mapped
= 1;
1113 void wMenuUnmap(WMenu
* menu
)
1117 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1118 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1119 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1121 menu
->flags
.buttoned
= 0;
1122 menu
->flags
.mapped
= 0;
1123 menu
->flags
.open_to_left
= 0;
1125 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1126 if (menu
->cascades
[i
] != NULL
1127 && menu
->cascades
[i
]->flags
.mapped
&& !menu
->cascades
[i
]->flags
.buttoned
) {
1129 wMenuUnmap(menu
->cascades
[i
]);
1132 menu
->selected_entry
= -1;
1135 void wMenuPaint(WMenu
* menu
)
1139 if (!menu
->flags
.mapped
) {
1144 for (i
= 0; i
< menu
->entry_no
; i
++) {
1145 paintEntry(menu
, i
, i
== menu
->selected_entry
);
1149 void wMenuSetEnabled(WMenu
* menu
, int index
, int enable
)
1151 if (index
>= menu
->entry_no
)
1153 menu
->entries
[index
]->flags
.enabled
= enable
;
1154 paintEntry(menu
, index
, index
== menu
->selected_entry
);
1155 paintEntry(menu
->brother
, index
, index
== menu
->selected_entry
);
1159 static void selectEntry(WMenu
* menu
, int entry_no
)
1165 if (menu
->entries
== NULL
)
1168 if (entry_no
>= menu
->entry_no
)
1171 old_entry
= menu
->selected_entry
;
1172 menu
->selected_entry
= entry_no
;
1174 if (old_entry
!= entry_no
) {
1176 /* unselect previous entry */
1177 if (old_entry
>= 0) {
1178 paintEntry(menu
, old_entry
, False
);
1179 entry
= menu
->entries
[old_entry
];
1182 if (entry
->cascade
>= 0 && menu
->cascades
) {
1183 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1184 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1190 menu
->selected_entry
= -1;
1193 entry
= menu
->entries
[entry_no
];
1195 if (entry
->cascade
>= 0 && menu
->cascades
&& entry
->flags
.enabled
) {
1196 /* Callback for when the submenu is opened.
1198 submenu
= menu
->cascades
[entry
->cascade
];
1199 if (submenu
&& submenu
->flags
.brother
)
1200 submenu
= submenu
->brother
;
1202 if (entry
->callback
) {
1203 /* Only call the callback if the submenu is not yet mapped.
1205 if (menu
->flags
.brother
) {
1206 if (!submenu
|| !submenu
->flags
.mapped
)
1207 (*entry
->callback
) (menu
->brother
, entry
);
1209 if (!submenu
|| !submenu
->flags
.buttoned
)
1210 (*entry
->callback
) (menu
, entry
);
1214 /* the submenu menu might have changed */
1215 submenu
= menu
->cascades
[entry
->cascade
];
1218 if (!submenu
->flags
.mapped
) {
1221 if (!submenu
->flags
.realized
)
1222 wMenuRealize(submenu
);
1223 if (wPreferences
.wrap_menus
) {
1224 if (menu
->flags
.open_to_left
)
1225 submenu
->flags
.open_to_left
= 1;
1227 if (submenu
->flags
.open_to_left
) {
1228 x
= menu
->frame_x
- MENUW(submenu
);
1231 submenu
->flags
.open_to_left
= 0;
1234 x
= menu
->frame_x
+ MENUW(menu
);
1236 if (x
+ MENUW(submenu
)
1237 >= menu
->frame
->screen_ptr
->scr_width
) {
1239 x
= menu
->frame_x
- MENUW(submenu
);
1240 submenu
->flags
.open_to_left
= 1;
1244 x
= menu
->frame_x
+ MENUW(menu
);
1247 if (wPreferences
.align_menus
) {
1250 y
= menu
->frame_y
+ menu
->entry_height
* entry_no
;
1251 if (menu
->flags
.titled
)
1252 y
+= menu
->frame
->top_width
;
1253 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1254 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1257 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1258 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1263 paintEntry(menu
, entry_no
, True
);
1267 static WMenu
*findMenu(WScreen
* scr
, int *x_ret
, int *y_ret
)
1270 WObjDescriptor
*desc
;
1271 Window root_ret
, win
, junk_win
;
1275 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
, &mask
);
1280 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1283 if (desc
->parent_type
== WCLASS_MENU
) {
1284 menu
= (WMenu
*) desc
->parent
;
1285 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
, x_ret
, y_ret
, &junk_win
);
1291 static void closeCascade(WMenu
* menu
)
1293 WMenu
*parent
= menu
->parent
;
1295 if (menu
->flags
.brother
|| (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
))) {
1297 selectEntry(menu
, -1);
1299 #if (MENU_BLINK_DELAY > 2)
1300 wusleep(MENU_BLINK_DELAY
/ 2);
1303 while (parent
!= NULL
1304 && (parent
->parent
!= NULL
|| !parent
->flags
.app_menu
|| parent
->flags
.brother
)
1305 && !parent
->flags
.buttoned
) {
1306 selectEntry(parent
, -1);
1308 parent
= parent
->parent
;
1311 selectEntry(parent
, -1);
1315 static void closeBrotherCascadesOf(WMenu
* menu
)
1320 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1321 if (menu
->cascades
[i
]->flags
.brother
) {
1322 tmp
= menu
->cascades
[i
];
1324 tmp
= menu
->cascades
[i
]->brother
;
1326 if (tmp
->flags
.mapped
) {
1327 selectEntry(tmp
->parent
, -1);
1328 closeBrotherCascadesOf(tmp
);
1334 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1336 static WMenu
*parentMenu(WMenu
* menu
)
1341 if (menu
->flags
.buttoned
)
1344 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1345 parent
= menu
->parent
;
1346 if (parent
->selected_entry
< 0)
1348 entry
= parent
->entries
[parent
->selected_entry
];
1349 if (!entry
->flags
.enabled
|| entry
->cascade
< 0 || !parent
->cascades
||
1350 parent
->cascades
[entry
->cascade
] != menu
)
1353 if (menu
->flags
.buttoned
)
1361 * Will raise the passed menu, if submenu = 0
1362 * If submenu > 0 will also raise all mapped submenus
1363 * until the first buttoned one
1364 * If submenu < 0 will also raise all mapped parent menus
1365 * until the first buttoned one
1368 static void raiseMenus(WMenu
* menu
, int submenus
)
1376 wRaiseFrame(menu
->frame
->core
);
1378 if (submenus
> 0 && menu
->selected_entry
>= 0) {
1379 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1380 if (i
>= 0 && menu
->cascades
) {
1381 submenu
= menu
->cascades
[i
];
1382 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1383 raiseMenus(submenu
, submenus
);
1386 if (submenus
< 0 && !menu
->flags
.buttoned
&& menu
->parent
&& menu
->parent
->flags
.mapped
)
1387 raiseMenus(menu
->parent
, submenus
);
1390 WMenu
*wMenuUnderPointer(WScreen
* screen
)
1392 WObjDescriptor
*desc
;
1393 Window root_ret
, win
;
1397 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
, &dummy
, &dummy
, &mask
);
1402 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1405 if (desc
->parent_type
== WCLASS_MENU
)
1406 return (WMenu
*) desc
->parent
;
1410 static void getPointerPosition(WScreen
* scr
, int *x
, int *y
)
1412 Window root_ret
, win
;
1416 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1419 static void getScrollAmount(WMenu
* menu
, int *hamount
, int *vamount
)
1421 WScreen
*scr
= menu
->menu
->screen_ptr
;
1422 int menuX1
= menu
->frame_x
;
1423 int menuY1
= menu
->frame_y
;
1424 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1425 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1427 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1432 getPointerPosition(scr
, &xroot
, &yroot
);
1434 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1435 /* scroll to the right */
1436 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1438 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) && menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1439 /* scroll to the left */
1440 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
- rect
.pos
.x
- rect
.size
.width
- 1));
1445 *hamount
= -*hamount
;
1448 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1450 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1452 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) && menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1454 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
- rect
.pos
.y
- rect
.size
.height
- 2));
1456 *vamount
= -*vamount
;
1460 static void dragScrollMenuCallback(void *data
)
1462 WMenu
*menu
= (WMenu
*) data
;
1463 WScreen
*scr
= menu
->menu
->screen_ptr
;
1464 WMenu
*parent
= parentMenu(menu
);
1465 int hamount
, vamount
;
1467 int newSelectedEntry
;
1469 getScrollAmount(menu
, &hamount
, &vamount
);
1471 if (hamount
!= 0 || vamount
!= 0) {
1472 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1473 if (findMenu(scr
, &x
, &y
)) {
1474 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1475 selectEntry(menu
, newSelectedEntry
);
1477 /* Pointer fell outside of menu. If the selected entry is
1478 * not a submenu, unselect it */
1479 if (menu
->selected_entry
>= 0 && menu
->entries
[menu
->selected_entry
]->cascade
< 0)
1480 selectEntry(menu
, -1);
1481 newSelectedEntry
= 0;
1484 /* paranoid check */
1485 if (newSelectedEntry
>= 0) {
1486 /* keep scrolling */
1487 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, dragScrollMenuCallback
, menu
);
1492 /* don't need to scroll anymore */
1494 if (findMenu(scr
, &x
, &y
)) {
1495 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1496 selectEntry(menu
, newSelectedEntry
);
1501 static void scrollMenuCallback(void *data
)
1503 WMenu
*menu
= (WMenu
*) data
;
1504 WMenu
*parent
= parentMenu(menu
);
1505 int hamount
= 0; /* amount to scroll */
1508 getScrollAmount(menu
, &hamount
, &vamount
);
1510 if (hamount
!= 0 || vamount
!= 0) {
1511 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1513 /* keep scrolling */
1514 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, scrollMenuCallback
, menu
);
1516 /* don't need to scroll anymore */
1521 #define MENU_SCROLL_BORDER 5
1523 static int isPointNearBoder(WMenu
* menu
, int x
, int y
)
1525 int menuX1
= menu
->frame_x
;
1526 int menuY1
= menu
->frame_y
;
1527 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1528 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1530 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1531 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1533 /* XXX: handle screen joins properly !! */
1535 if (x
>= menuX1
&& x
<= menuX2
&&
1536 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
|| y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1538 else if (y
>= menuY1
&& y
<= menuY2
&&
1539 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
|| x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1545 typedef struct _delay
{
1550 static void leaving(_delay
* dl
)
1552 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1553 dl
->menu
->jump_back
= NULL
;
1554 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1558 void wMenuScroll(WMenu
* menu
, XEvent
* event
)
1561 WMenu
*omenu
= parentMenu(menu
);
1562 WScreen
*scr
= menu
->frame
->screen_ptr
;
1565 int old_frame_x
= omenu
->frame_x
;
1566 int old_frame_y
= omenu
->frame_y
;
1569 if (omenu
->jump_back
)
1570 WMDeleteTimerWithClientData(omenu
->jump_back
);
1572 if (( /*omenu->flags.buttoned && */ !wPreferences
.wrap_menus
)
1573 || omenu
->flags
.app_menu
) {
1577 if (!wPreferences
.wrap_menus
)
1578 raiseMenus(omenu
, True
);
1580 raiseMenus(menu
, False
);
1583 scrollMenuCallback(menu
);
1586 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1589 WMNextEvent(dpy
, &ev
);
1594 x
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1595 y
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1597 /* on_border is != 0 if the pointer is between the menu
1598 * and the screen border and is close enough to the border */
1599 on_border
= isPointNearBoder(menu
, x
, y
);
1601 smenu
= wMenuUnderPointer(scr
);
1603 if ((smenu
== NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
) != omenu
)) {
1608 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1609 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1610 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1611 on_border
= on_x_edge
|| on_y_edge
;
1613 if (!on_border
&& !jump_back
) {
1618 if (menu
->timer
&& (smenu
!= menu
|| (!on_y_edge
&& !on_x_edge
))) {
1619 WMDeleteTimerHandler(menu
->timer
);
1627 scrollMenuCallback(menu
);
1630 /* True if we push on title, or drag the omenu to other position */
1631 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1632 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1633 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1634 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1636 smenu
= wMenuUnderPointer(scr
);
1637 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1639 else if (smenu
== omenu
&& on_title
) {
1653 WMDeleteTimerHandler(menu
->timer
);
1659 if (!omenu
->jump_back
) {
1660 delayer
= wmalloc(sizeof(_delay
));
1661 delayer
->menu
= omenu
;
1662 delayer
->ox
= old_frame_x
;
1663 delayer
->oy
= old_frame_y
;
1664 omenu
->jump_back
= delayer
;
1665 scr
->flags
.jump_back_pending
= 1;
1667 delayer
= omenu
->jump_back
;
1668 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
, (WMCallback
*) leaving
, delayer
);
1672 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
)
1674 wMenuPaint(desc
->parent
);
1678 int *delayed_select
;
1683 static void delaySelection(void *data
)
1685 delay_data
*d
= (delay_data
*) data
;
1691 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1692 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1693 entry_no
= getEntryAt(menu
, x
, y
);
1694 selectEntry(menu
, entry_no
);
1696 if (d
->delayed_select
)
1697 *(d
->delayed_select
) = 0;
1700 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
1703 XButtonEvent
*bev
= &event
->xbutton
;
1704 WMenu
*menu
= desc
->parent
;
1706 WScreen
*scr
= menu
->frame
->screen_ptr
;
1707 WMenuEntry
*entry
= NULL
;
1709 int close_on_exit
= 0;
1711 int delayed_select
= 0;
1715 int old_frame_x
= 0;
1716 int old_frame_y
= 0;
1717 delay_data d_data
= { NULL
, NULL
, NULL
};
1719 /* Doesn't seem to be needed anymore (if delayed selection handler is
1720 * added only if not present). there seem to be no other side effects
1721 * from removing this and it is also possible that it was only added
1722 * to avoid problems with adding the delayed selection timer handler
1725 /*if (menu->flags.inside_handler) {
1728 menu
->flags
.inside_handler
= 1;
1730 if (!wPreferences
.wrap_menus
) {
1731 smenu
= parentMenu(menu
);
1732 old_frame_x
= smenu
->frame_x
;
1733 old_frame_y
= smenu
->frame_y
;
1734 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1735 /* This is true if the menu was launched with right click on root window */
1736 if (!d_data
.magic
) {
1738 d_data
.delayed_select
= &delayed_select
;
1740 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
, delaySelection
, &d_data
);
1744 wRaiseFrame(menu
->frame
->core
);
1746 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1748 smenu
= findMenu(scr
, &x
, &y
);
1756 if (menu
->flags
.editing
) {
1759 entry_no
= getEntryAt(menu
, x
, y
);
1760 if (entry_no
>= 0) {
1761 entry
= menu
->entries
[entry_no
];
1763 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
&& entry
->flags
.editable
) {
1766 int number
= entry_no
- 2; /* Entries "New" and "Destroy Last" appear before workspaces */
1768 name
= wstrdup(scr
->workspaces
[number
]->name
);
1769 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), number
+ 1);
1771 wMenuUnmap(scr
->root_menu
);
1773 if (wInputDialog(scr
, _("Rename Workspace"), buffer
, &name
))
1774 wWorkspaceRename(scr
, number
, name
);
1780 } else if (bev
->state
& ControlMask
) {
1784 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1785 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1787 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&& menu
->selected_entry
!= entry_no
) {
1788 wMenuUnmap(submenu
);
1790 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1791 selectEntry(menu
, entry_no
);
1792 } else if (!submenu
->flags
.buttoned
) {
1793 selectEntry(menu
, -1);
1796 } else if (!delayed_select
) {
1797 if (menu
== scr
->switch_menu
&& event
->xbutton
.button
== Button3
) {
1798 selectEntry(menu
, entry_no
);
1799 OpenWindowMenu2((WWindow
*)entry
->clientdata
,
1800 event
->xbutton
.x_root
,
1801 event
->xbutton
.y_root
, False
);
1802 wwin
= (WWindow
*)entry
->clientdata
;
1803 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
1804 event
->xany
.send_event
= True
;
1805 (*desc
->handle_mousedown
)(desc
, event
);
1807 XUngrabPointer(dpy
, CurrentTime
);
1808 selectEntry(menu
, -1);
1811 selectEntry(menu
, entry_no
);
1815 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
1817 dragScrollMenuCallback(menu
);
1821 prevx
= bev
->x_root
;
1822 prevy
= bev
->y_root
;
1826 XAllowEvents(dpy
, AsyncPointer
| SyncPointer
, CurrentTime
);
1828 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
1831 smenu
= findMenu(scr
, &x
, &y
);
1833 if (smenu
== NULL
) {
1834 /* moved mouse out of menu */
1836 if (!delayed_select
&& d_data
.magic
) {
1837 WMDeleteTimerHandler(d_data
.magic
);
1838 d_data
.magic
= NULL
;
1841 || (menu
->selected_entry
>= 0
1842 && menu
->entries
[menu
->selected_entry
]->cascade
>= 0)) {
1843 prevx
= ev
.xmotion
.x_root
;
1844 prevy
= ev
.xmotion
.y_root
;
1848 selectEntry(menu
, -1);
1850 prevx
= ev
.xmotion
.x_root
;
1851 prevy
= ev
.xmotion
.y_root
;
1853 } else if (menu
&& menu
!= smenu
1854 && (menu
->selected_entry
< 0
1855 || menu
->entries
[menu
->selected_entry
]->cascade
< 0)) {
1856 selectEntry(menu
, -1);
1858 if (!delayed_select
&& d_data
.magic
) {
1859 WMDeleteTimerHandler(d_data
.magic
);
1860 d_data
.magic
= NULL
;
1864 /* hysteresis for item selection */
1866 /* check if the motion was to the side, indicating that
1867 * the user may want to cross to a submenu */
1868 if (!delayed_select
&& menu
) {
1870 Bool moved_to_submenu
; /* moved to direction of submenu */
1872 dx
= abs(prevx
- ev
.xmotion
.x_root
);
1874 moved_to_submenu
= False
;
1875 if (dx
> 0 /* if moved enough to the side */
1876 /* maybe a open submenu */
1877 && menu
->selected_entry
>= 0
1878 /* moving to the right direction */
1879 && (wPreferences
.align_menus
|| ev
.xmotion
.y_root
>= prevy
)) {
1882 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
1884 if (menu
->cascades
[index
]->frame_x
> menu
->frame_x
) {
1885 if (prevx
< ev
.xmotion
.x_root
)
1886 moved_to_submenu
= True
;
1888 if (prevx
> ev
.xmotion
.x_root
)
1889 moved_to_submenu
= True
;
1894 if (menu
!= smenu
) {
1896 WMDeleteTimerHandler(d_data
.magic
);
1897 d_data
.magic
= NULL
;
1899 } else if (moved_to_submenu
) {
1900 /* while we are moving, postpone the selection */
1902 WMDeleteTimerHandler(d_data
.magic
);
1904 d_data
.delayed_select
= NULL
;
1906 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
1907 delaySelection
, &d_data
);
1908 prevx
= ev
.xmotion
.x_root
;
1909 prevy
= ev
.xmotion
.y_root
;
1913 WMDeleteTimerHandler(d_data
.magic
);
1914 d_data
.magic
= NULL
;
1919 prevx
= ev
.xmotion
.x_root
;
1920 prevy
= ev
.xmotion
.y_root
;
1921 if (menu
!= smenu
) {
1922 /* pointer crossed menus */
1923 if (menu
&& menu
->timer
) {
1924 WMDeleteTimerHandler(menu
->timer
);
1928 dragScrollMenuCallback(smenu
);
1932 dragScrollMenuCallback(menu
);
1934 if (!delayed_select
) {
1935 entry_no
= getEntryAt(menu
, x
, y
);
1936 if (entry_no
>= 0) {
1937 entry
= menu
->entries
[entry_no
];
1938 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1939 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1940 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
1941 && menu
->selected_entry
!= entry_no
) {
1942 wMenuUnmap(submenu
);
1946 selectEntry(menu
, entry_no
);
1954 if (ev
.xbutton
.button
== event
->xbutton
.button
)
1964 if (menu
&& menu
->timer
) {
1965 WMDeleteTimerHandler(menu
->timer
);
1968 if (d_data
.magic
!= NULL
) {
1969 WMDeleteTimerHandler(d_data
.magic
);
1970 d_data
.magic
= NULL
;
1973 if (menu
&& menu
->selected_entry
>= 0) {
1974 entry
= menu
->entries
[menu
->selected_entry
];
1975 if (entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1976 /* blink and erase menu selection */
1977 #if (MENU_BLINK_DELAY > 0)
1978 int sel
= menu
->selected_entry
;
1981 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1982 paintEntry(menu
, sel
, False
);
1984 wusleep(MENU_BLINK_DELAY
);
1985 paintEntry(menu
, sel
, True
);
1987 wusleep(MENU_BLINK_DELAY
);
1990 /* unmap the menu, it's parents and call the callback */
1991 if (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
1994 selectEntry(menu
, -1);
1996 (*entry
->callback
) (menu
, entry
);
1998 /* If the user double clicks an entry, the entry will
1999 * be executed twice, which is not good for things like
2000 * the root menu. So, ignore any clicks that were generated
2001 * while the entry was being executed */
2002 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
, ButtonPress
, &ev
)) ;
2003 } else if (entry
->callback
!= NULL
&& entry
->cascade
< 0) {
2004 selectEntry(menu
, -1);
2006 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2007 selectEntry(menu
, -1);
2012 if (((WMenu
*) desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2013 closeCascade(desc
->parent
);
2015 /* close the cascade windows that should not remain opened */
2016 closeBrotherCascadesOf(desc
->parent
);
2018 if (!wPreferences
.wrap_menus
)
2019 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2022 /* Just to be sure in case we skip the 2 above because of a goto byebye */
2023 if (menu
&& menu
->timer
) {
2024 WMDeleteTimerHandler(menu
->timer
);
2027 if (d_data
.magic
!= NULL
) {
2028 WMDeleteTimerHandler(d_data
.magic
);
2029 d_data
.magic
= NULL
;
2032 ((WMenu
*) desc
->parent
)->flags
.inside_handler
= 0;
2035 void wMenuMove(WMenu
* menu
, int x
, int y
, int submenus
)
2045 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2047 if (submenus
> 0 && menu
->selected_entry
>= 0) {
2048 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2050 if (i
>= 0 && menu
->cascades
) {
2051 submenu
= menu
->cascades
[i
];
2052 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2053 if (wPreferences
.align_menus
) {
2054 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2056 wMenuMove(submenu
, x
+ MENUW(menu
),
2057 y
+ submenu
->entry_height
* menu
->selected_entry
, submenus
);
2062 if (submenus
< 0 && menu
->parent
!= NULL
&& menu
->parent
->flags
.mapped
&& !menu
->parent
->flags
.buttoned
) {
2063 if (wPreferences
.align_menus
) {
2064 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2066 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2067 - menu
->parent
->entry_height
* menu
->parent
->selected_entry
, submenus
);
2072 static void changeMenuLevels(WMenu
* menu
, int lower
)
2077 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
: WMSubmenuLevel
));
2078 wRaiseFrame(menu
->frame
->core
);
2079 menu
->flags
.lowered
= 0;
2081 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2082 wLowerFrame(menu
->frame
->core
);
2083 menu
->flags
.lowered
= 1;
2085 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2086 if (menu
->cascades
[i
]
2087 && !menu
->cascades
[i
]->flags
.buttoned
&& menu
->cascades
[i
]->flags
.lowered
!= lower
) {
2088 changeMenuLevels(menu
->cascades
[i
], lower
);
2093 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2098 if (event
->xbutton
.state
& MOD_MASK
) {
2099 if (menu
->flags
.lowered
) {
2104 changeMenuLevels(menu
, lower
);
2108 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2113 int x
= menu
->frame_x
, y
= menu
->frame_y
;
2114 int dx
= event
->xbutton
.x_root
, dy
= event
->xbutton
.y_root
;
2118 /* can't touch the menu copy */
2119 if (menu
->flags
.brother
)
2122 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2125 if (event
->xbutton
.state
& MOD_MASK
) {
2126 wLowerFrame(menu
->frame
->core
);
2129 wRaiseFrame(menu
->frame
->core
);
2134 /* lower/raise all submenus */
2136 if (tmp
->selected_entry
>= 0 && tmp
->cascades
&& tmp
->entries
[tmp
->selected_entry
]->cascade
>= 0) {
2137 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2138 if (!tmp
|| !tmp
->flags
.mapped
)
2141 wLowerFrame(tmp
->frame
->core
);
2143 wRaiseFrame(tmp
->frame
->core
);
2149 /* tear off the menu if it's a root menu or a cascade
2151 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
2152 menu
->flags
.buttoned
= 1;
2153 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2155 /* turn off selected menu entry in parent menu */
2156 selectEntry(menu
->parent
, -1);
2158 /* make parent map the copy in place of the original */
2159 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2160 if (menu
->parent
->cascades
[i
] == menu
) {
2161 menu
->parent
->cascades
[i
] = menu
->brother
;
2170 WMMaskEvent(dpy
, ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &ev
);
2174 x
+= ev
.xmotion
.x_root
- dx
;
2175 y
+= ev
.xmotion
.y_root
- dy
;
2176 dx
= ev
.xmotion
.x_root
;
2177 dy
= ev
.xmotion
.y_root
;
2178 wMenuMove(menu
, x
, y
, True
);
2180 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2181 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2183 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2184 ButtonMotionMask
| ButtonReleaseMask
2186 GrabModeAsync
, GrabModeAsync
, None
,
2187 wCursor
[WCUR_MOVE
], CurrentTime
);
2196 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2198 XUngrabPointer(dpy
, CurrentTime
);
2209 *----------------------------------------------------------------------
2211 * Handles mouse click on the close button of menus. The menu is
2212 * closed when the button is clicked.
2215 * The closed menu is reinserted at it's parent menus
2217 *----------------------------------------------------------------------
2219 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2221 WMenu
*menu
= (WMenu
*) data
;
2222 WMenu
*parent
= menu
->parent
;
2226 for (i
= 0; i
< parent
->cascade_no
; i
++) {
2227 /* find the entry that points to the copy */
2228 if (parent
->cascades
[i
] == menu
->brother
) {
2229 /* make it point to the original */
2230 parent
->cascades
[i
] = menu
;
2231 menu
->parent
= parent
;
2239 static void saveMenuInfo(WMPropList
* dict
, WMenu
* menu
, WMPropList
* key
)
2241 WMPropList
*value
, *list
;
2244 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2245 value
= WMCreatePLString(buffer
);
2246 list
= WMCreatePLArray(value
, NULL
);
2247 if (menu
->flags
.lowered
)
2248 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2249 WMPutInPLDictionary(dict
, key
, list
);
2250 WMReleasePropList(value
);
2251 WMReleasePropList(list
);
2254 void wMenuSaveState(WScreen
* scr
)
2256 WMPropList
*menus
, *key
;
2259 menus
= WMCreatePLDictionary(NULL
, NULL
);
2261 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2262 key
= WMCreatePLString("SwitchMenu");
2263 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2264 WMReleasePropList(key
);
2268 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2271 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2272 key
= WMCreatePLString("WorkspaceMenu");
2273 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2274 WMReleasePropList(key
);
2279 key
= WMCreatePLString("Menus");
2280 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2281 WMReleasePropList(key
);
2283 WMReleasePropList(menus
);
2286 static Bool
getMenuPath(WMenu
* menu
, char *buffer
, int bufSize
)
2291 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2294 len
= strlen(menu
->frame
->title
);
2299 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2304 strcat(buffer
, "\\");
2305 strcat(buffer
, menu
->frame
->title
);
2310 static Bool
saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
)
2313 int save_menus
= 0, i
;
2317 if (menu
->flags
.brother
)
2318 menu
= menu
->brother
;
2320 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2323 ok
= getMenuPath(menu
, buffer
, 510);
2326 key
= WMCreatePLString(buffer
);
2327 saveMenuInfo(menus
, menu
, key
);
2328 WMReleasePropList(key
);
2334 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2335 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2342 #define COMPLAIN(key) wwarning(_("bad value in menus state info: %s"), key)
2344 static Bool
getMenuInfo(WMPropList
* info
, int *x
, int *y
, Bool
* lowered
)
2350 if (WMIsPLArray(info
)) {
2352 pos
= WMGetFromPLArray(info
, 0);
2353 flags
= WMGetFromPLArray(info
, 1);
2354 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2355 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2362 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2363 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
) != 2)
2364 COMPLAIN("Position");
2366 COMPLAIN("(position, flags...)");
2373 static int restoreMenu(WScreen
* scr
, WMPropList
* menu
, int which
)
2376 Bool lowered
= False
;
2377 WMenu
*pmenu
= NULL
;
2382 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2385 if (which
& WSS_SWITCHMENU
) {
2386 OpenSwitchMenu(scr
, x
, y
, False
);
2387 pmenu
= scr
->switch_menu
;
2391 int width
= MENUW(pmenu
);
2392 int height
= MENUH(pmenu
);
2393 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2396 changeMenuLevels(pmenu
, True
);
2399 if (x
< rect
.pos
.x
- width
)
2401 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2402 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2405 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2406 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2408 wMenuMove(pmenu
, x
, y
, True
);
2409 pmenu
->flags
.buttoned
= 1;
2410 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2416 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
)
2418 WMPropList
*key
, *entry
;
2423 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2426 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2427 key
= WMCreatePLString(buffer
);
2428 entry
= WMGetFromPLDictionary(menus
, key
);
2431 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2433 if (!menu
->flags
.mapped
) {
2434 int width
= MENUW(menu
);
2435 int height
= MENUH(menu
);
2436 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2438 wMenuMapAt(menu
, x
, y
, False
);
2441 /* make parent map the copy in place of the original */
2442 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2443 if (menu
->parent
->cascades
[i
] == menu
) {
2444 menu
->parent
->cascades
[i
] = menu
->brother
;
2450 changeMenuLevels(menu
, True
);
2453 if (x
< rect
.pos
.x
- width
)
2455 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2456 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2459 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2460 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2462 wMenuMove(menu
, x
, y
, True
);
2463 menu
->flags
.buttoned
= 1;
2464 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2469 WMReleasePropList(key
);
2471 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2472 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2479 void wMenuRestoreState(WScreen
* scr
)
2481 WMPropList
*menus
, *menu
, *key
, *skey
;
2483 if (!scr
->session_state
) {
2487 key
= WMCreatePLString("Menus");
2488 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2489 WMReleasePropList(key
);
2496 skey
= WMCreatePLString("SwitchMenu");
2497 menu
= WMGetFromPLDictionary(menus
, skey
);
2498 WMReleasePropList(skey
);
2499 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2501 if (!scr
->root_menu
) {
2502 OpenRootMenu(scr
, scr
->scr_width
* 2, 0, False
);
2503 wMenuUnmap(scr
->root_menu
);
2505 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");