1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1997, 1998 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
37 #include "WindowMaker.h"
47 /****** Global Variables ******/
49 extern Cursor wCursor
[WCUR_LAST
];
51 extern XContext wWinContext
;
53 extern WPreferences wPreferences
;
55 #define MOD_MASK wPreferences.modifier_mask
57 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
58 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
62 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
63 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
66 /***** Local Stuff ******/
71 } menuScrollParameters
[5] = {
72 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
73 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
74 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
75 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
76 {MENU_SCROLL_STEPS_U
, MENU_SCROLL_DELAY_U
}};
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(proplist_t menus
, WScreen
*scr
, WMenu
*menu
);
91 static int restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
);
94 static void selectEntry(WMenu
*menu
, int entry_no
);
95 static void closeCascade(WMenu
*menu
);
98 /****** Notification Observers ******/
101 appearanceObserver(void *self
, WMNotification
*notif
)
103 WMenu
*menu
= (WMenu
*)self
;
104 int flags
= (int)WMGetNotificationClientData(notif
);
106 if (!menu
->flags
.realized
)
109 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
110 if (flags
& WFontSettings
) {
111 menu
->flags
.realized
= 0;
114 if (flags
& WTextureSettings
) {
115 if (!menu
->flags
.brother
)
118 if (flags
& (WTextureSettings
|WColorSettings
)) {
121 } else if (menu
->flags
.titled
) {
123 if (flags
& WFontSettings
) {
124 menu
->flags
.realized
= 0;
127 if (flags
& WTextureSettings
) {
128 menu
->frame
->flags
.need_texture_remake
= 1;
130 if (flags
& (WColorSettings
|WTextureSettings
)) {
131 wFrameWindowPaint(menu
->frame
);
136 /************************************/
140 *----------------------------------------------------------------------
142 * Creates a new empty menu with the specified title. If main_menu
143 * is True, the created menu will be a main menu, which has some special
144 * properties such as being placed over other normal menus.
145 * If title is NULL, the menu will have no titlebar.
149 *----------------------------------------------------------------------
152 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
155 static int brother
=0;
158 menu
= wmalloc(sizeof(WMenu
));
160 memset(menu
, 0, sizeof(WMenu
));
162 #ifdef SINGLE_MENULEVEL
163 tmp
= WMSubmenuLevel
;
165 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
168 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
170 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
171 menu
->flags
.titled
= 1;
174 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
175 screen
->menu_title_texture
, NULL
,
176 screen
->menu_title_pixel
,
177 #ifdef DRAWSTRING_PLUGIN
180 &screen
->menu_title_gc
,
181 &screen
->menu_title_font
);
183 menu
->frame
->core
->descriptor
.parent
= menu
;
184 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
185 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
187 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
190 menu
->frame
->title
= wstrdup(title
);
193 menu
->frame
->flags
.justification
= WTJ_LEFT
;
195 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
198 menu
->alloced_entries
= 0;
199 menu
->selected_entry
= -1;
200 menu
->entries
= NULL
;
202 menu
->frame_x
= screen
->app_menu_x
;
203 menu
->frame_y
= screen
->app_menu_y
;
205 menu
->frame
->child
= menu
;
207 menu
->flags
.lowered
= 0;
211 /* setup object descriptors */
212 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
213 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
216 menu
->frame
->on_click_right
= menuCloseClick
;
219 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
220 menu
->frame
->core
->width
, 10);
222 menu
->menu
->descriptor
.parent
= menu
;
223 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
224 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
225 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
227 menu
->menu_texture_data
= None
;
229 XMapWindow(dpy
, menu
->menu
->window
);
235 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
237 menu
->brother
->flags
.brother
= 1;
238 menu
->brother
->brother
= menu
;
240 WMAddNotificationObserver(appearanceObserver
, menu
,
241 WNMenuAppearanceSettingsChanged
, menu
);
243 WMAddNotificationObserver(appearanceObserver
, menu
,
244 WNMenuTitleAppearanceSettingsChanged
, menu
);
254 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
258 menu
= wMenuCreate(screen
, title
, main_menu
);
261 menu
->flags
.app_menu
= 1;
262 menu
->brother
->flags
.app_menu
= 1;
270 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
274 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
275 menu
->entries
[i
]->order
++;
276 menu
->entries
[i
+1] = menu
->entries
[i
];
278 menu
->entries
[index
] = entry
;
283 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
284 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
289 menu
->flags
.realized
= 0;
290 menu
->brother
->flags
.realized
= 0;
292 /* reallocate array if it's too small */
293 if (menu
->entry_no
>= menu
->alloced_entries
) {
296 tmp
= wrealloc(menu
->entries
,
297 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
300 menu
->alloced_entries
+= 5;
302 menu
->brother
->entries
= tmp
;
303 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
305 entry
= wmalloc(sizeof(WMenuEntry
));
306 memset(entry
, 0, sizeof(WMenuEntry
));
307 entry
->flags
.enabled
= 1;
308 entry
->text
= wstrdup(text
);
310 entry
->clientdata
= clientdata
;
311 entry
->callback
= callback
;
312 if (index
<0 || index
>=menu
->entry_no
) {
313 entry
->order
= menu
->entry_no
;
314 menu
->entries
[menu
->entry_no
] = entry
;
316 entry
->order
= index
;
317 insertEntry(menu
, entry
, index
);
321 menu
->brother
->entry_no
= menu
->entry_no
;
329 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
331 WMenu
*brother
= menu
->brother
;
334 assert(menu
->flags
.brother
==0);
336 if (entry
->cascade
>=0) {
337 menu
->flags
.realized
= 0;
338 brother
->flags
.realized
= 0;
341 cascade
->parent
= menu
;
343 cascade
->brother
->parent
= brother
;
346 for (i
=0; i
<menu
->cascade_no
; i
++) {
347 if (menu
->cascades
[i
]==NULL
) {
348 menu
->cascades
[i
] = cascade
;
349 brother
->cascades
[i
] = cascade
->brother
;
356 entry
->cascade
= menu
->cascade_no
;
358 menu
->cascades
= wrealloc(menu
->cascades
,
359 sizeof(WMenu
)*(menu
->cascade_no
+1));
360 menu
->cascades
[menu
->cascade_no
++] = cascade
;
363 brother
->cascades
= wrealloc(brother
->cascades
,
364 sizeof(WMenu
)*(brother
->cascade_no
+1));
365 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
369 if (menu
->flags
.lowered
) {
371 cascade
->flags
.lowered
= 1;
372 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
374 cascade
->brother
->flags
.lowered
= 1;
375 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
378 if (!menu
->flags
.realized
)
384 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
386 assert(menu
->flags
.brother
==0);
388 /* destroy cascade menu */
389 if (entry
->cascade
>=0 && menu
->cascades
390 && menu
->cascades
[entry
->cascade
]!=NULL
) {
392 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
394 menu
->cascades
[entry
->cascade
] = NULL
;
395 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
403 wMenuRemoveItem(WMenu
*menu
, int index
)
407 if (menu
->flags
.brother
) {
408 wMenuRemoveItem(menu
->brother
, index
);
412 if (index
>=menu
->entry_no
) return;
414 /* destroy cascade menu */
415 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
417 /* destroy unshared data */
419 if (menu
->entries
[index
]->text
)
420 free(menu
->entries
[index
]->text
);
422 if (menu
->entries
[index
]->rtext
)
423 free(menu
->entries
[index
]->rtext
);
425 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
426 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
428 free(menu
->entries
[index
]);
430 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
431 menu
->entries
[i
+1]->order
--;
432 menu
->entries
[i
]=menu
->entries
[i
+1];
435 menu
->brother
->entry_no
--;
440 renderTexture(WMenu
*menu
)
448 WScreen
*scr
= menu
->menu
->screen_ptr
;
449 WTexture
*texture
= scr
->menu_item_texture
;
451 if (wPreferences
.menu_style
== MS_NORMAL
) {
452 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
453 menu
->entry_height
, WREL_MENUENTRY
);
455 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
456 menu
->menu
->height
+1, WREL_MENUENTRY
);
459 wwarning(_("could not render texture: %s"),
460 RMessageForError(RErrorCode
));
465 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
467 light
.red
= light
.green
= light
.blue
= 80;
470 dark
.red
= dark
.green
= dark
.blue
= 0;
473 mid
.red
= mid
.green
= mid
.blue
= 40;
475 for (i
= 1; i
< menu
->entry_no
; i
++) {
476 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
477 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
479 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
480 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
482 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
483 menu
->menu
->width
-1, i
*menu
->entry_height
,
487 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
488 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
497 updateTexture(WMenu
*menu
)
499 WScreen
*scr
= menu
->menu
->screen_ptr
;
501 /* setup background texture */
502 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
503 if (!menu
->flags
.brother
) {
504 FREE_PIXMAP(menu
->menu_texture_data
);
506 menu
->menu_texture_data
= renderTexture(menu
);
508 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
509 menu
->menu_texture_data
);
510 XClearWindow(dpy
, menu
->menu
->window
);
512 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
513 menu
->menu_texture_data
);
514 XClearWindow(dpy
, menu
->brother
->menu
->window
);
517 XSetWindowBackground(dpy
, menu
->menu
->window
,
518 scr
->menu_item_texture
->any
.color
.pixel
);
519 XClearWindow(dpy
, menu
->menu
->window
);
525 wMenuRealize(WMenu
*menu
)
528 int width
, rwidth
, mrwidth
, mwidth
;
529 int theight
, twidth
, eheight
;
530 WScreen
*scr
= menu
->frame
->screen_ptr
;
531 static int brother_done
=0;
536 wMenuRealize(menu
->brother
);
540 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
541 if (menu
->flags
.titled
)
542 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
544 wFrameWindowUpdateBorders(menu
->frame
, flags
);
546 if (menu
->flags
.titled
) {
547 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
548 strlen(menu
->frame
->title
));
549 theight
= menu
->frame
->top_width
;
550 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
555 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
556 menu
->entry_height
= eheight
;
559 for (i
=0; i
<menu
->entry_no
; i
++) {
562 /* search widest text */
563 text
= menu
->entries
[i
]->text
;
564 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
566 if (menu
->entries
[i
]->flags
.indicator
) {
567 width
+= MENU_INDICATOR_SPACE
;
573 /* search widest text on right */
574 text
= menu
->entries
[i
]->rtext
;
576 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
578 else if (menu
->entries
[i
]->cascade
>=0)
583 if (rwidth
> mrwidth
)
592 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
594 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
595 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
600 menu
->flags
.realized
= 1;
602 if (menu
->flags
.mapped
)
604 if (menu
->brother
->flags
.mapped
)
605 wMenuPaint(menu
->brother
);
610 wMenuDestroy(WMenu
*menu
, int recurse
)
614 WMRemoveNotificationObserver(menu
);
616 /* remove any pending timers */
618 WMDeleteTimerHandler(menu
->timer
);
621 /* call destroy handler */
622 if (menu
->on_destroy
)
623 (*menu
->on_destroy
)(menu
);
625 /* Destroy items if this menu own them. If this is the "brother" menu,
626 * leave them alone as it is shared by them.
628 if (!menu
->flags
.brother
) {
629 for (i
=0; i
<menu
->entry_no
; i
++) {
631 free(menu
->entries
[i
]->text
);
633 if (menu
->entries
[i
]->rtext
)
634 free(menu
->entries
[i
]->rtext
);
637 if (menu
->entries
[i
]->instances
){
638 PLRelease(menu
->entries
[i
]->instances
);
640 #endif /* USER_MENU */
642 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
643 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
645 free(menu
->entries
[i
]);
649 for (i
=0; i
<menu
->cascade_no
; i
++) {
650 if (menu
->cascades
[i
]) {
651 if (menu
->cascades
[i
]->flags
.brother
)
652 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
654 wMenuDestroy(menu
->cascades
[i
], recurse
);
664 FREE_PIXMAP(menu
->menu_texture_data
);
667 free(menu
->cascades
);
669 wCoreDestroy(menu
->menu
);
670 wFrameWindowDestroy(menu
->frame
);
672 /* destroy copy of this menu */
673 if (!menu
->flags
.brother
&& menu
->brother
)
674 wMenuDestroy(menu
->brother
, False
);
686 drawFrame(WScreen
*scr
, Window win
, int y
, int w
, int h
, int type
)
692 segs
[i
].x1
= segs
[i
].x2
= w
-1;
694 segs
[i
].y2
= y
+ h
- 1;
696 if (type
!= F_TOP
&& type
!= F_NONE
) {
698 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
702 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
708 segs
[i
].y2
= y
+ h
- 1;
710 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
717 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
719 if (type
!= F_TOP
&& type
!= F_NONE
)
720 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
726 paintEntry(WMenu
*menu
, int index
, int selected
)
730 GC light
, dim
, dark
, textGC
;
731 WScreen
*scr
=menu
->frame
->screen_ptr
;
732 Window win
= menu
->menu
->window
;
733 WMenuEntry
*entry
=menu
->entries
[index
];
735 if (!menu
->flags
.realized
) return;
736 h
= menu
->entry_height
;
737 w
= menu
->menu
->width
;
740 light
= scr
->menu_item_auxtexture
->light_gc
;
741 dim
= scr
->menu_item_auxtexture
->dim_gc
;
742 dark
= scr
->menu_item_auxtexture
->dark_gc
;
744 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
747 else if (index
== menu
->entry_no
- 1)
755 /* paint background */
757 XSetForeground(dpy
, scr
->select_menu_gc
, scr
->select_pixel
);
758 XFillRectangle(dpy
, win
, scr
->select_menu_gc
, 1, y
+1, w
-2, h
-3);
759 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
760 drawFrame(scr
, win
, y
, w
, h
, type
);
762 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
763 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
765 drawFrame(scr
, win
, y
, w
, h
, type
);
767 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
772 textGC
= scr
->select_menu_gc
;
773 if (entry
->flags
.enabled
)
774 XSetForeground(dpy
, textGC
, scr
->select_text_pixel
);
776 XSetForeground(dpy
, textGC
, scr
->dtext_pixel
);
777 } else if (!entry
->flags
.enabled
) {
778 textGC
= scr
->disabled_menu_entry_gc
;
780 textGC
= scr
->menu_entry_gc
;
784 if (entry
->flags
.indicator
)
785 x
+= MENU_INDICATOR_SPACE
+ 2;
787 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
,
788 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
790 if (entry
->cascade
>=0) {
791 /* draw the cascade indicator */
792 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
793 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
794 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
798 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
803 switch (entry
->flags
.indicator_type
) {
805 indicator
= scr
->menu_check_indicator
;
808 indicator
= scr
->menu_mini_indicator
;
811 indicator
= scr
->menu_hide_indicator
;
814 indicator
= scr
->menu_shade_indicator
;
818 indicator
= scr
->menu_radio_indicator
;
822 iw
= indicator
->width
;
823 ih
= indicator
->height
;
824 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
825 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
827 XSetForeground(dpy
, scr
->copy_gc
, scr
->black_pixel
);
829 XSetForeground(dpy
, scr
->copy_gc
, scr
->mtext_pixel
);
830 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
832 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
833 iw, ih, 5, y+(h-ih)/2);
835 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
838 /* draw right text */
840 if (entry
->rtext
&& entry
->cascade
<0) {
841 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
842 strlen(entry
->rtext
));
844 WMDrawString(scr
->wmscreen
, win
, textGC
, scr
->menu_entry_font
, w
-6-tw
,
845 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
851 move_menus(WMenu
*menu
, int x
, int y
)
853 while (menu
->parent
) {
856 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
857 y
-= menu
->selected_entry
*menu
->entry_height
;
860 wMenuMove(menu
, x
, y
, True
);
864 makeVisible(WMenu
*menu
)
866 WScreen
*scr
= menu
->frame
->screen_ptr
;
867 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
869 if (menu
->entry_no
<0) return;
872 y1
= menu
->frame_y
+menu
->frame
->top_width
873 + menu
->selected_entry
*menu
->entry_height
;
874 x2
= x1
+ MENUW(menu
);
875 y2
= y1
+ menu
->entry_height
;
884 } else if (x2
>= scr
->scr_width
) {
885 new_x
= scr
->scr_width
- MENUW(menu
) - 1;
892 } else if (y2
>= scr
->scr_height
) {
893 new_y
= scr
->scr_height
- menu
->entry_height
- 1;
897 new_y
= new_y
- menu
->frame
->top_width
898 - menu
->selected_entry
*menu
->entry_height
;
899 move_menus(menu
, new_x
, new_y
);
904 check_key(WMenu
*menu
, XKeyEvent
*event
)
909 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
912 ch
= toupper(buffer
[0]);
914 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
917 for (i
=s
; i
<menu
->entry_no
; i
++) {
918 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
922 /* no match. Retry from start, if previous started from a selected entry */
932 keyboardMenu(WMenu
*menu
)
935 KeySym ksym
=NoSymbol
;
939 int old_pos_x
= menu
->frame_x
;
940 int old_pos_y
= menu
->frame_y
;
941 int new_x
= old_pos_x
, new_y
= old_pos_y
;
942 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
943 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
945 if (menu
->flags
.editing
)
949 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
950 GrabModeAsync
, CurrentTime
);
952 if (menu
->frame_y
+menu
->frame
->top_width
>= scr_height
)
953 new_y
= scr_height
- menu
->frame
->top_width
;
955 if (menu
->frame_x
+MENUW(menu
) >= scr_width
)
956 new_x
= scr_width
-MENUW(menu
)-1;
958 move_menus(menu
, new_x
, new_y
);
960 while (!done
&& menu
->flags
.mapped
) {
961 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
962 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
963 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
964 |SubstructureNotifyMask
, &event
);
966 switch (event
.type
) {
968 ksym
= XLookupKeysym(&event
.xkey
, 0);
976 selectEntry(menu
, 0);
982 selectEntry(menu
, menu
->entry_no
-1);
991 if (menu
->selected_entry
<= 0)
992 selectEntry(menu
, menu
->entry_no
-1);
994 selectEntry(menu
, menu
->selected_entry
-1);
1003 if (menu
->selected_entry
<0)
1004 selectEntry(menu
, 0);
1005 else if (menu
->selected_entry
== menu
->entry_no
-1)
1006 selectEntry(menu
, 0);
1007 else if (menu
->selected_entry
< menu
->entry_no
-1)
1008 selectEntry(menu
, menu
->selected_entry
+1);
1013 #ifdef ARROWLESS_KBD
1017 if (menu
->selected_entry
>=0) {
1019 entry
= menu
->entries
[menu
->selected_entry
];
1021 if (entry
->cascade
>= 0 && menu
->cascades
1022 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1024 XUngrabKeyboard(dpy
, CurrentTime
);
1026 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1027 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1030 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1031 GrabModeAsync
, GrabModeAsync
,
1038 #ifdef ARROWLESS_KBD
1042 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1043 selectEntry(menu
, -1);
1044 move_menus(menu
, old_pos_x
, old_pos_y
);
1054 index
= check_key(menu
, &event
.xkey
);
1056 selectEntry(menu
, index
);
1062 if (event
.type
==ButtonPress
)
1065 WMHandleEvent(&event
);
1069 XUngrabKeyboard(dpy
, CurrentTime
);
1071 if (done
==2 && menu
->selected_entry
>=0) {
1072 entry
= menu
->entries
[menu
->selected_entry
];
1077 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1078 && entry
->cascade
< 0) {
1079 #if (MENU_BLINK_COUNT > 0)
1080 int sel
= menu
->selected_entry
;
1083 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1084 paintEntry(menu
, sel
, False
);
1086 wusleep(MENU_BLINK_DELAY
);
1087 paintEntry(menu
, sel
, True
);
1089 wusleep(MENU_BLINK_DELAY
);
1092 selectEntry(menu
, -1);
1094 if (!menu
->flags
.buttoned
) {
1096 move_menus(menu
, old_pos_x
, old_pos_y
);
1100 (*entry
->callback
)(menu
, entry
);
1102 if (!menu
->flags
.buttoned
) {
1104 move_menus(menu
, old_pos_x
, old_pos_y
);
1106 selectEntry(menu
, -1);
1110 /* returns True if returning from a submenu to a parent menu,
1111 * False if exiting from menu */
1117 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1119 int scr_width
= menu
->frame
->screen_ptr
->scr_width
;
1120 int scr_height
= menu
->frame
->screen_ptr
->scr_height
;
1122 if (!menu
->flags
.realized
) {
1123 menu
->flags
.realized
=1;
1126 if (!menu
->flags
.mapped
) {
1127 if (wPreferences
.wrap_menus
) {
1130 if (x
+MENUW(menu
) > scr_width
)
1131 x
= scr_width
- MENUW(menu
);
1132 if (y
+MENUH(menu
) > scr_height
)
1133 y
= scr_height
- MENUH(menu
);
1136 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1139 XMapWindow(dpy
, menu
->frame
->core
->window
);
1140 wRaiseFrame(menu
->frame
->core
);
1141 menu
->flags
.mapped
= 1;
1143 selectEntry(menu
, 0);
1152 wMenuMap(WMenu
*menu
)
1154 if (!menu
->flags
.realized
) {
1155 menu
->flags
.realized
=1;
1158 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1159 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1160 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1161 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1163 XMapWindow(dpy
, menu
->frame
->core
->window
);
1164 wRaiseFrame(menu
->frame
->core
);
1165 menu
->flags
.mapped
= 1;
1170 wMenuUnmap(WMenu
*menu
)
1174 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1175 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1176 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1178 menu
->flags
.buttoned
= 0;
1179 menu
->flags
.mapped
= 0;
1180 menu
->flags
.open_to_left
= 0;
1182 for (i
=0; i
<menu
->cascade_no
; i
++) {
1183 if (menu
->cascades
[i
]!=NULL
1184 && menu
->cascades
[i
]->flags
.mapped
1185 && !menu
->cascades
[i
]->flags
.buttoned
) {
1187 wMenuUnmap(menu
->cascades
[i
]);
1190 menu
->selected_entry
= -1;
1196 wMenuPaint(WMenu
*menu
)
1200 if (!menu
->flags
.mapped
) {
1205 for (i
=0; i
<menu
->entry_no
; i
++) {
1206 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1212 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1214 if (index
>=menu
->entry_no
) return;
1215 menu
->entries
[index
]->flags
.enabled
=enable
;
1216 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1217 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1221 /* ====================================================================== */
1225 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1229 WObjDescriptor
*desc
;
1235 menu
->flags
.editing
= 1;
1237 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1238 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1240 wTextPutText(text
, entry
->text
);
1241 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1242 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1244 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1245 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1246 wwarning("could not grab keyboard");
1249 wSetFocusTo(menu
->frame
->screen_ptr
,
1250 menu
->frame
->screen_ptr
->focused_window
);
1255 while (!done
&& !text
->done
) {
1257 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1259 WMNextEvent(dpy
, &event
);
1261 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1262 (XPointer
*)&desc
)==XCNOENT
)
1265 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1267 (*desc
->handle_anything
)(desc
, &event
);
1270 switch (event
.type
) {
1272 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1276 WMHandleEvent(&event
);
1282 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1284 wSetFocusTo(menu
->frame
->screen_ptr
,
1285 menu
->frame
->screen_ptr
->focused_window
);
1288 t
= wTextGetText(text
);
1289 /* if !t, the user has canceled editing */
1293 entry
->text
= wstrdup(t
);
1295 menu
->flags
.realized
= 0;
1299 XUngrabKeyboard(dpy
, CurrentTime
);
1301 if (t
&& menu
->on_edit
)
1302 (*menu
->on_edit
)(menu
, entry
);
1304 menu
->flags
.editing
= 0;
1306 if (!menu
->flags
.realized
)
1312 selectEntry(WMenu
*menu
, int entry_no
)
1318 if (menu
->entries
==NULL
)
1321 if (entry_no
>= menu
->entry_no
)
1324 old_entry
= menu
->selected_entry
;
1325 menu
->selected_entry
= entry_no
;
1327 if (old_entry
!=entry_no
) {
1329 /* unselect previous entry */
1331 paintEntry(menu
, old_entry
, False
);
1332 entry
= menu
->entries
[old_entry
];
1335 if (entry
->cascade
>=0 && menu
->cascades
) {
1336 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1337 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1343 menu
->selected_entry
= -1;
1346 entry
= menu
->entries
[entry_no
];
1348 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1349 /* Callback for when the submenu is opened.
1351 submenu
= menu
->cascades
[entry
->cascade
];
1352 if (submenu
&& submenu
->flags
.brother
)
1353 submenu
= submenu
->brother
;
1355 if (entry
->callback
) {
1356 /* Only call the callback if the submenu is not yet mapped.
1358 if (menu
->flags
.brother
) {
1359 if (!submenu
|| !submenu
->flags
.mapped
)
1360 (*entry
->callback
)(menu
->brother
, entry
);
1362 if (!submenu
|| !submenu
->flags
.buttoned
)
1363 (*entry
->callback
)(menu
, entry
);
1367 /* the submenu menu might have changed */
1368 submenu
= menu
->cascades
[entry
->cascade
];
1371 if (!submenu
->flags
.mapped
) {
1374 if (!submenu
->flags
.realized
)
1375 wMenuRealize(submenu
);
1376 if (wPreferences
.wrap_menus
) {
1377 if (menu
->flags
.open_to_left
)
1378 submenu
->flags
.open_to_left
= 1;
1380 if (submenu
->flags
.open_to_left
) {
1381 x
= menu
->frame_x
- MENUW(submenu
);
1384 submenu
->flags
.open_to_left
= 0;
1387 x
= menu
->frame_x
+ MENUW(menu
);
1389 if (x
+ MENUW(submenu
)
1390 >= menu
->frame
->screen_ptr
->scr_width
) {
1392 x
= menu
->frame_x
- MENUW(submenu
);
1393 submenu
->flags
.open_to_left
= 1;
1397 x
= menu
->frame_x
+ MENUW(menu
);
1400 if (wPreferences
.align_menus
) {
1403 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1404 if (menu
->flags
.titled
)
1405 y
+= menu
->frame
->top_width
;
1406 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1407 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1410 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1411 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1416 paintEntry(menu
, entry_no
, True
);
1422 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1425 WObjDescriptor
*desc
;
1426 Window root_ret
, win
, junk_win
;
1430 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1433 if (win
==None
) return NULL
;
1435 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1438 if (desc
->parent_type
== WCLASS_MENU
) {
1439 menu
= (WMenu
*)desc
->parent
;
1440 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1441 x_ret
, y_ret
, &junk_win
);
1451 closeCascade(WMenu
*menu
)
1453 WMenu
*parent
=menu
->parent
;
1455 if (menu
->flags
.brother
1456 || (!menu
->flags
.buttoned
1457 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1459 selectEntry(menu
, -1);
1461 #if (MENU_BLINK_DELAY > 2)
1462 wusleep(MENU_BLINK_DELAY
/2);
1466 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1467 || parent
->flags
.brother
)
1468 && !parent
->flags
.buttoned
) {
1469 selectEntry(parent
, -1);
1471 parent
= parent
->parent
;
1474 selectEntry(parent
, -1);
1480 closeBrotherCascadesOf(WMenu
*menu
)
1485 for (i
=0; i
<menu
->cascade_no
; i
++) {
1486 if (menu
->cascades
[i
]->flags
.brother
) {
1487 tmp
= menu
->cascades
[i
];
1489 tmp
= menu
->cascades
[i
]->brother
;
1491 if (tmp
->flags
.mapped
) {
1492 selectEntry(tmp
->parent
, -1);
1493 closeBrotherCascadesOf(tmp
);
1500 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1504 parentMenu(WMenu
*menu
)
1509 if (menu
->flags
.buttoned
)
1512 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1513 parent
= menu
->parent
;
1514 if (parent
->selected_entry
< 0)
1516 entry
= parent
->entries
[parent
->selected_entry
];
1517 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1518 parent
->cascades
[entry
->cascade
] != menu
)
1521 if (menu
->flags
.buttoned
)
1531 * Will raise the passed menu, if submenu = 0
1532 * If submenu > 0 will also raise all mapped submenus
1533 * until the first buttoned one
1534 * If submenu < 0 will also raise all mapped parent menus
1535 * until the first buttoned one
1539 raiseMenus(WMenu
*menu
, int submenus
)
1546 wRaiseFrame(menu
->frame
->core
);
1548 if (submenus
>0 && menu
->selected_entry
>=0) {
1549 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1550 if (i
>=0 && menu
->cascades
) {
1551 submenu
= menu
->cascades
[i
];
1552 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1553 raiseMenus(submenu
, submenus
);
1556 if (submenus
<0 && !menu
->flags
.buttoned
&&
1557 menu
->parent
&& menu
->parent
->flags
.mapped
)
1558 raiseMenus(menu
->parent
, submenus
);
1563 wMenuUnderPointer(WScreen
*screen
)
1565 WObjDescriptor
*desc
;
1566 Window root_ret
, win
;
1570 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1571 &dummy
, &dummy
, &mask
);
1573 if (win
==None
) return NULL
;
1575 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1578 if (desc
->parent_type
== WCLASS_MENU
)
1579 return (WMenu
*)desc
->parent
;
1585 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
1589 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1591 Window root_ret
, win
;
1595 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1600 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1602 WScreen
*scr
= menu
->menu
->screen_ptr
;
1603 int menuX1
= menu
->frame_x
;
1604 int menuY1
= menu
->frame_y
;
1605 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1606 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1607 int screenW
= scr
->scr_width
;
1608 int screenH
= scr
->scr_height
;
1614 getPointerPosition(scr
, &xroot
, &yroot
);
1616 #ifdef VIRTUAL_DESKTOP
1617 if (wPreferences
.vedge_thickness
) {
1618 if (xroot
<= wPreferences
.vedge_thickness
+ 1 && menuX1
< wPreferences
.vedge_thickness
) {
1619 /* scroll to the right */
1620 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX1
));
1622 } else if (xroot
>= screenW
-2-wPreferences
.vedge_thickness
&& menuX2
> screenW
-1-wPreferences
.vedge_thickness
) {
1623 /* scroll to the left */
1624 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1629 *hamount
= -*hamount
;
1634 if (xroot
<= 1 && menuX1
< 0) {
1635 /* scroll to the right */
1636 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX1
));
1638 } else if (xroot
>= screenW
-2 && menuX2
> screenW
-1) {
1639 /* scroll to the left */
1640 *hamount
= MIN(MENU_SCROLL_STEP
, abs(menuX2
-screenW
-1));
1645 *hamount
= -*hamount
;
1648 if (yroot
<= 1 && menuY1
< 0) {
1650 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY1
));
1652 } else if (yroot
>= screenH
-2 && menuY2
> screenH
-1) {
1654 *vamount
= MIN(MENU_SCROLL_STEP
, abs(menuY2
-screenH
-2));
1656 *vamount
= -*vamount
;
1662 dragScrollMenuCallback(void *data
)
1664 WMenu
*menu
= (WMenu
*)data
;
1665 WScreen
*scr
= menu
->menu
->screen_ptr
;
1666 WMenu
*parent
= parentMenu(menu
);
1667 int hamount
, vamount
;
1669 int newSelectedEntry
;
1671 getScrollAmount(menu
, &hamount
, &vamount
);
1674 if (hamount
!= 0 || vamount
!= 0) {
1675 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1676 parent
->frame_y
+ vamount
, True
);
1677 if (findMenu(scr
, &x
, &y
)) {
1678 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1679 selectEntry(menu
, newSelectedEntry
);
1681 /* Pointer fell outside of menu. If the selected entry is
1682 * not a submenu, unselect it */
1683 if (menu
->selected_entry
>= 0
1684 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1685 selectEntry(menu
, -1);
1686 newSelectedEntry
= 0;
1689 /* paranoid check */
1690 if (newSelectedEntry
>= 0) {
1691 /* keep scrolling */
1692 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1693 dragScrollMenuCallback
, menu
);
1698 /* don't need to scroll anymore */
1700 if (findMenu(scr
, &x
, &y
)) {
1701 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1702 selectEntry(menu
, newSelectedEntry
);
1709 scrollMenuCallback(void *data
)
1711 WMenu
*menu
= (WMenu
*)data
;
1712 WMenu
*parent
= parentMenu(menu
);
1713 int hamount
= 0; /* amount to scroll */
1716 getScrollAmount(menu
, &hamount
, &vamount
);
1718 if (hamount
!= 0 || vamount
!= 0) {
1719 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1720 parent
->frame_y
+ vamount
, True
);
1722 /* keep scrolling */
1723 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1724 scrollMenuCallback
, menu
);
1726 /* don't need to scroll anymore */
1733 #define MENU_SCROLL_BORDER 5
1736 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1738 int menuX1
= menu
->frame_x
;
1739 int menuY1
= menu
->frame_y
;
1740 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1741 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1742 int scrXe
= menu
->menu
->screen_ptr
->scr_width
-1;
1743 int scrYe
= menu
->menu
->screen_ptr
->scr_height
-1;
1746 if (x
>= menuX1
&& x
<= menuX2
&& (y
< MENU_SCROLL_BORDER
1747 || y
> scrYe
-MENU_SCROLL_BORDER
))
1749 else if (y
>= menuY1
&& y
<= menuY2
&& (x
< MENU_SCROLL_BORDER
1750 || x
> scrXe
-MENU_SCROLL_BORDER
))
1757 typedef struct _delay
{
1765 _leaving(_delay
*dl
)
1767 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1768 dl
->menu
->jump_back
=NULL
;
1769 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1775 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1778 WMenu
*omenu
= parentMenu(menu
);
1779 WScreen
*scr
= menu
->frame
->screen_ptr
;
1782 int old_frame_x
= omenu
->frame_x
;
1783 int old_frame_y
= omenu
->frame_y
;
1786 if (omenu
->jump_back
)
1787 WMDeleteTimerWithClientData(omenu
->jump_back
);
1790 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1791 || omenu
->flags
.app_menu
) {
1795 if (!wPreferences
.wrap_menus
)
1796 raiseMenus(omenu
, True
);
1798 raiseMenus(menu
, False
);
1801 scrollMenuCallback(menu
);
1804 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1806 WMNextEvent(dpy
, &ev
);
1811 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1812 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1814 /* on_border is != 0 if the pointer is between the menu
1815 * and the screen border and is close enough to the border */
1816 on_border
= isPointNearBoder(menu
, x
, y
);
1818 smenu
= wMenuUnderPointer(scr
);
1820 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1825 on_x_edge
= x
<= 1 || x
>= scr
->scr_width
- 2;
1826 on_y_edge
= y
<= 1 || y
>= scr
->scr_height
- 2;
1827 on_border
= on_x_edge
|| on_y_edge
;
1829 if (!on_border
&& !jump_back
) {
1834 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1835 WMDeleteTimerHandler(menu
->timer
);
1843 scrollMenuCallback(menu
);
1846 /* True if we push on title, or drag the omenu to other position */
1847 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1848 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1849 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1850 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1852 smenu
= wMenuUnderPointer(scr
);
1853 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1855 else if (smenu
==omenu
&& on_title
) {
1869 WMDeleteTimerHandler(menu
->timer
);
1875 if (!omenu
->jump_back
) {
1876 delayer
=wmalloc(sizeof(_delay
));
1877 delayer
->menu
=omenu
;
1878 delayer
->ox
=old_frame_x
;
1879 delayer
->oy
=old_frame_y
;
1880 omenu
->jump_back
=delayer
;
1881 scr
->flags
.jump_back_pending
= 1;
1883 else delayer
= omenu
->jump_back
;
1884 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1891 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1893 wMenuPaint(desc
->parent
);
1897 int *delayed_select
;
1904 delaySelection(void *data
)
1906 delay_data
*d
= (delay_data
*)data
;
1912 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1913 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1914 entry_no
= getEntryAt(menu
, x
, y
);
1915 selectEntry(menu
, entry_no
);
1917 if (d
->delayed_select
)
1918 *(d
->delayed_select
) = 0;
1923 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1925 XButtonEvent
*bev
= &event
->xbutton
;
1926 WMenu
*menu
= desc
->parent
;
1928 WScreen
*scr
=menu
->frame
->screen_ptr
;
1929 WMenuEntry
*entry
=NULL
;
1931 int close_on_exit
=0;
1933 int delayed_select
= 0;
1937 int old_frame_x
= 0;
1938 int old_frame_y
= 0;
1939 delay_data d_data
= {NULL
, NULL
, NULL
};
1941 if (!wPreferences
.wrap_menus
) {
1942 smenu
= parentMenu(menu
);
1943 old_frame_x
= smenu
->frame_x
;
1944 old_frame_y
= smenu
->frame_y
;
1945 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1946 /* This is true if the menu was launched with right click on root window */
1948 d_data
.delayed_select
= &delayed_select
;
1950 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1951 delaySelection
, &d_data
);
1954 if (menu
->flags
.inside_handler
) {
1957 menu
->flags
.inside_handler
= 1;
1959 wRaiseFrame(menu
->frame
->core
);
1961 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1963 smenu
= findMenu(scr
, &x
, &y
);
1971 if (menu
->flags
.editing
) {
1974 entry_no
= getEntryAt(menu
, x
, y
);
1976 entry
= menu
->entries
[entry_no
];
1978 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1979 && entry
->flags
.editable
) {
1980 editEntry(smenu
, entry
);
1982 } else if (bev
->state
& ControlMask
) {
1986 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1987 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
1989 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
1990 menu
->selected_entry
!=entry_no
) {
1991 wMenuUnmap(submenu
);
1993 if (!submenu
->flags
.mapped
&& !delayed_select
) {
1994 selectEntry(menu
, entry_no
);
1995 } else if (!submenu
->flags
.buttoned
) {
1996 selectEntry(menu
, -1);
1999 } else if (!delayed_select
) {
2000 selectEntry(menu
, entry_no
);
2003 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2005 dragScrollMenuCallback(menu
);
2009 prevx
= bev
->x_root
;
2010 prevy
= bev
->y_root
;
2014 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2016 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2017 |ButtonPressMask
, &ev
);
2020 smenu
= findMenu(scr
, &x
, &y
);
2022 if (smenu
== NULL
) {
2023 /* moved mouse out of menu */
2025 if (!delayed_select
&& d_data
.magic
) {
2026 WMDeleteTimerHandler(d_data
.magic
);
2027 d_data
.magic
= NULL
;
2030 || (menu
->selected_entry
>=0
2031 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2032 prevx
= ev
.xmotion
.x_root
;
2033 prevy
= ev
.xmotion
.y_root
;
2037 selectEntry(menu
, -1);
2039 prevx
= ev
.xmotion
.x_root
;
2040 prevy
= ev
.xmotion
.y_root
;
2042 } else if (menu
&& menu
!=smenu
2043 && (menu
->selected_entry
<0
2044 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2045 selectEntry(menu
, -1);
2047 if (!delayed_select
&& d_data
.magic
) {
2048 WMDeleteTimerHandler(d_data
.magic
);
2049 d_data
.magic
= NULL
;
2053 /* hysteresis for item selection */
2055 /* check if the motion was to the side, indicating that
2056 * the user may want to cross to a submenu */
2057 if (!delayed_select
&& menu
) {
2059 Bool moved_to_submenu
;/* moved to direction of submenu */
2061 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2063 moved_to_submenu
= False
;
2064 if (dx
> 0 /* if moved enough to the side */
2065 /* maybe a open submenu */
2066 && menu
->selected_entry
>=0
2067 /* moving to the right direction */
2068 && (wPreferences
.align_menus
2069 || ev
.xmotion
.y_root
>= prevy
)) {
2072 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2074 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2075 if (prevx
< ev
.xmotion
.x_root
)
2076 moved_to_submenu
= True
;
2078 if (prevx
> ev
.xmotion
.x_root
)
2079 moved_to_submenu
= True
;
2085 if (menu
!= smenu
) {
2087 WMDeleteTimerHandler(d_data
.magic
);
2089 d_data
.magic
= NULL
;
2090 } else if (moved_to_submenu
) {
2091 /* while we are moving, postpone the selection */
2093 WMDeleteTimerHandler(d_data
.magic
);
2095 d_data
.delayed_select
= NULL
;
2097 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2100 prevx
= ev
.xmotion
.x_root
;
2101 prevy
= ev
.xmotion
.y_root
;
2105 WMDeleteTimerHandler(d_data
.magic
);
2106 d_data
.magic
= NULL
;
2110 prevx
= ev
.xmotion
.x_root
;
2111 prevy
= ev
.xmotion
.y_root
;
2113 /* pointer crossed menus */
2114 if (menu
&& menu
->timer
) {
2115 WMDeleteTimerHandler(menu
->timer
);
2119 dragScrollMenuCallback(smenu
);
2123 dragScrollMenuCallback(menu
);
2125 if (!delayed_select
) {
2126 entry_no
= getEntryAt(menu
, x
, y
);
2128 entry
= menu
->entries
[entry_no
];
2129 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2131 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2132 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2133 && menu
->selected_entry
!=entry_no
) {
2134 wMenuUnmap(submenu
);
2138 selectEntry(menu
, entry_no
);
2146 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2156 if (menu
&& menu
->timer
) {
2157 WMDeleteTimerHandler(menu
->timer
);
2160 if (d_data
.magic
!=NULL
)
2161 WMDeleteTimerHandler(d_data
.magic
);
2163 if (menu
&& menu
->selected_entry
>=0) {
2164 entry
= menu
->entries
[menu
->selected_entry
];
2165 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2166 && entry
->cascade
< 0) {
2167 /* blink and erase menu selection */
2168 #if (MENU_BLINK_DELAY > 0)
2169 int sel
= menu
->selected_entry
;
2172 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2173 paintEntry(menu
, sel
, False
);
2175 wusleep(MENU_BLINK_DELAY
);
2176 paintEntry(menu
, sel
, True
);
2178 wusleep(MENU_BLINK_DELAY
);
2181 /* unmap the menu, it's parents and call the callback */
2182 if (!menu
->flags
.buttoned
&&
2183 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2186 selectEntry(menu
, -1);
2188 (*entry
->callback
)(menu
, entry
);
2190 /* If the user double clicks an entry, the entry will
2191 * be executed twice, which is not good for things like
2192 * the root menu. So, ignore any clicks that were generated
2193 * while the entry was being executed */
2194 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2196 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2197 selectEntry(menu
, -1);
2199 if (entry
->cascade
>=0 && menu
->cascades
2200 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2201 selectEntry(menu
, -1);
2206 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2207 closeCascade(desc
->parent
);
2209 /* close the cascade windows that should not remain opened */
2210 closeBrotherCascadesOf(desc
->parent
);
2212 if (!wPreferences
.wrap_menus
)
2213 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2216 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2221 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2230 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2232 if (submenus
>0 && menu
->selected_entry
>=0) {
2233 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2235 if (i
>=0 && menu
->cascades
) {
2236 submenu
= menu
->cascades
[i
];
2237 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2238 if (wPreferences
.align_menus
) {
2239 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2241 wMenuMove(submenu
, x
+ MENUW(menu
),
2242 y
+ submenu
->entry_height
*menu
->selected_entry
,
2248 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2249 !menu
->parent
->flags
.buttoned
) {
2250 if (wPreferences
.align_menus
) {
2251 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2253 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2254 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2262 changeMenuLevels(WMenu
*menu
, int lower
)
2267 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2269 wRaiseFrame(menu
->frame
->core
);
2270 menu
->flags
.lowered
= 0;
2272 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2273 wLowerFrame(menu
->frame
->core
);
2274 menu
->flags
.lowered
= 1;
2276 for (i
=0; i
<menu
->cascade_no
; i
++) {
2277 if (menu
->cascades
[i
]
2278 && !menu
->cascades
[i
]->flags
.buttoned
2279 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2280 changeMenuLevels(menu
->cascades
[i
], lower
);
2288 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2293 if (event
->xbutton
.state
& MOD_MASK
) {
2294 if (menu
->flags
.lowered
) {
2299 changeMenuLevels(menu
, lower
);
2305 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2310 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2311 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2315 /* can't touch the menu copy */
2316 if (menu
->flags
.brother
)
2319 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2322 if (event
->xbutton
.state
& MOD_MASK
) {
2323 wLowerFrame(menu
->frame
->core
);
2326 wRaiseFrame(menu
->frame
->core
);
2331 /* lower/raise all submenus */
2333 if (tmp
->selected_entry
>=0 && tmp
->cascades
2334 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2335 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2336 if (!tmp
|| !tmp
->flags
.mapped
)
2339 wLowerFrame(tmp
->frame
->core
);
2341 wRaiseFrame(tmp
->frame
->core
);
2347 /* tear off the menu if it's a root menu or a cascade
2349 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2350 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2351 menu
->flags
.buttoned
=1;
2352 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2354 /* turn off selected menu entry in parent menu */
2355 selectEntry(menu
->parent
, -1);
2357 /* make parent map the copy in place of the original */
2358 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2359 if (menu
->parent
->cascades
[i
] == menu
) {
2360 menu
->parent
->cascades
[i
] = menu
->brother
;
2369 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2370 |ExposureMask
, &ev
);
2374 x
+= ev
.xmotion
.x_root
- dx
;
2375 y
+= ev
.xmotion
.y_root
- dy
;
2376 dx
= ev
.xmotion
.x_root
;
2377 dy
= ev
.xmotion
.y_root
;
2378 wMenuMove(menu
, x
, y
, True
);
2380 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2381 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2383 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2384 ButtonMotionMask
|ButtonReleaseMask
2386 GrabModeAsync
, GrabModeAsync
, None
,
2387 wCursor
[WCUR_MOVE
], CurrentTime
);
2396 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2398 XUngrabPointer(dpy
, CurrentTime
);
2409 *----------------------------------------------------------------------
2411 * Handles mouse click on the close button of menus. The menu is
2412 * closed when the button is clicked.
2415 * The closed menu is reinserted at it's parent menus
2417 *----------------------------------------------------------------------
2420 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2422 WMenu
*menu
= (WMenu
*)data
;
2423 WMenu
*parent
= menu
->parent
;
2427 for (i
=0; i
<parent
->cascade_no
; i
++) {
2428 /* find the entry that points to the copy */
2429 if (parent
->cascades
[i
] == menu
->brother
) {
2430 /* make it point to the original */
2431 parent
->cascades
[i
] = menu
;
2432 menu
->parent
= parent
;
2442 saveMenuInfo(proplist_t dict
, WMenu
*menu
, proplist_t key
)
2444 proplist_t value
, list
;
2447 sprintf(buffer
, "%i,%i", menu
->frame_x
, menu
->frame_y
);
2448 value
= PLMakeString(buffer
);
2449 list
= PLMakeArrayFromElements(value
, NULL
);
2450 if (menu
->flags
.lowered
)
2451 PLAppendArrayElement(list
, PLMakeString("lowered"));
2452 PLInsertDictionaryEntry(dict
, key
, list
);
2459 wMenuSaveState(WScreen
*scr
)
2461 proplist_t menus
, key
;
2464 menus
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
2467 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2468 key
= PLMakeString("SwitchMenu");
2469 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2474 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2478 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2479 key
= PLMakeString("WorkspaceMenu");
2480 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2486 key
= PLMakeString("Menus");
2487 PLInsertDictionaryEntry(scr
->session_state
, key
, menus
);
2497 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2502 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2505 len
= strlen(menu
->frame
->title
);
2510 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2515 strcat(buffer
, "\\");
2516 strcat(buffer
, menu
->frame
->title
);
2523 saveMenuRecurs(proplist_t menus
, WScreen
*scr
, WMenu
*menu
)
2526 int save_menus
= 0, i
;
2531 if (menu
->flags
.brother
)
2532 menu
= menu
->brother
;
2534 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2537 ok
= getMenuPath(menu
, buffer
, 510);
2540 key
= PLMakeString(buffer
);
2541 saveMenuInfo(menus
, menu
, key
);
2548 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2549 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2558 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2562 getMenuInfo(proplist_t info
, int *x
, int *y
, Bool
*lowered
)
2568 if (PLIsArray(info
)) {
2570 pos
= PLGetArrayElement(info
, 0);
2571 flags
= PLGetArrayElement(info
, 1);
2572 if (flags
!= NULL
&& PLIsString(flags
) && PLGetString(flags
) != NULL
2573 && strcmp(PLGetString(flags
), "lowered") == 0) {
2580 if (pos
!= NULL
&& PLIsString(pos
)) {
2581 if (sscanf(PLGetString(pos
), "%i,%i", x
, y
)!=2)
2582 COMPLAIN("Position");
2584 COMPLAIN("(position, flags...)");
2593 restoreMenu(WScreen
*scr
, proplist_t menu
, int which
)
2596 Bool lowered
= False
;
2597 WMenu
*pmenu
= NULL
;
2602 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2607 if (which
& WSS_SWITCHMENU
) {
2608 OpenSwitchMenu(scr
, x
, y
, False
);
2609 pmenu
= scr
->switch_menu
;
2614 int width
= MENUW(pmenu
);
2615 int height
= MENUH(pmenu
);
2618 changeMenuLevels(pmenu
, True
);
2621 x
= (x
< -width
) ? 0 : x
;
2622 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2623 y
= (y
< 0) ? 0 : y
;
2624 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2625 wMenuMove(pmenu
, x
, y
, True
);
2626 pmenu
->flags
.buttoned
= 1;
2627 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2636 restoreMenuRecurs(WScreen
*scr
, proplist_t menus
, WMenu
*menu
, char *path
)
2638 proplist_t key
, entry
;
2643 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2646 sprintf(buffer
, "%s\\%s", path
, menu
->frame
->title
);
2647 key
= PLMakeString(buffer
);
2648 entry
= PLGetDictionaryEntry(menus
, key
);
2651 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2653 if (!menu
->flags
.mapped
) {
2654 int width
= MENUW(menu
);
2655 int height
= MENUH(menu
);
2657 wMenuMapAt(menu
, x
, y
, False
);
2660 /* make parent map the copy in place of the original */
2661 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2662 if (menu
->parent
->cascades
[i
] == menu
) {
2663 menu
->parent
->cascades
[i
] = menu
->brother
;
2669 changeMenuLevels(menu
, True
);
2671 x
= (x
< -width
) ? 0 : x
;
2672 x
= (x
> scr
->scr_width
) ? scr
->scr_width
- width
: x
;
2673 y
= (y
< 0) ? 0 : y
;
2674 y
= (y
> scr
->scr_height
) ? scr
->scr_height
- height
: y
;
2675 wMenuMove(menu
, x
, y
, True
);
2676 menu
->flags
.buttoned
= 1;
2677 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2684 for (i
=0; i
<menu
->cascade_no
; i
++) {
2685 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2695 wMenuRestoreState(WScreen
*scr
)
2697 proplist_t menus
, menu
, key
, skey
;
2699 key
= PLMakeString("Menus");
2700 menus
= PLGetDictionaryEntry(scr
->session_state
, key
);
2708 skey
= PLMakeString("SwitchMenu");
2709 menu
= PLGetDictionaryEntry(menus
, skey
);
2711 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2714 if (!scr
->root_menu
) {
2715 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2716 wMenuUnmap(scr
->root_menu
);
2718 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2726 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2728 WMenu
*menu
, *parent
;
2732 if (!scr
->root_menu
) {
2733 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2734 wMenuUnmap(scr
->root_menu
);
2737 menu
= scr
->workspace_menu
;
2739 if (menu
->flags
.mapped
) {
2740 if (!menu
->flags
.buttoned
) {
2742 parent
= menu
->parent
;
2743 if (parent
&& parent
->selected_entry
>= 0) {
2744 entry
= parent
->entries
[parent
->selected_entry
];
2745 if (parent
->cascades
[entry
->cascade
] == menu
) {
2746 selectEntry(parent
, -1);
2747 wMenuMapAt(menu
, x
, y
, False
);
2751 wRaiseFrame(menu
->frame
->core
);
2752 wMenuMapCopyAt(menu
, x
, y
);
2755 wMenuMapAt(menu
, x
, y
, False
);