From fee874b5b76d457d3cca09dc1646f8e8f2c3c5f8 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Wed, 2 May 2018 23:18:52 +0000 Subject: [PATCH] Add Copy/Paste keys (#495) * Add Copy/Paste keys This is only a tiny update which introduces the `Copy` and `Paste` keys which are present on X11/Wayland/Windows. I'm not sure if this exists on MacOS too, but I'm not able to test that and it doesn't have names but just matches on the hex key values. The "Copy" element is a reserved keyword in Rust but shouldn't cause any conflicts in this scenario, this behavior falls in line with https://docs.rs/winit/0.13.1/winit/enum.MouseCursor.html#variant.Copy, but it would be possible to rename it. However `Copy` seems like the most intuitive choice. * Add Cut key, fix windows and update CHANGELOG This introduces a bunch of minor fixes: * The changes introduced by this branch have been added to the changelog * Since related, the `Cut` key has also been added * An attempt has been made to fix Windows * Fix position of fallback comment The new keys have been inserted at the wrong position, so the fallback comment has been moved to the `_ => ...` section again. * Fix windows build Apparently there are no keys for Cut/Paste on Windows, so for now those have been removed on Windows and only the `Copy` key has been added on Windows, the changelog has been updated to reflect that. Linux still implements Copy/Clone/Paste, but `Copy` is now working properly on Wayland. MacOS still does not have any of these keys. * Remove Windows changes Because the Windows design wasn't completely clear the VirtualKeyCode variants are now only used on Linux with X11 and Wayland and ignored on both MacOS and Windows. The CHANGELOG has also been updated. Windows has been removed from it and the Linux section has been clarified a bit. --- CHANGELOG.md | 1 + src/events.rs | 3 +++ src/platform/linux/wayland/keyboard.rs | 3 +++ src/platform/linux/x11/events.rs | 3 +++ 4 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bc0117e..b2fdb93e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- Created the `Copy`, `Paste` and `Cut` `VirtualKeyCode`s and added support for them on X11 and Wayland - Fix `.with_decorations(false)` in macOS - On Mac, `NSWindow` and supporting objects might be alive long after they were `closed` which resulted in apps consuming more heap then needed. Mainly it was affecting multi window applications. Not expecting any user visible change of behaviour after the fix. - Fix regression of Window platform extensions for macOS where `NSFullSizeContentViewWindowMask` was not being correctly applied to `.fullsize_content_view`. diff --git a/src/events.rs b/src/events.rs index 2dcc3ead..ec034d2e 100644 --- a/src/events.rs +++ b/src/events.rs @@ -431,6 +431,9 @@ pub enum VirtualKeyCode { WebSearch, WebStop, Yen, + Copy, + Paste, + Cut, } /// Represents the current state of the keyboard modifiers diff --git a/src/platform/linux/wayland/keyboard.rs b/src/platform/linux/wayland/keyboard.rs index ce670a42..45fc3802 100644 --- a/src/platform/linux/wayland/keyboard.rs +++ b/src/platform/linux/wayland/keyboard.rs @@ -290,6 +290,9 @@ fn keysym_to_vkey(keysym: u32) -> Option { // => Some(VirtualKeyCode::WebSearch), // => Some(VirtualKeyCode::WebStop), // => Some(VirtualKeyCode::Yen), + keysyms::XKB_KEY_XF86Copy => Some(VirtualKeyCode::Copy), + keysyms::XKB_KEY_XF86Paste => Some(VirtualKeyCode::Paste), + keysyms::XKB_KEY_XF86Cut => Some(VirtualKeyCode::Cut), // fallback _ => None } diff --git a/src/platform/linux/x11/events.rs b/src/platform/linux/x11/events.rs index 77543652..e76fb777 100644 --- a/src/platform/linux/x11/events.rs +++ b/src/platform/linux/x11/events.rs @@ -1000,6 +1000,9 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option { //ffi::XK_Hebrew_switch => events::VirtualKeyCode::Hebrew_switch, ffi::XF86XK_Back => VirtualKeyCode::NavigateBackward, ffi::XF86XK_Forward => VirtualKeyCode::NavigateForward, + ffi::XF86XK_Copy => VirtualKeyCode::Copy, + ffi::XF86XK_Paste => VirtualKeyCode::Paste, + ffi::XF86XK_Cut => VirtualKeyCode::Cut, _ => return None }) }