diff --git a/CHANGELOG.md b/CHANGELOG.md index 529522b..7b2f6c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ ## Fixes +# 0.2.2 - 2024-03-10 + +## Fixes + +- Invalid scale handling + # 0.2.1 - 2024-03-10 ## Features diff --git a/Cargo.lock b/Cargo.lock index 79076d0..8ce4d03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1676,7 +1676,7 @@ dependencies = [ [[package]] name = "yofi" -version = "0.2.1" +version = "0.2.2" dependencies = [ "anyhow", "argh", diff --git a/Cargo.toml b/Cargo.toml index 091edae..a240158 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yofi" -version = "0.2.1" +version = "0.2.2" authors = ["Kitsu "] edition = "2021" diff --git a/src/window.rs b/src/window.rs index 8bc8d26..a9421e7 100644 --- a/src/window.rs +++ b/src/window.rs @@ -181,6 +181,7 @@ impl Window { let width = self.width().try_into().expect("width overflow"); let height = self.height().try_into().expect("height overflow"); let stride = width * 4; + self.surface.set_buffer_scale(self.scale.into()); if self .buffer @@ -239,10 +240,9 @@ impl Window { }; let mut point = Point::new(0., 0.); - let scale = self.scale; let mut drawables = crate::draw::make_drawables(&self.config, &mut self.state); while let Some(d) = drawables.borrowed_next() { - let occupied = d.draw(&mut dt, scale, space_left, point); + let occupied = d.draw(&mut dt, self.scale, space_left, point); debug_assert!( occupied.width <= space_left.width && occupied.height <= space_left.height ); @@ -251,8 +251,7 @@ impl Window { space_left.height -= occupied.height; } - self.surface - .damage_buffer(0, 0, self.width as i32, self.height as i32); + self.surface.damage_buffer(0, 0, width, height); self.surface.frame(qh, self.surface.clone()); buffer.attach_to(&self.surface).expect("buffer attach"); self.buffer = Some(buffer); diff --git a/src/window/1Window b/src/window/1Window deleted file mode 100644 index e69de29..0000000 diff --git a/src/window/compositor.rs b/src/window/compositor.rs index 7b90582..9bd9f71 100644 --- a/src/window/compositor.rs +++ b/src/window/compositor.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use sctk::{ compositor::CompositorHandler, reexports::client::{ @@ -16,7 +17,20 @@ impl CompositorHandler for Window { _surface: &WlSurface, new_factor: i32, ) { + let old_scale = self.scale; self.scale = new_factor.try_into().expect("invalid surface scale factor"); + if old_scale != self.scale { + let size = (4 * self.width() * self.height()) + .try_into() + .expect("pixel buffer overflow"); + if let Err(err) = self + .pool + .resize(size) + .with_context(|| format!("on pool resize to {size}")) + { + self.error = Some(err); + } + } } fn transform_changed(