1
/******************************************************************************
3
*******************************************************************************
5
* Copyright (C) 2006,2007,2008 John Varouhakis *
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
* This program is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License *
19
* along with this program; if not, write to the Free Software *
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
24
* For further information contact me at johnvarouhakis@gmail.com *
25
******************************************************************************/
28
#include "rmd_shortcuts.h"
30
#include "rmd_types.h"
33
#include <X11/Xlibint.h>
34
#include <X11/keysym.h>
40
int RegisterShortcut(Display *dpy,
48
unsigned int modifier_mask=0,
51
XModifierKeymap *modmap;
53
if(strstr(shortcut,"Shift"))
54
modifier_mask = modifier_mask|ShiftMask;
55
if(strstr(shortcut,"Control"))
56
modifier_mask = modifier_mask|ControlMask;
57
if(strstr(shortcut,"Mod1"))
58
modifier_mask = modifier_mask|Mod1Mask;
59
if(strstr(shortcut,"Mod2"))
60
modifier_mask = modifier_mask|Mod2Mask;
61
if(strstr(shortcut,"Mod3"))
62
modifier_mask = modifier_mask|Mod3Mask;
63
if(strstr(shortcut,"Mod4"))
64
modifier_mask = modifier_mask|Mod4Mask;
65
if(strstr(shortcut,"Mod5"))
66
modifier_mask = modifier_mask|Mod5Mask;
68
//we register the shortcut on the root
69
//window, which means on every keypress event,
70
//so I think it's neccessary to have at least one
72
if(modifier_mask == 0)
74
if((keystr=rindex(shortcut,'+'))!=NULL){
76
if((key=XStringToKeysym(keystr))==NoSymbol)
79
keycode=XKeysymToKeycode(dpy,key);
85
/* Key grabbing stuff taken from tilda who took it from yeahconsole
86
* who took it from evilwm */
88
modmap = XGetModifierMapping(dpy);
90
for(j=0;j<modmap->max_keypermod;j++){
91
if(modmap->modifiermap[i*modmap->max_keypermod+j]==
92
XKeysymToKeycode(dpy,XK_Num_Lock))
96
XFreeModifiermap(modmap);
108
hotkey->mask[0]=modifier_mask;
113
LockMask | modifier_mask,
118
hotkey->mask[1]=LockMask | modifier_mask;
125
numlock_mask | modifier_mask,
130
hotkey->mask[2]=numlock_mask | modifier_mask;
135
numlock_mask | LockMask | modifier_mask,
140
hotkey->mask[3]=numlock_mask | LockMask | modifier_mask;