summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Braun2010-10-05 19:04:36 +0200
committerSebastien Braun2010-10-05 19:58:04 +0200
commit43038c98f8cc48cfded692ea44e02e93597da305 (patch)
treea6b4562d2e6a664923c10243e3ce0494a0055439
parentUpdate translation files (1) (diff)
downloadpvs-43038c98f8cc48cfded692ea44e02e93597da305.tar.gz
pvs-43038c98f8cc48cfded692ea44e02e93597da305.tar.xz
pvs-43038c98f8cc48cfded692ea44e02e93597da305.zip
Add hard requirement for XInput library.
XInput2 will be preferred if its presence is detected.
-rw-r--r--CMakeLists.txt7
-rw-r--r--src/input/CMakeLists.txt8
-rw-r--r--src/input/x11FakeKeyboardHandler.cpp49
3 files changed, 59 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ec688b5..dab8b1d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,10 +31,14 @@ INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR}
${X11_INCLUDE_DIR}
${X11_XTest_INCLUDE_PATH}
+ ${X11_Xinput_INCLUDE_PATH}
)
IF(NOT X11_XTest_FOUND)
- MESSAGE(FATAL_ERROR "Could not find X11 extension XTest. It is needed for PVS")
+ MESSAGE(FATAL_ERROR "Could not find X11 extension XTest or its developer files.")
+ENDIF()
+IF(NOT X11_Xinput_FOUND)
+ MESSAGE(FATAL_ERROR "Could not find X11 extension Xinput or its developer files.")
ENDIF()
ADD_SUBDIRECTORY(src/input)
@@ -322,6 +326,7 @@ TARGET_LINK_LIBRARIES( pvs
${VNC_LIBRARIES}
${X11_LIBRARIES}
${X11_XTest_LIB}
+ ${X11_Xinput_LIB}
pvsinput
)
diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt
index 29374e2..1a3b154 100644
--- a/src/input/CMakeLists.txt
+++ b/src/input/CMakeLists.txt
@@ -6,6 +6,14 @@ set(pvsinput_SRCS
)
if(UNIX)
+ find_file(XINPUT2_HDR X11/extensions/XInput2.h)
+ if(XINPUT2_HDR)
+ set_property(SOURCE x11FakeKeyboardHandler.cpp
+ APPEND
+ PROPERTY COMPILE_DEFINITIONS HAVE_XINPUT2_H
+ )
+ endif()
+
set(pvsprivinputd_SRCS
pvsprivinputd.cpp
pvsPrivInputHandler.cpp
diff --git a/src/input/x11FakeKeyboardHandler.cpp b/src/input/x11FakeKeyboardHandler.cpp
index 3a0b864..e7a5826 100644
--- a/src/input/x11FakeKeyboardHandler.cpp
+++ b/src/input/x11FakeKeyboardHandler.cpp
@@ -27,7 +27,11 @@
#include <X11/keysym.h>
#include <X11/keysymdef.h>
#include <X11/extensions/XTest.h>
-#include <X11/extensions/XInput2.h>
+#ifdef HAVE_XINPUT2_H
+# include <X11/extensions/XInput2.h>
+#else
+# include <X11/extensions/XInput.h>
+#endif
#include <X11/XKBlib.h>
#include <src/util/consoleLogger.h>
#include "x11InputUtils.h"
@@ -457,6 +461,37 @@ modifier_to_keycode_map modifier_to_keycode;
typedef std::map<int, xmodifier_type> keycode_to_modifier_map;
keycode_to_modifier_map keycode_to_modifier;
+// We need to query the input devices, preferrable through XInput2, but
+// if that is not available we will contend ourselves with XInput1:
+#ifndef HAVE_XINPUT2_H
+# define XIAllDevices 1 /* does not matter */
+# define XIDeviceInfo XDeviceInfo
+# define XIQueryDevice(dpy, which, ninfos) XListInputDevices(dpy, ninfos)
+# define XIFreeDeviceInfo(infos) XFreeDeviceList(infos)
+# define XIMasterKeyboard IsXKeyboard
+# define XISlaveKeyboard IsXExtensionKeyboard
+ static inline Atom* getDeviceProperties(Display* dpy, XIDeviceInfo* devinfo, int* nprops)
+ {
+ if(devinfo->use == IsXKeyboard)
+ {
+ // According to XOpenDevice(3X11) you cannot open the Core Keyboard.
+ *nprops = 0;
+ return 0;
+ }
+
+ XDevice* dev = XOpenDevice(dpy, devinfo->id);
+ Atom* props = XListDeviceProperties(dpy, dev, nprops);
+ XCloseDevice(dpy, dev);
+ return props;
+ }
+#else
+ static inline Atom* getDeviceProperties(Display* dpy, XIDeviceInfo* devinfo, int* nprops)
+ {
+ return XIListProperties(dpy, devinfo->deviceid, nprops);
+ }
+#endif
+
+
void initialize_basic_keycodes()
{
for(int i = 0; i < 8; i++) {
@@ -504,23 +539,26 @@ void initialize_basic_keycodes()
else
{
// Try to find out what device XTest will send events on:
- int xkbDeviceId = XkbUseCoreKbd;
+ unsigned int xkbDeviceId = XkbUseCoreKbd;
Atom xtestDeviceProp = XInternAtom(dpy, "XTEST Device", false);
int ndevinfos;
XIDeviceInfo* devinfos = XIQueryDevice(dpy, XIAllDevices, &ndevinfos);
if(devinfos)
{
+#ifndef HAVE_INPUT2_H
+# define deviceid id
+#endif
for(int i = 0; i < ndevinfos && xkbDeviceId == XkbUseCoreKbd; i++)
{
XIDeviceInfo* devinfo = devinfos + i;
- qDebug("Found device of type %d with name %s", devinfo->use, devinfo->name);
+ qDebug("Found device %lu of type %d with name %s", (unsigned long)devinfo->deviceid, devinfo->use, devinfo->name);
// We want it to be a keyboard.
if(devinfo->use != XIMasterKeyboard && devinfo->use != XISlaveKeyboard)
continue;
int nprops;
- Atom* props = XIListProperties(dpy, devinfo->deviceid, &nprops);
+ Atom* props = getDeviceProperties(dpy, devinfo, &nprops);
if(props)
{
for(int j = 0; j < nprops && xkbDeviceId == XkbUseCoreKbd; j++)
@@ -536,6 +574,9 @@ void initialize_basic_keycodes()
}
}
XIFreeDeviceInfo(devinfos);
+#ifdef deviceid /* XInput1 */
+# undef deviceid
+#endif
}
// Okay, we know which device to query. Now get its keymap: