1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
37 #include "WindowMaker.h"
48 /****** Global Variables ******/
50 extern Cursor wCursor
[WCUR_LAST
];
52 extern XContext wWinContext
;
54 extern WPreferences wPreferences
;
56 #define MOD_MASK wPreferences.modifier_mask
58 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
59 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
63 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
64 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
67 /***** Local Stuff ******/
72 } menuScrollParameters
[5] = {
73 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
74 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
75 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
76 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
77 {MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
80 static void menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
81 static void menuExpose(WObjDescriptor
*desc
, XEvent
*event
);
83 static void menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
84 static void menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
86 static void menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
88 static void updateTexture(WMenu
*menu
);
91 static int saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
);
92 static int restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
);
95 static void selectEntry(WMenu
*menu
, int entry_no
);
96 static void closeCascade(WMenu
*menu
);
99 /****** Notification Observers ******/
102 appearanceObserver(void *self
, WMNotification
*notif
)
104 WMenu
*menu
= (WMenu
*)self
;
105 int flags
= (int)WMGetNotificationClientData(notif
);
107 if (!menu
->flags
.realized
)
110 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
111 if (flags
& WFontSettings
) {
112 menu
->flags
.realized
= 0;
115 if (flags
& WTextureSettings
) {
116 if (!menu
->flags
.brother
)
119 if (flags
& (WTextureSettings
|WColorSettings
)) {
122 } else if (menu
->flags
.titled
) {
124 if (flags
& WFontSettings
) {
125 menu
->flags
.realized
= 0;
128 if (flags
& WTextureSettings
) {
129 menu
->frame
->flags
.need_texture_remake
= 1;
131 if (flags
& (WColorSettings
|WTextureSettings
)) {
132 wFrameWindowPaint(menu
->frame
);
137 /************************************/
141 *----------------------------------------------------------------------
143 * Creates a new empty menu with the specified title. If main_menu
144 * is True, the created menu will be a main menu, which has some special
145 * properties such as being placed over other normal menus.
146 * If title is NULL, the menu will have no titlebar.
150 *----------------------------------------------------------------------
153 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
156 static int brother
=0;
159 menu
= wmalloc(sizeof(WMenu
));
161 memset(menu
, 0, sizeof(WMenu
));
163 #ifdef SINGLE_MENULEVEL
164 tmp
= WMSubmenuLevel
;
166 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
169 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
171 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
172 menu
->flags
.titled
= 1;
175 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
176 screen
->menu_title_texture
, NULL
,
177 screen
->menu_title_color
,
178 &screen
->menu_title_font
);
180 menu
->frame
->core
->descriptor
.parent
= menu
;
181 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
182 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
184 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
187 menu
->frame
->title
= wstrdup(title
);
190 menu
->frame
->flags
.justification
= WTJ_LEFT
;
192 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
195 menu
->alloced_entries
= 0;
196 menu
->selected_entry
= -1;
197 menu
->entries
= NULL
;
199 menu
->frame_x
= screen
->app_menu_x
;
200 menu
->frame_y
= screen
->app_menu_y
;
202 menu
->frame
->child
= menu
;
204 menu
->flags
.lowered
= 0;
208 /* setup object descriptors */
209 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
210 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
213 menu
->frame
->on_click_right
= menuCloseClick
;
216 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
217 menu
->frame
->core
->width
, 10);
219 menu
->menu
->descriptor
.parent
= menu
;
220 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
221 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
222 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
224 menu
->menu_texture_data
= None
;
226 XMapWindow(dpy
, menu
->menu
->window
);
232 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
234 menu
->brother
->flags
.brother
= 1;
235 menu
->brother
->brother
= menu
;
237 WMAddNotificationObserver(appearanceObserver
, menu
,
238 WNMenuAppearanceSettingsChanged
, menu
);
240 WMAddNotificationObserver(appearanceObserver
, menu
,
241 WNMenuTitleAppearanceSettingsChanged
, menu
);
251 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
255 menu
= wMenuCreate(screen
, title
, main_menu
);
258 menu
->flags
.app_menu
= 1;
259 menu
->brother
->flags
.app_menu
= 1;
267 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
271 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
272 menu
->entries
[i
]->order
++;
273 menu
->entries
[i
+1] = menu
->entries
[i
];
275 menu
->entries
[index
] = entry
;
280 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
281 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
286 menu
->flags
.realized
= 0;
287 menu
->brother
->flags
.realized
= 0;
289 /* reallocate array if it's too small */
290 if (menu
->entry_no
>= menu
->alloced_entries
) {
293 tmp
= wrealloc(menu
->entries
,
294 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
297 menu
->alloced_entries
+= 5;
299 menu
->brother
->entries
= tmp
;
300 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
302 entry
= wmalloc(sizeof(WMenuEntry
));
303 memset(entry
, 0, sizeof(WMenuEntry
));
304 entry
->flags
.enabled
= 1;
305 entry
->text
= wstrdup(text
);
307 entry
->clientdata
= clientdata
;
308 entry
->callback
= callback
;
309 if (index
<0 || index
>=menu
->entry_no
) {
310 entry
->order
= menu
->entry_no
;
311 menu
->entries
[menu
->entry_no
] = entry
;
313 entry
->order
= index
;
314 insertEntry(menu
, entry
, index
);
318 menu
->brother
->entry_no
= menu
->entry_no
;
326 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
328 WMenu
*brother
= menu
->brother
;
331 assert(menu
->flags
.brother
==0);
333 if (entry
->cascade
>=0) {
334 menu
->flags
.realized
= 0;
335 brother
->flags
.realized
= 0;
338 cascade
->parent
= menu
;
340 cascade
->brother
->parent
= brother
;
343 for (i
=0; i
<menu
->cascade_no
; i
++) {
344 if (menu
->cascades
[i
]==NULL
) {
345 menu
->cascades
[i
] = cascade
;
346 brother
->cascades
[i
] = cascade
->brother
;
353 entry
->cascade
= menu
->cascade_no
;
355 menu
->cascades
= wrealloc(menu
->cascades
,
356 sizeof(WMenu
)*(menu
->cascade_no
+1));
357 menu
->cascades
[menu
->cascade_no
++] = cascade
;
360 brother
->cascades
= wrealloc(brother
->cascades
,
361 sizeof(WMenu
)*(brother
->cascade_no
+1));
362 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
366 if (menu
->flags
.lowered
) {
368 cascade
->flags
.lowered
= 1;
369 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
371 cascade
->brother
->flags
.lowered
= 1;
372 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
375 if (!menu
->flags
.realized
)
381 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
383 assert(menu
->flags
.brother
==0);
385 /* destroy cascade menu */
386 if (entry
->cascade
>=0 && menu
->cascades
387 && menu
->cascades
[entry
->cascade
]!=NULL
) {
389 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
391 menu
->cascades
[entry
->cascade
] = NULL
;
392 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
400 wMenuRemoveItem(WMenu
*menu
, int index
)
404 if (menu
->flags
.brother
) {
405 wMenuRemoveItem(menu
->brother
, index
);
409 if (index
>=menu
->entry_no
) return;
411 /* destroy cascade menu */
412 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
414 /* destroy unshared data */
416 if (menu
->entries
[index
]->text
)
417 wfree(menu
->entries
[index
]->text
);
419 if (menu
->entries
[index
]->rtext
)
420 wfree(menu
->entries
[index
]->rtext
);
422 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
423 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
425 wfree(menu
->entries
[index
]);
427 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
428 menu
->entries
[i
+1]->order
--;
429 menu
->entries
[i
]=menu
->entries
[i
+1];
432 menu
->brother
->entry_no
--;
437 renderTexture(WMenu
*menu
)
445 WScreen
*scr
= menu
->menu
->screen_ptr
;
446 WTexture
*texture
= scr
->menu_item_texture
;
448 if (wPreferences
.menu_style
== MS_NORMAL
) {
449 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
450 menu
->entry_height
, WREL_MENUENTRY
);
452 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
453 menu
->menu
->height
+1, WREL_MENUENTRY
);
456 wwarning(_("could not render texture: %s"),
457 RMessageForError(RErrorCode
));
462 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
464 light
.red
= light
.green
= light
.blue
= 80;
467 dark
.red
= dark
.green
= dark
.blue
= 0;
470 mid
.red
= mid
.green
= mid
.blue
= 40;
472 for (i
= 1; i
< menu
->entry_no
; i
++) {
473 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
474 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
476 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
477 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
479 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
480 menu
->menu
->width
-1, i
*menu
->entry_height
,
484 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
485 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
494 updateTexture(WMenu
*menu
)
496 WScreen
*scr
= menu
->menu
->screen_ptr
;
498 /* setup background texture */
499 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
500 if (!menu
->flags
.brother
) {
501 FREE_PIXMAP(menu
->menu_texture_data
);
503 menu
->menu_texture_data
= renderTexture(menu
);
505 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
506 menu
->menu_texture_data
);
507 XClearWindow(dpy
, menu
->menu
->window
);
509 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
510 menu
->menu_texture_data
);
511 XClearWindow(dpy
, menu
->brother
->menu
->window
);
514 XSetWindowBackground(dpy
, menu
->menu
->window
,
515 scr
->menu_item_texture
->any
.color
.pixel
);
516 XClearWindow(dpy
, menu
->menu
->window
);
522 wMenuRealize(WMenu
*menu
)
525 int width
, rwidth
, mrwidth
, mwidth
;
526 int theight
, twidth
, eheight
;
527 WScreen
*scr
= menu
->frame
->screen_ptr
;
528 static int brother_done
=0;
533 wMenuRealize(menu
->brother
);
537 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
538 if (menu
->flags
.titled
)
539 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
541 wFrameWindowUpdateBorders(menu
->frame
, flags
);
543 if (menu
->flags
.titled
) {
544 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
545 strlen(menu
->frame
->title
));
546 theight
= menu
->frame
->top_width
;
547 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
552 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
553 menu
->entry_height
= eheight
;
556 for (i
=0; i
<menu
->entry_no
; i
++) {
559 /* search widest text */
560 text
= menu
->entries
[i
]->text
;
561 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
563 if (menu
->entries
[i
]->flags
.indicator
) {
564 width
+= MENU_INDICATOR_SPACE
;
570 /* search widest text on right */
571 text
= menu
->entries
[i
]->rtext
;
573 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
575 else if (menu
->entries
[i
]->cascade
>=0)
580 if (rwidth
> mrwidth
)
589 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
591 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
592 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
597 menu
->flags
.realized
= 1;
599 if (menu
->flags
.mapped
)
601 if (menu
->brother
->flags
.mapped
)
602 wMenuPaint(menu
->brother
);
607 wMenuDestroy(WMenu
*menu
, int recurse
)
611 WMRemoveNotificationObserver(menu
);
613 /* remove any pending timers */
615 WMDeleteTimerHandler(menu
->timer
);
618 /* call destroy handler */
619 if (menu
->on_destroy
)
620 (*menu
->on_destroy
)(menu
);
622 /* Destroy items if this menu own them. If this is the "brother" menu,
623 * leave them alone as it is shared by them.
625 if (!menu
->flags
.brother
) {
626 for (i
=0; i
<menu
->entry_no
; i
++) {
628 wfree(menu
->entries
[i
]->text
);
630 if (menu
->entries
[i
]->rtext
)
631 wfree(menu
->entries
[i
]->rtext
);
634 if (menu
->entries
[i
]->instances
){
635 WMReleasePropList(menu
->entries
[i
]->instances
);
637 #endif /* USER_MENU */
639 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
640 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
642 wfree(menu
->entries
[i
]);
646 for (i
=0; i
<menu
->cascade_no
; i
++) {
647 if (menu
->cascades
[i
]) {
648 if (menu
->cascades
[i
]->flags
.brother
)
649 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
651 wMenuDestroy(menu
->cascades
[i
], recurse
);
657 wfree(menu
->entries
);
661 FREE_PIXMAP(menu
->menu_texture_data
);
664 wfree(menu
->cascades
);
666 wCoreDestroy(menu
->menu
);
667 wFrameWindowDestroy(menu
->frame
);
669 /* destroy copy of this menu */
670 if (!menu
->flags
.brother
&& menu
->brother
)
671 wMenuDestroy(menu
->brother
, False
);
683 drawFrame(WScreen
*scr
, Drawable win
, int y
, int w
, int h
, int type
)
689 segs
[i
].x1
= segs
[i
].x2
= w
-1;
691 segs
[i
].y2
= y
+ h
- 1;
693 if (type
!= F_TOP
&& type
!= F_NONE
) {
695 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
699 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
705 segs
[i
].y2
= y
+ h
- 1;
707 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
714 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
716 if (type
!= F_TOP
&& type
!= F_NONE
)
717 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
723 paintEntry(WMenu
*menu
, int index
, int selected
)
725 WScreen
*scr
=menu
->frame
->screen_ptr
;
726 Window win
= menu
->menu
->window
;
727 WMenuEntry
*entry
=menu
->entries
[index
];
733 if (!menu
->flags
.realized
) return;
734 h
= menu
->entry_height
;
735 w
= menu
->menu
->width
;
738 light
= scr
->menu_item_auxtexture
->light_gc
;
739 dim
= scr
->menu_item_auxtexture
->dim_gc
;
740 dark
= scr
->menu_item_auxtexture
->dark_gc
;
742 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
745 else if (index
== menu
->entry_no
- 1)
753 /* paint background */
755 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+1, w
-2, h
-3);
756 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
757 drawFrame(scr
, win
, y
, w
, h
, type
);
759 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
760 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
762 drawFrame(scr
, win
, y
, w
, h
, type
);
764 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
769 if (entry
->flags
.enabled
)
770 color
= scr
->select_text_color
;
772 color
= scr
->dtext_color
;
773 } else if (!entry
->flags
.enabled
) {
774 color
= scr
->dtext_color
;
776 color
= scr
->mtext_color
;
780 if (entry
->flags
.indicator
)
781 x
+= MENU_INDICATOR_SPACE
+ 2;
783 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
784 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
786 if (entry
->cascade
>=0) {
787 /* draw the cascade indicator */
788 XDrawLine(dpy
,win
,dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
789 XDrawLine(dpy
,win
,light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
790 XDrawLine(dpy
,win
,dark
, w
-12, y
+6, w
-12, y
+h
-8);
794 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
799 switch (entry
->flags
.indicator_type
) {
801 indicator
= scr
->menu_check_indicator
;
804 indicator
= scr
->menu_mini_indicator
;
807 indicator
= scr
->menu_hide_indicator
;
810 indicator
= scr
->menu_shade_indicator
;
814 indicator
= scr
->menu_radio_indicator
;
818 iw
= indicator
->width
;
819 ih
= indicator
->height
;
820 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
821 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
823 if (entry
->flags
.enabled
) {
824 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
826 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
829 if (entry
->flags
.enabled
) {
830 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
832 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
835 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
837 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
838 iw, ih, 5, y+(h-ih)/2);
840 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
843 /* draw right text */
845 if (entry
->rtext
&& entry
->cascade
<0) {
846 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
847 strlen(entry
->rtext
));
849 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
-6-tw
,
850 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
856 move_menus(WMenu
*menu
, int x
, int y
)
858 while (menu
->parent
) {
861 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
862 y
-= menu
->selected_entry
*menu
->entry_height
;
865 wMenuMove(menu
, x
, y
, True
);
869 makeVisible(WMenu
*menu
)
871 WScreen
*scr
= menu
->frame
->screen_ptr
;
872 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
873 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
875 if (menu
->entry_no
<0) return;
878 y1
= menu
->frame_y
+menu
->frame
->top_width
879 + menu
->selected_entry
*menu
->entry_height
;
880 x2
= x1
+ MENUW(menu
);
881 y2
= y1
+ menu
->entry_height
;
888 if (x1
< rect
.pos
.x
) {
891 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
892 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
896 if (y1
< rect
.pos
.y
) {
899 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
900 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
904 new_y
= new_y
- menu
->frame
->top_width
905 - menu
->selected_entry
*menu
->entry_height
;
906 move_menus(menu
, new_x
, new_y
);
911 check_key(WMenu
*menu
, XKeyEvent
*event
)
916 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
919 ch
= toupper(buffer
[0]);
921 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
924 for (i
=s
; i
<menu
->entry_no
; i
++) {
925 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
929 /* no match. Retry from start, if previous started from a selected entry */
939 keyboardMenu(WMenu
*menu
)
942 KeySym ksym
=NoSymbol
;
946 int old_pos_x
= menu
->frame_x
;
947 int old_pos_y
= menu
->frame_y
;
948 int new_x
= old_pos_x
, new_y
= old_pos_y
;
949 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
950 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
952 if (menu
->flags
.editing
)
956 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
957 GrabModeAsync
, CurrentTime
);
960 if (menu
->frame_y
+menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
961 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
963 if (menu
->frame_x
+MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
964 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
966 move_menus(menu
, new_x
, new_y
);
968 while (!done
&& menu
->flags
.mapped
) {
969 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
970 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
971 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
972 |SubstructureNotifyMask
, &event
);
974 switch (event
.type
) {
976 ksym
= XLookupKeysym(&event
.xkey
, 0);
986 selectEntry(menu
, 0);
994 selectEntry(menu
, menu
->entry_no
-1);
1005 if (menu
->selected_entry
<= 0)
1006 selectEntry(menu
, menu
->entry_no
-1);
1008 selectEntry(menu
, menu
->selected_entry
-1);
1013 #ifdef ARROWLESS_KBD
1019 if (menu
->selected_entry
<0)
1020 selectEntry(menu
, 0);
1021 else if (menu
->selected_entry
== menu
->entry_no
-1)
1022 selectEntry(menu
, 0);
1023 else if (menu
->selected_entry
< menu
->entry_no
-1)
1024 selectEntry(menu
, menu
->selected_entry
+1);
1029 #ifdef ARROWLESS_KBD
1035 if (menu
->selected_entry
>=0) {
1037 entry
= menu
->entries
[menu
->selected_entry
];
1039 if (entry
->cascade
>= 0 && menu
->cascades
1040 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1042 XUngrabKeyboard(dpy
, CurrentTime
);
1044 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1045 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1048 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1049 GrabModeAsync
, GrabModeAsync
,
1056 #ifdef ARROWLESS_KBD
1062 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1063 selectEntry(menu
, -1);
1064 move_menus(menu
, old_pos_x
, old_pos_y
);
1074 index
= check_key(menu
, &event
.xkey
);
1076 selectEntry(menu
, index
);
1082 if (event
.type
==ButtonPress
)
1085 WMHandleEvent(&event
);
1089 XUngrabKeyboard(dpy
, CurrentTime
);
1091 if (done
==2 && menu
->selected_entry
>=0) {
1092 entry
= menu
->entries
[menu
->selected_entry
];
1097 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1098 && entry
->cascade
< 0) {
1099 #if (MENU_BLINK_COUNT > 0)
1100 int sel
= menu
->selected_entry
;
1103 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1104 paintEntry(menu
, sel
, False
);
1106 wusleep(MENU_BLINK_DELAY
);
1107 paintEntry(menu
, sel
, True
);
1109 wusleep(MENU_BLINK_DELAY
);
1112 selectEntry(menu
, -1);
1114 if (!menu
->flags
.buttoned
) {
1116 move_menus(menu
, old_pos_x
, old_pos_y
);
1120 (*entry
->callback
)(menu
, entry
);
1122 if (!menu
->flags
.buttoned
) {
1124 move_menus(menu
, old_pos_x
, old_pos_y
);
1126 selectEntry(menu
, -1);
1130 /* returns True if returning from a submenu to a parent menu,
1131 * False if exiting from menu */
1137 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1139 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1140 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1142 if (!menu
->flags
.realized
) {
1143 menu
->flags
.realized
=1;
1146 if (!menu
->flags
.mapped
) {
1147 if (wPreferences
.wrap_menus
) {
1148 if (x
<rect
.pos
.x
) x
= rect
.pos
.x
;
1149 if (y
<rect
.pos
.y
) y
= rect
.pos
.y
;
1150 if (x
+MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1151 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1152 if (y
+MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1153 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1156 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1159 XMapWindow(dpy
, menu
->frame
->core
->window
);
1160 wRaiseFrame(menu
->frame
->core
);
1161 menu
->flags
.mapped
= 1;
1163 selectEntry(menu
, 0);
1172 wMenuMap(WMenu
*menu
)
1174 if (!menu
->flags
.realized
) {
1175 menu
->flags
.realized
=1;
1178 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1179 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1180 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1181 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1183 XMapWindow(dpy
, menu
->frame
->core
->window
);
1184 wRaiseFrame(menu
->frame
->core
);
1185 menu
->flags
.mapped
= 1;
1190 wMenuUnmap(WMenu
*menu
)
1194 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1195 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1196 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1198 menu
->flags
.buttoned
= 0;
1199 menu
->flags
.mapped
= 0;
1200 menu
->flags
.open_to_left
= 0;
1202 for (i
=0; i
<menu
->cascade_no
; i
++) {
1203 if (menu
->cascades
[i
]!=NULL
1204 && menu
->cascades
[i
]->flags
.mapped
1205 && !menu
->cascades
[i
]->flags
.buttoned
) {
1207 wMenuUnmap(menu
->cascades
[i
]);
1210 menu
->selected_entry
= -1;
1216 wMenuPaint(WMenu
*menu
)
1220 if (!menu
->flags
.mapped
) {
1225 for (i
=0; i
<menu
->entry_no
; i
++) {
1226 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1232 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1234 if (index
>=menu
->entry_no
) return;
1235 menu
->entries
[index
]->flags
.enabled
=enable
;
1236 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1237 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1241 /* ====================================================================== */
1245 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1249 WObjDescriptor
*desc
;
1255 menu
->flags
.editing
= 1;
1257 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1258 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1260 wTextPutText(text
, entry
->text
);
1261 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1262 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1264 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1265 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1266 wwarning(_("could not grab keyboard"));
1269 wSetFocusTo(menu
->frame
->screen_ptr
,
1270 menu
->frame
->screen_ptr
->focused_window
);
1275 while (!done
&& !text
->done
) {
1277 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1279 WMNextEvent(dpy
, &event
);
1281 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1282 (XPointer
*)&desc
)==XCNOENT
)
1285 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1287 (*desc
->handle_anything
)(desc
, &event
);
1290 switch (event
.type
) {
1292 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1296 WMHandleEvent(&event
);
1302 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1304 wSetFocusTo(menu
->frame
->screen_ptr
,
1305 menu
->frame
->screen_ptr
->focused_window
);
1308 t
= wTextGetText(text
);
1309 /* if !t, the user has canceled editing */
1313 entry
->text
= wstrdup(t
);
1315 menu
->flags
.realized
= 0;
1319 XUngrabKeyboard(dpy
, CurrentTime
);
1321 if (t
&& menu
->on_edit
)
1322 (*menu
->on_edit
)(menu
, entry
);
1324 menu
->flags
.editing
= 0;
1326 if (!menu
->flags
.realized
)
1332 selectEntry(WMenu
*menu
, int entry_no
)
1338 if (menu
->entries
==NULL
)
1341 if (entry_no
>= menu
->entry_no
)
1344 old_entry
= menu
->selected_entry
;
1345 menu
->selected_entry
= entry_no
;
1347 if (old_entry
!=entry_no
) {
1349 /* unselect previous entry */
1351 paintEntry(menu
, old_entry
, False
);
1352 entry
= menu
->entries
[old_entry
];
1355 if (entry
->cascade
>=0 && menu
->cascades
) {
1356 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1357 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1363 menu
->selected_entry
= -1;
1366 entry
= menu
->entries
[entry_no
];
1368 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1369 /* Callback for when the submenu is opened.
1371 submenu
= menu
->cascades
[entry
->cascade
];
1372 if (submenu
&& submenu
->flags
.brother
)
1373 submenu
= submenu
->brother
;
1375 if (entry
->callback
) {
1376 /* Only call the callback if the submenu is not yet mapped.
1378 if (menu
->flags
.brother
) {
1379 if (!submenu
|| !submenu
->flags
.mapped
)
1380 (*entry
->callback
)(menu
->brother
, entry
);
1382 if (!submenu
|| !submenu
->flags
.buttoned
)
1383 (*entry
->callback
)(menu
, entry
);
1387 /* the submenu menu might have changed */
1388 submenu
= menu
->cascades
[entry
->cascade
];
1391 if (!submenu
->flags
.mapped
) {
1394 if (!submenu
->flags
.realized
)
1395 wMenuRealize(submenu
);
1396 if (wPreferences
.wrap_menus
) {
1397 if (menu
->flags
.open_to_left
)
1398 submenu
->flags
.open_to_left
= 1;
1400 if (submenu
->flags
.open_to_left
) {
1401 x
= menu
->frame_x
- MENUW(submenu
);
1404 submenu
->flags
.open_to_left
= 0;
1407 x
= menu
->frame_x
+ MENUW(menu
);
1409 if (x
+ MENUW(submenu
)
1410 >= menu
->frame
->screen_ptr
->scr_width
) {
1412 x
= menu
->frame_x
- MENUW(submenu
);
1413 submenu
->flags
.open_to_left
= 1;
1417 x
= menu
->frame_x
+ MENUW(menu
);
1420 if (wPreferences
.align_menus
) {
1423 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1424 if (menu
->flags
.titled
)
1425 y
+= menu
->frame
->top_width
;
1426 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1427 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1430 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1431 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1436 paintEntry(menu
, entry_no
, True
);
1442 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1445 WObjDescriptor
*desc
;
1446 Window root_ret
, win
, junk_win
;
1450 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1453 if (win
==None
) return NULL
;
1455 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1458 if (desc
->parent_type
== WCLASS_MENU
) {
1459 menu
= (WMenu
*)desc
->parent
;
1460 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1461 x_ret
, y_ret
, &junk_win
);
1471 closeCascade(WMenu
*menu
)
1473 WMenu
*parent
=menu
->parent
;
1475 if (menu
->flags
.brother
1476 || (!menu
->flags
.buttoned
1477 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1479 selectEntry(menu
, -1);
1481 #if (MENU_BLINK_DELAY > 2)
1482 wusleep(MENU_BLINK_DELAY
/2);
1486 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1487 || parent
->flags
.brother
)
1488 && !parent
->flags
.buttoned
) {
1489 selectEntry(parent
, -1);
1491 parent
= parent
->parent
;
1494 selectEntry(parent
, -1);
1500 closeBrotherCascadesOf(WMenu
*menu
)
1505 for (i
=0; i
<menu
->cascade_no
; i
++) {
1506 if (menu
->cascades
[i
]->flags
.brother
) {
1507 tmp
= menu
->cascades
[i
];
1509 tmp
= menu
->cascades
[i
]->brother
;
1511 if (tmp
->flags
.mapped
) {
1512 selectEntry(tmp
->parent
, -1);
1513 closeBrotherCascadesOf(tmp
);
1520 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1524 parentMenu(WMenu
*menu
)
1529 if (menu
->flags
.buttoned
)
1532 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1533 parent
= menu
->parent
;
1534 if (parent
->selected_entry
< 0)
1536 entry
= parent
->entries
[parent
->selected_entry
];
1537 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1538 parent
->cascades
[entry
->cascade
] != menu
)
1541 if (menu
->flags
.buttoned
)
1551 * Will raise the passed menu, if submenu = 0
1552 * If submenu > 0 will also raise all mapped submenus
1553 * until the first buttoned one
1554 * If submenu < 0 will also raise all mapped parent menus
1555 * until the first buttoned one
1559 raiseMenus(WMenu
*menu
, int submenus
)
1566 wRaiseFrame(menu
->frame
->core
);
1568 if (submenus
>0 && menu
->selected_entry
>=0) {
1569 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1570 if (i
>=0 && menu
->cascades
) {
1571 submenu
= menu
->cascades
[i
];
1572 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1573 raiseMenus(submenu
, submenus
);
1576 if (submenus
<0 && !menu
->flags
.buttoned
&&
1577 menu
->parent
&& menu
->parent
->flags
.mapped
)
1578 raiseMenus(menu
->parent
, submenus
);
1583 wMenuUnderPointer(WScreen
*screen
)
1585 WObjDescriptor
*desc
;
1586 Window root_ret
, win
;
1590 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1591 &dummy
, &dummy
, &mask
);
1593 if (win
==None
) return NULL
;
1595 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1598 if (desc
->parent_type
== WCLASS_MENU
)
1599 return (WMenu
*)desc
->parent
;
1607 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1609 Window root_ret
, win
;
1613 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1618 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1620 WScreen
*scr
= menu
->menu
->screen_ptr
;
1621 int menuX1
= menu
->frame_x
;
1622 int menuY1
= menu
->frame_y
;
1623 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1624 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1626 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1632 getPointerPosition(scr
, &xroot
, &yroot
);
1634 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1635 /* scroll to the right */
1636 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1638 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) &&
1639 menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1640 /* scroll to the left */
1641 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-rect
.pos
.x
-rect
.size
.width
-1));
1646 *hamount
= -*hamount
;
1649 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1651 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1653 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) &&
1654 menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1656 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
-rect
.pos
.y
-rect
.size
.height
-2));
1658 *vamount
= -*vamount
;
1664 dragScrollMenuCallback(void *data
)
1666 WMenu
*menu
= (WMenu
*)data
;
1667 WScreen
*scr
= menu
->menu
->screen_ptr
;
1668 WMenu
*parent
= parentMenu(menu
);
1669 int hamount
, vamount
;
1671 int newSelectedEntry
;
1673 getScrollAmount(menu
, &hamount
, &vamount
);
1676 if (hamount
!= 0 || vamount
!= 0) {
1677 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1678 parent
->frame_y
+ vamount
, True
);
1679 if (findMenu(scr
, &x
, &y
)) {
1680 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1681 selectEntry(menu
, newSelectedEntry
);
1683 /* Pointer fell outside of menu. If the selected entry is
1684 * not a submenu, unselect it */
1685 if (menu
->selected_entry
>= 0
1686 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1687 selectEntry(menu
, -1);
1688 newSelectedEntry
= 0;
1691 /* paranoid check */
1692 if (newSelectedEntry
>= 0) {
1693 /* keep scrolling */
1694 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1695 dragScrollMenuCallback
, menu
);
1700 /* don't need to scroll anymore */
1702 if (findMenu(scr
, &x
, &y
)) {
1703 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1704 selectEntry(menu
, newSelectedEntry
);
1711 scrollMenuCallback(void *data
)
1713 WMenu
*menu
= (WMenu
*)data
;
1714 WMenu
*parent
= parentMenu(menu
);
1715 int hamount
= 0; /* amount to scroll */
1718 #ifdef VIRTUAL_DESKTOP
1719 /* don't scroll if it is in vdesk mode */
1720 if (!wPreferences
.vedge_thickness
)
1722 getScrollAmount(menu
, &hamount
, &vamount
);
1724 if (hamount
!= 0 || vamount
!= 0) {
1725 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1726 parent
->frame_y
+ vamount
, True
);
1728 /* keep scrolling */
1729 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1730 scrollMenuCallback
, menu
);
1732 /* don't need to scroll anymore */
1739 #define MENU_SCROLL_BORDER 5
1742 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1744 int menuX1
= menu
->frame_x
;
1745 int menuY1
= menu
->frame_y
;
1746 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1747 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1749 /* XXX: handle screen joins proper !! */
1750 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1751 wGetHeadForPoint(menu
->frame
->screen_ptr
, (WMPoint
){ x
, y
}));
1753 if (x
>= menuX1
&& x
<= menuX2
&&
1754 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
||
1755 y
>= rect
.pos
.y
+ rect
.size
.height
+ MENU_SCROLL_BORDER
))
1757 else if (y
>= menuY1
&& y
<= menuY2
&&
1758 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
||
1759 x
>= rect
.pos
.x
+ rect
.size
.width
+ MENU_SCROLL_BORDER
))
1766 typedef struct _delay
{
1774 _leaving(_delay
*dl
)
1776 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1777 dl
->menu
->jump_back
=NULL
;
1778 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1784 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1787 WMenu
*omenu
= parentMenu(menu
);
1788 WScreen
*scr
= menu
->frame
->screen_ptr
;
1791 int old_frame_x
= omenu
->frame_x
;
1792 int old_frame_y
= omenu
->frame_y
;
1795 if (omenu
->jump_back
)
1796 WMDeleteTimerWithClientData(omenu
->jump_back
);
1799 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1800 || omenu
->flags
.app_menu
) {
1804 if (!wPreferences
.wrap_menus
)
1805 raiseMenus(omenu
, True
);
1807 raiseMenus(menu
, False
);
1810 scrollMenuCallback(menu
);
1813 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1816 WMNextEvent(dpy
, &ev
);
1821 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1822 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1824 /* on_border is != 0 if the pointer is between the menu
1825 * and the screen border and is close enough to the border */
1826 on_border
= isPointNearBoder(menu
, x
, y
);
1828 smenu
= wMenuUnderPointer(scr
);
1830 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1835 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, (WMPoint
){ x
, y
}));
1836 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1837 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1838 on_border
= on_x_edge
|| on_y_edge
;
1840 if (!on_border
&& !jump_back
) {
1845 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1846 WMDeleteTimerHandler(menu
->timer
);
1854 scrollMenuCallback(menu
);
1857 /* True if we push on title, or drag the omenu to other position */
1858 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1859 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1860 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1861 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1863 smenu
= wMenuUnderPointer(scr
);
1864 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1866 else if (smenu
==omenu
&& on_title
) {
1880 WMDeleteTimerHandler(menu
->timer
);
1886 if (!omenu
->jump_back
) {
1887 delayer
=wmalloc(sizeof(_delay
));
1888 delayer
->menu
=omenu
;
1889 delayer
->ox
=old_frame_x
;
1890 delayer
->oy
=old_frame_y
;
1891 omenu
->jump_back
=delayer
;
1892 scr
->flags
.jump_back_pending
= 1;
1894 else delayer
= omenu
->jump_back
;
1895 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)_leaving
, delayer
);
1902 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1904 wMenuPaint(desc
->parent
);
1908 int *delayed_select
;
1915 delaySelection(void *data
)
1917 delay_data
*d
= (delay_data
*)data
;
1923 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1924 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1925 entry_no
= getEntryAt(menu
, x
, y
);
1926 selectEntry(menu
, entry_no
);
1928 if (d
->delayed_select
)
1929 *(d
->delayed_select
) = 0;
1934 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1936 XButtonEvent
*bev
= &event
->xbutton
;
1937 WMenu
*menu
= desc
->parent
;
1939 WScreen
*scr
=menu
->frame
->screen_ptr
;
1940 WMenuEntry
*entry
=NULL
;
1942 int close_on_exit
=0;
1944 int delayed_select
= 0;
1948 int old_frame_x
= 0;
1949 int old_frame_y
= 0;
1950 delay_data d_data
= {NULL
, NULL
, NULL
};
1952 if (!wPreferences
.wrap_menus
) {
1953 smenu
= parentMenu(menu
);
1954 old_frame_x
= smenu
->frame_x
;
1955 old_frame_y
= smenu
->frame_y
;
1956 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1957 /* This is true if the menu was launched with right click on root window */
1959 d_data
.delayed_select
= &delayed_select
;
1961 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1962 delaySelection
, &d_data
);
1965 if (menu
->flags
.inside_handler
) {
1968 menu
->flags
.inside_handler
= 1;
1970 wRaiseFrame(menu
->frame
->core
);
1972 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1974 smenu
= findMenu(scr
, &x
, &y
);
1982 if (menu
->flags
.editing
) {
1985 entry_no
= getEntryAt(menu
, x
, y
);
1987 entry
= menu
->entries
[entry_no
];
1989 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
1990 && entry
->flags
.editable
) {
1991 editEntry(smenu
, entry
);
1993 } else if (bev
->state
& ControlMask
) {
1997 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
1998 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2000 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
2001 menu
->selected_entry
!=entry_no
) {
2002 wMenuUnmap(submenu
);
2004 if (!submenu
->flags
.mapped
&& !delayed_select
) {
2005 selectEntry(menu
, entry_no
);
2006 } else if (!submenu
->flags
.buttoned
) {
2007 selectEntry(menu
, -1);
2010 } else if (!delayed_select
) {
2011 selectEntry(menu
, entry_no
);
2014 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2016 dragScrollMenuCallback(menu
);
2020 #ifdef VIRTUAL_DESKTOP
2021 if (wPreferences
.vedge_thickness
) {
2022 wWorkspaceLowerEdge(scr
);
2026 prevx
= bev
->x_root
;
2027 prevy
= bev
->y_root
;
2031 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2033 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2034 |ButtonPressMask
, &ev
);
2037 smenu
= findMenu(scr
, &x
, &y
);
2039 if (smenu
== NULL
) {
2040 /* moved mouse out of menu */
2042 if (!delayed_select
&& d_data
.magic
) {
2043 WMDeleteTimerHandler(d_data
.magic
);
2044 d_data
.magic
= NULL
;
2047 || (menu
->selected_entry
>=0
2048 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2049 prevx
= ev
.xmotion
.x_root
;
2050 prevy
= ev
.xmotion
.y_root
;
2054 selectEntry(menu
, -1);
2056 prevx
= ev
.xmotion
.x_root
;
2057 prevy
= ev
.xmotion
.y_root
;
2059 } else if (menu
&& menu
!=smenu
2060 && (menu
->selected_entry
<0
2061 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2062 selectEntry(menu
, -1);
2064 if (!delayed_select
&& d_data
.magic
) {
2065 WMDeleteTimerHandler(d_data
.magic
);
2066 d_data
.magic
= NULL
;
2070 /* hysteresis for item selection */
2072 /* check if the motion was to the side, indicating that
2073 * the user may want to cross to a submenu */
2074 if (!delayed_select
&& menu
) {
2076 Bool moved_to_submenu
;/* moved to direction of submenu */
2078 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2080 moved_to_submenu
= False
;
2081 if (dx
> 0 /* if moved enough to the side */
2082 /* maybe a open submenu */
2083 && menu
->selected_entry
>=0
2084 /* moving to the right direction */
2085 && (wPreferences
.align_menus
2086 || ev
.xmotion
.y_root
>= prevy
)) {
2089 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2091 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2092 if (prevx
< ev
.xmotion
.x_root
)
2093 moved_to_submenu
= True
;
2095 if (prevx
> ev
.xmotion
.x_root
)
2096 moved_to_submenu
= True
;
2102 if (menu
!= smenu
) {
2104 WMDeleteTimerHandler(d_data
.magic
);
2106 d_data
.magic
= NULL
;
2107 } else if (moved_to_submenu
) {
2108 /* while we are moving, postpone the selection */
2110 WMDeleteTimerHandler(d_data
.magic
);
2112 d_data
.delayed_select
= NULL
;
2114 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2117 prevx
= ev
.xmotion
.x_root
;
2118 prevy
= ev
.xmotion
.y_root
;
2122 WMDeleteTimerHandler(d_data
.magic
);
2123 d_data
.magic
= NULL
;
2127 prevx
= ev
.xmotion
.x_root
;
2128 prevy
= ev
.xmotion
.y_root
;
2130 /* pointer crossed menus */
2131 if (menu
&& menu
->timer
) {
2132 WMDeleteTimerHandler(menu
->timer
);
2136 dragScrollMenuCallback(smenu
);
2140 dragScrollMenuCallback(menu
);
2142 if (!delayed_select
) {
2143 entry_no
= getEntryAt(menu
, x
, y
);
2145 entry
= menu
->entries
[entry_no
];
2146 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2148 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2149 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2150 && menu
->selected_entry
!=entry_no
) {
2151 wMenuUnmap(submenu
);
2155 selectEntry(menu
, entry_no
);
2163 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2169 #ifdef VIRTUAL_DESKTOP
2170 /* since expose will raise edge up.. I need another ugly hack here */
2171 if (wPreferences
.vedge_thickness
) {
2172 wWorkspaceLowerEdge(scr
);
2179 if (menu
&& menu
->timer
) {
2180 WMDeleteTimerHandler(menu
->timer
);
2183 if (d_data
.magic
!=NULL
)
2184 WMDeleteTimerHandler(d_data
.magic
);
2186 if (menu
&& menu
->selected_entry
>=0) {
2187 entry
= menu
->entries
[menu
->selected_entry
];
2188 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2189 && entry
->cascade
< 0) {
2190 /* blink and erase menu selection */
2191 #if (MENU_BLINK_DELAY > 0)
2192 int sel
= menu
->selected_entry
;
2195 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2196 paintEntry(menu
, sel
, False
);
2198 wusleep(MENU_BLINK_DELAY
);
2199 paintEntry(menu
, sel
, True
);
2201 wusleep(MENU_BLINK_DELAY
);
2204 /* unmap the menu, it's parents and call the callback */
2205 if (!menu
->flags
.buttoned
&&
2206 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2209 selectEntry(menu
, -1);
2211 (*entry
->callback
)(menu
, entry
);
2213 /* If the user double clicks an entry, the entry will
2214 * be executed twice, which is not good for things like
2215 * the root menu. So, ignore any clicks that were generated
2216 * while the entry was being executed */
2217 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2219 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2220 selectEntry(menu
, -1);
2222 if (entry
->cascade
>=0 && menu
->cascades
2223 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2224 selectEntry(menu
, -1);
2229 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2230 closeCascade(desc
->parent
);
2232 /* close the cascade windows that should not remain opened */
2233 closeBrotherCascadesOf(desc
->parent
);
2235 if (!wPreferences
.wrap_menus
)
2236 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2239 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2240 #ifdef VIRTUAL_DESKTOP
2241 if (wPreferences
.vedge_thickness
) {
2242 wWorkspaceRaiseEdge(scr
);
2249 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2258 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2260 if (submenus
>0 && menu
->selected_entry
>=0) {
2261 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2263 if (i
>=0 && menu
->cascades
) {
2264 submenu
= menu
->cascades
[i
];
2265 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2266 if (wPreferences
.align_menus
) {
2267 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2269 wMenuMove(submenu
, x
+ MENUW(menu
),
2270 y
+ submenu
->entry_height
*menu
->selected_entry
,
2276 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2277 !menu
->parent
->flags
.buttoned
) {
2278 if (wPreferences
.align_menus
) {
2279 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2281 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2282 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2290 changeMenuLevels(WMenu
*menu
, int lower
)
2295 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2297 wRaiseFrame(menu
->frame
->core
);
2298 menu
->flags
.lowered
= 0;
2300 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2301 wLowerFrame(menu
->frame
->core
);
2302 menu
->flags
.lowered
= 1;
2304 for (i
=0; i
<menu
->cascade_no
; i
++) {
2305 if (menu
->cascades
[i
]
2306 && !menu
->cascades
[i
]->flags
.buttoned
2307 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2308 changeMenuLevels(menu
->cascades
[i
], lower
);
2316 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2321 if (event
->xbutton
.state
& MOD_MASK
) {
2322 if (menu
->flags
.lowered
) {
2327 changeMenuLevels(menu
, lower
);
2333 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2338 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2339 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2343 /* can't touch the menu copy */
2344 if (menu
->flags
.brother
)
2347 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2350 if (event
->xbutton
.state
& MOD_MASK
) {
2351 wLowerFrame(menu
->frame
->core
);
2354 wRaiseFrame(menu
->frame
->core
);
2359 /* lower/raise all submenus */
2361 if (tmp
->selected_entry
>=0 && tmp
->cascades
2362 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2363 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2364 if (!tmp
|| !tmp
->flags
.mapped
)
2367 wLowerFrame(tmp
->frame
->core
);
2369 wRaiseFrame(tmp
->frame
->core
);
2375 /* tear off the menu if it's a root menu or a cascade
2377 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2378 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2379 menu
->flags
.buttoned
=1;
2380 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2382 /* turn off selected menu entry in parent menu */
2383 selectEntry(menu
->parent
, -1);
2385 /* make parent map the copy in place of the original */
2386 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2387 if (menu
->parent
->cascades
[i
] == menu
) {
2388 menu
->parent
->cascades
[i
] = menu
->brother
;
2397 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2398 |ExposureMask
, &ev
);
2402 x
+= ev
.xmotion
.x_root
- dx
;
2403 y
+= ev
.xmotion
.y_root
- dy
;
2404 dx
= ev
.xmotion
.x_root
;
2405 dy
= ev
.xmotion
.y_root
;
2406 wMenuMove(menu
, x
, y
, True
);
2408 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2409 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2411 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2412 ButtonMotionMask
|ButtonReleaseMask
2414 GrabModeAsync
, GrabModeAsync
, None
,
2415 wCursor
[WCUR_MOVE
], CurrentTime
);
2424 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2426 XUngrabPointer(dpy
, CurrentTime
);
2437 *----------------------------------------------------------------------
2439 * Handles mouse click on the close button of menus. The menu is
2440 * closed when the button is clicked.
2443 * The closed menu is reinserted at it's parent menus
2445 *----------------------------------------------------------------------
2448 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2450 WMenu
*menu
= (WMenu
*)data
;
2451 WMenu
*parent
= menu
->parent
;
2455 for (i
=0; i
<parent
->cascade_no
; i
++) {
2456 /* find the entry that points to the copy */
2457 if (parent
->cascades
[i
] == menu
->brother
) {
2458 /* make it point to the original */
2459 parent
->cascades
[i
] = menu
;
2460 menu
->parent
= parent
;
2470 saveMenuInfo(WMPropList
*dict
, WMenu
*menu
, WMPropList
*key
)
2472 WMPropList
*value
, *list
;
2475 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2476 value
= WMCreatePLString(buffer
);
2477 list
= WMCreatePLArray(value
, NULL
);
2478 if (menu
->flags
.lowered
)
2479 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2480 WMPutInPLDictionary(dict
, key
, list
);
2481 WMReleasePropList(value
);
2482 WMReleasePropList(list
);
2487 wMenuSaveState(WScreen
*scr
)
2489 WMPropList
*menus
, *key
;
2492 menus
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
2495 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2496 key
= WMCreatePLString("SwitchMenu");
2497 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2498 WMReleasePropList(key
);
2502 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2506 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2507 key
= WMCreatePLString("WorkspaceMenu");
2508 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2509 WMReleasePropList(key
);
2514 key
= WMCreatePLString("Menus");
2515 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2516 WMReleasePropList(key
);
2518 WMReleasePropList(menus
);
2525 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2530 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2533 len
= strlen(menu
->frame
->title
);
2538 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2543 strcat(buffer
, "\\");
2544 strcat(buffer
, menu
->frame
->title
);
2551 saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
)
2554 int save_menus
= 0, i
;
2559 if (menu
->flags
.brother
)
2560 menu
= menu
->brother
;
2562 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2565 ok
= getMenuPath(menu
, buffer
, 510);
2568 key
= WMCreatePLString(buffer
);
2569 saveMenuInfo(menus
, menu
, key
);
2570 WMReleasePropList(key
);
2576 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2577 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2586 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2590 getMenuInfo(WMPropList
*info
, int *x
, int *y
, Bool
*lowered
)
2596 if (WMIsPLArray(info
)) {
2598 pos
= WMGetFromPLArray(info
, 0);
2599 flags
= WMGetFromPLArray(info
, 1);
2600 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2601 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2608 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2609 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
)!=2)
2610 COMPLAIN("Position");
2612 COMPLAIN("(position, flags...)");
2621 restoreMenu(WScreen
*scr
, WMPropList
*menu
, int which
)
2624 Bool lowered
= False
;
2625 WMenu
*pmenu
= NULL
;
2630 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2635 if (which
& WSS_SWITCHMENU
) {
2636 OpenSwitchMenu(scr
, x
, y
, False
);
2637 pmenu
= scr
->switch_menu
;
2642 int width
= MENUW(pmenu
);
2643 int height
= MENUH(pmenu
);
2644 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2647 changeMenuLevels(pmenu
, True
);
2650 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2651 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2652 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2653 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2655 wMenuMove(pmenu
, x
, y
, True
);
2656 pmenu
->flags
.buttoned
= 1;
2657 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2666 restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
)
2668 WMPropList
*key
, *entry
;
2673 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2676 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2677 key
= WMCreatePLString(buffer
);
2678 entry
= WMGetFromPLDictionary(menus
, key
);
2681 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2683 if (!menu
->flags
.mapped
) {
2684 int width
= MENUW(menu
);
2685 int height
= MENUH(menu
);
2686 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2688 wMenuMapAt(menu
, x
, y
, False
);
2691 /* make parent map the copy in place of the original */
2692 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2693 if (menu
->parent
->cascades
[i
] == menu
) {
2694 menu
->parent
->cascades
[i
] = menu
->brother
;
2700 changeMenuLevels(menu
, True
);
2703 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2704 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2705 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2706 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2708 wMenuMove(menu
, x
, y
, True
);
2709 menu
->flags
.buttoned
= 1;
2710 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2715 WMReleasePropList(key
);
2717 for (i
=0; i
<menu
->cascade_no
; i
++) {
2718 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2728 wMenuRestoreState(WScreen
*scr
)
2730 WMPropList
*menus
, *menu
, *key
, *skey
;
2732 key
= WMCreatePLString("Menus");
2733 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2734 WMReleasePropList(key
);
2741 skey
= WMCreatePLString("SwitchMenu");
2742 menu
= WMGetFromPLDictionary(menus
, skey
);
2743 WMReleasePropList(skey
);
2744 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2747 if (!scr
->root_menu
) {
2748 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2749 wMenuUnmap(scr
->root_menu
);
2751 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2757 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2759 WMenu
*menu
, *parent
;
2763 if (!scr
->root_menu
) {
2764 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2765 wMenuUnmap(scr
->root_menu
);
2768 menu
= scr
->workspace_menu
;
2770 if (menu
->flags
.mapped
) {
2771 if (!menu
->flags
.buttoned
) {
2773 parent
= menu
->parent
;
2774 if (parent
&& parent
->selected_entry
>= 0) {
2775 entry
= parent
->entries
[parent
->selected_entry
];
2776 if (parent
->cascades
[entry
->cascade
] == menu
) {
2777 selectEntry(parent
, -1);
2778 wMenuMapAt(menu
, x
, y
, False
);
2782 wRaiseFrame(menu
->frame
->core
);
2783 wMenuMapCopyAt(menu
, x
, y
);
2786 wMenuMapAt(menu
, x
, y
, False
);