Skip to content

Commit

Permalink
Reimplement half-delay on X11 as covered in #1132
Browse files Browse the repository at this point in the history
  • Loading branch information
sammdot committed Sep 27, 2023
1 parent c845e0e commit a127694
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion plover/oslayer/linux/keyboardcontrol_x11.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os
import select
import threading
from time import sleep

from Xlib import X, XK
from Xlib.display import Display
Expand Down Expand Up @@ -1223,7 +1224,7 @@ def send_backspaces(self, count):
self._display.sync()

def send_string(self, string):
for char in self.with_delay(string):
for char in string:
keysym = uchr_to_keysym(char)
# TODO: can we find mappings for multiple keys at a time?
mapping = self._get_mapping(keysym, automatically_map=False)
Expand All @@ -1232,12 +1233,18 @@ def send_string(self, string):
mapping = self._get_mapping(keysym, automatically_map=True)
if mapping is None:
continue
self._display.sync()
self.half_delay()
mapping_changed = True

self._send_keycode(mapping.keycode,
mapping.modifiers)

self._display.sync()
if mapping_changed:
self.half_delay()
else:
self.delay()

def send_key_combination(self, combo):
# Parse and validate combo.
Expand Down
4 changes: 4 additions & 0 deletions plover/output/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def delay(self):
if self._key_press_delay_ms > 0:
sleep(self._key_press_delay_ms / 1000)

def half_delay(self):
if self._key_press_delay_ms > 0:
sleep(self._key_press_delay_ms / 2000)

def with_delay(self, iterable):
for item in iterable:
yield item
Expand Down

0 comments on commit a127694

Please sign in to comment.