Skip to content
This repository was archived by the owner on Dec 18, 2021. It is now read-only.

Commit 84fe140

Browse files
committed
wayland: Fix the unwanted key repeat issue
Key repeat of bypassed key shouldn't be handled by IME. Reference: swaywm/sway#4932 (comment)
1 parent 0ab49f2 commit 84fe140

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/frontends/wayland/src/main.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,6 @@ impl KimeContext {
217217
} => {
218218
// NOTE: Never read `serial` of KeyEvent. You should rely on serial of KimeContext
219219
if state == KeyState::Pressed {
220-
// Start waiting for the key hold timer event
221-
if let Some((info, ref mut press_state)) = self.repeat_state {
222-
if !press_state.is_pressing(key) {
223-
let duration = Duration::from_millis(info.delay as u64);
224-
self.timer.set_timeout(&duration).unwrap();
225-
*press_state = PressState::Pressing {
226-
pressed_at: Instant::now(),
227-
is_repeating: false,
228-
key,
229-
wayland_time: time,
230-
};
231-
}
232-
}
233-
234220
let mut bypass = false;
235221
let ret = self
236222
.engine
@@ -268,6 +254,25 @@ impl KimeContext {
268254

269255
if bypass {
270256
self.vk.key(time, key, state as _);
257+
} else {
258+
// If the key was not bypassed by IME, start waiting for the key hold timer
259+
// event. Key repeat of bypassed key shouldn't be handled by IME.
260+
//
261+
// Reference:
262+
// https://github.com/swaywm/sway/pull/4932#issuecomment-774113129
263+
match self.repeat_state {
264+
Some((info, ref mut press_state)) if !press_state.is_pressing(key) => {
265+
let duration = Duration::from_millis(info.delay as u64);
266+
self.timer.set_timeout(&duration).unwrap();
267+
*press_state = PressState::Pressing {
268+
pressed_at: Instant::now(),
269+
is_repeating: false,
270+
key,
271+
wayland_time: time,
272+
};
273+
}
274+
_ => {}
275+
}
271276
}
272277
} else {
273278
// If user released the last pressed key, clear the timer and state

0 commit comments

Comments
 (0)