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

Wayland: improve keyboard handling #7970

Closed
wants to merge 6 commits into from

Conversation

romgrk
Copy link
Contributor

@romgrk romgrk commented Feb 18, 2024

Makes keyboard somewhat more usable under wayland.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 18, 2024
@Titaniumtown Titaniumtown mentioned this pull request Feb 18, 2024
12 tasks
Comment on lines +435 to +438

// Need to implement state.repeat_delay and state.repeat_rate
// todo!(linux)
state.repeat_current_keysym = Some(key_sym);
Copy link
Contributor Author

@romgrk romgrk Feb 18, 2024

Choose a reason for hiding this comment

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

Key repeat must be handled by the wayland client.

I'd do it myself but I don't understand async rust and the executor well enough. IIUC, to schedule a task to run after a timeout I should do something like this? Or should I cancel the task in the key-release event? If so, how do I cancel a task?

state.platform_inner.foreground_executor.spawn(async move {
  Timer::after(state.repeat_delay).await;
  if let Some(key_sym) = state.repeat_current_keysym {
    trigger_keypress_repeat();
  }
})

Comment on lines 390 to 404
xkb::Keysym::BackSpace
| xkb::Keysym::Escape
| xkb::Keysym::Home
| xkb::Keysym::End
| xkb::Keysym::Delete
| xkb::Keysym::Insert
| xkb::Keysym::Menu
| xkb::Keysym::Left
| xkb::Keysym::Right
| xkb::Keysym::Down
| xkb::Keysym::Up
| xkb::Keysym::Page_Down
| xkb::Keysym::Page_Up
| xkb::Keysym::Super_L
| xkb::Keysym::Super_R
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tab and space are inputed as \t and \s, should they be in this list? What we really want is a is_keysym_printable() function, but it always ends up as a list.

There's missing keysyms here. We might want to use a list from somewhere that has already done this more thouroughly, e.g. from chromium.

Copy link

@davidsmfreire davidsmfreire Feb 18, 2024

Choose a reason for hiding this comment

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

I'm also looking into translating control characters into the key pressed, so that we could use ctrl-(key) keymaps. (https://www.geeksforgeeks.org/control-characters/) #7975

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't the code below doing the work that you're trying to do there?

See line 407-408 of this file post patch, right below.

Choose a reason for hiding this comment

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

Yep, it does... My bad, and thank you, i'll close my PR

Comment on lines +426 to +429
} else if key_sym == xkb::Keysym::Super_L
|| key_sym == xkb::Keysym::Super_R
{
state.modifiers.command = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the time being, this allows to test keyboard shortcuts (and features) by using super instead of cmd as there isn't a linux keymap yet.

Not sure what behavior we want, but we could use the same convention as the web: both the super and command keys map to the "meta" modifier.

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't seem like a good desicion because it doesn't work on all platforms (e.g. Gnome)

@davidsmfreire
Copy link

Found this PR just as I was adding the else if for super to command modifier 😄 . I agree that super, cmd and windows key should map to a meta key. Also, I would add a comment to gpui/src/platform/keystroke.rs, right above the pub command: bool:

pub struct Modifiers {
    ....

    /// The command key, on macos
    /// the windows key, on windows
    /// the super key, on linux
    pub command: bool,

    ....
}

@tadeokondrak
Copy link
Contributor

I've just opened #7989, which I think might solve the same problems as this issue without having to maintain a list of keycodes here.

@romgrk
Copy link
Contributor Author

romgrk commented Feb 18, 2024

I've just opened #7989, which I think might solve the same problems as this issue without having to maintain a list of keycodes here.

That works for me, avoiding storing the modifiers is a better approach as it will make super+... shortcuts work even on gnome.

@romgrk romgrk closed this Feb 18, 2024
@romgrk romgrk deleted the fix-wayland-keyboard-input branch February 18, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants