1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 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_color
,
177 &screen
->menu_title_font
);
179 menu
->frame
->core
->descriptor
.parent
= menu
;
180 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
181 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
183 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
186 menu
->frame
->title
= wstrdup(title
);
189 menu
->frame
->flags
.justification
= WTJ_LEFT
;
191 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
194 menu
->alloced_entries
= 0;
195 menu
->selected_entry
= -1;
196 menu
->entries
= NULL
;
198 menu
->frame_x
= screen
->app_menu_x
;
199 menu
->frame_y
= screen
->app_menu_y
;
201 menu
->frame
->child
= menu
;
203 menu
->flags
.lowered
= 0;
207 /* setup object descriptors */
208 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
209 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
212 menu
->frame
->on_click_right
= menuCloseClick
;
215 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
216 menu
->frame
->core
->width
, 10);
218 menu
->menu
->descriptor
.parent
= menu
;
219 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
220 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
221 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
223 menu
->menu_texture_data
= None
;
225 XMapWindow(dpy
, menu
->menu
->window
);
231 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
233 menu
->brother
->flags
.brother
= 1;
234 menu
->brother
->brother
= menu
;
236 WMAddNotificationObserver(appearanceObserver
, menu
,
237 WNMenuAppearanceSettingsChanged
, menu
);
239 WMAddNotificationObserver(appearanceObserver
, menu
,
240 WNMenuTitleAppearanceSettingsChanged
, menu
);
250 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
254 menu
= wMenuCreate(screen
, title
, main_menu
);
257 menu
->flags
.app_menu
= 1;
258 menu
->brother
->flags
.app_menu
= 1;
266 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
270 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
271 menu
->entries
[i
]->order
++;
272 menu
->entries
[i
+1] = menu
->entries
[i
];
274 menu
->entries
[index
] = entry
;
279 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
280 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
285 menu
->flags
.realized
= 0;
286 menu
->brother
->flags
.realized
= 0;
288 /* reallocate array if it's too small */
289 if (menu
->entry_no
>= menu
->alloced_entries
) {
292 tmp
= wrealloc(menu
->entries
,
293 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
296 menu
->alloced_entries
+= 5;
298 menu
->brother
->entries
= tmp
;
299 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
301 entry
= wmalloc(sizeof(WMenuEntry
));
302 memset(entry
, 0, sizeof(WMenuEntry
));
303 entry
->flags
.enabled
= 1;
304 entry
->text
= wstrdup(text
);
306 entry
->clientdata
= clientdata
;
307 entry
->callback
= callback
;
308 if (index
<0 || index
>=menu
->entry_no
) {
309 entry
->order
= menu
->entry_no
;
310 menu
->entries
[menu
->entry_no
] = entry
;
312 entry
->order
= index
;
313 insertEntry(menu
, entry
, index
);
317 menu
->brother
->entry_no
= menu
->entry_no
;
325 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
327 WMenu
*brother
= menu
->brother
;
330 assert(menu
->flags
.brother
==0);
332 if (entry
->cascade
>=0) {
333 menu
->flags
.realized
= 0;
334 brother
->flags
.realized
= 0;
337 cascade
->parent
= menu
;
339 cascade
->brother
->parent
= brother
;
342 for (i
=0; i
<menu
->cascade_no
; i
++) {
343 if (menu
->cascades
[i
]==NULL
) {
344 menu
->cascades
[i
] = cascade
;
345 brother
->cascades
[i
] = cascade
->brother
;
352 entry
->cascade
= menu
->cascade_no
;
354 menu
->cascades
= wrealloc(menu
->cascades
,
355 sizeof(WMenu
)*(menu
->cascade_no
+1));
356 menu
->cascades
[menu
->cascade_no
++] = cascade
;
359 brother
->cascades
= wrealloc(brother
->cascades
,
360 sizeof(WMenu
)*(brother
->cascade_no
+1));
361 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
365 if (menu
->flags
.lowered
) {
367 cascade
->flags
.lowered
= 1;
368 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
370 cascade
->brother
->flags
.lowered
= 1;
371 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
374 if (!menu
->flags
.realized
)
380 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
382 assert(menu
->flags
.brother
==0);
384 /* destroy cascade menu */
385 if (entry
->cascade
>=0 && menu
->cascades
386 && menu
->cascades
[entry
->cascade
]!=NULL
) {
388 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
390 menu
->cascades
[entry
->cascade
] = NULL
;
391 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
399 wMenuRemoveItem(WMenu
*menu
, int index
)
403 if (menu
->flags
.brother
) {
404 wMenuRemoveItem(menu
->brother
, index
);
408 if (index
>=menu
->entry_no
) return;
410 /* destroy cascade menu */
411 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
413 /* destroy unshared data */
415 if (menu
->entries
[index
]->text
)
416 wfree(menu
->entries
[index
]->text
);
418 if (menu
->entries
[index
]->rtext
)
419 wfree(menu
->entries
[index
]->rtext
);
421 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
422 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
424 wfree(menu
->entries
[index
]);
426 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
427 menu
->entries
[i
+1]->order
--;
428 menu
->entries
[i
]=menu
->entries
[i
+1];
431 menu
->brother
->entry_no
--;
436 renderTexture(WMenu
*menu
)
444 WScreen
*scr
= menu
->menu
->screen_ptr
;
445 WTexture
*texture
= scr
->menu_item_texture
;
447 if (wPreferences
.menu_style
== MS_NORMAL
) {
448 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
449 menu
->entry_height
, WREL_MENUENTRY
);
451 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
452 menu
->menu
->height
+1, WREL_MENUENTRY
);
455 wwarning(_("could not render texture: %s"),
456 RMessageForError(RErrorCode
));
461 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
463 light
.red
= light
.green
= light
.blue
= 80;
466 dark
.red
= dark
.green
= dark
.blue
= 0;
469 mid
.red
= mid
.green
= mid
.blue
= 40;
471 for (i
= 1; i
< menu
->entry_no
; i
++) {
472 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
473 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
475 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
476 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
478 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
479 menu
->menu
->width
-1, i
*menu
->entry_height
,
483 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
484 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
493 updateTexture(WMenu
*menu
)
495 WScreen
*scr
= menu
->menu
->screen_ptr
;
497 /* setup background texture */
498 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
499 if (!menu
->flags
.brother
) {
500 FREE_PIXMAP(menu
->menu_texture_data
);
502 menu
->menu_texture_data
= renderTexture(menu
);
504 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
505 menu
->menu_texture_data
);
506 XClearWindow(dpy
, menu
->menu
->window
);
508 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
509 menu
->menu_texture_data
);
510 XClearWindow(dpy
, menu
->brother
->menu
->window
);
513 XSetWindowBackground(dpy
, menu
->menu
->window
,
514 scr
->menu_item_texture
->any
.color
.pixel
);
515 XClearWindow(dpy
, menu
->menu
->window
);
521 wMenuRealize(WMenu
*menu
)
524 int width
, rwidth
, mrwidth
, mwidth
;
525 int theight
, twidth
, eheight
;
526 WScreen
*scr
= menu
->frame
->screen_ptr
;
527 static int brother_done
=0;
532 wMenuRealize(menu
->brother
);
536 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
537 if (menu
->flags
.titled
)
538 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
540 wFrameWindowUpdateBorders(menu
->frame
, flags
);
542 if (menu
->flags
.titled
) {
543 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
544 strlen(menu
->frame
->title
));
545 theight
= menu
->frame
->top_width
;
546 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
551 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
552 menu
->entry_height
= eheight
;
555 for (i
=0; i
<menu
->entry_no
; i
++) {
558 /* search widest text */
559 text
= menu
->entries
[i
]->text
;
560 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
562 if (menu
->entries
[i
]->flags
.indicator
) {
563 width
+= MENU_INDICATOR_SPACE
;
569 /* search widest text on right */
570 text
= menu
->entries
[i
]->rtext
;
572 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
574 else if (menu
->entries
[i
]->cascade
>=0)
579 if (rwidth
> mrwidth
)
588 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
590 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
591 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
596 menu
->flags
.realized
= 1;
598 if (menu
->flags
.mapped
)
600 if (menu
->brother
->flags
.mapped
)
601 wMenuPaint(menu
->brother
);
606 wMenuDestroy(WMenu
*menu
, int recurse
)
610 WMRemoveNotificationObserver(menu
);
612 /* remove any pending timers */
614 WMDeleteTimerHandler(menu
->timer
);
617 /* call destroy handler */
618 if (menu
->on_destroy
)
619 (*menu
->on_destroy
)(menu
);
621 /* Destroy items if this menu own them. If this is the "brother" menu,
622 * leave them alone as it is shared by them.
624 if (!menu
->flags
.brother
) {
625 for (i
=0; i
<menu
->entry_no
; i
++) {
627 wfree(menu
->entries
[i
]->text
);
629 if (menu
->entries
[i
]->rtext
)
630 wfree(menu
->entries
[i
]->rtext
);
633 if (menu
->entries
[i
]->instances
){
634 WMReleasePropList(menu
->entries
[i
]->instances
);
636 #endif /* USER_MENU */
638 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
639 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
641 wfree(menu
->entries
[i
]);
645 for (i
=0; i
<menu
->cascade_no
; i
++) {
646 if (menu
->cascades
[i
]) {
647 if (menu
->cascades
[i
]->flags
.brother
)
648 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
650 wMenuDestroy(menu
->cascades
[i
], recurse
);
656 wfree(menu
->entries
);
660 FREE_PIXMAP(menu
->menu_texture_data
);
663 wfree(menu
->cascades
);
665 wCoreDestroy(menu
->menu
);
666 wFrameWindowDestroy(menu
->frame
);
668 /* destroy copy of this menu */
669 if (!menu
->flags
.brother
&& menu
->brother
)
670 wMenuDestroy(menu
->brother
, False
);
682 drawFrame(WScreen
*scr
, Drawable win
, int y
, int w
, int h
, int type
)
688 segs
[i
].x1
= segs
[i
].x2
= w
-1;
690 segs
[i
].y2
= y
+ h
- 1;
692 if (type
!= F_TOP
&& type
!= F_NONE
) {
694 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
698 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
704 segs
[i
].y2
= y
+ h
- 1;
706 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
713 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
715 if (type
!= F_TOP
&& type
!= F_NONE
)
716 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
722 paintEntry(WMenu
*menu
, int index
, int selected
)
724 WScreen
*scr
=menu
->frame
->screen_ptr
;
725 Window win
= menu
->menu
->window
;
726 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 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+1, w
-2, h
-3);
755 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
756 drawFrame(scr
, win
, y
, w
, h
, type
);
758 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
759 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
761 drawFrame(scr
, win
, y
, w
, h
, type
);
763 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
768 if (entry
->flags
.enabled
)
769 color
= scr
->select_text_color
;
771 color
= scr
->dtext_color
;
772 } else if (!entry
->flags
.enabled
) {
773 color
= scr
->dtext_color
;
775 color
= scr
->mtext_color
;
779 if (entry
->flags
.indicator
)
780 x
+= MENU_INDICATOR_SPACE
+ 2;
782 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
783 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
785 if (entry
->cascade
>=0) {
786 /* draw the cascade indicator */
787 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
788 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
789 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
793 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
798 switch (entry
->flags
.indicator_type
) {
800 indicator
= scr
->menu_check_indicator
;
803 indicator
= scr
->menu_mini_indicator
;
806 indicator
= scr
->menu_hide_indicator
;
809 indicator
= scr
->menu_shade_indicator
;
813 indicator
= scr
->menu_radio_indicator
;
817 iw
= indicator
->width
;
818 ih
= indicator
->height
;
819 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
820 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
822 if (entry
->flags
.enabled
) {
823 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
825 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
828 if (entry
->flags
.enabled
) {
829 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
831 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
834 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
836 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
837 iw, ih, 5, y+(h-ih)/2);
839 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
842 /* draw right text */
844 if (entry
->rtext
&& entry
->cascade
<0) {
845 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
846 strlen(entry
->rtext
));
848 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
-6-tw
,
849 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
855 move_menus(WMenu
*menu
, int x
, int y
)
857 while (menu
->parent
) {
860 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
861 y
-= menu
->selected_entry
*menu
->entry_height
;
864 wMenuMove(menu
, x
, y
, True
);
868 makeVisible(WMenu
*menu
)
870 WScreen
*scr
= menu
->frame
->screen_ptr
;
871 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
873 if (menu
->entry_no
<0) return;
876 y1
= menu
->frame_y
+menu
->frame
->top_width
877 + menu
->selected_entry
*menu
->entry_height
;
878 x2
= x1
+ MENUW(menu
);
879 y2
= y1
+ menu
->entry_height
;
888 } else if (x2
>= scr
->scr_width
) {
889 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
896 } else if (y2
>= scr
->scr_height
) {
897 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
901 new_y
= new_y
- menu
->frame
->top_width
902 - menu
->selected_entry
*menu
->entry_height
;
903 move_menus(menu
, new_x
, new_y
);
908 check_key(WMenu
*menu
, XKeyEvent
*event
)
913 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
916 ch
= toupper(buffer
[0]);
918 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
921 for (i
=s
; i
<menu
->entry_no
; i
++) {
922 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
926 /* no match. Retry from start, if previous started from a selected entry */
936 keyboardMenu(WMenu
*menu
)
939 KeySym ksym
=NoSymbol
;
943 int old_pos_x
= menu
->frame_x
;
944 int old_pos_y
= menu
->frame_y
;
945 int new_x
= old_pos_x
, new_y
= old_pos_y
;
946 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
947 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
949 if (menu
->flags
.editing
)
953 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
954 GrabModeAsync
, CurrentTime
);
956 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
957 new_y
= scr_height
- menu
->frame
->top_width
;
959 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
960 new_x
= scr_width
-MENUW(menu
)-1;
962 move_menus(menu
, new_x
, new_y
);
964 while (!done
&& menu
->flags
.mapped
) {
965 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
966 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
967 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
968 |SubstructureNotifyMask
, &event
);
970 switch (event
.type
) {
972 ksym
= XLookupKeysym(&event
.xkey
, 0);
982 selectEntry(menu
, 0);
990 selectEntry(menu
, menu
->entry_no
-1);
1001 if (menu
->selected_entry
<= 0)
1002 selectEntry(menu
, menu
->entry_no
-1);
1004 selectEntry(menu
, menu
->selected_entry
-1);
1009 #ifdef ARROWLESS_KBD
1015 if (menu
->selected_entry
<0)
1016 selectEntry(menu
, 0);
1017 else if (menu
->selected_entry
== menu
->entry_no
-1)
1018 selectEntry(menu
, 0);
1019 else if (menu
->selected_entry
< menu
->entry_no
-1)
1020 selectEntry(menu
, menu
->selected_entry
+1);
1025 #ifdef ARROWLESS_KBD
1031 if (menu
->selected_entry
>=0) {
1033 entry
= menu
->entries
[menu
->selected_entry
];
1035 if (entry
->cascade
>= 0 && menu
->cascades
1036 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1038 XUngrabKeyboard(dpy
, CurrentTime
);
1040 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1041 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1044 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1045 GrabModeAsync
, GrabModeAsync
,
1052 #ifdef ARROWLESS_KBD
1058 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1059 selectEntry(menu
, -1);
1060 move_menus(menu
, old_pos_x
, old_pos_y
);
1070 index
= check_key(menu
, &event
.xkey
);
1072 selectEntry(menu
, index
);
1078 if (event
.type
==ButtonPress
)
1081 WMHandleEvent(&event
);
1085 XUngrabKeyboard(dpy
, CurrentTime
);
1087 if (done
==2 && menu
->selected_entry
>=0) {
1088 entry
= menu
->entries
[menu
->selected_entry
];
1093 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1094 && entry
->cascade
< 0) {
1095 #if (MENU_BLINK_COUNT > 0)
1096 int sel
= menu
->selected_entry
;
1099 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1100 paintEntry(menu
, sel
, False
);
1102 wusleep(MENU_BLINK_DELAY
);
1103 paintEntry(menu
, sel
, True
);
1105 wusleep(MENU_BLINK_DELAY
);
1108 selectEntry(menu
, -1);
1110 if (!menu
->flags
.buttoned
) {
1112 move_menus(menu
, old_pos_x
, old_pos_y
);
1116 (*entry
->callback
)(menu
, entry
);
1118 if (!menu
->flags
.buttoned
) {
1120 move_menus(menu
, old_pos_x
, old_pos_y
);
1122 selectEntry(menu
, -1);
1126 /* returns True if returning from a submenu to a parent menu,
1127 * False if exiting from menu */
1133 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1135 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1136 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1138 if (!menu
->flags
.realized
) {
1139 menu
->flags
.realized
=1;
1142 if (!menu
->flags
.mapped
) {
1143 if (wPreferences
.wrap_menus
) {
1146 if (x
+MENUW(menu
) > scr_width
)
1147 x
= scr_width
- MENUW(menu
);
1148 if (y
+MENUH(menu
) > scr_height
)
1149 y
= scr_height
- MENUH(menu
);
1152 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1155 XMapWindow(dpy
, menu
->frame
->core
->window
);
1156 wRaiseFrame(menu
->frame
->core
);
1157 menu
->flags
.mapped
= 1;
1159 selectEntry(menu
, 0);
1168 wMenuMap(WMenu
*menu
)
1170 if (!menu
->flags
.realized
) {
1171 menu
->flags
.realized
=1;
1174 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1175 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1176 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1177 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1179 XMapWindow(dpy
, menu
->frame
->core
->window
);
1180 wRaiseFrame(menu
->frame
->core
);
1181 menu
->flags
.mapped
= 1;
1186 wMenuUnmap(WMenu
*menu
)
1190 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1191 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1192 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1194 menu
->flags
.buttoned
= 0;
1195 menu
->flags
.mapped
= 0;
1196 menu
->flags
.open_to_left
= 0;
1198 for (i
=0; i
<menu
->cascade_no
; i
++) {
1199 if (menu
->cascades
[i
]!=NULL
1200 && menu
->cascades
[i
]->flags
.mapped
1201 && !menu
->cascades
[i
]->flags
.buttoned
) {
1203 wMenuUnmap(menu
->cascades
[i
]);
1206 menu
->selected_entry
= -1;
1212 wMenuPaint(WMenu
*menu
)
1216 if (!menu
->flags
.mapped
) {
1221 for (i
=0; i
<menu
->entry_no
; i
++) {
1222 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1228 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1230 if (index
>=menu
->entry_no
) return;
1231 menu
->entries
[index
]->flags
.enabled
=enable
;
1232 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1233 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1237 /* ====================================================================== */
1241 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1245 WObjDescriptor
*desc
;
1251 menu
->flags
.editing
= 1;
1253 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1254 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1256 wTextPutText(text
, entry
->text
);
1257 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1258 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1260 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1261 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1262 wwarning(_("could not grab keyboard"));
1265 wSetFocusTo(menu
->frame
->screen_ptr
,
1266 menu
->frame
->screen_ptr
->focused_window
);
1271 while (!done
&& !text
->done
) {
1273 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1275 WMNextEvent(dpy
, &event
);
1277 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1278 (XPointer
*)&desc
)==XCNOENT
)
1281 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1283 (*desc
->handle_anything
)(desc
, &event
);
1286 switch (event
.type
) {
1288 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1292 WMHandleEvent(&event
);
1298 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1300 wSetFocusTo(menu
->frame
->screen_ptr
,
1301 menu
->frame
->screen_ptr
->focused_window
);
1304 t
= wTextGetText(text
);
1305 /* if !t, the user has canceled editing */
1309 entry
->text
= wstrdup(t
);
1311 menu
->flags
.realized
= 0;
1315 XUngrabKeyboard(dpy
, CurrentTime
);
1317 if (t
&& menu
->on_edit
)
1318 (*menu
->on_edit
)(menu
, entry
);
1320 menu
->flags
.editing
= 0;
1322 if (!menu
->flags
.realized
)
1328 selectEntry(WMenu
*menu
, int entry_no
)
1334 if (menu
->entries
==NULL
)
1337 if (entry_no
>= menu
->entry_no
)
1340 old_entry
= menu
->selected_entry
;
1341 menu
->selected_entry
= entry_no
;
1343 if (old_entry
!=entry_no
) {
1345 /* unselect previous entry */
1347 paintEntry(menu
, old_entry
, False
);
1348 entry
= menu
->entries
[old_entry
];
1351 if (entry
->cascade
>=0 && menu
->cascades
) {
1352 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1353 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1359 menu
->selected_entry
= -1;
1362 entry
= menu
->entries
[entry_no
];
1364 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1365 /* Callback for when the submenu is opened.
1367 submenu
= menu
->cascades
[entry
->cascade
];
1368 if (submenu
&& submenu
->flags
.brother
)
1369 submenu
= submenu
->brother
;
1371 if (entry
->callback
) {
1372 /* Only call the callback if the submenu is not yet mapped.
1374 if (menu
->flags
.brother
) {
1375 if (!submenu
|| !submenu
->flags
.mapped
)
1376 (*entry
->callback
)(menu
->brother
, entry
);
1378 if (!submenu
|| !submenu
->flags
.buttoned
)
1379 (*entry
->callback
)(menu
, entry
);
1383 /* the submenu menu might have changed */
1384 submenu
= menu
->cascades
[entry
->cascade
];
1387 if (!submenu
->flags
.mapped
) {
1390 if (!submenu
->flags
.realized
)
1391 wMenuRealize(submenu
);
1392 if (wPreferences
.wrap_menus
) {
1393 if (menu
->flags
.open_to_left
)
1394 submenu
->flags
.open_to_left
= 1;
1396 if (submenu
->flags
.open_to_left
) {
1397 x
= menu
->frame_x
- MENUW(submenu
);
1400 submenu
->flags
.open_to_left
= 0;
1403 x
= menu
->frame_x
+ MENUW(menu
);
1405 if (x
+ MENUW(submenu
)
1406 >= menu
->frame
->screen_ptr
->scr_width
) {
1408 x
= menu
->frame_x
- MENUW(submenu
);
1409 submenu
->flags
.open_to_left
= 1;
1413 x
= menu
->frame_x
+ MENUW(menu
);
1416 if (wPreferences
.align_menus
) {
1419 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1420 if (menu
->flags
.titled
)
1421 y
+= menu
->frame
->top_width
;
1422 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1423 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1426 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1427 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1432 paintEntry(menu
, entry_no
, True
);
1438 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1441 WObjDescriptor
*desc
;
1442 Window root_ret
, win
, junk_win
;
1446 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1449 if (win
==None
) return NULL
;
1451 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1454 if (desc
->parent_type
== WCLASS_MENU
) {
1455 menu
= (WMenu
*)desc
->parent
;
1456 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1457 x_ret
, y_ret
, &junk_win
);
1467 closeCascade(WMenu
*menu
)
1469 WMenu
*parent
=menu
->parent
;
1471 if (menu
->flags
.brother
1472 || (!menu
->flags
.buttoned
1473 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1475 selectEntry(menu
, -1);
1477 #if (MENU_BLINK_DELAY > 2)
1478 wusleep(MENU_BLINK_DELAY
/2);
1482 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1483 || parent
->flags
.brother
)
1484 && !parent
->flags
.buttoned
) {
1485 selectEntry(parent
, -1);
1487 parent
= parent
->parent
;
1490 selectEntry(parent
, -1);
1496 closeBrotherCascadesOf(WMenu
*menu
)
1501 for (i
=0; i
<menu
->cascade_no
; i
++) {
1502 if (menu
->cascades
[i
]->flags
.brother
) {
1503 tmp
= menu
->cascades
[i
];
1505 tmp
= menu
->cascades
[i
]->brother
;
1507 if (tmp
->flags
.mapped
) {
1508 selectEntry(tmp
->parent
, -1);
1509 closeBrotherCascadesOf(tmp
);
1516 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1520 parentMenu(WMenu
*menu
)
1525 if (menu
->flags
.buttoned
)
1528 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1529 parent
= menu
->parent
;
1530 if (parent
->selected_entry
< 0)
1532 entry
= parent
->entries
[parent
->selected_entry
];
1533 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1534 parent
->cascades
[entry
->cascade
] != menu
)
1537 if (menu
->flags
.buttoned
)
1547 * Will raise the passed menu, if submenu = 0
1548 * If submenu > 0 will also raise all mapped submenus
1549 * until the first buttoned one
1550 * If submenu < 0 will also raise all mapped parent menus
1551 * until the first buttoned one
1555 raiseMenus(WMenu
*menu
, int submenus
)
1562 wRaiseFrame(menu
->frame
->core
);
1564 if (submenus
>0 && menu
->selected_entry
>=0) {
1565 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1566 if (i
>=0 && menu
->cascades
) {
1567 submenu
= menu
->cascades
[i
];
1568 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1569 raiseMenus(submenu
, submenus
);
1572 if (submenus
<0 && !menu
->flags
.buttoned
&&
1573 menu
->parent
&& menu
->parent
->flags
.mapped
)
1574 raiseMenus(menu
->parent
, submenus
);
1579 wMenuUnderPointer(WScreen
*screen
)
1581 WObjDescriptor
*desc
;
1582 Window root_ret
, win
;
1586 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1587 &dummy
, &dummy
, &mask
);
1589 if (win
==None
) return NULL
;
1591 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1594 if (desc
->parent_type
== WCLASS_MENU
)
1595 return (WMenu
*)desc
->parent
;
1603 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1605 Window root_ret
, win
;
1609 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1614 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1616 WScreen
*scr
= menu
->menu
->screen_ptr
;
1617 int menuX1
= menu
->frame_x
;
1618 int menuY1
= menu
->frame_y
;
1619 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1620 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1621 int screenW
= scr
->scr_width
;
1622 int screenH
= scr
->scr_height
;
1628 getPointerPosition(scr
, &xroot
, &yroot
);
1631 if (xroot
<= 1 && menuX1
< 0) {
1632 /* scroll to the right */
1633 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1635 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1636 /* scroll to the left */
1637 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1642 *hamount
= -*hamount
;
1645 if (yroot
<= 1 && menuY1
< 0) {
1647 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1649 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1651 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1653 *vamount
= -*vamount
;
1659 dragScrollMenuCallback(void *data
)
1661 WMenu
*menu
= (WMenu
*)data
;
1662 WScreen
*scr
= menu
->menu
->screen_ptr
;
1663 WMenu
*parent
= parentMenu(menu
);
1664 int hamount
, vamount
;
1666 int newSelectedEntry
;
1668 getScrollAmount(menu
, &hamount
, &vamount
);
1671 if (hamount
!= 0 || vamount
!= 0) {
1672 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1673 parent
->frame_y
+ vamount
, True
);
1674 if (findMenu(scr
, &x
, &y
)) {
1675 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1676 selectEntry(menu
, newSelectedEntry
);
1678 /* Pointer fell outside of menu. If the selected entry is
1679 * not a submenu, unselect it */
1680 if (menu
->selected_entry
>= 0
1681 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1682 selectEntry(menu
, -1);
1683 newSelectedEntry
= 0;
1686 /* paranoid check */
1687 if (newSelectedEntry
>= 0) {
1688 /* keep scrolling */
1689 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1690 dragScrollMenuCallback
, menu
);
1695 /* don't need to scroll anymore */
1697 if (findMenu(scr
, &x
, &y
)) {
1698 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1699 selectEntry(menu
, newSelectedEntry
);
1706 scrollMenuCallback(void *data
)
1708 WMenu
*menu
= (WMenu
*)data
;
1709 WMenu
*parent
= parentMenu(menu
);
1710 int hamount
= 0; /* amount to scroll */
1713 #ifdef VIRTUAL_DESKTOP
1714 /* don't scroll if it is in vdesk mode */
1715 if (!wPreferences
.vedge_thickness
)
1717 getScrollAmount(menu
, &hamount
, &vamount
);
1719 if (hamount
!= 0 || vamount
!= 0) {
1720 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1721 parent
->frame_y
+ vamount
, True
);
1723 /* keep scrolling */
1724 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1725 scrollMenuCallback
, menu
);
1727 /* don't need to scroll anymore */
1734 #define MENU_SCROLL_BORDER 5
1737 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1739 int menuX1
= menu
->frame_x
;
1740 int menuY1
= menu
->frame_y
;
1741 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1742 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1743 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1744 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1747 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1748 || y
> scrYe
-MENU_SCROLL_BORDER
))
1750 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1751 || x
> scrXe
-MENU_SCROLL_BORDER
))
1758 typedef struct _delay
{
1766 _leaving(_delay
*dl
)
1768 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1769 dl
->menu
->jump_back
=NULL
;
1770 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1776 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1779 WMenu
*omenu
= parentMenu(menu
);
1780 WScreen
*scr
= menu
->frame
->screen_ptr
;
1783 int old_frame_x
= omenu
->frame_x
;
1784 int old_frame_y
= omenu
->frame_y
;
1787 if (omenu
->jump_back
)
1788 WMDeleteTimerWithClientData(omenu
->jump_back
);
1791 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1792 || omenu
->flags
.app_menu
) {
1796 if (!wPreferences
.wrap_menus
)
1797 raiseMenus(omenu
, True
);
1799 raiseMenus(menu
, False
);
1802 scrollMenuCallback(menu
);
1805 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1807 WMNextEvent(dpy
, &ev
);
1812 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1813 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1815 /* on_border is != 0 if the pointer is between the menu
1816 * and the screen border and is close enough to the border */
1817 on_border
= isPointNearBoder(menu
, x
, y
);
1819 smenu
= wMenuUnderPointer(scr
);
1821 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1826 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1827 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1828 on_border
= on_x_edge
|| on_y_edge
;
1830 if (!on_border
&& !jump_back
) {
1835 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1836 WMDeleteTimerHandler(menu
->timer
);
1844 scrollMenuCallback(menu
);
1847 /* True if we push on title, or drag the omenu to other position */
1848 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1849 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1850 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1851 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1853 smenu
= wMenuUnderPointer(scr
);
1854 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1856 else if (smenu
==omenu
&& on_title
) {
1870 WMDeleteTimerHandler(menu
->timer
);
1876 if (!omenu
->jump_back
) {
1877 delayer
=wmalloc(sizeof(_delay
));
1878 delayer
->menu
=omenu
;
1879 delayer
->ox
=old_frame_x
;
1880 delayer
->oy
=old_frame_y
;
1881 omenu
->jump_back
=delayer
;
1882 scr
->flags
.jump_back_pending
= 1;
1884 else delayer
= omenu
->jump_back
;
1885 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1892 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1894 wMenuPaint(desc
->parent
);
1898 int *delayed_select
;
1905 delaySelection(void *data
)
1907 delay_data
*d
= (delay_data
*)data
;
1913 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1914 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1915 entry_no
= getEntryAt(menu
, x
, y
);
1916 selectEntry(menu
, entry_no
);
1918 if (d
->delayed_select
)
1919 *(d
->delayed_select
) = 0;
1924 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1926 XButtonEvent
*bev
= &event
->xbutton
;
1927 WMenu
*menu
= desc
->parent
;
1929 WScreen
*scr
=menu
->frame
->screen_ptr
;
1930 WMenuEntry
*entry
=NULL
;
1932 int close_on_exit
=0;
1934 int delayed_select
= 0;
1938 int old_frame_x
= 0;
1939 int old_frame_y
= 0;
1940 delay_data d_data
= {NULL
, NULL
, NULL
};
1942 if (!wPreferences
.wrap_menus
) {
1943 smenu
= parentMenu(menu
);
1944 old_frame_x
= smenu
->frame_x
;
1945 old_frame_y
= smenu
->frame_y
;
1946 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1947 /* This is true if the menu was launched with right click on root window */
1949 d_data
.delayed_select
= &delayed_select
;
1951 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1952 delaySelection
, &d_data
);
1955 if (menu
->flags
.inside_handler
) {
1958 menu
->flags
.inside_handler
= 1;
1960 wRaiseFrame(menu
->frame
->core
);
1962 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1964 smenu
= findMenu(scr
, &x
, &y
);
1972 if (menu
->flags
.editing
) {
1975 entry_no
= getEntryAt(menu
, x
, y
);
1977 entry
= menu
->entries
[entry_no
];
1979 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1980 && entry
->flags
.editable
) {
1981 editEntry(smenu
, entry
);
1983 } else if (bev
->state
& ControlMask
) {
1987 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1988 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1990 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1991 menu
->selected_entry
!=entry_no
) {
1992 wMenuUnmap(submenu
);
1994 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1995 selectEntry(menu
, entry_no
);
1996 } else if (!submenu
->flags
.buttoned
) {
1997 selectEntry(menu
, -1);
2000 } else if (!delayed_select
) {
2001 selectEntry(menu
, entry_no
);
2004 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2006 dragScrollMenuCallback(menu
);
2010 #ifdef VIRTUAL_DESKTOP
2011 if (wPreferences
.vedge_thickness
) {
2012 wWorkspaceLowerEdge(scr
);
2016 prevx
= bev
->x_root
;
2017 prevy
= bev
->y_root
;
2021 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2023 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2024 |ButtonPressMask
, &ev
);
2027 smenu
= findMenu(scr
, &x
, &y
);
2029 if (smenu
== NULL
) {
2030 /* moved mouse out of menu */
2032 if (!delayed_select
&& d_data
.magic
) {
2033 WMDeleteTimerHandler(d_data
.magic
);
2034 d_data
.magic
= NULL
;
2037 || (menu
->selected_entry
>=0
2038 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2039 prevx
= ev
.xmotion
.x_root
;
2040 prevy
= ev
.xmotion
.y_root
;
2044 selectEntry(menu
, -1);
2046 prevx
= ev
.xmotion
.x_root
;
2047 prevy
= ev
.xmotion
.y_root
;
2049 } else if (menu
&& menu
!=smenu
2050 && (menu
->selected_entry
<0
2051 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2052 selectEntry(menu
, -1);
2054 if (!delayed_select
&& d_data
.magic
) {
2055 WMDeleteTimerHandler(d_data
.magic
);
2056 d_data
.magic
= NULL
;
2060 /* hysteresis for item selection */
2062 /* check if the motion was to the side, indicating that
2063 * the user may want to cross to a submenu */
2064 if (!delayed_select
&& menu
) {
2066 Bool moved_to_submenu
;/* moved to direction of submenu */
2068 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2070 moved_to_submenu
= False
;
2071 if (dx
> 0 /* if moved enough to the side */
2072 /* maybe a open submenu */
2073 && menu
->selected_entry
>=0
2074 /* moving to the right direction */
2075 && (wPreferences
.align_menus
2076 || ev
.xmotion
.y_root
>= prevy
)) {
2079 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2081 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2082 if (prevx
< ev
.xmotion
.x_root
)
2083 moved_to_submenu
= True
;
2085 if (prevx
> ev
.xmotion
.x_root
)
2086 moved_to_submenu
= True
;
2092 if (menu
!= smenu
) {
2094 WMDeleteTimerHandler(d_data
.magic
);
2096 d_data
.magic
= NULL
;
2097 } else if (moved_to_submenu
) {
2098 /* while we are moving, postpone the selection */
2100 WMDeleteTimerHandler(d_data
.magic
);
2102 d_data
.delayed_select
= NULL
;
2104 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2107 prevx
= ev
.xmotion
.x_root
;
2108 prevy
= ev
.xmotion
.y_root
;
2112 WMDeleteTimerHandler(d_data
.magic
);
2113 d_data
.magic
= NULL
;
2117 prevx
= ev
.xmotion
.x_root
;
2118 prevy
= ev
.xmotion
.y_root
;
2120 /* pointer crossed menus */
2121 if (menu
&& menu
->timer
) {
2122 WMDeleteTimerHandler(menu
->timer
);
2126 dragScrollMenuCallback(smenu
);
2130 dragScrollMenuCallback(menu
);
2132 if (!delayed_select
) {
2133 entry_no
= getEntryAt(menu
, x
, y
);
2135 entry
= menu
->entries
[entry_no
];
2136 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2138 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2139 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2140 && menu
->selected_entry
!=entry_no
) {
2141 wMenuUnmap(submenu
);
2145 selectEntry(menu
, entry_no
);
2153 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2159 #ifdef VIRTUAL_DESKTOP
2160 /* since expose will raise edge up.. I need another ugly hack here */
2161 if (wPreferences
.vedge_thickness
) {
2162 wWorkspaceLowerEdge(scr
);
2169 if (menu
&& menu
->timer
) {
2170 WMDeleteTimerHandler(menu
->timer
);
2173 if (d_data
.magic
!=NULL
)
2174 WMDeleteTimerHandler(d_data
.magic
);
2176 if (menu
&& menu
->selected_entry
>=0) {
2177 entry
= menu
->entries
[menu
->selected_entry
];
2178 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2179 && entry
->cascade
< 0) {
2180 /* blink and erase menu selection */
2181 #if (MENU_BLINK_DELAY > 0)
2182 int sel
= menu
->selected_entry
;
2185 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2186 paintEntry(menu
, sel
, False
);
2188 wusleep(MENU_BLINK_DELAY
);
2189 paintEntry(menu
, sel
, True
);
2191 wusleep(MENU_BLINK_DELAY
);
2194 /* unmap the menu, it's parents and call the callback */
2195 if (!menu
->flags
.buttoned
&&
2196 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2199 selectEntry(menu
, -1);
2201 (*entry
->callback
)(menu
, entry
);
2203 /* If the user double clicks an entry, the entry will
2204 * be executed twice, which is not good for things like
2205 * the root menu. So, ignore any clicks that were generated
2206 * while the entry was being executed */
2207 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2209 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2210 selectEntry(menu
, -1);
2212 if (entry
->cascade
>=0 && menu
->cascades
2213 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2214 selectEntry(menu
, -1);
2219 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2220 closeCascade(desc
->parent
);
2222 /* close the cascade windows that should not remain opened */
2223 closeBrotherCascadesOf(desc
->parent
);
2225 if (!wPreferences
.wrap_menus
)
2226 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2229 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2230 #ifdef VIRTUAL_DESKTOP
2231 if (wPreferences
.vedge_thickness
) {
2232 wWorkspaceRaiseEdge(scr
);
2239 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2248 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2250 if (submenus
>0 && menu
->selected_entry
>=0) {
2251 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2253 if (i
>=0 && menu
->cascades
) {
2254 submenu
= menu
->cascades
[i
];
2255 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2256 if (wPreferences
.align_menus
) {
2257 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2259 wMenuMove(submenu
, x
+ MENUW(menu
),
2260 y
+ submenu
->entry_height
*menu
->selected_entry
,
2266 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2267 !menu
->parent
->flags
.buttoned
) {
2268 if (wPreferences
.align_menus
) {
2269 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2271 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2272 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2280 changeMenuLevels(WMenu
*menu
, int lower
)
2285 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2287 wRaiseFrame(menu
->frame
->core
);
2288 menu
->flags
.lowered
= 0;
2290 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2291 wLowerFrame(menu
->frame
->core
);
2292 menu
->flags
.lowered
= 1;
2294 for (i
=0; i
<menu
->cascade_no
; i
++) {
2295 if (menu
->cascades
[i
]
2296 && !menu
->cascades
[i
]->flags
.buttoned
2297 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2298 changeMenuLevels(menu
->cascades
[i
], lower
);
2306 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2311 if (event
->xbutton
.state
& MOD_MASK
) {
2312 if (menu
->flags
.lowered
) {
2317 changeMenuLevels(menu
, lower
);
2323 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2328 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2329 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2333 /* can't touch the menu copy */
2334 if (menu
->flags
.brother
)
2337 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2340 if (event
->xbutton
.state
& MOD_MASK
) {
2341 wLowerFrame(menu
->frame
->core
);
2344 wRaiseFrame(menu
->frame
->core
);
2349 /* lower/raise all submenus */
2351 if (tmp
->selected_entry
>=0 && tmp
->cascades
2352 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2353 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2354 if (!tmp
|| !tmp
->flags
.mapped
)
2357 wLowerFrame(tmp
->frame
->core
);
2359 wRaiseFrame(tmp
->frame
->core
);
2365 /* tear off the menu if it's a root menu or a cascade
2367 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2368 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2369 menu
->flags
.buttoned
=1;
2370 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2372 /* turn off selected menu entry in parent menu */
2373 selectEntry(menu
->parent
, -1);
2375 /* make parent map the copy in place of the original */
2376 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2377 if (menu
->parent
->cascades
[i
] == menu
) {
2378 menu
->parent
->cascades
[i
] = menu
->brother
;
2387 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2388 |ExposureMask
, &ev
);
2392 x
+= ev
.xmotion
.x_root
- dx
;
2393 y
+= ev
.xmotion
.y_root
- dy
;
2394 dx
= ev
.xmotion
.x_root
;
2395 dy
= ev
.xmotion
.y_root
;
2396 wMenuMove(menu
, x
, y
, True
);
2398 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2399 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2401 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2402 ButtonMotionMask
|ButtonReleaseMask
2404 GrabModeAsync
, GrabModeAsync
, None
,
2405 wCursor
[WCUR_MOVE
], CurrentTime
);
2414 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2416 XUngrabPointer(dpy
, CurrentTime
);
2427 *----------------------------------------------------------------------
2429 * Handles mouse click on the close button of menus. The menu is
2430 * closed when the button is clicked.
2433 * The closed menu is reinserted at it's parent menus
2435 *----------------------------------------------------------------------
2438 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2440 WMenu
*menu
= (WMenu
*)data
;
2441 WMenu
*parent
= menu
->parent
;
2445 for (i
=0; i
<parent
->cascade_no
; i
++) {
2446 /* find the entry that points to the copy */
2447 if (parent
->cascades
[i
] == menu
->brother
) {
2448 /* make it point to the original */
2449 parent
->cascades
[i
] = menu
;
2450 menu
->parent
= parent
;
2460 saveMenuInfo(WMPropList
*dict
, WMenu
*menu
, WMPropList
*key
)
2462 WMPropList
*value
, *list
;
2465 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2466 value
= WMCreatePLString(buffer
);
2467 list
= WMCreatePLArray(value
, NULL
);
2468 if (menu
->flags
.lowered
)
2469 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2470 WMPutInPLDictionary(dict
, key
, list
);
2471 WMReleasePropList(value
);
2472 WMReleasePropList(list
);
2477 wMenuSaveState(WScreen
*scr
)
2479 WMPropList
*menus
, *key
;
2482 menus
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
2485 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2486 key
= WMCreatePLString("SwitchMenu");
2487 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2488 WMReleasePropList(key
);
2492 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2496 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2497 key
= WMCreatePLString("WorkspaceMenu");
2498 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2499 WMReleasePropList(key
);
2504 key
= WMCreatePLString("Menus");
2505 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2506 WMReleasePropList(key
);
2508 WMReleasePropList(menus
);
2515 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2520 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2523 len
= strlen(menu
->frame
->title
);
2528 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2533 strcat(buffer
, "\\");
2534 strcat(buffer
, menu
->frame
->title
);
2541 saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
)
2544 int save_menus
= 0, i
;
2549 if (menu
->flags
.brother
)
2550 menu
= menu
->brother
;
2552 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2555 ok
= getMenuPath(menu
, buffer
, 510);
2558 key
= WMCreatePLString(buffer
);
2559 saveMenuInfo(menus
, menu
, key
);
2560 WMReleasePropList(key
);
2566 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2567 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2576 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2580 getMenuInfo(WMPropList
*info
, int *x
, int *y
, Bool
*lowered
)
2586 if (WMIsPLArray(info
)) {
2588 pos
= WMGetFromPLArray(info
, 0);
2589 flags
= WMGetFromPLArray(info
, 1);
2590 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2591 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2598 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2599 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
)!=2)
2600 COMPLAIN("Position");
2602 COMPLAIN("(position, flags...)");
2611 restoreMenu(WScreen
*scr
, WMPropList
*menu
, int which
)
2614 Bool lowered
= False
;
2615 WMenu
*pmenu
= NULL
;
2620 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2625 if (which
& WSS_SWITCHMENU
) {
2626 OpenSwitchMenu(scr
, x
, y
, False
);
2627 pmenu
= scr
->switch_menu
;
2632 int width
= MENUW(pmenu
);
2633 int height
= MENUH(pmenu
);
2636 changeMenuLevels(pmenu
, True
);
2639 x
= (x
< -width
) ? 0 : x
;
2640 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2641 y
= (y
< 0) ? 0 : y
;
2642 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2643 wMenuMove(pmenu
, x
, y
, True
);
2644 pmenu
->flags
.buttoned
= 1;
2645 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2654 restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
)
2656 WMPropList
*key
, *entry
;
2661 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2664 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2665 key
= WMCreatePLString(buffer
);
2666 entry
= WMGetFromPLDictionary(menus
, key
);
2669 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2671 if (!menu
->flags
.mapped
) {
2672 int width
= MENUW(menu
);
2673 int height
= MENUH(menu
);
2675 wMenuMapAt(menu
, x
, y
, False
);
2678 /* make parent map the copy in place of the original */
2679 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2680 if (menu
->parent
->cascades
[i
] == menu
) {
2681 menu
->parent
->cascades
[i
] = menu
->brother
;
2687 changeMenuLevels(menu
, True
);
2689 x
= (x
< -width
) ? 0 : x
;
2690 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2691 y
= (y
< 0) ? 0 : y
;
2692 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2693 wMenuMove(menu
, x
, y
, True
);
2694 menu
->flags
.buttoned
= 1;
2695 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2700 WMReleasePropList(key
);
2702 for (i
=0; i
<menu
->cascade_no
; i
++) {
2703 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2713 wMenuRestoreState(WScreen
*scr
)
2715 WMPropList
*menus
, *menu
, *key
, *skey
;
2717 key
= WMCreatePLString("Menus");
2718 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2719 WMReleasePropList(key
);
2726 skey
= WMCreatePLString("SwitchMenu");
2727 menu
= WMGetFromPLDictionary(menus
, skey
);
2728 WMReleasePropList(skey
);
2729 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2732 if (!scr
->root_menu
) {
2733 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2734 wMenuUnmap(scr
->root_menu
);
2736 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2742 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2744 WMenu
*menu
, *parent
;
2748 if (!scr
->root_menu
) {
2749 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2750 wMenuUnmap(scr
->root_menu
);
2753 menu
= scr
->workspace_menu
;
2755 if (menu
->flags
.mapped
) {
2756 if (!menu
->flags
.buttoned
) {
2758 parent
= menu
->parent
;
2759 if (parent
&& parent
->selected_entry
>= 0) {
2760 entry
= parent
->entries
[parent
->selected_entry
];
2761 if (parent
->cascades
[entry
->cascade
] == menu
) {
2762 selectEntry(parent
, -1);
2763 wMenuMapAt(menu
, x
, y
, False
);
2767 wRaiseFrame(menu
->frame
->core
);
2768 wMenuMapCopyAt(menu
, x
, y
);
2771 wMenuMapAt(menu
, x
, y
, False
);