From 88653c4e3ea81d0dd13fabd5d5a378d577adae1c Mon Sep 17 00:00:00 2001 From: apricotbucket28 <71973804+apricotbucket28@users.noreply.github.com> Date: Fri, 26 Jul 2024 22:02:31 -0300 Subject: [PATCH] linux: Respect `window_min_size` property (#15314) https://github.com/zed-industries/zed/pull/13126 added the `window_min_size` property for window creation, but it was only implemented for macOS. This PR implements the property on Linux as well. Release Notes: - N/A --- crates/gpui/src/platform.rs | 1 - crates/gpui/src/platform/linux/wayland/window.rs | 5 ++++- crates/gpui/src/platform/linux/x11/window.rs | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 45de306ad2..7bd1b29443 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -706,7 +706,6 @@ pub(crate) struct WindowParams { pub display_id: Option, - #[cfg_attr(target_os = "linux", allow(dead_code))] pub window_min_size: Option>, } diff --git a/crates/gpui/src/platform/linux/wayland/window.rs b/crates/gpui/src/platform/linux/wayland/window.rs index 9ec5e9e2c0..2efbd1a2ec 100644 --- a/crates/gpui/src/platform/linux/wayland/window.rs +++ b/crates/gpui/src/platform/linux/wayland/window.rs @@ -264,7 +264,10 @@ impl WaylandWindow { .wm_base .get_xdg_surface(&surface, &globals.qh, surface.id()); let toplevel = xdg_surface.get_toplevel(&globals.qh, surface.id()); - toplevel.set_min_size(50, 50); + + if let Some(size) = params.window_min_size { + toplevel.set_min_size(size.width.0 as i32, size.height.0 as i32); + } if let Some(fractional_scale_manager) = globals.fractional_scale_manager.as_ref() { fractional_scale_manager.get_fractional_scale(&surface, &globals.qh, surface.id()); diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rs index 9e4908627e..b6c775db4e 100644 --- a/crates/gpui/src/platform/linux/x11/window.rs +++ b/crates/gpui/src/platform/linux/x11/window.rs @@ -14,6 +14,7 @@ use raw_window_handle as rwh; use util::{maybe, ResultExt}; use x11rb::{ connection::Connection, + properties::WmSizeHints, protocol::{ sync, xinput::{self, ConnectionExt as _}, @@ -371,6 +372,14 @@ impl X11WindowState { visual.depth, x_window, visual_set.root, bounds.origin.x.0 + 2, bounds.origin.y.0, bounds.size.width.0, bounds.size.height.0) })?; + if let Some(size) = params.window_min_size { + let mut size_hints = WmSizeHints::new(); + size_hints.min_size = Some((size.width.0 as i32, size.height.0 as i32)); + size_hints + .set_normal_hints(xcb_connection, x_window) + .unwrap(); + } + let reply = xcb_connection .get_geometry(x_window) .unwrap()