Skip to content

Commit 78e5a39

Browse files
authored
On Wayland, fix resize not propagating properly
On Wayland window size and scaling are double buffered, so winit should send redraw requested for a client on the next frame as well.
1 parent 7846e6a commit 78e5a39

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ And please only add new entries to the top of this list, right below the `# Unre
2121
- **Breaking:** Replaced `EventLoopExtMacOS` with `EventLoopBuilderExtMacOS` (which also has renamed methods).
2222
- **Breaking:** Replaced `EventLoopExtWindows` with `EventLoopBuilderExtWindows` (which also has renamed methods).
2323
- **Breaking:** Replaced `EventLoopExtUnix` with `EventLoopBuilderExtUnix` (which also has renamed methods).
24+
- On Wayland, fix resize and scale factor changes not being propagated properly.
2425

2526
# 0.26.1 (2022-01-05)
2627

src/platform_impl/linux/wayland/event_loop/mod.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::platform_impl::EventLoopWindowTarget as PlatformEventLoopWindowTarget
2424
use super::env::{WindowingFeatures, WinitEnv};
2525
use super::output::OutputManager;
2626
use super::seat::SeatManager;
27-
use super::window::shim::{self, WindowUpdate};
27+
use super::window::shim::{self, WindowRequest, WindowUpdate};
2828
use super::{DeviceId, WindowId};
2929

3030
mod proxy;
@@ -249,7 +249,8 @@ impl<T: 'static> EventLoop<T> {
249249
}
250250

251251
// Process 'new' pending updates.
252-
self.with_state(|state| {
252+
self.with_window_target(|window_target| {
253+
let state = window_target.state.get_mut();
253254
window_updates.clear();
254255
window_updates.extend(
255256
state
@@ -261,7 +262,8 @@ impl<T: 'static> EventLoop<T> {
261262

262263
for (window_id, window_update) in window_updates.iter_mut() {
263264
if let Some(scale_factor) = window_update.scale_factor.map(|f| f as f64) {
264-
let mut physical_size = self.with_state(|state| {
265+
let mut physical_size = self.with_window_target(|window_target| {
266+
let state = window_target.state.get_mut();
265267
let window_handle = state.window_map.get(window_id).unwrap();
266268
let mut size = window_handle.size.lock().unwrap();
267269

@@ -294,7 +296,8 @@ impl<T: 'static> EventLoop<T> {
294296
}
295297

296298
if let Some(size) = window_update.size.take() {
297-
let physical_size = self.with_state(|state| {
299+
let physical_size = self.with_window_target(|window_target| {
300+
let state = window_target.state.get_mut();
298301
let window_handle = state.window_map.get_mut(window_id).unwrap();
299302
let mut window_size = window_handle.size.lock().unwrap();
300303

@@ -320,6 +323,15 @@ impl<T: 'static> EventLoop<T> {
320323
// Mark that refresh isn't required, since we've done it right now.
321324
window_update.refresh_frame = false;
322325

326+
// Queue request for redraw into the next iteration of the loop, since
327+
// resize and scale factor changes are double buffered.
328+
window_handle
329+
.pending_window_requests
330+
.lock()
331+
.unwrap()
332+
.push(WindowRequest::Redraw);
333+
window_target.event_loop_awakener.ping();
334+
323335
physical_size
324336
});
325337

@@ -356,7 +368,8 @@ impl<T: 'static> EventLoop<T> {
356368
// The purpose of the back buffer and that swap is to not hold borrow_mut when
357369
// we're doing callback to the user, since we can double borrow if the user decides
358370
// to create a window in one of those callbacks.
359-
self.with_state(|state| {
371+
self.with_window_target(|window_target| {
372+
let state = window_target.state.get_mut();
360373
std::mem::swap(
361374
&mut event_sink_back_buffer,
362375
&mut state.event_sink.window_events,
@@ -381,7 +394,8 @@ impl<T: 'static> EventLoop<T> {
381394
for (window_id, window_update) in window_updates.iter() {
382395
// Handle refresh of the frame.
383396
if window_update.refresh_frame {
384-
self.with_state(|state| {
397+
self.with_window_target(|window_target| {
398+
let state = window_target.state.get_mut();
385399
let window_handle = state.window_map.get_mut(window_id).unwrap();
386400
window_handle.window.refresh();
387401
if !window_update.redraw_requested {
@@ -526,9 +540,9 @@ impl<T: 'static> EventLoop<T> {
526540
&self.window_target
527541
}
528542

529-
fn with_state<U, F: FnOnce(&mut WinitState) -> U>(&mut self, f: F) -> U {
543+
fn with_window_target<U, F: FnOnce(&mut EventLoopWindowTarget<T>) -> U>(&mut self, f: F) -> U {
530544
let state = match &mut self.window_target.p {
531-
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(),
545+
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target,
532546
#[cfg(feature = "x11")]
533547
_ => unreachable!(),
534548
};

0 commit comments

Comments
 (0)