|
@@ -1,3 +1,5 @@
|
|
1
|
+#include <chrono>
|
|
2
|
+#include <thread>
|
1
|
3
|
#include "mouse.hpp"
|
2
|
4
|
|
3
|
5
|
void slop::Mouse::setButton( int button, int state ) {
|
|
@@ -44,9 +46,20 @@ slop::Mouse::Mouse(X11* x11, int nodecorations, Window ignoreWindow ) {
|
44
|
46
|
currentCursor = XC_cross;
|
45
|
47
|
xcursor = XCreateFontCursor( x11->display, XC_cross );
|
46
|
48
|
hoverWindow = None;
|
47
|
|
- XGrabPointer( x11->display, x11->root, True,
|
48
|
|
- PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
|
49
|
|
- GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime );
|
|
49
|
+ int err = XGrabPointer( x11->display, x11->root, True,
|
|
50
|
+ PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
|
|
51
|
+ GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime );
|
|
52
|
+ int tries = 0;
|
|
53
|
+ while( err != GrabSuccess && tries < 5 ) {
|
|
54
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
55
|
+ err = XGrabPointer( x11->display, x11->root, True,
|
|
56
|
+ PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
|
|
57
|
+ GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime );
|
|
58
|
+ tries++;
|
|
59
|
+ }
|
|
60
|
+ if ( err != GrabSuccess ) {
|
|
61
|
+ throw new std::runtime_error( "Couldn't grab the mouse after 10 tries." );
|
|
62
|
+ }
|
50
|
63
|
this->nodecorations = nodecorations;
|
51
|
64
|
this->ignoreWindow = ignoreWindow;
|
52
|
65
|
hoverWindow = findWindow(x11->root);
|