Which dependencies to install for Debian (probably incomplete)
[notion/jeffpc.git] / mod_menu / grabmenu.c
blobd490b3970a1f575db586ac3056f19a662fba5930
1 /*
2 * ion/mod_menu/grabmenu.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
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>
18 #include "menu.h"
19 #include "mkmenu.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){
29 menu_finish(menu);
30 return TRUE;
32 return FALSE;
35 if(reg==NULL)
36 return FALSE;
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);
47 return FALSE;
51 static void grabkilled_handler(WRegion *reg)
53 destroy_obj((Obj*)reg);
57 /*--lowlevel routine not to be called by the user--*/
58 EXTL_EXPORT
59 WMenu *mod_menu_do_grabmenu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
60 ExtlTab param)
62 WMenuCreateParams fnp;
63 WMPlexAttachParams par;
64 WMenu *menu;
65 XKeyEvent *ev;
66 uint state, kcb;
67 bool sub;
69 if(!ioncore_current_key(&kcb, &state, &sub))
70 return NULL;
72 if(state==0){
73 WMenu *menu=mod_menu_do_menu(mplex, handler, tab, param);
75 if(menu!=NULL && cycle!=extl_fn_none()){
76 uint kcb, state;
78 menu->cycle_bindmap=region_add_cycle_bindmap((WRegion*)menu,
79 kcb, state, ???,
80 ???);
81 }*/
82 return menu;
85 fnp.handler=handler;
86 fnp.tab=tab;
87 fnp.pmenu_mode=FALSE;
88 fnp.submenu_mode=FALSE;
89 fnp.big_mode=extl_table_is_bool_set(param, "big");
90 fnp.initial=0;
91 extl_table_gets_i(param, "initial", &(fnp.initial));
93 par.flags=(MPLEX_ATTACH_SWITCHTO|
94 MPLEX_ATTACH_LEVEL|
95 MPLEX_ATTACH_UNNUMBERED|
96 MPLEX_ATTACH_SIZEPOLICY);
97 par.szplcy=SIZEPOLICY_FULL_BOUNDS;
98 par.level=STACKING_LEVEL_MODAL1+2;
100 menu=(WMenu*)mplex_do_attach_new(mplex, &par,
101 (WRegionCreateFn*)create_menu,
102 (void*)&fnp);
104 if(menu==NULL)
105 return NULL;
107 menu->gm_kcb=kcb;
108 menu->gm_state=state;
110 ioncore_grab_establish((WRegion*)menu, grabmenu_handler,
111 grabkilled_handler, 0);
113 return menu;