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
  • Loading branch information
kchibisov authored Dec 20, 2023
1 parent cc33212 commit 04ca85a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Unreleased` header.
- 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 Web, remove queuing fullscreen request in absence of transient activation.
- On Web, fix setting cursor icon overriding cursor visibility.
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,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
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,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 @@ -325,14 +325,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 @@ -358,13 +353,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 @@ -970,7 +979,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 @@ -1001,7 +1010,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 @@ -1149,7 +1158,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 04ca85a

Please sign in to comment.