Skip to content

Commit

Permalink
X11: Fix pasting multiple times
Browse files Browse the repository at this point in the history
The simulated key press delay for Shift+Insert could have been too long
due to the application processing other events. This could have caused
the clipboard to be pasted to a target application multiple times.

The fix is to block any processing before key release is sent.

Fixes #1729
  • Loading branch information
hluk committed Sep 23, 2022
1 parent 4121251 commit 3c9a6c5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/platform/x11/x11platformwindow.cpp
Expand Up @@ -34,6 +34,8 @@
# include <X11/extensions/XTest.h>
#endif

#include <unistd.h> // usleep()

namespace {

class KeyPressTester final {
Expand All @@ -56,9 +58,9 @@ class KeyPressTester final {
};

#ifdef HAS_X11TEST
void fakeKeyEvent(Display* display, unsigned int keyCode, Bool isPress)
void fakeKeyEvent(Display* display, unsigned int keyCode, Bool isPress, unsigned long delayMs = CurrentTime)
{
XTestFakeKeyEvent(display, keyCode, isPress, CurrentTime);
XTestFakeKeyEvent(display, keyCode, isPress, delayMs);
XSync(display, False);
}

Expand Down Expand Up @@ -114,8 +116,8 @@ void simulateKeyPress(Display *display, const QList<int> &modCodes, unsigned int

fakeKeyEvent(display, keyCode, True);
// This is needed to paste into URL bar in Chrome.
waitFor(config.option<Config::window_key_press_time_ms>());
fakeKeyEvent(display, keyCode, False);
const ulong delayMs = config.option<Config::window_key_press_time_ms>();
fakeKeyEvent(display, keyCode, False, delayMs);

simulateModifierKeyPress(display, modCodes, False);

Expand Down

0 comments on commit 3c9a6c5

Please sign in to comment.