Skip to content

Commit

Permalink
surface: Replace dimensions with width and height
Browse files Browse the repository at this point in the history
  • Loading branch information
danyspin97 committed Feb 14, 2024
1 parent aabcd40 commit bc75253
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions daemon/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub struct Surface {
pub surface: wl_surface::WlSurface,
pub output: WlOutput,
pub layer: LayerSurface,
pub dimensions: (u32, u32),
pub width: u32,
pub height: u32,
pub scale: i32,
egl_context: EglContext,
renderer: Renderer,
Expand Down Expand Up @@ -50,7 +51,8 @@ impl Surface {
name,
output,
layer,
dimensions: (0, 0),
width: 0,
height: 0,
scale: scale_factor,
surface,
egl_context,
Expand All @@ -63,10 +65,10 @@ impl Surface {

/// Returns true if something has been drawn to the surface
pub fn draw(&mut self) -> Result<()> {
debug_assert!(self.dimensions.0 != 0 || self.dimensions.1 != 0);
debug_assert!(self.width != 0 || self.height != 0);

let width = self.dimensions.0 as i32 * self.scale;
let height = self.dimensions.1 as i32 * self.scale;
let width = self.width as i32 * self.scale;
let height = self.height as i32 * self.scale;

// Use the correct context before loading the texture and drawing
self.egl_context.make_current()?;
Expand Down Expand Up @@ -133,9 +135,11 @@ impl Surface {
/// Resize the surface
/// configure: None means that the scale factor has changed
pub fn resize(&mut self, configure: Option<LayerSurfaceConfigure>) {
self.dimensions = configure.map(|c| c.new_size).unwrap_or(self.dimensions);
let width = TryInto::<i32>::try_into(self.dimensions.0).unwrap() * self.scale;
let height = TryInto::<i32>::try_into(self.dimensions.1).unwrap() * self.scale;
if let Some(configure) = configure {
(self.width, self.height) = configure.new_size;
}
let width = self.width as i32 * self.scale;
let height = self.height as i32 * self.scale;
self.egl_context.resize(&self.surface, width, height);
// Resize the gl viewport
self.egl_context.make_current().unwrap();
Expand All @@ -147,7 +151,7 @@ impl Surface {

/// Check that the dimensions are valid
pub(crate) fn is_configured(&self) -> bool {
self.dimensions.0 != 0 && self.dimensions.1 != 0
self.width != 0 && self.height != 0
}

/// Update the wallpaper_info of this Surface
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/wpaperd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl LayerShellHandler for Wpaperd {
// We always know the surface that it is being configured
.unwrap();

if surface.dimensions != configure.new_size {
if (surface.width, surface.height) != configure.new_size {
// Update dimensions
surface.resize(Some(configure));
}
Expand Down

0 comments on commit bc75253

Please sign in to comment.