From 546b0d6eaeaed4ec64ebb130c20043eead977017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Fri, 13 Nov 2020 21:37:13 +0100 Subject: [PATCH] Use keyboard-types types directly instead of druid wrappers --- src/event.rs | 6 +- src/keyboard.rs | 209 +-------------------------------------- src/lib.rs | 1 - src/macos/keyboard.rs | 102 ++++++++++---------- src/macos/window.rs | 5 +- src/x11/keyboard.rs | 220 +++++++++++++++++++++--------------------- 6 files changed, 170 insertions(+), 373 deletions(-) diff --git a/src/event.rs b/src/event.rs index 23face7..443f939 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,9 +1,9 @@ -use crate::{WindowInfo, Point, KeyEvent}; +use crate::{WindowInfo, Point}; #[derive(Debug, Clone, PartialEq)] pub enum KeyboardEvent { - KeyPressed(KeyEvent), - KeyReleased(KeyEvent), + KeyPressed(keyboard_types::KeyboardEvent), + KeyReleased(keyboard_types::KeyboardEvent), } diff --git a/src/keyboard.rs b/src/keyboard.rs index 1e4475d..38b2e9a 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -13,216 +13,11 @@ // limitations under the License. // Baseview modifications to druid code: -// - move code_to_location function to this file +// - only keep code_to_location function //! Keyboard types. -// This is a reasonable lint, but we keep signatures in sync with the -// bitflags implementation of the inner Modifiers type. -#![allow(clippy::trivially_copy_pass_by_ref)] - -use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not}; - -pub use keyboard_types::{Code, KeyState, Location}; - -/// The meaning (mapped value) of a keypress. -pub type KbKey = keyboard_types::Key; - -/// Information about a keyboard event. -/// -/// Note that this type is similar to [`KeyboardEvent`] in keyboard-types, -/// but has a few small differences for convenience. It is missing the `state` -/// field because that is already implicit in the event. -/// -/// [`KeyboardEvent`]: keyboard_types::KeyboardEvent -#[non_exhaustive] -#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)] -pub struct KeyEvent { - /// Whether the key is pressed or released. - pub state: KeyState, - /// Logical key value. - pub key: KbKey, - /// Physical key position. - pub code: Code, - /// Location for keys with multiple instances on common keyboards. - pub location: Location, - /// Flags for pressed modifier keys. - pub mods: Modifiers, - /// True if the key is currently auto-repeated. - pub repeat: bool, - /// Events with this flag should be ignored in a text editor - /// and instead composition events should be used. - pub is_composing: bool, -} - -/// The modifiers. -/// -/// This type is a thin wrappers around [`keyboard_types::Modifiers`], -/// mostly for the convenience methods. If those get upstreamed, it -/// will simply become that type. -/// -/// [`keyboard_types::Modifiers`]: keyboard_types::Modifiers -#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] -pub struct Modifiers(keyboard_types::Modifiers); - -/// A convenience trait for creating Key objects. -/// -/// This trait is implemented by [`KbKey`] itself and also strings, which are -/// converted into the `Character` variant. It is defined this way and not -/// using the standard `Into` mechanism because `KbKey` is a type in an external -/// crate. -/// -/// [`KbKey`]: KbKey -pub trait IntoKey { - fn into_key(self) -> KbKey; -} - -impl KeyEvent { - #[doc(hidden)] - /// Create a key event for testing purposes. - pub fn for_test(mods: impl Into, key: impl IntoKey) -> KeyEvent { - let mods = mods.into(); - let key = key.into_key(); - KeyEvent { - key, - code: Code::Unidentified, - location: Location::Standard, - state: KeyState::Down, - mods, - is_composing: false, - repeat: false, - } - } -} - -impl Modifiers { - pub const ALT: Modifiers = Modifiers(keyboard_types::Modifiers::ALT); - pub const ALT_GRAPH: Modifiers = Modifiers(keyboard_types::Modifiers::ALT_GRAPH); - pub const CAPS_LOCK: Modifiers = Modifiers(keyboard_types::Modifiers::CAPS_LOCK); - pub const CONTROL: Modifiers = Modifiers(keyboard_types::Modifiers::CONTROL); - pub const FN: Modifiers = Modifiers(keyboard_types::Modifiers::FN); - pub const FN_LOCK: Modifiers = Modifiers(keyboard_types::Modifiers::FN_LOCK); - pub const META: Modifiers = Modifiers(keyboard_types::Modifiers::META); - pub const NUM_LOCK: Modifiers = Modifiers(keyboard_types::Modifiers::NUM_LOCK); - pub const SCROLL_LOCK: Modifiers = Modifiers(keyboard_types::Modifiers::SCROLL_LOCK); - pub const SHIFT: Modifiers = Modifiers(keyboard_types::Modifiers::SHIFT); - pub const SYMBOL: Modifiers = Modifiers(keyboard_types::Modifiers::SYMBOL); - pub const SYMBOL_LOCK: Modifiers = Modifiers(keyboard_types::Modifiers::SYMBOL_LOCK); - pub const HYPER: Modifiers = Modifiers(keyboard_types::Modifiers::HYPER); - pub const SUPER: Modifiers = Modifiers(keyboard_types::Modifiers::SUPER); - - /// Get the inner value. - /// - /// Note that this function might go away if our changes are upstreamed. - pub fn raw(&self) -> keyboard_types::Modifiers { - self.0 - } - - /// Determine whether Shift is set. - pub fn shift(&self) -> bool { - self.contains(Modifiers::SHIFT) - } - - /// Determine whether Ctrl is set. - pub fn ctrl(&self) -> bool { - self.contains(Modifiers::CONTROL) - } - - /// Determine whether Alt is set. - pub fn alt(&self) -> bool { - self.contains(Modifiers::ALT) - } - - /// Determine whether Meta is set. - pub fn meta(&self) -> bool { - self.contains(Modifiers::META) - } - - /// Returns an empty set of modifiers. - pub fn empty() -> Modifiers { - Default::default() - } - - /// Returns `true` if no modifiers are set. - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - - /// Returns `true` if all the modifiers in `other` are set. - pub fn contains(&self, other: Modifiers) -> bool { - self.0.contains(other.0) - } - - /// Inserts or removes the specified modifiers depending on the passed value. - pub fn set(&mut self, other: Modifiers, value: bool) { - self.0.set(other.0, value) - } -} - -impl BitAnd for Modifiers { - type Output = Self; - - fn bitand(self, rhs: Self) -> Self { - Modifiers(self.0 & rhs.0) - } -} - -impl BitAndAssign for Modifiers { - // rhs is the "right-hand side" of the expression `a &= b` - fn bitand_assign(&mut self, rhs: Self) { - *self = Modifiers(self.0 & rhs.0) - } -} - -impl BitOr for Modifiers { - type Output = Self; - - fn bitor(self, rhs: Self) -> Self { - Modifiers(self.0 | rhs.0) - } -} - -impl BitOrAssign for Modifiers { - // rhs is the "right-hand side" of the expression `a &= b` - fn bitor_assign(&mut self, rhs: Self) { - *self = Modifiers(self.0 | rhs.0) - } -} - -impl BitXor for Modifiers { - type Output = Self; - - fn bitxor(self, rhs: Self) -> Self { - Modifiers(self.0 ^ rhs.0) - } -} - -impl BitXorAssign for Modifiers { - // rhs is the "right-hand side" of the expression `a &= b` - fn bitxor_assign(&mut self, rhs: Self) { - *self = Modifiers(self.0 ^ rhs.0) - } -} - -impl Not for Modifiers { - type Output = Self; - - fn not(self) -> Self { - Modifiers(!self.0) - } -} - -impl IntoKey for KbKey { - fn into_key(self) -> KbKey { - self - } -} - -impl IntoKey for &str { - fn into_key(self) -> KbKey { - KbKey::Character(self.into()) - } -} +use keyboard_types::{Code, Location}; #[cfg(any(target_os = "linux", target_os = "macos"))] diff --git a/src/lib.rs b/src/lib.rs index ef2f728..67ac9dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ mod mouse_cursor; mod window_info; mod window_open_options; pub use event::*; -pub use keyboard::KeyEvent; pub use mouse_cursor::MouseCursor; pub use window_info::*; pub use window_open_options::*; diff --git a/src/macos/keyboard.rs b/src/macos/keyboard.rs index 40cc511..4f1dd1b 100644 --- a/src/macos/keyboard.rs +++ b/src/macos/keyboard.rs @@ -21,10 +21,10 @@ use cocoa::appkit::{NSEvent, NSEventModifierFlags, NSEventType}; use cocoa::foundation::NSString; use cocoa::base::id; -use keyboard_types::{Code, KeyState}; +use keyboard_types::{Code, KeyState, Key, KeyboardEvent, Modifiers}; use objc::{msg_send, sel, sel_impl}; -use crate::keyboard::{code_to_location, KbKey, KeyEvent, Modifiers}; +use crate::keyboard::code_to_location; pub(crate) fn from_nsstring(s: id) -> String { @@ -195,52 +195,52 @@ fn key_code_to_code(key_code: u16) -> Code { /// /// The logic for this function is derived from KEY_MAP_COCOA bindings in /// NativeKeyToDOMKeyName.h. -fn code_to_key(code: Code) -> Option { +fn code_to_key(code: Code) -> Option { Some(match code { - Code::Escape => KbKey::Escape, - Code::ShiftLeft | Code::ShiftRight => KbKey::Shift, - Code::AltLeft | Code::AltRight => KbKey::Alt, - Code::MetaLeft | Code::MetaRight => KbKey::Meta, - Code::ControlLeft | Code::ControlRight => KbKey::Control, - Code::CapsLock => KbKey::CapsLock, + Code::Escape => Key::Escape, + Code::ShiftLeft | Code::ShiftRight => Key::Shift, + Code::AltLeft | Code::AltRight => Key::Alt, + Code::MetaLeft | Code::MetaRight => Key::Meta, + Code::ControlLeft | Code::ControlRight => Key::Control, + Code::CapsLock => Key::CapsLock, // kVK_ANSI_KeypadClear - Code::NumLock => KbKey::Clear, - Code::Fn => KbKey::Fn, - Code::F1 => KbKey::F1, - Code::F2 => KbKey::F2, - Code::F3 => KbKey::F3, - Code::F4 => KbKey::F4, - Code::F5 => KbKey::F5, - Code::F6 => KbKey::F6, - Code::F7 => KbKey::F7, - Code::F8 => KbKey::F8, - Code::F9 => KbKey::F9, - Code::F10 => KbKey::F10, - Code::F11 => KbKey::F11, - Code::F12 => KbKey::F12, - Code::Pause => KbKey::Pause, - Code::ScrollLock => KbKey::ScrollLock, - Code::PrintScreen => KbKey::PrintScreen, - Code::Insert => KbKey::Insert, - Code::Delete => KbKey::Delete, - Code::Tab => KbKey::Tab, - Code::Backspace => KbKey::Backspace, - Code::ContextMenu => KbKey::ContextMenu, + Code::NumLock => Key::Clear, + Code::Fn => Key::Fn, + Code::F1 => Key::F1, + Code::F2 => Key::F2, + Code::F3 => Key::F3, + Code::F4 => Key::F4, + Code::F5 => Key::F5, + Code::F6 => Key::F6, + Code::F7 => Key::F7, + Code::F8 => Key::F8, + Code::F9 => Key::F9, + Code::F10 => Key::F10, + Code::F11 => Key::F11, + Code::F12 => Key::F12, + Code::Pause => Key::Pause, + Code::ScrollLock => Key::ScrollLock, + Code::PrintScreen => Key::PrintScreen, + Code::Insert => Key::Insert, + Code::Delete => Key::Delete, + Code::Tab => Key::Tab, + Code::Backspace => Key::Backspace, + Code::ContextMenu => Key::ContextMenu, // kVK_JIS_Kana - Code::Lang1 => KbKey::KanjiMode, + Code::Lang1 => Key::KanjiMode, // kVK_JIS_Eisu - Code::Lang2 => KbKey::Eisu, - Code::Home => KbKey::Home, - Code::End => KbKey::End, - Code::PageUp => KbKey::PageUp, - Code::PageDown => KbKey::PageDown, - Code::ArrowLeft => KbKey::ArrowLeft, - Code::ArrowRight => KbKey::ArrowRight, - Code::ArrowUp => KbKey::ArrowUp, - Code::ArrowDown => KbKey::ArrowDown, - Code::Enter => KbKey::Enter, - Code::NumpadEnter => KbKey::Enter, - Code::Help => KbKey::Help, + Code::Lang2 => Key::Eisu, + Code::Home => Key::Home, + Code::End => Key::End, + Code::PageUp => Key::PageUp, + Code::PageDown => Key::PageDown, + Code::ArrowLeft => Key::ArrowLeft, + Code::ArrowRight => Key::ArrowRight, + Code::ArrowUp => Key::ArrowUp, + Code::ArrowDown => Key::ArrowDown, + Code::Enter => Key::Enter, + Code::NumpadEnter => Key::Enter, + Code::Help => Key::Help, _ => return None, }) } @@ -277,14 +277,14 @@ impl KeyboardState { KeyboardState { last_mods } } - pub(crate) fn process_native_event(&mut self, event: id) -> Option { + pub(crate) fn process_native_event(&mut self, event: id) -> Option { unsafe { let event_type = event.eventType(); let key_code = event.keyCode(); let code = key_code_to_code(key_code); let location = code_to_location(code); let raw_mods = event.modifierFlags(); - let mods = make_modifiers(raw_mods); + let modifiers = make_modifiers(raw_mods); let state = match event_type { NSEventType::NSKeyDown => KeyState::Down, NSEventType::NSKeyUp => KeyState::Up, @@ -318,22 +318,22 @@ impl KeyboardState { } else { let characters = from_nsstring(event.characters()); if is_valid_key(&characters) { - KbKey::Character(characters) + Key::Character(characters) } else { let chars_ignoring = from_nsstring(event.charactersIgnoringModifiers()); if is_valid_key(&chars_ignoring) { - KbKey::Character(chars_ignoring) + Key::Character(chars_ignoring) } else { // There may be more heroic things we can do here. - KbKey::Unidentified + Key::Unidentified } } }; - let event = KeyEvent { + let event = KeyboardEvent { code, key, location, - mods, + modifiers, state, is_composing, repeat, diff --git a/src/macos/window.rs b/src/macos/window.rs index 39dae1f..5e228f5 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -11,13 +11,14 @@ use cocoa::appkit::{ }; use cocoa::base::{id, nil, NO}; use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString}; +use keyboard_types::KeyboardEvent; use objc::{msg_send, runtime::Object, sel, sel_impl}; use raw_window_handle::{macos::MacOSHandle, HasRawWindowHandle, RawWindowHandle}; use crate::{ - Event, keyboard::KeyEvent, Parent, WindowHandler, WindowOpenOptions, + Event, Parent, WindowHandler, WindowOpenOptions, WindowScalePolicy, WindowInfo }; @@ -202,7 +203,7 @@ impl WindowState { pub(super) fn process_native_key_event( &mut self, event: *mut Object - ) -> Option { + ) -> Option { self.keyboard_state.process_native_event(event) } } diff --git a/src/x11/keyboard.rs b/src/x11/keyboard.rs index cf55b28..8568a01 100644 --- a/src/x11/keyboard.rs +++ b/src/x11/keyboard.rs @@ -20,27 +20,29 @@ use xcb::xproto; -use crate::keyboard::*; +use keyboard_types::*; + +use crate::keyboard::code_to_location; /// Convert a hardware scan code to a key. /// /// Note: this is a hardcoded layout. We need to detect the user's /// layout from the system and apply it. -fn code_to_key(code: Code, m: Modifiers) -> KbKey { - fn a(s: &str) -> KbKey { - KbKey::Character(s.into()) +fn code_to_key(code: Code, m: Modifiers) -> Key { + fn a(s: &str) -> Key { + Key::Character(s.into()) } - fn s(mods: Modifiers, base: &str, shifted: &str) -> KbKey { - if mods.shift() { - KbKey::Character(shifted.into()) + fn s(mods: Modifiers, base: &str, shifted: &str) -> Key { + if mods.contains(Modifiers::SHIFT) { + Key::Character(shifted.into()) } else { - KbKey::Character(base.into()) + Key::Character(base.into()) } } - fn n(mods: Modifiers, base: KbKey, num: &str) -> KbKey { - if mods.contains(Modifiers::NUM_LOCK) != mods.shift() { - KbKey::Character(num.into()) + fn n(mods: Modifiers, base: Key, num: &str) -> Key { + if mods.contains(Modifiers::NUM_LOCK) != mods.contains(Modifiers::SHIFT) { + Key::Character(num.into()) } else { base } @@ -98,105 +100,105 @@ fn code_to_key(code: Code, m: Modifiers) -> KbKey { Code::Space => a(" "), - Code::Escape => KbKey::Escape, - Code::Backspace => KbKey::Backspace, - Code::Tab => KbKey::Tab, - Code::Enter => KbKey::Enter, - Code::ControlLeft => KbKey::Control, - Code::ShiftLeft => KbKey::Shift, - Code::ShiftRight => KbKey::Shift, + Code::Escape => Key::Escape, + Code::Backspace => Key::Backspace, + Code::Tab => Key::Tab, + Code::Enter => Key::Enter, + Code::ControlLeft => Key::Control, + Code::ShiftLeft => Key::Shift, + Code::ShiftRight => Key::Shift, Code::NumpadMultiply => a("*"), - Code::AltLeft => KbKey::Alt, - Code::CapsLock => KbKey::CapsLock, - Code::F1 => KbKey::F1, - Code::F2 => KbKey::F2, - Code::F3 => KbKey::F3, - Code::F4 => KbKey::F4, - Code::F5 => KbKey::F5, - Code::F6 => KbKey::F6, - Code::F7 => KbKey::F7, - Code::F8 => KbKey::F8, - Code::F9 => KbKey::F9, - Code::F10 => KbKey::F10, - Code::NumLock => KbKey::NumLock, - Code::ScrollLock => KbKey::ScrollLock, - Code::Numpad0 => n(m, KbKey::Insert, "0"), - Code::Numpad1 => n(m, KbKey::End, "1"), - Code::Numpad2 => n(m, KbKey::ArrowDown, "2"), - Code::Numpad3 => n(m, KbKey::PageDown, "3"), - Code::Numpad4 => n(m, KbKey::ArrowLeft, "4"), - Code::Numpad5 => n(m, KbKey::Clear, "5"), - Code::Numpad6 => n(m, KbKey::ArrowRight, "6"), - Code::Numpad7 => n(m, KbKey::Home, "7"), - Code::Numpad8 => n(m, KbKey::ArrowUp, "8"), - Code::Numpad9 => n(m, KbKey::PageUp, "9"), + Code::AltLeft => Key::Alt, + Code::CapsLock => Key::CapsLock, + Code::F1 => Key::F1, + Code::F2 => Key::F2, + Code::F3 => Key::F3, + Code::F4 => Key::F4, + Code::F5 => Key::F5, + Code::F6 => Key::F6, + Code::F7 => Key::F7, + Code::F8 => Key::F8, + Code::F9 => Key::F9, + Code::F10 => Key::F10, + Code::NumLock => Key::NumLock, + Code::ScrollLock => Key::ScrollLock, + Code::Numpad0 => n(m, Key::Insert, "0"), + Code::Numpad1 => n(m, Key::End, "1"), + Code::Numpad2 => n(m, Key::ArrowDown, "2"), + Code::Numpad3 => n(m, Key::PageDown, "3"), + Code::Numpad4 => n(m, Key::ArrowLeft, "4"), + Code::Numpad5 => n(m, Key::Clear, "5"), + Code::Numpad6 => n(m, Key::ArrowRight, "6"), + Code::Numpad7 => n(m, Key::Home, "7"), + Code::Numpad8 => n(m, Key::ArrowUp, "8"), + Code::Numpad9 => n(m, Key::PageUp, "9"), Code::NumpadSubtract => a("-"), Code::NumpadAdd => a("+"), - Code::NumpadDecimal => n(m, KbKey::Delete, "."), + Code::NumpadDecimal => n(m, Key::Delete, "."), Code::IntlBackslash => s(m, "\\", "|"), - Code::F11 => KbKey::F11, - Code::F12 => KbKey::F12, + Code::F11 => Key::F11, + Code::F12 => Key::F12, // This mapping is based on the picture in the w3c spec. Code::IntlRo => a("\\"), - Code::Convert => KbKey::Convert, - Code::KanaMode => KbKey::KanaMode, - Code::NonConvert => KbKey::NonConvert, - Code::NumpadEnter => KbKey::Enter, - Code::ControlRight => KbKey::Control, + Code::Convert => Key::Convert, + Code::KanaMode => Key::KanaMode, + Code::NonConvert => Key::NonConvert, + Code::NumpadEnter => Key::Enter, + Code::ControlRight => Key::Control, Code::NumpadDivide => a("/"), - Code::PrintScreen => KbKey::PrintScreen, - Code::AltRight => KbKey::Alt, - Code::Home => KbKey::Home, - Code::ArrowUp => KbKey::ArrowUp, - Code::PageUp => KbKey::PageUp, - Code::ArrowLeft => KbKey::ArrowLeft, - Code::ArrowRight => KbKey::ArrowRight, - Code::End => KbKey::End, - Code::ArrowDown => KbKey::ArrowDown, - Code::PageDown => KbKey::PageDown, - Code::Insert => KbKey::Insert, - Code::Delete => KbKey::Delete, - Code::AudioVolumeMute => KbKey::AudioVolumeMute, - Code::AudioVolumeDown => KbKey::AudioVolumeDown, - Code::AudioVolumeUp => KbKey::AudioVolumeUp, + Code::PrintScreen => Key::PrintScreen, + Code::AltRight => Key::Alt, + Code::Home => Key::Home, + Code::ArrowUp => Key::ArrowUp, + Code::PageUp => Key::PageUp, + Code::ArrowLeft => Key::ArrowLeft, + Code::ArrowRight => Key::ArrowRight, + Code::End => Key::End, + Code::ArrowDown => Key::ArrowDown, + Code::PageDown => Key::PageDown, + Code::Insert => Key::Insert, + Code::Delete => Key::Delete, + Code::AudioVolumeMute => Key::AudioVolumeMute, + Code::AudioVolumeDown => Key::AudioVolumeDown, + Code::AudioVolumeUp => Key::AudioVolumeUp, Code::NumpadEqual => a("="), - Code::Pause => KbKey::Pause, + Code::Pause => Key::Pause, Code::NumpadComma => a(","), - Code::Lang1 => KbKey::HangulMode, - Code::Lang2 => KbKey::HanjaMode, + Code::Lang1 => Key::HangulMode, + Code::Lang2 => Key::HanjaMode, Code::IntlYen => a("¥"), - Code::MetaLeft => KbKey::Meta, - Code::MetaRight => KbKey::Meta, - Code::ContextMenu => KbKey::ContextMenu, - Code::BrowserStop => KbKey::BrowserStop, - Code::Again => KbKey::Again, - Code::Props => KbKey::Props, - Code::Undo => KbKey::Undo, - Code::Select => KbKey::Select, - Code::Copy => KbKey::Copy, - Code::Open => KbKey::Open, - Code::Paste => KbKey::Paste, - Code::Find => KbKey::Find, - Code::Cut => KbKey::Cut, - Code::Help => KbKey::Help, - Code::LaunchApp2 => KbKey::LaunchApplication2, - Code::WakeUp => KbKey::WakeUp, - Code::LaunchApp1 => KbKey::LaunchApplication1, - Code::LaunchMail => KbKey::LaunchMail, - Code::BrowserFavorites => KbKey::BrowserFavorites, - Code::BrowserBack => KbKey::BrowserBack, - Code::BrowserForward => KbKey::BrowserForward, - Code::Eject => KbKey::Eject, - Code::MediaTrackNext => KbKey::MediaTrackNext, - Code::MediaPlayPause => KbKey::MediaPlayPause, - Code::MediaTrackPrevious => KbKey::MediaTrackPrevious, - Code::MediaStop => KbKey::MediaStop, - Code::MediaSelect => KbKey::LaunchMediaPlayer, - Code::BrowserHome => KbKey::BrowserHome, - Code::BrowserRefresh => KbKey::BrowserRefresh, - Code::BrowserSearch => KbKey::BrowserSearch, + Code::MetaLeft => Key::Meta, + Code::MetaRight => Key::Meta, + Code::ContextMenu => Key::ContextMenu, + Code::BrowserStop => Key::BrowserStop, + Code::Again => Key::Again, + Code::Props => Key::Props, + Code::Undo => Key::Undo, + Code::Select => Key::Select, + Code::Copy => Key::Copy, + Code::Open => Key::Open, + Code::Paste => Key::Paste, + Code::Find => Key::Find, + Code::Cut => Key::Cut, + Code::Help => Key::Help, + Code::LaunchApp2 => Key::LaunchApplication2, + Code::WakeUp => Key::WakeUp, + Code::LaunchApp1 => Key::LaunchApplication1, + Code::LaunchMail => Key::LaunchMail, + Code::BrowserFavorites => Key::BrowserFavorites, + Code::BrowserBack => Key::BrowserBack, + Code::BrowserForward => Key::BrowserForward, + Code::Eject => Key::Eject, + Code::MediaTrackNext => Key::MediaTrackNext, + Code::MediaPlayPause => Key::MediaPlayPause, + Code::MediaTrackPrevious => Key::MediaTrackPrevious, + Code::MediaStop => Key::MediaStop, + Code::MediaSelect => Key::LaunchMediaPlayer, + Code::BrowserHome => Key::BrowserHome, + Code::BrowserRefresh => Key::BrowserRefresh, + Code::BrowserSearch => Key::BrowserSearch, - _ => KbKey::Unidentified, + _ => Key::Unidentified, } } @@ -386,18 +388,18 @@ fn key_mods(mods: u16) -> Modifiers { pub(super) fn convert_key_press_event( key_press: &xcb::KeyPressEvent, -) -> KeyEvent { +) -> KeyboardEvent { let hw_keycode = key_press.detail(); let code = hardware_keycode_to_code(hw_keycode.into()); - let mods = key_mods(key_press.state()); - let key = code_to_key(code, mods); + let modifiers = key_mods(key_press.state()); + let key = code_to_key(code, modifiers); let location = code_to_location(code); let state = KeyState::Down; - KeyEvent { + KeyboardEvent { code, key, - mods, + modifiers, location, state, repeat: false, @@ -408,18 +410,18 @@ pub(super) fn convert_key_press_event( pub(super) fn convert_key_release_event( key_release: &xcb::KeyReleaseEvent -) -> KeyEvent { +) -> KeyboardEvent { let hw_keycode = key_release.detail(); let code = hardware_keycode_to_code(hw_keycode.into()); - let mods = key_mods(key_release.state()); - let key = code_to_key(code, mods); + let modifiers = key_mods(key_release.state()); + let key = code_to_key(code, modifiers); let location = code_to_location(code); let state = KeyState::Up; - KeyEvent { + KeyboardEvent { code, key, - mods, + modifiers, location, state, repeat: false,