1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1997, 1998 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
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
37 #include "WindowMaker.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
62 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
63 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
66 /***** Local Stuff ******/
71 } menuScrollParameters
[5] = {
72 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
73 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
74 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
75 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
76 {MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
79 static void menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
80 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
);
85 static void menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
87 static void updateTexture(WMenu
*menu
);
90 static int saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
);
91 static int restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
);
94 static void selectEntry(WMenu
*menu
, int entry_no
);
95 static void closeCascade(WMenu
*menu
);
98 /****** Notification Observers ******/
101 appearanceObserver(void *self
, WMNotification
*notif
)
103 WMenu
*menu
= (WMenu
*)self
;
104 int flags
= (int)WMGetNotificationClientData(notif
);
106 if (!menu
->flags
.realized
)
109 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
110 if (flags
& WFontSettings
) {
111 menu
->flags
.realized
= 0;
114 if (flags
& WTextureSettings
) {
115 if (!menu
->flags
.brother
)
118 if (flags
& (WTextureSettings
|WColorSettings
)) {
121 } else if (menu
->flags
.titled
) {
123 if (flags
& WFontSettings
) {
124 menu
->flags
.realized
= 0;
127 if (flags
& WTextureSettings
) {
128 menu
->frame
->flags
.need_texture_remake
= 1;
130 if (flags
& (WColorSettings
|WTextureSettings
)) {
131 wFrameWindowPaint(menu
->frame
);
136 /************************************/
140 *----------------------------------------------------------------------
142 * Creates a new empty menu with the specified title. If main_menu
143 * is True, the created menu will be a main menu, which has some special
144 * properties such as being placed over other normal menus.
145 * If title is NULL, the menu will have no titlebar.
149 *----------------------------------------------------------------------
152 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
155 static int brother
=0;
158 menu
= wmalloc(sizeof(WMenu
));
160 memset(menu
, 0, sizeof(WMenu
));
162 #ifdef SINGLE_MENULEVEL
163 tmp
= WMSubmenuLevel
;
165 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
168 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
170 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
171 menu
->flags
.titled
= 1;
174 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
175 screen
->menu_title_texture
, NULL
,
176 screen
->menu_title_pixel
,
177 &screen
->menu_title_gc
,
178 &screen
->menu_title_font
);
180 menu
->frame
->core
->descriptor
.parent
= menu
;
181 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
182 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
184 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
187 menu
->frame
->title
= wstrdup(title
);
190 menu
->frame
->flags
.justification
= WTJ_LEFT
;
192 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
195 menu
->alloced_entries
= 0;
196 menu
->selected_entry
= -1;
197 menu
->entries
= NULL
;
199 menu
->frame_x
= screen
->app_menu_x
;
200 menu
->frame_y
= screen
->app_menu_y
;
202 menu
->frame
->child
= menu
;
204 menu
->flags
.lowered
= 0;
208 /* setup object descriptors */
209 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
210 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
213 menu
->frame
->on_click_right
= menuCloseClick
;
216 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
217 menu
->frame
->core
->width
, 10);
219 menu
->menu
->descriptor
.parent
= menu
;
220 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
221 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
222 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
224 menu
->menu_texture_data
= None
;
226 XMapWindow(dpy
, menu
->menu
->window
);
232 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
234 menu
->brother
->flags
.brother
= 1;
235 menu
->brother
->brother
= menu
;
237 WMAddNotificationObserver(appearanceObserver
, menu
,
238 WNMenuAppearanceSettingsChanged
, menu
);
240 WMAddNotificationObserver(appearanceObserver
, menu
,
241 WNMenuTitleAppearanceSettingsChanged
, menu
);
251 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
255 menu
= wMenuCreate(screen
, title
, main_menu
);
258 menu
->flags
.app_menu
= 1;
259 menu
->brother
->flags
.app_menu
= 1;
267 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
271 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
272 menu
->entries
[i
]->order
++;
273 menu
->entries
[i
+1] = menu
->entries
[i
];
275 menu
->entries
[index
] = entry
;
280 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
281 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
286 menu
->flags
.realized
= 0;
287 menu
->brother
->flags
.realized
= 0;
289 /* reallocate array if it's too small */
290 if (menu
->entry_no
>= menu
->alloced_entries
) {
293 tmp
= wrealloc(menu
->entries
,
294 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
297 menu
->alloced_entries
+= 5;
299 menu
->brother
->entries
= tmp
;
300 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
302 entry
= wmalloc(sizeof(WMenuEntry
));
303 memset(entry
, 0, sizeof(WMenuEntry
));
304 entry
->flags
.enabled
= 1;
305 entry
->text
= wstrdup(text
);
307 entry
->clientdata
= clientdata
;
308 entry
->callback
= callback
;
309 if (index
<0 || index
>=menu
->entry_no
) {
310 entry
->order
= menu
->entry_no
;
311 menu
->entries
[menu
->entry_no
] = entry
;
313 entry
->order
= index
;
314 insertEntry(menu
, entry
, index
);
318 menu
->brother
->entry_no
= menu
->entry_no
;
326 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
328 WMenu
*brother
= menu
->brother
;
331 assert(menu
->flags
.brother
==0);
333 if (entry
->cascade
>=0) {
334 menu
->flags
.realized
= 0;
335 brother
->flags
.realized
= 0;
338 cascade
->parent
= menu
;
340 cascade
->brother
->parent
= brother
;
343 for (i
=0; i
<menu
->cascade_no
; i
++) {
344 if (menu
->cascades
[i
]==NULL
) {
345 menu
->cascades
[i
] = cascade
;
346 brother
->cascades
[i
] = cascade
->brother
;
353 entry
->cascade
= menu
->cascade_no
;
355 menu
->cascades
= wrealloc(menu
->cascades
,
356 sizeof(WMenu
)*(menu
->cascade_no
+1));
357 menu
->cascades
[menu
->cascade_no
++] = cascade
;
360 brother
->cascades
= wrealloc(brother
->cascades
,
361 sizeof(WMenu
)*(brother
->cascade_no
+1));
362 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
366 if (menu
->flags
.lowered
) {
368 cascade
->flags
.lowered
= 1;
369 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
371 cascade
->brother
->flags
.lowered
= 1;
372 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
375 if (!menu
->flags
.realized
)
381 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
383 assert(menu
->flags
.brother
==0);
385 /* destroy cascade menu */
386 if (entry
->cascade
>=0 && menu
->cascades
387 && menu
->cascades
[entry
->cascade
]!=NULL
) {
389 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
391 menu
->cascades
[entry
->cascade
] = NULL
;
392 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
400 wMenuRemoveItem(WMenu
*menu
, int index
)
404 if (menu
->flags
.brother
) {
405 wMenuRemoveItem(menu
->brother
, index
);
409 if (index
>=menu
->entry_no
) return;
411 /* destroy cascade menu */
412 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
414 /* destroy unshared data */
416 if (menu
->entries
[index
]->text
)
417 wfree(menu
->entries
[index
]->text
);
419 if (menu
->entries
[index
]->rtext
)
420 wfree(menu
->entries
[index
]->rtext
);
422 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
423 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
425 wfree(menu
->entries
[index
]);
427 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
428 menu
->entries
[i
+1]->order
--;
429 menu
->entries
[i
]=menu
->entries
[i
+1];
432 menu
->brother
->entry_no
--;
437 renderTexture(WMenu
*menu
)
445 WScreen
*scr
= menu
->menu
->screen_ptr
;
446 WTexture
*texture
= scr
->menu_item_texture
;
448 if (wPreferences
.menu_style
== MS_NORMAL
) {
449 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
450 menu
->entry_height
, WREL_MENUENTRY
);
452 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
453 menu
->menu
->height
+1, WREL_MENUENTRY
);
456 wwarning(_("could not render texture: %s"),
457 RMessageForError(RErrorCode
));
462 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
464 light
.red
= light
.green
= light
.blue
= 80;
467 dark
.red
= dark
.green
= dark
.blue
= 0;
470 mid
.red
= mid
.green
= mid
.blue
= 40;
472 for (i
= 1; i
< menu
->entry_no
; i
++) {
473 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
474 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
476 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
477 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
479 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
480 menu
->menu
->width
-1, i
*menu
->entry_height
,
484 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
485 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
494 updateTexture(WMenu
*menu
)
496 WScreen
*scr
= menu
->menu
->screen_ptr
;
498 /* setup background texture */
499 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
500 if (!menu
->flags
.brother
) {
501 FREE_PIXMAP(menu
->menu_texture_data
);
503 menu
->menu_texture_data
= renderTexture(menu
);
505 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
506 menu
->menu_texture_data
);
507 XClearWindow(dpy
, menu
->menu
->window
);
509 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
510 menu
->menu_texture_data
);
511 XClearWindow(dpy
, menu
->brother
->menu
->window
);
514 XSetWindowBackground(dpy
, menu
->menu
->window
,
515 scr
->menu_item_texture
->any
.color
.pixel
);
516 XClearWindow(dpy
, menu
->menu
->window
);
522 wMenuRealize(WMenu
*menu
)
525 int width
, rwidth
, mrwidth
, mwidth
;
526 int theight
, twidth
, eheight
;
527 WScreen
*scr
= menu
->frame
->screen_ptr
;
528 static int brother_done
=0;
533 wMenuRealize(menu
->brother
);
537 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
538 if (menu
->flags
.titled
)
539 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
541 wFrameWindowUpdateBorders(menu
->frame
, flags
);
543 if (menu
->flags
.titled
) {
544 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
545 strlen(menu
->frame
->title
));
546 theight
= menu
->frame
->top_width
;
547 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
552 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
553 menu
->entry_height
= eheight
;
556 for (i
=0; i
<menu
->entry_no
; i
++) {
559 /* search widest text */
560 text
= menu
->entries
[i
]->text
;
561 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
563 if (menu
->entries
[i
]->flags
.indicator
) {
564 width
+= MENU_INDICATOR_SPACE
;
570 /* search widest text on right */
571 text
= menu
->entries
[i
]->rtext
;
573 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
575 else if (menu
->entries
[i
]->cascade
>=0)
580 if (rwidth
> mrwidth
)
589 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
591 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
592 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
597 menu
->flags
.realized
= 1;
599 if (menu
->flags
.mapped
)
601 if (menu
->brother
->flags
.mapped
)
602 wMenuPaint(menu
->brother
);
607 wMenuDestroy(WMenu
*menu
, int recurse
)
611 WMRemoveNotificationObserver(menu
);
613 /* remove any pending timers */
615 WMDeleteTimerHandler(menu
->timer
);
618 /* call destroy handler */
619 if (menu
->on_destroy
)
620 (*menu
->on_destroy
)(menu
);
622 /* Destroy items if this menu own them. If this is the "brother" menu,
623 * leave them alone as it is shared by them.
625 if (!menu
->flags
.brother
) {
626 for (i
=0; i
<menu
->entry_no
; i
++) {
628 wfree(menu
->entries
[i
]->text
);
630 if (menu
->entries
[i
]->rtext
)
631 wfree(menu
->entries
[i
]->rtext
);
634 if (menu
->entries
[i
]->instances
){
635 WMReleasePropList(menu
->entries
[i
]->instances
);
637 #endif /* USER_MENU */
639 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
640 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
642 wfree(menu
->entries
[i
]);
646 for (i
=0; i
<menu
->cascade_no
; i
++) {
647 if (menu
->cascades
[i
]) {
648 if (menu
->cascades
[i
]->flags
.brother
)
649 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
651 wMenuDestroy(menu
->cascades
[i
], recurse
);
657 wfree(menu
->entries
);
661 FREE_PIXMAP(menu
->menu_texture_data
);
664 wfree(menu
->cascades
);
666 wCoreDestroy(menu
->menu
);
667 wFrameWindowDestroy(menu
->frame
);
669 /* destroy copy of this menu */
670 if (!menu
->flags
.brother
&& menu
->brother
)
671 wMenuDestroy(menu
->brother
, False
);
683 drawFrame(WScreen
*scr
, Drawable win
, int y
, int w
, int h
, int type
)
689 segs
[i
].x1
= segs
[i
].x2
= w
-1;
691 segs
[i
].y2
= y
+ h
- 1;
693 if (type
!= F_TOP
&& type
!= F_NONE
) {
695 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
699 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
705 segs
[i
].y2
= y
+ h
- 1;
707 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
714 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
716 if (type
!= F_TOP
&& type
!= F_NONE
)
717 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
723 paintEntry(WMenu
*menu
, int index
, int selected
)
727 GC light
, dim
, dark
, textGC
;
728 WScreen
*scr
=menu
->frame
->screen_ptr
;
729 Window win
= menu
->menu
->window
;
730 WMenuEntry
*entry
=menu
->entries
[index
];
732 if (!menu
->flags
.realized
) return;
733 h
= menu
->entry_height
;
734 w
= menu
->menu
->width
;
737 light
= scr
->menu_item_auxtexture
->light_gc
;
738 dim
= scr
->menu_item_auxtexture
->dim_gc
;
739 dark
= scr
->menu_item_auxtexture
->dark_gc
;
741 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
744 else if (index
== menu
->entry_no
- 1)
752 /* paint background */
754 XSetForeground(dpy
, scr
->select_menu_gc
, scr
->select_pixel
);
755 XFillRectangle(dpy
, win
, scr
->select_menu_gc
, 1, y
+1, w
-2, h
-3);
756 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
757 drawFrame(scr
, win
, y
, w
, h
, type
);
759 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
760 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
762 drawFrame(scr
, win
, y
, w
, h
, type
);
764 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
769 textGC
= scr
->select_menu_gc
;
770 if (entry
->flags
.enabled
)
771 XSetForeground(dpy
, textGC
, scr
->select_text_pixel
);
773 XSetForeground(dpy
, textGC
, scr
->dtext_pixel
);
774 } else if (!entry
->flags
.enabled
) {
775 textGC
= scr
->disabled_menu_entry_gc
;
777 textGC
= scr
->menu_entry_gc
;
781 if (entry
->flags
.indicator
)
782 x
+= MENU_INDICATOR_SPACE
+ 2;
784 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
,
785 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
787 if (entry
->cascade
>=0) {
788 /* draw the cascade indicator */
789 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
790 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
791 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
795 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
800 switch (entry
->flags
.indicator_type
) {
802 indicator
= scr
->menu_check_indicator
;
805 indicator
= scr
->menu_mini_indicator
;
808 indicator
= scr
->menu_hide_indicator
;
811 indicator
= scr
->menu_shade_indicator
;
815 indicator
= scr
->menu_radio_indicator
;
819 iw
= indicator
->width
;
820 ih
= indicator
->height
;
821 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
822 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
824 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
826 XSetForeground(dpy
, scr
->copy_gc
, scr
->mtext_pixel
);
827 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
829 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
830 iw, ih, 5, y+(h-ih)/2);
832 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
835 /* draw right text */
837 if (entry
->rtext
&& entry
->cascade
<0) {
839 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
840 strlen(entry
->rtext
));
841 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
, w
-6-tw
,
842 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
848 move_menus(WMenu
*menu
, int x
, int y
)
850 while (menu
->parent
) {
853 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
854 y
-= menu
->selected_entry
*menu
->entry_height
;
857 wMenuMove(menu
, x
, y
, True
);
861 makeVisible(WMenu
*menu
)
863 WScreen
*scr
= menu
->frame
->screen_ptr
;
864 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
866 if (menu
->entry_no
<0) return;
869 y1
= menu
->frame_y
+menu
->frame
->top_width
870 + menu
->selected_entry
*menu
->entry_height
;
871 x2
= x1
+ MENUW(menu
);
872 y2
= y1
+ menu
->entry_height
;
881 } else if (x2
>= scr
->scr_width
) {
882 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
889 } else if (y2
>= scr
->scr_height
) {
890 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
894 new_y
= new_y
- menu
->frame
->top_width
895 - menu
->selected_entry
*menu
->entry_height
;
896 move_menus(menu
, new_x
, new_y
);
901 check_key(WMenu
*menu
, XKeyEvent
*event
)
906 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
909 ch
= toupper(buffer
[0]);
911 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
914 for (i
=s
; i
<menu
->entry_no
; i
++) {
915 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
919 /* no match. Retry from start, if previous started from a selected entry */
929 keyboardMenu(WMenu
*menu
)
932 KeySym ksym
=NoSymbol
;
936 int old_pos_x
= menu
->frame_x
;
937 int old_pos_y
= menu
->frame_y
;
938 int new_x
= old_pos_x
, new_y
= old_pos_y
;
939 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
940 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
942 if (menu
->flags
.editing
)
946 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
947 GrabModeAsync
, CurrentTime
);
949 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
950 new_y
= scr_height
- menu
->frame
->top_width
;
952 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
953 new_x
= scr_width
-MENUW(menu
)-1;
955 move_menus(menu
, new_x
, new_y
);
957 while (!done
&& menu
->flags
.mapped
) {
958 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
959 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
960 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
961 |SubstructureNotifyMask
, &event
);
963 switch (event
.type
) {
965 ksym
= XLookupKeysym(&event
.xkey
, 0);
975 selectEntry(menu
, 0);
983 selectEntry(menu
, menu
->entry_no
-1);
994 if (menu
->selected_entry
<= 0)
995 selectEntry(menu
, menu
->entry_no
-1);
997 selectEntry(menu
, menu
->selected_entry
-1);
1002 #ifdef ARROWLESS_KBD
1008 if (menu
->selected_entry
<0)
1009 selectEntry(menu
, 0);
1010 else if (menu
->selected_entry
== menu
->entry_no
-1)
1011 selectEntry(menu
, 0);
1012 else if (menu
->selected_entry
< menu
->entry_no
-1)
1013 selectEntry(menu
, menu
->selected_entry
+1);
1018 #ifdef ARROWLESS_KBD
1024 if (menu
->selected_entry
>=0) {
1026 entry
= menu
->entries
[menu
->selected_entry
];
1028 if (entry
->cascade
>= 0 && menu
->cascades
1029 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1031 XUngrabKeyboard(dpy
, CurrentTime
);
1033 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1034 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1037 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1038 GrabModeAsync
, GrabModeAsync
,
1045 #ifdef ARROWLESS_KBD
1051 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1052 selectEntry(menu
, -1);
1053 move_menus(menu
, old_pos_x
, old_pos_y
);
1063 index
= check_key(menu
, &event
.xkey
);
1065 selectEntry(menu
, index
);
1071 if (event
.type
==ButtonPress
)
1074 WMHandleEvent(&event
);
1078 XUngrabKeyboard(dpy
, CurrentTime
);
1080 if (done
==2 && menu
->selected_entry
>=0) {
1081 entry
= menu
->entries
[menu
->selected_entry
];
1086 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1087 && entry
->cascade
< 0) {
1088 #if (MENU_BLINK_COUNT > 0)
1089 int sel
= menu
->selected_entry
;
1092 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1093 paintEntry(menu
, sel
, False
);
1095 wusleep(MENU_BLINK_DELAY
);
1096 paintEntry(menu
, sel
, True
);
1098 wusleep(MENU_BLINK_DELAY
);
1101 selectEntry(menu
, -1);
1103 if (!menu
->flags
.buttoned
) {
1105 move_menus(menu
, old_pos_x
, old_pos_y
);
1109 (*entry
->callback
)(menu
, entry
);
1111 if (!menu
->flags
.buttoned
) {
1113 move_menus(menu
, old_pos_x
, old_pos_y
);
1115 selectEntry(menu
, -1);
1119 /* returns True if returning from a submenu to a parent menu,
1120 * False if exiting from menu */
1126 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1128 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1129 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1131 if (!menu
->flags
.realized
) {
1132 menu
->flags
.realized
=1;
1135 if (!menu
->flags
.mapped
) {
1136 if (wPreferences
.wrap_menus
) {
1139 if (x
+MENUW(menu
) > scr_width
)
1140 x
= scr_width
- MENUW(menu
);
1141 if (y
+MENUH(menu
) > scr_height
)
1142 y
= scr_height
- MENUH(menu
);
1145 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1148 XMapWindow(dpy
, menu
->frame
->core
->window
);
1149 wRaiseFrame(menu
->frame
->core
);
1150 menu
->flags
.mapped
= 1;
1152 selectEntry(menu
, 0);
1161 wMenuMap(WMenu
*menu
)
1163 if (!menu
->flags
.realized
) {
1164 menu
->flags
.realized
=1;
1167 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1168 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1169 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1170 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1172 XMapWindow(dpy
, menu
->frame
->core
->window
);
1173 wRaiseFrame(menu
->frame
->core
);
1174 menu
->flags
.mapped
= 1;
1179 wMenuUnmap(WMenu
*menu
)
1183 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1184 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1185 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1187 menu
->flags
.buttoned
= 0;
1188 menu
->flags
.mapped
= 0;
1189 menu
->flags
.open_to_left
= 0;
1191 for (i
=0; i
<menu
->cascade_no
; i
++) {
1192 if (menu
->cascades
[i
]!=NULL
1193 && menu
->cascades
[i
]->flags
.mapped
1194 && !menu
->cascades
[i
]->flags
.buttoned
) {
1196 wMenuUnmap(menu
->cascades
[i
]);
1199 menu
->selected_entry
= -1;
1205 wMenuPaint(WMenu
*menu
)
1209 if (!menu
->flags
.mapped
) {
1214 for (i
=0; i
<menu
->entry_no
; i
++) {
1215 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1221 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1223 if (index
>=menu
->entry_no
) return;
1224 menu
->entries
[index
]->flags
.enabled
=enable
;
1225 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1226 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1230 /* ====================================================================== */
1234 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1238 WObjDescriptor
*desc
;
1244 menu
->flags
.editing
= 1;
1246 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1247 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1249 wTextPutText(text
, entry
->text
);
1250 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1251 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1253 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1254 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1255 wwarning(_("could not grab keyboard"));
1258 wSetFocusTo(menu
->frame
->screen_ptr
,
1259 menu
->frame
->screen_ptr
->focused_window
);
1264 while (!done
&& !text
->done
) {
1266 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1268 WMNextEvent(dpy
, &event
);
1270 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1271 (XPointer
*)&desc
)==XCNOENT
)
1274 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1276 (*desc
->handle_anything
)(desc
, &event
);
1279 switch (event
.type
) {
1281 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1285 WMHandleEvent(&event
);
1291 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1293 wSetFocusTo(menu
->frame
->screen_ptr
,
1294 menu
->frame
->screen_ptr
->focused_window
);
1297 t
= wTextGetText(text
);
1298 /* if !t, the user has canceled editing */
1302 entry
->text
= wstrdup(t
);
1304 menu
->flags
.realized
= 0;
1308 XUngrabKeyboard(dpy
, CurrentTime
);
1310 if (t
&& menu
->on_edit
)
1311 (*menu
->on_edit
)(menu
, entry
);
1313 menu
->flags
.editing
= 0;
1315 if (!menu
->flags
.realized
)
1321 selectEntry(WMenu
*menu
, int entry_no
)
1327 if (menu
->entries
==NULL
)
1330 if (entry_no
>= menu
->entry_no
)
1333 old_entry
= menu
->selected_entry
;
1334 menu
->selected_entry
= entry_no
;
1336 if (old_entry
!=entry_no
) {
1338 /* unselect previous entry */
1340 paintEntry(menu
, old_entry
, False
);
1341 entry
= menu
->entries
[old_entry
];
1344 if (entry
->cascade
>=0 && menu
->cascades
) {
1345 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1346 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1352 menu
->selected_entry
= -1;
1355 entry
= menu
->entries
[entry_no
];
1357 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1358 /* Callback for when the submenu is opened.
1360 submenu
= menu
->cascades
[entry
->cascade
];
1361 if (submenu
&& submenu
->flags
.brother
)
1362 submenu
= submenu
->brother
;
1364 if (entry
->callback
) {
1365 /* Only call the callback if the submenu is not yet mapped.
1367 if (menu
->flags
.brother
) {
1368 if (!submenu
|| !submenu
->flags
.mapped
)
1369 (*entry
->callback
)(menu
->brother
, entry
);
1371 if (!submenu
|| !submenu
->flags
.buttoned
)
1372 (*entry
->callback
)(menu
, entry
);
1376 /* the submenu menu might have changed */
1377 submenu
= menu
->cascades
[entry
->cascade
];
1380 if (!submenu
->flags
.mapped
) {
1383 if (!submenu
->flags
.realized
)
1384 wMenuRealize(submenu
);
1385 if (wPreferences
.wrap_menus
) {
1386 if (menu
->flags
.open_to_left
)
1387 submenu
->flags
.open_to_left
= 1;
1389 if (submenu
->flags
.open_to_left
) {
1390 x
= menu
->frame_x
- MENUW(submenu
);
1393 submenu
->flags
.open_to_left
= 0;
1396 x
= menu
->frame_x
+ MENUW(menu
);
1398 if (x
+ MENUW(submenu
)
1399 >= menu
->frame
->screen_ptr
->scr_width
) {
1401 x
= menu
->frame_x
- MENUW(submenu
);
1402 submenu
->flags
.open_to_left
= 1;
1406 x
= menu
->frame_x
+ MENUW(menu
);
1409 if (wPreferences
.align_menus
) {
1412 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1413 if (menu
->flags
.titled
)
1414 y
+= menu
->frame
->top_width
;
1415 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1416 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1419 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1420 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1425 paintEntry(menu
, entry_no
, True
);
1431 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1434 WObjDescriptor
*desc
;
1435 Window root_ret
, win
, junk_win
;
1439 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1442 if (win
==None
) return NULL
;
1444 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1447 if (desc
->parent_type
== WCLASS_MENU
) {
1448 menu
= (WMenu
*)desc
->parent
;
1449 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1450 x_ret
, y_ret
, &junk_win
);
1460 closeCascade(WMenu
*menu
)
1462 WMenu
*parent
=menu
->parent
;
1464 if (menu
->flags
.brother
1465 || (!menu
->flags
.buttoned
1466 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1468 selectEntry(menu
, -1);
1470 #if (MENU_BLINK_DELAY > 2)
1471 wusleep(MENU_BLINK_DELAY
/2);
1475 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1476 || parent
->flags
.brother
)
1477 && !parent
->flags
.buttoned
) {
1478 selectEntry(parent
, -1);
1480 parent
= parent
->parent
;
1483 selectEntry(parent
, -1);
1489 closeBrotherCascadesOf(WMenu
*menu
)
1494 for (i
=0; i
<menu
->cascade_no
; i
++) {
1495 if (menu
->cascades
[i
]->flags
.brother
) {
1496 tmp
= menu
->cascades
[i
];
1498 tmp
= menu
->cascades
[i
]->brother
;
1500 if (tmp
->flags
.mapped
) {
1501 selectEntry(tmp
->parent
, -1);
1502 closeBrotherCascadesOf(tmp
);
1509 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1513 parentMenu(WMenu
*menu
)
1518 if (menu
->flags
.buttoned
)
1521 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1522 parent
= menu
->parent
;
1523 if (parent
->selected_entry
< 0)
1525 entry
= parent
->entries
[parent
->selected_entry
];
1526 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1527 parent
->cascades
[entry
->cascade
] != menu
)
1530 if (menu
->flags
.buttoned
)
1540 * Will raise the passed menu, if submenu = 0
1541 * If submenu > 0 will also raise all mapped submenus
1542 * until the first buttoned one
1543 * If submenu < 0 will also raise all mapped parent menus
1544 * until the first buttoned one
1548 raiseMenus(WMenu
*menu
, int submenus
)
1555 wRaiseFrame(menu
->frame
->core
);
1557 if (submenus
>0 && menu
->selected_entry
>=0) {
1558 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1559 if (i
>=0 && menu
->cascades
) {
1560 submenu
= menu
->cascades
[i
];
1561 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1562 raiseMenus(submenu
, submenus
);
1565 if (submenus
<0 && !menu
->flags
.buttoned
&&
1566 menu
->parent
&& menu
->parent
->flags
.mapped
)
1567 raiseMenus(menu
->parent
, submenus
);
1572 wMenuUnderPointer(WScreen
*screen
)
1574 WObjDescriptor
*desc
;
1575 Window root_ret
, win
;
1579 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1580 &dummy
, &dummy
, &mask
);
1582 if (win
==None
) return NULL
;
1584 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1587 if (desc
->parent_type
== WCLASS_MENU
)
1588 return (WMenu
*)desc
->parent
;
1596 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1598 Window root_ret
, win
;
1602 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1607 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1609 WScreen
*scr
= menu
->menu
->screen_ptr
;
1610 int menuX1
= menu
->frame_x
;
1611 int menuY1
= menu
->frame_y
;
1612 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1613 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1614 int screenW
= scr
->scr_width
;
1615 int screenH
= scr
->scr_height
;
1621 getPointerPosition(scr
, &xroot
, &yroot
);
1624 if (xroot
<= 1 && menuX1
< 0) {
1625 /* scroll to the right */
1626 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1628 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1629 /* scroll to the left */
1630 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1635 *hamount
= -*hamount
;
1638 if (yroot
<= 1 && menuY1
< 0) {
1640 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1642 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1644 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1646 *vamount
= -*vamount
;
1652 dragScrollMenuCallback(void *data
)
1654 WMenu
*menu
= (WMenu
*)data
;
1655 WScreen
*scr
= menu
->menu
->screen_ptr
;
1656 WMenu
*parent
= parentMenu(menu
);
1657 int hamount
, vamount
;
1659 int newSelectedEntry
;
1661 getScrollAmount(menu
, &hamount
, &vamount
);
1664 if (hamount
!= 0 || vamount
!= 0) {
1665 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1666 parent
->frame_y
+ vamount
, True
);
1667 if (findMenu(scr
, &x
, &y
)) {
1668 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1669 selectEntry(menu
, newSelectedEntry
);
1671 /* Pointer fell outside of menu. If the selected entry is
1672 * not a submenu, unselect it */
1673 if (menu
->selected_entry
>= 0
1674 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1675 selectEntry(menu
, -1);
1676 newSelectedEntry
= 0;
1679 /* paranoid check */
1680 if (newSelectedEntry
>= 0) {
1681 /* keep scrolling */
1682 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1683 dragScrollMenuCallback
, menu
);
1688 /* don't need to scroll anymore */
1690 if (findMenu(scr
, &x
, &y
)) {
1691 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1692 selectEntry(menu
, newSelectedEntry
);
1699 scrollMenuCallback(void *data
)
1701 WMenu
*menu
= (WMenu
*)data
;
1702 WMenu
*parent
= parentMenu(menu
);
1703 int hamount
= 0; /* amount to scroll */
1706 #ifdef VIRTUAL_DESKTOP
1707 /* don't scroll if it is in vdesk mode */
1708 if (!wPreferences
.vedge_thickness
)
1710 getScrollAmount(menu
, &hamount
, &vamount
);
1712 if (hamount
!= 0 || vamount
!= 0) {
1713 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1714 parent
->frame_y
+ vamount
, True
);
1716 /* keep scrolling */
1717 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1718 scrollMenuCallback
, menu
);
1720 /* don't need to scroll anymore */
1727 #define MENU_SCROLL_BORDER 5
1730 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1732 int menuX1
= menu
->frame_x
;
1733 int menuY1
= menu
->frame_y
;
1734 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1735 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1736 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1737 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1740 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1741 || y
> scrYe
-MENU_SCROLL_BORDER
))
1743 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1744 || x
> scrXe
-MENU_SCROLL_BORDER
))
1751 typedef struct _delay
{
1759 _leaving(_delay
*dl
)
1761 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1762 dl
->menu
->jump_back
=NULL
;
1763 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1769 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1772 WMenu
*omenu
= parentMenu(menu
);
1773 WScreen
*scr
= menu
->frame
->screen_ptr
;
1776 int old_frame_x
= omenu
->frame_x
;
1777 int old_frame_y
= omenu
->frame_y
;
1780 if (omenu
->jump_back
)
1781 WMDeleteTimerWithClientData(omenu
->jump_back
);
1784 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1785 || omenu
->flags
.app_menu
) {
1789 if (!wPreferences
.wrap_menus
)
1790 raiseMenus(omenu
, True
);
1792 raiseMenus(menu
, False
);
1795 scrollMenuCallback(menu
);
1798 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1800 WMNextEvent(dpy
, &ev
);
1805 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1806 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1808 /* on_border is != 0 if the pointer is between the menu
1809 * and the screen border and is close enough to the border */
1810 on_border
= isPointNearBoder(menu
, x
, y
);
1812 smenu
= wMenuUnderPointer(scr
);
1814 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1819 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1820 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1821 on_border
= on_x_edge
|| on_y_edge
;
1823 if (!on_border
&& !jump_back
) {
1828 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1829 WMDeleteTimerHandler(menu
->timer
);
1837 scrollMenuCallback(menu
);
1840 /* True if we push on title, or drag the omenu to other position */
1841 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1842 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1843 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1844 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1846 smenu
= wMenuUnderPointer(scr
);
1847 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1849 else if (smenu
==omenu
&& on_title
) {
1863 WMDeleteTimerHandler(menu
->timer
);
1869 if (!omenu
->jump_back
) {
1870 delayer
=wmalloc(sizeof(_delay
));
1871 delayer
->menu
=omenu
;
1872 delayer
->ox
=old_frame_x
;
1873 delayer
->oy
=old_frame_y
;
1874 omenu
->jump_back
=delayer
;
1875 scr
->flags
.jump_back_pending
= 1;
1877 else delayer
= omenu
->jump_back
;
1878 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1885 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1887 wMenuPaint(desc
->parent
);
1891 int *delayed_select
;
1898 delaySelection(void *data
)
1900 delay_data
*d
= (delay_data
*)data
;
1906 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1907 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1908 entry_no
= getEntryAt(menu
, x
, y
);
1909 selectEntry(menu
, entry_no
);
1911 if (d
->delayed_select
)
1912 *(d
->delayed_select
) = 0;
1917 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1919 XButtonEvent
*bev
= &event
->xbutton
;
1920 WMenu
*menu
= desc
->parent
;
1922 WScreen
*scr
=menu
->frame
->screen_ptr
;
1923 WMenuEntry
*entry
=NULL
;
1925 int close_on_exit
=0;
1927 int delayed_select
= 0;
1931 int old_frame_x
= 0;
1932 int old_frame_y
= 0;
1933 delay_data d_data
= {NULL
, NULL
, NULL
};
1935 if (!wPreferences
.wrap_menus
) {
1936 smenu
= parentMenu(menu
);
1937 old_frame_x
= smenu
->frame_x
;
1938 old_frame_y
= smenu
->frame_y
;
1939 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1940 /* This is true if the menu was launched with right click on root window */
1942 d_data
.delayed_select
= &delayed_select
;
1944 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1945 delaySelection
, &d_data
);
1948 if (menu
->flags
.inside_handler
) {
1951 menu
->flags
.inside_handler
= 1;
1953 wRaiseFrame(menu
->frame
->core
);
1955 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1957 smenu
= findMenu(scr
, &x
, &y
);
1965 if (menu
->flags
.editing
) {
1968 entry_no
= getEntryAt(menu
, x
, y
);
1970 entry
= menu
->entries
[entry_no
];
1972 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1973 && entry
->flags
.editable
) {
1974 editEntry(smenu
, entry
);
1976 } else if (bev
->state
& ControlMask
) {
1980 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1981 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1983 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1984 menu
->selected_entry
!=entry_no
) {
1985 wMenuUnmap(submenu
);
1987 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1988 selectEntry(menu
, entry_no
);
1989 } else if (!submenu
->flags
.buttoned
) {
1990 selectEntry(menu
, -1);
1993 } else if (!delayed_select
) {
1994 selectEntry(menu
, entry_no
);
1997 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
1999 dragScrollMenuCallback(menu
);
2003 #ifdef VIRTUAL_DESKTOP
2004 if (wPreferences
.vedge_thickness
) {
2005 wWorkspaceLowerEdge(scr
);
2009 prevx
= bev
->x_root
;
2010 prevy
= bev
->y_root
;
2014 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2016 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2017 |ButtonPressMask
, &ev
);
2020 smenu
= findMenu(scr
, &x
, &y
);
2022 if (smenu
== NULL
) {
2023 /* moved mouse out of menu */
2025 if (!delayed_select
&& d_data
.magic
) {
2026 WMDeleteTimerHandler(d_data
.magic
);
2027 d_data
.magic
= NULL
;
2030 || (menu
->selected_entry
>=0
2031 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2032 prevx
= ev
.xmotion
.x_root
;
2033 prevy
= ev
.xmotion
.y_root
;
2037 selectEntry(menu
, -1);
2039 prevx
= ev
.xmotion
.x_root
;
2040 prevy
= ev
.xmotion
.y_root
;
2042 } else if (menu
&& menu
!=smenu
2043 && (menu
->selected_entry
<0
2044 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2045 selectEntry(menu
, -1);
2047 if (!delayed_select
&& d_data
.magic
) {
2048 WMDeleteTimerHandler(d_data
.magic
);
2049 d_data
.magic
= NULL
;
2053 /* hysteresis for item selection */
2055 /* check if the motion was to the side, indicating that
2056 * the user may want to cross to a submenu */
2057 if (!delayed_select
&& menu
) {
2059 Bool moved_to_submenu
;/* moved to direction of submenu */
2061 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2063 moved_to_submenu
= False
;
2064 if (dx
> 0 /* if moved enough to the side */
2065 /* maybe a open submenu */
2066 && menu
->selected_entry
>=0
2067 /* moving to the right direction */
2068 && (wPreferences
.align_menus
2069 || ev
.xmotion
.y_root
>= prevy
)) {
2072 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2074 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2075 if (prevx
< ev
.xmotion
.x_root
)
2076 moved_to_submenu
= True
;
2078 if (prevx
> ev
.xmotion
.x_root
)
2079 moved_to_submenu
= True
;
2085 if (menu
!= smenu
) {
2087 WMDeleteTimerHandler(d_data
.magic
);
2089 d_data
.magic
= NULL
;
2090 } else if (moved_to_submenu
) {
2091 /* while we are moving, postpone the selection */
2093 WMDeleteTimerHandler(d_data
.magic
);
2095 d_data
.delayed_select
= NULL
;
2097 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2100 prevx
= ev
.xmotion
.x_root
;
2101 prevy
= ev
.xmotion
.y_root
;
2105 WMDeleteTimerHandler(d_data
.magic
);
2106 d_data
.magic
= NULL
;
2110 prevx
= ev
.xmotion
.x_root
;
2111 prevy
= ev
.xmotion
.y_root
;
2113 /* pointer crossed menus */
2114 if (menu
&& menu
->timer
) {
2115 WMDeleteTimerHandler(menu
->timer
);
2119 dragScrollMenuCallback(smenu
);
2123 dragScrollMenuCallback(menu
);
2125 if (!delayed_select
) {
2126 entry_no
= getEntryAt(menu
, x
, y
);
2128 entry
= menu
->entries
[entry_no
];
2129 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2131 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2132 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2133 && menu
->selected_entry
!=entry_no
) {
2134 wMenuUnmap(submenu
);
2138 selectEntry(menu
, entry_no
);
2146 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2152 #ifdef VIRTUAL_DESKTOP
2153 /* since expose will raise edge up.. I need another ugly hack here */
2154 if (wPreferences
.vedge_thickness
) {
2155 wWorkspaceLowerEdge(scr
);
2162 if (menu
&& menu
->timer
) {
2163 WMDeleteTimerHandler(menu
->timer
);
2166 if (d_data
.magic
!=NULL
)
2167 WMDeleteTimerHandler(d_data
.magic
);
2169 if (menu
&& menu
->selected_entry
>=0) {
2170 entry
= menu
->entries
[menu
->selected_entry
];
2171 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2172 && entry
->cascade
< 0) {
2173 /* blink and erase menu selection */
2174 #if (MENU_BLINK_DELAY > 0)
2175 int sel
= menu
->selected_entry
;
2178 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2179 paintEntry(menu
, sel
, False
);
2181 wusleep(MENU_BLINK_DELAY
);
2182 paintEntry(menu
, sel
, True
);
2184 wusleep(MENU_BLINK_DELAY
);
2187 /* unmap the menu, it's parents and call the callback */
2188 if (!menu
->flags
.buttoned
&&
2189 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2192 selectEntry(menu
, -1);
2194 (*entry
->callback
)(menu
, entry
);
2196 /* If the user double clicks an entry, the entry will
2197 * be executed twice, which is not good for things like
2198 * the root menu. So, ignore any clicks that were generated
2199 * while the entry was being executed */
2200 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2202 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2203 selectEntry(menu
, -1);
2205 if (entry
->cascade
>=0 && menu
->cascades
2206 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2207 selectEntry(menu
, -1);
2212 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2213 closeCascade(desc
->parent
);
2215 /* close the cascade windows that should not remain opened */
2216 closeBrotherCascadesOf(desc
->parent
);
2218 if (!wPreferences
.wrap_menus
)
2219 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2222 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2223 #ifdef VIRTUAL_DESKTOP
2224 if (wPreferences
.vedge_thickness
) {
2225 wWorkspaceRaiseEdge(scr
);
2232 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2241 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2243 if (submenus
>0 && menu
->selected_entry
>=0) {
2244 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2246 if (i
>=0 && menu
->cascades
) {
2247 submenu
= menu
->cascades
[i
];
2248 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2249 if (wPreferences
.align_menus
) {
2250 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2252 wMenuMove(submenu
, x
+ MENUW(menu
),
2253 y
+ submenu
->entry_height
*menu
->selected_entry
,
2259 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2260 !menu
->parent
->flags
.buttoned
) {
2261 if (wPreferences
.align_menus
) {
2262 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2264 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2265 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2273 changeMenuLevels(WMenu
*menu
, int lower
)
2278 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2280 wRaiseFrame(menu
->frame
->core
);
2281 menu
->flags
.lowered
= 0;
2283 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2284 wLowerFrame(menu
->frame
->core
);
2285 menu
->flags
.lowered
= 1;
2287 for (i
=0; i
<menu
->cascade_no
; i
++) {
2288 if (menu
->cascades
[i
]
2289 && !menu
->cascades
[i
]->flags
.buttoned
2290 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2291 changeMenuLevels(menu
->cascades
[i
], lower
);
2299 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2304 if (event
->xbutton
.state
& MOD_MASK
) {
2305 if (menu
->flags
.lowered
) {
2310 changeMenuLevels(menu
, lower
);
2316 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2321 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2322 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2326 /* can't touch the menu copy */
2327 if (menu
->flags
.brother
)
2330 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2333 if (event
->xbutton
.state
& MOD_MASK
) {
2334 wLowerFrame(menu
->frame
->core
);
2337 wRaiseFrame(menu
->frame
->core
);
2342 /* lower/raise all submenus */
2344 if (tmp
->selected_entry
>=0 && tmp
->cascades
2345 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2346 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2347 if (!tmp
|| !tmp
->flags
.mapped
)
2350 wLowerFrame(tmp
->frame
->core
);
2352 wRaiseFrame(tmp
->frame
->core
);
2358 /* tear off the menu if it's a root menu or a cascade
2360 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2361 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2362 menu
->flags
.buttoned
=1;
2363 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2365 /* turn off selected menu entry in parent menu */
2366 selectEntry(menu
->parent
, -1);
2368 /* make parent map the copy in place of the original */
2369 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2370 if (menu
->parent
->cascades
[i
] == menu
) {
2371 menu
->parent
->cascades
[i
] = menu
->brother
;
2380 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2381 |ExposureMask
, &ev
);
2385 x
+= ev
.xmotion
.x_root
- dx
;
2386 y
+= ev
.xmotion
.y_root
- dy
;
2387 dx
= ev
.xmotion
.x_root
;
2388 dy
= ev
.xmotion
.y_root
;
2389 wMenuMove(menu
, x
, y
, True
);
2391 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2392 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2394 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2395 ButtonMotionMask
|ButtonReleaseMask
2397 GrabModeAsync
, GrabModeAsync
, None
,
2398 wCursor
[WCUR_MOVE
], CurrentTime
);
2407 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2409 XUngrabPointer(dpy
, CurrentTime
);
2420 *----------------------------------------------------------------------
2422 * Handles mouse click on the close button of menus. The menu is
2423 * closed when the button is clicked.
2426 * The closed menu is reinserted at it's parent menus
2428 *----------------------------------------------------------------------
2431 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2433 WMenu
*menu
= (WMenu
*)data
;
2434 WMenu
*parent
= menu
->parent
;
2438 for (i
=0; i
<parent
->cascade_no
; i
++) {
2439 /* find the entry that points to the copy */
2440 if (parent
->cascades
[i
] == menu
->brother
) {
2441 /* make it point to the original */
2442 parent
->cascades
[i
] = menu
;
2443 menu
->parent
= parent
;
2453 saveMenuInfo(WMPropList
*dict
, WMenu
*menu
, WMPropList
*key
)
2455 WMPropList
*value
, *list
;
2458 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2459 value
= WMCreatePLString(buffer
);
2460 list
= WMCreatePLArray(value
, NULL
);
2461 if (menu
->flags
.lowered
)
2462 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2463 WMPutInPLDictionary(dict
, key
, list
);
2464 WMReleasePropList(value
);
2465 WMReleasePropList(list
);
2470 wMenuSaveState(WScreen
*scr
)
2472 WMPropList
*menus
, *key
;
2475 menus
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
2478 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2479 key
= WMCreatePLString("SwitchMenu");
2480 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2481 WMReleasePropList(key
);
2485 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2489 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2490 key
= WMCreatePLString("WorkspaceMenu");
2491 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2492 WMReleasePropList(key
);
2497 key
= WMCreatePLString("Menus");
2498 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2499 WMReleasePropList(key
);
2501 WMReleasePropList(menus
);
2508 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2513 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2516 len
= strlen(menu
->frame
->title
);
2521 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2526 strcat(buffer
, "\\");
2527 strcat(buffer
, menu
->frame
->title
);
2534 saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
)
2537 int save_menus
= 0, i
;
2542 if (menu
->flags
.brother
)
2543 menu
= menu
->brother
;
2545 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2548 ok
= getMenuPath(menu
, buffer
, 510);
2551 key
= WMCreatePLString(buffer
);
2552 saveMenuInfo(menus
, menu
, key
);
2553 WMReleasePropList(key
);
2559 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2560 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2569 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2573 getMenuInfo(WMPropList
*info
, int *x
, int *y
, Bool
*lowered
)
2579 if (WMIsPLArray(info
)) {
2581 pos
= WMGetFromPLArray(info
, 0);
2582 flags
= WMGetFromPLArray(info
, 1);
2583 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2584 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2591 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2592 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
)!=2)
2593 COMPLAIN("Position");
2595 COMPLAIN("(position, flags...)");
2604 restoreMenu(WScreen
*scr
, WMPropList
*menu
, int which
)
2607 Bool lowered
= False
;
2608 WMenu
*pmenu
= NULL
;
2613 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2618 if (which
& WSS_SWITCHMENU
) {
2619 OpenSwitchMenu(scr
, x
, y
, False
);
2620 pmenu
= scr
->switch_menu
;
2625 int width
= MENUW(pmenu
);
2626 int height
= MENUH(pmenu
);
2629 changeMenuLevels(pmenu
, True
);
2632 x
= (x
< -width
) ? 0 : x
;
2633 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2634 y
= (y
< 0) ? 0 : y
;
2635 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2636 wMenuMove(pmenu
, x
, y
, True
);
2637 pmenu
->flags
.buttoned
= 1;
2638 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2647 restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
)
2649 WMPropList
*key
, *entry
;
2654 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2657 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2658 key
= WMCreatePLString(buffer
);
2659 entry
= WMGetFromPLDictionary(menus
, key
);
2662 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2664 if (!menu
->flags
.mapped
) {
2665 int width
= MENUW(menu
);
2666 int height
= MENUH(menu
);
2668 wMenuMapAt(menu
, x
, y
, False
);
2671 /* make parent map the copy in place of the original */
2672 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2673 if (menu
->parent
->cascades
[i
] == menu
) {
2674 menu
->parent
->cascades
[i
] = menu
->brother
;
2680 changeMenuLevels(menu
, True
);
2682 x
= (x
< -width
) ? 0 : x
;
2683 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2684 y
= (y
< 0) ? 0 : y
;
2685 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2686 wMenuMove(menu
, x
, y
, True
);
2687 menu
->flags
.buttoned
= 1;
2688 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2693 WMReleasePropList(key
);
2695 for (i
=0; i
<menu
->cascade_no
; i
++) {
2696 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2706 wMenuRestoreState(WScreen
*scr
)
2708 WMPropList
*menus
, *menu
, *key
, *skey
;
2710 key
= WMCreatePLString("Menus");
2711 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2712 WMReleasePropList(key
);
2719 skey
= WMCreatePLString("SwitchMenu");
2720 menu
= WMGetFromPLDictionary(menus
, skey
);
2721 WMReleasePropList(skey
);
2722 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2725 if (!scr
->root_menu
) {
2726 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2727 wMenuUnmap(scr
->root_menu
);
2729 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2735 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2737 WMenu
*menu
, *parent
;
2741 if (!scr
->root_menu
) {
2742 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2743 wMenuUnmap(scr
->root_menu
);
2746 menu
= scr
->workspace_menu
;
2748 if (menu
->flags
.mapped
) {
2749 if (!menu
->flags
.buttoned
) {
2751 parent
= menu
->parent
;
2752 if (parent
&& parent
->selected_entry
>= 0) {
2753 entry
= parent
->entries
[parent
->selected_entry
];
2754 if (parent
->cascades
[entry
->cascade
] == menu
) {
2755 selectEntry(parent
, -1);
2756 wMenuMapAt(menu
, x
, y
, False
);
2760 wRaiseFrame(menu
->frame
->core
);
2761 wMenuMapCopyAt(menu
, x
, y
);
2764 wMenuMapAt(menu
, x
, y
, False
);