2 * ion/mod_menu/grabmenu.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
12 #include <libextl/extl.h>
14 #include <ioncore/common.h>
15 #include <ioncore/pointer.h>
16 #include <ioncore/grab.h>
17 #include <ioncore/binding.h>
18 #include <ioncore/conf-bindings.h>
19 #include <ioncore/key.h>
24 static bool grabmenu_handler(WRegion *reg, XEvent *xev)
26 XKeyEvent *ev=&xev->xkey;
27 WMenu *menu=(WMenu*)reg;
29 if(ev->type==KeyRelease){
30 if(ioncore_unmod(ev->state, ev->keycode)==0){
40 if(ev->keycode==menu->gm_kcb){
41 if(menu->gm_state==ev->state)
42 menu_select_next(menu);
43 else if((menu->gm_state|ShiftMask)==ev->state)
44 menu_select_prev(menu);
45 else if(menu->gm_state==AnyModifier)
46 menu_select_next(menu);
53 static void grabkilled_handler(WRegion *reg)
55 destroy_obj((Obj*)reg);
59 /*--lowlevel routine not to be called by the user--*/
61 WMenu *mod_menu_do_grabmenu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
64 WMenuCreateParams fnp;
65 WMPlexAttachParams par;
71 if(!ioncore_current_key(&kcb, &state, &sub))
75 WMenu *menu=mod_menu_do_menu(mplex, handler, tab, param);
77 if(menu!=NULL && cycle!=extl_fn_none()){
80 menu->cycle_bindmap=region_add_cycle_bindmap((WRegion*)menu,
90 fnp.submenu_mode=FALSE;
91 fnp.big_mode=extl_table_is_bool_set(param, "big");
93 extl_table_gets_i(param, "initial", &(fnp.initial));
95 par.flags=(MPLEX_ATTACH_SWITCHTO|
96 MPLEX_ATTACH_UNNUMBERED|
97 MPLEX_ATTACH_SIZEPOLICY);
98 par.szplcy=SIZEPOLICY_FULL_BOUNDS;
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);