Skip to content

Commit

Permalink
Use XSync instead of XFlush everywhere - fixes octalmage/robotjs#347
Browse files Browse the repository at this point in the history
  • Loading branch information
canonic-epicure committed Jan 15, 2018
1 parent 85e2e9c commit cc4b3d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/keypress.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(XTestFakeKeyEvent(display, \
XKeysymToKeycode(display, key), \
is_press, CurrentTime), \
XFlush(display))
XSync(display, false))
#define X_KEY_EVENT_WAIT(display, key, is_press) \
(X_KEY_EVENT(display, key, is_press), \
microsleep(DEADBEEF_UNIFORM(0.0, 62.5)))
Expand Down Expand Up @@ -162,25 +162,25 @@ void tapKeyCode(MMKeyCode code, MMKeyFlags flags)
}

void toggleKey(char c, const bool down, MMKeyFlags flags)
{
{
MMKeyCode keyCode = keyCodeForChar(c);

//Prevent unused variable warning for Mac and Linux.
#if defined(IS_WINDOWS)
int modifiers;
#endif
#endif

if (isupper(c) && !(flags & MOD_SHIFT)) {
flags |= MOD_SHIFT; /* Not sure if this is safe for all layouts. */
}

#if defined(IS_WINDOWS)
modifiers = keyCode >> 8; // Pull out modifers.
if ((modifiers & 1) != 0) flags |= MOD_SHIFT; // Uptdate flags from keycode modifiers.
if ((modifiers & 2) != 0) flags |= MOD_CONTROL;
if ((modifiers & 4) != 0) flags |= MOD_ALT;
keyCode = keyCode & 0xff; // Mask out modifiers.
#endif
#endif
toggleKeyCode(keyCode, down, flags);
}

Expand Down
6 changes: 3 additions & 3 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void moveMouse(MMPoint point)
Display *display = XGetMainDisplay();
XWarpPointer(display, None, DefaultRootWindow(display),
0, 0, 0, 0, point.x, point.y);
XFlush(display);
XSync(display, false);
#elif defined(IS_WINDOWS)
//Mouse motion is now done using SendInput with MOUSEINPUT. We use Absolute mouse positioning
#define MOUSE_COORD_TO_ABS(coord, width_or_height) (((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
Expand Down Expand Up @@ -184,7 +184,7 @@ void toggleMouse(bool down, MMMouseButton button)
#elif defined(USE_X11)
Display *display = XGetMainDisplay();
XTestFakeButtonEvent(display, button, down ? True : False, CurrentTime);
XFlush(display);
XSync(display, false);
#elif defined(IS_WINDOWS)
mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0);
#endif
Expand Down Expand Up @@ -278,7 +278,7 @@ void scrollMouse(int x, int y)
YTestFakeButtonEvent(display, ydir, 0, CurrentTime);
}

XFlush(display);
XSync(display, false);

#elif defined(IS_WINDOWS)

Expand Down

0 comments on commit cc4b3d3

Please sign in to comment.