1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
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>
38 #include "WindowMaker.h"
47 #include "workspace.h"
50 /****** Global Variables ******/
52 extern Cursor wCursor
[WCUR_LAST
];
54 extern XContext wWinContext
;
56 extern WPreferences wPreferences
;
58 #define MOD_MASK wPreferences.modifier_mask
60 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
61 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
65 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
66 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
69 /***** Local Stuff ******/
72 #define WSS_ROOTMENU (1<<0)
73 #define WSS_SWITCHMENU (1<<1)
74 #define WSS_WSMENU (1<<2)
80 } menuScrollParameters
[5] = {
81 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
82 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
83 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
84 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
85 {MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
88 static void menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
89 static void menuExpose(WObjDescriptor
*desc
, XEvent
*event
);
91 static void menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
92 static void menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
94 static void menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
96 static void updateTexture(WMenu
*menu
);
99 static int saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
);
100 static int restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
);
103 static void selectEntry(WMenu
*menu
, int entry_no
);
104 static void closeCascade(WMenu
*menu
);
107 /****** Notification Observers ******/
110 appearanceObserver(void *self
, WMNotification
*notif
)
112 WMenu
*menu
= (WMenu
*)self
;
113 int flags
= (int)(uintptr_t)WMGetNotificationClientData(notif
);
115 if (!menu
->flags
.realized
)
118 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
119 if (flags
& WFontSettings
) {
120 menu
->flags
.realized
= 0;
123 if (flags
& WTextureSettings
) {
124 if (!menu
->flags
.brother
)
127 if (flags
& (WTextureSettings
|WColorSettings
)) {
130 } else if (menu
->flags
.titled
) {
132 if (flags
& WFontSettings
) {
133 menu
->flags
.realized
= 0;
136 if (flags
& WTextureSettings
) {
137 menu
->frame
->flags
.need_texture_remake
= 1;
139 if (flags
& (WColorSettings
|WTextureSettings
)) {
140 wFrameWindowPaint(menu
->frame
);
145 /************************************/
149 *----------------------------------------------------------------------
151 * Creates a new empty menu with the specified title. If main_menu
152 * is True, the created menu will be a main menu, which has some special
153 * properties such as being placed over other normal menus.
154 * If title is NULL, the menu will have no titlebar.
158 *----------------------------------------------------------------------
161 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
164 static int brother
=0;
167 menu
= wmalloc(sizeof(WMenu
));
169 memset(menu
, 0, sizeof(WMenu
));
171 #ifdef SINGLE_MENULEVEL
172 tmp
= WMSubmenuLevel
;
174 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
177 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
179 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
180 menu
->flags
.titled
= 1;
183 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
184 screen
->menu_title_texture
, NULL
,
185 screen
->menu_title_color
,
186 &screen
->menu_title_font
);
188 menu
->frame
->core
->descriptor
.parent
= menu
;
189 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
190 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
192 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
195 menu
->frame
->title
= wstrdup(title
);
198 menu
->frame
->flags
.justification
= WTJ_LEFT
;
200 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
203 menu
->alloced_entries
= 0;
204 menu
->selected_entry
= -1;
205 menu
->entries
= NULL
;
207 menu
->frame_x
= screen
->app_menu_x
;
208 menu
->frame_y
= screen
->app_menu_y
;
210 menu
->frame
->child
= menu
;
212 menu
->flags
.lowered
= 0;
216 /* setup object descriptors */
217 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
218 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
221 menu
->frame
->on_click_right
= menuCloseClick
;
224 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
225 menu
->frame
->core
->width
, 10);
227 menu
->menu
->descriptor
.parent
= menu
;
228 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
229 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
230 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
232 menu
->menu_texture_data
= None
;
234 XMapWindow(dpy
, menu
->menu
->window
);
240 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
242 menu
->brother
->flags
.brother
= 1;
243 menu
->brother
->brother
= menu
;
245 WMAddNotificationObserver(appearanceObserver
, menu
,
246 WNMenuAppearanceSettingsChanged
, menu
);
248 WMAddNotificationObserver(appearanceObserver
, menu
,
249 WNMenuTitleAppearanceSettingsChanged
, menu
);
259 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
263 menu
= wMenuCreate(screen
, title
, main_menu
);
266 menu
->flags
.app_menu
= 1;
267 menu
->brother
->flags
.app_menu
= 1;
275 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
279 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
280 menu
->entries
[i
]->order
++;
281 menu
->entries
[i
+1] = menu
->entries
[i
];
283 menu
->entries
[index
] = entry
;
288 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
289 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
294 menu
->flags
.realized
= 0;
295 menu
->brother
->flags
.realized
= 0;
297 /* reallocate array if it's too small */
298 if (menu
->entry_no
>= menu
->alloced_entries
) {
301 tmp
= wrealloc(menu
->entries
,
302 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
305 menu
->alloced_entries
+= 5;
307 menu
->brother
->entries
= tmp
;
308 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
310 entry
= wmalloc(sizeof(WMenuEntry
));
311 memset(entry
, 0, sizeof(WMenuEntry
));
312 entry
->flags
.enabled
= 1;
313 entry
->text
= wstrdup(text
);
315 entry
->clientdata
= clientdata
;
316 entry
->callback
= callback
;
317 if (index
<0 || index
>=menu
->entry_no
) {
318 entry
->order
= menu
->entry_no
;
319 menu
->entries
[menu
->entry_no
] = entry
;
321 entry
->order
= index
;
322 insertEntry(menu
, entry
, index
);
326 menu
->brother
->entry_no
= menu
->entry_no
;
334 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
336 WMenu
*brother
= menu
->brother
;
339 assert(menu
->flags
.brother
==0);
341 if (entry
->cascade
>=0) {
342 menu
->flags
.realized
= 0;
343 brother
->flags
.realized
= 0;
346 cascade
->parent
= menu
;
348 cascade
->brother
->parent
= brother
;
351 for (i
=0; i
<menu
->cascade_no
; i
++) {
352 if (menu
->cascades
[i
]==NULL
) {
353 menu
->cascades
[i
] = cascade
;
354 brother
->cascades
[i
] = cascade
->brother
;
361 entry
->cascade
= menu
->cascade_no
;
363 menu
->cascades
= wrealloc(menu
->cascades
,
364 sizeof(WMenu
)*(menu
->cascade_no
+1));
365 menu
->cascades
[menu
->cascade_no
++] = cascade
;
368 brother
->cascades
= wrealloc(brother
->cascades
,
369 sizeof(WMenu
)*(brother
->cascade_no
+1));
370 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
374 if (menu
->flags
.lowered
) {
376 cascade
->flags
.lowered
= 1;
377 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
379 cascade
->brother
->flags
.lowered
= 1;
380 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
383 if (!menu
->flags
.realized
)
389 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
391 assert(menu
->flags
.brother
==0);
393 /* destroy cascade menu */
394 if (entry
->cascade
>=0 && menu
->cascades
395 && menu
->cascades
[entry
->cascade
]!=NULL
) {
397 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
399 menu
->cascades
[entry
->cascade
] = NULL
;
400 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
408 wMenuRemoveItem(WMenu
*menu
, int index
)
412 if (menu
->flags
.brother
) {
413 wMenuRemoveItem(menu
->brother
, index
);
417 if (index
>=menu
->entry_no
) return;
419 /* destroy cascade menu */
420 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
422 /* destroy unshared data */
424 if (menu
->entries
[index
]->text
)
425 wfree(menu
->entries
[index
]->text
);
427 if (menu
->entries
[index
]->rtext
)
428 wfree(menu
->entries
[index
]->rtext
);
430 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
431 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
433 wfree(menu
->entries
[index
]);
435 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
436 menu
->entries
[i
+1]->order
--;
437 menu
->entries
[i
]=menu
->entries
[i
+1];
440 menu
->brother
->entry_no
--;
445 renderTexture(WMenu
*menu
)
453 WScreen
*scr
= menu
->menu
->screen_ptr
;
454 WTexture
*texture
= scr
->menu_item_texture
;
456 if (wPreferences
.menu_style
== MS_NORMAL
) {
457 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
458 menu
->entry_height
, WREL_MENUENTRY
);
460 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
461 menu
->menu
->height
+1, WREL_MENUENTRY
);
464 wwarning(_("could not render texture: %s"),
465 RMessageForError(RErrorCode
));
470 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
472 light
.red
= light
.green
= light
.blue
= 80;
475 dark
.red
= dark
.green
= dark
.blue
= 0;
478 mid
.red
= mid
.green
= mid
.blue
= 40;
480 for (i
= 1; i
< menu
->entry_no
; i
++) {
481 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
482 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
484 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
485 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
487 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
488 menu
->menu
->width
-1, i
*menu
->entry_height
,
492 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
493 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
502 updateTexture(WMenu
*menu
)
504 WScreen
*scr
= menu
->menu
->screen_ptr
;
506 /* setup background texture */
507 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
508 if (!menu
->flags
.brother
) {
509 FREE_PIXMAP(menu
->menu_texture_data
);
511 menu
->menu_texture_data
= renderTexture(menu
);
513 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
514 menu
->menu_texture_data
);
515 XClearWindow(dpy
, menu
->menu
->window
);
517 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
518 menu
->menu_texture_data
);
519 XClearWindow(dpy
, menu
->brother
->menu
->window
);
522 XSetWindowBackground(dpy
, menu
->menu
->window
,
523 scr
->menu_item_texture
->any
.color
.pixel
);
524 XClearWindow(dpy
, menu
->menu
->window
);
530 wMenuRealize(WMenu
*menu
)
533 int width
, rwidth
, mrwidth
, mwidth
;
534 int theight
, twidth
, eheight
;
535 WScreen
*scr
= menu
->frame
->screen_ptr
;
536 static int brother_done
=0;
541 wMenuRealize(menu
->brother
);
545 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
546 if (menu
->flags
.titled
)
547 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
549 wFrameWindowUpdateBorders(menu
->frame
, flags
);
551 if (menu
->flags
.titled
) {
552 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
553 strlen(menu
->frame
->title
));
554 theight
= menu
->frame
->top_width
;
555 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
560 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
561 menu
->entry_height
= eheight
;
564 for (i
=0; i
<menu
->entry_no
; i
++) {
567 /* search widest text */
568 text
= menu
->entries
[i
]->text
;
569 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
571 if (menu
->entries
[i
]->flags
.indicator
) {
572 width
+= MENU_INDICATOR_SPACE
;
578 /* search widest text on right */
579 text
= menu
->entries
[i
]->rtext
;
581 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
583 else if (menu
->entries
[i
]->cascade
>=0)
588 if (rwidth
> mrwidth
)
597 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
599 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
600 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
605 menu
->flags
.realized
= 1;
607 if (menu
->flags
.mapped
)
609 if (menu
->brother
->flags
.mapped
)
610 wMenuPaint(menu
->brother
);
615 wMenuDestroy(WMenu
*menu
, int recurse
)
619 WMRemoveNotificationObserver(menu
);
621 /* remove any pending timers */
623 WMDeleteTimerHandler(menu
->timer
);
626 /* call destroy handler */
627 if (menu
->on_destroy
)
628 (*menu
->on_destroy
)(menu
);
630 /* Destroy items if this menu own them. If this is the "brother" menu,
631 * leave them alone as it is shared by them.
633 if (!menu
->flags
.brother
) {
634 for (i
=0; i
<menu
->entry_no
; i
++) {
636 wfree(menu
->entries
[i
]->text
);
638 if (menu
->entries
[i
]->rtext
)
639 wfree(menu
->entries
[i
]->rtext
);
642 if (menu
->entries
[i
]->instances
){
643 WMReleasePropList(menu
->entries
[i
]->instances
);
645 #endif /* USER_MENU */
647 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
648 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
650 wfree(menu
->entries
[i
]);
654 for (i
=0; i
<menu
->cascade_no
; i
++) {
655 if (menu
->cascades
[i
]) {
656 if (menu
->cascades
[i
]->flags
.brother
)
657 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
659 wMenuDestroy(menu
->cascades
[i
], recurse
);
665 wfree(menu
->entries
);
669 FREE_PIXMAP(menu
->menu_texture_data
);
672 wfree(menu
->cascades
);
674 wCoreDestroy(menu
->menu
);
675 wFrameWindowDestroy(menu
->frame
);
677 /* destroy copy of this menu */
678 if (!menu
->flags
.brother
&& menu
->brother
)
679 wMenuDestroy(menu
->brother
, False
);
691 drawFrame(WScreen
*scr
, Drawable win
, int y
, int w
, int h
, int type
)
697 segs
[i
].x1
= segs
[i
].x2
= w
-1;
699 segs
[i
].y2
= y
+ h
- 1;
701 if (type
!= F_TOP
&& type
!= F_NONE
) {
703 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
707 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
713 segs
[i
].y2
= y
+ h
- 1;
715 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
722 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
724 if (type
!= F_TOP
&& type
!= F_NONE
)
725 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
731 paintEntry(WMenu
*menu
, int index
, int selected
)
733 WScreen
*scr
=menu
->frame
->screen_ptr
;
734 Window win
= menu
->menu
->window
;
735 WMenuEntry
*entry
=menu
->entries
[index
];
741 if (!menu
->flags
.realized
) return;
742 h
= menu
->entry_height
;
743 w
= menu
->menu
->width
;
746 light
= scr
->menu_item_auxtexture
->light_gc
;
747 dim
= scr
->menu_item_auxtexture
->dim_gc
;
748 dark
= scr
->menu_item_auxtexture
->dark_gc
;
750 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
753 else if (index
== menu
->entry_no
- 1)
761 /* paint background */
763 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+1, w
-2, h
-3);
764 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
765 drawFrame(scr
, win
, y
, w
, h
, type
);
767 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
768 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
770 drawFrame(scr
, win
, y
, w
, h
, type
);
772 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
777 if (entry
->flags
.enabled
)
778 color
= scr
->select_text_color
;
780 color
= scr
->dtext_color
;
781 } else if (!entry
->flags
.enabled
) {
782 color
= scr
->dtext_color
;
784 color
= scr
->mtext_color
;
788 if (entry
->flags
.indicator
)
789 x
+= MENU_INDICATOR_SPACE
+ 2;
791 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
792 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
794 if (entry
->cascade
>=0) {
795 /* draw the cascade indicator */
796 XDrawLine(dpy
, win
, dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
797 XDrawLine(dpy
, win
, light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
798 XDrawLine(dpy
, win
, dark
, w
-12, y
+6, w
-12, y
+h
-8);
802 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
807 switch (entry
->flags
.indicator_type
) {
809 indicator
= scr
->menu_check_indicator
;
812 indicator
= scr
->menu_mini_indicator
;
815 indicator
= scr
->menu_hide_indicator
;
818 indicator
= scr
->menu_shade_indicator
;
822 indicator
= scr
->menu_radio_indicator
;
826 iw
= indicator
->width
;
827 ih
= indicator
->height
;
828 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
829 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
831 if (entry
->flags
.enabled
) {
832 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
834 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
837 if (entry
->flags
.enabled
) {
838 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
840 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
843 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
845 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
846 iw, ih, 5, y+(h-ih)/2);
848 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
851 /* draw right text */
853 if (entry
->rtext
&& entry
->cascade
<0) {
854 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
855 strlen(entry
->rtext
));
857 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
-6-tw
,
858 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
864 move_menus(WMenu
*menu
, int x
, int y
)
866 while (menu
->parent
) {
869 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
870 y
-= menu
->selected_entry
*menu
->entry_height
;
873 wMenuMove(menu
, x
, y
, True
);
877 makeVisible(WMenu
*menu
)
879 WScreen
*scr
= menu
->frame
->screen_ptr
;
880 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
881 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
883 if (menu
->entry_no
<0) return;
886 y1
= menu
->frame_y
+menu
->frame
->top_width
887 + menu
->selected_entry
*menu
->entry_height
;
888 x2
= x1
+ MENUW(menu
);
889 y2
= y1
+ menu
->entry_height
;
896 if (x1
< rect
.pos
.x
) {
899 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
900 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
904 if (y1
< rect
.pos
.y
) {
907 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
908 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
912 new_y
= new_y
- menu
->frame
->top_width
913 - menu
->selected_entry
*menu
->entry_height
;
914 move_menus(menu
, new_x
, new_y
);
919 check_key(WMenu
*menu
, XKeyEvent
*event
)
924 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
927 ch
= toupper(buffer
[0]);
929 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
932 for (i
=s
; i
<menu
->entry_no
; i
++) {
933 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
937 /* no match. Retry from start, if previous started from a selected entry */
947 keyboardMenu(WMenu
*menu
)
950 KeySym ksym
=NoSymbol
;
954 int old_pos_x
= menu
->frame_x
;
955 int old_pos_y
= menu
->frame_y
;
956 int new_x
= old_pos_x
, new_y
= old_pos_y
;
957 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
958 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
960 if (menu
->flags
.editing
)
964 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
965 GrabModeAsync
, CurrentTime
);
968 if (menu
->frame_y
+menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
969 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
971 if (menu
->frame_x
+MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
972 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
974 move_menus(menu
, new_x
, new_y
);
976 while (!done
&& menu
->flags
.mapped
) {
977 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
978 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
979 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
980 |SubstructureNotifyMask
, &event
);
982 switch (event
.type
) {
984 ksym
= XLookupKeysym(&event
.xkey
, 0);
994 selectEntry(menu
, 0);
1002 selectEntry(menu
, menu
->entry_no
-1);
1007 #ifdef ARROWLESS_KBD
1013 if (menu
->selected_entry
<= 0)
1014 selectEntry(menu
, menu
->entry_no
-1);
1016 selectEntry(menu
, menu
->selected_entry
-1);
1021 #ifdef ARROWLESS_KBD
1027 if (menu
->selected_entry
<0)
1028 selectEntry(menu
, 0);
1029 else if (menu
->selected_entry
== menu
->entry_no
-1)
1030 selectEntry(menu
, 0);
1031 else if (menu
->selected_entry
< menu
->entry_no
-1)
1032 selectEntry(menu
, menu
->selected_entry
+1);
1037 #ifdef ARROWLESS_KBD
1043 if (menu
->selected_entry
>=0) {
1045 entry
= menu
->entries
[menu
->selected_entry
];
1047 if (entry
->cascade
>= 0 && menu
->cascades
1048 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1050 XUngrabKeyboard(dpy
, CurrentTime
);
1052 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1053 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1056 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1057 GrabModeAsync
, GrabModeAsync
,
1064 #ifdef ARROWLESS_KBD
1070 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1071 selectEntry(menu
, -1);
1072 move_menus(menu
, old_pos_x
, old_pos_y
);
1085 index
= check_key(menu
, &event
.xkey
);
1087 selectEntry(menu
, index
);
1093 if (event
.type
==ButtonPress
)
1096 WMHandleEvent(&event
);
1100 XUngrabKeyboard(dpy
, CurrentTime
);
1102 if (done
==2 && menu
->selected_entry
>=0) {
1103 entry
= menu
->entries
[menu
->selected_entry
];
1108 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1109 && entry
->cascade
< 0) {
1110 #if (MENU_BLINK_COUNT > 0)
1111 int sel
= menu
->selected_entry
;
1114 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1115 paintEntry(menu
, sel
, False
);
1117 wusleep(MENU_BLINK_DELAY
);
1118 paintEntry(menu
, sel
, True
);
1120 wusleep(MENU_BLINK_DELAY
);
1123 selectEntry(menu
, -1);
1125 if (!menu
->flags
.buttoned
) {
1127 move_menus(menu
, old_pos_x
, old_pos_y
);
1131 (*entry
->callback
)(menu
, entry
);
1133 if (!menu
->flags
.buttoned
) {
1135 move_menus(menu
, old_pos_x
, old_pos_y
);
1137 selectEntry(menu
, -1);
1141 /* returns True if returning from a submenu to a parent menu,
1142 * False if exiting from menu */
1148 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1150 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1151 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1153 if (!menu
->flags
.realized
) {
1154 menu
->flags
.realized
=1;
1157 if (!menu
->flags
.mapped
) {
1158 if (wPreferences
.wrap_menus
) {
1159 if (x
<rect
.pos
.x
) x
= rect
.pos
.x
;
1160 if (y
<rect
.pos
.y
) y
= rect
.pos
.y
;
1161 if (x
+MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1162 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1163 if (y
+MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1164 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1167 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1168 menu
->frame_x
= (x
<0) ? 0 : x
;
1169 menu
->frame_y
= (y
<0) ? 0 : y
;
1170 XMapWindow(dpy
, menu
->frame
->core
->window
);
1171 wRaiseFrame(menu
->frame
->core
);
1172 menu
->flags
.mapped
= 1;
1174 selectEntry(menu
, 0);
1183 wMenuMap(WMenu
*menu
)
1185 if (!menu
->flags
.realized
) {
1186 menu
->flags
.realized
=1;
1189 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1190 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1191 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1192 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1194 XMapWindow(dpy
, menu
->frame
->core
->window
);
1195 wRaiseFrame(menu
->frame
->core
);
1196 menu
->flags
.mapped
= 1;
1201 wMenuUnmap(WMenu
*menu
)
1205 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1206 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1207 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1209 menu
->flags
.buttoned
= 0;
1210 menu
->flags
.mapped
= 0;
1211 menu
->flags
.open_to_left
= 0;
1213 for (i
=0; i
<menu
->cascade_no
; i
++) {
1214 if (menu
->cascades
[i
]!=NULL
1215 && menu
->cascades
[i
]->flags
.mapped
1216 && !menu
->cascades
[i
]->flags
.buttoned
) {
1218 wMenuUnmap(menu
->cascades
[i
]);
1221 menu
->selected_entry
= -1;
1227 wMenuPaint(WMenu
*menu
)
1231 if (!menu
->flags
.mapped
) {
1236 for (i
=0; i
<menu
->entry_no
; i
++) {
1237 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1243 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1245 if (index
>=menu
->entry_no
) return;
1246 menu
->entries
[index
]->flags
.enabled
=enable
;
1247 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1248 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1252 /* ====================================================================== */
1256 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1260 WObjDescriptor
*desc
;
1266 menu
->flags
.editing
= 1;
1268 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1269 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1271 wTextPutText(text
, entry
->text
);
1272 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1273 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1275 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1276 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1277 wwarning(_("could not grab keyboard"));
1280 wSetFocusTo(menu
->frame
->screen_ptr
,
1281 menu
->frame
->screen_ptr
->focused_window
);
1286 while (!done
&& !text
->done
) {
1288 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1290 WMNextEvent(dpy
, &event
);
1292 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1293 (XPointer
*)&desc
)==XCNOENT
)
1296 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1298 (*desc
->handle_anything
)(desc
, &event
);
1301 switch (event
.type
) {
1303 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1307 WMHandleEvent(&event
);
1313 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1315 wSetFocusTo(menu
->frame
->screen_ptr
,
1316 menu
->frame
->screen_ptr
->focused_window
);
1319 t
= wTextGetText(text
);
1320 /* if !t, the user has canceled editing */
1324 entry
->text
= wstrdup(t
);
1326 menu
->flags
.realized
= 0;
1330 XUngrabKeyboard(dpy
, CurrentTime
);
1332 if (t
&& menu
->on_edit
)
1333 (*menu
->on_edit
)(menu
, entry
);
1335 menu
->flags
.editing
= 0;
1337 if (!menu
->flags
.realized
)
1343 selectEntry(WMenu
*menu
, int entry_no
)
1349 if (menu
->entries
==NULL
)
1352 if (entry_no
>= menu
->entry_no
)
1355 old_entry
= menu
->selected_entry
;
1356 menu
->selected_entry
= entry_no
;
1358 if (old_entry
!=entry_no
) {
1360 /* unselect previous entry */
1362 paintEntry(menu
, old_entry
, False
);
1363 entry
= menu
->entries
[old_entry
];
1366 if (entry
->cascade
>=0 && menu
->cascades
) {
1367 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1368 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1374 menu
->selected_entry
= -1;
1377 entry
= menu
->entries
[entry_no
];
1379 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1380 /* Callback for when the submenu is opened.
1382 submenu
= menu
->cascades
[entry
->cascade
];
1383 if (submenu
&& submenu
->flags
.brother
)
1384 submenu
= submenu
->brother
;
1386 if (entry
->callback
) {
1387 /* Only call the callback if the submenu is not yet mapped.
1389 if (menu
->flags
.brother
) {
1390 if (!submenu
|| !submenu
->flags
.mapped
)
1391 (*entry
->callback
)(menu
->brother
, entry
);
1393 if (!submenu
|| !submenu
->flags
.buttoned
)
1394 (*entry
->callback
)(menu
, entry
);
1398 /* the submenu menu might have changed */
1399 submenu
= menu
->cascades
[entry
->cascade
];
1402 if (!submenu
->flags
.mapped
) {
1405 if (!submenu
->flags
.realized
)
1406 wMenuRealize(submenu
);
1407 if (wPreferences
.wrap_menus
) {
1408 if (menu
->flags
.open_to_left
)
1409 submenu
->flags
.open_to_left
= 1;
1411 if (submenu
->flags
.open_to_left
) {
1412 x
= menu
->frame_x
- MENUW(submenu
);
1415 submenu
->flags
.open_to_left
= 0;
1418 x
= menu
->frame_x
+ MENUW(menu
);
1420 if (x
+ MENUW(submenu
)
1421 >= menu
->frame
->screen_ptr
->scr_width
) {
1423 x
= menu
->frame_x
- MENUW(submenu
);
1424 submenu
->flags
.open_to_left
= 1;
1428 x
= menu
->frame_x
+ MENUW(menu
);
1431 if (wPreferences
.align_menus
) {
1434 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1435 if (menu
->flags
.titled
)
1436 y
+= menu
->frame
->top_width
;
1437 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1438 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1441 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1442 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1447 paintEntry(menu
, entry_no
, True
);
1453 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1456 WObjDescriptor
*desc
;
1457 Window root_ret
, win
, junk_win
;
1461 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1464 if (win
==None
) return NULL
;
1466 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1469 if (desc
->parent_type
== WCLASS_MENU
) {
1470 menu
= (WMenu
*)desc
->parent
;
1471 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1472 x_ret
, y_ret
, &junk_win
);
1482 closeCascade(WMenu
*menu
)
1484 WMenu
*parent
=menu
->parent
;
1486 if (menu
->flags
.brother
1487 || (!menu
->flags
.buttoned
1488 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1490 selectEntry(menu
, -1);
1492 #if (MENU_BLINK_DELAY > 2)
1493 wusleep(MENU_BLINK_DELAY
/2);
1497 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1498 || parent
->flags
.brother
)
1499 && !parent
->flags
.buttoned
) {
1500 selectEntry(parent
, -1);
1502 parent
= parent
->parent
;
1505 selectEntry(parent
, -1);
1511 closeBrotherCascadesOf(WMenu
*menu
)
1516 for (i
=0; i
<menu
->cascade_no
; i
++) {
1517 if (menu
->cascades
[i
]->flags
.brother
) {
1518 tmp
= menu
->cascades
[i
];
1520 tmp
= menu
->cascades
[i
]->brother
;
1522 if (tmp
->flags
.mapped
) {
1523 selectEntry(tmp
->parent
, -1);
1524 closeBrotherCascadesOf(tmp
);
1531 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1535 parentMenu(WMenu
*menu
)
1540 if (menu
->flags
.buttoned
)
1543 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1544 parent
= menu
->parent
;
1545 if (parent
->selected_entry
< 0)
1547 entry
= parent
->entries
[parent
->selected_entry
];
1548 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1549 parent
->cascades
[entry
->cascade
] != menu
)
1552 if (menu
->flags
.buttoned
)
1562 * Will raise the passed menu, if submenu = 0
1563 * If submenu > 0 will also raise all mapped submenus
1564 * until the first buttoned one
1565 * If submenu < 0 will also raise all mapped parent menus
1566 * until the first buttoned one
1570 raiseMenus(WMenu
*menu
, int submenus
)
1577 wRaiseFrame(menu
->frame
->core
);
1579 if (submenus
>0 && menu
->selected_entry
>=0) {
1580 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1581 if (i
>=0 && menu
->cascades
) {
1582 submenu
= menu
->cascades
[i
];
1583 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1584 raiseMenus(submenu
, submenus
);
1587 if (submenus
<0 && !menu
->flags
.buttoned
&&
1588 menu
->parent
&& menu
->parent
->flags
.mapped
)
1589 raiseMenus(menu
->parent
, submenus
);
1594 wMenuUnderPointer(WScreen
*screen
)
1596 WObjDescriptor
*desc
;
1597 Window root_ret
, win
;
1601 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1602 &dummy
, &dummy
, &mask
);
1604 if (win
==None
) return NULL
;
1606 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1609 if (desc
->parent_type
== WCLASS_MENU
)
1610 return (WMenu
*)desc
->parent
;
1618 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1620 Window root_ret
, win
;
1624 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1629 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1631 WScreen
*scr
= menu
->menu
->screen_ptr
;
1632 int menuX1
= menu
->frame_x
;
1633 int menuY1
= menu
->frame_y
;
1634 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1635 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1637 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1643 getPointerPosition(scr
, &xroot
, &yroot
);
1645 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1646 /* scroll to the right */
1647 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1649 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) &&
1650 menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1651 /* scroll to the left */
1652 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-rect
.pos
.x
-rect
.size
.width
-1));
1657 *hamount
= -*hamount
;
1660 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1662 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1664 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) &&
1665 menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1667 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
-rect
.pos
.y
-rect
.size
.height
-2));
1669 *vamount
= -*vamount
;
1675 dragScrollMenuCallback(void *data
)
1677 WMenu
*menu
= (WMenu
*)data
;
1678 WScreen
*scr
= menu
->menu
->screen_ptr
;
1679 WMenu
*parent
= parentMenu(menu
);
1680 int hamount
, vamount
;
1682 int newSelectedEntry
;
1684 getScrollAmount(menu
, &hamount
, &vamount
);
1687 if (hamount
!= 0 || vamount
!= 0) {
1688 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1689 parent
->frame_y
+ vamount
, True
);
1690 if (findMenu(scr
, &x
, &y
)) {
1691 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1692 selectEntry(menu
, newSelectedEntry
);
1694 /* Pointer fell outside of menu. If the selected entry is
1695 * not a submenu, unselect it */
1696 if (menu
->selected_entry
>= 0
1697 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1698 selectEntry(menu
, -1);
1699 newSelectedEntry
= 0;
1702 /* paranoid check */
1703 if (newSelectedEntry
>= 0) {
1704 /* keep scrolling */
1705 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1706 dragScrollMenuCallback
, menu
);
1711 /* don't need to scroll anymore */
1713 if (findMenu(scr
, &x
, &y
)) {
1714 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1715 selectEntry(menu
, newSelectedEntry
);
1722 scrollMenuCallback(void *data
)
1724 WMenu
*menu
= (WMenu
*)data
;
1725 WMenu
*parent
= parentMenu(menu
);
1726 int hamount
= 0; /* amount to scroll */
1729 #ifdef VIRTUAL_DESKTOP
1730 /* don't scroll if it is in vdesk mode */
1731 if (!wPreferences
.vdesk_enable
)
1733 getScrollAmount(menu
, &hamount
, &vamount
);
1735 if (hamount
!= 0 || vamount
!= 0) {
1736 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1737 parent
->frame_y
+ vamount
, True
);
1739 /* keep scrolling */
1740 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1741 scrollMenuCallback
, menu
);
1743 /* don't need to scroll anymore */
1750 #define MENU_SCROLL_BORDER 5
1753 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1755 int menuX1
= menu
->frame_x
;
1756 int menuY1
= menu
->frame_y
;
1757 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1758 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1760 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1761 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1763 /* XXX: handle screen joins properly !! */
1765 if (x
>= menuX1
&& x
<= menuX2
&&
1766 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
||
1767 y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1769 else if (y
>= menuY1
&& y
<= menuY2
&&
1770 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
||
1771 x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1778 typedef struct _delay
{
1787 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1788 dl
->menu
->jump_back
= NULL
;
1789 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1795 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1798 WMenu
*omenu
= parentMenu(menu
);
1799 WScreen
*scr
= menu
->frame
->screen_ptr
;
1802 int old_frame_x
= omenu
->frame_x
;
1803 int old_frame_y
= omenu
->frame_y
;
1806 if (omenu
->jump_back
)
1807 WMDeleteTimerWithClientData(omenu
->jump_back
);
1810 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1811 || omenu
->flags
.app_menu
) {
1815 if (!wPreferences
.wrap_menus
)
1816 raiseMenus(omenu
, True
);
1818 raiseMenus(menu
, False
);
1821 scrollMenuCallback(menu
);
1824 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1827 WMNextEvent(dpy
, &ev
);
1832 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1833 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1835 /* on_border is != 0 if the pointer is between the menu
1836 * and the screen border and is close enough to the border */
1837 on_border
= isPointNearBoder(menu
, x
, y
);
1839 smenu
= wMenuUnderPointer(scr
);
1841 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1846 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1847 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1848 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1849 on_border
= on_x_edge
|| on_y_edge
;
1851 if (!on_border
&& !jump_back
) {
1856 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1857 WMDeleteTimerHandler(menu
->timer
);
1865 scrollMenuCallback(menu
);
1868 /* True if we push on title, or drag the omenu to other position */
1869 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1870 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1871 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1872 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1874 smenu
= wMenuUnderPointer(scr
);
1875 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1877 else if (smenu
==omenu
&& on_title
) {
1891 WMDeleteTimerHandler(menu
->timer
);
1897 if (!omenu
->jump_back
) {
1898 delayer
= wmalloc(sizeof(_delay
));
1899 delayer
->menu
=omenu
;
1900 delayer
->ox
=old_frame_x
;
1901 delayer
->oy
=old_frame_y
;
1902 omenu
->jump_back
= delayer
;
1903 scr
->flags
.jump_back_pending
= 1;
1905 else delayer
= omenu
->jump_back
;
1906 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)leaving
, delayer
);
1913 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1915 wMenuPaint(desc
->parent
);
1919 int *delayed_select
;
1926 delaySelection(void *data
)
1928 delay_data
*d
= (delay_data
*)data
;
1934 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1935 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1936 entry_no
= getEntryAt(menu
, x
, y
);
1937 selectEntry(menu
, entry_no
);
1939 if (d
->delayed_select
)
1940 *(d
->delayed_select
) = 0;
1945 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1947 XButtonEvent
*bev
= &event
->xbutton
;
1948 WMenu
*menu
= desc
->parent
;
1950 WScreen
*scr
=menu
->frame
->screen_ptr
;
1951 WMenuEntry
*entry
=NULL
;
1953 int close_on_exit
=0;
1955 int delayed_select
= 0;
1959 int old_frame_x
= 0;
1960 int old_frame_y
= 0;
1961 delay_data d_data
= {NULL
, NULL
, NULL
};
1963 /* Doesn't seem to be needed anymore (if delayed selection handler is
1964 * added only if not present). there seem to be no other side effects
1965 * from removing this and it is also possible that it was only added
1966 * to avoid problems with adding the delayed selection timer handler
1969 /*if (menu->flags.inside_handler) {
1972 menu
->flags
.inside_handler
= 1;
1974 if (!wPreferences
.wrap_menus
) {
1975 smenu
= parentMenu(menu
);
1976 old_frame_x
= smenu
->frame_x
;
1977 old_frame_y
= smenu
->frame_y
;
1978 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1979 /* This is true if the menu was launched with right click on root window */
1980 if (!d_data
.magic
) {
1982 d_data
.delayed_select
= &delayed_select
;
1984 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1985 delaySelection
, &d_data
);
1989 wRaiseFrame(menu
->frame
->core
);
1991 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1993 smenu
= findMenu(scr
, &x
, &y
);
2001 if (menu
->flags
.editing
) {
2004 entry_no
= getEntryAt(menu
, x
, y
);
2006 entry
= menu
->entries
[entry_no
];
2008 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
2009 && entry
->flags
.editable
) {
2010 editEntry(smenu
, entry
);
2012 } else if (bev
->state
& ControlMask
) {
2016 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
2017 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2019 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
2020 menu
->selected_entry
!=entry_no
) {
2021 wMenuUnmap(submenu
);
2023 if (!submenu
->flags
.mapped
&& !delayed_select
) {
2024 selectEntry(menu
, entry_no
);
2025 } else if (!submenu
->flags
.buttoned
) {
2026 selectEntry(menu
, -1);
2029 } else if (!delayed_select
) {
2030 selectEntry(menu
, entry_no
);
2033 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2035 dragScrollMenuCallback(menu
);
2039 #ifdef VIRTUAL_DESKTOP
2040 if (wPreferences
.vdesk_enable
) {
2041 wWorkspaceLowerEdge(scr
);
2045 prevx
= bev
->x_root
;
2046 prevy
= bev
->y_root
;
2050 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2052 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2053 |ButtonPressMask
, &ev
);
2056 smenu
= findMenu(scr
, &x
, &y
);
2058 if (smenu
== NULL
) {
2059 /* moved mouse out of menu */
2061 if (!delayed_select
&& d_data
.magic
) {
2062 WMDeleteTimerHandler(d_data
.magic
);
2063 d_data
.magic
= NULL
;
2066 || (menu
->selected_entry
>=0
2067 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2068 prevx
= ev
.xmotion
.x_root
;
2069 prevy
= ev
.xmotion
.y_root
;
2073 selectEntry(menu
, -1);
2075 prevx
= ev
.xmotion
.x_root
;
2076 prevy
= ev
.xmotion
.y_root
;
2078 } else if (menu
&& menu
!=smenu
2079 && (menu
->selected_entry
<0
2080 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2081 selectEntry(menu
, -1);
2083 if (!delayed_select
&& d_data
.magic
) {
2084 WMDeleteTimerHandler(d_data
.magic
);
2085 d_data
.magic
= NULL
;
2089 /* hysteresis for item selection */
2091 /* check if the motion was to the side, indicating that
2092 * the user may want to cross to a submenu */
2093 if (!delayed_select
&& menu
) {
2095 Bool moved_to_submenu
;/* moved to direction of submenu */
2097 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2099 moved_to_submenu
= False
;
2100 if (dx
> 0 /* if moved enough to the side */
2101 /* maybe a open submenu */
2102 && menu
->selected_entry
>=0
2103 /* moving to the right direction */
2104 && (wPreferences
.align_menus
2105 || ev
.xmotion
.y_root
>= prevy
)) {
2108 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2110 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2111 if (prevx
< ev
.xmotion
.x_root
)
2112 moved_to_submenu
= True
;
2114 if (prevx
> ev
.xmotion
.x_root
)
2115 moved_to_submenu
= True
;
2121 if (menu
!= smenu
) {
2123 WMDeleteTimerHandler(d_data
.magic
);
2124 d_data
.magic
= NULL
;
2126 } else if (moved_to_submenu
) {
2127 /* while we are moving, postpone the selection */
2129 WMDeleteTimerHandler(d_data
.magic
);
2131 d_data
.delayed_select
= NULL
;
2133 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2136 prevx
= ev
.xmotion
.x_root
;
2137 prevy
= ev
.xmotion
.y_root
;
2141 WMDeleteTimerHandler(d_data
.magic
);
2142 d_data
.magic
= NULL
;
2147 prevx
= ev
.xmotion
.x_root
;
2148 prevy
= ev
.xmotion
.y_root
;
2150 /* pointer crossed menus */
2151 if (menu
&& menu
->timer
) {
2152 WMDeleteTimerHandler(menu
->timer
);
2156 dragScrollMenuCallback(smenu
);
2160 dragScrollMenuCallback(menu
);
2162 if (!delayed_select
) {
2163 entry_no
= getEntryAt(menu
, x
, y
);
2165 entry
= menu
->entries
[entry_no
];
2166 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2168 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2169 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2170 && menu
->selected_entry
!=entry_no
) {
2171 wMenuUnmap(submenu
);
2175 selectEntry(menu
, entry_no
);
2183 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2189 #ifdef VIRTUAL_DESKTOP
2190 /* since expose will raise edge up.. I need another ugly hack here */
2191 if (wPreferences
.vdesk_enable
) {
2192 wWorkspaceLowerEdge(scr
);
2199 if (menu
&& menu
->timer
) {
2200 WMDeleteTimerHandler(menu
->timer
);
2203 if (d_data
.magic
!=NULL
) {
2204 WMDeleteTimerHandler(d_data
.magic
);
2205 d_data
.magic
= NULL
;
2208 if (menu
&& menu
->selected_entry
>=0) {
2209 entry
= menu
->entries
[menu
->selected_entry
];
2210 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2211 && entry
->cascade
< 0) {
2212 /* blink and erase menu selection */
2213 #if (MENU_BLINK_DELAY > 0)
2214 int sel
= menu
->selected_entry
;
2217 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2218 paintEntry(menu
, sel
, False
);
2220 wusleep(MENU_BLINK_DELAY
);
2221 paintEntry(menu
, sel
, True
);
2223 wusleep(MENU_BLINK_DELAY
);
2226 /* unmap the menu, it's parents and call the callback */
2227 if (!menu
->flags
.buttoned
&&
2228 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2231 selectEntry(menu
, -1);
2233 (*entry
->callback
)(menu
, entry
);
2235 /* If the user double clicks an entry, the entry will
2236 * be executed twice, which is not good for things like
2237 * the root menu. So, ignore any clicks that were generated
2238 * while the entry was being executed */
2239 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2241 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2242 selectEntry(menu
, -1);
2244 if (entry
->cascade
>=0 && menu
->cascades
2245 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2246 selectEntry(menu
, -1);
2251 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2252 closeCascade(desc
->parent
);
2254 /* close the cascade windows that should not remain opened */
2255 closeBrotherCascadesOf(desc
->parent
);
2257 if (!wPreferences
.wrap_menus
)
2258 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2261 /* Just to be sure in case we skip the 2 above because of a goto byebye */
2262 if (menu
&& menu
->timer
) {
2263 WMDeleteTimerHandler(menu
->timer
);
2266 if (d_data
.magic
!=NULL
) {
2267 WMDeleteTimerHandler(d_data
.magic
);
2268 d_data
.magic
= NULL
;
2271 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2272 #ifdef VIRTUAL_DESKTOP
2273 wWorkspaceRaiseEdge(scr
);
2279 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2288 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2290 if (submenus
>0 && menu
->selected_entry
>=0) {
2291 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2293 if (i
>=0 && menu
->cascades
) {
2294 submenu
= menu
->cascades
[i
];
2295 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2296 if (wPreferences
.align_menus
) {
2297 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2299 wMenuMove(submenu
, x
+ MENUW(menu
),
2300 y
+ submenu
->entry_height
*menu
->selected_entry
,
2306 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2307 !menu
->parent
->flags
.buttoned
) {
2308 if (wPreferences
.align_menus
) {
2309 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2311 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2312 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2320 changeMenuLevels(WMenu
*menu
, int lower
)
2325 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2327 wRaiseFrame(menu
->frame
->core
);
2328 menu
->flags
.lowered
= 0;
2330 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2331 wLowerFrame(menu
->frame
->core
);
2332 menu
->flags
.lowered
= 1;
2334 for (i
=0; i
<menu
->cascade_no
; i
++) {
2335 if (menu
->cascades
[i
]
2336 && !menu
->cascades
[i
]->flags
.buttoned
2337 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2338 changeMenuLevels(menu
->cascades
[i
], lower
);
2346 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2351 if (event
->xbutton
.state
& MOD_MASK
) {
2352 if (menu
->flags
.lowered
) {
2357 changeMenuLevels(menu
, lower
);
2363 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2368 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2369 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2373 /* can't touch the menu copy */
2374 if (menu
->flags
.brother
)
2377 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2380 if (event
->xbutton
.state
& MOD_MASK
) {
2381 wLowerFrame(menu
->frame
->core
);
2384 wRaiseFrame(menu
->frame
->core
);
2389 /* lower/raise all submenus */
2391 if (tmp
->selected_entry
>=0 && tmp
->cascades
2392 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2393 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2394 if (!tmp
|| !tmp
->flags
.mapped
)
2397 wLowerFrame(tmp
->frame
->core
);
2399 wRaiseFrame(tmp
->frame
->core
);
2405 /* tear off the menu if it's a root menu or a cascade
2407 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2408 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2409 menu
->flags
.buttoned
=1;
2410 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2412 /* turn off selected menu entry in parent menu */
2413 selectEntry(menu
->parent
, -1);
2415 /* make parent map the copy in place of the original */
2416 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2417 if (menu
->parent
->cascades
[i
] == menu
) {
2418 menu
->parent
->cascades
[i
] = menu
->brother
;
2427 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2428 |ExposureMask
, &ev
);
2432 x
+= ev
.xmotion
.x_root
- dx
;
2433 y
+= ev
.xmotion
.y_root
- dy
;
2434 dx
= ev
.xmotion
.x_root
;
2435 dy
= ev
.xmotion
.y_root
;
2436 wMenuMove(menu
, x
, y
, True
);
2438 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2439 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2441 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2442 ButtonMotionMask
|ButtonReleaseMask
2444 GrabModeAsync
, GrabModeAsync
, None
,
2445 wCursor
[WCUR_MOVE
], CurrentTime
);
2454 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2456 XUngrabPointer(dpy
, CurrentTime
);
2467 *----------------------------------------------------------------------
2469 * Handles mouse click on the close button of menus. The menu is
2470 * closed when the button is clicked.
2473 * The closed menu is reinserted at it's parent menus
2475 *----------------------------------------------------------------------
2478 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2480 WMenu
*menu
= (WMenu
*)data
;
2481 WMenu
*parent
= menu
->parent
;
2485 for (i
=0; i
<parent
->cascade_no
; i
++) {
2486 /* find the entry that points to the copy */
2487 if (parent
->cascades
[i
] == menu
->brother
) {
2488 /* make it point to the original */
2489 parent
->cascades
[i
] = menu
;
2490 menu
->parent
= parent
;
2500 saveMenuInfo(WMPropList
*dict
, WMenu
*menu
, WMPropList
*key
)
2502 WMPropList
*value
, *list
;
2505 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2506 value
= WMCreatePLString(buffer
);
2507 list
= WMCreatePLArray(value
, NULL
);
2508 if (menu
->flags
.lowered
)
2509 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2510 WMPutInPLDictionary(dict
, key
, list
);
2511 WMReleasePropList(value
);
2512 WMReleasePropList(list
);
2517 wMenuSaveState(WScreen
*scr
)
2519 WMPropList
*menus
, *key
;
2522 menus
= WMCreatePLDictionary(NULL
, NULL
);
2525 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2526 key
= WMCreatePLString("SwitchMenu");
2527 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2528 WMReleasePropList(key
);
2532 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2536 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2537 key
= WMCreatePLString("WorkspaceMenu");
2538 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2539 WMReleasePropList(key
);
2544 key
= WMCreatePLString("Menus");
2545 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2546 WMReleasePropList(key
);
2548 WMReleasePropList(menus
);
2555 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2560 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2563 len
= strlen(menu
->frame
->title
);
2568 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2573 strcat(buffer
, "\\");
2574 strcat(buffer
, menu
->frame
->title
);
2581 saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
)
2584 int save_menus
= 0, i
;
2589 if (menu
->flags
.brother
)
2590 menu
= menu
->brother
;
2592 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2595 ok
= getMenuPath(menu
, buffer
, 510);
2598 key
= WMCreatePLString(buffer
);
2599 saveMenuInfo(menus
, menu
, key
);
2600 WMReleasePropList(key
);
2606 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2607 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2616 #define COMPLAIN(key) wwarning(_("bad value in menus state info: %s"), key)
2620 getMenuInfo(WMPropList
*info
, int *x
, int *y
, Bool
*lowered
)
2626 if (WMIsPLArray(info
)) {
2628 pos
= WMGetFromPLArray(info
, 0);
2629 flags
= WMGetFromPLArray(info
, 1);
2630 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2631 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2638 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2639 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
)!=2)
2640 COMPLAIN("Position");
2642 COMPLAIN("(position, flags...)");
2651 restoreMenu(WScreen
*scr
, WMPropList
*menu
, int which
)
2654 Bool lowered
= False
;
2655 WMenu
*pmenu
= NULL
;
2660 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2665 if (which
& WSS_SWITCHMENU
) {
2666 OpenSwitchMenu(scr
, x
, y
, False
);
2667 pmenu
= scr
->switch_menu
;
2672 int width
= MENUW(pmenu
);
2673 int height
= MENUH(pmenu
);
2674 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2677 changeMenuLevels(pmenu
, True
);
2680 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2681 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2682 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2683 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2685 wMenuMove(pmenu
, x
, y
, True
);
2686 pmenu
->flags
.buttoned
= 1;
2687 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2696 restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
)
2698 WMPropList
*key
, *entry
;
2703 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2706 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2707 key
= WMCreatePLString(buffer
);
2708 entry
= WMGetFromPLDictionary(menus
, key
);
2711 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2713 if (!menu
->flags
.mapped
) {
2714 int width
= MENUW(menu
);
2715 int height
= MENUH(menu
);
2716 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2718 wMenuMapAt(menu
, x
, y
, False
);
2721 /* make parent map the copy in place of the original */
2722 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2723 if (menu
->parent
->cascades
[i
] == menu
) {
2724 menu
->parent
->cascades
[i
] = menu
->brother
;
2730 changeMenuLevels(menu
, True
);
2733 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2734 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2735 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2736 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2738 wMenuMove(menu
, x
, y
, True
);
2739 menu
->flags
.buttoned
= 1;
2740 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2745 WMReleasePropList(key
);
2747 for (i
=0; i
<menu
->cascade_no
; i
++) {
2748 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2758 wMenuRestoreState(WScreen
*scr
)
2760 WMPropList
*menus
, *menu
, *key
, *skey
;
2762 if (!scr
->session_state
) {
2766 key
= WMCreatePLString("Menus");
2767 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2768 WMReleasePropList(key
);
2775 skey
= WMCreatePLString("SwitchMenu");
2776 menu
= WMGetFromPLDictionary(menus
, skey
);
2777 WMReleasePropList(skey
);
2778 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2781 if (!scr
->root_menu
) {
2782 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2783 wMenuUnmap(scr
->root_menu
);
2785 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2791 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2793 WMenu
*menu
, *parent
;
2797 if (!scr
->root_menu
) {
2798 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2799 wMenuUnmap(scr
->root_menu
);
2802 menu
= scr
->workspace_menu
;
2804 if (menu
->flags
.mapped
) {
2805 if (!menu
->flags
.buttoned
) {
2807 parent
= menu
->parent
;
2808 if (parent
&& parent
->selected_entry
>= 0) {
2809 entry
= parent
->entries
[parent
->selected_entry
];
2810 if (parent
->cascades
[entry
->cascade
] == menu
) {
2811 selectEntry(parent
, -1);
2812 wMenuMapAt(menu
, x
, y
, False
);
2816 wRaiseFrame(menu
->frame
->core
);
2817 wMenuMapCopyAt(menu
, x
, y
);
2820 wMenuMapAt(menu
, x
, y
, False
);