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 #include "switchmenu.h"
49 #define MOD_MASK wPreferences.modifier_mask
51 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
52 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
54 #define MENUW(m) ((m)->frame->core->width+2*(m)->frame->screen_ptr->frame_border_width)
55 #define MENUH(m) ((m)->frame->core->height+2*(m)->frame->screen_ptr->frame_border_width)
57 /***** Local Stuff ******/
59 #define WSS_ROOTMENU (1<<0)
60 #define WSS_SWITCHMENU (1<<1)
61 #define WSS_WSMENU (1<<2)
66 } menuScrollParameters
[5] = {
68 MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
}, {
69 MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
}, {
70 MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
}, {
71 MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
}, {
72 MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
74 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
75 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
);
76 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
77 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
);
78 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
79 static void updateTexture(WMenu
* menu
);
80 static int saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
);
81 static int restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, const char *path
);
82 static void selectEntry(WMenu
* menu
, int entry_no
);
83 static void closeCascade(WMenu
* menu
);
85 /****** Notification Observers ******/
87 static void appearanceObserver(void *self
, WMNotification
* notif
)
89 WMenu
*menu
= (WMenu
*) self
;
90 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
92 if (!menu
->flags
.realized
)
95 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
96 if (flags
& WFontSettings
) {
97 menu
->flags
.realized
= 0;
100 if (flags
& WTextureSettings
) {
101 if (!menu
->flags
.brother
)
104 if (flags
& (WTextureSettings
| WColorSettings
)) {
107 } else if (menu
->flags
.titled
) {
109 if (flags
& WFontSettings
) {
110 menu
->flags
.realized
= 0;
113 if (flags
& WTextureSettings
) {
114 menu
->frame
->flags
.need_texture_remake
= 1;
116 if (flags
& (WColorSettings
| WTextureSettings
)) {
117 wFrameWindowPaint(menu
->frame
);
122 /************************************/
125 *----------------------------------------------------------------------
127 * Creates a new empty menu with the specified title. If main_menu
128 * is True, the created menu will be a main menu, which has some special
129 * properties such as being placed over other normal menus.
130 * If title is NULL, the menu will have no titlebar.
134 *----------------------------------------------------------------------
136 WMenu
*wMenuCreate(WScreen
*screen
, const char *title
, int main_menu
)
139 static int brother
= 0;
142 menu
= wmalloc(sizeof(WMenu
));
144 #ifdef SINGLE_MENULEVEL
145 tmp
= WMSubmenuLevel
;
147 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
150 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
152 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
153 menu
->flags
.titled
= 1;
156 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
,
157 &wPreferences
.menu_title_min_height
,
158 &wPreferences
.menu_title_max_height
,
160 screen
->menu_title_texture
, NULL
,
161 screen
->menu_title_color
, &screen
->menu_title_font
,
162 screen
->w_depth
, screen
->w_visual
, screen
->w_colormap
);
164 menu
->frame
->core
->descriptor
.parent
= menu
;
165 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
166 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
168 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
171 menu
->frame
->title
= wstrdup(title
);
174 menu
->frame
->flags
.justification
= WTJ_LEFT
;
176 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
179 menu
->alloced_entries
= 0;
180 menu
->selected_entry
= -1;
181 menu
->entries
= NULL
;
183 menu
->frame_x
= screen
->app_menu_x
;
184 menu
->frame_y
= screen
->app_menu_y
;
186 menu
->frame
->child
= menu
;
188 menu
->flags
.lowered
= 0;
192 /* setup object descriptors */
193 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
194 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
197 menu
->frame
->on_click_right
= menuCloseClick
;
199 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
, menu
->frame
->core
->width
, 10);
201 menu
->menu
->descriptor
.parent
= menu
;
202 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
203 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
204 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
206 menu
->menu_texture_data
= None
;
208 XMapWindow(dpy
, menu
->menu
->window
);
214 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
216 menu
->brother
->flags
.brother
= 1;
217 menu
->brother
->brother
= menu
;
219 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuAppearanceSettingsChanged
, menu
);
221 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuTitleAppearanceSettingsChanged
, menu
);
226 WMenu
*wMenuCreateForApp(WScreen
*screen
, const char *title
, int main_menu
)
230 menu
= wMenuCreate(screen
, title
, main_menu
);
233 menu
->flags
.app_menu
= 1;
234 menu
->brother
->flags
.app_menu
= 1;
239 static void insertEntry(WMenu
* menu
, WMenuEntry
* entry
, int index
)
243 for (i
= menu
->entry_no
- 1; i
>= index
; i
--) {
244 menu
->entries
[i
]->order
++;
245 menu
->entries
[i
+ 1] = menu
->entries
[i
];
247 menu
->entries
[index
] = entry
;
250 WMenuEntry
*wMenuInsertCallback(WMenu
*menu
, int index
, const char *text
,
251 void (*callback
) (WMenu
* menu
, WMenuEntry
* entry
), void *clientdata
)
255 menu
->flags
.realized
= 0;
256 menu
->brother
->flags
.realized
= 0;
258 /* reallocate array if it's too small */
259 if (menu
->entry_no
>= menu
->alloced_entries
) {
262 tmp
= wrealloc(menu
->entries
, sizeof(WMenuEntry
) * (menu
->alloced_entries
+ 5));
265 menu
->alloced_entries
+= 5;
267 menu
->brother
->entries
= tmp
;
268 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
270 entry
= wmalloc(sizeof(WMenuEntry
));
271 entry
->flags
.enabled
= 1;
272 entry
->text
= wstrdup(text
);
274 entry
->clientdata
= clientdata
;
275 entry
->callback
= callback
;
276 if (index
< 0 || index
>= menu
->entry_no
) {
277 entry
->order
= menu
->entry_no
;
278 menu
->entries
[menu
->entry_no
] = entry
;
280 entry
->order
= index
;
281 insertEntry(menu
, entry
, index
);
285 menu
->brother
->entry_no
= menu
->entry_no
;
290 void wMenuEntrySetCascade(WMenu
* menu
, WMenuEntry
* entry
, WMenu
* cascade
)
292 WMenu
*brother
= menu
->brother
;
295 assert(menu
->flags
.brother
== 0);
297 if (entry
->cascade
>= 0) {
298 menu
->flags
.realized
= 0;
299 brother
->flags
.realized
= 0;
302 cascade
->parent
= menu
;
304 cascade
->brother
->parent
= brother
;
307 for (i
= 0; i
< menu
->cascade_no
; i
++) {
308 if (menu
->cascades
[i
] == NULL
) {
309 menu
->cascades
[i
] = cascade
;
310 brother
->cascades
[i
] = cascade
->brother
;
317 entry
->cascade
= menu
->cascade_no
;
319 menu
->cascades
= wrealloc(menu
->cascades
, sizeof(WMenu
) * (menu
->cascade_no
+ 1));
320 menu
->cascades
[menu
->cascade_no
++] = cascade
;
322 brother
->cascades
= wrealloc(brother
->cascades
, sizeof(WMenu
) * (brother
->cascade_no
+ 1));
323 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
326 if (menu
->flags
.lowered
) {
328 cascade
->flags
.lowered
= 1;
329 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
331 cascade
->brother
->flags
.lowered
= 1;
332 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
335 if (!menu
->flags
.realized
)
339 void wMenuEntryRemoveCascade(WMenu
* menu
, WMenuEntry
* entry
)
341 assert(menu
->flags
.brother
== 0);
343 /* destroy cascade menu */
344 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
] != NULL
) {
346 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
348 menu
->cascades
[entry
->cascade
] = NULL
;
349 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
355 void wMenuRemoveItem(WMenu
* menu
, int index
)
359 if (menu
->flags
.brother
) {
360 wMenuRemoveItem(menu
->brother
, index
);
364 if (index
>= menu
->entry_no
)
367 /* destroy cascade menu */
368 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
370 /* destroy unshared data */
372 if (menu
->entries
[index
]->text
)
373 wfree(menu
->entries
[index
]->text
);
375 if (menu
->entries
[index
]->rtext
)
376 wfree(menu
->entries
[index
]->rtext
);
378 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
379 (*menu
->entries
[index
]->free_cdata
) (menu
->entries
[index
]->clientdata
);
381 wfree(menu
->entries
[index
]);
383 for (i
= index
; i
< menu
->entry_no
- 1; i
++) {
384 menu
->entries
[i
+ 1]->order
--;
385 menu
->entries
[i
] = menu
->entries
[i
+ 1];
388 menu
->brother
->entry_no
--;
391 static Pixmap
renderTexture(WMenu
* menu
)
399 WScreen
*scr
= menu
->menu
->screen_ptr
;
400 WTexture
*texture
= scr
->menu_item_texture
;
402 if (wPreferences
.menu_style
== MS_NORMAL
) {
403 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->entry_height
, WREL_MENUENTRY
);
405 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->menu
->height
+ 1, WREL_MENUENTRY
);
408 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode
));
413 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
415 light
.red
= light
.green
= light
.blue
= 80;
418 dark
.red
= dark
.green
= dark
.blue
= 0;
421 mid
.red
= mid
.green
= mid
.blue
= 40;
423 for (i
= 1; i
< menu
->entry_no
; i
++) {
424 ROperateLine(img
, RSubtractOperation
, 0, i
* menu
->entry_height
- 2,
425 menu
->menu
->width
- 1, i
* menu
->entry_height
- 2, &mid
);
427 RDrawLine(img
, 0, i
* menu
->entry_height
- 1,
428 menu
->menu
->width
- 1, i
* menu
->entry_height
- 1, &dark
);
430 ROperateLine(img
, RAddOperation
, 0, i
* menu
->entry_height
,
431 menu
->menu
->width
- 1, i
* menu
->entry_height
, &light
);
434 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
435 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
442 static void updateTexture(WMenu
* menu
)
444 WScreen
*scr
= menu
->menu
->screen_ptr
;
446 /* setup background texture */
447 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
448 if (!menu
->flags
.brother
) {
449 FREE_PIXMAP(menu
->menu_texture_data
);
451 menu
->menu_texture_data
= renderTexture(menu
);
453 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
, menu
->menu_texture_data
);
454 XClearWindow(dpy
, menu
->menu
->window
);
456 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
, menu
->menu_texture_data
);
457 XClearWindow(dpy
, menu
->brother
->menu
->window
);
460 XSetWindowBackground(dpy
, menu
->menu
->window
, scr
->menu_item_texture
->any
.color
.pixel
);
461 XClearWindow(dpy
, menu
->menu
->window
);
465 void wMenuRealize(WMenu
* menu
)
468 int width
, rwidth
, mrwidth
, mwidth
;
469 int theight
, twidth
, eheight
;
470 WScreen
*scr
= menu
->frame
->screen_ptr
;
471 static int brother_done
= 0;
476 wMenuRealize(menu
->brother
);
480 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
481 if (menu
->flags
.titled
)
482 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
484 wFrameWindowUpdateBorders(menu
->frame
, flags
);
486 if (menu
->flags
.titled
) {
487 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
, strlen(menu
->frame
->title
));
488 theight
= menu
->frame
->top_width
;
489 twidth
+= theight
+ (wPreferences
.new_style
== TS_NEW
? 16 : 8);
494 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
495 menu
->entry_height
= eheight
;
498 for (i
= 0; i
< menu
->entry_no
; i
++) {
501 /* search widest text */
502 text
= menu
->entries
[i
]->text
;
503 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
)) + 10;
505 if (menu
->entries
[i
]->flags
.indicator
) {
506 width
+= MENU_INDICATOR_SPACE
;
512 /* search widest text on right */
513 text
= menu
->entries
[i
]->rtext
;
515 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
517 else if (menu
->entries
[i
]->cascade
>= 0)
522 if (rwidth
> mrwidth
)
530 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
* eheight
- 1);
532 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
* eheight
- 1
533 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
537 menu
->flags
.realized
= 1;
539 if (menu
->flags
.mapped
)
541 if (menu
->brother
->flags
.mapped
)
542 wMenuPaint(menu
->brother
);
545 void wMenuDestroy(WMenu
* menu
, int recurse
)
549 WMRemoveNotificationObserver(menu
);
551 /* remove any pending timers */
553 WMDeleteTimerHandler(menu
->timer
);
556 /* call destroy handler */
557 if (menu
->on_destroy
)
558 (*menu
->on_destroy
) (menu
);
560 /* Destroy items if this menu own them. If this is the "brother" menu,
561 * leave them alone as it is shared by them.
563 if (!menu
->flags
.brother
) {
564 for (i
= 0; i
< menu
->entry_no
; i
++) {
566 wfree(menu
->entries
[i
]->text
);
568 if (menu
->entries
[i
]->rtext
)
569 wfree(menu
->entries
[i
]->rtext
);
572 if (menu
->entries
[i
]->instances
) {
573 WMReleasePropList(menu
->entries
[i
]->instances
);
575 #endif /* USER_MENU */
577 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
578 (*menu
->entries
[i
]->free_cdata
) (menu
->entries
[i
]->clientdata
);
580 wfree(menu
->entries
[i
]);
584 for (i
= 0; i
< menu
->cascade_no
; i
++) {
585 if (menu
->cascades
[i
]) {
586 if (menu
->cascades
[i
]->flags
.brother
)
587 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
589 wMenuDestroy(menu
->cascades
[i
], recurse
);
595 wfree(menu
->entries
);
599 FREE_PIXMAP(menu
->menu_texture_data
);
602 wfree(menu
->cascades
);
604 wCoreDestroy(menu
->menu
);
605 wFrameWindowDestroy(menu
->frame
);
607 /* destroy copy of this menu */
608 if (!menu
->flags
.brother
&& menu
->brother
)
609 wMenuDestroy(menu
->brother
, False
);
619 static void drawFrame(WScreen
* scr
, Drawable win
, int y
, int w
, int h
, int type
)
625 segs
[i
].x1
= segs
[i
].x2
= w
- 1;
627 segs
[i
].y2
= y
+ h
- 1;
629 if (type
!= F_TOP
&& type
!= F_NONE
) {
631 segs
[i
].y1
= segs
[i
].y2
= y
+ h
- 2;
635 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
641 segs
[i
].y2
= y
+ h
- 1;
643 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
650 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
652 if (type
!= F_TOP
&& type
!= F_NONE
)
653 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+ h
- 1, w
- 1, y
+ h
- 1);
656 static void paintEntry(WMenu
* menu
, int index
, int selected
)
658 WScreen
*scr
= menu
->frame
->screen_ptr
;
659 Window win
= menu
->menu
->window
;
660 WMenuEntry
*entry
= menu
->entries
[index
];
666 if (!menu
->flags
.realized
)
668 h
= menu
->entry_height
;
669 w
= menu
->menu
->width
;
672 light
= scr
->menu_item_auxtexture
->light_gc
;
673 dim
= scr
->menu_item_auxtexture
->dim_gc
;
674 dark
= scr
->menu_item_auxtexture
->dark_gc
;
676 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
679 else if (index
== menu
->entry_no
- 1)
687 /* paint background */
689 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+ 1, w
- 2, h
- 3);
690 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
691 drawFrame(scr
, win
, y
, w
, h
, type
);
693 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
694 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
696 drawFrame(scr
, win
, y
, w
, h
, type
);
698 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
703 if (entry
->flags
.enabled
)
704 color
= scr
->select_text_color
;
706 color
= scr
->dtext_color
;
707 } else if (!entry
->flags
.enabled
) {
708 color
= scr
->dtext_color
;
710 color
= scr
->mtext_color
;
714 if (entry
->flags
.indicator
)
715 x
+= MENU_INDICATOR_SPACE
+ 2;
717 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
718 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
720 if (entry
->cascade
>= 0) {
721 /* draw the cascade indicator */
722 XDrawLine(dpy
, win
, dim
, w
- 11, y
+ 6, w
- 6, y
+ h
/ 2 - 1);
723 XDrawLine(dpy
, win
, light
, w
- 11, y
+ h
- 8, w
- 6, y
+ h
/ 2 - 1);
724 XDrawLine(dpy
, win
, dark
, w
- 12, y
+ 6, w
- 12, y
+ h
- 8);
728 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
732 switch (entry
->flags
.indicator_type
) {
734 indicator
= scr
->menu_check_indicator
;
737 indicator
= scr
->menu_mini_indicator
;
740 indicator
= scr
->menu_hide_indicator
;
743 indicator
= scr
->menu_shade_indicator
;
747 indicator
= scr
->menu_radio_indicator
;
751 iw
= indicator
->width
;
752 ih
= indicator
->height
;
753 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
754 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2);
756 if (entry
->flags
.enabled
) {
757 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
759 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
762 if (entry
->flags
.enabled
) {
763 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
765 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
768 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2, iw
, ih
);
770 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
771 iw, ih, 5, y+(h-ih)/2);
773 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
776 /* draw right text */
778 if (entry
->rtext
&& entry
->cascade
< 0) {
779 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
, strlen(entry
->rtext
));
781 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
- 6 - tw
,
782 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
786 static void move_menus(WMenu
* menu
, int x
, int y
)
788 while (menu
->parent
) {
791 if (!wPreferences
.align_menus
&& menu
->selected_entry
>= 0) {
792 y
-= menu
->selected_entry
* menu
->entry_height
;
795 wMenuMove(menu
, x
, y
, True
);
798 static void makeVisible(WMenu
* menu
)
800 WScreen
*scr
= menu
->frame
->screen_ptr
;
801 int x1
, y1
, x2
, y2
, new_x
, new_y
;
802 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
804 if (menu
->entry_no
< 0)
808 y1
= menu
->frame_y
+ menu
->frame
->top_width
+ menu
->selected_entry
* menu
->entry_height
;
809 x2
= x1
+ MENUW(menu
);
810 y2
= y1
+ menu
->entry_height
;
815 if (x1
< rect
.pos
.x
) {
817 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
818 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
821 if (y1
< rect
.pos
.y
) {
823 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
824 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
827 new_y
= new_y
- menu
->frame
->top_width
- menu
->selected_entry
* menu
->entry_height
;
828 move_menus(menu
, new_x
, new_y
);
831 static int check_key(WMenu
* menu
, XKeyEvent
* event
)
836 if (XLookupString(event
, buffer
, 32, NULL
, NULL
) < 1)
839 ch
= toupper(buffer
[0]);
841 s
= (menu
->selected_entry
>= 0 ? menu
->selected_entry
+ 1 : 0);
844 for (i
= s
; i
< menu
->entry_no
; i
++) {
845 if (ch
== toupper(menu
->entries
[i
]->text
[0])) {
849 /* no match. Retry from start, if previous started from a selected entry */
857 static int keyboardMenu(WMenu
* menu
)
860 KeySym ksym
= NoSymbol
;
864 int old_pos_x
= menu
->frame_x
;
865 int old_pos_y
= menu
->frame_y
;
866 int new_x
= old_pos_x
, new_y
= old_pos_y
;
867 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
868 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
870 if (menu
->flags
.editing
)
873 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
875 if (menu
->frame_y
+ menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
876 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
878 if (menu
->frame_x
+ MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
879 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
881 move_menus(menu
, new_x
, new_y
);
883 while (!done
&& menu
->flags
.mapped
) {
884 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
885 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonPressMask
886 | ButtonReleaseMask
| KeyPressMask
| KeyReleaseMask
| SubstructureNotifyMask
, &event
);
888 switch (event
.type
) {
890 ksym
= XLookupKeysym(&event
.xkey
, 0);
891 if (wPreferences
.vi_key_menus
) {
920 selectEntry(menu
, 0);
928 selectEntry(menu
, menu
->entry_no
- 1);
936 if (menu
->selected_entry
<= 0)
937 selectEntry(menu
, menu
->entry_no
- 1);
939 selectEntry(menu
, menu
->selected_entry
- 1);
947 if (menu
->selected_entry
< 0)
948 selectEntry(menu
, 0);
949 else if (menu
->selected_entry
== menu
->entry_no
- 1)
950 selectEntry(menu
, 0);
951 else if (menu
->selected_entry
< menu
->entry_no
- 1)
952 selectEntry(menu
, menu
->selected_entry
+ 1);
960 if (menu
->selected_entry
>= 0) {
962 entry
= menu
->entries
[menu
->selected_entry
];
964 if (entry
->cascade
>= 0 && menu
->cascades
965 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
967 XUngrabKeyboard(dpy
, CurrentTime
);
969 selectEntry(menu
->cascades
[entry
->cascade
], 0);
970 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
973 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
974 GrabModeAsync
, GrabModeAsync
, CurrentTime
);
983 if (menu
->parent
!= NULL
&& menu
->parent
->selected_entry
>= 0) {
984 selectEntry(menu
, -1);
985 move_menus(menu
, old_pos_x
, old_pos_y
);
998 index
= check_key(menu
, &event
.xkey
);
1000 selectEntry(menu
, index
);
1006 if (event
.type
== ButtonPress
)
1009 WMHandleEvent(&event
);
1013 XUngrabKeyboard(dpy
, CurrentTime
);
1015 if (done
== 2 && menu
->selected_entry
>= 0) {
1016 entry
= menu
->entries
[menu
->selected_entry
];
1021 if (entry
&& entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1022 #if (MENU_BLINK_COUNT > 0)
1023 int sel
= menu
->selected_entry
;
1026 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1027 paintEntry(menu
, sel
, False
);
1029 wusleep(MENU_BLINK_DELAY
);
1030 paintEntry(menu
, sel
, True
);
1032 wusleep(MENU_BLINK_DELAY
);
1035 selectEntry(menu
, -1);
1037 if (!menu
->flags
.buttoned
) {
1039 move_menus(menu
, old_pos_x
, old_pos_y
);
1043 (*entry
->callback
) (menu
, entry
);
1045 if (!menu
->flags
.buttoned
) {
1047 move_menus(menu
, old_pos_x
, old_pos_y
);
1049 selectEntry(menu
, -1);
1052 /* returns True if returning from a submenu to a parent menu,
1053 * False if exiting from menu */
1057 void wMenuMapAt(WMenu
* menu
, int x
, int y
, int keyboard
)
1059 if (!menu
->flags
.realized
) {
1060 menu
->flags
.realized
= 1;
1064 if (!menu
->flags
.mapped
) {
1065 if (wPreferences
.wrap_menus
) {
1066 WScreen
*scr
= menu
->frame
->screen_ptr
;
1067 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1073 if (x
+ MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1074 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1075 if (y
+ MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1076 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1079 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1082 XMapWindow(dpy
, menu
->frame
->core
->window
);
1083 wRaiseFrame(menu
->frame
->core
);
1084 menu
->flags
.mapped
= 1;
1086 selectEntry(menu
, 0);
1093 void wMenuMap(WMenu
* menu
)
1095 if (!menu
->flags
.realized
) {
1096 menu
->flags
.realized
= 1;
1099 if (menu
->flags
.app_menu
&& menu
->parent
== NULL
) {
1100 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1101 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1102 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1104 XMapWindow(dpy
, menu
->frame
->core
->window
);
1105 wRaiseFrame(menu
->frame
->core
);
1106 menu
->flags
.mapped
= 1;
1109 void wMenuUnmap(WMenu
* menu
)
1113 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1114 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1115 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1117 menu
->flags
.buttoned
= 0;
1118 menu
->flags
.mapped
= 0;
1119 menu
->flags
.open_to_left
= 0;
1121 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1122 if (menu
->cascades
[i
] != NULL
1123 && menu
->cascades
[i
]->flags
.mapped
&& !menu
->cascades
[i
]->flags
.buttoned
) {
1125 wMenuUnmap(menu
->cascades
[i
]);
1128 menu
->selected_entry
= -1;
1131 void wMenuPaint(WMenu
* menu
)
1135 if (!menu
->flags
.mapped
) {
1140 for (i
= 0; i
< menu
->entry_no
; i
++) {
1141 paintEntry(menu
, i
, i
== menu
->selected_entry
);
1145 void wMenuSetEnabled(WMenu
* menu
, int index
, int enable
)
1147 if (index
>= menu
->entry_no
)
1149 menu
->entries
[index
]->flags
.enabled
= enable
;
1150 paintEntry(menu
, index
, index
== menu
->selected_entry
);
1151 paintEntry(menu
->brother
, index
, index
== menu
->selected_entry
);
1155 static void selectEntry(WMenu
* menu
, int entry_no
)
1161 if (menu
->entries
== NULL
)
1164 if (entry_no
>= menu
->entry_no
)
1167 old_entry
= menu
->selected_entry
;
1168 menu
->selected_entry
= entry_no
;
1170 if (old_entry
!= entry_no
) {
1172 /* unselect previous entry */
1173 if (old_entry
>= 0) {
1174 paintEntry(menu
, old_entry
, False
);
1175 entry
= menu
->entries
[old_entry
];
1178 if (entry
->cascade
>= 0 && menu
->cascades
) {
1179 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1180 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1186 menu
->selected_entry
= -1;
1189 entry
= menu
->entries
[entry_no
];
1191 if (entry
->cascade
>= 0 && menu
->cascades
&& entry
->flags
.enabled
) {
1192 /* Callback for when the submenu is opened.
1194 submenu
= menu
->cascades
[entry
->cascade
];
1195 if (submenu
&& submenu
->flags
.brother
)
1196 submenu
= submenu
->brother
;
1198 if (entry
->callback
) {
1199 /* Only call the callback if the submenu is not yet mapped.
1201 if (menu
->flags
.brother
) {
1202 if (!submenu
|| !submenu
->flags
.mapped
)
1203 (*entry
->callback
) (menu
->brother
, entry
);
1205 if (!submenu
|| !submenu
->flags
.buttoned
)
1206 (*entry
->callback
) (menu
, entry
);
1210 /* the submenu menu might have changed */
1211 submenu
= menu
->cascades
[entry
->cascade
];
1214 if (!submenu
->flags
.mapped
) {
1217 if (!submenu
->flags
.realized
)
1218 wMenuRealize(submenu
);
1219 if (wPreferences
.wrap_menus
) {
1220 if (menu
->flags
.open_to_left
)
1221 submenu
->flags
.open_to_left
= 1;
1223 if (submenu
->flags
.open_to_left
) {
1224 x
= menu
->frame_x
- MENUW(submenu
);
1227 submenu
->flags
.open_to_left
= 0;
1230 x
= menu
->frame_x
+ MENUW(menu
);
1232 if (x
+ MENUW(submenu
)
1233 >= menu
->frame
->screen_ptr
->scr_width
) {
1235 x
= menu
->frame_x
- MENUW(submenu
);
1236 submenu
->flags
.open_to_left
= 1;
1240 x
= menu
->frame_x
+ MENUW(menu
);
1243 if (wPreferences
.align_menus
) {
1246 y
= menu
->frame_y
+ menu
->entry_height
* entry_no
;
1247 if (menu
->flags
.titled
)
1248 y
+= menu
->frame
->top_width
;
1249 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1250 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1253 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1254 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1259 paintEntry(menu
, entry_no
, True
);
1263 static WMenu
*findMenu(WScreen
* scr
, int *x_ret
, int *y_ret
)
1266 WObjDescriptor
*desc
;
1267 Window root_ret
, win
, junk_win
;
1271 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
, &mask
);
1276 if (XFindContext(dpy
, win
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
)
1279 if (desc
->parent_type
== WCLASS_MENU
) {
1280 menu
= (WMenu
*) desc
->parent
;
1281 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
, x_ret
, y_ret
, &junk_win
);
1287 static void closeCascade(WMenu
* menu
)
1289 WMenu
*parent
= menu
->parent
;
1291 if (menu
->flags
.brother
|| (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
))) {
1293 selectEntry(menu
, -1);
1295 #if (MENU_BLINK_DELAY > 2)
1296 wusleep(MENU_BLINK_DELAY
/ 2);
1299 while (parent
!= NULL
1300 && (parent
->parent
!= NULL
|| !parent
->flags
.app_menu
|| parent
->flags
.brother
)
1301 && !parent
->flags
.buttoned
) {
1302 selectEntry(parent
, -1);
1304 parent
= parent
->parent
;
1307 selectEntry(parent
, -1);
1311 static void closeBrotherCascadesOf(WMenu
* menu
)
1316 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1317 if (menu
->cascades
[i
]->flags
.brother
) {
1318 tmp
= menu
->cascades
[i
];
1320 tmp
= menu
->cascades
[i
]->brother
;
1322 if (tmp
->flags
.mapped
) {
1323 selectEntry(tmp
->parent
, -1);
1324 closeBrotherCascadesOf(tmp
);
1330 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1332 static WMenu
*parentMenu(WMenu
* menu
)
1337 if (menu
->flags
.buttoned
)
1340 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1341 parent
= menu
->parent
;
1342 if (parent
->selected_entry
< 0)
1344 entry
= parent
->entries
[parent
->selected_entry
];
1345 if (!entry
->flags
.enabled
|| entry
->cascade
< 0 || !parent
->cascades
||
1346 parent
->cascades
[entry
->cascade
] != menu
)
1349 if (menu
->flags
.buttoned
)
1357 * Will raise the passed menu, if submenu = 0
1358 * If submenu > 0 will also raise all mapped submenus
1359 * until the first buttoned one
1360 * If submenu < 0 will also raise all mapped parent menus
1361 * until the first buttoned one
1364 static void raiseMenus(WMenu
* menu
, int submenus
)
1372 wRaiseFrame(menu
->frame
->core
);
1374 if (submenus
> 0 && menu
->selected_entry
>= 0) {
1375 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1376 if (i
>= 0 && menu
->cascades
) {
1377 submenu
= menu
->cascades
[i
];
1378 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1379 raiseMenus(submenu
, submenus
);
1382 if (submenus
< 0 && !menu
->flags
.buttoned
&& menu
->parent
&& menu
->parent
->flags
.mapped
)
1383 raiseMenus(menu
->parent
, submenus
);
1386 WMenu
*wMenuUnderPointer(WScreen
* screen
)
1388 WObjDescriptor
*desc
;
1389 Window root_ret
, win
;
1393 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
, &dummy
, &dummy
, &mask
);
1398 if (XFindContext(dpy
, win
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
)
1401 if (desc
->parent_type
== WCLASS_MENU
)
1402 return (WMenu
*) desc
->parent
;
1406 static void getPointerPosition(WScreen
* scr
, int *x
, int *y
)
1408 Window root_ret
, win
;
1412 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1415 static void getScrollAmount(WMenu
* menu
, int *hamount
, int *vamount
)
1417 WScreen
*scr
= menu
->menu
->screen_ptr
;
1418 int menuX1
= menu
->frame_x
;
1419 int menuY1
= menu
->frame_y
;
1420 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1421 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1423 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1428 getPointerPosition(scr
, &xroot
, &yroot
);
1430 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1431 /* scroll to the right */
1432 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1434 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) && menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1435 /* scroll to the left */
1436 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
- rect
.pos
.x
- rect
.size
.width
- 1));
1441 *hamount
= -*hamount
;
1444 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1446 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1448 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) && menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1450 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
- rect
.pos
.y
- rect
.size
.height
- 2));
1452 *vamount
= -*vamount
;
1456 static void dragScrollMenuCallback(void *data
)
1458 WMenu
*menu
= (WMenu
*) data
;
1459 WScreen
*scr
= menu
->menu
->screen_ptr
;
1460 WMenu
*parent
= parentMenu(menu
);
1461 int hamount
, vamount
;
1463 int newSelectedEntry
;
1465 getScrollAmount(menu
, &hamount
, &vamount
);
1467 if (hamount
!= 0 || vamount
!= 0) {
1468 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1469 if (findMenu(scr
, &x
, &y
)) {
1470 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1471 selectEntry(menu
, newSelectedEntry
);
1473 /* Pointer fell outside of menu. If the selected entry is
1474 * not a submenu, unselect it */
1475 if (menu
->selected_entry
>= 0 && menu
->entries
[menu
->selected_entry
]->cascade
< 0)
1476 selectEntry(menu
, -1);
1477 newSelectedEntry
= 0;
1480 /* paranoid check */
1481 if (newSelectedEntry
>= 0) {
1482 /* keep scrolling */
1483 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, dragScrollMenuCallback
, menu
);
1488 /* don't need to scroll anymore */
1490 if (findMenu(scr
, &x
, &y
)) {
1491 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1492 selectEntry(menu
, newSelectedEntry
);
1497 static void scrollMenuCallback(void *data
)
1499 WMenu
*menu
= (WMenu
*) data
;
1500 WMenu
*parent
= parentMenu(menu
);
1501 int hamount
= 0; /* amount to scroll */
1504 getScrollAmount(menu
, &hamount
, &vamount
);
1506 if (hamount
!= 0 || vamount
!= 0) {
1507 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1509 /* keep scrolling */
1510 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, scrollMenuCallback
, menu
);
1512 /* don't need to scroll anymore */
1517 #define MENU_SCROLL_BORDER 5
1519 static int isPointNearBoder(WMenu
* menu
, int x
, int y
)
1521 int menuX1
= menu
->frame_x
;
1522 int menuY1
= menu
->frame_y
;
1523 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1524 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1526 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1527 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1529 /* XXX: handle screen joins properly !! */
1531 if (x
>= menuX1
&& x
<= menuX2
&&
1532 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
|| y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1534 else if (y
>= menuY1
&& y
<= menuY2
&&
1535 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
|| x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1541 typedef struct _delay
{
1546 static void leaving(_delay
* dl
)
1548 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1549 dl
->menu
->jump_back
= NULL
;
1550 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1554 void wMenuScroll(WMenu
* menu
, XEvent
* event
)
1557 WMenu
*omenu
= parentMenu(menu
);
1558 WScreen
*scr
= menu
->frame
->screen_ptr
;
1561 int old_frame_x
= omenu
->frame_x
;
1562 int old_frame_y
= omenu
->frame_y
;
1565 if (omenu
->jump_back
)
1566 WMDeleteTimerWithClientData(omenu
->jump_back
);
1568 if (( /*omenu->flags.buttoned && */ !wPreferences
.wrap_menus
)
1569 || omenu
->flags
.app_menu
) {
1573 if (!wPreferences
.wrap_menus
)
1574 raiseMenus(omenu
, True
);
1576 raiseMenus(menu
, False
);
1579 scrollMenuCallback(menu
);
1582 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1585 WMNextEvent(dpy
, &ev
);
1590 x
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1591 y
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1593 /* on_border is != 0 if the pointer is between the menu
1594 * and the screen border and is close enough to the border */
1595 on_border
= isPointNearBoder(menu
, x
, y
);
1597 smenu
= wMenuUnderPointer(scr
);
1599 if ((smenu
== NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
) != omenu
)) {
1604 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1605 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1606 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1607 on_border
= on_x_edge
|| on_y_edge
;
1609 if (!on_border
&& !jump_back
) {
1614 if (menu
->timer
&& (smenu
!= menu
|| (!on_y_edge
&& !on_x_edge
))) {
1615 WMDeleteTimerHandler(menu
->timer
);
1623 scrollMenuCallback(menu
);
1626 /* True if we push on title, or drag the omenu to other position */
1627 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1628 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1629 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1630 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1632 smenu
= wMenuUnderPointer(scr
);
1633 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1635 else if (smenu
== omenu
&& on_title
) {
1649 WMDeleteTimerHandler(menu
->timer
);
1655 if (!omenu
->jump_back
) {
1656 delayer
= wmalloc(sizeof(_delay
));
1657 delayer
->menu
= omenu
;
1658 delayer
->ox
= old_frame_x
;
1659 delayer
->oy
= old_frame_y
;
1660 omenu
->jump_back
= delayer
;
1661 scr
->flags
.jump_back_pending
= 1;
1663 delayer
= omenu
->jump_back
;
1664 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
, (WMCallback
*) leaving
, delayer
);
1668 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
)
1670 /* Parameter not used, but tell the compiler that it is ok */
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
- 3; /* Entries "New", "Destroy Last" and "Last Used" appear before workspaces */
1767 name
= wstrdup(w_global
.workspace
.array
[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 wPreferences
.cursor
[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 (w_global
.workspace
.menu
&& w_global
.workspace
.menu
->flags
.buttoned
) {
2271 key
= WMCreatePLString("WorkspaceMenu");
2272 saveMenuInfo(menus
, w_global
.workspace
.menu
, key
);
2273 WMReleasePropList(key
);
2278 key
= WMCreatePLString("Menus");
2279 WMPutInPLDictionary(w_global
.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
, const 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 (!w_global
.session_state
)
2485 key
= WMCreatePLString("Menus");
2486 menus
= WMGetFromPLDictionary(w_global
.session_state
, key
);
2487 WMReleasePropList(key
);
2494 skey
= WMCreatePLString("SwitchMenu");
2495 menu
= WMGetFromPLDictionary(menus
, skey
);
2496 WMReleasePropList(skey
);
2497 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2499 if (!scr
->root_menu
) {
2500 OpenRootMenu(scr
, scr
->scr_width
* 2, 0, False
);
2501 wMenuUnmap(scr
->root_menu
);
2503 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");