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

New keyboard API for Linux #1932

Closed
Closed
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
94ea878
Get stuff to compile
maroider Mar 19, 2021
6ddf1f8
WIP
maroider Mar 19, 2021
280eb74
Add some keysym mappings and move the keymap.rs file
maroider Mar 28, 2021
2417022
Add key location and some minor corrections
maroider Mar 29, 2021
a7445b1
Use xkbcommon-dl rather than xkbcommon
maroider Mar 29, 2021
0cb11c0
Hoist keyboard handling code from sctk into Winit
maroider Mar 31, 2021
b444cd1
fixup! Hoist keyboard handling code from sctk into Winit
maroider Jan 10, 2022
63c0370
Wire up the new events properly
maroider Apr 1, 2021
2a39d69
Fix creation of key value strings
maroider Apr 1, 2021
0f57043
Add missing keysym mapping
maroider Apr 1, 2021
e41c35b
Fix `key_without_modifiers`
maroider Apr 1, 2021
c9f8bb0
Feature-gate things which depend on memmap2
maroider Apr 1, 2021
a5bcc62
Be more consistent with what `keycode` means
maroider Apr 1, 2021
5d91b79
Improve key string handling
maroider Apr 1, 2021
08df35c
Add initial X11 support
maroider Apr 24, 2021
6297e99
Address compilation errors
maroider Apr 25, 2021
31759f7
Improve debug printing of `NativeKeyCode`
maroider Apr 24, 2021
2729cd9
Hook up X11 XKB modifier keys
maroider Apr 28, 2021
b337590
Use XInput2 for regular key events
maroider May 1, 2021
ad0916d
Implement dead-key handling
maroider May 7, 2021
8f08e95
Remove unused module
maroider May 7, 2021
297c19c
Update xkbcommon-dl
ArturKovacs May 10, 2021
b2372b5
Update xkbcommon-dl again
maroider May 16, 2021
da6d1c7
Remove accidentally included attribute
maroider May 16, 2021
c41ad69
Use `as u32` to cast `i32`s to `u32`s
maroider May 16, 2021
94f02bb
Put more things behind the "wayland" feature
maroider May 16, 2021
1603f6b
Remove superfluous scope
maroider May 16, 2021
69dc88b
Separate out loading of the X11 keymap
maroider Jun 16, 2021
f919bdb
Wire up X11 IME support
maroider Jun 16, 2021
d8e281f
Use the currently active keyboard layout on X11
ArturKovacs Jul 4, 2021
21c6a57
fixup! Wire up X11 IME support
maroider Jul 4, 2021
a40acad
Enable keysym mapping for "Alt Graph"
maroider Aug 3, 2021
fd3139e
Actually respect keyboard layout changes
maroider Aug 4, 2021
42c85e1
Make `xkb_state` more internally consistent
maroider Aug 5, 2021
05af68a
Improve the safety of `KbState`
maroider Aug 5, 2021
5195072
Make a decision on control characters and dead keys
maroider Aug 5, 2021
1e1ec76
Store keycodes with X11's keycode offset
maroider Aug 5, 2021
7784cfd
Log an error if we can't select XKB events
maroider Aug 5, 2021
23c4bfb
Remove superfluous call to `Vec::set_len`
maroider Aug 5, 2021
9e8310b
Send a warning if the server doesn't send a keymap
maroider Aug 11, 2021
446f243
Implement `KeyCodeExtScancode` on Wayland and X11
maroider Aug 24, 2021
48cce91
Implement `reset_dead_keys` (poorly)
maroider Aug 24, 2021
e7a3043
Split the native XKB keycode enum variant in two
maroider Sep 9, 2021
b68b364
Add a TODO regarding the `ModifiersChanged` event.
maroider Sep 9, 2021
31103b8
fix: meta mod key on focus handling for gnome/x11
rti Sep 9, 2021
53c28f8
Remove the `XkbStateNotify` handler
maroider Oct 6, 2021
a160354
X11: Only fetch virtual keyboard events from master devices
mahkoh Oct 21, 2021
6363ab0
Revert "fix: meta mod key on focus handling for gnome/x11"
maroider Jun 12, 2022
9dc461d
General clippy fixes and formatting
maroider Jun 13, 2022
f012932
Improve libxkbcommon string handling
maroider Jun 13, 2022
21508a1
Add `WindowBuilder::transparent`
kchibisov Jun 12, 2022
246dd51
Fix doubled device events on X11
maroider Jun 13, 2022
da1652e
Don't reload the keymap on every keypress
maroider Jun 15, 2022
0d5ae7c
Use XkbStateNotify to track the active set of modifiers
maroider Jul 7, 2022
6c7820e
Rip out the old code-path for modifier state tracking on X11
maroider Jul 7, 2022
51975ef
Rip out some vestigial parts
maroider Jul 7, 2022
9d077ab
Deal with various TODOs
maroider Jul 7, 2022
29c6762
Deduplicate code in ModifiersState::update_with
maroider Nov 18, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ And please only add new entries to the top of this list, right below the `# Unre

- Build docs on `docs.rs` for iOS and Android as well.
- **Breaking:** Removed the `WindowAttributes` struct, since all its functionality is accessible from `WindowBuilder`.
- Added `WindowBuilder::transparent` getter to check if the user set `transparent` attribute.
- On macOS, Fix emitting `Event::LoopDestroyed` on CMD+Q.
- On macOS, fixed an issue where having multiple windows would prevent run_return from ever returning.
- On Wayland, fix bug where the cursor wouldn't hide in GNOME.
Expand Down
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ targets = [

[features]
default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]
x11 = ["x11-dl", "mio", "percent-encoding", "parking_lot"]
wayland = ["wayland-client", "wayland-protocols", "sctk"]
x11 = ["x11-dl", "mio", "percent-encoding", "parking_lot", "xkbcommon-dl/x11"]
wayland = ["wayland-client", "wayland-protocols", "sctk", "memmap2"]
wayland-dlopen = ["sctk/dlopen", "wayland-client/dlopen"]
wayland-csd-adwaita = ["sctk-adwaita", "sctk-adwaita/title"]
wayland-csd-adwaita-notitle = ["sctk-adwaita"]
Expand Down Expand Up @@ -112,6 +112,8 @@ x11-dl = { version = "2.18.5", optional = true }
percent-encoding = { version = "2.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }
libc = "0.2.64"
memmap2 = { version = "0.2.1", optional = true }
xkbcommon-dl = { git = "https://github.com/maroider/xkbcommon-dl", rev = "900832888ad6f11011d1369befb344a9aa8a9610" }

[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]
package = "web-sys"
Expand Down
21 changes: 16 additions & 5 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ pub enum NativeKeyCode {
Unidentified,
Windows(u16),
MacOS(u32),
XKB(u32),
XkbCode(u32),
XkbSym(u32),
}
impl std::fmt::Debug for NativeKeyCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use NativeKeyCode::{MacOS, Unidentified, Windows, XKB};
use NativeKeyCode::{MacOS, Unidentified, Windows, XkbCode, XkbSym};
let mut debug_tuple;
match self {
Unidentified => {
Expand All @@ -193,9 +194,13 @@ impl std::fmt::Debug for NativeKeyCode {
debug_tuple = f.debug_tuple(name_of!(MacOS));
debug_tuple.field(v);
}
XKB(v) => {
debug_tuple = f.debug_tuple(name_of!(XKB));
debug_tuple.field(v);
XkbCode(v) => {
debug_tuple = f.debug_tuple(name_of!(XkbCode));
debug_tuple.field(&format_args!("0x{:04X}", v));
}
XkbSym(v) => {
debug_tuple = f.debug_tuple(name_of!(XkbSym));
debug_tuple.field(&format_args!("0x{:04X}", v));
}
}
debug_tuple.finish()
Expand Down Expand Up @@ -536,6 +541,9 @@ pub enum KeyCode {
AudioVolumeMute,
AudioVolumeUp,
WakeUp,
// Legacy modifier key. Also called "Super" in certain places.
Meta,
// Legacy modifier key.
Hyper,
Turbo,
Abort,
Expand Down Expand Up @@ -731,6 +739,9 @@ pub enum Key<'a> {
/// The Symbol modifier key (used on some virtual keyboards).
Symbol,
SymbolLock,
// Legacy modifier key. Also called "Super" in certain places.
Meta,
// Legacy modifier key.
Hyper,
/// Used to enable "super" modifier function for interpreting concurrent or subsequent keyboard
/// input. This key value is used for the "Windows Logo" key and the Apple `Command` or `⌘` key.
Expand Down
1 change: 1 addition & 0 deletions src/platform/scancode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub trait KeyCodeExtScancode {
///
/// ## Platform-specific
/// - **Windows:** A 16bit extended scancode
/// - **Wayland/X11**: A 32-bit X11-style keycode.
// TODO: Describe what this value contains for each platform
fn to_scancode(self) -> Option<u32>;

Expand Down
26 changes: 26 additions & 0 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ use std::os::raw;
use std::{ptr, sync::Arc};

use crate::{
event::KeyEvent,
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
keyboard::{Key, KeyCode},
monitor::MonitorHandle,
platform::{modifier_supplement::KeyEventExtModifierSupplement, scancode::KeyCodeExtScancode},
platform_impl::common::keymap,
window::{Window, WindowBuilder},
};

Expand Down Expand Up @@ -434,3 +438,25 @@ impl MonitorHandleExtUnix for MonitorHandle {
self.inner.native_identifier()
}
}

impl KeyEventExtModifierSupplement for KeyEvent {
#[inline]
fn text_with_all_modifiers(&self) -> Option<&str> {
self.platform_specific.text_with_all_modifiers
}

#[inline]
fn key_without_modifiers(&self) -> Key<'static> {
self.platform_specific.key_without_modifiers
}
}

impl KeyCodeExtScancode for KeyCode {
fn from_scancode(scancode: u32) -> KeyCode {
keymap::raw_keycode_to_keycode(scancode)
}

fn to_scancode(self) -> Option<u32> {
keymap::keycode_to_raw(self)
}
}
Loading