~ubuntu-branches/ubuntu/karmic/recordmydesktop/karmic

« back to all changes in this revision

Viewing changes to src/rmd_shortcuts.c

  • Committer: Bazaar Package Importer
  • Author(s): Alan Pope
  • Date: 2009-04-21 10:57:22 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090421105722-w6l4gz958gva15wn
Tags: 0.3.8.1-0ubuntu1
* New upstream release (LP: #364674)
* debian/control: Fixed libjack0.100.0-dev dependancy
* debian/control: Fixed project home page

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
*                            recordMyDesktop                                  *
 
3
*******************************************************************************
 
4
*                                                                             *
 
5
*            Copyright (C) 2006,2007,2008 John Varouhakis                     *
 
6
*                                                                             *
 
7
*                                                                             *
 
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.                                       *
 
12
*                                                                             *
 
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.                              *
 
17
*                                                                             *
 
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  *
 
21
*                                                                             *
 
22
*                                                                             *
 
23
*                                                                             *
 
24
*   For further information contact me at johnvarouhakis@gmail.com            *
 
25
******************************************************************************/
 
26
 
 
27
#include "config.h"
 
28
#include "rmd_shortcuts.h"
 
29
 
 
30
#include "rmd_types.h"
 
31
 
 
32
#include <X11/Xlib.h>
 
33
#include <X11/Xlibint.h>
 
34
#include <X11/keysym.h> 
 
35
 
 
36
#include <stdio.h>
 
37
#include <stdlib.h>
 
38
#include <string.h>
 
39
 
 
40
int RegisterShortcut(Display *dpy,
 
41
                     Window root,
 
42
                     const char *shortcut,
 
43
                     HotKey *hotkey){
 
44
 
 
45
    int keycode=0, 
 
46
        i, j ;
 
47
    KeySym key=0;
 
48
    unsigned int modifier_mask=0,
 
49
                 numlock_mask=0;
 
50
    char *keystr=NULL;
 
51
    XModifierKeymap *modmap;
 
52
 
 
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;
 
67
    
 
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 
 
71
    //modifier.
 
72
    if(modifier_mask == 0)
 
73
        return 1;
 
74
    if((keystr=rindex(shortcut,'+'))!=NULL){
 
75
        keystr++;
 
76
        if((key=XStringToKeysym(keystr))==NoSymbol)
 
77
            return 1;
 
78
        else
 
79
            keycode=XKeysymToKeycode(dpy,key);
 
80
    }
 
81
    else
 
82
        return 1;
 
83
 
 
84
 
 
85
    /* Key grabbing stuff taken from tilda who took it from yeahconsole 
 
86
     * who took it from evilwm */
 
87
 
 
88
    modmap = XGetModifierMapping(dpy);
 
89
    for(i=0;i<8;i++){
 
90
        for(j=0;j<modmap->max_keypermod;j++){
 
91
            if(modmap->modifiermap[i*modmap->max_keypermod+j]==
 
92
               XKeysymToKeycode(dpy,XK_Num_Lock))
 
93
                numlock_mask=(1<<i);
 
94
        }
 
95
    }
 
96
    XFreeModifiermap(modmap);
 
97
 
 
98
    hotkey->modnum=0;
 
99
    hotkey->key=keycode;
 
100
 
 
101
    XGrabKey(dpy,
 
102
             keycode,
 
103
             modifier_mask,
 
104
             root,
 
105
             True,
 
106
             GrabModeAsync,
 
107
             GrabModeAsync);
 
108
    hotkey->mask[0]=modifier_mask;
 
109
    hotkey->modnum++;
 
110
 
 
111
    XGrabKey(dpy,
 
112
             keycode,
 
113
             LockMask | modifier_mask,
 
114
             root,
 
115
             True,
 
116
             GrabModeAsync,
 
117
             GrabModeAsync);
 
118
    hotkey->mask[1]=LockMask | modifier_mask;
 
119
    hotkey->modnum++;
 
120
 
 
121
    if(numlock_mask){
 
122
 
 
123
        XGrabKey(dpy,
 
124
                 keycode,
 
125
                 numlock_mask | modifier_mask,
 
126
                 root,
 
127
                 True,
 
128
                 GrabModeAsync,
 
129
                 GrabModeAsync);
 
130
        hotkey->mask[2]=numlock_mask | modifier_mask;
 
131
        hotkey->modnum++;
 
132
 
 
133
        XGrabKey(dpy,
 
134
                 keycode,
 
135
                 numlock_mask | LockMask | modifier_mask,
 
136
                 root,
 
137
                 True,
 
138
                 GrabModeAsync,
 
139
                 GrabModeAsync);
 
140
        hotkey->mask[3]=numlock_mask | LockMask | modifier_mask;
 
141
        hotkey->modnum++;
 
142
 
 
143
    }
 
144
 
 
145
    return 0;
 
146
 
 
147
}
 
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153