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
);
1081 index
= check_key(menu
, &event
.xkey
);
1083 selectEntry(menu
, index
);
1089 if (event
.type
==ButtonPress
)
1092 WMHandleEvent(&event
);
1096 XUngrabKeyboard(dpy
, CurrentTime
);
1098 if (done
==2 && menu
->selected_entry
>=0) {
1099 entry
= menu
->entries
[menu
->selected_entry
];
1104 if (entry
&& entry
->callback
!=NULL
&& entry
->flags
.enabled
1105 && entry
->cascade
< 0) {
1106 #if (MENU_BLINK_COUNT > 0)
1107 int sel
= menu
->selected_entry
;
1110 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
1111 paintEntry(menu
, sel
, False
);
1113 wusleep(MENU_BLINK_DELAY
);
1114 paintEntry(menu
, sel
, True
);
1116 wusleep(MENU_BLINK_DELAY
);
1119 selectEntry(menu
, -1);
1121 if (!menu
->flags
.buttoned
) {
1123 move_menus(menu
, old_pos_x
, old_pos_y
);
1127 (*entry
->callback
)(menu
, entry
);
1129 if (!menu
->flags
.buttoned
) {
1131 move_menus(menu
, old_pos_x
, old_pos_y
);
1133 selectEntry(menu
, -1);
1137 /* returns True if returning from a submenu to a parent menu,
1138 * False if exiting from menu */
1144 wMenuMapAt(WMenu
*menu
, int x
, int y
, int keyboard
)
1146 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
1147 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
1149 if (!menu
->flags
.realized
) {
1150 menu
->flags
.realized
=1;
1153 if (!menu
->flags
.mapped
) {
1154 if (wPreferences
.wrap_menus
) {
1155 if (x
<rect
.pos
.x
) x
= rect
.pos
.x
;
1156 if (y
<rect
.pos
.y
) y
= rect
.pos
.y
;
1157 if (x
+MENUW(menu
) > rect
.pos
.x
+ rect
.size
.width
)
1158 x
= rect
.pos
.x
+ rect
.size
.width
- MENUW(menu
);
1159 if (y
+MENUH(menu
) > rect
.pos
.y
+ rect
.size
.height
)
1160 y
= rect
.pos
.y
+ rect
.size
.height
- MENUH(menu
);
1163 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
1166 XMapWindow(dpy
, menu
->frame
->core
->window
);
1167 wRaiseFrame(menu
->frame
->core
);
1168 menu
->flags
.mapped
= 1;
1170 selectEntry(menu
, 0);
1179 wMenuMap(WMenu
*menu
)
1181 if (!menu
->flags
.realized
) {
1182 menu
->flags
.realized
=1;
1185 if (menu
->flags
.app_menu
&& menu
->parent
==NULL
) {
1186 menu
->frame_x
= menu
->frame
->screen_ptr
->app_menu_x
;
1187 menu
->frame_y
= menu
->frame
->screen_ptr
->app_menu_y
;
1188 XMoveWindow(dpy
, menu
->frame
->core
->window
, menu
->frame_x
, menu
->frame_y
);
1190 XMapWindow(dpy
, menu
->frame
->core
->window
);
1191 wRaiseFrame(menu
->frame
->core
);
1192 menu
->flags
.mapped
= 1;
1197 wMenuUnmap(WMenu
*menu
)
1201 XUnmapWindow(dpy
, menu
->frame
->core
->window
);
1202 if (menu
->flags
.titled
&& menu
->flags
.buttoned
) {
1203 wFrameWindowHideButton(menu
->frame
, WFF_RIGHT_BUTTON
);
1205 menu
->flags
.buttoned
= 0;
1206 menu
->flags
.mapped
= 0;
1207 menu
->flags
.open_to_left
= 0;
1209 for (i
=0; i
<menu
->cascade_no
; i
++) {
1210 if (menu
->cascades
[i
]!=NULL
1211 && menu
->cascades
[i
]->flags
.mapped
1212 && !menu
->cascades
[i
]->flags
.buttoned
) {
1214 wMenuUnmap(menu
->cascades
[i
]);
1217 menu
->selected_entry
= -1;
1223 wMenuPaint(WMenu
*menu
)
1227 if (!menu
->flags
.mapped
) {
1232 for (i
=0; i
<menu
->entry_no
; i
++) {
1233 paintEntry(menu
, i
, i
==menu
->selected_entry
);
1239 wMenuSetEnabled(WMenu
*menu
, int index
, int enable
)
1241 if (index
>=menu
->entry_no
) return;
1242 menu
->entries
[index
]->flags
.enabled
=enable
;
1243 paintEntry(menu
, index
, index
==menu
->selected_entry
);
1244 paintEntry(menu
->brother
, index
, index
==menu
->selected_entry
);
1248 /* ====================================================================== */
1252 editEntry(WMenu
*menu
, WMenuEntry
*entry
)
1256 WObjDescriptor
*desc
;
1262 menu
->flags
.editing
= 1;
1264 text
= wTextCreate(menu
->menu
, 1, menu
->entry_height
* entry
->order
,
1265 menu
->menu
->width
- 2, menu
->entry_height
- 1);
1267 wTextPutText(text
, entry
->text
);
1268 XGetInputFocus(dpy
, &old_focus
, &old_revert
);
1269 XSetInputFocus(dpy
, text
->core
->window
, RevertToNone
, CurrentTime
);
1271 if (XGrabKeyboard(dpy
, text
->core
->window
, True
, GrabModeAsync
,
1272 GrabModeAsync
, CurrentTime
)!=GrabSuccess
) {
1273 wwarning(_("could not grab keyboard"));
1276 wSetFocusTo(menu
->frame
->screen_ptr
,
1277 menu
->frame
->screen_ptr
->focused_window
);
1282 while (!done
&& !text
->done
) {
1284 XAllowEvents(dpy
, AsyncKeyboard
|AsyncPointer
, CurrentTime
);
1286 WMNextEvent(dpy
, &event
);
1288 if (XFindContext(dpy
, event
.xany
.window
, wWinContext
,
1289 (XPointer
*)&desc
)==XCNOENT
)
1292 if ((desc
!= NULL
) && (desc
->handle_anything
!= NULL
)) {
1294 (*desc
->handle_anything
)(desc
, &event
);
1297 switch (event
.type
) {
1299 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
1303 WMHandleEvent(&event
);
1309 XSetInputFocus(dpy
, old_focus
, old_revert
, CurrentTime
);
1311 wSetFocusTo(menu
->frame
->screen_ptr
,
1312 menu
->frame
->screen_ptr
->focused_window
);
1315 t
= wTextGetText(text
);
1316 /* if !t, the user has canceled editing */
1320 entry
->text
= wstrdup(t
);
1322 menu
->flags
.realized
= 0;
1326 XUngrabKeyboard(dpy
, CurrentTime
);
1328 if (t
&& menu
->on_edit
)
1329 (*menu
->on_edit
)(menu
, entry
);
1331 menu
->flags
.editing
= 0;
1333 if (!menu
->flags
.realized
)
1339 selectEntry(WMenu
*menu
, int entry_no
)
1345 if (menu
->entries
==NULL
)
1348 if (entry_no
>= menu
->entry_no
)
1351 old_entry
= menu
->selected_entry
;
1352 menu
->selected_entry
= entry_no
;
1354 if (old_entry
!=entry_no
) {
1356 /* unselect previous entry */
1358 paintEntry(menu
, old_entry
, False
);
1359 entry
= menu
->entries
[old_entry
];
1362 if (entry
->cascade
>=0 && menu
->cascades
) {
1363 if (!menu
->cascades
[entry
->cascade
]->flags
.buttoned
) {
1364 wMenuUnmap(menu
->cascades
[entry
->cascade
]);
1370 menu
->selected_entry
= -1;
1373 entry
= menu
->entries
[entry_no
];
1375 if (entry
->cascade
>=0 && menu
->cascades
&& entry
->flags
.enabled
) {
1376 /* Callback for when the submenu is opened.
1378 submenu
= menu
->cascades
[entry
->cascade
];
1379 if (submenu
&& submenu
->flags
.brother
)
1380 submenu
= submenu
->brother
;
1382 if (entry
->callback
) {
1383 /* Only call the callback if the submenu is not yet mapped.
1385 if (menu
->flags
.brother
) {
1386 if (!submenu
|| !submenu
->flags
.mapped
)
1387 (*entry
->callback
)(menu
->brother
, entry
);
1389 if (!submenu
|| !submenu
->flags
.buttoned
)
1390 (*entry
->callback
)(menu
, entry
);
1394 /* the submenu menu might have changed */
1395 submenu
= menu
->cascades
[entry
->cascade
];
1398 if (!submenu
->flags
.mapped
) {
1401 if (!submenu
->flags
.realized
)
1402 wMenuRealize(submenu
);
1403 if (wPreferences
.wrap_menus
) {
1404 if (menu
->flags
.open_to_left
)
1405 submenu
->flags
.open_to_left
= 1;
1407 if (submenu
->flags
.open_to_left
) {
1408 x
= menu
->frame_x
- MENUW(submenu
);
1411 submenu
->flags
.open_to_left
= 0;
1414 x
= menu
->frame_x
+ MENUW(menu
);
1416 if (x
+ MENUW(submenu
)
1417 >= menu
->frame
->screen_ptr
->scr_width
) {
1419 x
= menu
->frame_x
- MENUW(submenu
);
1420 submenu
->flags
.open_to_left
= 1;
1424 x
= menu
->frame_x
+ MENUW(menu
);
1427 if (wPreferences
.align_menus
) {
1430 y
= menu
->frame_y
+ menu
->entry_height
*entry_no
;
1431 if (menu
->flags
.titled
)
1432 y
+= menu
->frame
->top_width
;
1433 if (menu
->cascades
[entry
->cascade
]->flags
.titled
)
1434 y
-= menu
->cascades
[entry
->cascade
]->frame
->top_width
;
1437 wMenuMapAt(menu
->cascades
[entry
->cascade
], x
, y
, False
);
1438 menu
->cascades
[entry
->cascade
]->parent
= menu
;
1443 paintEntry(menu
, entry_no
, True
);
1449 findMenu(WScreen
*scr
, int *x_ret
, int *y_ret
)
1452 WObjDescriptor
*desc
;
1453 Window root_ret
, win
, junk_win
;
1457 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, &x
, &y
, &wx
, &wy
,
1460 if (win
==None
) return NULL
;
1462 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1465 if (desc
->parent_type
== WCLASS_MENU
) {
1466 menu
= (WMenu
*)desc
->parent
;
1467 XTranslateCoordinates(dpy
, root_ret
, menu
->menu
->window
, wx
, wy
,
1468 x_ret
, y_ret
, &junk_win
);
1478 closeCascade(WMenu
*menu
)
1480 WMenu
*parent
=menu
->parent
;
1482 if (menu
->flags
.brother
1483 || (!menu
->flags
.buttoned
1484 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
))) {
1486 selectEntry(menu
, -1);
1488 #if (MENU_BLINK_DELAY > 2)
1489 wusleep(MENU_BLINK_DELAY
/2);
1493 && (parent
->parent
!=NULL
|| !parent
->flags
.app_menu
1494 || parent
->flags
.brother
)
1495 && !parent
->flags
.buttoned
) {
1496 selectEntry(parent
, -1);
1498 parent
= parent
->parent
;
1501 selectEntry(parent
, -1);
1507 closeBrotherCascadesOf(WMenu
*menu
)
1512 for (i
=0; i
<menu
->cascade_no
; i
++) {
1513 if (menu
->cascades
[i
]->flags
.brother
) {
1514 tmp
= menu
->cascades
[i
];
1516 tmp
= menu
->cascades
[i
]->brother
;
1518 if (tmp
->flags
.mapped
) {
1519 selectEntry(tmp
->parent
, -1);
1520 closeBrotherCascadesOf(tmp
);
1527 #define getEntryAt(menu, x, y) ((y)<0 ? -1 : (y)/(menu->entry_height))
1531 parentMenu(WMenu
*menu
)
1536 if (menu
->flags
.buttoned
)
1539 while (menu
->parent
&& menu
->parent
->flags
.mapped
) {
1540 parent
= menu
->parent
;
1541 if (parent
->selected_entry
< 0)
1543 entry
= parent
->entries
[parent
->selected_entry
];
1544 if (!entry
->flags
.enabled
|| entry
->cascade
<0 || !parent
->cascades
||
1545 parent
->cascades
[entry
->cascade
] != menu
)
1548 if (menu
->flags
.buttoned
)
1558 * Will raise the passed menu, if submenu = 0
1559 * If submenu > 0 will also raise all mapped submenus
1560 * until the first buttoned one
1561 * If submenu < 0 will also raise all mapped parent menus
1562 * until the first buttoned one
1566 raiseMenus(WMenu
*menu
, int submenus
)
1573 wRaiseFrame(menu
->frame
->core
);
1575 if (submenus
>0 && menu
->selected_entry
>=0) {
1576 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
1577 if (i
>=0 && menu
->cascades
) {
1578 submenu
= menu
->cascades
[i
];
1579 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
)
1580 raiseMenus(submenu
, submenus
);
1583 if (submenus
<0 && !menu
->flags
.buttoned
&&
1584 menu
->parent
&& menu
->parent
->flags
.mapped
)
1585 raiseMenus(menu
->parent
, submenus
);
1590 wMenuUnderPointer(WScreen
*screen
)
1592 WObjDescriptor
*desc
;
1593 Window root_ret
, win
;
1597 XQueryPointer(dpy
, screen
->root_win
, &root_ret
, &win
, &dummy
, &dummy
,
1598 &dummy
, &dummy
, &mask
);
1600 if (win
==None
) return NULL
;
1602 if (XFindContext(dpy
, win
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
1605 if (desc
->parent_type
== WCLASS_MENU
)
1606 return (WMenu
*)desc
->parent
;
1614 getPointerPosition(WScreen
*scr
, int *x
, int *y
)
1616 Window root_ret
, win
;
1620 XQueryPointer(dpy
, scr
->root_win
, &root_ret
, &win
, x
, y
, &wx
, &wy
, &mask
);
1625 getScrollAmount(WMenu
*menu
, int *hamount
, int *vamount
)
1627 WScreen
*scr
= menu
->menu
->screen_ptr
;
1628 int menuX1
= menu
->frame_x
;
1629 int menuY1
= menu
->frame_y
;
1630 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1631 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1633 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1639 getPointerPosition(scr
, &xroot
, &yroot
);
1641 if (xroot
<= (rect
.pos
.x
+ 1) && menuX1
< rect
.pos
.x
) {
1642 /* scroll to the right */
1643 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX1
));
1645 } else if (xroot
>= (rect
.pos
.x
+ rect
.size
.width
- 2) &&
1646 menuX2
> (rect
.pos
.x
+ rect
.size
.width
- 1)) {
1647 /* scroll to the left */
1648 *hamount
= WMIN(MENU_SCROLL_STEP
, abs(menuX2
-rect
.pos
.x
-rect
.size
.width
-1));
1653 *hamount
= -*hamount
;
1656 if (yroot
<= (rect
.pos
.y
+ 1) && menuY1
< rect
.pos
.y
) {
1658 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY1
));
1660 } else if (yroot
>= (rect
.pos
.y
+ rect
.size
.height
- 2) &&
1661 menuY2
> (rect
.pos
.y
+ rect
.size
.height
- 1)) {
1663 *vamount
= WMIN(MENU_SCROLL_STEP
, abs(menuY2
-rect
.pos
.y
-rect
.size
.height
-2));
1665 *vamount
= -*vamount
;
1671 dragScrollMenuCallback(void *data
)
1673 WMenu
*menu
= (WMenu
*)data
;
1674 WScreen
*scr
= menu
->menu
->screen_ptr
;
1675 WMenu
*parent
= parentMenu(menu
);
1676 int hamount
, vamount
;
1678 int newSelectedEntry
;
1680 getScrollAmount(menu
, &hamount
, &vamount
);
1683 if (hamount
!= 0 || vamount
!= 0) {
1684 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1685 parent
->frame_y
+ vamount
, True
);
1686 if (findMenu(scr
, &x
, &y
)) {
1687 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1688 selectEntry(menu
, newSelectedEntry
);
1690 /* Pointer fell outside of menu. If the selected entry is
1691 * not a submenu, unselect it */
1692 if (menu
->selected_entry
>= 0
1693 && menu
->entries
[menu
->selected_entry
]->cascade
<0)
1694 selectEntry(menu
, -1);
1695 newSelectedEntry
= 0;
1698 /* paranoid check */
1699 if (newSelectedEntry
>= 0) {
1700 /* keep scrolling */
1701 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1702 dragScrollMenuCallback
, menu
);
1707 /* don't need to scroll anymore */
1709 if (findMenu(scr
, &x
, &y
)) {
1710 newSelectedEntry
= getEntryAt(menu
, x
, y
);
1711 selectEntry(menu
, newSelectedEntry
);
1718 scrollMenuCallback(void *data
)
1720 WMenu
*menu
= (WMenu
*)data
;
1721 WMenu
*parent
= parentMenu(menu
);
1722 int hamount
= 0; /* amount to scroll */
1725 #ifdef VIRTUAL_DESKTOP
1726 /* don't scroll if it is in vdesk mode */
1727 if (!wPreferences
.vedge_thickness
)
1729 getScrollAmount(menu
, &hamount
, &vamount
);
1731 if (hamount
!= 0 || vamount
!= 0) {
1732 wMenuMove(parent
, parent
->frame_x
+ hamount
,
1733 parent
->frame_y
+ vamount
, True
);
1735 /* keep scrolling */
1736 menu
->timer
= WMAddTimerHandler(MENU_SCROLL_DELAY
,
1737 scrollMenuCallback
, menu
);
1739 /* don't need to scroll anymore */
1746 #define MENU_SCROLL_BORDER 5
1749 isPointNearBoder(WMenu
*menu
, int x
, int y
)
1751 int menuX1
= menu
->frame_x
;
1752 int menuY1
= menu
->frame_y
;
1753 int menuX2
= menu
->frame_x
+ MENUW(menu
);
1754 int menuY2
= menu
->frame_y
+ MENUH(menu
);
1756 int head
= wGetHeadForPoint(menu
->frame
->screen_ptr
, wmkpoint(x
, y
));
1757 WMRect rect
= wGetRectForHead(menu
->frame
->screen_ptr
, head
);
1759 /* XXX: handle screen joins properly !! */
1761 if (x
>= menuX1
&& x
<= menuX2
&&
1762 (y
< rect
.pos
.y
+ MENU_SCROLL_BORDER
||
1763 y
>= rect
.pos
.y
+ rect
.size
.height
- MENU_SCROLL_BORDER
))
1765 else if (y
>= menuY1
&& y
<= menuY2
&&
1766 (x
< rect
.pos
.x
+ MENU_SCROLL_BORDER
||
1767 x
>= rect
.pos
.x
+ rect
.size
.width
- MENU_SCROLL_BORDER
))
1774 typedef struct _delay
{
1783 wMenuMove(dl
->menu
, dl
->ox
, dl
->oy
, True
);
1784 dl
->menu
->jump_back
= NULL
;
1785 dl
->menu
->menu
->screen_ptr
->flags
.jump_back_pending
= 0;
1791 wMenuScroll(WMenu
*menu
, XEvent
*event
)
1794 WMenu
*omenu
= parentMenu(menu
);
1795 WScreen
*scr
= menu
->frame
->screen_ptr
;
1798 int old_frame_x
= omenu
->frame_x
;
1799 int old_frame_y
= omenu
->frame_y
;
1802 if (omenu
->jump_back
)
1803 WMDeleteTimerWithClientData(omenu
->jump_back
);
1806 if ((/*omenu->flags.buttoned &&*/ !wPreferences
.wrap_menus
)
1807 || omenu
->flags
.app_menu
) {
1811 if (!wPreferences
.wrap_menus
)
1812 raiseMenus(omenu
, True
);
1814 raiseMenus(menu
, False
);
1817 scrollMenuCallback(menu
);
1820 int x
, y
, on_border
, on_x_edge
, on_y_edge
, on_title
;
1823 WMNextEvent(dpy
, &ev
);
1828 x
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.x_root
: ev
.xcrossing
.x_root
;
1829 y
= (ev
.type
==MotionNotify
) ? ev
.xmotion
.y_root
: ev
.xcrossing
.y_root
;
1831 /* on_border is != 0 if the pointer is between the menu
1832 * and the screen border and is close enough to the border */
1833 on_border
= isPointNearBoder(menu
, x
, y
);
1835 smenu
= wMenuUnderPointer(scr
);
1837 if ((smenu
==NULL
&& !on_border
) || (smenu
&& parentMenu(smenu
)!=omenu
)) {
1842 rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, wmkpoint(x
, y
)));
1843 on_x_edge
= x
<= rect
.pos
.x
+ 1 || x
>= rect
.pos
.x
+ rect
.size
.width
- 2;
1844 on_y_edge
= y
<= rect
.pos
.y
+ 1 || y
>= rect
.pos
.y
+ rect
.size
.height
- 2;
1845 on_border
= on_x_edge
|| on_y_edge
;
1847 if (!on_border
&& !jump_back
) {
1852 if (menu
->timer
&& (smenu
!=menu
|| (!on_y_edge
&& !on_x_edge
))) {
1853 WMDeleteTimerHandler(menu
->timer
);
1861 scrollMenuCallback(menu
);
1864 /* True if we push on title, or drag the omenu to other position */
1865 on_title
= ev
.xbutton
.x_root
>= omenu
->frame_x
&&
1866 ev
.xbutton
.x_root
<= omenu
->frame_x
+ MENUW(omenu
) &&
1867 ev
.xbutton
.y_root
>= omenu
->frame_y
&&
1868 ev
.xbutton
.y_root
<= omenu
->frame_y
+ omenu
->frame
->top_width
;
1870 smenu
= wMenuUnderPointer(scr
);
1871 if (smenu
== NULL
|| (smenu
&& smenu
->flags
.buttoned
&& smenu
!= omenu
))
1873 else if (smenu
==omenu
&& on_title
) {
1887 WMDeleteTimerHandler(menu
->timer
);
1893 if (!omenu
->jump_back
) {
1894 delayer
= wmalloc(sizeof(_delay
));
1895 delayer
->menu
=omenu
;
1896 delayer
->ox
=old_frame_x
;
1897 delayer
->oy
=old_frame_y
;
1898 omenu
->jump_back
= delayer
;
1899 scr
->flags
.jump_back_pending
= 1;
1901 else delayer
= omenu
->jump_back
;
1902 WMAddTimerHandler(MENU_JUMP_BACK_DELAY
,(WMCallback
*)leaving
, delayer
);
1909 menuExpose(WObjDescriptor
*desc
, XEvent
*event
)
1911 wMenuPaint(desc
->parent
);
1915 int *delayed_select
;
1922 delaySelection(void *data
)
1924 delay_data
*d
= (delay_data
*)data
;
1930 menu
= findMenu(d
->menu
->menu
->screen_ptr
, &x
, &y
);
1931 if (menu
&& (d
->menu
== menu
|| d
->delayed_select
)) {
1932 entry_no
= getEntryAt(menu
, x
, y
);
1933 selectEntry(menu
, entry_no
);
1935 if (d
->delayed_select
)
1936 *(d
->delayed_select
) = 0;
1941 menuMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
1943 XButtonEvent
*bev
= &event
->xbutton
;
1944 WMenu
*menu
= desc
->parent
;
1946 WScreen
*scr
=menu
->frame
->screen_ptr
;
1947 WMenuEntry
*entry
=NULL
;
1949 int close_on_exit
=0;
1951 int delayed_select
= 0;
1955 int old_frame_x
= 0;
1956 int old_frame_y
= 0;
1957 delay_data d_data
= {NULL
, NULL
, NULL
};
1959 /* Doesn't seem to be needed anymore (if delayed selection handler is
1960 * added only if not present). there seem to be no other side effects
1961 * from removing this and it is also possible that it was only added
1962 * to avoid problems with adding the delayed selection timer handler
1965 /*if (menu->flags.inside_handler) {
1968 menu
->flags
.inside_handler
= 1;
1970 if (!wPreferences
.wrap_menus
) {
1971 smenu
= parentMenu(menu
);
1972 old_frame_x
= smenu
->frame_x
;
1973 old_frame_y
= smenu
->frame_y
;
1974 } else if (event
->xbutton
.window
== menu
->frame
->core
->window
) {
1975 /* This is true if the menu was launched with right click on root window */
1976 if (!d_data
.magic
) {
1978 d_data
.delayed_select
= &delayed_select
;
1980 d_data
.magic
= WMAddTimerHandler(wPreferences
.dblclick_time
,
1981 delaySelection
, &d_data
);
1985 wRaiseFrame(menu
->frame
->core
);
1987 close_on_exit
= (bev
->send_event
|| menu
->flags
.brother
);
1989 smenu
= findMenu(scr
, &x
, &y
);
1997 if (menu
->flags
.editing
) {
2000 entry_no
= getEntryAt(menu
, x
, y
);
2002 entry
= menu
->entries
[entry_no
];
2004 if (!close_on_exit
&& (bev
->state
& ControlMask
) && smenu
2005 && entry
->flags
.editable
) {
2006 editEntry(smenu
, entry
);
2008 } else if (bev
->state
& ControlMask
) {
2012 if (entry
->flags
.enabled
&& entry
->cascade
>=0 && menu
->cascades
) {
2013 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2015 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
&&
2016 menu
->selected_entry
!=entry_no
) {
2017 wMenuUnmap(submenu
);
2019 if (!submenu
->flags
.mapped
&& !delayed_select
) {
2020 selectEntry(menu
, entry_no
);
2021 } else if (!submenu
->flags
.buttoned
) {
2022 selectEntry(menu
, -1);
2025 } else if (!delayed_select
) {
2026 selectEntry(menu
, entry_no
);
2029 if (!wPreferences
.wrap_menus
&& !wPreferences
.scrollable_menus
) {
2031 dragScrollMenuCallback(menu
);
2035 #ifdef VIRTUAL_DESKTOP
2036 if (wPreferences
.vedge_thickness
) {
2037 wWorkspaceLowerEdge(scr
);
2041 prevx
= bev
->x_root
;
2042 prevy
= bev
->y_root
;
2046 XAllowEvents(dpy
, AsyncPointer
|SyncPointer
, CurrentTime
);
2048 WMMaskEvent(dpy
, ExposureMask
|ButtonMotionMask
|ButtonReleaseMask
2049 |ButtonPressMask
, &ev
);
2052 smenu
= findMenu(scr
, &x
, &y
);
2054 if (smenu
== NULL
) {
2055 /* moved mouse out of menu */
2057 if (!delayed_select
&& d_data
.magic
) {
2058 WMDeleteTimerHandler(d_data
.magic
);
2059 d_data
.magic
= NULL
;
2062 || (menu
->selected_entry
>=0
2063 && menu
->entries
[menu
->selected_entry
]->cascade
>=0)) {
2064 prevx
= ev
.xmotion
.x_root
;
2065 prevy
= ev
.xmotion
.y_root
;
2069 selectEntry(menu
, -1);
2071 prevx
= ev
.xmotion
.x_root
;
2072 prevy
= ev
.xmotion
.y_root
;
2074 } else if (menu
&& menu
!=smenu
2075 && (menu
->selected_entry
<0
2076 || menu
->entries
[menu
->selected_entry
]->cascade
<0)) {
2077 selectEntry(menu
, -1);
2079 if (!delayed_select
&& d_data
.magic
) {
2080 WMDeleteTimerHandler(d_data
.magic
);
2081 d_data
.magic
= NULL
;
2085 /* hysteresis for item selection */
2087 /* check if the motion was to the side, indicating that
2088 * the user may want to cross to a submenu */
2089 if (!delayed_select
&& menu
) {
2091 Bool moved_to_submenu
;/* moved to direction of submenu */
2093 dx
= abs(prevx
- ev
.xmotion
.x_root
);
2095 moved_to_submenu
= False
;
2096 if (dx
> 0 /* if moved enough to the side */
2097 /* maybe a open submenu */
2098 && menu
->selected_entry
>=0
2099 /* moving to the right direction */
2100 && (wPreferences
.align_menus
2101 || ev
.xmotion
.y_root
>= prevy
)) {
2104 index
= menu
->entries
[menu
->selected_entry
]->cascade
;
2106 if (menu
->cascades
[index
]->frame_x
>menu
->frame_x
) {
2107 if (prevx
< ev
.xmotion
.x_root
)
2108 moved_to_submenu
= True
;
2110 if (prevx
> ev
.xmotion
.x_root
)
2111 moved_to_submenu
= True
;
2117 if (menu
!= smenu
) {
2119 WMDeleteTimerHandler(d_data
.magic
);
2120 d_data
.magic
= NULL
;
2122 } else if (moved_to_submenu
) {
2123 /* while we are moving, postpone the selection */
2125 WMDeleteTimerHandler(d_data
.magic
);
2127 d_data
.delayed_select
= NULL
;
2129 d_data
.magic
= WMAddTimerHandler(MENU_SELECT_DELAY
,
2132 prevx
= ev
.xmotion
.x_root
;
2133 prevy
= ev
.xmotion
.y_root
;
2137 WMDeleteTimerHandler(d_data
.magic
);
2138 d_data
.magic
= NULL
;
2143 prevx
= ev
.xmotion
.x_root
;
2144 prevy
= ev
.xmotion
.y_root
;
2146 /* pointer crossed menus */
2147 if (menu
&& menu
->timer
) {
2148 WMDeleteTimerHandler(menu
->timer
);
2152 dragScrollMenuCallback(smenu
);
2156 dragScrollMenuCallback(menu
);
2158 if (!delayed_select
) {
2159 entry_no
= getEntryAt(menu
, x
, y
);
2161 entry
= menu
->entries
[entry_no
];
2162 if (entry
->flags
.enabled
&& entry
->cascade
>=0 &&
2164 WMenu
*submenu
= menu
->cascades
[entry
->cascade
];
2165 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
2166 && menu
->selected_entry
!=entry_no
) {
2167 wMenuUnmap(submenu
);
2171 selectEntry(menu
, entry_no
);
2179 if (ev
.xbutton
.button
== event
->xbutton
.button
)
2185 #ifdef VIRTUAL_DESKTOP
2186 /* since expose will raise edge up.. I need another ugly hack here */
2187 if (wPreferences
.vedge_thickness
) {
2188 wWorkspaceLowerEdge(scr
);
2195 if (menu
&& menu
->timer
) {
2196 WMDeleteTimerHandler(menu
->timer
);
2199 if (d_data
.magic
!=NULL
) {
2200 WMDeleteTimerHandler(d_data
.magic
);
2201 d_data
.magic
= NULL
;
2204 if (menu
&& menu
->selected_entry
>=0) {
2205 entry
= menu
->entries
[menu
->selected_entry
];
2206 if (entry
->callback
!=NULL
&& entry
->flags
.enabled
2207 && entry
->cascade
< 0) {
2208 /* blink and erase menu selection */
2209 #if (MENU_BLINK_DELAY > 0)
2210 int sel
= menu
->selected_entry
;
2213 for (i
=0; i
<MENU_BLINK_COUNT
; i
++) {
2214 paintEntry(menu
, sel
, False
);
2216 wusleep(MENU_BLINK_DELAY
);
2217 paintEntry(menu
, sel
, True
);
2219 wusleep(MENU_BLINK_DELAY
);
2222 /* unmap the menu, it's parents and call the callback */
2223 if (!menu
->flags
.buttoned
&&
2224 (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2227 selectEntry(menu
, -1);
2229 (*entry
->callback
)(menu
, entry
);
2231 /* If the user double clicks an entry, the entry will
2232 * be executed twice, which is not good for things like
2233 * the root menu. So, ignore any clicks that were generated
2234 * while the entry was being executed */
2235 while (XCheckTypedWindowEvent(dpy
, menu
->menu
->window
,
2237 } else if (entry
->callback
!=NULL
&& entry
->cascade
<0) {
2238 selectEntry(menu
, -1);
2240 if (entry
->cascade
>=0 && menu
->cascades
2241 && menu
->cascades
[entry
->cascade
]->flags
.brother
) {
2242 selectEntry(menu
, -1);
2247 if (((WMenu
*)desc
->parent
)->flags
.brother
|| close_on_exit
|| !smenu
)
2248 closeCascade(desc
->parent
);
2250 /* close the cascade windows that should not remain opened */
2251 closeBrotherCascadesOf(desc
->parent
);
2253 if (!wPreferences
.wrap_menus
)
2254 wMenuMove(parentMenu(desc
->parent
), old_frame_x
, old_frame_y
, True
);
2257 /* Just to be sure in case we skip the 2 above because of a goto byebye */
2258 if (menu
&& menu
->timer
) {
2259 WMDeleteTimerHandler(menu
->timer
);
2262 if (d_data
.magic
!=NULL
) {
2263 WMDeleteTimerHandler(d_data
.magic
);
2264 d_data
.magic
= NULL
;
2267 ((WMenu
*)desc
->parent
)->flags
.inside_handler
= 0;
2268 #ifdef VIRTUAL_DESKTOP
2269 wWorkspaceRaiseEdge(scr
);
2275 wMenuMove(WMenu
*menu
, int x
, int y
, int submenus
)
2284 XMoveWindow(dpy
, menu
->frame
->core
->window
, x
, y
);
2286 if (submenus
>0 && menu
->selected_entry
>=0) {
2287 i
= menu
->entries
[menu
->selected_entry
]->cascade
;
2289 if (i
>=0 && menu
->cascades
) {
2290 submenu
= menu
->cascades
[i
];
2291 if (submenu
->flags
.mapped
&& !submenu
->flags
.buttoned
) {
2292 if (wPreferences
.align_menus
) {
2293 wMenuMove(submenu
, x
+ MENUW(menu
), y
, submenus
);
2295 wMenuMove(submenu
, x
+ MENUW(menu
),
2296 y
+ submenu
->entry_height
*menu
->selected_entry
,
2302 if (submenus
<0 && menu
->parent
!=NULL
&& menu
->parent
->flags
.mapped
&&
2303 !menu
->parent
->flags
.buttoned
) {
2304 if (wPreferences
.align_menus
) {
2305 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), y
, submenus
);
2307 wMenuMove(menu
->parent
, x
- MENUW(menu
->parent
), menu
->frame_y
2308 - menu
->parent
->entry_height
*menu
->parent
->selected_entry
,
2316 changeMenuLevels(WMenu
*menu
, int lower
)
2321 ChangeStackingLevel(menu
->frame
->core
, (!menu
->parent
? WMMainMenuLevel
2323 wRaiseFrame(menu
->frame
->core
);
2324 menu
->flags
.lowered
= 0;
2326 ChangeStackingLevel(menu
->frame
->core
, WMNormalLevel
);
2327 wLowerFrame(menu
->frame
->core
);
2328 menu
->flags
.lowered
= 1;
2330 for (i
=0; i
<menu
->cascade_no
; i
++) {
2331 if (menu
->cascades
[i
]
2332 && !menu
->cascades
[i
]->flags
.buttoned
2333 && menu
->cascades
[i
]->flags
.lowered
!=lower
) {
2334 changeMenuLevels(menu
->cascades
[i
], lower
);
2342 menuTitleDoubleClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2347 if (event
->xbutton
.state
& MOD_MASK
) {
2348 if (menu
->flags
.lowered
) {
2353 changeMenuLevels(menu
, lower
);
2359 menuTitleMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2364 int x
=menu
->frame_x
, y
=menu
->frame_y
;
2365 int dx
=event
->xbutton
.x_root
, dy
=event
->xbutton
.y_root
;
2369 /* can't touch the menu copy */
2370 if (menu
->flags
.brother
)
2373 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button2
)
2376 if (event
->xbutton
.state
& MOD_MASK
) {
2377 wLowerFrame(menu
->frame
->core
);
2380 wRaiseFrame(menu
->frame
->core
);
2385 /* lower/raise all submenus */
2387 if (tmp
->selected_entry
>=0 && tmp
->cascades
2388 && tmp
->entries
[tmp
->selected_entry
]->cascade
>=0) {
2389 tmp
= tmp
->cascades
[tmp
->entries
[tmp
->selected_entry
]->cascade
];
2390 if (!tmp
|| !tmp
->flags
.mapped
)
2393 wLowerFrame(tmp
->frame
->core
);
2395 wRaiseFrame(tmp
->frame
->core
);
2401 /* tear off the menu if it's a root menu or a cascade
2403 if (!menu
->flags
.buttoned
&& !menu
->flags
.brother
2404 && (!menu
->flags
.app_menu
||menu
->parent
!=NULL
)) {
2405 menu
->flags
.buttoned
=1;
2406 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2408 /* turn off selected menu entry in parent menu */
2409 selectEntry(menu
->parent
, -1);
2411 /* make parent map the copy in place of the original */
2412 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2413 if (menu
->parent
->cascades
[i
] == menu
) {
2414 menu
->parent
->cascades
[i
] = menu
->brother
;
2423 WMMaskEvent(dpy
, ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
2424 |ExposureMask
, &ev
);
2428 x
+= ev
.xmotion
.x_root
- dx
;
2429 y
+= ev
.xmotion
.y_root
- dy
;
2430 dx
= ev
.xmotion
.x_root
;
2431 dy
= ev
.xmotion
.y_root
;
2432 wMenuMove(menu
, x
, y
, True
);
2434 if (abs(ev
.xmotion
.x_root
- dx
) > MOVE_THRESHOLD
2435 || abs(ev
.xmotion
.y_root
- dy
) > MOVE_THRESHOLD
) {
2437 XGrabPointer(dpy
, menu
->frame
->titlebar
->window
, False
,
2438 ButtonMotionMask
|ButtonReleaseMask
2440 GrabModeAsync
, GrabModeAsync
, None
,
2441 wCursor
[WCUR_MOVE
], CurrentTime
);
2450 if (ev
.xbutton
.button
!= event
->xbutton
.button
)
2452 XUngrabPointer(dpy
, CurrentTime
);
2463 *----------------------------------------------------------------------
2465 * Handles mouse click on the close button of menus. The menu is
2466 * closed when the button is clicked.
2469 * The closed menu is reinserted at it's parent menus
2471 *----------------------------------------------------------------------
2474 menuCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2476 WMenu
*menu
= (WMenu
*)data
;
2477 WMenu
*parent
= menu
->parent
;
2481 for (i
=0; i
<parent
->cascade_no
; i
++) {
2482 /* find the entry that points to the copy */
2483 if (parent
->cascades
[i
] == menu
->brother
) {
2484 /* make it point to the original */
2485 parent
->cascades
[i
] = menu
;
2486 menu
->parent
= parent
;
2496 saveMenuInfo(WMPropList
*dict
, WMenu
*menu
, WMPropList
*key
)
2498 WMPropList
*value
, *list
;
2501 snprintf(buffer
, sizeof(buffer
), "%i,%i", menu
->frame_x
, menu
->frame_y
);
2502 value
= WMCreatePLString(buffer
);
2503 list
= WMCreatePLArray(value
, NULL
);
2504 if (menu
->flags
.lowered
)
2505 WMAddToPLArray(list
, WMCreatePLString("lowered"));
2506 WMPutInPLDictionary(dict
, key
, list
);
2507 WMReleasePropList(value
);
2508 WMReleasePropList(list
);
2513 wMenuSaveState(WScreen
*scr
)
2515 WMPropList
*menus
, *key
;
2518 menus
= WMCreatePLDictionary(NULL
, NULL
);
2521 if (scr
->switch_menu
&& scr
->switch_menu
->flags
.buttoned
) {
2522 key
= WMCreatePLString("SwitchMenu");
2523 saveMenuInfo(menus
, scr
->switch_menu
, key
);
2524 WMReleasePropList(key
);
2528 if (saveMenuRecurs(menus
, scr
, scr
->root_menu
))
2532 if (scr
->workspace_menu
&& scr
->workspace_menu
->flags
.buttoned
) {
2533 key
= WMCreatePLString("WorkspaceMenu");
2534 saveMenuInfo(menus
, scr
->workspace_menu
, key
);
2535 WMReleasePropList(key
);
2540 key
= WMCreatePLString("Menus");
2541 WMPutInPLDictionary(scr
->session_state
, key
, menus
);
2542 WMReleasePropList(key
);
2544 WMReleasePropList(menus
);
2551 getMenuPath(WMenu
*menu
, char *buffer
, int bufSize
)
2556 if (!menu
->flags
.titled
|| !menu
->frame
->title
[0])
2559 len
= strlen(menu
->frame
->title
);
2564 ok
= getMenuPath(menu
->parent
, buffer
, bufSize
- len
- 1);
2569 strcat(buffer
, "\\");
2570 strcat(buffer
, menu
->frame
->title
);
2577 saveMenuRecurs(WMPropList
*menus
, WScreen
*scr
, WMenu
*menu
)
2580 int save_menus
= 0, i
;
2585 if (menu
->flags
.brother
)
2586 menu
= menu
->brother
;
2588 if (menu
->flags
.buttoned
&& menu
!= scr
->switch_menu
) {
2591 ok
= getMenuPath(menu
, buffer
, 510);
2594 key
= WMCreatePLString(buffer
);
2595 saveMenuInfo(menus
, menu
, key
);
2596 WMReleasePropList(key
);
2602 for (i
= 0; i
< menu
->cascade_no
; i
++) {
2603 if (saveMenuRecurs(menus
, scr
, menu
->cascades
[i
]))
2612 #define COMPLAIN(key) wwarning(_("bad value in menus state info:%s"), key)
2616 getMenuInfo(WMPropList
*info
, int *x
, int *y
, Bool
*lowered
)
2622 if (WMIsPLArray(info
)) {
2624 pos
= WMGetFromPLArray(info
, 0);
2625 flags
= WMGetFromPLArray(info
, 1);
2626 if (flags
!= NULL
&& WMIsPLString(flags
) && WMGetFromPLString(flags
) != NULL
2627 && strcmp(WMGetFromPLString(flags
), "lowered") == 0) {
2634 if (pos
!= NULL
&& WMIsPLString(pos
)) {
2635 if (sscanf(WMGetFromPLString(pos
), "%i,%i", x
, y
)!=2)
2636 COMPLAIN("Position");
2638 COMPLAIN("(position, flags...)");
2647 restoreMenu(WScreen
*scr
, WMPropList
*menu
, int which
)
2650 Bool lowered
= False
;
2651 WMenu
*pmenu
= NULL
;
2656 if (!getMenuInfo(menu
, &x
, &y
, &lowered
))
2661 if (which
& WSS_SWITCHMENU
) {
2662 OpenSwitchMenu(scr
, x
, y
, False
);
2663 pmenu
= scr
->switch_menu
;
2668 int width
= MENUW(pmenu
);
2669 int height
= MENUH(pmenu
);
2670 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2673 changeMenuLevels(pmenu
, True
);
2676 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2677 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2678 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2679 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2681 wMenuMove(pmenu
, x
, y
, True
);
2682 pmenu
->flags
.buttoned
= 1;
2683 wFrameWindowShowButton(pmenu
->frame
, WFF_RIGHT_BUTTON
);
2692 restoreMenuRecurs(WScreen
*scr
, WMPropList
*menus
, WMenu
*menu
, char *path
)
2694 WMPropList
*key
, *entry
;
2699 if (strlen(path
) + strlen(menu
->frame
->title
) > 510)
2702 snprintf(buffer
, sizeof(buffer
), "%s\\%s", path
, menu
->frame
->title
);
2703 key
= WMCreatePLString(buffer
);
2704 entry
= WMGetFromPLDictionary(menus
, key
);
2707 if (entry
&& getMenuInfo(entry
, &x
, &y
, &lowered
)) {
2709 if (!menu
->flags
.mapped
) {
2710 int width
= MENUW(menu
);
2711 int height
= MENUH(menu
);
2712 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
2714 wMenuMapAt(menu
, x
, y
, False
);
2717 /* make parent map the copy in place of the original */
2718 for (i
=0; i
<menu
->parent
->cascade_no
; i
++) {
2719 if (menu
->parent
->cascades
[i
] == menu
) {
2720 menu
->parent
->cascades
[i
] = menu
->brother
;
2726 changeMenuLevels(menu
, True
);
2729 if (x
< rect
.pos
.x
- width
) x
= rect
.pos
.x
;
2730 if (x
> rect
.pos
.x
+ rect
.size
.width
) x
= rect
.pos
.x
+ rect
.size
.width
- width
;
2731 if (y
< rect
.pos
.y
) y
= rect
.pos
.y
;
2732 if (y
> rect
.pos
.y
+ rect
.size
.height
) y
= rect
.pos
.y
+ rect
.size
.height
- height
;
2734 wMenuMove(menu
, x
, y
, True
);
2735 menu
->flags
.buttoned
= 1;
2736 wFrameWindowShowButton(menu
->frame
, WFF_RIGHT_BUTTON
);
2741 WMReleasePropList(key
);
2743 for (i
=0; i
<menu
->cascade_no
; i
++) {
2744 if (restoreMenuRecurs(scr
, menus
, menu
->cascades
[i
], buffer
) != False
)
2754 wMenuRestoreState(WScreen
*scr
)
2756 WMPropList
*menus
, *menu
, *key
, *skey
;
2758 if (!scr
->session_state
) {
2762 key
= WMCreatePLString("Menus");
2763 menus
= WMGetFromPLDictionary(scr
->session_state
, key
);
2764 WMReleasePropList(key
);
2771 skey
= WMCreatePLString("SwitchMenu");
2772 menu
= WMGetFromPLDictionary(menus
, skey
);
2773 WMReleasePropList(skey
);
2774 restoreMenu(scr
, menu
, WSS_SWITCHMENU
);
2777 if (!scr
->root_menu
) {
2778 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2779 wMenuUnmap(scr
->root_menu
);
2781 restoreMenuRecurs(scr
, menus
, scr
->root_menu
, "");
2787 OpenWorkspaceMenu(WScreen
*scr
, int x
, int y
)
2789 WMenu
*menu
, *parent
;
2793 if (!scr
->root_menu
) {
2794 OpenRootMenu(scr
, scr
->scr_width
*2, 0, False
);
2795 wMenuUnmap(scr
->root_menu
);
2798 menu
= scr
->workspace_menu
;
2800 if (menu
->flags
.mapped
) {
2801 if (!menu
->flags
.buttoned
) {
2803 parent
= menu
->parent
;
2804 if (parent
&& parent
->selected_entry
>= 0) {
2805 entry
= parent
->entries
[parent
->selected_entry
];
2806 if (parent
->cascades
[entry
->cascade
] == menu
) {
2807 selectEntry(parent
, -1);
2808 wMenuMapAt(menu
, x
, y
, False
);
2812 wRaiseFrame(menu
->frame
->core
);
2813 wMenuMapCopyAt(menu
, x
, y
);
2816 wMenuMapAt(menu
, x
, y
, False
);