Allow changing resize increments after window creation
This commit is contained in:
parent
97d2aaa953
commit
ab56e9f57d
15 changed files with 213 additions and 45 deletions
|
|
@ -757,6 +757,12 @@ impl Window {
|
|||
|
||||
pub fn set_max_inner_size(&self, _: Option<Size>) {}
|
||||
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn set_resize_increments(&self, _increments: Option<Size>) {}
|
||||
|
||||
pub fn set_title(&self, _title: &str) {}
|
||||
|
||||
pub fn set_visible(&self, _visibility: bool) {}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,15 @@ impl Inner {
|
|||
warn!("`Window::set_max_inner_size` is ignored on iOS")
|
||||
}
|
||||
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resize_increments(&self, _increments: Option<Size>) {
|
||||
warn!("`Window::set_resize_increments` is ignored on iOS")
|
||||
}
|
||||
|
||||
pub fn set_resizable(&self, _resizable: bool) {
|
||||
warn!("`Window::set_resizable` is ignored on iOS")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,8 +95,6 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
|||
#[cfg(feature = "x11")]
|
||||
pub screen_id: Option<i32>,
|
||||
#[cfg(feature = "x11")]
|
||||
pub resize_increments: Option<Size>,
|
||||
#[cfg(feature = "x11")]
|
||||
pub base_size: Option<Size>,
|
||||
#[cfg(feature = "x11")]
|
||||
pub override_redirect: bool,
|
||||
|
|
@ -117,8 +115,6 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
|||
#[cfg(feature = "x11")]
|
||||
screen_id: None,
|
||||
#[cfg(feature = "x11")]
|
||||
resize_increments: None,
|
||||
#[cfg(feature = "x11")]
|
||||
base_size: None,
|
||||
#[cfg(feature = "x11")]
|
||||
override_redirect: false,
|
||||
|
|
@ -391,6 +387,16 @@ impl Window {
|
|||
x11_or_wayland!(match self; Window(w) => w.set_max_inner_size(dimensions))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
x11_or_wayland!(match self; Window(w) => w.resize_increments())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resize_increments(&self, increments: Option<Size>) {
|
||||
x11_or_wayland!(match self; Window(w) => w.set_resize_increments(increments))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resizable(&self, resizable: bool) {
|
||||
x11_or_wayland!(match self; Window(w) => w.set_resizable(resizable))
|
||||
|
|
|
|||
|
|
@ -404,6 +404,16 @@ impl Window {
|
|||
self.send_request(WindowRequest::MaxSize(size));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resize_increments(&self, _increments: Option<Size>) {
|
||||
warn!("`set_resize_increments` is not implemented for Wayland");
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resizable(&self, resizable: bool) {
|
||||
self.resizeable.store(resizable, Ordering::Relaxed);
|
||||
|
|
|
|||
|
|
@ -197,11 +197,17 @@ impl<'a> NormalHints<'a> {
|
|||
}
|
||||
|
||||
pub fn get_position(&self) -> Option<(i32, i32)> {
|
||||
if has_flag(self.size_hints.flags, ffi::PPosition) {
|
||||
Some((self.size_hints.x as i32, self.size_hints.y as i32))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
has_flag(self.size_hints.flags, ffi::PPosition)
|
||||
.then(|| (self.size_hints.x as i32, self.size_hints.y as i32))
|
||||
}
|
||||
|
||||
pub fn get_resize_increments(&self) -> Option<(u32, u32)> {
|
||||
has_flag(self.size_hints.flags, ffi::PResizeInc).then(|| {
|
||||
(
|
||||
self.size_hints.width_inc as u32,
|
||||
self.size_hints.height_inc as u32,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_position(&mut self, position: Option<(i32, i32)>) {
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ impl UnownedWindow {
|
|||
let mut shared_state = window.shared_state.get_mut().unwrap();
|
||||
shared_state.min_inner_size = min_inner_size.map(Into::into);
|
||||
shared_state.max_inner_size = max_inner_size.map(Into::into);
|
||||
shared_state.resize_increments = pl_attribs.resize_increments;
|
||||
shared_state.resize_increments = window_attrs.resize_increments;
|
||||
shared_state.base_size = pl_attribs.base_size;
|
||||
|
||||
let mut normal_hints = util::NormalHints::new(xconn);
|
||||
|
|
@ -387,7 +387,7 @@ impl UnownedWindow {
|
|||
normal_hints.set_min_size(min_inner_size.map(Into::into));
|
||||
normal_hints.set_max_size(max_inner_size.map(Into::into));
|
||||
normal_hints.set_resize_increments(
|
||||
pl_attribs
|
||||
window_attrs
|
||||
.resize_increments
|
||||
.map(|size| size.to_physical::<u32>(scale_factor).into()),
|
||||
);
|
||||
|
|
@ -1172,6 +1172,24 @@ impl UnownedWindow {
|
|||
self.set_max_inner_size_physical(physical_dimensions);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
self.xconn
|
||||
.get_normal_hints(self.xwindow)
|
||||
.ok()
|
||||
.and_then(|hints| hints.get_resize_increments())
|
||||
.map(Into::into)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resize_increments(&self, increments: Option<Size>) {
|
||||
self.shared_state_lock().resize_increments = increments;
|
||||
let physical_increments =
|
||||
increments.map(|increments| increments.to_physical::<u32>(self.scale_factor()).into());
|
||||
self.update_normal_hints(|hints| hints.set_resize_increments(physical_increments))
|
||||
.expect("Failed to call `XSetWMNormalHints`");
|
||||
}
|
||||
|
||||
pub(crate) fn adjust_for_dpi(
|
||||
&self,
|
||||
old_scale_factor: f64,
|
||||
|
|
|
|||
|
|
@ -242,10 +242,14 @@ fn create_window(
|
|||
}
|
||||
|
||||
if let Some(increments) = pl_attrs.resize_increments {
|
||||
let (x, y) = (increments.width, increments.height);
|
||||
if x >= 1.0 && y >= 1.0 {
|
||||
let size = NSSize::new(x as CGFloat, y as CGFloat);
|
||||
ns_window.setResizeIncrements_(size);
|
||||
let (w, h) = (increments.width, increments.height);
|
||||
if w >= 1.0 && h >= 1.0 {
|
||||
let size = NSSize::new(w as CGFloat, h as CGFloat);
|
||||
// It was concluded (#2411) that there is never a use-case for
|
||||
// "outer" resize increments, hence we set "inner" ones here.
|
||||
// ("outer" in macOS being just resizeIncrements, and "inner" - contentResizeIncrements)
|
||||
// This is consistent with X11 size hints behavior
|
||||
ns_window.setContentResizeIncrements_(size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -590,6 +594,28 @@ impl UnownedWindow {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
let increments = unsafe { self.ns_window.contentResizeIncrements() };
|
||||
let (x, y) = (increments.width, increments.height);
|
||||
if x > 1.0 || y > 1.0 {
|
||||
Some(LogicalSize::new(x, y).to_physical(self.scale_factor()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_resize_increments(&self, increments: Option<Size>) {
|
||||
let size = increments
|
||||
.map(|increments| {
|
||||
let logical = increments.to_logical::<f64>(self.scale_factor());
|
||||
NSSize::new(logical.width.max(1.0), logical.height.max(1.0))
|
||||
})
|
||||
.unwrap_or_else(|| NSSize::new(1.0, 1.0));
|
||||
unsafe {
|
||||
self.ns_window.setContentResizeIncrements_(size);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resizable(&self, resizable: bool) {
|
||||
let fullscreen = {
|
||||
|
|
|
|||
|
|
@ -153,6 +153,16 @@ impl Window {
|
|||
// Intentionally a no-op: users can't resize canvas elements
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resize_increments(&self, _increments: Option<Size>) {
|
||||
// Intentionally a no-op: users can't resize canvas elements
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resizable(&self, _resizable: bool) {
|
||||
// Intentionally a no-op: users can't resize canvas elements
|
||||
|
|
|
|||
|
|
@ -235,6 +235,14 @@ impl Window {
|
|||
self.set_inner_size(size.into());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resize_increments(&self, _increments: Option<Size>) {}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resizable(&self, resizable: bool) {
|
||||
let window = self.window.clone();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue