Skip to content

Commit

Permalink
fix output transforms
Browse files Browse the repository at this point in the history
Instead of always setting width >= height on transforms we thought were
vertical, we now properly process transforms only when commiting surface
changes. This means a portrait monitor in landscape mode would behave
correctly.
  • Loading branch information
LGFae committed May 3, 2024
1 parent f31c591 commit e525f41
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 47 deletions.
12 changes: 1 addition & 11 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,7 @@ impl Dispatch<wl_output::WlOutput, ()> for Daemon {
} => {
debug!("output {} position: {x},{y}", proxy.id());
match transform {
wayland_client::WEnum::Value(v) => match v {
wl_output::Transform::_90
| wl_output::Transform::_270
| wl_output::Transform::Flipped90
| wl_output::Transform::Flipped270 => wallpaper.set_vertical(),
wl_output::Transform::Normal
| wl_output::Transform::_180
| wl_output::Transform::Flipped
| wl_output::Transform::Flipped180 => wallpaper.set_horizontal(),
e => warn!("unprocessed transform: {e:?}"),
},
wayland_client::WEnum::Value(v) => wallpaper.set_transform(v),
wayland_client::WEnum::Unknown(u) => {
error!("received unknown transform from compositor: {u}")
}
Expand Down
65 changes: 29 additions & 36 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ use std::{
};

use wayland_client::{
protocol::{wl_output::WlOutput, wl_shm::WlShm, wl_surface::WlSurface},
protocol::{
wl_output::{Transform, WlOutput},
wl_shm::WlShm,
wl_surface::WlSurface,
},
Proxy, QueueHandle,
};

Expand Down Expand Up @@ -49,7 +53,7 @@ struct WallpaperInner {
width: NonZeroI32,
height: NonZeroI32,
scale_factor: Scale,
is_vertical: bool,
transform: Transform,
}

impl Default for WallpaperInner {
Expand All @@ -60,7 +64,7 @@ impl Default for WallpaperInner {
width: unsafe { NonZeroI32::new_unchecked(4) },
height: unsafe { NonZeroI32::new_unchecked(4) },
scale_factor: Scale::Whole(unsafe { NonZeroI32::new_unchecked(1) }),
is_vertical: false,
transform: Transform::Normal,
}
}
}
Expand Down Expand Up @@ -188,30 +192,11 @@ impl Wallpaper {
)
}
}

if lock.is_vertical {
if lock.width > lock.height {
let t = lock.width;
lock.width = lock.height;
lock.height = t;
}
} else if lock.width < lock.height {
let t = lock.width;
lock.width = lock.height;
lock.height = t;
}
}

#[inline]
pub fn set_vertical(&self) {
let mut lock = self.inner_staging.lock().unwrap();
lock.is_vertical = true;
}

#[inline]
pub fn set_horizontal(&self) {
let mut lock = self.inner_staging.lock().unwrap();
lock.is_vertical = false;
pub fn set_transform(&self, transform: Transform) {
self.inner_staging.lock().unwrap().transform = transform;
}

#[inline]
Expand Down Expand Up @@ -268,7 +253,16 @@ impl Wallpaper {
}
}

if staging.scale_factor != inner.scale_factor {
let (width, height) = if matches!(
staging.transform,
Transform::_90 | Transform::_270 | Transform::Flipped90 | Transform::Flipped270
) {
(staging.height, staging.width)
} else {
(staging.width, staging.height)
};

if staging.scale_factor != inner.scale_factor || staging.transform != inner.transform {
match staging.scale_factor {
Scale::Whole(i) => {
// unset destination
Expand All @@ -277,27 +271,26 @@ impl Wallpaper {
}
Scale::Fractional(_) => {
self.wl_surface.set_buffer_scale(1);
self.wp_viewport
.set_destination(staging.width.get(), staging.height.get());
self.wp_viewport.set_destination(width.get(), height.get());
}
}
}

if (inner.width, inner.height) == (staging.width, staging.height) {
inner.scale_factor = staging.scale_factor;
inner.name = staging.name.clone();
inner.desc = staging.desc.clone();
inner.scale_factor = staging.scale_factor;
inner.transform = staging.transform;
inner.name.clone_from(&staging.name);
inner.desc.clone_from(&staging.desc);
if (inner.width, inner.height) == (width, height) {
return;
}
//otherwise, everything changed
*inner = staging.clone();
self.stop_animations();
inner.width = width;
inner.height = height;

let (width, height, scale_factor) = (staging.width, staging.height, staging.scale_factor);
let scale_factor = staging.scale_factor;
drop(inner);
drop(staging);

self.stop_animations();

self.layer_surface
.set_size(width.get() as u32, height.get() as u32);

Expand Down

0 comments on commit e525f41

Please sign in to comment.