1 /* menu.c- generic menu, used for root menu, application menus etc.
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
37 #include "WindowMaker.h"
46 #include "workspace.h"
49 /****** Global Variables ******/
51 extern Cursor wCursor
[WCUR_LAST
];
53 extern XContext wWinContext
;
55 extern WPreferences wPreferences
;
57 #define MOD_MASK wPreferences.modifier_mask
59 #define MENU_SCROLL_STEP menuScrollParameters[(int)wPreferences.menu_scroll_speed].steps
60 #define MENU_SCROLL_DELAY menuScrollParameters[(int)wPreferences.menu_scroll_speed].delay
64 #define MENUW(m) ((m)->frame->core->width+2*FRAME_BORDER_WIDTH)
65 #define MENUH(m) ((m)->frame->core->height+2*FRAME_BORDER_WIDTH)
68 /***** Local Stuff ******/
71 #define WSS_ROOTMENU (1<<0)
72 #define WSS_SWITCHMENU (1<<1)
73 #define WSS_WSMENU (1<<2)
79 } menuScrollParameters
[5] = {
80 {MENU_SCROLL_STEPS_UF
, MENU_SCROLL_DELAY_UF
},
81 {MENU_SCROLL_STEPS_F
, MENU_SCROLL_DELAY_F
},
82 {MENU_SCROLL_STEPS_M
, MENU_SCROLL_DELAY_M
},
83 {MENU_SCROLL_STEPS_S
, MENU_SCROLL_DELAY_S
},
84 {MENU_SCROLL_STEPS_US
, MENU_SCROLL_DELAY_US
}};
87 static void menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
88 static void menuExpose(WObjDescriptor
*desc
, XEvent
*event
);
90 static void menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
91 static void menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
93 static void menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
95 static void updateTexture(WMenu
*menu
);
98 static int saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
);
99 static int restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
);
102 static void selectEntry(WMenu
*menu
, int entry_no
);
103 static void closeCascade(WMenu
*menu
);
106 /****** Notification Observers ******/
109 appearanceObserver(void *self
, WMNotification
*notif
)
111 WMenu
*menu
= (WMenu
*)self
;
112 int flags
= (int)WMGetNotificationClientData(notif
);
114 if (!menu
->flags
.realized
)
117 if (WMGetNotificationName(notif
) == WNMenuAppearanceSettingsChanged
) {
118 if (flags
& WFontSettings
) {
119 menu
->flags
.realized
= 0;
122 if (flags
& WTextureSettings
) {
123 if (!menu
->flags
.brother
)
126 if (flags
& (WTextureSettings
|WColorSettings
)) {
129 } else if (menu
->flags
.titled
) {
131 if (flags
& WFontSettings
) {
132 menu
->flags
.realized
= 0;
135 if (flags
& WTextureSettings
) {
136 menu
->frame
->flags
.need_texture_remake
= 1;
138 if (flags
& (WColorSettings
|WTextureSettings
)) {
139 wFrameWindowPaint(menu
->frame
);
144 /************************************/
148 *----------------------------------------------------------------------
150 * Creates a new empty menu with the specified title. If main_menu
151 * is True, the created menu will be a main menu, which has some special
152 * properties such as being placed over other normal menus.
153 * If title is NULL, the menu will have no titlebar.
157 *----------------------------------------------------------------------
160 wMenuCreate(WScreen
*screen
, char *title
, int main_menu
)
163 static int brother
=0;
166 menu
= wmalloc(sizeof(WMenu
));
168 memset(menu
, 0, sizeof(WMenu
));
170 #ifdef SINGLE_MENULEVEL
171 tmp
= WMSubmenuLevel
;
173 tmp
= (main_menu
? WMMainMenuLevel
: WMSubmenuLevel
);
176 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
178 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
179 menu
->flags
.titled
= 1;
182 wFrameWindowCreate(screen
, tmp
, 8, 2, 1, 1, &wPreferences
.menu_title_clearance
, flags
,
183 screen
->menu_title_texture
, NULL
,
184 screen
->menu_title_color
,
185 &screen
->menu_title_font
);
187 menu
->frame
->core
->descriptor
.parent
= menu
;
188 menu
->frame
->core
->descriptor
.parent_type
= WCLASS_MENU
;
189 menu
->frame
->core
->descriptor
.handle_mousedown
= menuMouseDown
;
191 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
194 menu
->frame
->title
= wstrdup(title
);
197 menu
->frame
->flags
.justification
= WTJ_LEFT
;
199 menu
->frame
->rbutton_image
= screen
->b_pixmaps
[WBUT_CLOSE
];
202 menu
->alloced_entries
= 0;
203 menu
->selected_entry
= -1;
204 menu
->entries
= NULL
;
206 menu
->frame_x
= screen
->app_menu_x
;
207 menu
->frame_y
= screen
->app_menu_y
;
209 menu
->frame
->child
= menu
;
211 menu
->flags
.lowered
= 0;
215 /* setup object descriptors */
216 menu
->frame
->on_mousedown_titlebar
= menuTitleMouseDown
;
217 menu
->frame
->on_dblclick_titlebar
= menuTitleDoubleClick
;
220 menu
->frame
->on_click_right
= menuCloseClick
;
223 menu
->menu
= wCoreCreate(menu
->frame
->core
, 0, menu
->frame
->top_width
,
224 menu
->frame
->core
->width
, 10);
226 menu
->menu
->descriptor
.parent
= menu
;
227 menu
->menu
->descriptor
.parent_type
= WCLASS_MENU
;
228 menu
->menu
->descriptor
.handle_expose
= menuExpose
;
229 menu
->menu
->descriptor
.handle_mousedown
= menuMouseDown
;
231 menu
->menu_texture_data
= None
;
233 XMapWindow(dpy
, menu
->menu
->window
);
239 menu
->brother
= wMenuCreate(screen
, title
, main_menu
);
241 menu
->brother
->flags
.brother
= 1;
242 menu
->brother
->brother
= menu
;
244 WMAddNotificationObserver(appearanceObserver
, menu
,
245 WNMenuAppearanceSettingsChanged
, menu
);
247 WMAddNotificationObserver(appearanceObserver
, menu
,
248 WNMenuTitleAppearanceSettingsChanged
, menu
);
258 wMenuCreateForApp(WScreen
*screen
, char *title
, int main_menu
)
262 menu
= wMenuCreate(screen
, title
, main_menu
);
265 menu
->flags
.app_menu
= 1;
266 menu
->brother
->flags
.app_menu
= 1;
274 insertEntry(WMenu
*menu
, WMenuEntry
*entry
, int index
)
278 for (i
= menu
->entry_no
-1; i
>= index
; i
--) {
279 menu
->entries
[i
]->order
++;
280 menu
->entries
[i
+1] = menu
->entries
[i
];
282 menu
->entries
[index
] = entry
;
287 wMenuInsertCallback(WMenu
*menu
, int index
, char *text
,
288 void (*callback
)(WMenu
*menu
, WMenuEntry
*entry
),
293 menu
->flags
.realized
= 0;
294 menu
->brother
->flags
.realized
= 0;
296 /* reallocate array if it's too small */
297 if (menu
->entry_no
>= menu
->alloced_entries
) {
300 tmp
= wrealloc(menu
->entries
,
301 sizeof(WMenuEntry
)*(menu
->alloced_entries
+5));
304 menu
->alloced_entries
+= 5;
306 menu
->brother
->entries
= tmp
;
307 menu
->brother
->alloced_entries
= menu
->alloced_entries
;
309 entry
= wmalloc(sizeof(WMenuEntry
));
310 memset(entry
, 0, sizeof(WMenuEntry
));
311 entry
->flags
.enabled
= 1;
312 entry
->text
= wstrdup(text
);
314 entry
->clientdata
= clientdata
;
315 entry
->callback
= callback
;
316 if (index
<0 || index
>=menu
->entry_no
) {
317 entry
->order
= menu
->entry_no
;
318 menu
->entries
[menu
->entry_no
] = entry
;
320 entry
->order
= index
;
321 insertEntry(menu
, entry
, index
);
325 menu
->brother
->entry_no
= menu
->entry_no
;
333 wMenuEntrySetCascade(WMenu
*menu
, WMenuEntry
*entry
, WMenu
*cascade
)
335 WMenu
*brother
= menu
->brother
;
338 assert(menu
->flags
.brother
==0);
340 if (entry
->cascade
>=0) {
341 menu
->flags
.realized
= 0;
342 brother
->flags
.realized
= 0;
345 cascade
->parent
= menu
;
347 cascade
->brother
->parent
= brother
;
350 for (i
=0; i
<menu
->cascade_no
; i
++) {
351 if (menu
->cascades
[i
]==NULL
) {
352 menu
->cascades
[i
] = cascade
;
353 brother
->cascades
[i
] = cascade
->brother
;
360 entry
->cascade
= menu
->cascade_no
;
362 menu
->cascades
= wrealloc(menu
->cascades
,
363 sizeof(WMenu
)*(menu
->cascade_no
+1));
364 menu
->cascades
[menu
->cascade_no
++] = cascade
;
367 brother
->cascades
= wrealloc(brother
->cascades
,
368 sizeof(WMenu
)*(brother
->cascade_no
+1));
369 brother
->cascades
[brother
->cascade_no
++] = cascade
->brother
;
373 if (menu
->flags
.lowered
) {
375 cascade
->flags
.lowered
= 1;
376 ChangeStackingLevel(cascade
->frame
->core
, WMNormalLevel
);
378 cascade
->brother
->flags
.lowered
= 1;
379 ChangeStackingLevel(cascade
->brother
->frame
->core
, WMNormalLevel
);
382 if (!menu
->flags
.realized
)
388 wMenuEntryRemoveCascade(WMenu
*menu
, WMenuEntry
*entry
)
390 assert(menu
->flags
.brother
==0);
392 /* destroy cascade menu */
393 if (entry
->cascade
>=0 && menu
->cascades
394 && menu
->cascades
[entry
->cascade
]!=NULL
) {
396 wMenuDestroy(menu
->cascades
[entry
->cascade
], True
);
398 menu
->cascades
[entry
->cascade
] = NULL
;
399 menu
->brother
->cascades
[entry
->cascade
] = NULL
;
407 wMenuRemoveItem(WMenu
*menu
, int index
)
411 if (menu
->flags
.brother
) {
412 wMenuRemoveItem(menu
->brother
, index
);
416 if (index
>=menu
->entry_no
) return;
418 /* destroy cascade menu */
419 wMenuEntryRemoveCascade(menu
, menu
->entries
[index
]);
421 /* destroy unshared data */
423 if (menu
->entries
[index
]->text
)
424 wfree(menu
->entries
[index
]->text
);
426 if (menu
->entries
[index
]->rtext
)
427 wfree(menu
->entries
[index
]->rtext
);
429 if (menu
->entries
[index
]->free_cdata
&& menu
->entries
[index
]->clientdata
)
430 (*menu
->entries
[index
]->free_cdata
)(menu
->entries
[index
]->clientdata
);
432 wfree(menu
->entries
[index
]);
434 for (i
=index
; i
<menu
->entry_no
-1; i
++) {
435 menu
->entries
[i
+1]->order
--;
436 menu
->entries
[i
]=menu
->entries
[i
+1];
439 menu
->brother
->entry_no
--;
444 renderTexture(WMenu
*menu
)
452 WScreen
*scr
= menu
->menu
->screen_ptr
;
453 WTexture
*texture
= scr
->menu_item_texture
;
455 if (wPreferences
.menu_style
== MS_NORMAL
) {
456 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
457 menu
->entry_height
, WREL_MENUENTRY
);
459 img
= wTextureRenderImage(texture
, menu
->menu
->width
,
460 menu
->menu
->height
+1, WREL_MENUENTRY
);
463 wwarning(_("could not render texture: %s"),
464 RMessageForError(RErrorCode
));
469 if (wPreferences
.menu_style
== MS_SINGLE_TEXTURE
) {
471 light
.red
= light
.green
= light
.blue
= 80;
474 dark
.red
= dark
.green
= dark
.blue
= 0;
477 mid
.red
= mid
.green
= mid
.blue
= 40;
479 for (i
= 1; i
< menu
->entry_no
; i
++) {
480 ROperateLine(img
, RSubtractOperation
, 0, i
*menu
->entry_height
-2,
481 menu
->menu
->width
-1, i
*menu
->entry_height
-2, &mid
);
483 RDrawLine(img
, 0, i
*menu
->entry_height
-1,
484 menu
->menu
->width
-1, i
*menu
->entry_height
-1, &dark
);
486 ROperateLine(img
, RAddOperation
, 0, i
*menu
->entry_height
,
487 menu
->menu
->width
-1, i
*menu
->entry_height
,
491 if (!RConvertImage(scr
->rcontext
, img
, &pix
)) {
492 wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode
));
501 updateTexture(WMenu
*menu
)
503 WScreen
*scr
= menu
->menu
->screen_ptr
;
505 /* setup background texture */
506 if (scr
->menu_item_texture
->any
.type
!= WTEX_SOLID
) {
507 if (!menu
->flags
.brother
) {
508 FREE_PIXMAP(menu
->menu_texture_data
);
510 menu
->menu_texture_data
= renderTexture(menu
);
512 XSetWindowBackgroundPixmap(dpy
, menu
->menu
->window
,
513 menu
->menu_texture_data
);
514 XClearWindow(dpy
, menu
->menu
->window
);
516 XSetWindowBackgroundPixmap(dpy
, menu
->brother
->menu
->window
,
517 menu
->menu_texture_data
);
518 XClearWindow(dpy
, menu
->brother
->menu
->window
);
521 XSetWindowBackground(dpy
, menu
->menu
->window
,
522 scr
->menu_item_texture
->any
.color
.pixel
);
523 XClearWindow(dpy
, menu
->menu
->window
);
529 wMenuRealize(WMenu
*menu
)
532 int width
, rwidth
, mrwidth
, mwidth
;
533 int theight
, twidth
, eheight
;
534 WScreen
*scr
= menu
->frame
->screen_ptr
;
535 static int brother_done
=0;
540 wMenuRealize(menu
->brother
);
544 flags
= WFF_SINGLE_STATE
|WFF_BORDER
;
545 if (menu
->flags
.titled
)
546 flags
|= WFF_TITLEBAR
|WFF_RIGHT_BUTTON
;
548 wFrameWindowUpdateBorders(menu
->frame
, flags
);
550 if (menu
->flags
.titled
) {
551 twidth
= WMWidthOfString(scr
->menu_title_font
, menu
->frame
->title
,
552 strlen(menu
->frame
->title
));
553 theight
= menu
->frame
->top_width
;
554 twidth
+= theight
+ (wPreferences
.new_style
? 16 : 8);
559 eheight
= WMFontHeight(scr
->menu_entry_font
) + 6 + wPreferences
.menu_text_clearance
* 2;
560 menu
->entry_height
= eheight
;
563 for (i
=0; i
<menu
->entry_no
; i
++) {
566 /* search widest text */
567 text
= menu
->entries
[i
]->text
;
568 width
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))+10;
570 if (menu
->entries
[i
]->flags
.indicator
) {
571 width
+= MENU_INDICATOR_SPACE
;
577 /* search widest text on right */
578 text
= menu
->entries
[i
]->rtext
;
580 rwidth
= WMWidthOfString(scr
->menu_entry_font
, text
, strlen(text
))
582 else if (menu
->entries
[i
]->cascade
>=0)
587 if (rwidth
> mrwidth
)
596 wCoreConfigure(menu
->menu
, 0, theight
, mwidth
, menu
->entry_no
*eheight
-1);
598 wFrameWindowResize(menu
->frame
, mwidth
, menu
->entry_no
*eheight
-1
599 + menu
->frame
->top_width
+ menu
->frame
->bottom_width
);
604 menu
->flags
.realized
= 1;
606 if (menu
->flags
.mapped
)
608 if (menu
->brother
->flags
.mapped
)
609 wMenuPaint(menu
->brother
);
614 wMenuDestroy(WMenu
*menu
, int recurse
)
618 WMRemoveNotificationObserver(menu
);
620 /* remove any pending timers */
622 WMDeleteTimerHandler(menu
->timer
);
625 /* call destroy handler */
626 if (menu
->on_destroy
)
627 (*menu
->on_destroy
)(menu
);
629 /* Destroy items if this menu own them. If this is the "brother" menu,
630 * leave them alone as it is shared by them.
632 if (!menu
->flags
.brother
) {
633 for (i
=0; i
<menu
->entry_no
; i
++) {
635 wfree(menu
->entries
[i
]->text
);
637 if (menu
->entries
[i
]->rtext
)
638 wfree(menu
->entries
[i
]->rtext
);
641 if (menu
->entries
[i
]->instances
){
642 WMReleasePropList(menu
->entries
[i
]->instances
);
644 #endif /* USER_MENU */
646 if (menu
->entries
[i
]->free_cdata
&& menu
->entries
[i
]->clientdata
) {
647 (*menu
->entries
[i
]->free_cdata
)(menu
->entries
[i
]->clientdata
);
649 wfree(menu
->entries
[i
]);
653 for (i
=0; i
<menu
->cascade_no
; i
++) {
654 if (menu
->cascades
[i
]) {
655 if (menu
->cascades
[i
]->flags
.brother
)
656 wMenuDestroy(menu
->cascades
[i
]->brother
, recurse
);
658 wMenuDestroy(menu
->cascades
[i
], recurse
);
664 wfree(menu
->entries
);
668 FREE_PIXMAP(menu
->menu_texture_data
);
671 wfree(menu
->cascades
);
673 wCoreDestroy(menu
->menu
);
674 wFrameWindowDestroy(menu
->frame
);
676 /* destroy copy of this menu */
677 if (!menu
->flags
.brother
&& menu
->brother
)
678 wMenuDestroy(menu
->brother
, False
);
690 drawFrame(WScreen
*scr
, Drawable win
, int y
, int w
, int h
, int type
)
696 segs
[i
].x1
= segs
[i
].x2
= w
-1;
698 segs
[i
].y2
= y
+ h
- 1;
700 if (type
!= F_TOP
&& type
!= F_NONE
) {
702 segs
[i
].y1
= segs
[i
].y2
= y
+ h
-2;
706 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->dim_gc
, segs
, i
);
712 segs
[i
].y2
= y
+ h
- 1;
714 if (type
!= F_BOTTOM
&& type
!= F_NONE
) {
721 XDrawSegments(dpy
, win
, scr
->menu_item_auxtexture
->light_gc
, segs
, i
);
723 if (type
!= F_TOP
&& type
!= F_NONE
)
724 XDrawLine(dpy
, win
, scr
->menu_item_auxtexture
->dark_gc
, 0, y
+h
-1,
730 paintEntry(WMenu
*menu
, int index
, int selected
)
732 WScreen
*scr
=menu
->frame
->screen_ptr
;
733 Window win
= menu
->menu
->window
;
734 WMenuEntry
*entry
=menu
->entries
[index
];
740 if (!menu
->flags
.realized
) return;
741 h
= menu
->entry_height
;
742 w
= menu
->menu
->width
;
745 light
= scr
->menu_item_auxtexture
->light_gc
;
746 dim
= scr
->menu_item_auxtexture
->dim_gc
;
747 dark
= scr
->menu_item_auxtexture
->dark_gc
;
749 if (wPreferences
.menu_style
== MS_FLAT
&& menu
->entry_no
> 1) {
752 else if (index
== menu
->entry_no
- 1)
760 /* paint background */
762 XFillRectangle(dpy
, win
, WMColorGC(scr
->select_color
), 1, y
+1, w
-2, h
-3);
763 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
)
764 drawFrame(scr
, win
, y
, w
, h
, type
);
766 if (scr
->menu_item_texture
->any
.type
== WTEX_SOLID
) {
767 XClearArea(dpy
, win
, 0, y
+ 1, w
- 1, h
- 3, False
);
769 drawFrame(scr
, win
, y
, w
, h
, type
);
771 XClearArea(dpy
, win
, 0, y
, w
, h
, False
);
776 if (entry
->flags
.enabled
)
777 color
= scr
->select_text_color
;
779 color
= scr
->dtext_color
;
780 } else if (!entry
->flags
.enabled
) {
781 color
= scr
->dtext_color
;
783 color
= scr
->mtext_color
;
787 if (entry
->flags
.indicator
)
788 x
+= MENU_INDICATOR_SPACE
+ 2;
790 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
,
791 x
, 3 + y
+ wPreferences
.menu_text_clearance
, entry
->text
, strlen(entry
->text
));
793 if (entry
->cascade
>=0) {
794 /* draw the cascade indicator */
795 XDrawLine(dpy
, win
, dim
, w
-11, y
+6, w
-6, y
+h
/2-1);
796 XDrawLine(dpy
, win
, light
, w
-11, y
+h
-8, w
-6, y
+h
/2-1);
797 XDrawLine(dpy
, win
, dark
, w
-12, y
+6, w
-12, y
+h
-8);
801 if (entry
->flags
.indicator
&& entry
->flags
.indicator_on
) {
806 switch (entry
->flags
.indicator_type
) {
808 indicator
= scr
->menu_check_indicator
;
811 indicator
= scr
->menu_mini_indicator
;
814 indicator
= scr
->menu_hide_indicator
;
817 indicator
= scr
->menu_shade_indicator
;
821 indicator
= scr
->menu_radio_indicator
;
825 iw
= indicator
->width
;
826 ih
= indicator
->height
;
827 XSetClipMask(dpy
, scr
->copy_gc
, indicator
->mask
);
828 XSetClipOrigin(dpy
, scr
->copy_gc
, 5, y
+(h
-ih
)/2);
830 if (entry
->flags
.enabled
) {
831 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->select_text_color
));
833 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
836 if (entry
->flags
.enabled
) {
837 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->mtext_color
));
839 XSetForeground(dpy
, scr
->copy_gc
, WMColorPixel(scr
->dtext_color
));
842 XFillRectangle(dpy
, win
, scr
->copy_gc
, 5, y
+(h
-ih
)/2, iw
, ih
);
844 XCopyArea(dpy, indicator->image, win, scr->copy_gc, 0, 0,
845 iw, ih, 5, y+(h-ih)/2);
847 XSetClipOrigin(dpy
, scr
->copy_gc
, 0, 0);
850 /* draw right text */
852 if (entry
->rtext
&& entry
->cascade
<0) {
853 tw
= WMWidthOfString(scr
->menu_entry_font
, entry
->rtext
,
854 strlen(entry
->rtext
));
856 WMDrawString(scr
->wmscreen
, win
, color
, scr
->menu_entry_font
, w
-6-tw
,
857 y
+ 3 + wPreferences
.menu_text_clearance
, entry
->rtext
, strlen(entry
->rtext
));
863 move_menus(WMenu
*menu
, int x
, int y
)
865 while (menu
->parent
) {
868 if (!wPreferences
.align_menus
&& menu
->selected_entry
>=0) {
869 y
-= menu
->selected_entry
*menu
->entry_height
;
872 wMenuMove(menu
, x
, y
, True
);
876 makeVisible(WMenu
*menu
)
878 WScreen
*scr
= menu
->frame
->screen_ptr
;
879 int x1
, y1
, x2
, y2
, new_x
, new_y
, move
;
880 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
882 if (menu
->entry_no
<0) return;
885 y1
= menu
->frame_y
+menu
->frame
->top_width
886 + menu
->selected_entry
*menu
->entry_height
;
887 x2
= x1
+ MENUW(menu
);
888 y2
= y1
+ menu
->entry_height
;
895 if (x1
< rect
.pos
.x
) {
898 } else if (x2
>= rect
.pos
.x
+ rect
.size
.width
) {
899 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
903 if (y1
< rect
.pos
.y
) {
906 } else if (y2
>= rect
.pos
.y
+ rect
.size
.height
) {
907 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->entry_height
- 1;
911 new_y
= new_y
- menu
->frame
->top_width
912 - menu
->selected_entry
*menu
->entry_height
;
913 move_menus(menu
, new_x
, new_y
);
918 check_key(WMenu
*menu
, XKeyEvent
*event
)
923 if (XLookupString(event
, buffer
, 32, NULL
, NULL
)<1)
926 ch
= toupper(buffer
[0]);
928 s
= (menu
->selected_entry
>=0 ? menu
->selected_entry
+1 : 0);
931 for (i
=s
; i
<menu
->entry_no
; i
++) {
932 if (ch
==toupper(menu
->entries
[i
]->text
[0])) {
936 /* no match. Retry from start, if previous started from a selected entry */
946 keyboardMenu(WMenu
*menu
)
949 KeySym ksym
=NoSymbol
;
953 int old_pos_x
= menu
->frame_x
;
954 int old_pos_y
= menu
->frame_y
;
955 int new_x
= old_pos_x
, new_y
= old_pos_y
;
956 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
957 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
959 if (menu
->flags
.editing
)
963 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
, GrabModeAsync
,
964 GrabModeAsync
, CurrentTime
);
967 if (menu
->frame_y
+menu
->frame
->top_width
>= rect
.pos
.y
+ rect
.size
.height
)
968 new_y
= rect
.pos
.y
+ rect
.size
.height
- menu
->frame
->top_width
;
970 if (menu
->frame_x
+MENUW(menu
) >= rect
.pos
.x
+ rect
.size
.width
)
971 new_x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
) - 1;
973 move_menus(menu
, new_x
, new_y
);
975 while (!done
&& menu
->flags
.mapped
) {
976 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
977 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonPressMask
978 |ButtonReleaseMask
|KeyPressMask
|KeyReleaseMask
979 |SubstructureNotifyMask
, &event
);
981 switch (event
.type
) {
983 ksym
= XLookupKeysym(&event
.xkey
, 0);
993 selectEntry(menu
, 0);
1001 selectEntry(menu
, menu
->entry_no
-1);
1006 #ifdef ARROWLESS_KBD
1012 if (menu
->selected_entry
<= 0)
1013 selectEntry(menu
, menu
->entry_no
-1);
1015 selectEntry(menu
, menu
->selected_entry
-1);
1020 #ifdef ARROWLESS_KBD
1026 if (menu
->selected_entry
<0)
1027 selectEntry(menu
, 0);
1028 else if (menu
->selected_entry
== menu
->entry_no
-1)
1029 selectEntry(menu
, 0);
1030 else if (menu
->selected_entry
< menu
->entry_no
-1)
1031 selectEntry(menu
, menu
->selected_entry
+1);
1036 #ifdef ARROWLESS_KBD
1042 if (menu
->selected_entry
>=0) {
1044 entry
= menu
->entries
[menu
->selected_entry
];
1046 if (entry
->cascade
>= 0 && menu
->cascades
1047 && menu
->cascades
[entry
->cascade
]->entry_no
> 0) {
1049 XUngrabKeyboard(dpy
, CurrentTime
);
1051 selectEntry(menu
->cascades
[entry
->cascade
], 0);
1052 if (!keyboardMenu(menu
->cascades
[entry
->cascade
]))
1055 XGrabKeyboard(dpy
, menu
->frame
->core
->window
, True
,
1056 GrabModeAsync
, GrabModeAsync
,
1063 #ifdef ARROWLESS_KBD
1069 if (menu
->parent
!=NULL
&& menu
->parent
->selected_entry
>=0) {
1070 selectEntry(menu
, -1);
1071 move_menus(menu
, old_pos_x
, old_pos_y
);
1084 index
= check_key(menu
, &event
.xkey
);
1086 selectEntry(menu
, index
);
1092 if (event
.type
==ButtonPress
)
1095 WMHandleEvent(&event
);
1099 XUngrabKeyboard(dpy
, CurrentTime
);
1101 if (done
==2 && menu
->selected_entry
>=0) {
1102 entry
= menu
->entries
[menu
->selected_entry
];
1107 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1108 && entry
->cascade
< 0) {
1109 #if (MENU_BLINK_COUNT > 0)
1110 int sel
= menu
->selected_entry
;
1113 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1114 paintEntry(menu
, sel
, False
);
1116 wusleep(MENU_BLINK_DELAY
);
1117 paintEntry(menu
, sel
, True
);
1119 wusleep(MENU_BLINK_DELAY
);
1122 selectEntry(menu
, -1);
1124 if (!menu
->flags
.buttoned
) {
1126 move_menus(menu
, old_pos_x
, old_pos_y
);
1130 (*entry
->callback
)(menu
, entry
);
1132 if (!menu
->flags
.buttoned
) {
1134 move_menus(menu
, old_pos_x
, old_pos_y
);
1136 selectEntry(menu
, -1);
1140 /* returns True if returning from a submenu to a parent menu,
1141 * False if exiting from menu */
1147 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1149 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1150 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1152 if (!menu
->flags
.realized
) {
1153 menu
->flags
.realized
=1;
1156 if (!menu
->flags
.mapped
) {
1157 if (wPreferences
.wrap_menus
) {
1158 if (x
<rect
.pos
.x
) x
= rect
.pos
.x
;
1159 if (y
<rect
.pos
.y
) y
= rect
.pos
.y
;
1160 if (x
+MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1161 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1162 if (y
+MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1163 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1166 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1169 XMapWindow(dpy
, menu
->frame
->core
->window
);
1170 wRaiseFrame(menu
->frame
->core
);
1171 menu
->flags
.mapped
= 1;
1173 selectEntry(menu
, 0);
1182 wMenuMap(WMenu
*menu
)
1184 if (!menu
->flags
.realized
) {
1185 menu
->flags
.realized
=1;
1188 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1189 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1190 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1191 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1193 XMapWindow(dpy
, menu
->frame
->core
->window
);
1194 wRaiseFrame(menu
->frame
->core
);
1195 menu
->flags
.mapped
= 1;
1200 wMenuUnmap(WMenu
*menu
)
1204 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1205 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1206 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1208 menu
->flags
.buttoned
= 0;
1209 menu
->flags
.mapped
= 0;
1210 menu
->flags
.open_to_left
= 0;
1212 for (i
=0; i
<menu
->cascade_no
; i
++) {
1213 if (menu
->cascades
[i
]!=NULL
1214 && menu
->cascades
[i
]->flags
.mapped
1215 && !menu
->cascades
[i
]->flags
.buttoned
) {
1217 wMenuUnmap(menu
->cascades
[i
]);
1220 menu
->selected_entry
= -1;
1226 wMenuPaint(WMenu
*menu
)
1230 if (!menu
->flags
.mapped
) {
1235 for (i
=0; i
<menu
->entry_no
; i
++) {
1236 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1242 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1244 if (index
>=menu
->entry_no
) return;
1245 menu
->entries
[index
]->flags
.enabled
=enable
;
1246 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1247 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1251 /* ====================================================================== */
1255 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1259 WObjDescriptor
*desc
;
1265 menu
->flags
.editing
= 1;
1267 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1268 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1270 wTextPutText(text
, entry
->text
);
1271 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1272 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1274 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1275 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1276 wwarning(_("could not grab keyboard"));
1279 wSetFocusTo(menu
->frame
->screen_ptr
,
1280 menu
->frame
->screen_ptr
->focused_window
);
1285 while (!done
&& !text
->done
) {
1287 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1289 WMNextEvent(dpy
, &event
);
1291 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1292 (XPointer
*)&desc
)==XCNOENT
)
1295 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1297 (*desc
->handle_anything
)(desc
, &event
);
1300 switch (event
.type
) {
1302 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1306 WMHandleEvent(&event
);
1312 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1314 wSetFocusTo(menu
->frame
->screen_ptr
,
1315 menu
->frame
->screen_ptr
->focused_window
);
1318 t
= wTextGetText(text
);
1319 /* if !t, the user has canceled editing */
1323 entry
->text
= wstrdup(t
);
1325 menu
->flags
.realized
= 0;
1329 XUngrabKeyboard(dpy
, CurrentTime
);
1331 if (t
&& menu
->on_edit
)
1332 (*menu
->on_edit
)(menu
, entry
);
1334 menu
->flags
.editing
= 0;
1336 if (!menu
->flags
.realized
)
1342 selectEntry(WMenu
*menu
, int entry_no
)
1348 if (menu
->entries
==NULL
)
1351 if (entry_no
>= menu
->entry_no
)
1354 old_entry
= menu
->selected_entry
;
1355 menu
->selected_entry
= entry_no
;
1357 if (old_entry
!=entry_no
) {
1359 /* unselect previous entry */
1361 paintEntry(menu
, old_entry
, False
);
1362 entry
= menu
->entries
[old_entry
];
1365 if (entry
->cascade
>=0 && menu
->cascades
) {
1366 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1367 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1373 menu
->selected_entry
= -1;
1376 entry
= menu
->entries
[entry_no
];
1378 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1379 /* Callback for when the submenu is opened.
1381 submenu
= menu
->cascades
[entry
->cascade
];
1382 if (submenu
&& submenu
->flags
.brother
)
1383 submenu
= submenu
->brother
;
1385 if (entry
->callback
) {
1386 /* Only call the callback if the submenu is not yet mapped.
1388 if (menu
->flags
.brother
) {
1389 if (!submenu
|| !submenu
->flags
.mapped
)
1390 (*entry
->callback
)(menu
->brother
, entry
);
1392 if (!submenu
|| !submenu
->flags
.buttoned
)
1393 (*entry
->callback
)(menu
, entry
);
1397 /* the submenu menu might have changed */
1398 submenu
= menu
->cascades
[entry
->cascade
];
1401 if (!submenu
->flags
.mapped
) {
1404 if (!submenu
->flags
.realized
)
1405 wMenuRealize(submenu
);
1406 if (wPreferences
.wrap_menus
) {
1407 if (menu
->flags
.open_to_left
)
1408 submenu
->flags
.open_to_left
= 1;
1410 if (submenu
->flags
.open_to_left
) {
1411 x
= menu
->frame_x
- MENUW(submenu
);
1414 submenu
->flags
.open_to_left
= 0;
1417 x
= menu
->frame_x
+ MENUW(menu
);
1419 if (x
+ MENUW(submenu
)
1420 >= menu
->frame
->screen_ptr
->scr_width
) {
1422 x
= menu
->frame_x
- MENUW(submenu
);
1423 submenu
->flags
.open_to_left
= 1;
1427 x
= menu
->frame_x
+ MENUW(menu
);
1430 if (wPreferences
.align_menus
) {
1433 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1434 if (menu
->flags
.titled
)
1435 y
+= menu
->frame
->top_width
;
1436 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1437 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1440 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1441 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1446 paintEntry(menu
, entry_no
, True
);
1452 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1455 WObjDescriptor
*desc
;
1456 Window root_ret
, win
, junk_win
;
1460 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1463 if (win
==None
) return NULL
;
1465 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1468 if (desc
->parent_type
== WCLASS_MENU
) {
1469 menu
= (WMenu
*)desc
->parent
;
1470 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1471 x_ret
, y_ret
, &junk_win
);
1481 closeCascade(WMenu
*menu
)
1483 WMenu
*parent
=menu
->parent
;
1485 if (menu
->flags
.brother
1486 || (!menu
->flags
.buttoned
1487 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1489 selectEntry(menu
, -1);
1491 #if (MENU_BLINK_DELAY > 2)
1492 wusleep(MENU_BLINK_DELAY
/2);
1496 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1497 || parent
->flags
.brother
)
1498 && !parent
->flags
.buttoned
) {
1499 selectEntry(parent
, -1);
1501 parent
= parent
->parent
;
1504 selectEntry(parent
, -1);
1510 closeBrotherCascadesOf(WMenu
*menu
)
1515 for (i
=0; i
<menu
->cascade_no
; i
++) {
1516 if (menu
->cascades
[i
]->flags
.brother
) {
1517 tmp
= menu
->cascades
[i
];
1519 tmp
= menu
->cascades
[i
]->brother
;
1521 if (tmp
->flags
.mapped
) {
1522 selectEntry(tmp
->parent
, -1);
1523 closeBrotherCascadesOf(tmp
);
1530 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1534 parentMenu(WMenu
*menu
)
1539 if (menu
->flags
.buttoned
)
1542 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1543 parent
= menu
->parent
;
1544 if (parent
->selected_entry
< 0)
1546 entry
= parent
->entries
[parent
->selected_entry
];
1547 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1548 parent
->cascades
[entry
->cascade
] != menu
)
1551 if (menu
->flags
.buttoned
)
1561 * Will raise the passed menu, if submenu = 0
1562 * If submenu > 0 will also raise all mapped submenus
1563 * until the first buttoned one
1564 * If submenu < 0 will also raise all mapped parent menus
1565 * until the first buttoned one
1569 raiseMenus(WMenu
*menu
, int submenus
)
1576 wRaiseFrame(menu
->frame
->core
);
1578 if (submenus
>0 && menu
->selected_entry
>=0) {
1579 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1580 if (i
>=0 && menu
->cascades
) {
1581 submenu
= menu
->cascades
[i
];
1582 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1583 raiseMenus(submenu
, submenus
);
1586 if (submenus
<0 && !menu
->flags
.buttoned
&&
1587 menu
->parent
&& menu
->parent
->flags
.mapped
)
1588 raiseMenus(menu
->parent
, submenus
);
1593 wMenuUnderPointer(WScreen
*screen
)
1595 WObjDescriptor
*desc
;
1596 Window root_ret
, win
;
1600 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1601 &dummy
, &dummy
, &mask
);
1603 if (win
==None
) return NULL
;
1605 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1608 if (desc
->parent_type
== WCLASS_MENU
)
1609 return (WMenu
*)desc
->parent
;
1617 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1619 Window root_ret
, win
;
1623 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1628 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1630 WScreen
*scr
= menu
->menu
->screen_ptr
;
1631 int menuX1
= menu
->frame_x
;
1632 int menuY1
= menu
->frame_y
;
1633 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1634 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1636 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1642 getPointerPosition(scr
, &xroot
, &yroot
);
1644 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1645 /* scroll to the right */
1646 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1648 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) &&
1649 menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1650 /* scroll to the left */
1651 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-rect
.pos
.x
-rect
.size
.width
-1));
1656 *hamount
= -*hamount
;
1659 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1661 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1663 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) &&
1664 menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1666 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
-rect
.pos
.y
-rect
.size
.height
-2));
1668 *vamount
= -*vamount
;
1674 dragScrollMenuCallback(void *data
)
1676 WMenu
*menu
= (WMenu
*)data
;
1677 WScreen
*scr
= menu
->menu
->screen_ptr
;
1678 WMenu
*parent
= parentMenu(menu
);
1679 int hamount
, vamount
;
1681 int newSelectedEntry
;
1683 getScrollAmount(menu
, &hamount
, &vamount
);
1686 if (hamount
!= 0 || vamount
!= 0) {
1687 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1688 parent
->frame_y
+ vamount
, True
);
1689 if (findMenu(scr
, &x
, &y
)) {
1690 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1691 selectEntry(menu
, newSelectedEntry
);
1693 /* Pointer fell outside of menu. If the selected entry is
1694 * not a submenu, unselect it */
1695 if (menu
->selected_entry
>= 0
1696 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1697 selectEntry(menu
, -1);
1698 newSelectedEntry
= 0;
1701 /* paranoid check */
1702 if (newSelectedEntry
>= 0) {
1703 /* keep scrolling */
1704 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1705 dragScrollMenuCallback
, menu
);
1710 /* don't need to scroll anymore */
1712 if (findMenu(scr
, &x
, &y
)) {
1713 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1714 selectEntry(menu
, newSelectedEntry
);
1721 scrollMenuCallback(void *data
)
1723 WMenu
*menu
= (WMenu
*)data
;
1724 WMenu
*parent
= parentMenu(menu
);
1725 int hamount
= 0; /* amount to scroll */
1728 #ifdef VIRTUAL_DESKTOP
1729 /* don't scroll if it is in vdesk mode */
1730 if (!wPreferences
.vdesk_enable
)
1732 getScrollAmount(menu
, &hamount
, &vamount
);
1734 if (hamount
!= 0 || vamount
!= 0) {
1735 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1736 parent
->frame_y
+ vamount
, True
);
1738 /* keep scrolling */
1739 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1740 scrollMenuCallback
, menu
);
1742 /* don't need to scroll anymore */
1749 #define MENU_SCROLL_BORDER 5
1752 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1754 int menuX1
= menu
->frame_x
;
1755 int menuY1
= menu
->frame_y
;
1756 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1757 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1759 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1760 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1762 /* XXX: handle screen joins properly !! */
1764 if (x
>= menuX1
&& x
<= menuX2
&&
1765 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
||
1766 y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1768 else if (y
>= menuY1
&& y
<= menuY2
&&
1769 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
||
1770 x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1777 typedef struct _delay
{
1786 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1787 dl
->menu
->jump_back
= NULL
;
1788 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1794 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1797 WMenu
*omenu
= parentMenu(menu
);
1798 WScreen
*scr
= menu
->frame
->screen_ptr
;
1801 int old_frame_x
= omenu
->frame_x
;
1802 int old_frame_y
= omenu
->frame_y
;
1805 if (omenu
->jump_back
)
1806 WMDeleteTimerWithClientData(omenu
->jump_back
);
1809 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1810 || omenu
->flags
.app_menu
) {
1814 if (!wPreferences
.wrap_menus
)
1815 raiseMenus(omenu
, True
);
1817 raiseMenus(menu
, False
);
1820 scrollMenuCallback(menu
);
1823 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1826 WMNextEvent(dpy
, &ev
);
1831 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1832 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1834 /* on_border is != 0 if the pointer is between the menu
1835 * and the screen border and is close enough to the border */
1836 on_border
= isPointNearBoder(menu
, x
, y
);
1838 smenu
= wMenuUnderPointer(scr
);
1840 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1845 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1846 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1847 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1848 on_border
= on_x_edge
|| on_y_edge
;
1850 if (!on_border
&& !jump_back
) {
1855 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1856 WMDeleteTimerHandler(menu
->timer
);
1864 scrollMenuCallback(menu
);
1867 /* True if we push on title, or drag the omenu to other position */
1868 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1869 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1870 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1871 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1873 smenu
= wMenuUnderPointer(scr
);
1874 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1876 else if (smenu
==omenu
&& on_title
) {
1890 WMDeleteTimerHandler(menu
->timer
);
1896 if (!omenu
->jump_back
) {
1897 delayer
= wmalloc(sizeof(_delay
));
1898 delayer
->menu
=omenu
;
1899 delayer
->ox
=old_frame_x
;
1900 delayer
->oy
=old_frame_y
;
1901 omenu
->jump_back
= delayer
;
1902 scr
->flags
.jump_back_pending
= 1;
1904 else delayer
= omenu
->jump_back
;
1905 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)leaving
, delayer
);
1912 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1914 wMenuPaint(desc
->parent
);
1918 int *delayed_select
;
1925 delaySelection(void *data
)
1927 delay_data
*d
= (delay_data
*)data
;
1933 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1934 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1935 entry_no
= getEntryAt(menu
, x
, y
);
1936 selectEntry(menu
, entry_no
);
1938 if (d
->delayed_select
)
1939 *(d
->delayed_select
) = 0;
1944 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1946 XButtonEvent
*bev
= &event
->xbutton
;
1947 WMenu
*menu
= desc
->parent
;
1949 WScreen
*scr
=menu
->frame
->screen_ptr
;
1950 WMenuEntry
*entry
=NULL
;
1952 int close_on_exit
=0;
1954 int delayed_select
= 0;
1958 int old_frame_x
= 0;
1959 int old_frame_y
= 0;
1960 delay_data d_data
= {NULL
, NULL
, NULL
};
1962 /* Doesn't seem to be needed anymore (if delayed selection handler is
1963 * added only if not present). there seem to be no other side effects
1964 * from removing this and it is also possible that it was only added
1965 * to avoid problems with adding the delayed selection timer handler
1968 /*if (menu->flags.inside_handler) {
1971 menu
->flags
.inside_handler
= 1;
1973 if (!wPreferences
.wrap_menus
) {
1974 smenu
= parentMenu(menu
);
1975 old_frame_x
= smenu
->frame_x
;
1976 old_frame_y
= smenu
->frame_y
;
1977 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1978 /* This is true if the menu was launched with right click on root window */
1979 if (!d_data
.magic
) {
1981 d_data
.delayed_select
= &delayed_select
;
1983 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1984 delaySelection
, &d_data
);
1988 wRaiseFrame(menu
->frame
->core
);
1990 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1992 smenu
= findMenu(scr
, &x
, &y
);
2000 if (menu
->flags
.editing
) {
2003 entry_no
= getEntryAt(menu
, x
, y
);
2005 entry
= menu
->entries
[entry_no
];
2007 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
2008 && entry
->flags
.editable
) {
2009 editEntry(smenu
, entry
);
2011 } else if (bev
->state
& ControlMask
) {
2015 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
2016 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2018 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
2019 menu
->selected_entry
!=entry_no
) {
2020 wMenuUnmap(submenu
);
2022 if (!submenu
->flags
.mapped
&& !delayed_select
) {
2023 selectEntry(menu
, entry_no
);
2024 } else if (!submenu
->flags
.buttoned
) {
2025 selectEntry(menu
, -1);
2028 } else if (!delayed_select
) {
2029 selectEntry(menu
, entry_no
);
2032 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2034 dragScrollMenuCallback(menu
);
2038 #ifdef VIRTUAL_DESKTOP
2039 if (wPreferences
.vdesk_enable
) {
2040 wWorkspaceLowerEdge(scr
);
2044 prevx
= bev
->x_root
;
2045 prevy
= bev
->y_root
;
2049 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2051 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2052 |ButtonPressMask
, &ev
);
2055 smenu
= findMenu(scr
, &x
, &y
);
2057 if (smenu
== NULL
) {
2058 /* moved mouse out of menu */
2060 if (!delayed_select
&& d_data
.magic
) {
2061 WMDeleteTimerHandler(d_data
.magic
);
2062 d_data
.magic
= NULL
;
2065 || (menu
->selected_entry
>=0
2066 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2067 prevx
= ev
.xmotion
.x_root
;
2068 prevy
= ev
.xmotion
.y_root
;
2072 selectEntry(menu
, -1);
2074 prevx
= ev
.xmotion
.x_root
;
2075 prevy
= ev
.xmotion
.y_root
;
2077 } else if (menu
&& menu
!=smenu
2078 && (menu
->selected_entry
<0
2079 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2080 selectEntry(menu
, -1);
2082 if (!delayed_select
&& d_data
.magic
) {
2083 WMDeleteTimerHandler(d_data
.magic
);
2084 d_data
.magic
= NULL
;
2088 /* hysteresis for item selection */
2090 /* check if the motion was to the side, indicating that
2091 * the user may want to cross to a submenu */
2092 if (!delayed_select
&& menu
) {
2094 Bool moved_to_submenu
;/* moved to direction of submenu */
2096 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2098 moved_to_submenu
= False
;
2099 if (dx
> 0 /* if moved enough to the side */
2100 /* maybe a open submenu */
2101 && menu
->selected_entry
>=0
2102 /* moving to the right direction */
2103 && (wPreferences
.align_menus
2104 || ev
.xmotion
.y_root
>= prevy
)) {
2107 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2109 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2110 if (prevx
< ev
.xmotion
.x_root
)
2111 moved_to_submenu
= True
;
2113 if (prevx
> ev
.xmotion
.x_root
)
2114 moved_to_submenu
= True
;
2120 if (menu
!= smenu
) {
2122 WMDeleteTimerHandler(d_data
.magic
);
2123 d_data
.magic
= NULL
;
2125 } else if (moved_to_submenu
) {
2126 /* while we are moving, postpone the selection */
2128 WMDeleteTimerHandler(d_data
.magic
);
2130 d_data
.delayed_select
= NULL
;
2132 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2135 prevx
= ev
.xmotion
.x_root
;
2136 prevy
= ev
.xmotion
.y_root
;
2140 WMDeleteTimerHandler(d_data
.magic
);
2141 d_data
.magic
= NULL
;
2146 prevx
= ev
.xmotion
.x_root
;
2147 prevy
= ev
.xmotion
.y_root
;
2149 /* pointer crossed menus */
2150 if (menu
&& menu
->timer
) {
2151 WMDeleteTimerHandler(menu
->timer
);
2155 dragScrollMenuCallback(smenu
);
2159 dragScrollMenuCallback(menu
);
2161 if (!delayed_select
) {
2162 entry_no
= getEntryAt(menu
, x
, y
);
2164 entry
= menu
->entries
[entry_no
];
2165 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2167 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2168 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2169 && menu
->selected_entry
!=entry_no
) {
2170 wMenuUnmap(submenu
);
2174 selectEntry(menu
, entry_no
);
2182 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2188 #ifdef VIRTUAL_DESKTOP
2189 /* since expose will raise edge up.. I need another ugly hack here */
2190 if (wPreferences
.vdesk_enable
) {
2191 wWorkspaceLowerEdge(scr
);
2198 if (menu
&& menu
->timer
) {
2199 WMDeleteTimerHandler(menu
->timer
);
2202 if (d_data
.magic
!=NULL
) {
2203 WMDeleteTimerHandler(d_data
.magic
);
2204 d_data
.magic
= NULL
;
2207 if (menu
&& menu
->selected_entry
>=0) {
2208 entry
= menu
->entries
[menu
->selected_entry
];
2209 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2210 && entry
->cascade
< 0) {
2211 /* blink and erase menu selection */
2212 #if (MENU_BLINK_DELAY > 0)
2213 int sel
= menu
->selected_entry
;
2216 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2217 paintEntry(menu
, sel
, False
);
2219 wusleep(MENU_BLINK_DELAY
);
2220 paintEntry(menu
, sel
, True
);
2222 wusleep(MENU_BLINK_DELAY
);
2225 /* unmap the menu, it's parents and call the callback */
2226 if (!menu
->flags
.buttoned
&&
2227 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2230 selectEntry(menu
, -1);
2232 (*entry
->callback
)(menu
, entry
);
2234 /* If the user double clicks an entry, the entry will
2235 * be executed twice, which is not good for things like
2236 * the root menu. So, ignore any clicks that were generated
2237 * while the entry was being executed */
2238 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2240 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2241 selectEntry(menu
, -1);
2243 if (entry
->cascade
>=0 && menu
->cascades
2244 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2245 selectEntry(menu
, -1);
2250 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2251 closeCascade(desc
->parent
);
2253 /* close the cascade windows that should not remain opened */
2254 closeBrotherCascadesOf(desc
->parent
);
2256 if (!wPreferences
.wrap_menus
)
2257 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2260 /* Just to be sure in case we skip the 2 above because of a goto byebye */
2261 if (menu
&& menu
->timer
) {
2262 WMDeleteTimerHandler(menu
->timer
);
2265 if (d_data
.magic
!=NULL
) {
2266 WMDeleteTimerHandler(d_data
.magic
);
2267 d_data
.magic
= NULL
;
2270 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2271 #ifdef VIRTUAL_DESKTOP
2272 wWorkspaceRaiseEdge(scr
);
2278 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2287 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2289 if (submenus
>0 && menu
->selected_entry
>=0) {
2290 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2292 if (i
>=0 && menu
->cascades
) {
2293 submenu
= menu
->cascades
[i
];
2294 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2295 if (wPreferences
.align_menus
) {
2296 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2298 wMenuMove(submenu
, x
+ MENUW(menu
),
2299 y
+ submenu
->entry_height
*menu
->selected_entry
,
2305 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2306 !menu
->parent
->flags
.buttoned
) {
2307 if (wPreferences
.align_menus
) {
2308 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2310 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2311 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2319 changeMenuLevels(WMenu
*menu
, int lower
)
2324 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2326 wRaiseFrame(menu
->frame
->core
);
2327 menu
->flags
.lowered
= 0;
2329 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2330 wLowerFrame(menu
->frame
->core
);
2331 menu
->flags
.lowered
= 1;
2333 for (i
=0; i
<menu
->cascade_no
; i
++) {
2334 if (menu
->cascades
[i
]
2335 && !menu
->cascades
[i
]->flags
.buttoned
2336 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2337 changeMenuLevels(menu
->cascades
[i
], lower
);
2345 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2350 if (event
->xbutton
.state
& MOD_MASK
) {
2351 if (menu
->flags
.lowered
) {
2356 changeMenuLevels(menu
, lower
);
2362 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2367 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2368 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2372 /* can't touch the menu copy */
2373 if (menu
->flags
.brother
)
2376 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2379 if (event
->xbutton
.state
& MOD_MASK
) {
2380 wLowerFrame(menu
->frame
->core
);
2383 wRaiseFrame(menu
->frame
->core
);
2388 /* lower/raise all submenus */
2390 if (tmp
->selected_entry
>=0 && tmp
->cascades
2391 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2392 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2393 if (!tmp
|| !tmp
->flags
.mapped
)
2396 wLowerFrame(tmp
->frame
->core
);
2398 wRaiseFrame(tmp
->frame
->core
);
2404 /* tear off the menu if it's a root menu or a cascade
2406 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2407 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2408 menu
->flags
.buttoned
=1;
2409 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2411 /* turn off selected menu entry in parent menu */
2412 selectEntry(menu
->parent
, -1);
2414 /* make parent map the copy in place of the original */
2415 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2416 if (menu
->parent
->cascades
[i
] == menu
) {
2417 menu
->parent
->cascades
[i
] = menu
->brother
;
2426 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2427 |ExposureMask
, &ev
);
2431 x
+= ev
.xmotion
.x_root
- dx
;
2432 y
+= ev
.xmotion
.y_root
- dy
;
2433 dx
= ev
.xmotion
.x_root
;
2434 dy
= ev
.xmotion
.y_root
;
2435 wMenuMove(menu
, x
, y
, True
);
2437 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2438 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2440 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2441 ButtonMotionMask
|ButtonReleaseMask
2443 GrabModeAsync
, GrabModeAsync
, None
,
2444 wCursor
[WCUR_MOVE
], CurrentTime
);
2453 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2455 XUngrabPointer(dpy
, CurrentTime
);
2466 *----------------------------------------------------------------------
2468 * Handles mouse click on the close button of menus. The menu is
2469 * closed when the button is clicked.
2472 * The closed menu is reinserted at it's parent menus
2474 *----------------------------------------------------------------------
2477 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2479 WMenu
*menu
= (WMenu
*)data
;
2480 WMenu
*parent
= menu
->parent
;
2484 for (i
=0; i
<parent
->cascade_no
; i
++) {
2485 /* find the entry that points to the copy */
2486 if (parent
->cascades
[i
] == menu
->brother
) {
2487 /* make it point to the original */
2488 parent
->cascades
[i
] = menu
;
2489 menu
->parent
= parent
;
2499 saveMenuInfo(WMPropList
*dict
, WMenu
*menu
, WMPropList
*key
)
2501 WMPropList
*value
, *list
;
2504 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2505 value
= WMCreatePLString(buffer
);
2506 list
= WMCreatePLArray(value
, NULL
);
2507 if (menu
->flags
.lowered
)
2508 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2509 WMPutInPLDictionary(dict
, key
, list
);
2510 WMReleasePropList(value
);
2511 WMReleasePropList(list
);
2516 wMenuSaveState(WScreen
*scr
)
2518 WMPropList
*menus
, *key
;
2521 menus
= WMCreatePLDictionary(NULL
, NULL
);
2524 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2525 key
= WMCreatePLString("SwitchMenu");
2526 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2527 WMReleasePropList(key
);
2531 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2535 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2536 key
= WMCreatePLString("WorkspaceMenu");
2537 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2538 WMReleasePropList(key
);
2543 key
= WMCreatePLString("Menus");
2544 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2545 WMReleasePropList(key
);
2547 WMReleasePropList(menus
);
2554 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2559 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2562 len
= strlen(menu
->frame
->title
);
2567 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2572 strcat(buffer
, "\\");
2573 strcat(buffer
, menu
->frame
->title
);
2580 saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
)
2583 int save_menus
= 0, i
;
2588 if (menu
->flags
.brother
)
2589 menu
= menu
->brother
;
2591 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2594 ok
= getMenuPath(menu
, buffer
, 510);
2597 key
= WMCreatePLString(buffer
);
2598 saveMenuInfo(menus
, menu
, key
);
2599 WMReleasePropList(key
);
2605 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2606 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2615 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2619 getMenuInfo(WMPropList
*info
, int *x
, int *y
, Bool
*lowered
)
2625 if (WMIsPLArray(info
)) {
2627 pos
= WMGetFromPLArray(info
, 0);
2628 flags
= WMGetFromPLArray(info
, 1);
2629 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2630 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2637 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2638 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
)!=2)
2639 COMPLAIN("Position");
2641 COMPLAIN("(position, flags...)");
2650 restoreMenu(WScreen
*scr
, WMPropList
*menu
, int which
)
2653 Bool lowered
= False
;
2654 WMenu
*pmenu
= NULL
;
2659 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2664 if (which
& WSS_SWITCHMENU
) {
2665 OpenSwitchMenu(scr
, x
, y
, False
);
2666 pmenu
= scr
->switch_menu
;
2671 int width
= MENUW(pmenu
);
2672 int height
= MENUH(pmenu
);
2673 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2676 changeMenuLevels(pmenu
, True
);
2679 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2680 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2681 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2682 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2684 wMenuMove(pmenu
, x
, y
, True
);
2685 pmenu
->flags
.buttoned
= 1;
2686 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2695 restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
)
2697 WMPropList
*key
, *entry
;
2702 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2705 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2706 key
= WMCreatePLString(buffer
);
2707 entry
= WMGetFromPLDictionary(menus
, key
);
2710 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2712 if (!menu
->flags
.mapped
) {
2713 int width
= MENUW(menu
);
2714 int height
= MENUH(menu
);
2715 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2717 wMenuMapAt(menu
, x
, y
, False
);
2720 /* make parent map the copy in place of the original */
2721 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2722 if (menu
->parent
->cascades
[i
] == menu
) {
2723 menu
->parent
->cascades
[i
] = menu
->brother
;
2729 changeMenuLevels(menu
, True
);
2732 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2733 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2734 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2735 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2737 wMenuMove(menu
, x
, y
, True
);
2738 menu
->flags
.buttoned
= 1;
2739 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2744 WMReleasePropList(key
);
2746 for (i
=0; i
<menu
->cascade_no
; i
++) {
2747 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2757 wMenuRestoreState(WScreen
*scr
)
2759 WMPropList
*menus
, *menu
, *key
, *skey
;
2761 if (!scr
->session_state
) {
2765 key
= WMCreatePLString("Menus");
2766 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2767 WMReleasePropList(key
);
2774 skey
= WMCreatePLString("SwitchMenu");
2775 menu
= WMGetFromPLDictionary(menus
, skey
);
2776 WMReleasePropList(skey
);
2777 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2780 if (!scr
->root_menu
) {
2781 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2782 wMenuUnmap(scr
->root_menu
);
2784 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2790 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2792 WMenu
*menu
, *parent
;
2796 if (!scr
->root_menu
) {
2797 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2798 wMenuUnmap(scr
->root_menu
);
2801 menu
= scr
->workspace_menu
;
2803 if (menu
->flags
.mapped
) {
2804 if (!menu
->flags
.buttoned
) {
2806 parent
= menu
->parent
;
2807 if (parent
&& parent
->selected_entry
>= 0) {
2808 entry
= parent
->entries
[parent
->selected_entry
];
2809 if (parent
->cascades
[entry
->cascade
] == menu
) {
2810 selectEntry(parent
, -1);
2811 wMenuMapAt(menu
, x
, y
, False
);
2815 wRaiseFrame(menu
->frame
->core
);
2816 wMenuMapCopyAt(menu
, x
, y
);
2819 wMenuMapAt(menu
, x
, y
, False
);