Skip to content

Commit

Permalink
refactor(wayland): put everything in wl_surface user data
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Feb 15, 2024
1 parent 8d75334 commit 2834f26
Show file tree
Hide file tree
Showing 16 changed files with 1,298 additions and 1,118 deletions.
58 changes: 22 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ ctrlc = "3.4.1"
libc = "0.2.148"
input-event-codes = "5.16.8"
nix = "0.27.1"
wayland-scanner = "0.31.0"
wayland-backend = "0.3.2"
wayland-scanner = "0.31.1"
wayland-backend = "0.3.3"
cluFlock = "1.2.7"
fxtypemap = "0.2.0"

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ fn adaptive_sleep(
});
}

#[tokio::main]
// #[tokio::main(flavor = "current_thread")]
// #[tokio::main]
#[tokio::main(flavor = "current_thread")]
async fn event_loop(info_sender: oneshot::Sender<EventLoopInfo>) -> color_eyre::eyre::Result<()> {
let socket_path =
server::get_free_socket_path().expect("Unable to find a free stardust socket path");
Expand Down
16 changes: 10 additions & 6 deletions src/nodes/items/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use serde::{
};
use stardust_xr::schemas::flex::{deserialize, serialize};
use std::sync::{Arc, Weak};
use tracing::debug;
use tracing::{debug, info};

lazy_static! {
pub static ref ITEM_TYPE_INFO_PANEL: TypeInfo = TypeInfo {
Expand Down Expand Up @@ -220,17 +220,20 @@ pub struct PanelItem<B: Backend + ?Sized> {
pub backend: Box<B>,
}
impl<B: Backend + ?Sized> PanelItem<B> {
pub fn create(backend: Box<B>, pid: Option<i32>) -> Arc<PanelItem<B>> {
pub fn create(backend: Box<B>, pid: Option<i32>) -> (Arc<Node>, Arc<PanelItem<B>>) {
debug!(?pid, "Create panel item");

let startup_settings = pid
.and_then(|pid| get_env(pid).ok())
.and_then(|env| state(&env));

let uid = nanoid!();
let node = Node::create_parent_name(&INTERNAL_CLIENT, "/item/panel/item", &uid, true)
.add_to_scenegraph()
.unwrap();
let node = Arc::new(Node::create_parent_name(
&INTERNAL_CLIENT,
"/item/panel/item",
&uid,
true,
));
let spatial = Spatial::add_to(&node, None, Mat4::IDENTITY, false);
if let Some(startup_settings) = &startup_settings {
spatial.set_local_transform(startup_settings.root);
Expand Down Expand Up @@ -266,7 +269,7 @@ impl<B: Backend + ?Sized> PanelItem<B> {
node.add_local_signal("touch_up", Self::touch_up_flex);
node.add_local_signal("reset_touches", Self::reset_touches_flex);

panel_item
(node, panel_item)
}
pub fn drop_toplevel(&self) {
let Some(node) = self.node.upgrade() else {
Expand Down Expand Up @@ -593,5 +596,6 @@ impl<B: Backend + ?Sized> Backend for PanelItem<B> {
impl<B: Backend + ?Sized> Drop for PanelItem<B> {
fn drop(&mut self) {
// Dropped panel item, basically just a debug breakpoint place
info!("Dropped panel item {}", self.uid);
}
}
9 changes: 7 additions & 2 deletions src/wayland/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ impl Dispatch<wl_drm::WlDrm, (), WaylandState> for WaylandState {
return;
}

let mut dma = Dmabuf::builder((width, height), format, DmabufFlags::empty());
dma.add_plane(name, 0, offset0 as u32, stride0 as u32, Modifier::Invalid);
let mut dma = Dmabuf::builder(
(width, height),
format,
Modifier::Invalid,
DmabufFlags::empty(),
);
dma.add_plane(name, 0, offset0 as u32, stride0 as u32);
match dma.build() {
Some(dmabuf) => {
state.dmabuf_tx.send((dmabuf.clone(), None)).unwrap();
Expand Down
16 changes: 8 additions & 8 deletions src/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod state;
mod surface;
// mod xdg_activation;
mod drm;
mod utils;
mod xdg_shell;
#[cfg(feature = "xwayland_rootful")]
pub mod xwayland_rootful;
Expand All @@ -30,6 +31,7 @@ use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::egl::EGLContext;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::backend::renderer::ImportDma;
use smithay::output::Output;
use smithay::reexports::wayland_server::backend::ClientId;
use smithay::reexports::wayland_server::DisplayHandle;
use smithay::reexports::wayland_server::{Display, ListeningSocket};
Expand Down Expand Up @@ -97,8 +99,8 @@ pub struct Wayland {
pub socket_name: Option<String>,
join_handle: JoinHandle<Result<()>>,
renderer: GlesRenderer,
output: Output,
dmabuf_rx: UnboundedReceiver<(Dmabuf, Option<dmabuf::ImportNotifier>)>,
wayland_state: Arc<Mutex<WaylandState>>,
#[cfg(feature = "xwayland_rootful")]
pub x_lock: X11Lock,
#[cfg(feature = "xwayland_rootless")]
Expand All @@ -124,6 +126,7 @@ impl Wayland {
#[cfg(feature = "xwayland_rootless")]
let xwayland_state = XWaylandState::create(&display_handle)?;
let wayland_state = WaylandState::new(display_handle, &renderer, dmabuf_tx);
let output = wayland_state.lock().output.clone();

let socket = ListeningSocket::bind_auto("wayland", 0..33)?;
let socket_name = socket
Expand All @@ -137,15 +140,14 @@ impl Wayland {
let x_display = start_xwayland(socket.as_raw_fd())?;
info!(socket_name, "Wayland active");

let join_handle = Wayland::start_loop(display.clone(), socket, wayland_state.clone())?;

let join_handle = Wayland::start_loop(display.clone(), socket, wayland_state)?;
Ok(Wayland {
display,
socket_name,
join_handle,
renderer,
output,
dmabuf_rx,
wayland_state,
#[cfg(feature = "xwayland_rootful")]
x_lock: x_display,
#[cfg(feature = "xwayland_rootless")]
Expand Down Expand Up @@ -185,7 +187,7 @@ impl Wayland {
e = dispatch_poll_listener.readable() => { // Dispatch
let mut guard = e?;
debug_span!("Dispatch wayland event").in_scope(|| -> Result<(), color_eyre::Report> {
display.dispatch_clients(&mut *state.lock())?;
display.dispatch_clients(&mut state.lock())?;
display.flush_clients(None);
Ok(())
})?;
Expand Down Expand Up @@ -213,10 +215,8 @@ impl Wayland {
}

pub fn frame_event(&self, sk: &impl StereoKitDraw) {
let output = self.wayland_state.lock().output.clone();

for core_surface in CORE_SURFACES.get_valid_contents() {
core_surface.frame(sk, output.clone());
core_surface.frame(sk, self.output.clone());
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/wayland/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use smithay::{
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as DecorationMode,
wayland_server::{
backend::{ClientData, ClientId, DisconnectReason},
protocol::{wl_buffer::WlBuffer, wl_data_device_manager::WlDataDeviceManager},
protocol::{
wl_buffer::WlBuffer, wl_data_device_manager::WlDataDeviceManager,
wl_output::WlOutput,
},
DisplayHandle,
},
},
Expand All @@ -29,6 +32,7 @@ use smithay::{
dmabuf::{
self, DmabufFeedback, DmabufFeedbackBuilder, DmabufGlobal, DmabufHandler, DmabufState,
},
output::OutputHandler,
shell::kde::decoration::KdeDecorationState,
shm::{ShmHandler, ShmState},
},
Expand Down Expand Up @@ -201,6 +205,9 @@ impl DmabufHandler for WaylandState {
self.dmabuf_tx.send((dmabuf, Some(notifier))).unwrap();
}
}
impl OutputHandler for WaylandState {
fn output_bound(&mut self, _output: Output, _wl_output: WlOutput) {}
}
delegate_dmabuf!(WaylandState);
delegate_shm!(WaylandState);
delegate_output!(WaylandState);
Loading

0 comments on commit 2834f26

Please sign in to comment.