]> git.decadent.org.uk Git - ion3.git/blob - mod_menu/grabmenu.c
[svn-upgrade] Integrating new upstream version, ion3 (20070203)
[ion3.git] / mod_menu / grabmenu.c
1 /*
2  * ion/mod_menu/grabmenu.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
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.
10  */
11
12 #include <libextl/extl.h>
13
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>
20 #include "menu.h"
21 #include "mkmenu.h"
22
23
24 static bool grabmenu_handler(WRegion *reg, XEvent *xev)
25 {
26     XKeyEvent *ev=&xev->xkey;
27     WMenu *menu=(WMenu*)reg;
28     
29     if(ev->type==KeyRelease){
30         if(ioncore_unmod(ev->state, ev->keycode)==0){
31             menu_finish(menu);
32             return TRUE;
33         }
34         return FALSE;
35     }
36     
37     if(reg==NULL)
38         return FALSE;
39     
40     if((menu->gm_state==ev->state || menu->gm_state==AnyModifier) 
41        && ev->keycode==menu->gm_kcb){
42         menu_select_next(menu);
43     }
44     
45     return FALSE;
46 }
47
48
49 /*--lowlevel routine not to be called by the user--*/
50 EXTL_EXPORT
51 WMenu *mod_menu_do_grabmenu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
52                             ExtlTab param)
53 {
54     WMenuCreateParams fnp;
55     WMPlexAttachParams par;
56     WMenu *menu;
57     XKeyEvent *ev;
58     uint state, kcb;
59     bool sub;
60     
61     if(!ioncore_current_key(&kcb, &state, &sub))
62         return NULL;
63     
64     if(state==0){
65         /* TODO: cycle key? */
66         return mod_menu_do_menu(mplex, handler, tab, param);
67     }
68     
69     fnp.handler=handler;
70     fnp.tab=tab;
71     fnp.pmenu_mode=FALSE;
72     fnp.submenu_mode=FALSE;
73     fnp.big_mode=extl_table_is_bool_set(param, "big");
74     fnp.initial=0;
75     extl_table_gets_i(param, "initial", &(fnp.initial));
76
77     par.flags=(MPLEX_ATTACH_SWITCHTO|
78                MPLEX_ATTACH_UNNUMBERED|
79                MPLEX_ATTACH_SIZEPOLICY);
80     par.szplcy=SIZEPOLICY_FULL_BOUNDS;
81
82     menu=(WMenu*)mplex_do_attach_new(mplex, &par,
83                                      (WRegionCreateFn*)create_menu,
84                                      (void*)&fnp); 
85     
86     if(menu==NULL)
87         return NULL;
88  
89     menu->gm_kcb=kcb;
90     menu->gm_state=state;
91     
92     ioncore_grab_establish((WRegion*)menu, grabmenu_handler, NULL, 0);
93     
94     return menu;
95 }
96