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

WIP: Use keyboard-types #4026

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ android-game-activity = ["android-activity/game-activity"]
android-native-activity = ["android-activity/native-activity"]
default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]
mint = ["dpi/mint"]
serde = ["dep:serde", "cursor-icon/serde", "smol_str/serde", "dpi/serde", "bitflags/serde"]
serde = [
"dep:serde",
"cursor-icon/serde",
"smol_str/serde",
"dpi/serde",
"bitflags/serde",
"keyboard-types/serde",
]
wayland = [
"wayland-client",
"wayland-backend",
Expand All @@ -79,6 +86,7 @@ cfg_aliases = "0.2.1"
bitflags = "2"
cursor-icon = "1.1.0"
dpi = { version = "0.1.1", path = "dpi" }
keyboard-types = { git = "https://github.com/madsmtm/keyboard-types.git", branch = "winit", default-features = false }
rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"] }
serde = { workspace = true, optional = true }
smol_str = "0.2.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ fn modifiers_to_string(mods: ModifiersState) -> String {
let mut mods_line = String::new();
// Always add + since it's printed as a part of the bindings.
for (modifier, desc) in [
(ModifiersState::SUPER, "Super+"),
(ModifiersState::META, "Meta+"),
(ModifiersState::ALT, "Alt+"),
(ModifiersState::CONTROL, "Ctrl+"),
(ModifiersState::SHIFT, "Shift+"),
Expand Down Expand Up @@ -1224,10 +1224,10 @@ const KEY_BINDINGS: &[Binding<&'static str>] = &[
Binding::new("Z", ModifiersState::CONTROL, Action::ToggleCursorVisibility),
// K.
Binding::new("K", ModifiersState::empty(), Action::SetTheme(None)),
Binding::new("K", ModifiersState::SUPER, Action::SetTheme(Some(Theme::Light))),
Binding::new("K", ModifiersState::META, Action::SetTheme(Some(Theme::Light))),
Binding::new("K", ModifiersState::CONTROL, Action::SetTheme(Some(Theme::Dark))),
#[cfg(macos_platform)]
Binding::new("T", ModifiersState::SUPER, Action::CreateNewTab),
Binding::new("T", ModifiersState::META, Action::CreateNewTab),
#[cfg(macos_platform)]
Binding::new("O", ModifiersState::CONTROL, Action::CycleOptionAsAlt),
Binding::new("S", ModifiersState::CONTROL, Action::Message),
Expand Down
2 changes: 2 additions & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ changelog entry.
- In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`.
- Remove `Force::Calibrated::altitude_angle`.
- On X11, use bottom-right corner for IME hotspot in `Window::set_ime_cursor_area`.
- Renamed "super" key to "meta", to match the naming in the W3C specification.

### Removed

Expand Down Expand Up @@ -193,6 +194,7 @@ changelog entry.
`ButtonSource` as part of the new pointer event overhaul.
- Remove `Force::altitude_angle`.
- Removed `Window::inner_position`, use the new `Window::surface_position` instead.
- Removed `NamedKey::Space`, match on `Key::Character(" ")` instead.

### Fixed

Expand Down
10 changes: 6 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,17 @@ pub struct KeyEvent {
/// The most prevalent use case for this is games. For example the default keys for the player
/// to move around might be the W, A, S, and D keys on a US layout. The position of these keys
/// is more important than their label, so they should map to Z, Q, S, and D on an "AZERTY"
/// layout. (This value is `KeyCode::KeyW` for the Z key on an AZERTY layout.)
/// layout. (This value is [`Code::KeyW`] for the Z key on an AZERTY layout.)
///
/// [`Code::KeyW`]: keyboard_types::Code::KeyW
///
/// ## Caveats
///
/// - Certain niche hardware will shuffle around physical key positions, e.g. a keyboard that
/// implements DVORAK in hardware (or firmware)
/// - Your application will likely have to handle keyboards which are missing keys that your
/// own keyboard has.
/// - Certain `KeyCode`s will move between a couple of different positions depending on what
/// - Certain `Code`s will move between a couple of different positions depending on what
/// layout the keyboard was manufactured to support.
///
/// **Because of these caveats, it is important that you provide users with a way to configure
Expand Down Expand Up @@ -910,12 +912,12 @@ impl Modifiers {

/// The state of the left super key.
pub fn lsuper_state(&self) -> ModifiersKeyState {
self.mod_state(ModifiersKeys::LSUPER)
self.mod_state(ModifiersKeys::LMETA)
}

/// The state of the right super key.
pub fn rsuper_state(&self) -> ModifiersKeyState {
self.mod_state(ModifiersKeys::RSUPER)
self.mod_state(ModifiersKeys::RMETA)
}

fn mod_state(&self, modifier: ModifiersKeys) -> ModifiersKeyState {
Expand Down
Loading