diff --git a/CHANGELOG.md b/CHANGELOG.md index 822192e9..66fdd75b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Various safety and correctness improvements to the X11 backend internals. - Fixed memory leak on X11 every time the mouse entered the window. - On X11, drag and drop now works reliably in release mode. +- Added `WindowBuilderExt::with_resize_increments` and `WindowBuilderExt::with_base_size` to X11, allowing for more optional hints to be set. # Version 0.13.1 (2018-04-26) diff --git a/src/os/unix.rs b/src/os/unix.rs index b68b3ff8..1d8814cb 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -199,6 +199,11 @@ impl WindowExt for Window { pub trait WindowBuilderExt { fn with_x11_visual(self, visual_infos: *const T) -> WindowBuilder; fn with_x11_screen(self, screen_id: i32) -> WindowBuilder; + + /// Build window with resize increment hint. Only implemented on X11. + fn with_resize_increments(self, width_inc: i32, height_inc: i32) -> WindowBuilder; + /// Build window with base size hint. Only implemented on X11. + fn with_base_size(self, base_width: i32, base_height: i32) -> WindowBuilder; } impl WindowBuilderExt for WindowBuilder { @@ -215,6 +220,18 @@ impl WindowBuilderExt for WindowBuilder { self.platform_specific.screen_id = Some(screen_id); self } + + #[inline] + fn with_resize_increments(mut self, width_inc: i32, height_inc: i32) -> WindowBuilder { + self.platform_specific.resize_increments = Some((width_inc, height_inc)); + self + } + + #[inline] + fn with_base_size(mut self, base_width: i32, base_height: i32) -> WindowBuilder { + self.platform_specific.base_size = Some((base_width, base_height)); + self + } } /// Additional methods on `MonitorId` that are specific to Linux. diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 6446f591..24e9e887 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -32,6 +32,8 @@ const BACKEND_PREFERENCE_ENV_VAR: &str = "WINIT_UNIX_BACKEND"; pub struct PlatformSpecificWindowBuilderAttributes { pub visual_infos: Option, pub screen_id: Option, + pub resize_increments: Option<(i32, i32)>, + pub base_size: Option<(i32, i32)>, } lazy_static!( diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index 00d387ca..5f83b90e 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -212,15 +212,25 @@ impl Window2 { (*size_hints).flags = ffi::PSize; (*size_hints).width = dimensions.0 as c_int; (*size_hints).height = dimensions.1 as c_int; - if let Some(dimensions) = window_attrs.min_dimensions { + if let Some((min_width, min_height)) = window_attrs.min_dimensions { (*size_hints).flags |= ffi::PMinSize; - (*size_hints).min_width = dimensions.0 as c_int; - (*size_hints).min_height = dimensions.1 as c_int; + (*size_hints).min_width = min_width as c_int; + (*size_hints).min_height = min_height as c_int; } - if let Some(dimensions) = window_attrs.max_dimensions { + if let Some((max_width, max_height)) = window_attrs.max_dimensions { (*size_hints).flags |= ffi::PMaxSize; - (*size_hints).max_width = dimensions.0 as c_int; - (*size_hints).max_height = dimensions.1 as c_int; + (*size_hints).max_width = max_width as c_int; + (*size_hints).max_height = max_height as c_int; + } + if let Some((width_inc, height_inc)) = pl_attribs.resize_increments { + (*size_hints).flags |= ffi::PResizeInc; + (*size_hints).width_inc = width_inc as c_int; + (*size_hints).height_inc = height_inc as c_int; + } + if let Some((base_width, base_height)) = pl_attribs.base_size { + (*size_hints).flags |= ffi::PBaseSize; + (*size_hints).base_width = base_width as c_int; + (*size_hints).base_height = base_height as c_int; } unsafe { (xconn.xlib.XSetWMNormalHints)(