1
0
Fork 0
forked from wry/wry

surface: split ext::pre_commit into two parts

This commit is contained in:
Julian Orth 2024-03-20 19:21:40 +01:00
parent 86d37b5aa4
commit 943626a7f7
5 changed files with 39 additions and 26 deletions

View file

@ -198,13 +198,22 @@ enum CommitAction {
} }
trait SurfaceExt { trait SurfaceExt {
fn pre_commit(self: Rc<Self>, ctx: CommitContext) -> Result<CommitAction, WlSurfaceError> { fn prepare_commit(&self, ctx: CommitContext, pending: &mut PendingState) -> CommitAction {
let _ = ctx; let _ = ctx;
Ok(CommitAction::ContinueCommit) let _ = pending;
CommitAction::ContinueCommit
} }
fn post_commit(self: Rc<Self>) { fn before_apply_commit(
// nothing self: Rc<Self>,
pending: &mut PendingState,
) -> Result<(), WlSurfaceError> {
let _ = pending;
Ok(())
}
fn after_apply_commit(self: Rc<Self>, pending: &mut PendingState) {
let _ = pending;
} }
fn is_some(&self) -> bool { fn is_some(&self) -> bool {
@ -647,9 +656,11 @@ impl WlSurface {
fn do_commit(self: &Rc<Self>, ctx: CommitContext) -> Result<(), WlSurfaceError> { fn do_commit(self: &Rc<Self>, ctx: CommitContext) -> Result<(), WlSurfaceError> {
let ext = self.ext.get(); 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(()); return Ok(());
} }
ext.clone().before_apply_commit(pending)?;
{ {
let children = self.children.borrow(); let children = self.children.borrow();
if let Some(children) = children.deref() { if let Some(children) = children.deref() {
@ -658,7 +669,6 @@ impl WlSurface {
} }
} }
} }
let pending = &mut *self.pending.borrow_mut();
let mut scale_changed = false; let mut scale_changed = false;
if let Some(scale) = pending.scale.take() { if let Some(scale) = pending.scale.take() {
scale_changed = true; scale_changed = true;
@ -853,7 +863,7 @@ impl WlSurface {
cursor.update_hardware_cursor(); cursor.update_hardware_cursor();
} }
} }
ext.post_commit(); ext.after_apply_commit(pending);
self.client.state.damage(); self.client.state.damage();
Ok(()) Ok(())
} }

View file

@ -2,8 +2,8 @@ use {
crate::{ crate::{
client::ClientError, client::ClientError,
ifs::wl_surface::{ ifs::wl_surface::{
CommitAction, CommitContext, StackElement, SurfaceExt, SurfaceRole, WlSurface, CommitAction, CommitContext, PendingState, StackElement, SurfaceExt, SurfaceRole,
WlSurfaceError, WlSurfaceId, WlSurface, WlSurfaceError, WlSurfaceId,
}, },
leaks::Tracker, leaks::Tracker,
object::Object, object::Object,
@ -264,15 +264,15 @@ impl Object for WlSubsurface {
simple_add_obj!(WlSubsurface); simple_add_obj!(WlSubsurface);
impl SurfaceExt for WlSubsurface { impl SurfaceExt for WlSubsurface {
fn pre_commit(self: Rc<Self>, ctx: CommitContext) -> Result<CommitAction, WlSurfaceError> { fn prepare_commit(&self, ctx: CommitContext, _pending: &mut PendingState) -> CommitAction {
if ctx == CommitContext::RootCommit && self.sync() { if ctx == CommitContext::RootCommit && self.sync() {
log::debug!("Aborting commit due to 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<Self>) { fn after_apply_commit(self: Rc<Self>, _pending: &mut PendingState) {
if let Some(v) = self.pending.node.take() { if let Some(v) = self.pending.node.take() {
v.pending.set(false); v.pending.set(false);
self.node.borrow_mut().replace(v); self.node.borrow_mut().replace(v);

View file

@ -2,7 +2,7 @@ use {
crate::{ crate::{
ifs::wl_surface::{ ifs::wl_surface::{
x_surface::{xwayland_surface_v1::XwaylandSurfaceV1, xwindow::Xwindow}, x_surface::{xwayland_surface_v1::XwaylandSurfaceV1, xwindow::Xwindow},
SurfaceExt, WlSurface, WlSurfaceError, PendingState, SurfaceExt, WlSurface, WlSurfaceError,
}, },
leaks::Tracker, leaks::Tracker,
tree::ToplevelNode, tree::ToplevelNode,
@ -23,7 +23,7 @@ pub struct XSurface {
} }
impl SurfaceExt for XSurface { impl SurfaceExt for XSurface {
fn post_commit(self: Rc<Self>) { fn after_apply_commit(self: Rc<Self>, _pending: &mut PendingState) {
if let Some(xwindow) = self.xwindow.get() { if let Some(xwindow) = self.xwindow.get() {
xwindow.map_status_changed(); xwindow.map_status_changed();
} }

View file

@ -10,7 +10,7 @@ use {
xdg_popup::{XdgPopup, XdgPopupError}, xdg_popup::{XdgPopup, XdgPopupError},
xdg_toplevel::{XdgToplevel, WM_CAPABILITIES_SINCE}, xdg_toplevel::{XdgToplevel, WM_CAPABILITIES_SINCE},
}, },
CommitAction, CommitContext, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError, PendingState, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError,
}, },
xdg_wm_base::XdgWmBase, xdg_wm_base::XdgWmBase,
}, },
@ -357,7 +357,10 @@ impl Object for XdgSurface {
dedicated_add_obj!(XdgSurface, XdgSurfaceId, xdg_surfaces); dedicated_add_obj!(XdgSurface, XdgSurfaceId, xdg_surfaces);
impl SurfaceExt for XdgSurface { impl SurfaceExt for XdgSurface {
fn pre_commit(self: Rc<Self>, _ctx: CommitContext) -> Result<CommitAction, WlSurfaceError> { fn before_apply_commit(
self: Rc<Self>,
_pending: &mut PendingState,
) -> Result<(), WlSurfaceError> {
{ {
let ase = self.acked_serial.get(); let ase = self.acked_serial.get();
let rse = self.requested_serial.get(); let rse = self.requested_serial.get();
@ -368,17 +371,16 @@ impl SurfaceExt for XdgSurface {
} }
self.send_configure(rse); self.send_configure(rse);
} }
// return CommitAction::AbortCommit;
} }
} }
if let Some(geometry) = self.pending.geometry.take() { if let Some(geometry) = self.pending.geometry.take() {
self.geometry.set(Some(geometry)); self.geometry.set(Some(geometry));
self.update_extents(); self.update_extents();
} }
Ok(CommitAction::ContinueCommit) Ok(())
} }
fn post_commit(self: Rc<Self>) { fn after_apply_commit(self: Rc<Self>, _pending: &mut PendingState) {
if let Some(ext) = self.ext.get() { if let Some(ext) = self.ext.get() {
ext.post_commit(); ext.post_commit();
} }

View file

@ -3,9 +3,7 @@ use {
client::{Client, ClientError}, client::{Client, ClientError},
ifs::{ ifs::{
wl_seat::NodeSeatState, wl_seat::NodeSeatState,
wl_surface::{ wl_surface::{PendingState, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError},
CommitAction, CommitContext, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError,
},
zwlr_layer_shell_v1::{ZwlrLayerShellV1, OVERLAY}, zwlr_layer_shell_v1::{ZwlrLayerShellV1, OVERLAY},
}, },
leaks::Tracker, leaks::Tracker,
@ -313,12 +311,15 @@ impl ZwlrLayerSurfaceV1 {
} }
impl SurfaceExt for ZwlrLayerSurfaceV1 { impl SurfaceExt for ZwlrLayerSurfaceV1 {
fn pre_commit(self: Rc<Self>, _ctx: CommitContext) -> Result<CommitAction, WlSurfaceError> { fn before_apply_commit(
self: Rc<Self>,
_pending: &mut PendingState,
) -> Result<(), WlSurfaceError> {
self.deref().pre_commit()?; self.deref().pre_commit()?;
Ok(CommitAction::ContinueCommit) Ok(())
} }
fn post_commit(self: Rc<Self>) { fn after_apply_commit(self: Rc<Self>, _pending: &mut PendingState) {
let buffer = self.surface.buffer.get(); let buffer = self.surface.buffer.get();
if self.mapped.get() { if self.mapped.get() {
if buffer.is_none() { if buffer.is_none() {