"Fossies" - the Fresh Open Source Software Archive 
Member "bbkeys-0.9.1/src/KeyGrabber.cpp" (6 Dec 2007, 4241 Bytes) of package /linux/privat/old/bbkeys-0.9.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "KeyGrabber.cpp" see the
Fossies "Dox" file reference documentation.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // -- KeyGrabber.cpp --
3 // Copyright (c) 2001 - 2003 Jason 'vanRijn' Kasper <vR at movingparts dot net>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // E_O_H_VR
24
25 #include <iostream>
26
27 #include "version.h"
28 #include "KeyGrabber.h"
29 //--------------------------------------------------------
30 // Constructor/Destructor
31 //--------------------------------------------------------
32 KeyGrabber::KeyGrabber (Display * display, unsigned int numlockMask, unsigned int scrolllockMask)
33 : _display(display), _numlockMask(numlockMask), _scrolllockMask(scrolllockMask)
34 {
35 }
36 KeyGrabber::~KeyGrabber ()
37 {
38 }
39 //--------------------------------------------------------
40 // grab
41 //--------------------------------------------------------
42 bool KeyGrabber::grab (const KeyCode & keyCode,
43 const unsigned int & modifierMask, Window window)
44 {
45 int ret =
46 XGrabKey(_display, keyCode, modifierMask,
47 window, True, GrabModeAsync, GrabModeAsync);
48 XGrabKey(_display, keyCode,
49 modifierMask|LockMask,
50 window, True, GrabModeAsync, GrabModeAsync);
51 XGrabKey(_display, keyCode,
52 modifierMask|_scrolllockMask,
53 window, True, GrabModeAsync, GrabModeAsync);
54 XGrabKey(_display, keyCode,
55 modifierMask|_numlockMask,
56 window, True, GrabModeAsync, GrabModeAsync);
57
58 XGrabKey(_display, keyCode,
59 modifierMask|LockMask|_scrolllockMask,
60 window, True, GrabModeAsync, GrabModeAsync);
61 XGrabKey(_display, keyCode,
62 modifierMask|_scrolllockMask|_numlockMask,
63 window, True, GrabModeAsync, GrabModeAsync);
64 XGrabKey(_display, keyCode,
65 modifierMask|_numlockMask|LockMask,
66 window, True, GrabModeAsync, GrabModeAsync);
67
68 XGrabKey(_display, keyCode,
69 modifierMask|_numlockMask|LockMask|_scrolllockMask,
70 window, True, GrabModeAsync, GrabModeAsync);
71
72 // Um. Isn't there SOME way we can tell if a grab worked???
73 // return (ret == Success);
74 return true;
75 }
76 //--------------------------------------------------------
77 // ungrab
78 //--------------------------------------------------------
79 bool KeyGrabber::ungrab (const KeyCode & keyCode,
80 const unsigned int & modifierMask, Window window)
81 {
82 XUngrabKey(_display, keyCode, modifierMask, window);
83 XUngrabKey(_display, keyCode, modifierMask|LockMask, window);
84 XUngrabKey(_display, keyCode, modifierMask|_scrolllockMask, window);
85 XUngrabKey(_display, keyCode, modifierMask|_numlockMask, window);
86
87 XUngrabKey(_display, keyCode, modifierMask|LockMask|_scrolllockMask, window);
88 XUngrabKey(_display, keyCode, modifierMask|_scrolllockMask|_numlockMask, window);
89 XUngrabKey(_display, keyCode, modifierMask|_numlockMask|LockMask, window);
90 XUngrabKey(_display, keyCode, modifierMask|_numlockMask|LockMask|
91 _scrolllockMask, window);
92
93 return true;
94 }
95 //--------------------------------------------------------
96 // ungrabAll
97 //--------------------------------------------------------
98 bool KeyGrabber::ungrabAll (Window window)
99 {
100
101 XUngrabKey(_display, AnyKey, AnyModifier, window);
102
103 return true;
104 }