1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
27 #include <X11/keysym.h>
35 #include "WindowMaker.h"
43 #include "workspace.h"
47 /****** Global Variables ******/
49 extern Cursor wCursor
[WCUR_LAST
];
51 extern XContext wWinContext
;
53 extern WPreferences wPreferences
;
55 #define MOD_MASK wPreferences.modifier_mask
57 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
58 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
60 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
61 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
63 /***** Local Stuff ******/
65 #define WSS_ROOTMENU (1<<0)
66 #define WSS_SWITCHMENU (1<<1)
67 #define WSS_WSMENU (1<<2)
72 } menuScrollParameters
[5] = {
74 MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
}, {
75 MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
}, {
76 MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
}, {
77 MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
}, {
78 MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
80 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
81 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
);
82 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
83 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
);
84 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
85 static void updateTexture(WMenu
* menu
);
86 static int saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
);
87 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
);
88 static void selectEntry(WMenu
* menu
, int entry_no
);
89 static void closeCascade(WMenu
* menu
);
91 /****** Notification Observers ******/
93 static void appearanceObserver(void *self
, WMNotification
* notif
)
95 WMenu
*menu
= (WMenu
*) self
;
96 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
98 if (!menu
->flags
.realized
)
101 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
102 if (flags
& WFontSettings
) {
103 menu
->flags
.realized
= 0;
106 if (flags
& WTextureSettings
) {
107 if (!menu
->flags
.brother
)
110 if (flags
& (WTextureSettings
| WColorSettings
)) {
113 } else if (menu
->flags
.titled
) {
115 if (flags
& WFontSettings
) {
116 menu
->flags
.realized
= 0;
119 if (flags
& WTextureSettings
) {
120 menu
->frame
->flags
.need_texture_remake
= 1;
122 if (flags
& (WColorSettings
| WTextureSettings
)) {
123 wFrameWindowPaint(menu
->frame
);
128 /************************************/
131 *----------------------------------------------------------------------
133 * Creates a new empty menu with the specified title. If main_menu
134 * is True, the created menu will be a main menu, which has some special
135 * properties such as being placed over other normal menus.
136 * If title is NULL, the menu will have no titlebar.
140 *----------------------------------------------------------------------
142 WMenu
*wMenuCreate(WScreen
* screen
, char *title
, int main_menu
)
145 static int brother
= 0;
148 menu
= wmalloc(sizeof(WMenu
));
150 #ifdef SINGLE_MENULEVEL
151 tmp
= WMSubmenuLevel
;
153 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
156 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
158 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
159 menu
->flags
.titled
= 1;
162 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
,
163 &wPreferences
.menu_title_min_height
,
164 &wPreferences
.menu_title_max_height
,
166 screen
->menu_title_texture
, NULL
,
167 screen
->menu_title_color
, &screen
->menu_title_font
,
168 screen
->w_depth
, screen
->w_visual
, screen
->w_colormap
);
170 menu
->frame
->core
->descriptor
.parent
= menu
;
171 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
172 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
174 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
177 menu
->frame
->title
= wstrdup(title
);
180 menu
->frame
->flags
.justification
= WTJ_LEFT
;
182 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
185 menu
->alloced_entries
= 0;
186 menu
->selected_entry
= -1;
187 menu
->entries
= NULL
;
189 menu
->frame_x
= screen
->app_menu_x
;
190 menu
->frame_y
= screen
->app_menu_y
;
192 menu
->frame
->child
= menu
;
194 menu
->flags
.lowered
= 0;
198 /* setup object descriptors */
199 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
200 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
203 menu
->frame
->on_click_right
= menuCloseClick
;
205 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
, menu
->frame
->core
->width
, 10);
207 menu
->menu
->descriptor
.parent
= menu
;
208 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
209 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
210 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
212 menu
->menu_texture_data
= None
;
214 XMapWindow(dpy
, menu
->menu
->window
);
220 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
222 menu
->brother
->flags
.brother
= 1;
223 menu
->brother
->brother
= menu
;
225 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuAppearanceSettingsChanged
, menu
);
227 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuTitleAppearanceSettingsChanged
, menu
);
232 WMenu
*wMenuCreateForApp(WScreen
* screen
, char *title
, int main_menu
)
236 menu
= wMenuCreate(screen
, title
, main_menu
);
239 menu
->flags
.app_menu
= 1;
240 menu
->brother
->flags
.app_menu
= 1;
245 static void insertEntry(WMenu
* menu
, WMenuEntry
* entry
, int index
)
249 for (i
= menu
->entry_no
- 1; i
>= index
; i
--) {
250 menu
->entries
[i
]->order
++;
251 menu
->entries
[i
+ 1] = menu
->entries
[i
];
253 menu
->entries
[index
] = entry
;
256 WMenuEntry
*wMenuInsertCallback(WMenu
* menu
, int index
, char *text
,
257 void (*callback
) (WMenu
* menu
, WMenuEntry
* entry
), void *clientdata
)
261 menu
->flags
.realized
= 0;
262 menu
->brother
->flags
.realized
= 0;
264 /* reallocate array if it's too small */
265 if (menu
->entry_no
>= menu
->alloced_entries
) {
268 tmp
= wrealloc(menu
->entries
, sizeof(WMenuEntry
) * (menu
->alloced_entries
+ 5));
271 menu
->alloced_entries
+= 5;
273 menu
->brother
->entries
= tmp
;
274 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
276 entry
= wmalloc(sizeof(WMenuEntry
));
277 entry
->flags
.enabled
= 1;
278 entry
->text
= wstrdup(text
);
280 entry
->clientdata
= clientdata
;
281 entry
->callback
= callback
;
282 if (index
< 0 || index
>= menu
->entry_no
) {
283 entry
->order
= menu
->entry_no
;
284 menu
->entries
[menu
->entry_no
] = entry
;
286 entry
->order
= index
;
287 insertEntry(menu
, entry
, index
);
291 menu
->brother
->entry_no
= menu
->entry_no
;
296 void wMenuEntrySetCascade(WMenu
* menu
, WMenuEntry
* entry
, WMenu
* cascade
)
298 WMenu
*brother
= menu
->brother
;
301 assert(menu
->flags
.brother
== 0);
303 if (entry
->cascade
>= 0) {
304 menu
->flags
.realized
= 0;
305 brother
->flags
.realized
= 0;
308 cascade
->parent
= menu
;
310 cascade
->brother
->parent
= brother
;
313 for (i
= 0; i
< menu
->cascade_no
; i
++) {
314 if (menu
->cascades
[i
] == NULL
) {
315 menu
->cascades
[i
] = cascade
;
316 brother
->cascades
[i
] = cascade
->brother
;
323 entry
->cascade
= menu
->cascade_no
;
325 menu
->cascades
= wrealloc(menu
->cascades
, sizeof(WMenu
) * (menu
->cascade_no
+ 1));
326 menu
->cascades
[menu
->cascade_no
++] = cascade
;
328 brother
->cascades
= wrealloc(brother
->cascades
, sizeof(WMenu
) * (brother
->cascade_no
+ 1));
329 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
332 if (menu
->flags
.lowered
) {
334 cascade
->flags
.lowered
= 1;
335 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
337 cascade
->brother
->flags
.lowered
= 1;
338 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
341 if (!menu
->flags
.realized
)
345 void wMenuEntryRemoveCascade(WMenu
* menu
, WMenuEntry
* entry
)
347 assert(menu
->flags
.brother
== 0);
349 /* destroy cascade menu */
350 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
] != NULL
) {
352 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
354 menu
->cascades
[entry
->cascade
] = NULL
;
355 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
361 void wMenuRemoveItem(WMenu
* menu
, int index
)
365 if (menu
->flags
.brother
) {
366 wMenuRemoveItem(menu
->brother
, index
);
370 if (index
>= menu
->entry_no
)
373 /* destroy cascade menu */
374 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
376 /* destroy unshared data */
378 if (menu
->entries
[index
]->text
)
379 wfree(menu
->entries
[index
]->text
);
381 if (menu
->entries
[index
]->rtext
)
382 wfree(menu
->entries
[index
]->rtext
);
384 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
385 (*menu
->entries
[index
]->free_cdata
) (menu
->entries
[index
]->clientdata
);
387 wfree(menu
->entries
[index
]);
389 for (i
= index
; i
< menu
->entry_no
- 1; i
++) {
390 menu
->entries
[i
+ 1]->order
--;
391 menu
->entries
[i
] = menu
->entries
[i
+ 1];
394 menu
->brother
->entry_no
--;
397 static Pixmap
renderTexture(WMenu
* menu
)
405 WScreen
*scr
= menu
->menu
->screen_ptr
;
406 WTexture
*texture
= scr
->menu_item_texture
;
408 if (wPreferences
.menu_style
== MS_NORMAL
) {
409 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->entry_height
, WREL_MENUENTRY
);
411 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->menu
->height
+ 1, WREL_MENUENTRY
);
414 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode
));
419 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
421 light
.red
= light
.green
= light
.blue
= 80;
424 dark
.red
= dark
.green
= dark
.blue
= 0;
427 mid
.red
= mid
.green
= mid
.blue
= 40;
429 for (i
= 1; i
< menu
->entry_no
; i
++) {
430 ROperateLine(img
, RSubtractOperation
, 0, i
* menu
->entry_height
- 2,
431 menu
->menu
->width
- 1, i
* menu
->entry_height
- 2, &mid
);
433 RDrawLine(img
, 0, i
* menu
->entry_height
- 1,
434 menu
->menu
->width
- 1, i
* menu
->entry_height
- 1, &dark
);
436 ROperateLine(img
, RAddOperation
, 0, i
* menu
->entry_height
,
437 menu
->menu
->width
- 1, i
* menu
->entry_height
, &light
);
440 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
441 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
448 static void updateTexture(WMenu
* menu
)
450 WScreen
*scr
= menu
->menu
->screen_ptr
;
452 /* setup background texture */
453 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
454 if (!menu
->flags
.brother
) {
455 FREE_PIXMAP(menu
->menu_texture_data
);
457 menu
->menu_texture_data
= renderTexture(menu
);
459 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
, menu
->menu_texture_data
);
460 XClearWindow(dpy
, menu
->menu
->window
);
462 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
, menu
->menu_texture_data
);
463 XClearWindow(dpy
, menu
->brother
->menu
->window
);
466 XSetWindowBackground(dpy
, menu
->menu
->window
, scr
->menu_item_texture
->any
.color
.pixel
);
467 XClearWindow(dpy
, menu
->menu
->window
);
471 void wMenuRealize(WMenu
* menu
)
474 int width
, rwidth
, mrwidth
, mwidth
;
475 int theight
, twidth
, eheight
;
476 WScreen
*scr
= menu
->frame
->screen_ptr
;
477 static int brother_done
= 0;
482 wMenuRealize(menu
->brother
);
486 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
487 if (menu
->flags
.titled
)
488 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
490 wFrameWindowUpdateBorders(menu
->frame
, flags
);
492 if (menu
->flags
.titled
) {
493 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
, strlen(menu
->frame
->title
));
494 theight
= menu
->frame
->top_width
;
495 twidth
+= theight
+ (wPreferences
.new_style
== TS_NEW
? 16 : 8);
500 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
501 menu
->entry_height
= eheight
;
504 for (i
= 0; i
< menu
->entry_no
; i
++) {
507 /* search widest text */
508 text
= menu
->entries
[i
]->text
;
509 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
)) + 10;
511 if (menu
->entries
[i
]->flags
.indicator
) {
512 width
+= MENU_INDICATOR_SPACE
;
518 /* search widest text on right */
519 text
= menu
->entries
[i
]->rtext
;
521 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
523 else if (menu
->entries
[i
]->cascade
>= 0)
528 if (rwidth
> mrwidth
)
536 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
* eheight
- 1);
538 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
* eheight
- 1
539 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
543 menu
->flags
.realized
= 1;
545 if (menu
->flags
.mapped
)
547 if (menu
->brother
->flags
.mapped
)
548 wMenuPaint(menu
->brother
);
551 void wMenuDestroy(WMenu
* menu
, int recurse
)
555 WMRemoveNotificationObserver(menu
);
557 /* remove any pending timers */
559 WMDeleteTimerHandler(menu
->timer
);
562 /* call destroy handler */
563 if (menu
->on_destroy
)
564 (*menu
->on_destroy
) (menu
);
566 /* Destroy items if this menu own them. If this is the "brother" menu,
567 * leave them alone as it is shared by them.
569 if (!menu
->flags
.brother
) {
570 for (i
= 0; i
< menu
->entry_no
; i
++) {
572 wfree(menu
->entries
[i
]->text
);
574 if (menu
->entries
[i
]->rtext
)
575 wfree(menu
->entries
[i
]->rtext
);
578 if (menu
->entries
[i
]->instances
) {
579 WMReleasePropList(menu
->entries
[i
]->instances
);
581 #endif /* USER_MENU */
583 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
584 (*menu
->entries
[i
]->free_cdata
) (menu
->entries
[i
]->clientdata
);
586 wfree(menu
->entries
[i
]);
590 for (i
= 0; i
< menu
->cascade_no
; i
++) {
591 if (menu
->cascades
[i
]) {
592 if (menu
->cascades
[i
]->flags
.brother
)
593 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
595 wMenuDestroy(menu
->cascades
[i
], recurse
);
601 wfree(menu
->entries
);
605 FREE_PIXMAP(menu
->menu_texture_data
);
608 wfree(menu
->cascades
);
610 wCoreDestroy(menu
->menu
);
611 wFrameWindowDestroy(menu
->frame
);
613 /* destroy copy of this menu */
614 if (!menu
->flags
.brother
&& menu
->brother
)
615 wMenuDestroy(menu
->brother
, False
);
625 static void drawFrame(WScreen
* scr
, Drawable win
, int y
, int w
, int h
, int type
)
631 segs
[i
].x1
= segs
[i
].x2
= w
- 1;
633 segs
[i
].y2
= y
+ h
- 1;
635 if (type
!= F_TOP
&& type
!= F_NONE
) {
637 segs
[i
].y1
= segs
[i
].y2
= y
+ h
- 2;
641 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
647 segs
[i
].y2
= y
+ h
- 1;
649 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
656 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
658 if (type
!= F_TOP
&& type
!= F_NONE
)
659 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+ h
- 1, w
- 1, y
+ h
- 1);
662 static void paintEntry(WMenu
* menu
, int index
, int selected
)
664 WScreen
*scr
= menu
->frame
->screen_ptr
;
665 Window win
= menu
->menu
->window
;
666 WMenuEntry
*entry
= menu
->entries
[index
];
672 if (!menu
->flags
.realized
)
674 h
= menu
->entry_height
;
675 w
= menu
->menu
->width
;
678 light
= scr
->menu_item_auxtexture
->light_gc
;
679 dim
= scr
->menu_item_auxtexture
->dim_gc
;
680 dark
= scr
->menu_item_auxtexture
->dark_gc
;
682 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
685 else if (index
== menu
->entry_no
- 1)
693 /* paint background */
695 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+ 1, w
- 2, h
- 3);
696 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
697 drawFrame(scr
, win
, y
, w
, h
, type
);
699 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
700 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
702 drawFrame(scr
, win
, y
, w
, h
, type
);
704 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
709 if (entry
->flags
.enabled
)
710 color
= scr
->select_text_color
;
712 color
= scr
->dtext_color
;
713 } else if (!entry
->flags
.enabled
) {
714 color
= scr
->dtext_color
;
716 color
= scr
->mtext_color
;
720 if (entry
->flags
.indicator
)
721 x
+= MENU_INDICATOR_SPACE
+ 2;
723 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
724 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
726 if (entry
->cascade
>= 0) {
727 /* draw the cascade indicator */
728 XDrawLine(dpy
, win
, dim
, w
- 11, y
+ 6, w
- 6, y
+ h
/ 2 - 1);
729 XDrawLine(dpy
, win
, light
, w
- 11, y
+ h
- 8, w
- 6, y
+ h
/ 2 - 1);
730 XDrawLine(dpy
, win
, dark
, w
- 12, y
+ 6, w
- 12, y
+ h
- 8);
734 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
738 switch (entry
->flags
.indicator_type
) {
740 indicator
= scr
->menu_check_indicator
;
743 indicator
= scr
->menu_mini_indicator
;
746 indicator
= scr
->menu_hide_indicator
;
749 indicator
= scr
->menu_shade_indicator
;
753 indicator
= scr
->menu_radio_indicator
;
757 iw
= indicator
->width
;
758 ih
= indicator
->height
;
759 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
760 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2);
762 if (entry
->flags
.enabled
) {
763 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
765 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
768 if (entry
->flags
.enabled
) {
769 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
771 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
774 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2, iw
, ih
);
776 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
777 iw, ih, 5, y+(h-ih)/2);
779 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
782 /* draw right text */
784 if (entry
->rtext
&& entry
->cascade
< 0) {
785 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
, strlen(entry
->rtext
));
787 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
- 6 - tw
,
788 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
792 static void move_menus(WMenu
* menu
, int x
, int y
)
794 while (menu
->parent
) {
797 if (!wPreferences
.align_menus
&& menu
->selected_entry
>= 0) {
798 y
-= menu
->selected_entry
* menu
->entry_height
;
801 wMenuMove(menu
, x
, y
, True
);
804 static void makeVisible(WMenu
* menu
)
806 WScreen
*scr
= menu
->frame
->screen_ptr
;
807 int x1
, y1
, x2
, y2
, new_x
, new_y
;
808 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
810 if (menu
->entry_no
< 0)
814 y1
= menu
->frame_y
+ menu
->frame
->top_width
+ menu
->selected_entry
* menu
->entry_height
;
815 x2
= x1
+ MENUW(menu
);
816 y2
= y1
+ menu
->entry_height
;
821 if (x1
< rect
.pos
.x
) {
823 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
824 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
827 if (y1
< rect
.pos
.y
) {
829 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
830 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
833 new_y
= new_y
- menu
->frame
->top_width
- menu
->selected_entry
* menu
->entry_height
;
834 move_menus(menu
, new_x
, new_y
);
837 static int check_key(WMenu
* menu
, XKeyEvent
* event
)
842 if (XLookupString(event
, buffer
, 32, NULL
, NULL
) < 1)
845 ch
= toupper(buffer
[0]);
847 s
= (menu
->selected_entry
>= 0 ? menu
->selected_entry
+ 1 : 0);
850 for (i
= s
; i
< menu
->entry_no
; i
++) {
851 if (ch
== toupper(menu
->entries
[i
]->text
[0])) {
855 /* no match. Retry from start, if previous started from a selected entry */
863 static int keyboardMenu(WMenu
* menu
)
866 KeySym ksym
= NoSymbol
;
870 int old_pos_x
= menu
->frame_x
;
871 int old_pos_y
= menu
->frame_y
;
872 int new_x
= old_pos_x
, new_y
= old_pos_y
;
873 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
874 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
876 if (menu
->flags
.editing
)
879 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
881 if (menu
->frame_y
+ menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
882 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
884 if (menu
->frame_x
+ MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
885 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
887 move_menus(menu
, new_x
, new_y
);
889 while (!done
&& menu
->flags
.mapped
) {
890 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
891 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonPressMask
892 | ButtonReleaseMask
| KeyPressMask
| KeyReleaseMask
| SubstructureNotifyMask
, &event
);
894 switch (event
.type
) {
896 ksym
= XLookupKeysym(&event
.xkey
, 0);
897 if (wPreferences
.vi_key_menus
) {
926 selectEntry(menu
, 0);
934 selectEntry(menu
, menu
->entry_no
- 1);
942 if (menu
->selected_entry
<= 0)
943 selectEntry(menu
, menu
->entry_no
- 1);
945 selectEntry(menu
, menu
->selected_entry
- 1);
953 if (menu
->selected_entry
< 0)
954 selectEntry(menu
, 0);
955 else if (menu
->selected_entry
== menu
->entry_no
- 1)
956 selectEntry(menu
, 0);
957 else if (menu
->selected_entry
< menu
->entry_no
- 1)
958 selectEntry(menu
, menu
->selected_entry
+ 1);
966 if (menu
->selected_entry
>= 0) {
968 entry
= menu
->entries
[menu
->selected_entry
];
970 if (entry
->cascade
>= 0 && menu
->cascades
971 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
973 XUngrabKeyboard(dpy
, CurrentTime
);
975 selectEntry(menu
->cascades
[entry
->cascade
], 0);
976 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
979 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
980 GrabModeAsync
, GrabModeAsync
, CurrentTime
);
989 if (menu
->parent
!= NULL
&& menu
->parent
->selected_entry
>= 0) {
990 selectEntry(menu
, -1);
991 move_menus(menu
, old_pos_x
, old_pos_y
);
1004 index
= check_key(menu
, &event
.xkey
);
1006 selectEntry(menu
, index
);
1012 if (event
.type
== ButtonPress
)
1015 WMHandleEvent(&event
);
1019 XUngrabKeyboard(dpy
, CurrentTime
);
1021 if (done
== 2 && menu
->selected_entry
>= 0) {
1022 entry
= menu
->entries
[menu
->selected_entry
];
1027 if (entry
&& entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1028 #if (MENU_BLINK_COUNT > 0)
1029 int sel
= menu
->selected_entry
;
1032 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1033 paintEntry(menu
, sel
, False
);
1035 wusleep(MENU_BLINK_DELAY
);
1036 paintEntry(menu
, sel
, True
);
1038 wusleep(MENU_BLINK_DELAY
);
1041 selectEntry(menu
, -1);
1043 if (!menu
->flags
.buttoned
) {
1045 move_menus(menu
, old_pos_x
, old_pos_y
);
1049 (*entry
->callback
) (menu
, entry
);
1051 if (!menu
->flags
.buttoned
) {
1053 move_menus(menu
, old_pos_x
, old_pos_y
);
1055 selectEntry(menu
, -1);
1058 /* returns True if returning from a submenu to a parent menu,
1059 * False if exiting from menu */
1063 void wMenuMapAt(WMenu
* menu
, int x
, int y
, int keyboard
)
1065 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1066 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1068 if (!menu
->flags
.realized
) {
1069 menu
->flags
.realized
= 1;
1072 if (!menu
->flags
.mapped
) {
1073 if (wPreferences
.wrap_menus
) {
1078 if (x
+ MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1079 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1080 if (y
+ MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1081 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1084 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1087 XMapWindow(dpy
, menu
->frame
->core
->window
);
1088 wRaiseFrame(menu
->frame
->core
);
1089 menu
->flags
.mapped
= 1;
1091 selectEntry(menu
, 0);
1098 void wMenuMap(WMenu
* menu
)
1100 if (!menu
->flags
.realized
) {
1101 menu
->flags
.realized
= 1;
1104 if (menu
->flags
.app_menu
&& menu
->parent
== NULL
) {
1105 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1106 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1107 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1109 XMapWindow(dpy
, menu
->frame
->core
->window
);
1110 wRaiseFrame(menu
->frame
->core
);
1111 menu
->flags
.mapped
= 1;
1114 void wMenuUnmap(WMenu
* menu
)
1118 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1119 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1120 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1122 menu
->flags
.buttoned
= 0;
1123 menu
->flags
.mapped
= 0;
1124 menu
->flags
.open_to_left
= 0;
1126 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1127 if (menu
->cascades
[i
] != NULL
1128 && menu
->cascades
[i
]->flags
.mapped
&& !menu
->cascades
[i
]->flags
.buttoned
) {
1130 wMenuUnmap(menu
->cascades
[i
]);
1133 menu
->selected_entry
= -1;
1136 void wMenuPaint(WMenu
* menu
)
1140 if (!menu
->flags
.mapped
) {
1145 for (i
= 0; i
< menu
->entry_no
; i
++) {
1146 paintEntry(menu
, i
, i
== menu
->selected_entry
);
1150 void wMenuSetEnabled(WMenu
* menu
, int index
, int enable
)
1152 if (index
>= menu
->entry_no
)
1154 menu
->entries
[index
]->flags
.enabled
= enable
;
1155 paintEntry(menu
, index
, index
== menu
->selected_entry
);
1156 paintEntry(menu
->brother
, index
, index
== menu
->selected_entry
);
1160 static void selectEntry(WMenu
* menu
, int entry_no
)
1166 if (menu
->entries
== NULL
)
1169 if (entry_no
>= menu
->entry_no
)
1172 old_entry
= menu
->selected_entry
;
1173 menu
->selected_entry
= entry_no
;
1175 if (old_entry
!= entry_no
) {
1177 /* unselect previous entry */
1178 if (old_entry
>= 0) {
1179 paintEntry(menu
, old_entry
, False
);
1180 entry
= menu
->entries
[old_entry
];
1183 if (entry
->cascade
>= 0 && menu
->cascades
) {
1184 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1185 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1191 menu
->selected_entry
= -1;
1194 entry
= menu
->entries
[entry_no
];
1196 if (entry
->cascade
>= 0 && menu
->cascades
&& entry
->flags
.enabled
) {
1197 /* Callback for when the submenu is opened.
1199 submenu
= menu
->cascades
[entry
->cascade
];
1200 if (submenu
&& submenu
->flags
.brother
)
1201 submenu
= submenu
->brother
;
1203 if (entry
->callback
) {
1204 /* Only call the callback if the submenu is not yet mapped.
1206 if (menu
->flags
.brother
) {
1207 if (!submenu
|| !submenu
->flags
.mapped
)
1208 (*entry
->callback
) (menu
->brother
, entry
);
1210 if (!submenu
|| !submenu
->flags
.buttoned
)
1211 (*entry
->callback
) (menu
, entry
);
1215 /* the submenu menu might have changed */
1216 submenu
= menu
->cascades
[entry
->cascade
];
1219 if (!submenu
->flags
.mapped
) {
1222 if (!submenu
->flags
.realized
)
1223 wMenuRealize(submenu
);
1224 if (wPreferences
.wrap_menus
) {
1225 if (menu
->flags
.open_to_left
)
1226 submenu
->flags
.open_to_left
= 1;
1228 if (submenu
->flags
.open_to_left
) {
1229 x
= menu
->frame_x
- MENUW(submenu
);
1232 submenu
->flags
.open_to_left
= 0;
1235 x
= menu
->frame_x
+ MENUW(menu
);
1237 if (x
+ MENUW(submenu
)
1238 >= menu
->frame
->screen_ptr
->scr_width
) {
1240 x
= menu
->frame_x
- MENUW(submenu
);
1241 submenu
->flags
.open_to_left
= 1;
1245 x
= menu
->frame_x
+ MENUW(menu
);
1248 if (wPreferences
.align_menus
) {
1251 y
= menu
->frame_y
+ menu
->entry_height
* entry_no
;
1252 if (menu
->flags
.titled
)
1253 y
+= menu
->frame
->top_width
;
1254 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1255 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1258 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1259 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1264 paintEntry(menu
, entry_no
, True
);
1268 static WMenu
*findMenu(WScreen
* scr
, int *x_ret
, int *y_ret
)
1271 WObjDescriptor
*desc
;
1272 Window root_ret
, win
, junk_win
;
1276 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
, &mask
);
1281 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1284 if (desc
->parent_type
== WCLASS_MENU
) {
1285 menu
= (WMenu
*) desc
->parent
;
1286 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
, x_ret
, y_ret
, &junk_win
);
1292 static void closeCascade(WMenu
* menu
)
1294 WMenu
*parent
= menu
->parent
;
1296 if (menu
->flags
.brother
|| (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
))) {
1298 selectEntry(menu
, -1);
1300 #if (MENU_BLINK_DELAY > 2)
1301 wusleep(MENU_BLINK_DELAY
/ 2);
1304 while (parent
!= NULL
1305 && (parent
->parent
!= NULL
|| !parent
->flags
.app_menu
|| parent
->flags
.brother
)
1306 && !parent
->flags
.buttoned
) {
1307 selectEntry(parent
, -1);
1309 parent
= parent
->parent
;
1312 selectEntry(parent
, -1);
1316 static void closeBrotherCascadesOf(WMenu
* menu
)
1321 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1322 if (menu
->cascades
[i
]->flags
.brother
) {
1323 tmp
= menu
->cascades
[i
];
1325 tmp
= menu
->cascades
[i
]->brother
;
1327 if (tmp
->flags
.mapped
) {
1328 selectEntry(tmp
->parent
, -1);
1329 closeBrotherCascadesOf(tmp
);
1335 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1337 static WMenu
*parentMenu(WMenu
* menu
)
1342 if (menu
->flags
.buttoned
)
1345 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1346 parent
= menu
->parent
;
1347 if (parent
->selected_entry
< 0)
1349 entry
= parent
->entries
[parent
->selected_entry
];
1350 if (!entry
->flags
.enabled
|| entry
->cascade
< 0 || !parent
->cascades
||
1351 parent
->cascades
[entry
->cascade
] != menu
)
1354 if (menu
->flags
.buttoned
)
1362 * Will raise the passed menu, if submenu = 0
1363 * If submenu > 0 will also raise all mapped submenus
1364 * until the first buttoned one
1365 * If submenu < 0 will also raise all mapped parent menus
1366 * until the first buttoned one
1369 static void raiseMenus(WMenu
* menu
, int submenus
)
1377 wRaiseFrame(menu
->frame
->core
);
1379 if (submenus
> 0 && menu
->selected_entry
>= 0) {
1380 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1381 if (i
>= 0 && menu
->cascades
) {
1382 submenu
= menu
->cascades
[i
];
1383 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1384 raiseMenus(submenu
, submenus
);
1387 if (submenus
< 0 && !menu
->flags
.buttoned
&& menu
->parent
&& menu
->parent
->flags
.mapped
)
1388 raiseMenus(menu
->parent
, submenus
);
1391 WMenu
*wMenuUnderPointer(WScreen
* screen
)
1393 WObjDescriptor
*desc
;
1394 Window root_ret
, win
;
1398 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
, &dummy
, &dummy
, &mask
);
1403 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1406 if (desc
->parent_type
== WCLASS_MENU
)
1407 return (WMenu
*) desc
->parent
;
1411 static void getPointerPosition(WScreen
* scr
, int *x
, int *y
)
1413 Window root_ret
, win
;
1417 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1420 static void getScrollAmount(WMenu
* menu
, int *hamount
, int *vamount
)
1422 WScreen
*scr
= menu
->menu
->screen_ptr
;
1423 int menuX1
= menu
->frame_x
;
1424 int menuY1
= menu
->frame_y
;
1425 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1426 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1428 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1433 getPointerPosition(scr
, &xroot
, &yroot
);
1435 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1436 /* scroll to the right */
1437 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1439 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) && menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1440 /* scroll to the left */
1441 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
- rect
.pos
.x
- rect
.size
.width
- 1));
1446 *hamount
= -*hamount
;
1449 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1451 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1453 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) && menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1455 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
- rect
.pos
.y
- rect
.size
.height
- 2));
1457 *vamount
= -*vamount
;
1461 static void dragScrollMenuCallback(void *data
)
1463 WMenu
*menu
= (WMenu
*) data
;
1464 WScreen
*scr
= menu
->menu
->screen_ptr
;
1465 WMenu
*parent
= parentMenu(menu
);
1466 int hamount
, vamount
;
1468 int newSelectedEntry
;
1470 getScrollAmount(menu
, &hamount
, &vamount
);
1472 if (hamount
!= 0 || vamount
!= 0) {
1473 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1474 if (findMenu(scr
, &x
, &y
)) {
1475 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1476 selectEntry(menu
, newSelectedEntry
);
1478 /* Pointer fell outside of menu. If the selected entry is
1479 * not a submenu, unselect it */
1480 if (menu
->selected_entry
>= 0 && menu
->entries
[menu
->selected_entry
]->cascade
< 0)
1481 selectEntry(menu
, -1);
1482 newSelectedEntry
= 0;
1485 /* paranoid check */
1486 if (newSelectedEntry
>= 0) {
1487 /* keep scrolling */
1488 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, dragScrollMenuCallback
, menu
);
1493 /* don't need to scroll anymore */
1495 if (findMenu(scr
, &x
, &y
)) {
1496 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1497 selectEntry(menu
, newSelectedEntry
);
1502 static void scrollMenuCallback(void *data
)
1504 WMenu
*menu
= (WMenu
*) data
;
1505 WMenu
*parent
= parentMenu(menu
);
1506 int hamount
= 0; /* amount to scroll */
1509 getScrollAmount(menu
, &hamount
, &vamount
);
1511 if (hamount
!= 0 || vamount
!= 0) {
1512 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1514 /* keep scrolling */
1515 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, scrollMenuCallback
, menu
);
1517 /* don't need to scroll anymore */
1522 #define MENU_SCROLL_BORDER 5
1524 static int isPointNearBoder(WMenu
* menu
, int x
, int y
)
1526 int menuX1
= menu
->frame_x
;
1527 int menuY1
= menu
->frame_y
;
1528 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1529 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1531 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1532 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1534 /* XXX: handle screen joins properly !! */
1536 if (x
>= menuX1
&& x
<= menuX2
&&
1537 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
|| y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1539 else if (y
>= menuY1
&& y
<= menuY2
&&
1540 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
|| x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1546 typedef struct _delay
{
1551 static void leaving(_delay
* dl
)
1553 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1554 dl
->menu
->jump_back
= NULL
;
1555 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1559 void wMenuScroll(WMenu
* menu
, XEvent
* event
)
1562 WMenu
*omenu
= parentMenu(menu
);
1563 WScreen
*scr
= menu
->frame
->screen_ptr
;
1566 int old_frame_x
= omenu
->frame_x
;
1567 int old_frame_y
= omenu
->frame_y
;
1570 if (omenu
->jump_back
)
1571 WMDeleteTimerWithClientData(omenu
->jump_back
);
1573 if (( /*omenu->flags.buttoned && */ !wPreferences
.wrap_menus
)
1574 || omenu
->flags
.app_menu
) {
1578 if (!wPreferences
.wrap_menus
)
1579 raiseMenus(omenu
, True
);
1581 raiseMenus(menu
, False
);
1584 scrollMenuCallback(menu
);
1587 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1590 WMNextEvent(dpy
, &ev
);
1595 x
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1596 y
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1598 /* on_border is != 0 if the pointer is between the menu
1599 * and the screen border and is close enough to the border */
1600 on_border
= isPointNearBoder(menu
, x
, y
);
1602 smenu
= wMenuUnderPointer(scr
);
1604 if ((smenu
== NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
) != omenu
)) {
1609 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1610 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1611 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1612 on_border
= on_x_edge
|| on_y_edge
;
1614 if (!on_border
&& !jump_back
) {
1619 if (menu
->timer
&& (smenu
!= menu
|| (!on_y_edge
&& !on_x_edge
))) {
1620 WMDeleteTimerHandler(menu
->timer
);
1628 scrollMenuCallback(menu
);
1631 /* True if we push on title, or drag the omenu to other position */
1632 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1633 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1634 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1635 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1637 smenu
= wMenuUnderPointer(scr
);
1638 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1640 else if (smenu
== omenu
&& on_title
) {
1654 WMDeleteTimerHandler(menu
->timer
);
1660 if (!omenu
->jump_back
) {
1661 delayer
= wmalloc(sizeof(_delay
));
1662 delayer
->menu
= omenu
;
1663 delayer
->ox
= old_frame_x
;
1664 delayer
->oy
= old_frame_y
;
1665 omenu
->jump_back
= delayer
;
1666 scr
->flags
.jump_back_pending
= 1;
1668 delayer
= omenu
->jump_back
;
1669 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
, (WMCallback
*) leaving
, delayer
);
1673 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
)
1675 wMenuPaint(desc
->parent
);
1679 int *delayed_select
;
1684 static void delaySelection(void *data
)
1686 delay_data
*d
= (delay_data
*) data
;
1692 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1693 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1694 entry_no
= getEntryAt(menu
, x
, y
);
1695 selectEntry(menu
, entry_no
);
1697 if (d
->delayed_select
)
1698 *(d
->delayed_select
) = 0;
1701 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
1704 XButtonEvent
*bev
= &event
->xbutton
;
1705 WMenu
*menu
= desc
->parent
;
1707 WScreen
*scr
= menu
->frame
->screen_ptr
;
1708 WMenuEntry
*entry
= NULL
;
1710 int close_on_exit
= 0;
1712 int delayed_select
= 0;
1716 int old_frame_x
= 0;
1717 int old_frame_y
= 0;
1718 delay_data d_data
= { NULL
, NULL
, NULL
};
1720 /* Doesn't seem to be needed anymore (if delayed selection handler is
1721 * added only if not present). there seem to be no other side effects
1722 * from removing this and it is also possible that it was only added
1723 * to avoid problems with adding the delayed selection timer handler
1726 /*if (menu->flags.inside_handler) {
1729 menu
->flags
.inside_handler
= 1;
1731 if (!wPreferences
.wrap_menus
) {
1732 smenu
= parentMenu(menu
);
1733 old_frame_x
= smenu
->frame_x
;
1734 old_frame_y
= smenu
->frame_y
;
1735 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1736 /* This is true if the menu was launched with right click on root window */
1737 if (!d_data
.magic
) {
1739 d_data
.delayed_select
= &delayed_select
;
1741 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
, delaySelection
, &d_data
);
1745 wRaiseFrame(menu
->frame
->core
);
1747 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1749 smenu
= findMenu(scr
, &x
, &y
);
1757 if (menu
->flags
.editing
) {
1760 entry_no
= getEntryAt(menu
, x
, y
);
1761 if (entry_no
>= 0) {
1762 entry
= menu
->entries
[entry_no
];
1764 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
&& entry
->flags
.editable
) {
1767 int number
= entry_no
- 2; /* Entries "New" and "Destroy Last" appear before workspaces */
1769 name
= wstrdup(scr
->workspaces
[number
]->name
);
1770 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), number
+ 1);
1772 wMenuUnmap(scr
->root_menu
);
1774 if (wInputDialog(scr
, _("Rename Workspace"), buffer
, &name
))
1775 wWorkspaceRename(scr
, number
, name
);
1781 } else if (bev
->state
& ControlMask
) {
1785 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1786 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1788 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&& menu
->selected_entry
!= entry_no
) {
1789 wMenuUnmap(submenu
);
1791 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1792 selectEntry(menu
, entry_no
);
1793 } else if (!submenu
->flags
.buttoned
) {
1794 selectEntry(menu
, -1);
1797 } else if (!delayed_select
) {
1798 if (menu
== scr
->switch_menu
&& event
->xbutton
.button
== Button3
) {
1799 selectEntry(menu
, entry_no
);
1800 OpenWindowMenu2((WWindow
*)entry
->clientdata
,
1801 event
->xbutton
.x_root
,
1802 event
->xbutton
.y_root
, False
);
1803 wwin
= (WWindow
*)entry
->clientdata
;
1804 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
1805 event
->xany
.send_event
= True
;
1806 (*desc
->handle_mousedown
)(desc
, event
);
1808 XUngrabPointer(dpy
, CurrentTime
);
1809 selectEntry(menu
, -1);
1812 selectEntry(menu
, entry_no
);
1816 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
1818 dragScrollMenuCallback(menu
);
1822 prevx
= bev
->x_root
;
1823 prevy
= bev
->y_root
;
1827 XAllowEvents(dpy
, AsyncPointer
| SyncPointer
, CurrentTime
);
1829 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
1832 smenu
= findMenu(scr
, &x
, &y
);
1834 if (smenu
== NULL
) {
1835 /* moved mouse out of menu */
1837 if (!delayed_select
&& d_data
.magic
) {
1838 WMDeleteTimerHandler(d_data
.magic
);
1839 d_data
.magic
= NULL
;
1842 || (menu
->selected_entry
>= 0
1843 && menu
->entries
[menu
->selected_entry
]->cascade
>= 0)) {
1844 prevx
= ev
.xmotion
.x_root
;
1845 prevy
= ev
.xmotion
.y_root
;
1849 selectEntry(menu
, -1);
1851 prevx
= ev
.xmotion
.x_root
;
1852 prevy
= ev
.xmotion
.y_root
;
1854 } else if (menu
&& menu
!= smenu
1855 && (menu
->selected_entry
< 0
1856 || menu
->entries
[menu
->selected_entry
]->cascade
< 0)) {
1857 selectEntry(menu
, -1);
1859 if (!delayed_select
&& d_data
.magic
) {
1860 WMDeleteTimerHandler(d_data
.magic
);
1861 d_data
.magic
= NULL
;
1865 /* hysteresis for item selection */
1867 /* check if the motion was to the side, indicating that
1868 * the user may want to cross to a submenu */
1869 if (!delayed_select
&& menu
) {
1871 Bool moved_to_submenu
; /* moved to direction of submenu */
1873 dx
= abs(prevx
- ev
.xmotion
.x_root
);
1875 moved_to_submenu
= False
;
1876 if (dx
> 0 /* if moved enough to the side */
1877 /* maybe a open submenu */
1878 && menu
->selected_entry
>= 0
1879 /* moving to the right direction */
1880 && (wPreferences
.align_menus
|| ev
.xmotion
.y_root
>= prevy
)) {
1883 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
1885 if (menu
->cascades
[index
]->frame_x
> menu
->frame_x
) {
1886 if (prevx
< ev
.xmotion
.x_root
)
1887 moved_to_submenu
= True
;
1889 if (prevx
> ev
.xmotion
.x_root
)
1890 moved_to_submenu
= True
;
1895 if (menu
!= smenu
) {
1897 WMDeleteTimerHandler(d_data
.magic
);
1898 d_data
.magic
= NULL
;
1900 } else if (moved_to_submenu
) {
1901 /* while we are moving, postpone the selection */
1903 WMDeleteTimerHandler(d_data
.magic
);
1905 d_data
.delayed_select
= NULL
;
1907 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
1908 delaySelection
, &d_data
);
1909 prevx
= ev
.xmotion
.x_root
;
1910 prevy
= ev
.xmotion
.y_root
;
1914 WMDeleteTimerHandler(d_data
.magic
);
1915 d_data
.magic
= NULL
;
1920 prevx
= ev
.xmotion
.x_root
;
1921 prevy
= ev
.xmotion
.y_root
;
1922 if (menu
!= smenu
) {
1923 /* pointer crossed menus */
1924 if (menu
&& menu
->timer
) {
1925 WMDeleteTimerHandler(menu
->timer
);
1929 dragScrollMenuCallback(smenu
);
1933 dragScrollMenuCallback(menu
);
1935 if (!delayed_select
) {
1936 entry_no
= getEntryAt(menu
, x
, y
);
1937 if (entry_no
>= 0) {
1938 entry
= menu
->entries
[entry_no
];
1939 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1940 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1941 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
1942 && menu
->selected_entry
!= entry_no
) {
1943 wMenuUnmap(submenu
);
1947 selectEntry(menu
, entry_no
);
1955 if (ev
.xbutton
.button
== event
->xbutton
.button
)
1965 if (menu
&& menu
->timer
) {
1966 WMDeleteTimerHandler(menu
->timer
);
1969 if (d_data
.magic
!= NULL
) {
1970 WMDeleteTimerHandler(d_data
.magic
);
1971 d_data
.magic
= NULL
;
1974 if (menu
&& menu
->selected_entry
>= 0) {
1975 entry
= menu
->entries
[menu
->selected_entry
];
1976 if (entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1977 /* blink and erase menu selection */
1978 #if (MENU_BLINK_DELAY > 0)
1979 int sel
= menu
->selected_entry
;
1982 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1983 paintEntry(menu
, sel
, False
);
1985 wusleep(MENU_BLINK_DELAY
);
1986 paintEntry(menu
, sel
, True
);
1988 wusleep(MENU_BLINK_DELAY
);
1991 /* unmap the menu, it's parents and call the callback */
1992 if (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
1995 selectEntry(menu
, -1);
1997 (*entry
->callback
) (menu
, entry
);
1999 /* If the user double clicks an entry, the entry will
2000 * be executed twice, which is not good for things like
2001 * the root menu. So, ignore any clicks that were generated
2002 * while the entry was being executed */
2003 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
, ButtonPress
, &ev
)) ;
2004 } else if (entry
->callback
!= NULL
&& entry
->cascade
< 0) {
2005 selectEntry(menu
, -1);
2007 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2008 selectEntry(menu
, -1);
2013 if (((WMenu
*) desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2014 closeCascade(desc
->parent
);
2016 /* close the cascade windows that should not remain opened */
2017 closeBrotherCascadesOf(desc
->parent
);
2019 if (!wPreferences
.wrap_menus
)
2020 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2023 /* Just to be sure in case we skip the 2 above because of a goto byebye */
2024 if (menu
&& menu
->timer
) {
2025 WMDeleteTimerHandler(menu
->timer
);
2028 if (d_data
.magic
!= NULL
) {
2029 WMDeleteTimerHandler(d_data
.magic
);
2030 d_data
.magic
= NULL
;
2033 ((WMenu
*) desc
->parent
)->flags
.inside_handler
= 0;
2036 void wMenuMove(WMenu
* menu
, int x
, int y
, int submenus
)
2046 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2048 if (submenus
> 0 && menu
->selected_entry
>= 0) {
2049 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2051 if (i
>= 0 && menu
->cascades
) {
2052 submenu
= menu
->cascades
[i
];
2053 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2054 if (wPreferences
.align_menus
) {
2055 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2057 wMenuMove(submenu
, x
+ MENUW(menu
),
2058 y
+ submenu
->entry_height
* menu
->selected_entry
, submenus
);
2063 if (submenus
< 0 && menu
->parent
!= NULL
&& menu
->parent
->flags
.mapped
&& !menu
->parent
->flags
.buttoned
) {
2064 if (wPreferences
.align_menus
) {
2065 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2067 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2068 - menu
->parent
->entry_height
* menu
->parent
->selected_entry
, submenus
);
2073 static void changeMenuLevels(WMenu
* menu
, int lower
)
2078 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
: WMSubmenuLevel
));
2079 wRaiseFrame(menu
->frame
->core
);
2080 menu
->flags
.lowered
= 0;
2082 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2083 wLowerFrame(menu
->frame
->core
);
2084 menu
->flags
.lowered
= 1;
2086 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2087 if (menu
->cascades
[i
]
2088 && !menu
->cascades
[i
]->flags
.buttoned
&& menu
->cascades
[i
]->flags
.lowered
!= lower
) {
2089 changeMenuLevels(menu
->cascades
[i
], lower
);
2094 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2099 if (event
->xbutton
.state
& MOD_MASK
) {
2100 if (menu
->flags
.lowered
) {
2105 changeMenuLevels(menu
, lower
);
2109 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2114 int x
= menu
->frame_x
, y
= menu
->frame_y
;
2115 int dx
= event
->xbutton
.x_root
, dy
= event
->xbutton
.y_root
;
2119 /* can't touch the menu copy */
2120 if (menu
->flags
.brother
)
2123 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2126 if (event
->xbutton
.state
& MOD_MASK
) {
2127 wLowerFrame(menu
->frame
->core
);
2130 wRaiseFrame(menu
->frame
->core
);
2135 /* lower/raise all submenus */
2137 if (tmp
->selected_entry
>= 0 && tmp
->cascades
&& tmp
->entries
[tmp
->selected_entry
]->cascade
>= 0) {
2138 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2139 if (!tmp
|| !tmp
->flags
.mapped
)
2142 wLowerFrame(tmp
->frame
->core
);
2144 wRaiseFrame(tmp
->frame
->core
);
2150 /* tear off the menu if it's a root menu or a cascade
2152 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
2153 menu
->flags
.buttoned
= 1;
2154 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2156 /* turn off selected menu entry in parent menu */
2157 selectEntry(menu
->parent
, -1);
2159 /* make parent map the copy in place of the original */
2160 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2161 if (menu
->parent
->cascades
[i
] == menu
) {
2162 menu
->parent
->cascades
[i
] = menu
->brother
;
2171 WMMaskEvent(dpy
, ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &ev
);
2175 x
+= ev
.xmotion
.x_root
- dx
;
2176 y
+= ev
.xmotion
.y_root
- dy
;
2177 dx
= ev
.xmotion
.x_root
;
2178 dy
= ev
.xmotion
.y_root
;
2179 wMenuMove(menu
, x
, y
, True
);
2181 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2182 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2184 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2185 ButtonMotionMask
| ButtonReleaseMask
2187 GrabModeAsync
, GrabModeAsync
, None
,
2188 wCursor
[WCUR_MOVE
], CurrentTime
);
2197 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2199 XUngrabPointer(dpy
, CurrentTime
);
2210 *----------------------------------------------------------------------
2212 * Handles mouse click on the close button of menus. The menu is
2213 * closed when the button is clicked.
2216 * The closed menu is reinserted at it's parent menus
2218 *----------------------------------------------------------------------
2220 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2222 WMenu
*menu
= (WMenu
*) data
;
2223 WMenu
*parent
= menu
->parent
;
2227 for (i
= 0; i
< parent
->cascade_no
; i
++) {
2228 /* find the entry that points to the copy */
2229 if (parent
->cascades
[i
] == menu
->brother
) {
2230 /* make it point to the original */
2231 parent
->cascades
[i
] = menu
;
2232 menu
->parent
= parent
;
2240 static void saveMenuInfo(WMPropList
* dict
, WMenu
* menu
, WMPropList
* key
)
2242 WMPropList
*value
, *list
;
2245 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2246 value
= WMCreatePLString(buffer
);
2247 list
= WMCreatePLArray(value
, NULL
);
2248 if (menu
->flags
.lowered
)
2249 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2250 WMPutInPLDictionary(dict
, key
, list
);
2251 WMReleasePropList(value
);
2252 WMReleasePropList(list
);
2255 void wMenuSaveState(WScreen
* scr
)
2257 WMPropList
*menus
, *key
;
2260 menus
= WMCreatePLDictionary(NULL
, NULL
);
2262 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2263 key
= WMCreatePLString("SwitchMenu");
2264 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2265 WMReleasePropList(key
);
2269 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2272 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2273 key
= WMCreatePLString("WorkspaceMenu");
2274 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2275 WMReleasePropList(key
);
2280 key
= WMCreatePLString("Menus");
2281 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2282 WMReleasePropList(key
);
2284 WMReleasePropList(menus
);
2287 static Bool
getMenuPath(WMenu
* menu
, char *buffer
, int bufSize
)
2292 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2295 len
= strlen(menu
->frame
->title
);
2300 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2305 strcat(buffer
, "\\");
2306 strcat(buffer
, menu
->frame
->title
);
2311 static Bool
saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
)
2314 int save_menus
= 0, i
;
2318 if (menu
->flags
.brother
)
2319 menu
= menu
->brother
;
2321 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2324 ok
= getMenuPath(menu
, buffer
, 510);
2327 key
= WMCreatePLString(buffer
);
2328 saveMenuInfo(menus
, menu
, key
);
2329 WMReleasePropList(key
);
2335 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2336 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2343 #define COMPLAIN(key) wwarning(_("bad value in menus state info: %s"), key)
2345 static Bool
getMenuInfo(WMPropList
* info
, int *x
, int *y
, Bool
* lowered
)
2351 if (WMIsPLArray(info
)) {
2353 pos
= WMGetFromPLArray(info
, 0);
2354 flags
= WMGetFromPLArray(info
, 1);
2355 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2356 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2363 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2364 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
) != 2)
2365 COMPLAIN("Position");
2367 COMPLAIN("(position, flags...)");
2374 static int restoreMenu(WScreen
* scr
, WMPropList
* menu
, int which
)
2377 Bool lowered
= False
;
2378 WMenu
*pmenu
= NULL
;
2383 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2386 if (which
& WSS_SWITCHMENU
) {
2387 OpenSwitchMenu(scr
, x
, y
, False
);
2388 pmenu
= scr
->switch_menu
;
2392 int width
= MENUW(pmenu
);
2393 int height
= MENUH(pmenu
);
2394 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2397 changeMenuLevels(pmenu
, True
);
2400 if (x
< rect
.pos
.x
- width
)
2402 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2403 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2406 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2407 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2409 wMenuMove(pmenu
, x
, y
, True
);
2410 pmenu
->flags
.buttoned
= 1;
2411 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2417 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
)
2419 WMPropList
*key
, *entry
;
2424 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2427 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2428 key
= WMCreatePLString(buffer
);
2429 entry
= WMGetFromPLDictionary(menus
, key
);
2432 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2434 if (!menu
->flags
.mapped
) {
2435 int width
= MENUW(menu
);
2436 int height
= MENUH(menu
);
2437 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2439 wMenuMapAt(menu
, x
, y
, False
);
2442 /* make parent map the copy in place of the original */
2443 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2444 if (menu
->parent
->cascades
[i
] == menu
) {
2445 menu
->parent
->cascades
[i
] = menu
->brother
;
2451 changeMenuLevels(menu
, True
);
2454 if (x
< rect
.pos
.x
- width
)
2456 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2457 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2460 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2461 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2463 wMenuMove(menu
, x
, y
, True
);
2464 menu
->flags
.buttoned
= 1;
2465 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2470 WMReleasePropList(key
);
2472 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2473 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2480 void wMenuRestoreState(WScreen
* scr
)
2482 WMPropList
*menus
, *menu
, *key
, *skey
;
2484 if (!scr
->session_state
) {
2488 key
= WMCreatePLString("Menus");
2489 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2490 WMReleasePropList(key
);
2497 skey
= WMCreatePLString("SwitchMenu");
2498 menu
= WMGetFromPLDictionary(menus
, skey
);
2499 WMReleasePropList(skey
);
2500 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2502 if (!scr
->root_menu
) {
2503 OpenRootMenu(scr
, scr
->scr_width
* 2, 0, False
);
2504 wMenuUnmap(scr
->root_menu
);
2506 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");