Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gtk key repeat logic #1081

Merged
merged 4 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 @@ -348,6 +349,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),
Comment on lines +847 to +849
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on Wayland and I'm getting MOD2_MASK as well.

];

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