refactor(wayland): move surface id to wl_surface

This commit is contained in:
Nova
2025-09-05 17:04:59 -07:00
parent c5440bc426
commit 7314428ce7
3 changed files with 16 additions and 7 deletions

View File

@@ -2,7 +2,10 @@ use super::{buffer::Buffer, callback::Callback};
use crate::{ use crate::{
BevyMaterial, BevyMaterial,
core::registry::Registry, core::registry::Registry,
nodes::{drawable::model::ModelPart, items::panel::Geometry}, nodes::{
drawable::model::ModelPart,
items::panel::{Geometry, SurfaceId},
},
wayland::{ wayland::{
Message, MessageSink, Message, MessageSink,
core::buffer::BufferUsage, core::buffer::BufferUsage,
@@ -70,10 +73,10 @@ impl Default for SurfaceState {
// if returning false, don't run this callback again... just remove it // if returning false, don't run this callback again... just remove it
pub type OnCommitCallback = Box<dyn Fn(&Surface, &SurfaceState) -> bool + Send + Sync>; pub type OnCommitCallback = Box<dyn Fn(&Surface, &SurfaceState) -> bool + Send + Sync>;
#[derive(Dispatcher)] #[derive(Dispatcher)]
pub struct Surface { pub struct Surface {
pub id: ObjectId, pub id: ObjectId,
pub surface_id: OnceLock<SurfaceId>,
state: Mutex<DoubleBuffer<SurfaceState>>, state: Mutex<DoubleBuffer<SurfaceState>>,
pub message_sink: MessageSink, pub message_sink: MessageSink,
pub role: OnceLock<SurfaceRole>, pub role: OnceLock<SurfaceRole>,
@@ -85,6 +88,8 @@ pub struct Surface {
impl std::fmt::Debug for Surface { impl std::fmt::Debug for Surface {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Surface") f.debug_struct("Surface")
.field("id", &self.id)
.field("surface_id", &self.surface_id)
.field("state", &self.state) .field("state", &self.state)
.field("message_sink", &self.message_sink) .field("message_sink", &self.message_sink)
.field("role", &self.role) .field("role", &self.role)
@@ -92,6 +97,8 @@ impl std::fmt::Debug for Surface {
"on_commit_handlers", "on_commit_handlers",
&format!("<{} handlers>", self.on_commit_handlers.lock().len()), &format!("<{} handlers>", self.on_commit_handlers.lock().len()),
) )
.field("material", &self.material)
.field("presentation_feedback", &self.presentation_feedback)
.finish() .finish()
} }
} }
@@ -100,6 +107,7 @@ impl Surface {
pub fn new(client: &Client, id: ObjectId) -> Self { pub fn new(client: &Client, id: ObjectId) -> Self {
Surface { Surface {
id, id,
surface_id: OnceLock::new(),
state: Default::default(), state: Default::default(),
message_sink: client.message_sink(), message_sink: client.message_sink(),
role: OnceLock::new(), role: OnceLock::new(),

View File

@@ -19,7 +19,6 @@ use waynest::{
pub struct Popup { pub struct Popup {
id: ObjectId, id: ObjectId,
version: u32, version: u32,
surface_id: SurfaceId,
parent: Arc<Surface>, parent: Arc<Surface>,
surface: Weak<Surface>, surface: Weak<Surface>,
pub panel_item: Weak<PanelItem<XdgBackend>>, pub panel_item: Weak<PanelItem<XdgBackend>>,
@@ -36,11 +35,15 @@ impl Popup {
xdg_surface: &Arc<Surface>, xdg_surface: &Arc<Surface>,
positioner: &Positioner, positioner: &Positioner,
) -> Self { ) -> Self {
xdg_surface
.wl_surface()
.surface_id
.set(SurfaceId::Child(rand::thread_rng().gen_range(0..u64::MAX)));
let positioner_data = positioner.data(); let positioner_data = positioner.data();
Self { Self {
id, id,
version, version,
surface_id: SurfaceId::Child(rand::thread_rng().gen_range(0..u64::MAX)),
parent, parent,
surface: Arc::downgrade(xdg_surface), surface: Arc::downgrade(xdg_surface),
panel_item: Arc::downgrade(panel_item), panel_item: Arc::downgrade(panel_item),

View File

@@ -5,9 +5,7 @@ use crate::wayland::{
display::Display, display::Display,
xdg::{toplevel::Toplevel, wm_base::XdgSurfaceRole}, xdg::{toplevel::Toplevel, wm_base::XdgSurfaceRole},
}; };
use std::sync::Arc; use std::sync::{Arc, OnceLock, Weak};
use std::sync::OnceLock;
use std::sync::Weak;
pub use waynest::server::protocol::stable::xdg_shell::xdg_surface::*; pub use waynest::server::protocol::stable::xdg_shell::xdg_surface::*;
use waynest::{ use waynest::{
server::{Client, Dispatcher, Result}, server::{Client, Dispatcher, Result},