Skip to content

Commit

Permalink
Merge pull request #1081 from linebender/gtk-kb-fix
Browse files Browse the repository at this point in the history
Fix gtk key repeat logic
  • Loading branch information
raphlinus authored Jul 12, 2020
2 parents f7f4248 + 2a45eff commit 1d6a30f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You can find its changes [documented below](#060---2020-06-01).
- GTK: Don't crash when receiving an external command while a file dialog is visible. ([#1043] by [@jneem])
- Fix derive `Data` when type param bounds are defined ([#1058] by [@chris-zen])
- Ensure that `update` is called after all commands. ([#1062] by [@jneem])
- GTK: Don't interrupt `KeyEvent.repeat` when releasing another key. ([#1081] by [@raphlinus])

### Visual

Expand Down Expand Up @@ -351,6 +352,7 @@ Last release without a changelog :(
[#1054]: https://github.com/linebender/druid/pull/1054
[#1058]: https://github.com/linebender/druid/pull/1058
[#1062]: https://github.com/linebender/druid/pull/1062
[#1081]: https://github.com/linebender/druid/pull/1081

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0
Expand Down
20 changes: 14 additions & 6 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub(crate) struct WindowState {
drawing_area: DrawingArea,
pub(crate) handler: RefCell<Box<dyn WinHandler>>,
idle_queue: Arc<Mutex<Vec<IdleKind>>>,
current_keyval: RefCell<Option<u32>>,
current_keycode: RefCell<Option<u16>>,
}

impl WindowBuilder {
Expand Down Expand Up @@ -201,7 +201,7 @@ impl WindowBuilder {
drawing_area,
handler: RefCell::new(handler),
idle_queue: Arc::new(Mutex::new(vec![])),
current_keyval: RefCell::new(None),
current_keycode: RefCell::new(None),
});

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

let mut current_keyval = state.current_keyval.borrow_mut();
let repeat = *current_keyval == Some(key.get_keyval());
let mut current_keycode = state.current_keycode.borrow_mut();
let hw_keycode = key.get_hardware_keycode();
let repeat = *current_keycode == Some(hw_keycode);

*current_keyval = Some(key.get_keyval());
*current_keycode = Some(hw_keycode);

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

*(state.current_keyval.borrow_mut()) = None;
let mut current_keycode = state.current_keycode.borrow_mut();
if *current_keycode == Some(key.get_hardware_keycode()) {
*current_keycode = None;
}

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

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

0 comments on commit 1d6a30f

Please sign in to comment.