2 * ion/mod_menu/grabmenu.c
4 * Copyright (c) Tuomo Valkonen 1999-2008.
6 * See the included file LICENSE for details.
9 #include <libextl/extl.h>
11 #include <ioncore/common.h>
12 #include <ioncore/pointer.h>
13 #include <ioncore/grab.h>
14 #include <ioncore/binding.h>
15 #include <ioncore/conf-bindings.h>
16 #include <ioncore/key.h>
17 #include <ioncore/stacking.h>
22 static bool grabmenu_handler(WRegion *reg, XEvent *xev)
24 XKeyEvent *ev=&xev->xkey;
25 WMenu *menu=(WMenu*)reg;
27 if(ev->type==KeyRelease){
28 if(ioncore_unmod(ev->state, ev->keycode)==0){
38 if(ev->keycode==menu->gm_kcb){
39 if(menu->gm_state==ev->state)
40 menu_select_next(menu);
41 else if((menu->gm_state|ShiftMask)==ev->state)
42 menu_select_prev(menu);
43 else if(menu->gm_state==AnyModifier)
44 menu_select_next(menu);
51 static void grabkilled_handler(WRegion *reg)
53 destroy_obj((Obj*)reg);
57 /*--lowlevel routine not to be called by the user--*/
59 WMenu *mod_menu_do_grabmenu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
62 WMenuCreateParams fnp;
63 WMPlexAttachParams par;
69 if(!ioncore_current_key(&kcb, &state, &sub))
73 WMenu *menu=mod_menu_do_menu(mplex, handler, tab, param);
75 if(menu!=NULL && cycle!=extl_fn_none()){
78 menu->cycle_bindmap=region_add_cycle_bindmap((WRegion*)menu,
88 fnp.submenu_mode=FALSE;
89 fnp.big_mode=extl_table_is_bool_set(param, "big");
91 extl_table_gets_i(param, "initial", &(fnp.initial));
93 par.flags=(MPLEX_ATTACH_SWITCHTO|
95 MPLEX_ATTACH_UNNUMBERED|
96 MPLEX_ATTACH_SIZEPOLICY);
97 par.szplcy=SIZEPOLICY_FULL_BOUNDS;
98 par.level=STACKING_LEVEL_MODAL1+1;
100 menu=(WMenu*)mplex_do_attach_new(mplex, &par,
101 (WRegionCreateFn*)create_menu,
108 menu->gm_state=state;
110 ioncore_grab_establish((WRegion*)menu, grabmenu_handler,
111 grabkilled_handler, 0);