fixed xerrorhandler

fixes #4
This commit is contained in:
Skycoder42
2017-06-25 14:40:03 +02:00
parent f288e85ef1
commit 1833a053f6
+11 -6
View File
@@ -106,7 +106,7 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
GrabModeAsync, GrabModeAsync,
GrabModeAsync); GrabModeAsync);
} }
XFlush(display); XSync(display, False);
if(errorHandler.hasError) { if(errorHandler.hasError) {
qCWarning(logQHotkey) << "Failed to register hotkey. Error:" qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
@@ -130,7 +130,7 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
shortcut.modifier | specialMod, shortcut.modifier | specialMod,
DefaultRootWindow(display)); DefaultRootWindow(display));
} }
XFlush(display); XSync(display, False);
if(errorHandler.hasError) { if(errorHandler.hasError) {
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:" qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
@@ -156,27 +156,32 @@ QString QHotkeyPrivateX11::HotkeyErrorHandler::errorString;
QHotkeyPrivateX11::HotkeyErrorHandler::HotkeyErrorHandler() QHotkeyPrivateX11::HotkeyErrorHandler::HotkeyErrorHandler()
{ {
this->prevHandler = XSetErrorHandler(&HotkeyErrorHandler::handleError); prevHandler = XSetErrorHandler(&HotkeyErrorHandler::handleError);
} }
QHotkeyPrivateX11::HotkeyErrorHandler::~HotkeyErrorHandler() QHotkeyPrivateX11::HotkeyErrorHandler::~HotkeyErrorHandler()
{ {
XSetErrorHandler(this->prevHandler); XSetErrorHandler(prevHandler);
hasError = false;
errorString.clear();
} }
int QHotkeyPrivateX11::HotkeyErrorHandler::handleError(Display *display, XErrorEvent *error) int QHotkeyPrivateX11::HotkeyErrorHandler::handleError(Display *display, XErrorEvent *error)
{ {
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wimplicit-fallthrough")
switch (error->error_code) { switch (error->error_code) {
case BadAccess: case BadAccess:
case BadValue: case BadValue:
case BadWindow: case BadWindow:
if (error->request_code == 33 || //grab key if (error->request_code == 33 || //grab key
error->request_code == 34) {// ungrab key error->request_code == 34) {// ungrab key
HotkeyErrorHandler::hasError = true; hasError = true;
HotkeyErrorHandler::errorString = QHotkeyPrivateX11::formatX11Error(display, error->error_code); errorString = QHotkeyPrivateX11::formatX11Error(display, error->error_code);
return 1; return 1;
} }
default: default:
return 0; return 0;
} }
QT_WARNING_POP
} }