|
@@ -176,7 +176,10 @@ void slop::XEngine::selectAllInputs( Window win, long event_mask) {
|
176
|
176
|
}
|
177
|
177
|
|
178
|
178
|
// Grabs the cursor, be wary that setCursor changes the mouse masks.
|
179
|
|
-int slop::XEngine::grabCursor( slop::CursorType type ) {
|
|
179
|
+// waittime is how long grabCursor can repeatedly try to grab the cursor, if it fails to grab.
|
|
180
|
+// This is because tiling window managers like i3 grab the mouse while holding down certain keys,
|
|
181
|
+// while these certain keys also launch slop.
|
|
182
|
+int slop::XEngine::grabCursor( slop::CursorType type, double waittime ) {
|
180
|
183
|
if ( !m_good ) {
|
181
|
184
|
return EXIT_FAILURE;
|
182
|
185
|
}
|
|
@@ -184,8 +187,33 @@ int slop::XEngine::grabCursor( slop::CursorType type ) {
|
184
|
187
|
int err = XGrabPointer( m_display, m_root, True,
|
185
|
188
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
|
186
|
189
|
GrabModeAsync, GrabModeAsync, None, xfontcursor, CurrentTime );
|
|
190
|
+ double accumulationtime = 0;
|
|
191
|
+ int timestep = 10000; // in microseconds
|
|
192
|
+ while ( err != GrabSuccess && accumulationtime < waittime ) {
|
|
193
|
+ err = XGrabPointer( m_display, m_root, True,
|
|
194
|
+ PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
|
|
195
|
+ GrabModeAsync, GrabModeAsync, None, xfontcursor, CurrentTime );
|
|
196
|
+ usleep( timestep );
|
|
197
|
+ accumulationtime += double( timestep/1000000.f );
|
|
198
|
+ }
|
187
|
199
|
if ( err != GrabSuccess ) {
|
188
|
200
|
fprintf( stderr, "Error: Failed to grab X cursor.\n" );
|
|
201
|
+ switch( err ) {
|
|
202
|
+ case 1:
|
|
203
|
+ fprintf( stderr, " The cursor is already grabbed by another application.\n" );
|
|
204
|
+ break;
|
|
205
|
+ case 2:
|
|
206
|
+ fprintf( stderr, " The cursor grab was initiated at an invalid time (in the past?) .\n" );
|
|
207
|
+ break;
|
|
208
|
+ case 3:
|
|
209
|
+ fprintf( stderr, " The cursor is not viewable or outside of the bounds of the root window.\n" );
|
|
210
|
+ break;
|
|
211
|
+ case 4:
|
|
212
|
+ fprintf( stderr, " The grab is frozen already by an active grab by another application.\n" );
|
|
213
|
+ break;
|
|
214
|
+ default:
|
|
215
|
+ break;
|
|
216
|
+ }
|
189
|
217
|
fprintf( stderr, " This can be caused by launching slop weirdly.\n" );
|
190
|
218
|
return EXIT_FAILURE;
|
191
|
219
|
}
|