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"
46 /****** Global Variables ******/
48 extern Cursor wCursor
[WCUR_LAST
];
50 extern XContext wWinContext
;
52 extern WPreferences wPreferences
;
54 #define MOD_MASK wPreferences.modifier_mask
56 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
57 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
59 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
60 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
62 /***** Local Stuff ******/
64 #define WSS_ROOTMENU (1<<0)
65 #define WSS_SWITCHMENU (1<<1)
66 #define WSS_WSMENU (1<<2)
71 } menuScrollParameters
[5] = {
73 MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
}, {
74 MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
}, {
75 MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
}, {
76 MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
}, {
77 MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
79 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
80 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
);
81 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
82 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
);
83 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
84 static void updateTexture(WMenu
* menu
);
85 static int saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
);
86 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
);
87 static void selectEntry(WMenu
* menu
, int entry_no
);
88 static void closeCascade(WMenu
* menu
);
90 /****** Notification Observers ******/
92 static void appearanceObserver(void *self
, WMNotification
* notif
)
94 WMenu
*menu
= (WMenu
*) self
;
95 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
97 if (!menu
->flags
.realized
)
100 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
101 if (flags
& WFontSettings
) {
102 menu
->flags
.realized
= 0;
105 if (flags
& WTextureSettings
) {
106 if (!menu
->flags
.brother
)
109 if (flags
& (WTextureSettings
| WColorSettings
)) {
112 } else if (menu
->flags
.titled
) {
114 if (flags
& WFontSettings
) {
115 menu
->flags
.realized
= 0;
118 if (flags
& WTextureSettings
) {
119 menu
->frame
->flags
.need_texture_remake
= 1;
121 if (flags
& (WColorSettings
| WTextureSettings
)) {
122 wFrameWindowPaint(menu
->frame
);
127 /************************************/
130 *----------------------------------------------------------------------
132 * Creates a new empty menu with the specified title. If main_menu
133 * is True, the created menu will be a main menu, which has some special
134 * properties such as being placed over other normal menus.
135 * If title is NULL, the menu will have no titlebar.
139 *----------------------------------------------------------------------
141 WMenu
*wMenuCreate(WScreen
* screen
, char *title
, int main_menu
)
144 static int brother
= 0;
147 menu
= wmalloc(sizeof(WMenu
));
149 memset(menu
, 0, sizeof(WMenu
));
151 #ifdef SINGLE_MENULEVEL
152 tmp
= WMSubmenuLevel
;
154 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
157 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
159 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
160 menu
->flags
.titled
= 1;
163 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
164 screen
->menu_title_texture
, NULL
,
165 screen
->menu_title_color
, &screen
->menu_title_font
);
167 menu
->frame
->core
->descriptor
.parent
= menu
;
168 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
169 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
171 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
174 menu
->frame
->title
= wstrdup(title
);
177 menu
->frame
->flags
.justification
= WTJ_LEFT
;
179 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
182 menu
->alloced_entries
= 0;
183 menu
->selected_entry
= -1;
184 menu
->entries
= NULL
;
186 menu
->frame_x
= screen
->app_menu_x
;
187 menu
->frame_y
= screen
->app_menu_y
;
189 menu
->frame
->child
= menu
;
191 menu
->flags
.lowered
= 0;
195 /* setup object descriptors */
196 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
197 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
200 menu
->frame
->on_click_right
= menuCloseClick
;
202 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
, menu
->frame
->core
->width
, 10);
204 menu
->menu
->descriptor
.parent
= menu
;
205 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
206 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
207 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
209 menu
->menu_texture_data
= None
;
211 XMapWindow(dpy
, menu
->menu
->window
);
217 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
219 menu
->brother
->flags
.brother
= 1;
220 menu
->brother
->brother
= menu
;
222 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuAppearanceSettingsChanged
, menu
);
224 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuTitleAppearanceSettingsChanged
, menu
);
229 WMenu
*wMenuCreateForApp(WScreen
* screen
, char *title
, int main_menu
)
233 menu
= wMenuCreate(screen
, title
, main_menu
);
236 menu
->flags
.app_menu
= 1;
237 menu
->brother
->flags
.app_menu
= 1;
242 static void insertEntry(WMenu
* menu
, WMenuEntry
* entry
, int index
)
246 for (i
= menu
->entry_no
- 1; i
>= index
; i
--) {
247 menu
->entries
[i
]->order
++;
248 menu
->entries
[i
+ 1] = menu
->entries
[i
];
250 menu
->entries
[index
] = entry
;
253 WMenuEntry
*wMenuInsertCallback(WMenu
* menu
, int index
, char *text
,
254 void (*callback
) (WMenu
* menu
, WMenuEntry
* entry
), void *clientdata
)
258 menu
->flags
.realized
= 0;
259 menu
->brother
->flags
.realized
= 0;
261 /* reallocate array if it's too small */
262 if (menu
->entry_no
>= menu
->alloced_entries
) {
265 tmp
= wrealloc(menu
->entries
, sizeof(WMenuEntry
) * (menu
->alloced_entries
+ 5));
268 menu
->alloced_entries
+= 5;
270 menu
->brother
->entries
= tmp
;
271 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
273 entry
= wmalloc(sizeof(WMenuEntry
));
274 memset(entry
, 0, sizeof(WMenuEntry
));
275 entry
->flags
.enabled
= 1;
276 entry
->text
= wstrdup(text
);
278 entry
->clientdata
= clientdata
;
279 entry
->callback
= callback
;
280 if (index
< 0 || index
>= menu
->entry_no
) {
281 entry
->order
= menu
->entry_no
;
282 menu
->entries
[menu
->entry_no
] = entry
;
284 entry
->order
= index
;
285 insertEntry(menu
, entry
, index
);
289 menu
->brother
->entry_no
= menu
->entry_no
;
294 void wMenuEntrySetCascade(WMenu
* menu
, WMenuEntry
* entry
, WMenu
* cascade
)
296 WMenu
*brother
= menu
->brother
;
299 assert(menu
->flags
.brother
== 0);
301 if (entry
->cascade
>= 0) {
302 menu
->flags
.realized
= 0;
303 brother
->flags
.realized
= 0;
306 cascade
->parent
= menu
;
308 cascade
->brother
->parent
= brother
;
311 for (i
= 0; i
< menu
->cascade_no
; i
++) {
312 if (menu
->cascades
[i
] == NULL
) {
313 menu
->cascades
[i
] = cascade
;
314 brother
->cascades
[i
] = cascade
->brother
;
321 entry
->cascade
= menu
->cascade_no
;
323 menu
->cascades
= wrealloc(menu
->cascades
, sizeof(WMenu
) * (menu
->cascade_no
+ 1));
324 menu
->cascades
[menu
->cascade_no
++] = cascade
;
326 brother
->cascades
= wrealloc(brother
->cascades
, sizeof(WMenu
) * (brother
->cascade_no
+ 1));
327 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
330 if (menu
->flags
.lowered
) {
332 cascade
->flags
.lowered
= 1;
333 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
335 cascade
->brother
->flags
.lowered
= 1;
336 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
339 if (!menu
->flags
.realized
)
343 void wMenuEntryRemoveCascade(WMenu
* menu
, WMenuEntry
* entry
)
345 assert(menu
->flags
.brother
== 0);
347 /* destroy cascade menu */
348 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
] != NULL
) {
350 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
352 menu
->cascades
[entry
->cascade
] = NULL
;
353 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
359 void wMenuRemoveItem(WMenu
* menu
, int index
)
363 if (menu
->flags
.brother
) {
364 wMenuRemoveItem(menu
->brother
, index
);
368 if (index
>= menu
->entry_no
)
371 /* destroy cascade menu */
372 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
374 /* destroy unshared data */
376 if (menu
->entries
[index
]->text
)
377 wfree(menu
->entries
[index
]->text
);
379 if (menu
->entries
[index
]->rtext
)
380 wfree(menu
->entries
[index
]->rtext
);
382 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
383 (*menu
->entries
[index
]->free_cdata
) (menu
->entries
[index
]->clientdata
);
385 wfree(menu
->entries
[index
]);
387 for (i
= index
; i
< menu
->entry_no
- 1; i
++) {
388 menu
->entries
[i
+ 1]->order
--;
389 menu
->entries
[i
] = menu
->entries
[i
+ 1];
392 menu
->brother
->entry_no
--;
395 static Pixmap
renderTexture(WMenu
* menu
)
403 WScreen
*scr
= menu
->menu
->screen_ptr
;
404 WTexture
*texture
= scr
->menu_item_texture
;
406 if (wPreferences
.menu_style
== MS_NORMAL
) {
407 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->entry_height
, WREL_MENUENTRY
);
409 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->menu
->height
+ 1, WREL_MENUENTRY
);
412 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode
));
417 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
419 light
.red
= light
.green
= light
.blue
= 80;
422 dark
.red
= dark
.green
= dark
.blue
= 0;
425 mid
.red
= mid
.green
= mid
.blue
= 40;
427 for (i
= 1; i
< menu
->entry_no
; i
++) {
428 ROperateLine(img
, RSubtractOperation
, 0, i
* menu
->entry_height
- 2,
429 menu
->menu
->width
- 1, i
* menu
->entry_height
- 2, &mid
);
431 RDrawLine(img
, 0, i
* menu
->entry_height
- 1,
432 menu
->menu
->width
- 1, i
* menu
->entry_height
- 1, &dark
);
434 ROperateLine(img
, RAddOperation
, 0, i
* menu
->entry_height
,
435 menu
->menu
->width
- 1, i
* menu
->entry_height
, &light
);
438 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
439 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
446 static void updateTexture(WMenu
* menu
)
448 WScreen
*scr
= menu
->menu
->screen_ptr
;
450 /* setup background texture */
451 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
452 if (!menu
->flags
.brother
) {
453 FREE_PIXMAP(menu
->menu_texture_data
);
455 menu
->menu_texture_data
= renderTexture(menu
);
457 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
, menu
->menu_texture_data
);
458 XClearWindow(dpy
, menu
->menu
->window
);
460 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
, menu
->menu_texture_data
);
461 XClearWindow(dpy
, menu
->brother
->menu
->window
);
464 XSetWindowBackground(dpy
, menu
->menu
->window
, scr
->menu_item_texture
->any
.color
.pixel
);
465 XClearWindow(dpy
, menu
->menu
->window
);
469 void wMenuRealize(WMenu
* menu
)
472 int width
, rwidth
, mrwidth
, mwidth
;
473 int theight
, twidth
, eheight
;
474 WScreen
*scr
= menu
->frame
->screen_ptr
;
475 static int brother_done
= 0;
480 wMenuRealize(menu
->brother
);
484 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
485 if (menu
->flags
.titled
)
486 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
488 wFrameWindowUpdateBorders(menu
->frame
, flags
);
490 if (menu
->flags
.titled
) {
491 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
, strlen(menu
->frame
->title
));
492 theight
= menu
->frame
->top_width
;
493 twidth
+= theight
+ (wPreferences
.new_style
== TS_NEW
? 16 : 8);
498 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
499 menu
->entry_height
= eheight
;
502 for (i
= 0; i
< menu
->entry_no
; i
++) {
505 /* search widest text */
506 text
= menu
->entries
[i
]->text
;
507 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
)) + 10;
509 if (menu
->entries
[i
]->flags
.indicator
) {
510 width
+= MENU_INDICATOR_SPACE
;
516 /* search widest text on right */
517 text
= menu
->entries
[i
]->rtext
;
519 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
521 else if (menu
->entries
[i
]->cascade
>= 0)
526 if (rwidth
> mrwidth
)
534 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
* eheight
- 1);
536 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
* eheight
- 1
537 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
541 menu
->flags
.realized
= 1;
543 if (menu
->flags
.mapped
)
545 if (menu
->brother
->flags
.mapped
)
546 wMenuPaint(menu
->brother
);
549 void wMenuDestroy(WMenu
* menu
, int recurse
)
553 WMRemoveNotificationObserver(menu
);
555 /* remove any pending timers */
557 WMDeleteTimerHandler(menu
->timer
);
560 /* call destroy handler */
561 if (menu
->on_destroy
)
562 (*menu
->on_destroy
) (menu
);
564 /* Destroy items if this menu own them. If this is the "brother" menu,
565 * leave them alone as it is shared by them.
567 if (!menu
->flags
.brother
) {
568 for (i
= 0; i
< menu
->entry_no
; i
++) {
570 wfree(menu
->entries
[i
]->text
);
572 if (menu
->entries
[i
]->rtext
)
573 wfree(menu
->entries
[i
]->rtext
);
576 if (menu
->entries
[i
]->instances
) {
577 WMReleasePropList(menu
->entries
[i
]->instances
);
579 #endif /* USER_MENU */
581 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
582 (*menu
->entries
[i
]->free_cdata
) (menu
->entries
[i
]->clientdata
);
584 wfree(menu
->entries
[i
]);
588 for (i
= 0; i
< menu
->cascade_no
; i
++) {
589 if (menu
->cascades
[i
]) {
590 if (menu
->cascades
[i
]->flags
.brother
)
591 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
593 wMenuDestroy(menu
->cascades
[i
], recurse
);
599 wfree(menu
->entries
);
603 FREE_PIXMAP(menu
->menu_texture_data
);
606 wfree(menu
->cascades
);
608 wCoreDestroy(menu
->menu
);
609 wFrameWindowDestroy(menu
->frame
);
611 /* destroy copy of this menu */
612 if (!menu
->flags
.brother
&& menu
->brother
)
613 wMenuDestroy(menu
->brother
, False
);
623 static void drawFrame(WScreen
* scr
, Drawable win
, int y
, int w
, int h
, int type
)
629 segs
[i
].x1
= segs
[i
].x2
= w
- 1;
631 segs
[i
].y2
= y
+ h
- 1;
633 if (type
!= F_TOP
&& type
!= F_NONE
) {
635 segs
[i
].y1
= segs
[i
].y2
= y
+ h
- 2;
639 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
645 segs
[i
].y2
= y
+ h
- 1;
647 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
654 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
656 if (type
!= F_TOP
&& type
!= F_NONE
)
657 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+ h
- 1, w
- 1, y
+ h
- 1);
660 static void paintEntry(WMenu
* menu
, int index
, int selected
)
662 WScreen
*scr
= menu
->frame
->screen_ptr
;
663 Window win
= menu
->menu
->window
;
664 WMenuEntry
*entry
= menu
->entries
[index
];
670 if (!menu
->flags
.realized
)
672 h
= menu
->entry_height
;
673 w
= menu
->menu
->width
;
676 light
= scr
->menu_item_auxtexture
->light_gc
;
677 dim
= scr
->menu_item_auxtexture
->dim_gc
;
678 dark
= scr
->menu_item_auxtexture
->dark_gc
;
680 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
683 else if (index
== menu
->entry_no
- 1)
691 /* paint background */
693 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+ 1, w
- 2, h
- 3);
694 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
695 drawFrame(scr
, win
, y
, w
, h
, type
);
697 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
698 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
700 drawFrame(scr
, win
, y
, w
, h
, type
);
702 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
707 if (entry
->flags
.enabled
)
708 color
= scr
->select_text_color
;
710 color
= scr
->dtext_color
;
711 } else if (!entry
->flags
.enabled
) {
712 color
= scr
->dtext_color
;
714 color
= scr
->mtext_color
;
718 if (entry
->flags
.indicator
)
719 x
+= MENU_INDICATOR_SPACE
+ 2;
721 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
722 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
724 if (entry
->cascade
>= 0) {
725 /* draw the cascade indicator */
726 XDrawLine(dpy
, win
, dim
, w
- 11, y
+ 6, w
- 6, y
+ h
/ 2 - 1);
727 XDrawLine(dpy
, win
, light
, w
- 11, y
+ h
- 8, w
- 6, y
+ h
/ 2 - 1);
728 XDrawLine(dpy
, win
, dark
, w
- 12, y
+ 6, w
- 12, y
+ h
- 8);
732 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
736 switch (entry
->flags
.indicator_type
) {
738 indicator
= scr
->menu_check_indicator
;
741 indicator
= scr
->menu_mini_indicator
;
744 indicator
= scr
->menu_hide_indicator
;
747 indicator
= scr
->menu_shade_indicator
;
751 indicator
= scr
->menu_radio_indicator
;
755 iw
= indicator
->width
;
756 ih
= indicator
->height
;
757 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
758 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2);
760 if (entry
->flags
.enabled
) {
761 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
763 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
766 if (entry
->flags
.enabled
) {
767 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
769 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
772 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2, iw
, ih
);
774 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
775 iw, ih, 5, y+(h-ih)/2);
777 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
780 /* draw right text */
782 if (entry
->rtext
&& entry
->cascade
< 0) {
783 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
, strlen(entry
->rtext
));
785 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
- 6 - tw
,
786 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
790 static void move_menus(WMenu
* menu
, int x
, int y
)
792 while (menu
->parent
) {
795 if (!wPreferences
.align_menus
&& menu
->selected_entry
>= 0) {
796 y
-= menu
->selected_entry
* menu
->entry_height
;
799 wMenuMove(menu
, x
, y
, True
);
802 static void makeVisible(WMenu
* menu
)
804 WScreen
*scr
= menu
->frame
->screen_ptr
;
805 int x1
, y1
, x2
, y2
, new_x
, new_y
;
806 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
808 if (menu
->entry_no
< 0)
812 y1
= menu
->frame_y
+ menu
->frame
->top_width
+ menu
->selected_entry
* menu
->entry_height
;
813 x2
= x1
+ MENUW(menu
);
814 y2
= y1
+ menu
->entry_height
;
819 if (x1
< rect
.pos
.x
) {
821 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
822 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
825 if (y1
< rect
.pos
.y
) {
827 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
828 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
831 new_y
= new_y
- menu
->frame
->top_width
- menu
->selected_entry
* menu
->entry_height
;
832 move_menus(menu
, new_x
, new_y
);
835 static int check_key(WMenu
* menu
, XKeyEvent
* event
)
840 if (XLookupString(event
, buffer
, 32, NULL
, NULL
) < 1)
843 ch
= toupper(buffer
[0]);
845 s
= (menu
->selected_entry
>= 0 ? menu
->selected_entry
+ 1 : 0);
848 for (i
= s
; i
< menu
->entry_no
; i
++) {
849 if (ch
== toupper(menu
->entries
[i
]->text
[0])) {
853 /* no match. Retry from start, if previous started from a selected entry */
861 static int keyboardMenu(WMenu
* menu
)
864 KeySym ksym
= NoSymbol
;
868 int old_pos_x
= menu
->frame_x
;
869 int old_pos_y
= menu
->frame_y
;
870 int new_x
= old_pos_x
, new_y
= old_pos_y
;
871 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
872 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
874 if (menu
->flags
.editing
)
877 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
879 if (menu
->frame_y
+ menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
880 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
882 if (menu
->frame_x
+ MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
883 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
885 move_menus(menu
, new_x
, new_y
);
887 while (!done
&& menu
->flags
.mapped
) {
888 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
889 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonPressMask
890 | ButtonReleaseMask
| KeyPressMask
| KeyReleaseMask
| SubstructureNotifyMask
, &event
);
892 switch (event
.type
) {
894 ksym
= XLookupKeysym(&event
.xkey
, 0);
895 if (wPreferences
.vi_key_menus
) {
924 selectEntry(menu
, 0);
932 selectEntry(menu
, menu
->entry_no
- 1);
940 if (menu
->selected_entry
<= 0)
941 selectEntry(menu
, menu
->entry_no
- 1);
943 selectEntry(menu
, menu
->selected_entry
- 1);
951 if (menu
->selected_entry
< 0)
952 selectEntry(menu
, 0);
953 else if (menu
->selected_entry
== menu
->entry_no
- 1)
954 selectEntry(menu
, 0);
955 else if (menu
->selected_entry
< menu
->entry_no
- 1)
956 selectEntry(menu
, menu
->selected_entry
+ 1);
964 if (menu
->selected_entry
>= 0) {
966 entry
= menu
->entries
[menu
->selected_entry
];
968 if (entry
->cascade
>= 0 && menu
->cascades
969 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
971 XUngrabKeyboard(dpy
, CurrentTime
);
973 selectEntry(menu
->cascades
[entry
->cascade
], 0);
974 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
977 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
978 GrabModeAsync
, GrabModeAsync
, CurrentTime
);
987 if (menu
->parent
!= NULL
&& menu
->parent
->selected_entry
>= 0) {
988 selectEntry(menu
, -1);
989 move_menus(menu
, old_pos_x
, old_pos_y
);
1002 index
= check_key(menu
, &event
.xkey
);
1004 selectEntry(menu
, index
);
1010 if (event
.type
== ButtonPress
)
1013 WMHandleEvent(&event
);
1017 XUngrabKeyboard(dpy
, CurrentTime
);
1019 if (done
== 2 && menu
->selected_entry
>= 0) {
1020 entry
= menu
->entries
[menu
->selected_entry
];
1025 if (entry
&& entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1026 #if (MENU_BLINK_COUNT > 0)
1027 int sel
= menu
->selected_entry
;
1030 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1031 paintEntry(menu
, sel
, False
);
1033 wusleep(MENU_BLINK_DELAY
);
1034 paintEntry(menu
, sel
, True
);
1036 wusleep(MENU_BLINK_DELAY
);
1039 selectEntry(menu
, -1);
1041 if (!menu
->flags
.buttoned
) {
1043 move_menus(menu
, old_pos_x
, old_pos_y
);
1047 (*entry
->callback
) (menu
, entry
);
1049 if (!menu
->flags
.buttoned
) {
1051 move_menus(menu
, old_pos_x
, old_pos_y
);
1053 selectEntry(menu
, -1);
1056 /* returns True if returning from a submenu to a parent menu,
1057 * False if exiting from menu */
1061 void wMenuMapAt(WMenu
* menu
, int x
, int y
, int keyboard
)
1063 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1064 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1066 if (!menu
->flags
.realized
) {
1067 menu
->flags
.realized
= 1;
1070 if (!menu
->flags
.mapped
) {
1071 if (wPreferences
.wrap_menus
) {
1076 if (x
+ MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1077 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1078 if (y
+ MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1079 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1082 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1085 XMapWindow(dpy
, menu
->frame
->core
->window
);
1086 wRaiseFrame(menu
->frame
->core
);
1087 menu
->flags
.mapped
= 1;
1089 selectEntry(menu
, 0);
1096 void wMenuMap(WMenu
* menu
)
1098 if (!menu
->flags
.realized
) {
1099 menu
->flags
.realized
= 1;
1102 if (menu
->flags
.app_menu
&& menu
->parent
== NULL
) {
1103 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1104 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1105 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1107 XMapWindow(dpy
, menu
->frame
->core
->window
);
1108 wRaiseFrame(menu
->frame
->core
);
1109 menu
->flags
.mapped
= 1;
1112 void wMenuUnmap(WMenu
* menu
)
1116 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1117 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1118 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1120 menu
->flags
.buttoned
= 0;
1121 menu
->flags
.mapped
= 0;
1122 menu
->flags
.open_to_left
= 0;
1124 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1125 if (menu
->cascades
[i
] != NULL
1126 && menu
->cascades
[i
]->flags
.mapped
&& !menu
->cascades
[i
]->flags
.buttoned
) {
1128 wMenuUnmap(menu
->cascades
[i
]);
1131 menu
->selected_entry
= -1;
1134 void wMenuPaint(WMenu
* menu
)
1138 if (!menu
->flags
.mapped
) {
1143 for (i
= 0; i
< menu
->entry_no
; i
++) {
1144 paintEntry(menu
, i
, i
== menu
->selected_entry
);
1148 void wMenuSetEnabled(WMenu
* menu
, int index
, int enable
)
1150 if (index
>= menu
->entry_no
)
1152 menu
->entries
[index
]->flags
.enabled
= enable
;
1153 paintEntry(menu
, index
, index
== menu
->selected_entry
);
1154 paintEntry(menu
->brother
, index
, index
== menu
->selected_entry
);
1158 static void selectEntry(WMenu
* menu
, int entry_no
)
1164 if (menu
->entries
== NULL
)
1167 if (entry_no
>= menu
->entry_no
)
1170 old_entry
= menu
->selected_entry
;
1171 menu
->selected_entry
= entry_no
;
1173 if (old_entry
!= entry_no
) {
1175 /* unselect previous entry */
1176 if (old_entry
>= 0) {
1177 paintEntry(menu
, old_entry
, False
);
1178 entry
= menu
->entries
[old_entry
];
1181 if (entry
->cascade
>= 0 && menu
->cascades
) {
1182 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1183 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1189 menu
->selected_entry
= -1;
1192 entry
= menu
->entries
[entry_no
];
1194 if (entry
->cascade
>= 0 && menu
->cascades
&& entry
->flags
.enabled
) {
1195 /* Callback for when the submenu is opened.
1197 submenu
= menu
->cascades
[entry
->cascade
];
1198 if (submenu
&& submenu
->flags
.brother
)
1199 submenu
= submenu
->brother
;
1201 if (entry
->callback
) {
1202 /* Only call the callback if the submenu is not yet mapped.
1204 if (menu
->flags
.brother
) {
1205 if (!submenu
|| !submenu
->flags
.mapped
)
1206 (*entry
->callback
) (menu
->brother
, entry
);
1208 if (!submenu
|| !submenu
->flags
.buttoned
)
1209 (*entry
->callback
) (menu
, entry
);
1213 /* the submenu menu might have changed */
1214 submenu
= menu
->cascades
[entry
->cascade
];
1217 if (!submenu
->flags
.mapped
) {
1220 if (!submenu
->flags
.realized
)
1221 wMenuRealize(submenu
);
1222 if (wPreferences
.wrap_menus
) {
1223 if (menu
->flags
.open_to_left
)
1224 submenu
->flags
.open_to_left
= 1;
1226 if (submenu
->flags
.open_to_left
) {
1227 x
= menu
->frame_x
- MENUW(submenu
);
1230 submenu
->flags
.open_to_left
= 0;
1233 x
= menu
->frame_x
+ MENUW(menu
);
1235 if (x
+ MENUW(submenu
)
1236 >= menu
->frame
->screen_ptr
->scr_width
) {
1238 x
= menu
->frame_x
- MENUW(submenu
);
1239 submenu
->flags
.open_to_left
= 1;
1243 x
= menu
->frame_x
+ MENUW(menu
);
1246 if (wPreferences
.align_menus
) {
1249 y
= menu
->frame_y
+ menu
->entry_height
* entry_no
;
1250 if (menu
->flags
.titled
)
1251 y
+= menu
->frame
->top_width
;
1252 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1253 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1256 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1257 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1262 paintEntry(menu
, entry_no
, True
);
1266 static WMenu
*findMenu(WScreen
* scr
, int *x_ret
, int *y_ret
)
1269 WObjDescriptor
*desc
;
1270 Window root_ret
, win
, junk_win
;
1274 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
, &mask
);
1279 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1282 if (desc
->parent_type
== WCLASS_MENU
) {
1283 menu
= (WMenu
*) desc
->parent
;
1284 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
, x_ret
, y_ret
, &junk_win
);
1290 static void closeCascade(WMenu
* menu
)
1292 WMenu
*parent
= menu
->parent
;
1294 if (menu
->flags
.brother
|| (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
))) {
1296 selectEntry(menu
, -1);
1298 #if (MENU_BLINK_DELAY > 2)
1299 wusleep(MENU_BLINK_DELAY
/ 2);
1302 while (parent
!= NULL
1303 && (parent
->parent
!= NULL
|| !parent
->flags
.app_menu
|| parent
->flags
.brother
)
1304 && !parent
->flags
.buttoned
) {
1305 selectEntry(parent
, -1);
1307 parent
= parent
->parent
;
1310 selectEntry(parent
, -1);
1314 static void closeBrotherCascadesOf(WMenu
* menu
)
1319 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1320 if (menu
->cascades
[i
]->flags
.brother
) {
1321 tmp
= menu
->cascades
[i
];
1323 tmp
= menu
->cascades
[i
]->brother
;
1325 if (tmp
->flags
.mapped
) {
1326 selectEntry(tmp
->parent
, -1);
1327 closeBrotherCascadesOf(tmp
);
1333 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1335 static WMenu
*parentMenu(WMenu
* menu
)
1340 if (menu
->flags
.buttoned
)
1343 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1344 parent
= menu
->parent
;
1345 if (parent
->selected_entry
< 0)
1347 entry
= parent
->entries
[parent
->selected_entry
];
1348 if (!entry
->flags
.enabled
|| entry
->cascade
< 0 || !parent
->cascades
||
1349 parent
->cascades
[entry
->cascade
] != menu
)
1352 if (menu
->flags
.buttoned
)
1360 * Will raise the passed menu, if submenu = 0
1361 * If submenu > 0 will also raise all mapped submenus
1362 * until the first buttoned one
1363 * If submenu < 0 will also raise all mapped parent menus
1364 * until the first buttoned one
1367 static void raiseMenus(WMenu
* menu
, int submenus
)
1375 wRaiseFrame(menu
->frame
->core
);
1377 if (submenus
> 0 && menu
->selected_entry
>= 0) {
1378 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1379 if (i
>= 0 && menu
->cascades
) {
1380 submenu
= menu
->cascades
[i
];
1381 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1382 raiseMenus(submenu
, submenus
);
1385 if (submenus
< 0 && !menu
->flags
.buttoned
&& menu
->parent
&& menu
->parent
->flags
.mapped
)
1386 raiseMenus(menu
->parent
, submenus
);
1389 WMenu
*wMenuUnderPointer(WScreen
* screen
)
1391 WObjDescriptor
*desc
;
1392 Window root_ret
, win
;
1396 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
, &dummy
, &dummy
, &mask
);
1401 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1404 if (desc
->parent_type
== WCLASS_MENU
)
1405 return (WMenu
*) desc
->parent
;
1409 static void getPointerPosition(WScreen
* scr
, int *x
, int *y
)
1411 Window root_ret
, win
;
1415 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1418 static void getScrollAmount(WMenu
* menu
, int *hamount
, int *vamount
)
1420 WScreen
*scr
= menu
->menu
->screen_ptr
;
1421 int menuX1
= menu
->frame_x
;
1422 int menuY1
= menu
->frame_y
;
1423 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1424 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1426 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1431 getPointerPosition(scr
, &xroot
, &yroot
);
1433 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1434 /* scroll to the right */
1435 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1437 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) && menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1438 /* scroll to the left */
1439 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
- rect
.pos
.x
- rect
.size
.width
- 1));
1444 *hamount
= -*hamount
;
1447 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1449 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1451 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) && menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1453 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
- rect
.pos
.y
- rect
.size
.height
- 2));
1455 *vamount
= -*vamount
;
1459 static void dragScrollMenuCallback(void *data
)
1461 WMenu
*menu
= (WMenu
*) data
;
1462 WScreen
*scr
= menu
->menu
->screen_ptr
;
1463 WMenu
*parent
= parentMenu(menu
);
1464 int hamount
, vamount
;
1466 int newSelectedEntry
;
1468 getScrollAmount(menu
, &hamount
, &vamount
);
1470 if (hamount
!= 0 || vamount
!= 0) {
1471 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1472 if (findMenu(scr
, &x
, &y
)) {
1473 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1474 selectEntry(menu
, newSelectedEntry
);
1476 /* Pointer fell outside of menu. If the selected entry is
1477 * not a submenu, unselect it */
1478 if (menu
->selected_entry
>= 0 && menu
->entries
[menu
->selected_entry
]->cascade
< 0)
1479 selectEntry(menu
, -1);
1480 newSelectedEntry
= 0;
1483 /* paranoid check */
1484 if (newSelectedEntry
>= 0) {
1485 /* keep scrolling */
1486 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, dragScrollMenuCallback
, menu
);
1491 /* don't need to scroll anymore */
1493 if (findMenu(scr
, &x
, &y
)) {
1494 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1495 selectEntry(menu
, newSelectedEntry
);
1500 static void scrollMenuCallback(void *data
)
1502 WMenu
*menu
= (WMenu
*) data
;
1503 WMenu
*parent
= parentMenu(menu
);
1504 int hamount
= 0; /* amount to scroll */
1507 getScrollAmount(menu
, &hamount
, &vamount
);
1509 if (hamount
!= 0 || vamount
!= 0) {
1510 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1512 /* keep scrolling */
1513 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, scrollMenuCallback
, menu
);
1515 /* don't need to scroll anymore */
1520 #define MENU_SCROLL_BORDER 5
1522 static int isPointNearBoder(WMenu
* menu
, int x
, int y
)
1524 int menuX1
= menu
->frame_x
;
1525 int menuY1
= menu
->frame_y
;
1526 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1527 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1529 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1530 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1532 /* XXX: handle screen joins properly !! */
1534 if (x
>= menuX1
&& x
<= menuX2
&&
1535 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
|| y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1537 else if (y
>= menuY1
&& y
<= menuY2
&&
1538 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
|| x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1544 typedef struct _delay
{
1549 static void leaving(_delay
* dl
)
1551 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1552 dl
->menu
->jump_back
= NULL
;
1553 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1557 void wMenuScroll(WMenu
* menu
, XEvent
* event
)
1560 WMenu
*omenu
= parentMenu(menu
);
1561 WScreen
*scr
= menu
->frame
->screen_ptr
;
1564 int old_frame_x
= omenu
->frame_x
;
1565 int old_frame_y
= omenu
->frame_y
;
1568 if (omenu
->jump_back
)
1569 WMDeleteTimerWithClientData(omenu
->jump_back
);
1571 if (( /*omenu->flags.buttoned && */ !wPreferences
.wrap_menus
)
1572 || omenu
->flags
.app_menu
) {
1576 if (!wPreferences
.wrap_menus
)
1577 raiseMenus(omenu
, True
);
1579 raiseMenus(menu
, False
);
1582 scrollMenuCallback(menu
);
1585 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1588 WMNextEvent(dpy
, &ev
);
1593 x
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1594 y
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1596 /* on_border is != 0 if the pointer is between the menu
1597 * and the screen border and is close enough to the border */
1598 on_border
= isPointNearBoder(menu
, x
, y
);
1600 smenu
= wMenuUnderPointer(scr
);
1602 if ((smenu
== NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
) != omenu
)) {
1607 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1608 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1609 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1610 on_border
= on_x_edge
|| on_y_edge
;
1612 if (!on_border
&& !jump_back
) {
1617 if (menu
->timer
&& (smenu
!= menu
|| (!on_y_edge
&& !on_x_edge
))) {
1618 WMDeleteTimerHandler(menu
->timer
);
1626 scrollMenuCallback(menu
);
1629 /* True if we push on title, or drag the omenu to other position */
1630 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1631 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1632 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1633 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1635 smenu
= wMenuUnderPointer(scr
);
1636 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1638 else if (smenu
== omenu
&& on_title
) {
1652 WMDeleteTimerHandler(menu
->timer
);
1658 if (!omenu
->jump_back
) {
1659 delayer
= wmalloc(sizeof(_delay
));
1660 delayer
->menu
= omenu
;
1661 delayer
->ox
= old_frame_x
;
1662 delayer
->oy
= old_frame_y
;
1663 omenu
->jump_back
= delayer
;
1664 scr
->flags
.jump_back_pending
= 1;
1666 delayer
= omenu
->jump_back
;
1667 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
, (WMCallback
*) leaving
, delayer
);
1671 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
)
1673 wMenuPaint(desc
->parent
);
1677 int *delayed_select
;
1682 static void delaySelection(void *data
)
1684 delay_data
*d
= (delay_data
*) data
;
1690 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1691 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1692 entry_no
= getEntryAt(menu
, x
, y
);
1693 selectEntry(menu
, entry_no
);
1695 if (d
->delayed_select
)
1696 *(d
->delayed_select
) = 0;
1699 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
1702 XButtonEvent
*bev
= &event
->xbutton
;
1703 WMenu
*menu
= desc
->parent
;
1705 WScreen
*scr
= menu
->frame
->screen_ptr
;
1706 WMenuEntry
*entry
= NULL
;
1708 int close_on_exit
= 0;
1710 int delayed_select
= 0;
1714 int old_frame_x
= 0;
1715 int old_frame_y
= 0;
1716 delay_data d_data
= { NULL
, NULL
, NULL
};
1718 /* Doesn't seem to be needed anymore (if delayed selection handler is
1719 * added only if not present). there seem to be no other side effects
1720 * from removing this and it is also possible that it was only added
1721 * to avoid problems with adding the delayed selection timer handler
1724 /*if (menu->flags.inside_handler) {
1727 menu
->flags
.inside_handler
= 1;
1729 if (!wPreferences
.wrap_menus
) {
1730 smenu
= parentMenu(menu
);
1731 old_frame_x
= smenu
->frame_x
;
1732 old_frame_y
= smenu
->frame_y
;
1733 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1734 /* This is true if the menu was launched with right click on root window */
1735 if (!d_data
.magic
) {
1737 d_data
.delayed_select
= &delayed_select
;
1739 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
, delaySelection
, &d_data
);
1743 wRaiseFrame(menu
->frame
->core
);
1745 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1747 smenu
= findMenu(scr
, &x
, &y
);
1755 if (menu
->flags
.editing
) {
1758 entry_no
= getEntryAt(menu
, x
, y
);
1759 if (entry_no
>= 0) {
1760 entry
= menu
->entries
[entry_no
];
1762 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
&& entry
->flags
.editable
) {
1765 int number
= entry_no
- 2; /* Entries "New" and "Destroy Last" appear before workspaces */
1767 name
= wstrdup(scr
->workspaces
[number
]->name
);
1768 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), number
+ 1);
1770 wMenuUnmap(scr
->root_menu
);
1772 if (wInputDialog(scr
, _("Rename Workspace"), buffer
, &name
))
1773 wWorkspaceRename(scr
, number
, name
);
1779 } else if (bev
->state
& ControlMask
) {
1783 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1784 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1786 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&& menu
->selected_entry
!= entry_no
) {
1787 wMenuUnmap(submenu
);
1789 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1790 selectEntry(menu
, entry_no
);
1791 } else if (!submenu
->flags
.buttoned
) {
1792 selectEntry(menu
, -1);
1795 } else if (!delayed_select
) {
1796 if (menu
== scr
->switch_menu
&& event
->xbutton
.button
== Button3
) {
1797 selectEntry(menu
, entry_no
);
1798 OpenWindowMenu2((WWindow
*)entry
->clientdata
,
1799 event
->xbutton
.x_root
,
1800 event
->xbutton
.y_root
, False
);
1801 wwin
= (WWindow
*)entry
->clientdata
;
1802 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
1803 event
->xany
.send_event
= True
;
1804 (*desc
->handle_mousedown
)(desc
, event
);
1806 XUngrabPointer(dpy
, CurrentTime
);
1807 selectEntry(menu
, -1);
1810 selectEntry(menu
, entry_no
);
1814 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
1816 dragScrollMenuCallback(menu
);
1820 prevx
= bev
->x_root
;
1821 prevy
= bev
->y_root
;
1825 XAllowEvents(dpy
, AsyncPointer
| SyncPointer
, CurrentTime
);
1827 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
1830 smenu
= findMenu(scr
, &x
, &y
);
1832 if (smenu
== NULL
) {
1833 /* moved mouse out of menu */
1835 if (!delayed_select
&& d_data
.magic
) {
1836 WMDeleteTimerHandler(d_data
.magic
);
1837 d_data
.magic
= NULL
;
1840 || (menu
->selected_entry
>= 0
1841 && menu
->entries
[menu
->selected_entry
]->cascade
>= 0)) {
1842 prevx
= ev
.xmotion
.x_root
;
1843 prevy
= ev
.xmotion
.y_root
;
1847 selectEntry(menu
, -1);
1849 prevx
= ev
.xmotion
.x_root
;
1850 prevy
= ev
.xmotion
.y_root
;
1852 } else if (menu
&& menu
!= smenu
1853 && (menu
->selected_entry
< 0
1854 || menu
->entries
[menu
->selected_entry
]->cascade
< 0)) {
1855 selectEntry(menu
, -1);
1857 if (!delayed_select
&& d_data
.magic
) {
1858 WMDeleteTimerHandler(d_data
.magic
);
1859 d_data
.magic
= NULL
;
1863 /* hysteresis for item selection */
1865 /* check if the motion was to the side, indicating that
1866 * the user may want to cross to a submenu */
1867 if (!delayed_select
&& menu
) {
1869 Bool moved_to_submenu
; /* moved to direction of submenu */
1871 dx
= abs(prevx
- ev
.xmotion
.x_root
);
1873 moved_to_submenu
= False
;
1874 if (dx
> 0 /* if moved enough to the side */
1875 /* maybe a open submenu */
1876 && menu
->selected_entry
>= 0
1877 /* moving to the right direction */
1878 && (wPreferences
.align_menus
|| ev
.xmotion
.y_root
>= prevy
)) {
1881 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
1883 if (menu
->cascades
[index
]->frame_x
> menu
->frame_x
) {
1884 if (prevx
< ev
.xmotion
.x_root
)
1885 moved_to_submenu
= True
;
1887 if (prevx
> ev
.xmotion
.x_root
)
1888 moved_to_submenu
= True
;
1893 if (menu
!= smenu
) {
1895 WMDeleteTimerHandler(d_data
.magic
);
1896 d_data
.magic
= NULL
;
1898 } else if (moved_to_submenu
) {
1899 /* while we are moving, postpone the selection */
1901 WMDeleteTimerHandler(d_data
.magic
);
1903 d_data
.delayed_select
= NULL
;
1905 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
1906 delaySelection
, &d_data
);
1907 prevx
= ev
.xmotion
.x_root
;
1908 prevy
= ev
.xmotion
.y_root
;
1912 WMDeleteTimerHandler(d_data
.magic
);
1913 d_data
.magic
= NULL
;
1918 prevx
= ev
.xmotion
.x_root
;
1919 prevy
= ev
.xmotion
.y_root
;
1920 if (menu
!= smenu
) {
1921 /* pointer crossed menus */
1922 if (menu
&& menu
->timer
) {
1923 WMDeleteTimerHandler(menu
->timer
);
1927 dragScrollMenuCallback(smenu
);
1931 dragScrollMenuCallback(menu
);
1933 if (!delayed_select
) {
1934 entry_no
= getEntryAt(menu
, x
, y
);
1935 if (entry_no
>= 0) {
1936 entry
= menu
->entries
[entry_no
];
1937 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1938 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1939 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
1940 && menu
->selected_entry
!= entry_no
) {
1941 wMenuUnmap(submenu
);
1945 selectEntry(menu
, entry_no
);
1953 if (ev
.xbutton
.button
== event
->xbutton
.button
)
1963 if (menu
&& menu
->timer
) {
1964 WMDeleteTimerHandler(menu
->timer
);
1967 if (d_data
.magic
!= NULL
) {
1968 WMDeleteTimerHandler(d_data
.magic
);
1969 d_data
.magic
= NULL
;
1972 if (menu
&& menu
->selected_entry
>= 0) {
1973 entry
= menu
->entries
[menu
->selected_entry
];
1974 if (entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1975 /* blink and erase menu selection */
1976 #if (MENU_BLINK_DELAY > 0)
1977 int sel
= menu
->selected_entry
;
1980 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1981 paintEntry(menu
, sel
, False
);
1983 wusleep(MENU_BLINK_DELAY
);
1984 paintEntry(menu
, sel
, True
);
1986 wusleep(MENU_BLINK_DELAY
);
1989 /* unmap the menu, it's parents and call the callback */
1990 if (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
1993 selectEntry(menu
, -1);
1995 (*entry
->callback
) (menu
, entry
);
1997 /* If the user double clicks an entry, the entry will
1998 * be executed twice, which is not good for things like
1999 * the root menu. So, ignore any clicks that were generated
2000 * while the entry was being executed */
2001 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
, ButtonPress
, &ev
)) ;
2002 } else if (entry
->callback
!= NULL
&& entry
->cascade
< 0) {
2003 selectEntry(menu
, -1);
2005 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2006 selectEntry(menu
, -1);
2011 if (((WMenu
*) desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2012 closeCascade(desc
->parent
);
2014 /* close the cascade windows that should not remain opened */
2015 closeBrotherCascadesOf(desc
->parent
);
2017 if (!wPreferences
.wrap_menus
)
2018 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2021 /* Just to be sure in case we skip the 2 above because of a goto byebye */
2022 if (menu
&& menu
->timer
) {
2023 WMDeleteTimerHandler(menu
->timer
);
2026 if (d_data
.magic
!= NULL
) {
2027 WMDeleteTimerHandler(d_data
.magic
);
2028 d_data
.magic
= NULL
;
2031 ((WMenu
*) desc
->parent
)->flags
.inside_handler
= 0;
2034 void wMenuMove(WMenu
* menu
, int x
, int y
, int submenus
)
2044 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2046 if (submenus
> 0 && menu
->selected_entry
>= 0) {
2047 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2049 if (i
>= 0 && menu
->cascades
) {
2050 submenu
= menu
->cascades
[i
];
2051 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2052 if (wPreferences
.align_menus
) {
2053 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2055 wMenuMove(submenu
, x
+ MENUW(menu
),
2056 y
+ submenu
->entry_height
* menu
->selected_entry
, submenus
);
2061 if (submenus
< 0 && menu
->parent
!= NULL
&& menu
->parent
->flags
.mapped
&& !menu
->parent
->flags
.buttoned
) {
2062 if (wPreferences
.align_menus
) {
2063 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2065 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2066 - menu
->parent
->entry_height
* menu
->parent
->selected_entry
, submenus
);
2071 static void changeMenuLevels(WMenu
* menu
, int lower
)
2076 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
: WMSubmenuLevel
));
2077 wRaiseFrame(menu
->frame
->core
);
2078 menu
->flags
.lowered
= 0;
2080 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2081 wLowerFrame(menu
->frame
->core
);
2082 menu
->flags
.lowered
= 1;
2084 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2085 if (menu
->cascades
[i
]
2086 && !menu
->cascades
[i
]->flags
.buttoned
&& menu
->cascades
[i
]->flags
.lowered
!= lower
) {
2087 changeMenuLevels(menu
->cascades
[i
], lower
);
2092 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2097 if (event
->xbutton
.state
& MOD_MASK
) {
2098 if (menu
->flags
.lowered
) {
2103 changeMenuLevels(menu
, lower
);
2107 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2112 int x
= menu
->frame_x
, y
= menu
->frame_y
;
2113 int dx
= event
->xbutton
.x_root
, dy
= event
->xbutton
.y_root
;
2117 /* can't touch the menu copy */
2118 if (menu
->flags
.brother
)
2121 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2124 if (event
->xbutton
.state
& MOD_MASK
) {
2125 wLowerFrame(menu
->frame
->core
);
2128 wRaiseFrame(menu
->frame
->core
);
2133 /* lower/raise all submenus */
2135 if (tmp
->selected_entry
>= 0 && tmp
->cascades
&& tmp
->entries
[tmp
->selected_entry
]->cascade
>= 0) {
2136 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2137 if (!tmp
|| !tmp
->flags
.mapped
)
2140 wLowerFrame(tmp
->frame
->core
);
2142 wRaiseFrame(tmp
->frame
->core
);
2148 /* tear off the menu if it's a root menu or a cascade
2150 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
2151 menu
->flags
.buttoned
= 1;
2152 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2154 /* turn off selected menu entry in parent menu */
2155 selectEntry(menu
->parent
, -1);
2157 /* make parent map the copy in place of the original */
2158 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2159 if (menu
->parent
->cascades
[i
] == menu
) {
2160 menu
->parent
->cascades
[i
] = menu
->brother
;
2169 WMMaskEvent(dpy
, ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &ev
);
2173 x
+= ev
.xmotion
.x_root
- dx
;
2174 y
+= ev
.xmotion
.y_root
- dy
;
2175 dx
= ev
.xmotion
.x_root
;
2176 dy
= ev
.xmotion
.y_root
;
2177 wMenuMove(menu
, x
, y
, True
);
2179 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2180 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2182 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2183 ButtonMotionMask
| ButtonReleaseMask
2185 GrabModeAsync
, GrabModeAsync
, None
,
2186 wCursor
[WCUR_MOVE
], CurrentTime
);
2195 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2197 XUngrabPointer(dpy
, CurrentTime
);
2208 *----------------------------------------------------------------------
2210 * Handles mouse click on the close button of menus. The menu is
2211 * closed when the button is clicked.
2214 * The closed menu is reinserted at it's parent menus
2216 *----------------------------------------------------------------------
2218 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2220 WMenu
*menu
= (WMenu
*) data
;
2221 WMenu
*parent
= menu
->parent
;
2225 for (i
= 0; i
< parent
->cascade_no
; i
++) {
2226 /* find the entry that points to the copy */
2227 if (parent
->cascades
[i
] == menu
->brother
) {
2228 /* make it point to the original */
2229 parent
->cascades
[i
] = menu
;
2230 menu
->parent
= parent
;
2238 static void saveMenuInfo(WMPropList
* dict
, WMenu
* menu
, WMPropList
* key
)
2240 WMPropList
*value
, *list
;
2243 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2244 value
= WMCreatePLString(buffer
);
2245 list
= WMCreatePLArray(value
, NULL
);
2246 if (menu
->flags
.lowered
)
2247 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2248 WMPutInPLDictionary(dict
, key
, list
);
2249 WMReleasePropList(value
);
2250 WMReleasePropList(list
);
2253 void wMenuSaveState(WScreen
* scr
)
2255 WMPropList
*menus
, *key
;
2258 menus
= WMCreatePLDictionary(NULL
, NULL
);
2260 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2261 key
= WMCreatePLString("SwitchMenu");
2262 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2263 WMReleasePropList(key
);
2267 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2270 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2271 key
= WMCreatePLString("WorkspaceMenu");
2272 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2273 WMReleasePropList(key
);
2278 key
= WMCreatePLString("Menus");
2279 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2280 WMReleasePropList(key
);
2282 WMReleasePropList(menus
);
2285 static Bool
getMenuPath(WMenu
* menu
, char *buffer
, int bufSize
)
2290 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2293 len
= strlen(menu
->frame
->title
);
2298 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2303 strcat(buffer
, "\\");
2304 strcat(buffer
, menu
->frame
->title
);
2309 static Bool
saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
)
2312 int save_menus
= 0, i
;
2316 if (menu
->flags
.brother
)
2317 menu
= menu
->brother
;
2319 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2322 ok
= getMenuPath(menu
, buffer
, 510);
2325 key
= WMCreatePLString(buffer
);
2326 saveMenuInfo(menus
, menu
, key
);
2327 WMReleasePropList(key
);
2333 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2334 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2341 #define COMPLAIN(key) wwarning(_("bad value in menus state info: %s"), key)
2343 static Bool
getMenuInfo(WMPropList
* info
, int *x
, int *y
, Bool
* lowered
)
2349 if (WMIsPLArray(info
)) {
2351 pos
= WMGetFromPLArray(info
, 0);
2352 flags
= WMGetFromPLArray(info
, 1);
2353 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2354 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2361 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2362 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
) != 2)
2363 COMPLAIN("Position");
2365 COMPLAIN("(position, flags...)");
2372 static int restoreMenu(WScreen
* scr
, WMPropList
* menu
, int which
)
2375 Bool lowered
= False
;
2376 WMenu
*pmenu
= NULL
;
2381 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2384 if (which
& WSS_SWITCHMENU
) {
2385 OpenSwitchMenu(scr
, x
, y
, False
);
2386 pmenu
= scr
->switch_menu
;
2390 int width
= MENUW(pmenu
);
2391 int height
= MENUH(pmenu
);
2392 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2395 changeMenuLevels(pmenu
, True
);
2398 if (x
< rect
.pos
.x
- width
)
2400 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2401 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2404 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2405 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2407 wMenuMove(pmenu
, x
, y
, True
);
2408 pmenu
->flags
.buttoned
= 1;
2409 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2415 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
)
2417 WMPropList
*key
, *entry
;
2422 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2425 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2426 key
= WMCreatePLString(buffer
);
2427 entry
= WMGetFromPLDictionary(menus
, key
);
2430 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2432 if (!menu
->flags
.mapped
) {
2433 int width
= MENUW(menu
);
2434 int height
= MENUH(menu
);
2435 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2437 wMenuMapAt(menu
, x
, y
, False
);
2440 /* make parent map the copy in place of the original */
2441 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2442 if (menu
->parent
->cascades
[i
] == menu
) {
2443 menu
->parent
->cascades
[i
] = menu
->brother
;
2449 changeMenuLevels(menu
, True
);
2452 if (x
< rect
.pos
.x
- width
)
2454 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2455 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2458 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2459 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2461 wMenuMove(menu
, x
, y
, True
);
2462 menu
->flags
.buttoned
= 1;
2463 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2468 WMReleasePropList(key
);
2470 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2471 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2478 void wMenuRestoreState(WScreen
* scr
)
2480 WMPropList
*menus
, *menu
, *key
, *skey
;
2482 if (!scr
->session_state
) {
2486 key
= WMCreatePLString("Menus");
2487 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2488 WMReleasePropList(key
);
2495 skey
= WMCreatePLString("SwitchMenu");
2496 menu
= WMGetFromPLDictionary(menus
, skey
);
2497 WMReleasePropList(skey
);
2498 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2500 if (!scr
->root_menu
) {
2501 OpenRootMenu(scr
, scr
->scr_width
* 2, 0, False
);
2502 wMenuUnmap(scr
->root_menu
);
2504 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");