Skip to content

Commit 1d6a30f

Browse files
authored
Merge pull request #1081 from linebender/gtk-kb-fix
Fix gtk key repeat logic
2 parents f7f4248 + 2a45eff commit 1d6a30f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ You can find its changes [documented below](#060---2020-06-01).
3131
- GTK: Don't crash when receiving an external command while a file dialog is visible. ([#1043] by [@jneem])
3232
- Fix derive `Data` when type param bounds are defined ([#1058] by [@chris-zen])
3333
- Ensure that `update` is called after all commands. ([#1062] by [@jneem])
34+
- GTK: Don't interrupt `KeyEvent.repeat` when releasing another key. ([#1081] by [@raphlinus])
3435

3536
### Visual
3637

@@ -351,6 +352,7 @@ Last release without a changelog :(
351352
[#1054]: https://github.com/linebender/druid/pull/1054
352353
[#1058]: https://github.com/linebender/druid/pull/1058
353354
[#1062]: https://github.com/linebender/druid/pull/1062
355+
[#1081]: https://github.com/linebender/druid/pull/1081
354356

355357
[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
356358
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0

druid-shell/src/platform/gtk/window.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub(crate) struct WindowState {
119119
drawing_area: DrawingArea,
120120
pub(crate) handler: RefCell<Box<dyn WinHandler>>,
121121
idle_queue: Arc<Mutex<Vec<IdleKind>>>,
122-
current_keyval: RefCell<Option<u32>>,
122+
current_keycode: RefCell<Option<u16>>,
123123
}
124124

125125
impl WindowBuilder {
@@ -201,7 +201,7 @@ impl WindowBuilder {
201201
drawing_area,
202202
handler: RefCell::new(handler),
203203
idle_queue: Arc::new(Mutex::new(vec![])),
204-
current_keyval: RefCell::new(None),
204+
current_keycode: RefCell::new(None),
205205
});
206206

207207
self.app
@@ -475,10 +475,11 @@ impl WindowBuilder {
475475
win_state.drawing_area.connect_key_press_event(clone!(handle => move |_widget, key| {
476476
if let Some(state) = handle.state.upgrade() {
477477

478-
let mut current_keyval = state.current_keyval.borrow_mut();
479-
let repeat = *current_keyval == Some(key.get_keyval());
478+
let mut current_keycode = state.current_keycode.borrow_mut();
479+
let hw_keycode = key.get_hardware_keycode();
480+
let repeat = *current_keycode == Some(hw_keycode);
480481

481-
*current_keyval = Some(key.get_keyval());
482+
*current_keycode = Some(hw_keycode);
482483

483484
if let Ok(mut handler) = state.handler.try_borrow_mut() {
484485
handler.key_down(make_key_event(key, repeat, KeyState::Down));
@@ -493,7 +494,10 @@ impl WindowBuilder {
493494
win_state.drawing_area.connect_key_release_event(clone!(handle => move |_widget, key| {
494495
if let Some(state) = handle.state.upgrade() {
495496

496-
*(state.current_keyval.borrow_mut()) = None;
497+
let mut current_keycode = state.current_keycode.borrow_mut();
498+
if *current_keycode == Some(key.get_hardware_keycode()) {
499+
*current_keycode = None;
500+
}
497501

498502
if let Ok(mut handler) = state.handler.try_borrow_mut() {
499503
handler.key_up(make_key_event(key, false, KeyState::Up));
@@ -839,6 +843,10 @@ const MODIFIER_MAP: &[(gdk::ModifierType, Modifiers)] = &[
839843
(ModifierType::MOD1_MASK, Modifiers::ALT),
840844
(ModifierType::CONTROL_MASK, Modifiers::CONTROL),
841845
(ModifierType::META_MASK, Modifiers::META),
846+
(ModifierType::LOCK_MASK, Modifiers::CAPS_LOCK),
847+
// Note: this is the usual value on X11, not sure how consistent it is.
848+
// Possibly we should use `Keymap::get_num_lock_state()` instead.
849+
(ModifierType::MOD2_MASK, Modifiers::NUM_LOCK),
842850
];
843851

844852
fn get_modifiers(modifiers: gdk::ModifierType) -> Modifiers {

0 commit comments

Comments
 (0)