Skip to content

Commit

Permalink
On Wayland, fix resize being sent on focus change
Browse files Browse the repository at this point in the history
Fixes #3263.
  • Loading branch information
kchibisov committed Dec 21, 2023
1 parent 44052a0 commit a5b89bf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@ Unreleased` header.
- On Wayland, disable Client Side Decorations when `wl_subcompositor` is not supported.
- On X11, fix `Xft.dpi` detection from Xresources.
- On Windows, fix consecutive calls to `window.set_fullscreen(Some(Fullscreen::Borderless(None)))` resulting in losing previous window state when eventually exiting fullscreen using `window.set_fullscreen(None)`.
- On Wayland, fix resize being sent on focus change.

# 0.29.4

Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/linux/wayland/state.rs
Expand Up @@ -299,7 +299,11 @@ impl WindowHandler for WinitState {
&mut self.events_sink,
);

self.window_compositor_updates[pos].size = Some(new_size);
// NOTE: Only update when the value is `Some` to not override consequent configures with
// the same sizes.
if new_size.is_some() {
self.window_compositor_updates[pos].size = new_size;
}
}
}

Expand Down
43 changes: 26 additions & 17 deletions src/platform_impl/linux/wayland/window/state.rs
Expand Up @@ -256,7 +256,7 @@ impl WindowState {
shm: &Shm,
subcompositor: &Option<Arc<SubcompositorState>>,
event_sink: &mut EventSink,
) -> LogicalSize<u32> {
) -> Option<LogicalSize<u32>> {
// NOTE: when using fractional scaling or wl_compositor@v6 the scaling
// should be delivered before the first configure, thus apply it to
// properly scale the physical sizes provided by the users.
Expand Down Expand Up @@ -319,14 +319,9 @@ impl WindowState {
match configure.new_size {
(Some(width), Some(height)) => {
let (width, height) = frame.subtract_borders(width, height);
(
(
width.map(|w| w.get()).unwrap_or(1),
height.map(|h| h.get()).unwrap_or(1),
)
.into(),
false,
)
let width = width.map(|w| w.get()).unwrap_or(1);
let height = height.map(|h| h.get()).unwrap_or(1);
((width, height).into(), false)
}
(_, _) if stateless => (self.stateless_size, true),
_ => (self.size, true),
Expand All @@ -352,13 +347,27 @@ impl WindowState {
.unwrap_or(new_size.height);
}

// XXX Set the configure before doing a resize.
self.last_configure = Some(configure);
let new_state = configure.state;
let old_state = self
.last_configure
.as_ref()
.map(|configure| configure.state)
.unwrap_or(XdgWindowState::empty());

let state_change_requires_resize = !new_state
.symmetric_difference(old_state)
.difference(XdgWindowState::ACTIVATED | XdgWindowState::SUSPENDED)
.is_empty();

// XXX Update the new size right away.
self.resize(new_size);
// NOTE: Set the configure before doing a resize, since we query it during it.
self.last_configure = Some(configure);

new_size
if state_change_requires_resize || new_size != self.inner_size() {
self.resize(new_size);
Some(new_size)
} else {
None
}
}

/// Compute the bounds for the inner size of the surface.
Expand Down Expand Up @@ -912,7 +921,7 @@ impl WindowState {

/// Set the IME position.
pub fn set_ime_cursor_area(&self, position: LogicalPosition<u32>, size: LogicalSize<u32>) {
// XXX This won't fly unless user will have a way to request IME window per seat, since
// FIXME: This won't fly unless user will have a way to request IME window per seat, since
// the ime windows will be overlapping, but winit doesn't expose API to specify for
// which seat we're setting IME position.
let (x, y) = (position.x as i32, position.y as i32);
Expand Down Expand Up @@ -943,7 +952,7 @@ impl WindowState {
pub fn set_scale_factor(&mut self, scale_factor: f64) {
self.scale_factor = scale_factor;

// XXX when fractional scaling is not used update the buffer scale.
// NOTE: When fractional scaling is not used update the buffer scale.
if self.fractional_scale.is_none() {
let _ = self.window.set_buffer_scale(self.scale_factor as _);
}
Expand Down Expand Up @@ -1091,7 +1100,7 @@ impl From<ResizeDirection> for XdgResizeEdge {
}
}

// XXX rust doesn't allow from `Option`.
// NOTE: Rust doesn't allow `From<Option<Theme>>`.
#[cfg(feature = "sctk-adwaita")]
fn into_sctk_adwaita_config(theme: Option<Theme>) -> sctk_adwaita::FrameConfig {
match theme {
Expand Down

0 comments on commit a5b89bf

Please sign in to comment.