mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 05:21:31 +11:00
X11: Implement resize increments and base size (#494)
This commit is contained in:
parent
c4b92ebd45
commit
cc8907b956
|
@ -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)
|
||||
|
||||
|
|
|
@ -199,6 +199,11 @@ impl WindowExt for Window {
|
|||
pub trait WindowBuilderExt {
|
||||
fn with_x11_visual<T>(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.
|
||||
|
|
|
@ -32,6 +32,8 @@ const BACKEND_PREFERENCE_ENV_VAR: &str = "WINIT_UNIX_BACKEND";
|
|||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub visual_infos: Option<XVisualInfo>,
|
||||
pub screen_id: Option<i32>,
|
||||
pub resize_increments: Option<(i32, i32)>,
|
||||
pub base_size: Option<(i32, i32)>,
|
||||
}
|
||||
|
||||
lazy_static!(
|
||||
|
|
|
@ -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)(
|
||||
|
|
Loading…
Reference in a new issue