Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify behavior of resizable across platforms #2252

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ And please only add new entries to the top of this list, right below the `# Unre
sent a cancel or frame event.
- On iOS, send `RedrawEventsCleared` even if there are no redraw events, consistent with other platforms.
- **Breaking:** Replaced `Window::with_app_id` and `Window::with_class` with `Window::with_name` on `WindowBuilderExtUnix`.
- On Wayland and X11, fix window not resizing with `Window::set_inner_size` after calling `Window:set_resizable(false)`.

# 0.26.1 (2022-01-05)

Expand Down
3 changes: 3 additions & 0 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ impl Window {
window_requests.clone(),
);

// Set resizable state, so we can determine how to handle `Window::set_inner_size`.
window_handle.is_resizable.set(attributes.resizable);

let mut winit_state = event_loop_window_target.state.borrow_mut();

winit_state.window_map.insert(window_id, window_handle);
Expand Down
13 changes: 12 additions & 1 deletion src/platform_impl/linux/wayland/window/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ pub struct WindowHandle {
/// Current cursor icon.
pub cursor_icon: Cell<CursorIcon>,

/// Whether the window is resizable.
pub is_resizable: Cell<bool>,

/// Visible cursor or not.
cursor_visible: Cell<bool>,

Expand Down Expand Up @@ -193,6 +196,7 @@ impl WindowHandle {
size,
pending_window_requests,
cursor_icon: Cell::new(CursorIcon::Default),
is_resizable: Cell::new(true),
confined: Cell::new(false),
cursor_visible: Cell::new(true),
pointers: Vec::new(),
Expand Down Expand Up @@ -443,7 +447,14 @@ pub fn handle_window_requests(winit_state: &mut WinitState) {
window_update.redraw_requested = true;
}
WindowRequest::FrameSize(size) => {
// Set new size.
if !window_handle.is_resizable.get() {
// On Wayland non-resizable window is achieved by setting both min and max
// size of the window to the same value.
let size = Some((size.width, size.height));
window_handle.window.set_max_size(size);
window_handle.window.set_min_size(size);
}

window_handle.window.resize(size.width, size.height);

// We should refresh the frame after resize.
Expand Down
11 changes: 9 additions & 2 deletions src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,15 @@ impl UnownedWindow {
#[inline]
pub fn set_inner_size(&self, size: Size) {
let scale_factor = self.scale_factor();
let (width, height) = size.to_physical::<u32>(scale_factor).into();
self.set_inner_size_physical(width, height);
let size = size.to_physical::<u32>(scale_factor).into();
if !self.shared_state.lock().is_resizable {
self.update_normal_hints(|normal_hints| {
normal_hints.set_min_size(Some(size));
normal_hints.set_max_size(Some(size));
})
.expect("Failed to call `XSetWMNormalHints`");
}
self.set_inner_size_physical(size.0, size.1);
}

fn update_normal_hints<F>(&self, callback: F) -> Result<(), XError>
Expand Down
5 changes: 3 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,9 @@ impl Window {

/// Sets whether the window is resizable or not.
///
/// Note that making the window unresizable doesn't exempt you from handling `Resized`, as that event can still be
/// triggered by DPI scaling, entering fullscreen mode, etc.
/// Note that making the window unresizable doesn't exempt you from handling `Resized`, as that
/// event can still be triggered by DPI scaling, entering fullscreen mode, etc. Also, the
/// window could still be resized by calling `[Window::set_inner_size]`.
///
/// ## Platform-specific
///
Expand Down