Skip to content

Commit

Permalink
less casting between types
Browse files Browse the repository at this point in the history
  • Loading branch information
LGFae committed Apr 16, 2024
1 parent 43d1227 commit cdaf424
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
25 changes: 13 additions & 12 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ impl Wallpaper {
#[inline]
pub fn set_dimensions(&self, width: i32, height: i32) {
let mut lock = self.inner_staging.lock().unwrap();
let (width, height) = lock.scale_factor.div_dim(width as u32, height as u32);
let (width, height) = lock.scale_factor.div_dim(width, height);

match NonZeroI32::new(width as i32) {
match NonZeroI32::new(width) {
Some(width) => lock.width = width,
None => {
error!(
Expand All @@ -188,7 +188,7 @@ impl Wallpaper {
}
}

match NonZeroI32::new(height as i32) {
match NonZeroI32::new(height) {
Some(height) => lock.height = height,
None => {
error!(
Expand All @@ -208,11 +208,11 @@ impl Wallpaper {

let (old_width, old_height) = lock
.scale_factor
.mul_dim(lock.width.get() as u32, lock.height.get() as u32);
.mul_dim(lock.width.get(), lock.height.get());

lock.scale_factor = scale;
let (width, height) = lock.scale_factor.div_dim(old_width, old_height);
match NonZeroI32::new(width as i32) {
match NonZeroI32::new(width) {
Some(width) => lock.width = width,
None => {
error!(
Expand All @@ -222,7 +222,7 @@ impl Wallpaper {
}
}

match NonZeroI32::new(height as i32) {
match NonZeroI32::new(height) {
Some(height) => lock.height = height,
None => {
error!(
Expand Down Expand Up @@ -287,8 +287,8 @@ impl Wallpaper {
self.layer_surface
.set_size(width.get() as u32, height.get() as u32);

let (w, h) = scale_factor.mul_dim(width.get() as u32, height.get() as u32);
self.pool.lock().unwrap().resize(w as i32, h as i32);
let (w, h) = scale_factor.mul_dim(width.get(), height.get());
self.pool.lock().unwrap().resize(w, h);

*self.frame_callback_handler.time.lock().unwrap() = Some(0);
self.wl_surface.commit();
Expand Down Expand Up @@ -329,9 +329,10 @@ impl Wallpaper {

pub(super) fn get_dimensions(&self) -> (u32, u32) {
let inner = self.inner.read().unwrap();
inner
let dim = inner
.scale_factor
.mul_dim(inner.width.get() as u32, inner.height.get() as u32)
.mul_dim(inner.width.get(), inner.height.get());
(dim.0 as u32, dim.1 as u32)
}

#[inline]
Expand Down Expand Up @@ -396,11 +397,11 @@ impl Wallpaper {
if let Some(buf) = self.pool.lock().unwrap().get_commitable_buffer() {
let (width, height) = inner
.scale_factor
.mul_dim(inner.width.get() as u32, inner.height.get() as u32);
.mul_dim(inner.width.get(), inner.height.get());
let surface = &self.wl_surface;
surface.attach(Some(buf), 0, 0);
drop(inner);
surface.damage_buffer(0, 0, width as i32, height as i32);
surface.damage_buffer(0, 0, width, height);
surface.commit();
surface.frame(&self.qh, surface.clone());
} else {
Expand Down
23 changes: 10 additions & 13 deletions utils/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,19 @@ pub enum Scale {
impl Scale {
#[inline]
#[must_use]
pub fn mul_dim(&self, width: u32, height: u32) -> (u32, u32) {
pub fn mul_dim(&self, width: i32, height: i32) -> (i32, i32) {
match self {
Scale::Whole(i) => (width * i.get() as u32, height * i.get() as u32),
Scale::Fractional(f) => (
(width * f.get() as u32 + 60) / 120,
(height * f.get() as u32 + 60) / 120,
),
Scale::Whole(i) => (width * i.get(), height * i.get()),
Scale::Fractional(f) => ((width * f.get() + 60) / 120, (height * f.get() + 60) / 120),
}
}

#[inline]
#[must_use]
pub fn div_dim(&self, width: u32, height: u32) -> (u32, u32) {
pub fn div_dim(&self, width: i32, height: i32) -> (i32, i32) {
match self {
Scale::Whole(i) => (width / i.get() as u32, height / i.get() as u32),
Scale::Fractional(f) => (
(width * 120) / f.get() as u32,
(height * 120) / f.get() as u32,
),
Scale::Whole(i) => (width / i.get(), height / i.get()),
Scale::Fractional(f) => ((width * 120) / f.get(), (height * 120) / f.get()),
}
}
}
Expand Down Expand Up @@ -193,7 +187,10 @@ impl BgInfo {
#[inline]
#[must_use]
pub fn real_dim(&self) -> (u32, u32) {
self.scale_factor.mul_dim(self.dim.0, self.dim.1)
let dim = self
.scale_factor
.mul_dim(self.dim.0 as i32, self.dim.1 as i32);
(dim.0 as u32, dim.1 as u32)
}
}

Expand Down

0 comments on commit cdaf424

Please sign in to comment.