patch: for "old" unix, fixed compile problems (missing xi2 stuff), and refactored header tests (thanks to Jim Hague)

This commit is contained in:
Nick Bolton 2012-07-20 15:14:19 +00:00
parent fb377bbc78
commit 6dcefaf353
4 changed files with 112 additions and 98 deletions

View File

@ -173,34 +173,35 @@ if (UNIX)
else()
# add include dir for bsd (posix uses /usr/include/)
set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}:/usr/local/include")
set(XKBlib "X11/XKBlib.h")
check_include_files("${XKBlib};X11/extensions/Xrandr.h" HAVE_X11_EXTENSIONS_XRANDR_H)
check_include_files("${XKBlib};X11/extensions/dpms.h" HAVE_X11_EXTENSIONS_DPMS_H)
check_include_files("X11/extensions/Xinerama.h" HAVE_X11_EXTENSIONS_XINERAMA_H)
check_include_files("${XKBlib};X11/extensions/XKBstr.h" HAVE_X11_EXTENSIONS_XKBSTR_H)
check_include_files("X11/extensions/XKB.h" HAVE_XKB_EXTENSION)
check_include_files("X11/extensions/XTest.h" HAVE_X11_EXTENSIONS_XTEST_H)
check_include_files(${XKBlib} HAVE_X11_XKBLIB_H)
check_include_files("X11/extensions/XInput2.h" HAVE_XI2)
if (HAVE_X11_EXTENSIONS_DPMS_H)
# add include dir for bsd (posix uses /usr/include/)
set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}:/usr/local/include")
set(XKBlib "X11/Xlib.h;X11/XKBlib.h")
check_symbol_exists("XRRNotifyEvent" "${XKBlib};X11/extensions/Xrandr.h" HAVE_X11_EXTENSIONS_XRANDR_H)
check_include_files("${XKBlib};X11/extensions/dpms.h" HAVE_X11_EXTENSIONS_DPMS_H)
check_include_files("X11/extensions/Xinerama.h" HAVE_X11_EXTENSIONS_XINERAMA_H)
check_include_files("${XKBlib};X11/extensions/XKBstr.h" HAVE_X11_EXTENSIONS_XKBSTR_H)
check_include_files("X11/extensions/XKB.h" HAVE_XKB_EXTENSION)
check_include_files("X11/extensions/XTest.h" HAVE_X11_EXTENSIONS_XTEST_H)
check_include_files("${XKBlib}" HAVE_X11_XKBLIB_H)
check_include_files("X11/extensions/XInput2.h" HAVE_XI2)
if (HAVE_X11_EXTENSIONS_DPMS_H)
# Assume that function prototypes declared, when include exists.
set(HAVE_DPMS_PROTOTYPES 1)
endif()
if (NOT HAVE_X11_XKBLIB_H)
message(FATAL_ERROR "Missing header: " ${XKBlib})
endif()
check_library_exists("SM;ICE" IceConnectionNumber "" HAVE_ICE)
check_library_exists("X11;Xext" DPMSQueryExtension "" HAVE_Xext)
check_library_exists("X11;Xext;Xtst" XTestQueryExtension "" HAVE_Xtst)
check_library_exists("Xinerama" XineramaQueryExtension "" HAVE_Xinerama)
check_library_exists("Xi" XISelectEvents "" HAVE_Xi)
check_library_exists("Xrandr" XRRQueryExtension "" HAVE_Xrandr)
endif()
check_library_exists("SM;ICE" IceConnectionNumber "" HAVE_ICE)
check_library_exists("Xext;X11" DPMSQueryExtension "" HAVE_Xext)
check_library_exists("Xtst;Xext;X11" XTestQueryExtension "" HAVE_Xtst)
check_library_exists("Xinerama" XineramaQueryExtension "" HAVE_Xinerama)
check_library_exists("Xi" XISelectEvents "" HAVE_Xi)
check_library_exists("Xrandr" XRRQueryExtension "" HAVE_Xrandr)
if (HAVE_ICE)
@ -211,13 +212,13 @@ if (UNIX)
endif()
if (HAVE_Xtst)
# Xtxt depends on X11.
set(HAVE_X11)
list(APPEND libs X11 Xtst)
else()
# Xtxt depends on X11.
set(HAVE_X11)
list(APPEND libs Xtst X11)
else()
message(FATAL_ERROR "Missing library: Xtst")
endif()
@ -227,13 +228,14 @@ if (UNIX)
endif()
if (HAVE_Xinerama)
list(APPEND libs Xinerama)
else (HAVE_Xinerama)
if (HAVE_X11_EXTENSIONS_XINERAMA_H)
message(FATAL_ERROR "Missing library: Xinerama")
endif()
endif()
list(APPEND libs Xinerama)
else (HAVE_Xinerama)
if (HAVE_X11_EXTENSIONS_XINERAMA_H)
set(HAVE_X11_EXTENSIONS_XINERAMA_H 0)
message(WARNING "Old Xinerama implementation detected, disabled")
endif()
endif()
if (HAVE_Xrandr)
list(APPEND libs Xrandr)
endif()

View File

@ -153,13 +153,15 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool d
if (m_isPrimary) {
// start watching for events on other windows
selectEvents(m_root);
m_xi2detected = detectXI2();
if (m_xi2detected) {
selectXIRawMotion();
} else
{
// start watching for events on other windows
m_xi2detected = detectXI2();
if (m_xi2detected) {
#ifdef HAVE_XI2
selectXIRawMotion();
#endif
} else
{
// start watching for events on other windows
selectEvents(m_root);
}
@ -1226,13 +1228,13 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
else if (xevent->type == KeyRelease &&
xevent->xkey.keycode == m_lastKeycode) {
m_lastKeycode = 0;
}
// now filter the event
if (XFilterEvent(xevent, None)) {
if (xevent->type == KeyPress) {
// add filtered presses to the filtered list
m_filtered.insert(m_lastKeycode);
}
// now filter the event
if (XFilterEvent(xevent, DefaultRootWindow(m_display))) {
if (xevent->type == KeyPress) {
// add filtered presses to the filtered list
m_filtered.insert(m_lastKeycode);
}
return;
}
@ -1249,12 +1251,13 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
// let screen saver have a go
if (m_screensaver->handleXEvent(xevent)) {
// screen saver handled it
return;
}
if (m_xi2detected) {
// Process RawMotion
XGenericEventCookie *cookie = (XGenericEventCookie*)&xevent->xcookie;
return;
}
#ifdef HAVE_XI2
if (m_xi2detected) {
// Process RawMotion
XGenericEventCookie *cookie = (XGenericEventCookie*)&xevent->xcookie;
if (XGetEventData(m_display, cookie) &&
cookie->type == GenericEvent &&
cookie->extension == xi_opcode) {
@ -1279,12 +1282,13 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
XFreeEventData(m_display, cookie);
return;
}
XFreeEventData(m_display, cookie);
}
}
// handle the event ourself
switch (xevent->type) {
XFreeEventData(m_display, cookie);
}
}
#endif
// handle the event ourself
switch (xevent->type) {
case CreateNotify:
if (m_isPrimary) {
// select events on new window
@ -2061,16 +2065,17 @@ CXWindowsScreen::CHotKeyItem::operator<(const CHotKeyItem& x) const
}
bool
CXWindowsScreen::detectXI2()
{
int event, error;
return XQueryExtension(m_display,
"XInputExtension", &xi_opcode, &event, &error);
}
void
CXWindowsScreen::selectXIRawMotion()
{
CXWindowsScreen::detectXI2()
{
int event, error;
return XQueryExtension(m_display,
"XInputExtension", &xi_opcode, &event, &error);
}
#ifdef HAVE_XI2
void
CXWindowsScreen::selectXIRawMotion()
{
XIEventMask mask;
mask.deviceid = XIAllDevices;
@ -2080,6 +2085,7 @@ CXWindowsScreen::selectXIRawMotion()
memset(mask.mask, 0, 2);
XISetMask(mask.mask, XI_RawKeyRelease);
XISetMask(mask.mask, XI_RawMotion);
XISelectEvents(m_display, DefaultRootWindow(m_display), &mask, 1);
free(mask.mask);
}
XISelectEvents(m_display, DefaultRootWindow(m_display), &mask, 1);
free(mask.mask);
}
#endif

View File

@ -137,13 +137,15 @@ private:
bool onHotKey(XKeyEvent&, bool isRepeat);
void onMousePress(const XButtonEvent&);
void onMouseRelease(const XButtonEvent&);
void onMouseMove(const XMotionEvent&);
bool detectXI2();
void selectXIRawMotion();
void selectEvents(Window) const;
void doSelectEvents(Window) const;
void onMouseMove(const XMotionEvent&);
bool detectXI2();
#ifdef HAVE_XI2
void selectXIRawMotion();
#endif
void selectEvents(Window) const;
void doSelectEvents(Window) const;
KeyID mapKeyFromX(XKeyEvent*) const;
ButtonID mapButtonFromX(const XButtonEvent*) const;
unsigned int mapButtonToX(ButtonID id) const;

View File

@ -1476,14 +1476,16 @@ CXWindowsUtil::mapKeySymToKeyID(KeySym k)
case XK_ISO_Left_Tab:
return kKeyLeftTab;
case XK_ISO_Level3_Shift:
return kKeyAltGr;
case XK_ISO_Level5_Shift:
return XK_ISO_Level5_Shift; //FIXME: there is no "usual" key for this...
case XK_ISO_Next_Group:
return kKeyNextGroup;
case XK_ISO_Level3_Shift:
return kKeyAltGr;
#ifdef XK_ISO_Level5_Shift
case XK_ISO_Level5_Shift:
return XK_ISO_Level5_Shift; //FIXME: there is no "usual" key for this...
#endif
case XK_ISO_Next_Group:
return kKeyNextGroup;
case XK_ISO_Prev_Group:
return kKeyPrevGroup;
@ -1579,14 +1581,16 @@ CXWindowsUtil::getModifierBitForKeySym(KeySym keysym)
return kKeyModifierBitSuper;
case XK_Mode_switch:
case XK_ISO_Level3_Shift:
return kKeyModifierBitAltGr;
case XK_ISO_Level5_Shift:
return kKeyModifierBitLevel5Lock;
case XK_Caps_Lock:
return kKeyModifierBitCapsLock;
case XK_ISO_Level3_Shift:
return kKeyModifierBitAltGr;
#ifdef XK_ISO_Level5_Shift
case XK_ISO_Level5_Shift:
return kKeyModifierBitLevel5Lock;
#endif
case XK_Caps_Lock:
return kKeyModifierBitCapsLock;
case XK_Num_Lock:
return kKeyModifierBitNumLock;