1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
27 #include <X11/keysym.h>
35 #include "WindowMaker.h"
43 #include "workspace.h"
46 /****** Global Variables ******/
48 extern Cursor wCursor
[WCUR_LAST
];
50 extern XContext wWinContext
;
52 extern WPreferences wPreferences
;
54 #define MOD_MASK wPreferences.modifier_mask
56 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
57 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
59 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
60 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
62 /***** Local Stuff ******/
64 #define WSS_ROOTMENU (1<<0)
65 #define WSS_SWITCHMENU (1<<1)
66 #define WSS_WSMENU (1<<2)
71 } menuScrollParameters
[5] = {
73 MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
}, {
74 MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
}, {
75 MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
}, {
76 MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
}, {
77 MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
79 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
80 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
);
81 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
82 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
);
83 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
84 static void updateTexture(WMenu
* menu
);
85 static int saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
);
86 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
);
87 static void selectEntry(WMenu
* menu
, int entry_no
);
88 static void closeCascade(WMenu
* menu
);
90 /****** Notification Observers ******/
92 static void appearanceObserver(void *self
, WMNotification
* notif
)
94 WMenu
*menu
= (WMenu
*) self
;
95 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
97 if (!menu
->flags
.realized
)
100 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
101 if (flags
& WFontSettings
) {
102 menu
->flags
.realized
= 0;
105 if (flags
& WTextureSettings
) {
106 if (!menu
->flags
.brother
)
109 if (flags
& (WTextureSettings
| WColorSettings
)) {
112 } else if (menu
->flags
.titled
) {
114 if (flags
& WFontSettings
) {
115 menu
->flags
.realized
= 0;
118 if (flags
& WTextureSettings
) {
119 menu
->frame
->flags
.need_texture_remake
= 1;
121 if (flags
& (WColorSettings
| WTextureSettings
)) {
122 wFrameWindowPaint(menu
->frame
);
127 /************************************/
130 *----------------------------------------------------------------------
132 * Creates a new empty menu with the specified title. If main_menu
133 * is True, the created menu will be a main menu, which has some special
134 * properties such as being placed over other normal menus.
135 * If title is NULL, the menu will have no titlebar.
139 *----------------------------------------------------------------------
141 WMenu
*wMenuCreate(WScreen
* screen
, char *title
, int main_menu
)
144 static int brother
= 0;
147 menu
= wmalloc(sizeof(WMenu
));
149 memset(menu
, 0, sizeof(WMenu
));
151 #ifdef SINGLE_MENULEVEL
152 tmp
= WMSubmenuLevel
;
154 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
157 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
159 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
160 menu
->flags
.titled
= 1;
163 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
164 screen
->menu_title_texture
, NULL
,
165 screen
->menu_title_color
, &screen
->menu_title_font
);
167 menu
->frame
->core
->descriptor
.parent
= menu
;
168 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
169 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
171 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
174 menu
->frame
->title
= wstrdup(title
);
177 menu
->frame
->flags
.justification
= WTJ_LEFT
;
179 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
182 menu
->alloced_entries
= 0;
183 menu
->selected_entry
= -1;
184 menu
->entries
= NULL
;
186 menu
->frame_x
= screen
->app_menu_x
;
187 menu
->frame_y
= screen
->app_menu_y
;
189 menu
->frame
->child
= menu
;
191 menu
->flags
.lowered
= 0;
195 /* setup object descriptors */
196 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
197 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
200 menu
->frame
->on_click_right
= menuCloseClick
;
202 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
, menu
->frame
->core
->width
, 10);
204 menu
->menu
->descriptor
.parent
= menu
;
205 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
206 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
207 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
209 menu
->menu_texture_data
= None
;
211 XMapWindow(dpy
, menu
->menu
->window
);
217 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
219 menu
->brother
->flags
.brother
= 1;
220 menu
->brother
->brother
= menu
;
222 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuAppearanceSettingsChanged
, menu
);
224 WMAddNotificationObserver(appearanceObserver
, menu
, WNMenuTitleAppearanceSettingsChanged
, menu
);
229 WMenu
*wMenuCreateForApp(WScreen
* screen
, char *title
, int main_menu
)
233 menu
= wMenuCreate(screen
, title
, main_menu
);
236 menu
->flags
.app_menu
= 1;
237 menu
->brother
->flags
.app_menu
= 1;
242 static void insertEntry(WMenu
* menu
, WMenuEntry
* entry
, int index
)
246 for (i
= menu
->entry_no
- 1; i
>= index
; i
--) {
247 menu
->entries
[i
]->order
++;
248 menu
->entries
[i
+ 1] = menu
->entries
[i
];
250 menu
->entries
[index
] = entry
;
253 WMenuEntry
*wMenuInsertCallback(WMenu
* menu
, int index
, char *text
,
254 void (*callback
) (WMenu
* menu
, WMenuEntry
* entry
), void *clientdata
)
258 menu
->flags
.realized
= 0;
259 menu
->brother
->flags
.realized
= 0;
261 /* reallocate array if it's too small */
262 if (menu
->entry_no
>= menu
->alloced_entries
) {
265 tmp
= wrealloc(menu
->entries
, sizeof(WMenuEntry
) * (menu
->alloced_entries
+ 5));
268 menu
->alloced_entries
+= 5;
270 menu
->brother
->entries
= tmp
;
271 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
273 entry
= wmalloc(sizeof(WMenuEntry
));
274 memset(entry
, 0, sizeof(WMenuEntry
));
275 entry
->flags
.enabled
= 1;
276 entry
->text
= wstrdup(text
);
278 entry
->clientdata
= clientdata
;
279 entry
->callback
= callback
;
280 if (index
< 0 || index
>= menu
->entry_no
) {
281 entry
->order
= menu
->entry_no
;
282 menu
->entries
[menu
->entry_no
] = entry
;
284 entry
->order
= index
;
285 insertEntry(menu
, entry
, index
);
289 menu
->brother
->entry_no
= menu
->entry_no
;
294 void wMenuEntrySetCascade(WMenu
* menu
, WMenuEntry
* entry
, WMenu
* cascade
)
296 WMenu
*brother
= menu
->brother
;
299 assert(menu
->flags
.brother
== 0);
301 if (entry
->cascade
>= 0) {
302 menu
->flags
.realized
= 0;
303 brother
->flags
.realized
= 0;
306 cascade
->parent
= menu
;
308 cascade
->brother
->parent
= brother
;
311 for (i
= 0; i
< menu
->cascade_no
; i
++) {
312 if (menu
->cascades
[i
] == NULL
) {
313 menu
->cascades
[i
] = cascade
;
314 brother
->cascades
[i
] = cascade
->brother
;
321 entry
->cascade
= menu
->cascade_no
;
323 menu
->cascades
= wrealloc(menu
->cascades
, sizeof(WMenu
) * (menu
->cascade_no
+ 1));
324 menu
->cascades
[menu
->cascade_no
++] = cascade
;
326 brother
->cascades
= wrealloc(brother
->cascades
, sizeof(WMenu
) * (brother
->cascade_no
+ 1));
327 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
330 if (menu
->flags
.lowered
) {
332 cascade
->flags
.lowered
= 1;
333 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
335 cascade
->brother
->flags
.lowered
= 1;
336 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
339 if (!menu
->flags
.realized
)
343 void wMenuEntryRemoveCascade(WMenu
* menu
, WMenuEntry
* entry
)
345 assert(menu
->flags
.brother
== 0);
347 /* destroy cascade menu */
348 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
] != NULL
) {
350 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
352 menu
->cascades
[entry
->cascade
] = NULL
;
353 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
359 void wMenuRemoveItem(WMenu
* menu
, int index
)
363 if (menu
->flags
.brother
) {
364 wMenuRemoveItem(menu
->brother
, index
);
368 if (index
>= menu
->entry_no
)
371 /* destroy cascade menu */
372 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
374 /* destroy unshared data */
376 if (menu
->entries
[index
]->text
)
377 wfree(menu
->entries
[index
]->text
);
379 if (menu
->entries
[index
]->rtext
)
380 wfree(menu
->entries
[index
]->rtext
);
382 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
383 (*menu
->entries
[index
]->free_cdata
) (menu
->entries
[index
]->clientdata
);
385 wfree(menu
->entries
[index
]);
387 for (i
= index
; i
< menu
->entry_no
- 1; i
++) {
388 menu
->entries
[i
+ 1]->order
--;
389 menu
->entries
[i
] = menu
->entries
[i
+ 1];
392 menu
->brother
->entry_no
--;
395 static Pixmap
renderTexture(WMenu
* menu
)
403 WScreen
*scr
= menu
->menu
->screen_ptr
;
404 WTexture
*texture
= scr
->menu_item_texture
;
406 if (wPreferences
.menu_style
== MS_NORMAL
) {
407 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->entry_height
, WREL_MENUENTRY
);
409 img
= wTextureRenderImage(texture
, menu
->menu
->width
, menu
->menu
->height
+ 1, WREL_MENUENTRY
);
412 wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode
));
417 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
419 light
.red
= light
.green
= light
.blue
= 80;
422 dark
.red
= dark
.green
= dark
.blue
= 0;
425 mid
.red
= mid
.green
= mid
.blue
= 40;
427 for (i
= 1; i
< menu
->entry_no
; i
++) {
428 ROperateLine(img
, RSubtractOperation
, 0, i
* menu
->entry_height
- 2,
429 menu
->menu
->width
- 1, i
* menu
->entry_height
- 2, &mid
);
431 RDrawLine(img
, 0, i
* menu
->entry_height
- 1,
432 menu
->menu
->width
- 1, i
* menu
->entry_height
- 1, &dark
);
434 ROperateLine(img
, RAddOperation
, 0, i
* menu
->entry_height
,
435 menu
->menu
->width
- 1, i
* menu
->entry_height
, &light
);
438 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
439 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
446 static void updateTexture(WMenu
* menu
)
448 WScreen
*scr
= menu
->menu
->screen_ptr
;
450 /* setup background texture */
451 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
452 if (!menu
->flags
.brother
) {
453 FREE_PIXMAP(menu
->menu_texture_data
);
455 menu
->menu_texture_data
= renderTexture(menu
);
457 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
, menu
->menu_texture_data
);
458 XClearWindow(dpy
, menu
->menu
->window
);
460 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
, menu
->menu_texture_data
);
461 XClearWindow(dpy
, menu
->brother
->menu
->window
);
464 XSetWindowBackground(dpy
, menu
->menu
->window
, scr
->menu_item_texture
->any
.color
.pixel
);
465 XClearWindow(dpy
, menu
->menu
->window
);
469 void wMenuRealize(WMenu
* menu
)
472 int width
, rwidth
, mrwidth
, mwidth
;
473 int theight
, twidth
, eheight
;
474 WScreen
*scr
= menu
->frame
->screen_ptr
;
475 static int brother_done
= 0;
480 wMenuRealize(menu
->brother
);
484 flags
= WFF_SINGLE_STATE
| WFF_BORDER
;
485 if (menu
->flags
.titled
)
486 flags
|= WFF_TITLEBAR
| WFF_RIGHT_BUTTON
;
488 wFrameWindowUpdateBorders(menu
->frame
, flags
);
490 if (menu
->flags
.titled
) {
491 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
, strlen(menu
->frame
->title
));
492 theight
= menu
->frame
->top_width
;
493 twidth
+= theight
+ (wPreferences
.new_style
== TS_NEW
? 16 : 8);
498 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
499 menu
->entry_height
= eheight
;
502 for (i
= 0; i
< menu
->entry_no
; i
++) {
505 /* search widest text */
506 text
= menu
->entries
[i
]->text
;
507 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
)) + 10;
509 if (menu
->entries
[i
]->flags
.indicator
) {
510 width
+= MENU_INDICATOR_SPACE
;
516 /* search widest text on right */
517 text
= menu
->entries
[i
]->rtext
;
519 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
521 else if (menu
->entries
[i
]->cascade
>= 0)
526 if (rwidth
> mrwidth
)
534 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
* eheight
- 1);
536 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
* eheight
- 1
537 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
541 menu
->flags
.realized
= 1;
543 if (menu
->flags
.mapped
)
545 if (menu
->brother
->flags
.mapped
)
546 wMenuPaint(menu
->brother
);
549 void wMenuDestroy(WMenu
* menu
, int recurse
)
553 WMRemoveNotificationObserver(menu
);
555 /* remove any pending timers */
557 WMDeleteTimerHandler(menu
->timer
);
560 /* call destroy handler */
561 if (menu
->on_destroy
)
562 (*menu
->on_destroy
) (menu
);
564 /* Destroy items if this menu own them. If this is the "brother" menu,
565 * leave them alone as it is shared by them.
567 if (!menu
->flags
.brother
) {
568 for (i
= 0; i
< menu
->entry_no
; i
++) {
570 wfree(menu
->entries
[i
]->text
);
572 if (menu
->entries
[i
]->rtext
)
573 wfree(menu
->entries
[i
]->rtext
);
576 if (menu
->entries
[i
]->instances
) {
577 WMReleasePropList(menu
->entries
[i
]->instances
);
579 #endif /* USER_MENU */
581 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
582 (*menu
->entries
[i
]->free_cdata
) (menu
->entries
[i
]->clientdata
);
584 wfree(menu
->entries
[i
]);
588 for (i
= 0; i
< menu
->cascade_no
; i
++) {
589 if (menu
->cascades
[i
]) {
590 if (menu
->cascades
[i
]->flags
.brother
)
591 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
593 wMenuDestroy(menu
->cascades
[i
], recurse
);
599 wfree(menu
->entries
);
603 FREE_PIXMAP(menu
->menu_texture_data
);
606 wfree(menu
->cascades
);
608 wCoreDestroy(menu
->menu
);
609 wFrameWindowDestroy(menu
->frame
);
611 /* destroy copy of this menu */
612 if (!menu
->flags
.brother
&& menu
->brother
)
613 wMenuDestroy(menu
->brother
, False
);
623 static void drawFrame(WScreen
* scr
, Drawable win
, int y
, int w
, int h
, int type
)
629 segs
[i
].x1
= segs
[i
].x2
= w
- 1;
631 segs
[i
].y2
= y
+ h
- 1;
633 if (type
!= F_TOP
&& type
!= F_NONE
) {
635 segs
[i
].y1
= segs
[i
].y2
= y
+ h
- 2;
639 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
645 segs
[i
].y2
= y
+ h
- 1;
647 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
654 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
656 if (type
!= F_TOP
&& type
!= F_NONE
)
657 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+ h
- 1, w
- 1, y
+ h
- 1);
660 static void paintEntry(WMenu
* menu
, int index
, int selected
)
662 WScreen
*scr
= menu
->frame
->screen_ptr
;
663 Window win
= menu
->menu
->window
;
664 WMenuEntry
*entry
= menu
->entries
[index
];
670 if (!menu
->flags
.realized
)
672 h
= menu
->entry_height
;
673 w
= menu
->menu
->width
;
676 light
= scr
->menu_item_auxtexture
->light_gc
;
677 dim
= scr
->menu_item_auxtexture
->dim_gc
;
678 dark
= scr
->menu_item_auxtexture
->dark_gc
;
680 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
683 else if (index
== menu
->entry_no
- 1)
691 /* paint background */
693 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+ 1, w
- 2, h
- 3);
694 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
695 drawFrame(scr
, win
, y
, w
, h
, type
);
697 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
698 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
700 drawFrame(scr
, win
, y
, w
, h
, type
);
702 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
707 if (entry
->flags
.enabled
)
708 color
= scr
->select_text_color
;
710 color
= scr
->dtext_color
;
711 } else if (!entry
->flags
.enabled
) {
712 color
= scr
->dtext_color
;
714 color
= scr
->mtext_color
;
718 if (entry
->flags
.indicator
)
719 x
+= MENU_INDICATOR_SPACE
+ 2;
721 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
722 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
724 if (entry
->cascade
>= 0) {
725 /* draw the cascade indicator */
726 XDrawLine(dpy
, win
, dim
, w
- 11, y
+ 6, w
- 6, y
+ h
/ 2 - 1);
727 XDrawLine(dpy
, win
, light
, w
- 11, y
+ h
- 8, w
- 6, y
+ h
/ 2 - 1);
728 XDrawLine(dpy
, win
, dark
, w
- 12, y
+ 6, w
- 12, y
+ h
- 8);
732 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
736 switch (entry
->flags
.indicator_type
) {
738 indicator
= scr
->menu_check_indicator
;
741 indicator
= scr
->menu_mini_indicator
;
744 indicator
= scr
->menu_hide_indicator
;
747 indicator
= scr
->menu_shade_indicator
;
751 indicator
= scr
->menu_radio_indicator
;
755 iw
= indicator
->width
;
756 ih
= indicator
->height
;
757 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
758 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2);
760 if (entry
->flags
.enabled
) {
761 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
763 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
766 if (entry
->flags
.enabled
) {
767 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
769 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
772 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+ (h
- ih
) / 2, iw
, ih
);
774 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
775 iw, ih, 5, y+(h-ih)/2);
777 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
780 /* draw right text */
782 if (entry
->rtext
&& entry
->cascade
< 0) {
783 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
, strlen(entry
->rtext
));
785 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
- 6 - tw
,
786 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
790 static void move_menus(WMenu
* menu
, int x
, int y
)
792 while (menu
->parent
) {
795 if (!wPreferences
.align_menus
&& menu
->selected_entry
>= 0) {
796 y
-= menu
->selected_entry
* menu
->entry_height
;
799 wMenuMove(menu
, x
, y
, True
);
802 static void makeVisible(WMenu
* menu
)
804 WScreen
*scr
= menu
->frame
->screen_ptr
;
805 int x1
, y1
, x2
, y2
, new_x
, new_y
;
806 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
808 if (menu
->entry_no
< 0)
812 y1
= menu
->frame_y
+ menu
->frame
->top_width
+ menu
->selected_entry
* menu
->entry_height
;
813 x2
= x1
+ MENUW(menu
);
814 y2
= y1
+ menu
->entry_height
;
819 if (x1
< rect
.pos
.x
) {
821 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
822 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
825 if (y1
< rect
.pos
.y
) {
827 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
828 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
831 new_y
= new_y
- menu
->frame
->top_width
- menu
->selected_entry
* menu
->entry_height
;
832 move_menus(menu
, new_x
, new_y
);
835 static int check_key(WMenu
* menu
, XKeyEvent
* event
)
840 if (XLookupString(event
, buffer
, 32, NULL
, NULL
) < 1)
843 ch
= toupper(buffer
[0]);
845 s
= (menu
->selected_entry
>= 0 ? menu
->selected_entry
+ 1 : 0);
848 for (i
= s
; i
< menu
->entry_no
; i
++) {
849 if (ch
== toupper(menu
->entries
[i
]->text
[0])) {
853 /* no match. Retry from start, if previous started from a selected entry */
861 static int keyboardMenu(WMenu
* menu
)
864 KeySym ksym
= NoSymbol
;
868 int old_pos_x
= menu
->frame_x
;
869 int old_pos_y
= menu
->frame_y
;
870 int new_x
= old_pos_x
, new_y
= old_pos_y
;
871 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
872 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
874 if (menu
->flags
.editing
)
877 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
879 if (menu
->frame_y
+ menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
880 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
882 if (menu
->frame_x
+ MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
883 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
885 move_menus(menu
, new_x
, new_y
);
887 while (!done
&& menu
->flags
.mapped
) {
888 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
889 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonPressMask
890 | ButtonReleaseMask
| KeyPressMask
| KeyReleaseMask
| SubstructureNotifyMask
, &event
);
892 switch (event
.type
) {
894 ksym
= XLookupKeysym(&event
.xkey
, 0);
904 selectEntry(menu
, 0);
912 selectEntry(menu
, menu
->entry_no
- 1);
923 if (menu
->selected_entry
<= 0)
924 selectEntry(menu
, menu
->entry_no
- 1);
926 selectEntry(menu
, menu
->selected_entry
- 1);
937 if (menu
->selected_entry
< 0)
938 selectEntry(menu
, 0);
939 else if (menu
->selected_entry
== menu
->entry_no
- 1)
940 selectEntry(menu
, 0);
941 else if (menu
->selected_entry
< menu
->entry_no
- 1)
942 selectEntry(menu
, menu
->selected_entry
+ 1);
953 if (menu
->selected_entry
>= 0) {
955 entry
= menu
->entries
[menu
->selected_entry
];
957 if (entry
->cascade
>= 0 && menu
->cascades
958 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
960 XUngrabKeyboard(dpy
, CurrentTime
);
962 selectEntry(menu
->cascades
[entry
->cascade
], 0);
963 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
966 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
967 GrabModeAsync
, GrabModeAsync
, CurrentTime
);
979 if (menu
->parent
!= NULL
&& menu
->parent
->selected_entry
>= 0) {
980 selectEntry(menu
, -1);
981 move_menus(menu
, old_pos_x
, old_pos_y
);
994 index
= check_key(menu
, &event
.xkey
);
996 selectEntry(menu
, index
);
1002 if (event
.type
== ButtonPress
)
1005 WMHandleEvent(&event
);
1009 XUngrabKeyboard(dpy
, CurrentTime
);
1011 if (done
== 2 && menu
->selected_entry
>= 0) {
1012 entry
= menu
->entries
[menu
->selected_entry
];
1017 if (entry
&& entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1018 #if (MENU_BLINK_COUNT > 0)
1019 int sel
= menu
->selected_entry
;
1022 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1023 paintEntry(menu
, sel
, False
);
1025 wusleep(MENU_BLINK_DELAY
);
1026 paintEntry(menu
, sel
, True
);
1028 wusleep(MENU_BLINK_DELAY
);
1031 selectEntry(menu
, -1);
1033 if (!menu
->flags
.buttoned
) {
1035 move_menus(menu
, old_pos_x
, old_pos_y
);
1039 (*entry
->callback
) (menu
, entry
);
1041 if (!menu
->flags
.buttoned
) {
1043 move_menus(menu
, old_pos_x
, old_pos_y
);
1045 selectEntry(menu
, -1);
1048 /* returns True if returning from a submenu to a parent menu,
1049 * False if exiting from menu */
1053 void wMenuMapAt(WMenu
* menu
, int x
, int y
, int keyboard
)
1055 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1056 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1058 if (!menu
->flags
.realized
) {
1059 menu
->flags
.realized
= 1;
1062 if (!menu
->flags
.mapped
) {
1063 if (wPreferences
.wrap_menus
) {
1068 if (x
+ MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1069 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1070 if (y
+ MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1071 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1074 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1077 XMapWindow(dpy
, menu
->frame
->core
->window
);
1078 wRaiseFrame(menu
->frame
->core
);
1079 menu
->flags
.mapped
= 1;
1081 selectEntry(menu
, 0);
1088 void wMenuMap(WMenu
* menu
)
1090 if (!menu
->flags
.realized
) {
1091 menu
->flags
.realized
= 1;
1094 if (menu
->flags
.app_menu
&& menu
->parent
== NULL
) {
1095 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1096 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1097 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1099 XMapWindow(dpy
, menu
->frame
->core
->window
);
1100 wRaiseFrame(menu
->frame
->core
);
1101 menu
->flags
.mapped
= 1;
1104 void wMenuUnmap(WMenu
* menu
)
1108 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1109 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1110 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1112 menu
->flags
.buttoned
= 0;
1113 menu
->flags
.mapped
= 0;
1114 menu
->flags
.open_to_left
= 0;
1116 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1117 if (menu
->cascades
[i
] != NULL
1118 && menu
->cascades
[i
]->flags
.mapped
&& !menu
->cascades
[i
]->flags
.buttoned
) {
1120 wMenuUnmap(menu
->cascades
[i
]);
1123 menu
->selected_entry
= -1;
1126 void wMenuPaint(WMenu
* menu
)
1130 if (!menu
->flags
.mapped
) {
1135 for (i
= 0; i
< menu
->entry_no
; i
++) {
1136 paintEntry(menu
, i
, i
== menu
->selected_entry
);
1140 void wMenuSetEnabled(WMenu
* menu
, int index
, int enable
)
1142 if (index
>= menu
->entry_no
)
1144 menu
->entries
[index
]->flags
.enabled
= enable
;
1145 paintEntry(menu
, index
, index
== menu
->selected_entry
);
1146 paintEntry(menu
->brother
, index
, index
== menu
->selected_entry
);
1150 static void selectEntry(WMenu
* menu
, int entry_no
)
1156 if (menu
->entries
== NULL
)
1159 if (entry_no
>= menu
->entry_no
)
1162 old_entry
= menu
->selected_entry
;
1163 menu
->selected_entry
= entry_no
;
1165 if (old_entry
!= entry_no
) {
1167 /* unselect previous entry */
1168 if (old_entry
>= 0) {
1169 paintEntry(menu
, old_entry
, False
);
1170 entry
= menu
->entries
[old_entry
];
1173 if (entry
->cascade
>= 0 && menu
->cascades
) {
1174 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1175 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1181 menu
->selected_entry
= -1;
1184 entry
= menu
->entries
[entry_no
];
1186 if (entry
->cascade
>= 0 && menu
->cascades
&& entry
->flags
.enabled
) {
1187 /* Callback for when the submenu is opened.
1189 submenu
= menu
->cascades
[entry
->cascade
];
1190 if (submenu
&& submenu
->flags
.brother
)
1191 submenu
= submenu
->brother
;
1193 if (entry
->callback
) {
1194 /* Only call the callback if the submenu is not yet mapped.
1196 if (menu
->flags
.brother
) {
1197 if (!submenu
|| !submenu
->flags
.mapped
)
1198 (*entry
->callback
) (menu
->brother
, entry
);
1200 if (!submenu
|| !submenu
->flags
.buttoned
)
1201 (*entry
->callback
) (menu
, entry
);
1205 /* the submenu menu might have changed */
1206 submenu
= menu
->cascades
[entry
->cascade
];
1209 if (!submenu
->flags
.mapped
) {
1212 if (!submenu
->flags
.realized
)
1213 wMenuRealize(submenu
);
1214 if (wPreferences
.wrap_menus
) {
1215 if (menu
->flags
.open_to_left
)
1216 submenu
->flags
.open_to_left
= 1;
1218 if (submenu
->flags
.open_to_left
) {
1219 x
= menu
->frame_x
- MENUW(submenu
);
1222 submenu
->flags
.open_to_left
= 0;
1225 x
= menu
->frame_x
+ MENUW(menu
);
1227 if (x
+ MENUW(submenu
)
1228 >= menu
->frame
->screen_ptr
->scr_width
) {
1230 x
= menu
->frame_x
- MENUW(submenu
);
1231 submenu
->flags
.open_to_left
= 1;
1235 x
= menu
->frame_x
+ MENUW(menu
);
1238 if (wPreferences
.align_menus
) {
1241 y
= menu
->frame_y
+ menu
->entry_height
* entry_no
;
1242 if (menu
->flags
.titled
)
1243 y
+= menu
->frame
->top_width
;
1244 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1245 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1248 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1249 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1254 paintEntry(menu
, entry_no
, True
);
1258 static WMenu
*findMenu(WScreen
* scr
, int *x_ret
, int *y_ret
)
1261 WObjDescriptor
*desc
;
1262 Window root_ret
, win
, junk_win
;
1266 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
, &mask
);
1271 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1274 if (desc
->parent_type
== WCLASS_MENU
) {
1275 menu
= (WMenu
*) desc
->parent
;
1276 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
, x_ret
, y_ret
, &junk_win
);
1282 static void closeCascade(WMenu
* menu
)
1284 WMenu
*parent
= menu
->parent
;
1286 if (menu
->flags
.brother
|| (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
))) {
1288 selectEntry(menu
, -1);
1290 #if (MENU_BLINK_DELAY > 2)
1291 wusleep(MENU_BLINK_DELAY
/ 2);
1294 while (parent
!= NULL
1295 && (parent
->parent
!= NULL
|| !parent
->flags
.app_menu
|| parent
->flags
.brother
)
1296 && !parent
->flags
.buttoned
) {
1297 selectEntry(parent
, -1);
1299 parent
= parent
->parent
;
1302 selectEntry(parent
, -1);
1306 static void closeBrotherCascadesOf(WMenu
* menu
)
1311 for (i
= 0; i
< menu
->cascade_no
; i
++) {
1312 if (menu
->cascades
[i
]->flags
.brother
) {
1313 tmp
= menu
->cascades
[i
];
1315 tmp
= menu
->cascades
[i
]->brother
;
1317 if (tmp
->flags
.mapped
) {
1318 selectEntry(tmp
->parent
, -1);
1319 closeBrotherCascadesOf(tmp
);
1325 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1327 static WMenu
*parentMenu(WMenu
* menu
)
1332 if (menu
->flags
.buttoned
)
1335 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1336 parent
= menu
->parent
;
1337 if (parent
->selected_entry
< 0)
1339 entry
= parent
->entries
[parent
->selected_entry
];
1340 if (!entry
->flags
.enabled
|| entry
->cascade
< 0 || !parent
->cascades
||
1341 parent
->cascades
[entry
->cascade
] != menu
)
1344 if (menu
->flags
.buttoned
)
1352 * Will raise the passed menu, if submenu = 0
1353 * If submenu > 0 will also raise all mapped submenus
1354 * until the first buttoned one
1355 * If submenu < 0 will also raise all mapped parent menus
1356 * until the first buttoned one
1359 static void raiseMenus(WMenu
* menu
, int submenus
)
1367 wRaiseFrame(menu
->frame
->core
);
1369 if (submenus
> 0 && menu
->selected_entry
>= 0) {
1370 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1371 if (i
>= 0 && menu
->cascades
) {
1372 submenu
= menu
->cascades
[i
];
1373 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1374 raiseMenus(submenu
, submenus
);
1377 if (submenus
< 0 && !menu
->flags
.buttoned
&& menu
->parent
&& menu
->parent
->flags
.mapped
)
1378 raiseMenus(menu
->parent
, submenus
);
1381 WMenu
*wMenuUnderPointer(WScreen
* screen
)
1383 WObjDescriptor
*desc
;
1384 Window root_ret
, win
;
1388 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
, &dummy
, &dummy
, &mask
);
1393 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
1396 if (desc
->parent_type
== WCLASS_MENU
)
1397 return (WMenu
*) desc
->parent
;
1401 static void getPointerPosition(WScreen
* scr
, int *x
, int *y
)
1403 Window root_ret
, win
;
1407 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1410 static void getScrollAmount(WMenu
* menu
, int *hamount
, int *vamount
)
1412 WScreen
*scr
= menu
->menu
->screen_ptr
;
1413 int menuX1
= menu
->frame_x
;
1414 int menuY1
= menu
->frame_y
;
1415 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1416 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1418 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1423 getPointerPosition(scr
, &xroot
, &yroot
);
1425 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1426 /* scroll to the right */
1427 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1429 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) && menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1430 /* scroll to the left */
1431 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
- rect
.pos
.x
- rect
.size
.width
- 1));
1436 *hamount
= -*hamount
;
1439 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1441 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1443 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) && menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1445 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
- rect
.pos
.y
- rect
.size
.height
- 2));
1447 *vamount
= -*vamount
;
1451 static void dragScrollMenuCallback(void *data
)
1453 WMenu
*menu
= (WMenu
*) data
;
1454 WScreen
*scr
= menu
->menu
->screen_ptr
;
1455 WMenu
*parent
= parentMenu(menu
);
1456 int hamount
, vamount
;
1458 int newSelectedEntry
;
1460 getScrollAmount(menu
, &hamount
, &vamount
);
1462 if (hamount
!= 0 || vamount
!= 0) {
1463 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1464 if (findMenu(scr
, &x
, &y
)) {
1465 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1466 selectEntry(menu
, newSelectedEntry
);
1468 /* Pointer fell outside of menu. If the selected entry is
1469 * not a submenu, unselect it */
1470 if (menu
->selected_entry
>= 0 && menu
->entries
[menu
->selected_entry
]->cascade
< 0)
1471 selectEntry(menu
, -1);
1472 newSelectedEntry
= 0;
1475 /* paranoid check */
1476 if (newSelectedEntry
>= 0) {
1477 /* keep scrolling */
1478 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, dragScrollMenuCallback
, menu
);
1483 /* don't need to scroll anymore */
1485 if (findMenu(scr
, &x
, &y
)) {
1486 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1487 selectEntry(menu
, newSelectedEntry
);
1492 static void scrollMenuCallback(void *data
)
1494 WMenu
*menu
= (WMenu
*) data
;
1495 WMenu
*parent
= parentMenu(menu
);
1496 int hamount
= 0; /* amount to scroll */
1499 getScrollAmount(menu
, &hamount
, &vamount
);
1501 if (hamount
!= 0 || vamount
!= 0) {
1502 wMenuMove(parent
, parent
->frame_x
+ hamount
, parent
->frame_y
+ vamount
, True
);
1504 /* keep scrolling */
1505 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
, scrollMenuCallback
, menu
);
1507 /* don't need to scroll anymore */
1512 #define MENU_SCROLL_BORDER 5
1514 static int isPointNearBoder(WMenu
* menu
, int x
, int y
)
1516 int menuX1
= menu
->frame_x
;
1517 int menuY1
= menu
->frame_y
;
1518 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1519 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1521 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1522 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1524 /* XXX: handle screen joins properly !! */
1526 if (x
>= menuX1
&& x
<= menuX2
&&
1527 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
|| y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1529 else if (y
>= menuY1
&& y
<= menuY2
&&
1530 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
|| x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1536 typedef struct _delay
{
1541 static void leaving(_delay
* dl
)
1543 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1544 dl
->menu
->jump_back
= NULL
;
1545 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1549 void wMenuScroll(WMenu
* menu
, XEvent
* event
)
1552 WMenu
*omenu
= parentMenu(menu
);
1553 WScreen
*scr
= menu
->frame
->screen_ptr
;
1556 int old_frame_x
= omenu
->frame_x
;
1557 int old_frame_y
= omenu
->frame_y
;
1560 if (omenu
->jump_back
)
1561 WMDeleteTimerWithClientData(omenu
->jump_back
);
1563 if (( /*omenu->flags.buttoned && */ !wPreferences
.wrap_menus
)
1564 || omenu
->flags
.app_menu
) {
1568 if (!wPreferences
.wrap_menus
)
1569 raiseMenus(omenu
, True
);
1571 raiseMenus(menu
, False
);
1574 scrollMenuCallback(menu
);
1577 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1580 WMNextEvent(dpy
, &ev
);
1585 x
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1586 y
= (ev
.type
== MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1588 /* on_border is != 0 if the pointer is between the menu
1589 * and the screen border and is close enough to the border */
1590 on_border
= isPointNearBoder(menu
, x
, y
);
1592 smenu
= wMenuUnderPointer(scr
);
1594 if ((smenu
== NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
) != omenu
)) {
1599 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1600 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1601 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1602 on_border
= on_x_edge
|| on_y_edge
;
1604 if (!on_border
&& !jump_back
) {
1609 if (menu
->timer
&& (smenu
!= menu
|| (!on_y_edge
&& !on_x_edge
))) {
1610 WMDeleteTimerHandler(menu
->timer
);
1618 scrollMenuCallback(menu
);
1621 /* True if we push on title, or drag the omenu to other position */
1622 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1623 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1624 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1625 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1627 smenu
= wMenuUnderPointer(scr
);
1628 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1630 else if (smenu
== omenu
&& on_title
) {
1644 WMDeleteTimerHandler(menu
->timer
);
1650 if (!omenu
->jump_back
) {
1651 delayer
= wmalloc(sizeof(_delay
));
1652 delayer
->menu
= omenu
;
1653 delayer
->ox
= old_frame_x
;
1654 delayer
->oy
= old_frame_y
;
1655 omenu
->jump_back
= delayer
;
1656 scr
->flags
.jump_back_pending
= 1;
1658 delayer
= omenu
->jump_back
;
1659 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
, (WMCallback
*) leaving
, delayer
);
1663 static void menuExpose(WObjDescriptor
* desc
, XEvent
* event
)
1665 wMenuPaint(desc
->parent
);
1669 int *delayed_select
;
1674 static void delaySelection(void *data
)
1676 delay_data
*d
= (delay_data
*) data
;
1682 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1683 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1684 entry_no
= getEntryAt(menu
, x
, y
);
1685 selectEntry(menu
, entry_no
);
1687 if (d
->delayed_select
)
1688 *(d
->delayed_select
) = 0;
1691 static void menuMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
1694 XButtonEvent
*bev
= &event
->xbutton
;
1695 WMenu
*menu
= desc
->parent
;
1697 WScreen
*scr
= menu
->frame
->screen_ptr
;
1698 WMenuEntry
*entry
= NULL
;
1700 int close_on_exit
= 0;
1702 int delayed_select
= 0;
1706 int old_frame_x
= 0;
1707 int old_frame_y
= 0;
1708 delay_data d_data
= { NULL
, NULL
, NULL
};
1710 /* Doesn't seem to be needed anymore (if delayed selection handler is
1711 * added only if not present). there seem to be no other side effects
1712 * from removing this and it is also possible that it was only added
1713 * to avoid problems with adding the delayed selection timer handler
1716 /*if (menu->flags.inside_handler) {
1719 menu
->flags
.inside_handler
= 1;
1721 if (!wPreferences
.wrap_menus
) {
1722 smenu
= parentMenu(menu
);
1723 old_frame_x
= smenu
->frame_x
;
1724 old_frame_y
= smenu
->frame_y
;
1725 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1726 /* This is true if the menu was launched with right click on root window */
1727 if (!d_data
.magic
) {
1729 d_data
.delayed_select
= &delayed_select
;
1731 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
, delaySelection
, &d_data
);
1735 wRaiseFrame(menu
->frame
->core
);
1737 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1739 smenu
= findMenu(scr
, &x
, &y
);
1747 if (menu
->flags
.editing
) {
1750 entry_no
= getEntryAt(menu
, x
, y
);
1751 if (entry_no
>= 0) {
1752 entry
= menu
->entries
[entry_no
];
1754 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
&& entry
->flags
.editable
) {
1757 int number
= entry_no
- 2; /* Entries "New" and "Destroy Last" appear before workspaces */
1759 name
= wstrdup(scr
->workspaces
[number
]->name
);
1760 snprintf(buffer
, sizeof(buffer
), _("Type the name for workspace %i:"), number
+ 1);
1762 wMenuUnmap(scr
->root_menu
);
1764 if (wInputDialog(scr
, _("Rename Workspace"), buffer
, &name
))
1765 wWorkspaceRename(scr
, number
, name
);
1771 } else if (bev
->state
& ControlMask
) {
1775 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1776 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1778 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&& menu
->selected_entry
!= entry_no
) {
1779 wMenuUnmap(submenu
);
1781 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1782 selectEntry(menu
, entry_no
);
1783 } else if (!submenu
->flags
.buttoned
) {
1784 selectEntry(menu
, -1);
1787 } else if (!delayed_select
) {
1788 if (menu
== scr
->switch_menu
&& event
->xbutton
.button
== Button3
) {
1789 selectEntry(menu
, entry_no
);
1790 OpenWindowMenu2((WWindow
*)entry
->clientdata
,
1791 event
->xbutton
.x_root
,
1792 event
->xbutton
.y_root
, False
);
1793 wwin
= (WWindow
*)entry
->clientdata
;
1794 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
1795 event
->xany
.send_event
= True
;
1796 (*desc
->handle_mousedown
)(desc
, event
);
1798 XUngrabPointer(dpy
, CurrentTime
);
1799 selectEntry(menu
, -1);
1802 selectEntry(menu
, entry_no
);
1806 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
1808 dragScrollMenuCallback(menu
);
1812 prevx
= bev
->x_root
;
1813 prevy
= bev
->y_root
;
1817 XAllowEvents(dpy
, AsyncPointer
| SyncPointer
, CurrentTime
);
1819 WMMaskEvent(dpy
, ExposureMask
| ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
, &ev
);
1822 smenu
= findMenu(scr
, &x
, &y
);
1824 if (smenu
== NULL
) {
1825 /* moved mouse out of menu */
1827 if (!delayed_select
&& d_data
.magic
) {
1828 WMDeleteTimerHandler(d_data
.magic
);
1829 d_data
.magic
= NULL
;
1832 || (menu
->selected_entry
>= 0
1833 && menu
->entries
[menu
->selected_entry
]->cascade
>= 0)) {
1834 prevx
= ev
.xmotion
.x_root
;
1835 prevy
= ev
.xmotion
.y_root
;
1839 selectEntry(menu
, -1);
1841 prevx
= ev
.xmotion
.x_root
;
1842 prevy
= ev
.xmotion
.y_root
;
1844 } else if (menu
&& menu
!= smenu
1845 && (menu
->selected_entry
< 0
1846 || menu
->entries
[menu
->selected_entry
]->cascade
< 0)) {
1847 selectEntry(menu
, -1);
1849 if (!delayed_select
&& d_data
.magic
) {
1850 WMDeleteTimerHandler(d_data
.magic
);
1851 d_data
.magic
= NULL
;
1855 /* hysteresis for item selection */
1857 /* check if the motion was to the side, indicating that
1858 * the user may want to cross to a submenu */
1859 if (!delayed_select
&& menu
) {
1861 Bool moved_to_submenu
; /* moved to direction of submenu */
1863 dx
= abs(prevx
- ev
.xmotion
.x_root
);
1865 moved_to_submenu
= False
;
1866 if (dx
> 0 /* if moved enough to the side */
1867 /* maybe a open submenu */
1868 && menu
->selected_entry
>= 0
1869 /* moving to the right direction */
1870 && (wPreferences
.align_menus
|| ev
.xmotion
.y_root
>= prevy
)) {
1873 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
1875 if (menu
->cascades
[index
]->frame_x
> menu
->frame_x
) {
1876 if (prevx
< ev
.xmotion
.x_root
)
1877 moved_to_submenu
= True
;
1879 if (prevx
> ev
.xmotion
.x_root
)
1880 moved_to_submenu
= True
;
1885 if (menu
!= smenu
) {
1887 WMDeleteTimerHandler(d_data
.magic
);
1888 d_data
.magic
= NULL
;
1890 } else if (moved_to_submenu
) {
1891 /* while we are moving, postpone the selection */
1893 WMDeleteTimerHandler(d_data
.magic
);
1895 d_data
.delayed_select
= NULL
;
1897 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
1898 delaySelection
, &d_data
);
1899 prevx
= ev
.xmotion
.x_root
;
1900 prevy
= ev
.xmotion
.y_root
;
1904 WMDeleteTimerHandler(d_data
.magic
);
1905 d_data
.magic
= NULL
;
1910 prevx
= ev
.xmotion
.x_root
;
1911 prevy
= ev
.xmotion
.y_root
;
1912 if (menu
!= smenu
) {
1913 /* pointer crossed menus */
1914 if (menu
&& menu
->timer
) {
1915 WMDeleteTimerHandler(menu
->timer
);
1919 dragScrollMenuCallback(smenu
);
1923 dragScrollMenuCallback(menu
);
1925 if (!delayed_select
) {
1926 entry_no
= getEntryAt(menu
, x
, y
);
1927 if (entry_no
>= 0) {
1928 entry
= menu
->entries
[entry_no
];
1929 if (entry
->flags
.enabled
&& entry
->cascade
>= 0 && menu
->cascades
) {
1930 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1931 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
1932 && menu
->selected_entry
!= entry_no
) {
1933 wMenuUnmap(submenu
);
1937 selectEntry(menu
, entry_no
);
1945 if (ev
.xbutton
.button
== event
->xbutton
.button
)
1955 if (menu
&& menu
->timer
) {
1956 WMDeleteTimerHandler(menu
->timer
);
1959 if (d_data
.magic
!= NULL
) {
1960 WMDeleteTimerHandler(d_data
.magic
);
1961 d_data
.magic
= NULL
;
1964 if (menu
&& menu
->selected_entry
>= 0) {
1965 entry
= menu
->entries
[menu
->selected_entry
];
1966 if (entry
->callback
!= NULL
&& entry
->flags
.enabled
&& entry
->cascade
< 0) {
1967 /* blink and erase menu selection */
1968 #if (MENU_BLINK_DELAY > 0)
1969 int sel
= menu
->selected_entry
;
1972 for (i
= 0; i
< MENU_BLINK_COUNT
; i
++) {
1973 paintEntry(menu
, sel
, False
);
1975 wusleep(MENU_BLINK_DELAY
);
1976 paintEntry(menu
, sel
, True
);
1978 wusleep(MENU_BLINK_DELAY
);
1981 /* unmap the menu, it's parents and call the callback */
1982 if (!menu
->flags
.buttoned
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
1985 selectEntry(menu
, -1);
1987 (*entry
->callback
) (menu
, entry
);
1989 /* If the user double clicks an entry, the entry will
1990 * be executed twice, which is not good for things like
1991 * the root menu. So, ignore any clicks that were generated
1992 * while the entry was being executed */
1993 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
, ButtonPress
, &ev
)) ;
1994 } else if (entry
->callback
!= NULL
&& entry
->cascade
< 0) {
1995 selectEntry(menu
, -1);
1997 if (entry
->cascade
>= 0 && menu
->cascades
&& menu
->cascades
[entry
->cascade
]->flags
.brother
) {
1998 selectEntry(menu
, -1);
2003 if (((WMenu
*) desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2004 closeCascade(desc
->parent
);
2006 /* close the cascade windows that should not remain opened */
2007 closeBrotherCascadesOf(desc
->parent
);
2009 if (!wPreferences
.wrap_menus
)
2010 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2013 /* Just to be sure in case we skip the 2 above because of a goto byebye */
2014 if (menu
&& menu
->timer
) {
2015 WMDeleteTimerHandler(menu
->timer
);
2018 if (d_data
.magic
!= NULL
) {
2019 WMDeleteTimerHandler(d_data
.magic
);
2020 d_data
.magic
= NULL
;
2023 ((WMenu
*) desc
->parent
)->flags
.inside_handler
= 0;
2026 void wMenuMove(WMenu
* menu
, int x
, int y
, int submenus
)
2036 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2038 if (submenus
> 0 && menu
->selected_entry
>= 0) {
2039 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2041 if (i
>= 0 && menu
->cascades
) {
2042 submenu
= menu
->cascades
[i
];
2043 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2044 if (wPreferences
.align_menus
) {
2045 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2047 wMenuMove(submenu
, x
+ MENUW(menu
),
2048 y
+ submenu
->entry_height
* menu
->selected_entry
, submenus
);
2053 if (submenus
< 0 && menu
->parent
!= NULL
&& menu
->parent
->flags
.mapped
&& !menu
->parent
->flags
.buttoned
) {
2054 if (wPreferences
.align_menus
) {
2055 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2057 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2058 - menu
->parent
->entry_height
* menu
->parent
->selected_entry
, submenus
);
2063 static void changeMenuLevels(WMenu
* menu
, int lower
)
2068 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
: WMSubmenuLevel
));
2069 wRaiseFrame(menu
->frame
->core
);
2070 menu
->flags
.lowered
= 0;
2072 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2073 wLowerFrame(menu
->frame
->core
);
2074 menu
->flags
.lowered
= 1;
2076 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2077 if (menu
->cascades
[i
]
2078 && !menu
->cascades
[i
]->flags
.buttoned
&& menu
->cascades
[i
]->flags
.lowered
!= lower
) {
2079 changeMenuLevels(menu
->cascades
[i
], lower
);
2084 static void menuTitleDoubleClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2089 if (event
->xbutton
.state
& MOD_MASK
) {
2090 if (menu
->flags
.lowered
) {
2095 changeMenuLevels(menu
, lower
);
2099 static void menuTitleMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2104 int x
= menu
->frame_x
, y
= menu
->frame_y
;
2105 int dx
= event
->xbutton
.x_root
, dy
= event
->xbutton
.y_root
;
2109 /* can't touch the menu copy */
2110 if (menu
->flags
.brother
)
2113 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2116 if (event
->xbutton
.state
& MOD_MASK
) {
2117 wLowerFrame(menu
->frame
->core
);
2120 wRaiseFrame(menu
->frame
->core
);
2125 /* lower/raise all submenus */
2127 if (tmp
->selected_entry
>= 0 && tmp
->cascades
&& tmp
->entries
[tmp
->selected_entry
]->cascade
>= 0) {
2128 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2129 if (!tmp
|| !tmp
->flags
.mapped
)
2132 wLowerFrame(tmp
->frame
->core
);
2134 wRaiseFrame(tmp
->frame
->core
);
2140 /* tear off the menu if it's a root menu or a cascade
2142 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
&& (!menu
->flags
.app_menu
|| menu
->parent
!= NULL
)) {
2143 menu
->flags
.buttoned
= 1;
2144 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2146 /* turn off selected menu entry in parent menu */
2147 selectEntry(menu
->parent
, -1);
2149 /* make parent map the copy in place of the original */
2150 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2151 if (menu
->parent
->cascades
[i
] == menu
) {
2152 menu
->parent
->cascades
[i
] = menu
->brother
;
2161 WMMaskEvent(dpy
, ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
| ExposureMask
, &ev
);
2165 x
+= ev
.xmotion
.x_root
- dx
;
2166 y
+= ev
.xmotion
.y_root
- dy
;
2167 dx
= ev
.xmotion
.x_root
;
2168 dy
= ev
.xmotion
.y_root
;
2169 wMenuMove(menu
, x
, y
, True
);
2171 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2172 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2174 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2175 ButtonMotionMask
| ButtonReleaseMask
2177 GrabModeAsync
, GrabModeAsync
, None
,
2178 wCursor
[WCUR_MOVE
], CurrentTime
);
2187 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2189 XUngrabPointer(dpy
, CurrentTime
);
2200 *----------------------------------------------------------------------
2202 * Handles mouse click on the close button of menus. The menu is
2203 * closed when the button is clicked.
2206 * The closed menu is reinserted at it's parent menus
2208 *----------------------------------------------------------------------
2210 static void menuCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2212 WMenu
*menu
= (WMenu
*) data
;
2213 WMenu
*parent
= menu
->parent
;
2217 for (i
= 0; i
< parent
->cascade_no
; i
++) {
2218 /* find the entry that points to the copy */
2219 if (parent
->cascades
[i
] == menu
->brother
) {
2220 /* make it point to the original */
2221 parent
->cascades
[i
] = menu
;
2222 menu
->parent
= parent
;
2230 static void saveMenuInfo(WMPropList
* dict
, WMenu
* menu
, WMPropList
* key
)
2232 WMPropList
*value
, *list
;
2235 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2236 value
= WMCreatePLString(buffer
);
2237 list
= WMCreatePLArray(value
, NULL
);
2238 if (menu
->flags
.lowered
)
2239 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2240 WMPutInPLDictionary(dict
, key
, list
);
2241 WMReleasePropList(value
);
2242 WMReleasePropList(list
);
2245 void wMenuSaveState(WScreen
* scr
)
2247 WMPropList
*menus
, *key
;
2250 menus
= WMCreatePLDictionary(NULL
, NULL
);
2252 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2253 key
= WMCreatePLString("SwitchMenu");
2254 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2255 WMReleasePropList(key
);
2259 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2262 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2263 key
= WMCreatePLString("WorkspaceMenu");
2264 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2265 WMReleasePropList(key
);
2270 key
= WMCreatePLString("Menus");
2271 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2272 WMReleasePropList(key
);
2274 WMReleasePropList(menus
);
2277 static Bool
getMenuPath(WMenu
* menu
, char *buffer
, int bufSize
)
2282 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2285 len
= strlen(menu
->frame
->title
);
2290 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2295 strcat(buffer
, "\\");
2296 strcat(buffer
, menu
->frame
->title
);
2301 static Bool
saveMenuRecurs(WMPropList
* menus
, WScreen
* scr
, WMenu
* menu
)
2304 int save_menus
= 0, i
;
2308 if (menu
->flags
.brother
)
2309 menu
= menu
->brother
;
2311 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2314 ok
= getMenuPath(menu
, buffer
, 510);
2317 key
= WMCreatePLString(buffer
);
2318 saveMenuInfo(menus
, menu
, key
);
2319 WMReleasePropList(key
);
2325 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2326 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2333 #define COMPLAIN(key) wwarning(_("bad value in menus state info: %s"), key)
2335 static Bool
getMenuInfo(WMPropList
* info
, int *x
, int *y
, Bool
* lowered
)
2341 if (WMIsPLArray(info
)) {
2343 pos
= WMGetFromPLArray(info
, 0);
2344 flags
= WMGetFromPLArray(info
, 1);
2345 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2346 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2353 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2354 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
) != 2)
2355 COMPLAIN("Position");
2357 COMPLAIN("(position, flags...)");
2364 static int restoreMenu(WScreen
* scr
, WMPropList
* menu
, int which
)
2367 Bool lowered
= False
;
2368 WMenu
*pmenu
= NULL
;
2373 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2376 if (which
& WSS_SWITCHMENU
) {
2377 OpenSwitchMenu(scr
, x
, y
, False
);
2378 pmenu
= scr
->switch_menu
;
2382 int width
= MENUW(pmenu
);
2383 int height
= MENUH(pmenu
);
2384 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2387 changeMenuLevels(pmenu
, True
);
2390 if (x
< rect
.pos
.x
- width
)
2392 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2393 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2396 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2397 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2399 wMenuMove(pmenu
, x
, y
, True
);
2400 pmenu
->flags
.buttoned
= 1;
2401 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2407 static int restoreMenuRecurs(WScreen
* scr
, WMPropList
* menus
, WMenu
* menu
, char *path
)
2409 WMPropList
*key
, *entry
;
2414 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2417 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2418 key
= WMCreatePLString(buffer
);
2419 entry
= WMGetFromPLDictionary(menus
, key
);
2422 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2424 if (!menu
->flags
.mapped
) {
2425 int width
= MENUW(menu
);
2426 int height
= MENUH(menu
);
2427 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2429 wMenuMapAt(menu
, x
, y
, False
);
2432 /* make parent map the copy in place of the original */
2433 for (i
= 0; i
< menu
->parent
->cascade_no
; i
++) {
2434 if (menu
->parent
->cascades
[i
] == menu
) {
2435 menu
->parent
->cascades
[i
] = menu
->brother
;
2441 changeMenuLevels(menu
, True
);
2444 if (x
< rect
.pos
.x
- width
)
2446 if (x
> rect
.pos
.x
+ rect
.size
.width
)
2447 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2450 if (y
> rect
.pos
.y
+ rect
.size
.height
)
2451 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2453 wMenuMove(menu
, x
, y
, True
);
2454 menu
->flags
.buttoned
= 1;
2455 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2460 WMReleasePropList(key
);
2462 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2463 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2470 void wMenuRestoreState(WScreen
* scr
)
2472 WMPropList
*menus
, *menu
, *key
, *skey
;
2474 if (!scr
->session_state
) {
2478 key
= WMCreatePLString("Menus");
2479 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2480 WMReleasePropList(key
);
2487 skey
= WMCreatePLString("SwitchMenu");
2488 menu
= WMGetFromPLDictionary(menus
, skey
);
2489 WMReleasePropList(skey
);
2490 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2492 if (!scr
->root_menu
) {
2493 OpenRootMenu(scr
, scr
->scr_width
* 2, 0, False
);
2494 wMenuUnmap(scr
->root_menu
);
2496 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2499 void OpenWorkspaceMenu(WScreen
* scr
, int x
, int y
)
2501 WMenu
*menu
, *parent
;
2504 if (!scr
->root_menu
) {
2505 OpenRootMenu(scr
, scr
->scr_width
* 2, 0, False
);
2506 wMenuUnmap(scr
->root_menu
);
2509 menu
= scr
->workspace_menu
;
2511 if (menu
->flags
.mapped
) {
2512 if (!menu
->flags
.buttoned
) {
2514 parent
= menu
->parent
;
2515 if (parent
&& parent
->selected_entry
>= 0) {
2516 entry
= parent
->entries
[parent
->selected_entry
];
2517 if (parent
->cascades
[entry
->cascade
] == menu
) {
2518 selectEntry(parent
, -1);
2519 wMenuMapAt(menu
, x
, y
, False
);
2523 wRaiseFrame(menu
->frame
->core
);
2524 wMenuMapCopyAt(menu
, x
, y
);
2527 wMenuMapAt(menu
, x
, y
, False
);