Use correct namespace for focus policies.
[basket4.git] / src / keyboard.cpp
blob4cfa3eeba53a7449820d3f973ea74ca5dd84ebda
1 /***************************************************************************
2 * Copyright (C) 2003 by Sébastien Laoût *
3 * slaout@linux62.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <kapplication.h> // it define Q_WS_X11
23 #include "keyboard.h"
25 /* This file contain modified code from klistbox.cpp
28 // ShiftMask, ControlMask and Mod1Mask are defined in <X11/X.h>
29 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
30 #include <X11/Xlib.h> // schroder
31 #include <QX11Info>
32 #endif
34 void Keyboard::pressedKeys(bool &shiftPressed, bool &controlPressed)
36 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
37 Window root;
38 Window child;
39 int root_x, root_y, win_x, win_y;
40 uint keybstate;
41 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root, &child,
42 &root_x, &root_y, &win_x, &win_y, &keybstate );
44 shiftPressed = keybstate & ShiftMask;
45 controlPressed = keybstate & ControlMask;
46 #endif
49 /** Same code as pressedKeys(...) but for shift key only
51 bool Keyboard::shiftPressed()
53 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
54 Window root;
55 Window child;
56 int root_x, root_y, win_x, win_y;
57 uint keybstate;
58 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root, &child,
59 &root_x, &root_y, &win_x, &win_y, &keybstate );
61 return (keybstate & ShiftMask) != 0;
62 #else
63 return false;
64 #endif
67 /** Same code as pressedKeys(...) but for control key only
69 bool Keyboard::controlPressed()
71 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
72 Window root;
73 Window child;
74 int root_x, root_y, win_x, win_y;
75 uint keybstate;
76 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root, &child,
77 &root_x, &root_y, &win_x, &win_y, &keybstate );
79 return (keybstate & ControlMask) != 0;
80 #else
81 return false;
82 #endif
85 /** Return if Alt key is pressed
87 bool Keyboard::altPressed()
89 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
90 Window root;
91 Window child;
92 int root_x, root_y, win_x, win_y;
93 uint keybstate;
94 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root, &child,
95 &root_x, &root_y, &win_x, &win_y, &keybstate );
97 return (keybstate & Mod1Mask) != 0;
98 #else
99 return false;
100 #endif
103 /*******************
104 * What does KDE 3.1 and later:
105 * FIXME: Use this function in KDE 4
106 * (I wasn't knowing it by creating this class)
109 * Returns the currently pressed keyboard modifiers (e.g. shift, control, etc.)
110 * Usually you simply want to test for those in key events, in which case
111 * QKeyEvent::state() does the job (or QKeyEvent::key() to
112 * notice when a modifier is pressed alone).
113 * But it can be useful to query for the status of the modifiers at another moment
114 * (e.g. some KDE apps do that upon a drop event).
115 * @return the keyboard modifiers
116 * @since 3.1
118 uint KApplication::keyboardModifiers()
120 Window root;
121 Window child;
122 int root_x, root_y, win_x, win_y;
123 uint keybstate;
124 XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &root, &child,
125 &root_x, &root_y, &win_x, &win_y, &keybstate );
126 return keybstate & 0x00ff;
130 *******************/