From 11bc28080ff43b4c787eaa35868e3b1d6cf48355 Mon Sep 17 00:00:00 2001 From: apricotbucket28 <71973804+apricotbucket28@users.noreply.github.com> Date: Mon, 6 May 2024 17:23:49 -0300 Subject: [PATCH] linux: Fix some small issues (#11458) Fixed various small issues on Linux, mainly on Wayland. Apart from the first commit (which should be self-describing), the other commits have a description explaining the issue and what they do. caadc58bead6cb654d7e1da25faaba72be79cd27 should fix https://github.com/zed-industries/zed/issues/11037 Release Notes: - N/A --- crates/gpui/src/platform/linux/platform.rs | 8 +++----- .../gpui/src/platform/linux/wayland/client.rs | 19 +++++++++---------- .../gpui/src/platform/linux/wayland/window.rs | 17 +++++++++++------ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index bd519a098d..c1f6df1593 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -613,11 +613,9 @@ impl Keystroke { } }; - // Ignore control characters (and DEL) for the purposes of ime_key, - // but if key_utf32 is 0 then assume it isn't one - let ime_key = ((key_utf32 == 0 || (key_utf32 >= 32 && key_utf32 != 127)) - && !key_utf8.is_empty()) - .then_some(key_utf8); + // Ignore control characters (and DEL) for the purposes of ime_key + let ime_key = + (key_utf32 >= 32 && key_utf32 != 127 && !key_utf8.is_empty()).then_some(key_utf8); if handle_consumed_modifiers { let mod_shift_index = state.get_keymap().mod_get_index(xkb::MOD_NAME_SHIFT); diff --git a/crates/gpui/src/platform/linux/wayland/client.rs b/crates/gpui/src/platform/linux/wayland/client.rs index 7dfde29921..b5aed4e941 100644 --- a/crates/gpui/src/platform/linux/wayland/client.rs +++ b/crates/gpui/src/platform/linux/wayland/client.rs @@ -59,7 +59,7 @@ use crate::platform::linux::wayland::serial::{SerialKind, SerialTracker}; use crate::platform::linux::wayland::window::WaylandWindow; use crate::platform::linux::LinuxClient; use crate::platform::PlatformWindow; -use crate::{point, px, FileDropEvent, ForegroundExecutor, MouseExitEvent}; +use crate::{point, px, FileDropEvent, ForegroundExecutor, MouseExitEvent, SCROLL_LINES}; use crate::{ AnyWindowHandle, CursorStyle, DisplayId, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, @@ -204,7 +204,7 @@ impl WaylandClientStatePtr { } if let Some(window) = state.keyboard_focused_window.take() { if !window.ptr_eq(&closed_window) { - state.mouse_focused_window = Some(window); + state.keyboard_focused_window = Some(window); } } if state.windows.is_empty() { @@ -1098,7 +1098,9 @@ impl Dispatch for WaylandClientStatePtr { value, .. } => { - let axis_source = state.axis_source; + if state.axis_source == AxisSource::Wheel { + return; + } let axis_modifier = match axis { wl_pointer::Axis::VerticalScroll => state.vertical_modifier, wl_pointer::Axis::HorizontalScroll => state.horizontal_modifier, @@ -1133,16 +1135,13 @@ impl Dispatch for WaylandClientStatePtr { _ => 1.0, }; - // TODO: Make nice feeling kinetic scrolling that integrates with the platform's scroll settings - let modifier = 3.0; - let scroll_delta = state.discrete_scroll_delta.get_or_insert(point(0.0, 0.0)); match axis { wl_pointer::Axis::VerticalScroll => { - scroll_delta.y += discrete as f32 * axis_modifier * modifier; + scroll_delta.y += discrete as f32 * axis_modifier * SCROLL_LINES as f32; } wl_pointer::Axis::HorizontalScroll => { - scroll_delta.x += discrete as f32 * axis_modifier * modifier; + scroll_delta.x += discrete as f32 * axis_modifier * SCROLL_LINES as f32; } _ => unreachable!(), } @@ -1180,10 +1179,10 @@ impl Dispatch for WaylandClientStatePtr { let wheel_percent = value120 as f32 / 120.0; match axis { wl_pointer::Axis::VerticalScroll => { - scroll_delta.y += wheel_percent * axis_modifier; + scroll_delta.y += wheel_percent * axis_modifier * SCROLL_LINES as f32; } wl_pointer::Axis::HorizontalScroll => { - scroll_delta.x += wheel_percent * axis_modifier; + scroll_delta.x += wheel_percent * axis_modifier * SCROLL_LINES as f32; } _ => unreachable!(), } diff --git a/crates/gpui/src/platform/linux/wayland/window.rs b/crates/gpui/src/platform/linux/wayland/window.rs index 7848a9b284..8924a322b5 100644 --- a/crates/gpui/src/platform/linux/wayland/window.rs +++ b/crates/gpui/src/platform/linux/wayland/window.rs @@ -299,7 +299,7 @@ impl WaylandWindowStatePtr { self.set_decoration_state(WaylandDecorationState::Server) } WEnum::Value(zxdg_toplevel_decoration_v1::Mode::ClientSide) => { - self.set_decoration_state(WaylandDecorationState::Server) + self.set_decoration_state(WaylandDecorationState::Client) } WEnum::Value(_) => { log::warn!("Unknown decoration mode"); @@ -610,11 +610,11 @@ impl PlatformWindow for WaylandWindow { } fn set_title(&mut self, title: &str) { - self.borrow_mut().toplevel.set_title(title.to_string()); + self.borrow().toplevel.set_title(title.to_string()); } fn set_app_id(&mut self, app_id: &str) { - self.borrow_mut().toplevel.set_app_id(app_id.to_owned()); + self.borrow().toplevel.set_app_id(app_id.to_owned()); } fn set_background_appearance(&mut self, background_appearance: WindowBackgroundAppearance) { @@ -666,15 +666,20 @@ impl PlatformWindow for WaylandWindow { } fn minimize(&self) { - self.borrow_mut().toplevel.set_minimized(); + self.borrow().toplevel.set_minimized(); } fn zoom(&self) { - // todo(linux) + let state = self.borrow(); + if !state.maximized { + state.toplevel.set_maximized(); + } else { + state.toplevel.unset_maximized(); + } } fn toggle_fullscreen(&self) { - let state = self.borrow_mut(); + let state = self.borrow(); if !state.fullscreen { state.toplevel.set_fullscreen(None); } else {