4 * Copyright (c) Lukas Schroeder 2002
5 * See the included file LICENSE for details.
20 bool shortcut_is_valid(int cut
)
22 return ((cut
>='0' && cut
<='9') || (cut
>='A' && cut
<='z'));
25 void shortcut_remove(int cut
)
29 if(!shortcut_is_valid(cut
))
32 thing
=wglobal
.shortcuts
[cut
];
36 if(WTHING_IS(thing
, WFrame
)){
37 WFrame
*frame
=(WFrame
*)thing
;
41 wglobal
.shortcuts
[cut
]=NULL
;
44 static void shortcut_remove_from_frame(WFrame
*frame
)
46 shortcut_remove(frame
->shortcut
);
47 assert(frame
->shortcut
==0);
48 frame_recalc_bar(frame
);
51 void shortcut_set(WThing
*thing
, int cut
)
53 bool valid
=shortcut_is_valid(cut
);
56 WThing
*oldthing
=wglobal
.shortcuts
[cut
];
57 if(oldthing
&& WTHING_IS(thing
, WFrame
))
58 shortcut_remove_from_frame((WFrame
*)oldthing
);
61 if(WTHING_IS(thing
, WFrame
))
62 shortcut_remove_from_frame((WFrame
*)thing
);
69 wglobal
.shortcuts
[cut
]=thing
;
70 if(WTHING_IS(thing
, WFrame
)){
71 WFrame
*frame
=(WFrame
*)thing
;
73 frame_recalc_bar(frame
);
77 static char *decode_keysym(XKeyEvent
*ev
)
79 static char buffer
[10];
82 len
= XLookupString(ev
, buffer
, 10, NULL
, NULL
);
83 if(!len
|| !shortcut_is_valid((int)buffer
[0]))
89 static bool setshortcut_handler(WThing
*thing
, XEvent
*ev
)
94 if(ismod(ev
->xkey
.keycode
))
97 sc
=decode_keysym(&ev
->xkey
);
98 shortcut_set(thing
, (int)sc
[0]);
102 static bool gotoshortcut_handler(WThing
*thing
, XEvent
*ev
)
107 if(ismod(ev
->xkey
.keycode
))
110 sc
=decode_keysym(&ev
->xkey
);
111 if(sc
[0] && shortcut_is_valid((int)sc
[0])){
113 target
=wglobal
.shortcuts
[(int)sc
[0]];
117 if(WTHING_IS(target
, WFrame
)){
118 goto_window((WWindow
*)target
);
119 }else if(WTHING_IS(target
, WClient
))
120 goto_client((WClient
*)target
);
121 /* else: "Ooops. target is not a WFrame" */
123 /*skip_focusenter();*/
127 void set_shortcut(WFrame
*frame
)
129 grab_establish((WThing
*)frame
, setshortcut_handler
, FocusChangeMask
|KeyReleaseMask
);
132 void goto_shortcut(WFrame
*frame
)
134 grab_establish((WThing
*)frame
, gotoshortcut_handler
, FocusChangeMask
|KeyReleaseMask
);