1
0
Fork 0
forked from wry/wry

Merge pull request #795 from mahkoh/jorth/already-attached

wl_subsurface: unconditionally update visibility upon first parent co…
This commit is contained in:
mahkoh 2026-03-13 15:50:50 +01:00 committed by GitHub
commit 479d2171b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 72 additions and 14 deletions

View file

@ -45,6 +45,7 @@ pub struct WlSubsurface {
pub tracker: Tracker<Self>,
had_buffer: Cell<bool>,
version: Version,
initial_commit: Cell<bool>,
}
#[derive(Default)]
@ -111,6 +112,7 @@ impl WlSubsurface {
tracker: Default::default(),
had_buffer: Cell::new(false),
version,
initial_commit: Cell::new(true),
}
}
@ -128,6 +130,9 @@ impl WlSubsurface {
}
pub fn apply_state(&self, pending: &mut PendingSubsurfaceData) -> Result<(), WlSurfaceError> {
if self.initial_commit.take() {
self.update_has_buffer();
}
if let Some(state) = &mut pending.state.take() {
self.surface.apply_state(state)?;
}
@ -283,6 +288,23 @@ impl WlSubsurface {
}
self.surface.client.state.damage(rect);
}
fn update_has_buffer(&self) {
let has_buffer = self.surface.buffer.is_some();
if self.had_buffer.replace(has_buffer) != has_buffer {
if has_buffer {
if self.parent.visible.get() {
self.surface.set_visible(true);
self.damage();
}
} else {
if self.surface.toplevel.is_some() {
self.damage();
}
self.surface.destroy_node();
}
}
}
}
impl WlSubsurfaceRequestHandler for WlSubsurface {
@ -381,20 +403,7 @@ impl SurfaceExt for WlSubsurface {
}
fn after_apply_commit(self: Rc<Self>) {
let has_buffer = self.surface.buffer.is_some();
if self.had_buffer.replace(has_buffer) != has_buffer {
if has_buffer {
if self.parent.visible.get() {
self.surface.set_visible(true);
self.damage();
}
} else {
if self.surface.toplevel.is_some() {
self.damage();
}
self.surface.destroy_node();
}
}
self.update_has_buffer();
}
fn subsurface_parent(&self) -> Option<Rc<WlSurface>> {

View file

@ -84,6 +84,7 @@ mod t0050_fifo;
mod t0051_pointer_warp;
mod t0052_bar;
mod t0053_theme;
mod t0054_subsurface_already_attached;
pub trait TestCase: Sync {
fn name(&self) -> &'static str;
@ -156,5 +157,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> {
t0051_pointer_warp,
t0052_bar,
t0053_theme,
t0054_subsurface_already_attached,
}
}

View file

@ -0,0 +1,47 @@
use {
crate::{
it::{test_error::TestError, testrun::TestRun},
theme::Color,
tree::Node,
},
std::rc::Rc,
};
testcase!();
/// Test subsurface with already attached buffer
async fn test(run: Rc<TestRun>) -> Result<(), TestError> {
run.backend.install_default()?;
let seat = run.get_seat("default")?;
run.state.eng.yield_now().await;
run.cfg.show_workspace(seat.id(), "")?;
let client = run.create_client().await?;
let parent = client.create_window().await?;
parent.map().await?;
parent.set_color(0, 0, 0, 255);
let child = client.comp.create_surface().await?;
let buffer = client
.spbm
.create_buffer(Color::from_srgba_straight(255, 255, 255, 255))?;
child.attach(buffer.id)?;
let child_viewport = client.viewporter.get_viewport(&child)?;
child_viewport.set_source(0, 0, 1, 1)?;
child_viewport.set_destination(100, 100)?;
child.commit()?;
let _sub = client
.sub
.get_subsurface(child.id, parent.surface.id)
.await?;
parent.map().await?;
tassert!(child.server.node_visible());
Ok(())
}