From 943626a7f774f9968cb5bf32bd9a04d0feb6b6f0 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 20 Mar 2024 19:21:40 +0100 Subject: [PATCH] surface: split ext::pre_commit into two parts --- src/ifs/wl_surface.rs | 24 +++++++++++++++------ src/ifs/wl_surface/wl_subsurface.rs | 12 +++++------ src/ifs/wl_surface/x_surface.rs | 4 ++-- src/ifs/wl_surface/xdg_surface.rs | 12 ++++++----- src/ifs/wl_surface/zwlr_layer_surface_v1.rs | 13 +++++------ 5 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index c34d51d2..48bd28d2 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -198,13 +198,22 @@ enum CommitAction { } trait SurfaceExt { - fn pre_commit(self: Rc, ctx: CommitContext) -> Result { + fn prepare_commit(&self, ctx: CommitContext, pending: &mut PendingState) -> CommitAction { let _ = ctx; - Ok(CommitAction::ContinueCommit) + let _ = pending; + CommitAction::ContinueCommit } - fn post_commit(self: Rc) { - // nothing + fn before_apply_commit( + self: Rc, + pending: &mut PendingState, + ) -> Result<(), WlSurfaceError> { + let _ = pending; + Ok(()) + } + + fn after_apply_commit(self: Rc, pending: &mut PendingState) { + let _ = pending; } fn is_some(&self) -> bool { @@ -647,9 +656,11 @@ impl WlSurface { fn do_commit(self: &Rc, ctx: CommitContext) -> Result<(), WlSurfaceError> { let ext = self.ext.get(); - if ext.clone().pre_commit(ctx)? == CommitAction::AbortCommit { + let pending = &mut *self.pending.borrow_mut(); + if ext.prepare_commit(ctx, pending) == CommitAction::AbortCommit { return Ok(()); } + ext.clone().before_apply_commit(pending)?; { let children = self.children.borrow(); if let Some(children) = children.deref() { @@ -658,7 +669,6 @@ impl WlSurface { } } } - let pending = &mut *self.pending.borrow_mut(); let mut scale_changed = false; if let Some(scale) = pending.scale.take() { scale_changed = true; @@ -853,7 +863,7 @@ impl WlSurface { cursor.update_hardware_cursor(); } } - ext.post_commit(); + ext.after_apply_commit(pending); self.client.state.damage(); Ok(()) } diff --git a/src/ifs/wl_surface/wl_subsurface.rs b/src/ifs/wl_surface/wl_subsurface.rs index f1fce993..c54a6a29 100644 --- a/src/ifs/wl_surface/wl_subsurface.rs +++ b/src/ifs/wl_surface/wl_subsurface.rs @@ -2,8 +2,8 @@ use { crate::{ client::ClientError, ifs::wl_surface::{ - CommitAction, CommitContext, StackElement, SurfaceExt, SurfaceRole, WlSurface, - WlSurfaceError, WlSurfaceId, + CommitAction, CommitContext, PendingState, StackElement, SurfaceExt, SurfaceRole, + WlSurface, WlSurfaceError, WlSurfaceId, }, leaks::Tracker, object::Object, @@ -264,15 +264,15 @@ impl Object for WlSubsurface { simple_add_obj!(WlSubsurface); impl SurfaceExt for WlSubsurface { - fn pre_commit(self: Rc, ctx: CommitContext) -> Result { + fn prepare_commit(&self, ctx: CommitContext, _pending: &mut PendingState) -> CommitAction { if ctx == CommitContext::RootCommit && self.sync() { log::debug!("Aborting commit due to sync"); - return Ok(CommitAction::AbortCommit); + return CommitAction::AbortCommit; } - Ok(CommitAction::ContinueCommit) + CommitAction::ContinueCommit } - fn post_commit(self: Rc) { + fn after_apply_commit(self: Rc, _pending: &mut PendingState) { if let Some(v) = self.pending.node.take() { v.pending.set(false); self.node.borrow_mut().replace(v); diff --git a/src/ifs/wl_surface/x_surface.rs b/src/ifs/wl_surface/x_surface.rs index 6fed1b2d..3da57314 100644 --- a/src/ifs/wl_surface/x_surface.rs +++ b/src/ifs/wl_surface/x_surface.rs @@ -2,7 +2,7 @@ use { crate::{ ifs::wl_surface::{ x_surface::{xwayland_surface_v1::XwaylandSurfaceV1, xwindow::Xwindow}, - SurfaceExt, WlSurface, WlSurfaceError, + PendingState, SurfaceExt, WlSurface, WlSurfaceError, }, leaks::Tracker, tree::ToplevelNode, @@ -23,7 +23,7 @@ pub struct XSurface { } impl SurfaceExt for XSurface { - fn post_commit(self: Rc) { + fn after_apply_commit(self: Rc, _pending: &mut PendingState) { if let Some(xwindow) = self.xwindow.get() { xwindow.map_status_changed(); } diff --git a/src/ifs/wl_surface/xdg_surface.rs b/src/ifs/wl_surface/xdg_surface.rs index 379d01dc..83fbb4e7 100644 --- a/src/ifs/wl_surface/xdg_surface.rs +++ b/src/ifs/wl_surface/xdg_surface.rs @@ -10,7 +10,7 @@ use { xdg_popup::{XdgPopup, XdgPopupError}, xdg_toplevel::{XdgToplevel, WM_CAPABILITIES_SINCE}, }, - CommitAction, CommitContext, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError, + PendingState, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError, }, xdg_wm_base::XdgWmBase, }, @@ -357,7 +357,10 @@ impl Object for XdgSurface { dedicated_add_obj!(XdgSurface, XdgSurfaceId, xdg_surfaces); impl SurfaceExt for XdgSurface { - fn pre_commit(self: Rc, _ctx: CommitContext) -> Result { + fn before_apply_commit( + self: Rc, + _pending: &mut PendingState, + ) -> Result<(), WlSurfaceError> { { let ase = self.acked_serial.get(); let rse = self.requested_serial.get(); @@ -368,17 +371,16 @@ impl SurfaceExt for XdgSurface { } self.send_configure(rse); } - // return CommitAction::AbortCommit; } } if let Some(geometry) = self.pending.geometry.take() { self.geometry.set(Some(geometry)); self.update_extents(); } - Ok(CommitAction::ContinueCommit) + Ok(()) } - fn post_commit(self: Rc) { + fn after_apply_commit(self: Rc, _pending: &mut PendingState) { if let Some(ext) = self.ext.get() { ext.post_commit(); } diff --git a/src/ifs/wl_surface/zwlr_layer_surface_v1.rs b/src/ifs/wl_surface/zwlr_layer_surface_v1.rs index 38f04daa..4eaf585d 100644 --- a/src/ifs/wl_surface/zwlr_layer_surface_v1.rs +++ b/src/ifs/wl_surface/zwlr_layer_surface_v1.rs @@ -3,9 +3,7 @@ use { client::{Client, ClientError}, ifs::{ wl_seat::NodeSeatState, - wl_surface::{ - CommitAction, CommitContext, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError, - }, + wl_surface::{PendingState, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError}, zwlr_layer_shell_v1::{ZwlrLayerShellV1, OVERLAY}, }, leaks::Tracker, @@ -313,12 +311,15 @@ impl ZwlrLayerSurfaceV1 { } impl SurfaceExt for ZwlrLayerSurfaceV1 { - fn pre_commit(self: Rc, _ctx: CommitContext) -> Result { + fn before_apply_commit( + self: Rc, + _pending: &mut PendingState, + ) -> Result<(), WlSurfaceError> { self.deref().pre_commit()?; - Ok(CommitAction::ContinueCommit) + Ok(()) } - fn post_commit(self: Rc) { + fn after_apply_commit(self: Rc, _pending: &mut PendingState) { let buffer = self.surface.buffer.get(); if self.mapped.get() { if buffer.is_none() {