Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
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
47 changes: 38 additions & 9 deletions common/src/ipc/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,31 @@ impl PixelFormat {

#[derive(Clone, Copy, Debug)]
pub enum Scale {
Whole(NonZeroI32),
/// sent by wl_output::scale events
Output(NonZeroI32),
/// sent by wl_surface::preferred_buffer_scale events
Preferred(NonZeroI32),
/// sent by wp_fractional_scale_v1::preferred_scale events
Fractional(NonZeroI32),
}

impl Scale {
#[inline]
#[must_use]
pub fn priority(&self) -> u32 {
match self {
Scale::Output(_) => 0,
Scale::Preferred(_) => 1,
Scale::Fractional(_) => 2,
}
}

#[inline]
#[must_use]
pub fn mul_dim(&self, width: i32, height: i32) -> (i32, i32) {
match self {
Scale::Whole(i) => (width * i.get(), height * i.get()),
Scale::Output(i) => (width * i.get(), height * i.get()),
Scale::Preferred(i) => (width * i.get(), height * i.get()),
Scale::Fractional(f) => {
let scale = f.get() as f64 / 120.0;
let width = (width as f64 * scale).round() as i32;
Expand All @@ -176,7 +191,8 @@ impl Scale {
#[must_use]
pub fn div_dim(&self, width: i32, height: i32) -> (i32, i32) {
match self {
Scale::Whole(i) => (width / i.get(), height / i.get()),
Scale::Output(i) => (width / i.get(), height / i.get()),
Scale::Preferred(i) => (width / i.get(), height / i.get()),
Scale::Fractional(f) => {
let scale = 120.0 / f.get() as f64;
let width = (width as f64 * scale).round() as i32;
Expand All @@ -190,10 +206,12 @@ impl Scale {
impl PartialEq for Scale {
fn eq(&self, other: &Self) -> bool {
(match self {
Self::Whole(i) => i.get() * 120,
Self::Output(i) => i.get() * 120,
Self::Preferred(i) => i.get() * 120,
Self::Fractional(f) => f.get(),
}) == (match other {
Self::Whole(i) => i.get() * 120,
Self::Output(i) => i.get() * 120,
Self::Preferred(i) => i.get() * 120,
Self::Fractional(f) => f.get(),
})
}
Expand All @@ -205,7 +223,8 @@ impl fmt::Display for Scale {
f,
"{}",
match self {
Scale::Whole(i) => i.get() as f32,
Scale::Output(i) => i.get() as f32,
Scale::Preferred(i) => i.get() as f32,
Scale::Fractional(f) => f.get() as f32 / 120.0,
}
)
Expand Down Expand Up @@ -258,14 +277,18 @@ impl BgInfo {
i += 8;

match scale_factor {
Scale::Whole(value) => {
Scale::Output(value) => {
buf[i] = 0;
buf[i + 1..i + 5].copy_from_slice(&value.get().to_ne_bytes());
}
Scale::Fractional(value) => {
Scale::Preferred(value) => {
buf[i] = 1;
buf[i + 1..i + 5].copy_from_slice(&value.get().to_ne_bytes());
}
Scale::Fractional(value) => {
buf[i] = 2;
buf[i + 1..i + 5].copy_from_slice(&value.get().to_ne_bytes());
}
}
i += 5;

Expand Down Expand Up @@ -302,7 +325,13 @@ impl BgInfo {
i += 8;

let scale_factor = if bytes[i] == 0 {
Scale::Whole(
Scale::Output(
i32::from_ne_bytes(bytes[i + 1..i + 5].try_into().unwrap())
.try_into()
.unwrap(),
)
} else if bytes[i] == 1 {
Scale::Preferred(
i32::from_ne_bytes(bytes[i + 1..i + 5].try_into().unwrap())
.try_into()
.unwrap(),
Expand Down
6 changes: 3 additions & 3 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl wayland::wl_output::EvHandler for Daemon {
let mut wallpaper = wallpaper.borrow_mut();
if wallpaper.has_output(sender_id) {
match NonZeroI32::new(factor) {
Some(factor) => wallpaper.set_scale(Scale::Whole(factor)),
Some(factor) => wallpaper.set_scale(Scale::Output(factor)),
None => error!("received scale factor of 0 from compositor"),
}
break;
Expand Down Expand Up @@ -516,7 +516,7 @@ impl wayland::wl_surface::EvHandler for Daemon {
let mut wallpaper = wallpaper.borrow_mut();
if wallpaper.has_surface(sender_id) {
match NonZeroI32::new(factor) {
Some(factor) => wallpaper.set_scale(Scale::Whole(factor)),
Some(factor) => wallpaper.set_scale(Scale::Preferred(factor)),
None => error!("received scale factor of 0 from compositor"),
}
break;
Expand All @@ -529,7 +529,7 @@ impl wayland::wl_surface::EvHandler for Daemon {
_sender_id: ObjectId,
_transform: wayland::wl_output::Transform,
) {
warn!("Received PreferredBufferTransform. We currently ignore those")
//Ignore these for now
}
}

Expand Down
11 changes: 8 additions & 3 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Default for WallpaperInner {
desc: None,
width: unsafe { NonZeroI32::new_unchecked(4) },
height: unsafe { NonZeroI32::new_unchecked(4) },
scale_factor: Scale::Whole(unsafe { NonZeroI32::new_unchecked(1) }),
scale_factor: Scale::Output(unsafe { NonZeroI32::new_unchecked(1) }),
transform: wl_output::Transform::normal,
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ impl Wallpaper {

pub fn set_scale(&mut self, scale: Scale) {
let staging = &mut self.inner_staging;
if staging.scale_factor == scale {
if staging.scale_factor == scale || scale.priority() < staging.scale_factor.priority() {
return;
}

Expand Down Expand Up @@ -316,7 +316,12 @@ impl Wallpaper {

if staging.scale_factor != inner.scale_factor || staging.transform != inner.transform {
match staging.scale_factor {
Scale::Whole(i) => {
Scale::Output(i) => {
// unset destination
wp_viewport::req::set_destination(backend, self.wp_viewport, -1, -1).unwrap();
wl_surface::req::set_buffer_scale(backend, self.wl_surface, i.get()).unwrap();
}
Scale::Preferred(i) => {
// unset destination
wp_viewport::req::set_destination(backend, self.wp_viewport, -1, -1).unwrap();
wl_surface::req::set_buffer_scale(backend, self.wl_surface, i.get()).unwrap();
Expand Down
Loading