From d4584a10b6e7dd55e218ba7fba3484419ee46ab5 Mon Sep 17 00:00:00 2001 From: Julia <30666851+ForLoveOfCats@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:13:01 -0500 Subject: [PATCH] Tell Wayland compositor we can handle keyboard ver 4 for repeat info (#8446) Fixes us not getting Wayland key repeat info from the compositor Release Notes: - N/A --- crates/gpui/src/platform/linux/platform.rs | 6 ++-- .../gpui/src/platform/linux/wayland/client.rs | 30 +++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index 518c2edfb3..9657f015c8 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -227,7 +227,8 @@ impl Platform for LinuxPlatform { options: PathPromptOptions, ) -> oneshot::Receiver>> { let (done_tx, done_rx) = oneshot::channel(); - self.foreground_executor() + self.inner + .foreground_executor .spawn(async move { let title = if options.multiple { if !options.files { @@ -270,7 +271,8 @@ impl Platform for LinuxPlatform { fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver> { let (done_tx, done_rx) = oneshot::channel(); let directory = directory.to_owned(); - self.foreground_executor() + self.inner + .foreground_executor .spawn(async move { let result = SaveFileRequest::default() .modal(true) diff --git a/crates/gpui/src/platform/linux/wayland/client.rs b/crates/gpui/src/platform/linux/wayland/client.rs index f415024c32..aa6df7ffe4 100644 --- a/crates/gpui/src/platform/linux/wayland/client.rs +++ b/crates/gpui/src/platform/linux/wayland/client.rs @@ -65,8 +65,8 @@ pub(crate) struct WaylandClientStateInner { pub(crate) struct WaylandClientState(Rc>); pub(crate) struct KeyRepeat { - rate: i32, - delay: i32, + characters_per_second: u32, + delay: Duration, current_id: u64, current_keysym: Option, } @@ -93,8 +93,8 @@ impl WaylandClient { wl_seat: None, keymap_state: None, repeat: KeyRepeat { - rate: 16, - delay: 500, + characters_per_second: 16, + delay: Duration::from_millis(500), current_id: 0, current_keysym: None, }, @@ -242,7 +242,7 @@ impl Dispatch for WaylandClientState { state.wm_base = Some(wm_base); } "wl_seat" => { - let seat = registry.bind::(name, 1, qh, ()); + let seat = registry.bind::(name, 4, qh, ()); state.wl_seat = Some(seat); } "wp_fractional_scale_manager_v1" => { @@ -412,18 +412,18 @@ impl Dispatch for WaylandClientState { impl Dispatch for WaylandClientState { fn event( - state_container: &mut Self, + this: &mut Self, keyboard: &wl_keyboard::WlKeyboard, event: wl_keyboard::Event, data: &(), conn: &Connection, qh: &QueueHandle, ) { - let mut state = state_container.0.borrow_mut(); + let mut state = this.0.borrow_mut(); match event { wl_keyboard::Event::RepeatInfo { rate, delay } => { - state.repeat.rate = rate; - state.repeat.delay = delay; + state.repeat.characters_per_second = rate as u32; + state.repeat.delay = Duration::from_millis(delay as u64); } wl_keyboard::Event::Keymap { format: WEnum::Value(format), @@ -524,25 +524,25 @@ impl Dispatch for WaylandClientState { state.repeat.current_id += 1; state.repeat.current_keysym = Some(keysym); - let rate = state.repeat.rate; + let rate = state.repeat.characters_per_second; let delay = state.repeat.delay; let id = state.repeat.current_id; - let keysym = state.repeat.current_keysym; - let state_container = state_container.clone(); + let this = this.clone(); state .platform_inner .foreground_executor .spawn(async move { - let mut wait_time = Duration::from_millis(delay as u64); + let mut wait_time = delay; loop { Timer::after(wait_time).await; - let state = state_container.0.borrow_mut(); + let state = this.0.borrow_mut(); let is_repeating = id == state.repeat.current_id && state.repeat.current_keysym.is_some() && state.keyboard_focused_window.is_some(); + if !is_repeating { return; } @@ -553,7 +553,7 @@ impl Dispatch for WaylandClientState { .unwrap() .handle_input(input.clone()); - wait_time = Duration::from_millis(1000 / rate as u64); + wait_time = Duration::from_secs(1) / rate; } }) .detach();