]> git.decadent.org.uk Git - ion3.git/blob - mod_menu/grabmenu.c
[svn-inject] Installing original source of ion3
[ion3.git] / mod_menu / grabmenu.c
1 /*
2  * ion/mod_menu/grabmenu.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2006. 
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 && ev->keycode==menu->gm_kcb)
41         menu_select_next(menu);
42     
43     return FALSE;
44 }
45
46
47 /*--lowlevel routine not to be called by the user--*/
48 EXTL_EXPORT
49 WMenu *mod_menu_do_grabmenu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
50                             ExtlTab param)
51 {
52     WMenuCreateParams fnp;
53     WMPlexAttachParams par;
54     WMenu *menu;
55     XKeyEvent *ev;
56     
57     ev=ioncore_current_key_event();
58     
59     if(ev==NULL)
60         return NULL;
61     
62     fnp.handler=handler;
63     fnp.tab=tab;
64     fnp.pmenu_mode=FALSE;
65     fnp.submenu_mode=FALSE;
66     fnp.big_mode=extl_table_is_bool_set(param, "big");
67     fnp.initial=0;
68     extl_table_gets_i(param, "initial", &(fnp.initial));
69
70     par.flags=(MPLEX_ATTACH_SWITCHTO|
71                MPLEX_ATTACH_UNNUMBERED|
72                MPLEX_ATTACH_SIZEPOLICY);
73     par.szplcy=SIZEPOLICY_FULL_BOUNDS;
74
75     menu=(WMenu*)mplex_do_attach_new(mplex, &par,
76                                      (WRegionCreateFn*)create_menu,
77                                      (void*)&fnp); 
78     
79     if(menu==NULL)
80         return FALSE;
81  
82     menu->gm_kcb=ev->keycode;
83     menu->gm_state=ev->state;
84     
85     ioncore_grab_establish((WRegion*)menu, grabmenu_handler, NULL, 0);
86     
87     return menu;
88 }
89