From 21e636aabf6633faf8f4e505718d10cc56adc879 Mon Sep 17 00:00:00 2001 From: drendog Date: Sat, 6 Dec 2025 03:26:01 +0100 Subject: [PATCH] refactor: rename window to surface to avoid misleading --- crates/adapters/src/lib.rs | 6 +- .../wayland/event_handling/app_dispatcher.rs | 62 ++++---- .../event_handling/event_dispatcher.rs | 4 +- crates/adapters/src/wayland/facade.rs | 14 +- .../adapters/src/wayland/globals/context.rs | 3 +- .../src/wayland/outputs/output_manager.rs | 18 +-- crates/adapters/src/wayland/shell_adapter.rs | 65 ++++---- .../src/wayland/surfaces/app_state.rs | 115 +++++++------- .../src/wayland/surfaces/event_context.rs | 14 +- crates/adapters/src/wayland/surfaces/mod.rs | 2 +- .../src/wayland/surfaces/popup_manager.rs | 37 ++--- .../src/wayland/surfaces/rendering_state.rs | 8 +- .../src/wayland/surfaces/surface_builder.rs | 12 +- ...window_renderer.rs => surface_renderer.rs} | 8 +- .../src/wayland/surfaces/surface_state.rs | 18 +-- crates/composition/src/event_loop.rs | 6 +- crates/composition/src/layer_shika.rs | 150 +++++++++--------- crates/composition/src/layer_surface.rs | 6 +- crates/composition/src/lib.rs | 4 +- crates/composition/src/shell.rs | 102 ++++++------ crates/composition/src/system.rs | 88 +++++----- crates/domain/src/ports/mod.rs | 2 +- .../src/ports/{windowing.rs => shell.rs} | 2 +- examples/event-loop/src/channel.rs | 8 +- examples/event-loop/src/custom_source.rs | 8 +- examples/event-loop/src/timer.rs | 8 +- src/lib.rs | 2 +- src/prelude.rs | 2 +- src/shell.rs | 2 +- 29 files changed, 390 insertions(+), 386 deletions(-) rename crates/adapters/src/wayland/surfaces/{window_renderer.rs => surface_renderer.rs} (96%) rename crates/domain/src/ports/{windowing.rs => shell.rs} (85%) diff --git a/crates/adapters/src/lib.rs b/crates/adapters/src/lib.rs index 2b88827..ee48f61 100644 --- a/crates/adapters/src/lib.rs +++ b/crates/adapters/src/lib.rs @@ -7,11 +7,11 @@ pub(crate) mod wayland; pub use rendering::femtovg::popup_window::PopupWindow; pub use wayland::config::{MultiSurfaceConfig, ShellSurfaceConfig, WaylandSurfaceConfig}; -pub use wayland::facade::WindowingSystemFacade; -pub use wayland::shell_adapter::WaylandWindowingSystem; +pub use wayland::facade::ShellSystemFacade; +pub use wayland::shell_adapter::WaylandShellSystem; pub use wayland::surfaces::app_state::AppState; pub use wayland::surfaces::popup_manager::PopupManager; -pub use wayland::surfaces::surface_state::WindowState; +pub use wayland::surfaces::surface_state::SurfaceState; pub mod platform { pub use slint; diff --git a/crates/adapters/src/wayland/event_handling/app_dispatcher.rs b/crates/adapters/src/wayland/event_handling/app_dispatcher.rs index 8e008e4..5e51558 100644 --- a/crates/adapters/src/wayland/event_handling/app_dispatcher.rs +++ b/crates/adapters/src/wayland/event_handling/app_dispatcher.rs @@ -1,6 +1,6 @@ use crate::wayland::surfaces::app_state::AppState; use crate::wayland::surfaces::display_metrics::DisplayMetrics; -use crate::wayland::surfaces::surface_state::WindowState; +use crate::wayland::surfaces::surface_state::SurfaceState; use layer_shika_domain::value_objects::output_info::OutputGeometry; use log::{debug, info}; use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::{ @@ -50,7 +50,7 @@ impl Dispatch for AppState { height, } => { let layer_surface_id = layer_surface.id(); - let Some(window) = state.get_output_by_layer_surface_mut(&layer_surface_id) else { + let Some(surface) = state.get_output_by_layer_surface_mut(&layer_surface_id) else { info!( "Could not find window for layer surface {:?}", layer_surface_id @@ -58,12 +58,12 @@ impl Dispatch for AppState { return; }; - window.handle_layer_surface_configure(layer_surface, serial, width, height); + surface.handle_layer_surface_configure(layer_surface, serial, width, height); } zwlr_layer_surface_v1::Event::Closed => { let layer_surface_id = layer_surface.id(); - if let Some(window) = state.get_output_by_layer_surface_mut(&layer_surface_id) { - window.handle_layer_surface_closed(); + if let Some(surface) = state.get_output_by_layer_surface_mut(&layer_surface_id) { + surface.handle_layer_surface_closed(); } } _ => {} @@ -98,8 +98,8 @@ impl Dispatch for AppState { width, height, is_current, is_preferred ); if is_current { - for window in state.all_windows_for_output_mut(&output_id) { - window.handle_output_mode(width, height); + for surface in state.all_surfaces_for_output_mut(&output_id) { + surface.handle_output_mode(width, height); } } } @@ -203,13 +203,13 @@ impl Dispatch for AppState { let surface_id = surface.id(); if let Some(key) = state.get_key_by_surface(&surface_id).cloned() { - if let Some(window) = state.get_window_by_key_mut(&key) { - window.handle_pointer_enter(serial, &surface, surface_x, surface_y); + if let Some(layer_surface) = state.get_surface_by_key_mut(&key) { + layer_surface.handle_pointer_enter(serial, &surface, surface_x, surface_y); } state.set_active_surface_key(Some(key)); } else if let Some(key) = state.get_key_by_popup(&surface_id).cloned() { - if let Some(window) = state.get_window_by_key_mut(&key) { - window.handle_pointer_enter(serial, &surface, surface_x, surface_y); + if let Some(layer_surface) = state.get_surface_by_key_mut(&key) { + layer_surface.handle_pointer_enter(serial, &surface, surface_x, surface_y); } state.set_active_surface_key(Some(key)); } @@ -220,14 +220,14 @@ impl Dispatch for AppState { surface_y, .. } => { - if let Some(window) = state.active_surface_mut() { - window.handle_pointer_motion(surface_x, surface_y); + if let Some(surface) = state.active_surface_mut() { + surface.handle_pointer_motion(surface_x, surface_y); } } wl_pointer::Event::Leave { .. } => { - if let Some(window) = state.active_surface_mut() { - window.handle_pointer_leave(); + if let Some(surface) = state.active_surface_mut() { + surface.handle_pointer_leave(); } state.set_active_surface_key(None); } @@ -237,8 +237,8 @@ impl Dispatch for AppState { state: button_state, .. } => { - if let Some(window) = state.active_surface_mut() { - window.handle_pointer_button(serial, button_state); + if let Some(surface) = state.active_surface_mut() { + surface.handle_pointer_button(serial, button_state); } } _ => {} @@ -259,8 +259,8 @@ impl Dispatch for AppState { let scale_float = DisplayMetrics::scale_factor_from_120ths(scale); info!("Fractional scale received: {scale_float} ({scale}x)"); - for window in state.all_outputs_mut() { - window.handle_fractional_scale(proxy, scale); + for surface in state.all_outputs_mut() { + surface.handle_fractional_scale(proxy, scale); } } } @@ -276,7 +276,7 @@ impl Dispatch for AppState { _qhandle: &QueueHandle, ) { if let xdg_wm_base::Event::Ping { serial } = event { - WindowState::handle_xdg_wm_base_ping(xdg_wm_base, serial); + SurfaceState::handle_xdg_wm_base_ping(xdg_wm_base, serial); } } } @@ -298,10 +298,10 @@ impl Dispatch for AppState { height, } => { let popup_id = xdg_popup.id(); - for window in state.all_outputs_mut() { - if let Some(popup_manager) = window.popup_manager() { + for surface in state.all_outputs_mut() { + if let Some(popup_manager) = surface.popup_manager() { if popup_manager.find_by_xdg_popup(&popup_id).is_some() { - window.handle_xdg_popup_configure(xdg_popup, x, y, width, height); + surface.handle_xdg_popup_configure(xdg_popup, x, y, width, height); break; } } @@ -311,14 +311,14 @@ impl Dispatch for AppState { info!("XdgPopup dismissed by compositor"); let popup_id = xdg_popup.id(); - for window in state.all_outputs_mut() { - let popup_handle = window + for surface in state.all_outputs_mut() { + let popup_handle = surface .popup_manager() .as_ref() .and_then(|pm| pm.find_by_xdg_popup(&popup_id)); if popup_handle.is_some() { - window.handle_xdg_popup_done(xdg_popup); + surface.handle_xdg_popup_done(xdg_popup); break; } } @@ -327,8 +327,8 @@ impl Dispatch for AppState { info!("XdgPopup repositioned with token {token}"); let popup_id = xdg_popup.id(); - for window in state.all_outputs_mut() { - if let Some(popup_manager) = window.popup_manager() { + for surface in state.all_outputs_mut() { + if let Some(popup_manager) = surface.popup_manager() { if let Some(handle) = popup_manager.find_by_xdg_popup(&popup_id) { info!("Committing popup surface after reposition"); popup_manager.commit_popup_surface(handle.key()); @@ -353,10 +353,10 @@ impl Dispatch for AppState { ) { if let xdg_surface::Event::Configure { serial } = event { let xdg_surface_id = xdg_surface.id(); - for window in state.all_outputs_mut() { - if let Some(popup_manager) = window.popup_manager() { + for surface in state.all_outputs_mut() { + if let Some(popup_manager) = surface.popup_manager() { if popup_manager.find_by_xdg_surface(&xdg_surface_id).is_some() { - window.handle_xdg_surface_configure(xdg_surface, serial); + surface.handle_xdg_surface_configure(xdg_surface, serial); break; } } diff --git a/crates/adapters/src/wayland/event_handling/event_dispatcher.rs b/crates/adapters/src/wayland/event_handling/event_dispatcher.rs index 9187d18..d51871d 100644 --- a/crates/adapters/src/wayland/event_handling/event_dispatcher.rs +++ b/crates/adapters/src/wayland/event_handling/event_dispatcher.rs @@ -1,4 +1,4 @@ -use crate::wayland::surfaces::surface_state::WindowState; +use crate::wayland::surfaces::surface_state::SurfaceState; use log::info; use slint::{ PhysicalSize, @@ -24,7 +24,7 @@ use wayland_protocols::xdg::shell::client::{ xdg_wm_base::XdgWmBase, }; -impl WindowState { +impl SurfaceState { #[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_sign_loss)] #[allow(clippy::cast_precision_loss)] diff --git a/crates/adapters/src/wayland/facade.rs b/crates/adapters/src/wayland/facade.rs index f6f0aa0..e14512c 100644 --- a/crates/adapters/src/wayland/facade.rs +++ b/crates/adapters/src/wayland/facade.rs @@ -1,21 +1,21 @@ use crate::errors::Result; -use crate::wayland::shell_adapter::WaylandWindowingSystem; +use crate::wayland::shell_adapter::WaylandShellSystem; use slint_interpreter::ComponentInstance; -pub struct WindowingSystemFacade { - inner: WaylandWindowingSystem, +pub struct ShellSystemFacade { + inner: WaylandShellSystem, } -impl WindowingSystemFacade { - pub fn new(inner: WaylandWindowingSystem) -> Self { +impl ShellSystemFacade { + pub fn new(inner: WaylandShellSystem) -> Self { Self { inner } } - pub fn inner_ref(&self) -> &WaylandWindowingSystem { + pub fn inner_ref(&self) -> &WaylandShellSystem { &self.inner } - pub fn inner_mut(&mut self) -> &mut WaylandWindowingSystem { + pub fn inner_mut(&mut self) -> &mut WaylandShellSystem { &mut self.inner } diff --git a/crates/adapters/src/wayland/globals/context.rs b/crates/adapters/src/wayland/globals/context.rs index 29cfec4..42055c3 100644 --- a/crates/adapters/src/wayland/globals/context.rs +++ b/crates/adapters/src/wayland/globals/context.rs @@ -105,8 +105,7 @@ impl GlobalContext { info!("Viewporter protocol not available"); } - let render_context_manager = - RenderContextManager::new(&connection.display().id())?; + let render_context_manager = RenderContextManager::new(&connection.display().id())?; Ok(Self { compositor, diff --git a/crates/adapters/src/wayland/outputs/output_manager.rs b/crates/adapters/src/wayland/outputs/output_manager.rs index 5207ab3..aa57354 100644 --- a/crates/adapters/src/wayland/outputs/output_manager.rs +++ b/crates/adapters/src/wayland/outputs/output_manager.rs @@ -3,14 +3,14 @@ use crate::{ rendering::egl::context_factory::RenderContextFactory, wayland::{ config::{LayerSurfaceConfig, WaylandSurfaceConfig}, - shell_adapter::WaylandWindowingSystem, + shell_adapter::WaylandShellSystem, surfaces::{ app_state::AppState, event_context::SharedPointerSerial, layer_surface::{SurfaceCtx, SurfaceSetupParams}, popup_manager::{PopupContext, PopupManager}, - surface_builder::WindowStateBuilder, - surface_state::WindowState, + surface_builder::SurfaceStateBuilder, + surface_state::SurfaceState, }, }, }; @@ -141,14 +141,14 @@ impl OutputManager { output_id, is_primary ); - let (window, main_surface_id) = + let (surface, main_surface_id) = self.create_window_for_output(&pending_output.proxy, output_id, queue_handle)?; app_state.add_output( output_id, &self.config.surface_name, main_surface_id, - window, + surface, ); Ok(()) @@ -159,7 +159,7 @@ impl OutputManager { output: &WlOutput, _output_id: &ObjectId, queue_handle: &QueueHandle, - ) -> Result<(WindowState, ObjectId)> { + ) -> Result<(SurfaceState, ObjectId)> { let setup_params = SurfaceSetupParams { compositor: &self.context.compositor, output, @@ -174,13 +174,13 @@ impl OutputManager { let surface_ctx = SurfaceCtx::setup(&setup_params, &self.layer_surface_config); let main_surface_id = surface_ctx.surface.id(); - let window = WaylandWindowingSystem::initialize_renderer( + let window = WaylandShellSystem::initialize_renderer( &surface_ctx.surface, &self.config, &self.context.render_factory, )?; - let mut builder = WindowStateBuilder::new() + let mut builder = SurfaceStateBuilder::new() .with_component_definition(self.config.component_definition.clone()) .with_compilation_result(self.config.compilation_result.clone()) .with_surface(Rc::clone(&surface_ctx.surface)) @@ -202,7 +202,7 @@ impl OutputManager { } let mut window_state = - WindowState::new(builder).map_err(|e| LayerShikaError::WindowConfiguration { + SurfaceState::new(builder).map_err(|e| LayerShikaError::WindowConfiguration { message: e.to_string(), })?; diff --git a/crates/adapters/src/wayland/shell_adapter.rs b/crates/adapters/src/wayland/shell_adapter.rs index 9753d92..510e3d0 100644 --- a/crates/adapters/src/wayland/shell_adapter.rs +++ b/crates/adapters/src/wayland/shell_adapter.rs @@ -8,8 +8,8 @@ use crate::wayland::{ surfaces::{ app_state::AppState, event_context::SharedPointerSerial, - surface_builder::{PlatformWrapper, WindowStateBuilder}, - surface_state::WindowState, + surface_builder::{PlatformWrapper, SurfaceStateBuilder}, + surface_state::SurfaceState, }, }; use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1; @@ -23,7 +23,7 @@ use crate::{ }; use core::result::Result as CoreResult; use layer_shika_domain::errors::DomainError; -use layer_shika_domain::ports::windowing::WindowingSystemPort; +use layer_shika_domain::ports::shell::ShellSystemPort; use layer_shika_domain::value_objects::output_handle::OutputHandle; use layer_shika_domain::value_objects::output_info::OutputInfo; use log::{error, info}; @@ -49,7 +49,7 @@ struct OutputSetup { output_id: ObjectId, main_surface_id: ObjectId, window: Rc, - builder: WindowStateBuilder, + builder: SurfaceStateBuilder, shell_surface_name: String, } @@ -64,14 +64,14 @@ struct OutputManagerParams<'a> { shared_serial: &'a Rc, } -pub struct WaylandWindowingSystem { +pub struct WaylandShellSystem { state: AppState, connection: Rc, event_queue: EventQueue, event_loop: EventLoop<'static, AppState>, } -impl WaylandWindowingSystem { +impl WaylandShellSystem { pub fn new(config: &WaylandSurfaceConfig) -> Result { info!("Initializing WindowingSystem"); let (connection, mut event_queue) = Self::init_wayland_connection()?; @@ -172,7 +172,7 @@ impl WaylandWindowingSystem { let window = Self::initialize_renderer(&surface_ctx.surface, config, &render_factory)?; - let mut builder = WindowStateBuilder::new() + let mut builder = SurfaceStateBuilder::new() .with_component_definition(config.component_definition.clone()) .with_compilation_result(config.compilation_result.clone()) .with_surface(Rc::clone(&surface_ctx.surface)) @@ -234,7 +234,7 @@ impl WaylandWindowingSystem { let mut layer_surfaces = Vec::new(); for setup in setups { - let mut per_output_window = WindowState::new(setup.builder).map_err(|e| { + let mut per_output_surface = SurfaceState::new(setup.builder).map_err(|e| { LayerShikaError::WindowConfiguration { message: e.to_string(), } @@ -242,20 +242,20 @@ impl WaylandWindowingSystem { let popup_manager = Rc::new(PopupManager::new( popup_context.clone(), - Rc::clone(per_output_window.display_metrics()), + Rc::clone(per_output_surface.display_metrics()), )); - per_output_window.set_popup_manager(Rc::clone(&popup_manager)); - per_output_window.set_shared_pointer_serial(Rc::clone(shared_serial)); + per_output_surface.set_popup_manager(Rc::clone(&popup_manager)); + per_output_surface.set_shared_pointer_serial(Rc::clone(shared_serial)); popup_managers.push(Rc::clone(&popup_manager)); - layer_surfaces.push(per_output_window.layer_surface()); + layer_surfaces.push(per_output_surface.layer_surface()); app_state.add_shell_surface( &setup.output_id, &setup.shell_surface_name, setup.main_surface_id, - per_output_window, + per_output_surface, ); } @@ -447,7 +447,7 @@ impl WaylandWindowingSystem { let window = Self::initialize_renderer(&surface_ctx.surface, config, &render_factory)?; - let mut builder = WindowStateBuilder::new() + let mut builder = SurfaceStateBuilder::new() .with_component_definition(config.component_definition.clone()) .with_compilation_result(config.compilation_result.clone()) .with_surface(Rc::clone(&surface_ctx.surface)) @@ -542,14 +542,14 @@ impl WaylandWindowingSystem { if popup_manager.has_pending_popup() { info!("Found pending popup in output #{}", idx); - let popup_window = popup_manager + let popup_surface = popup_manager .create_pending_popup(&queue_handle_clone, layer_surface, serial) .map_err(|e| { PlatformError::Other(format!("Failed to create popup: {e}")) })?; info!("Popup created successfully for output #{}", idx); - return Ok(popup_window as Rc); + return Ok(popup_surface as Rc); } } @@ -594,23 +594,22 @@ impl WaylandWindowingSystem { update_timers_and_animations(); - for window in self.state.all_outputs() { - window - .window() - .render_frame_if_dirty() - .map_err(|e| RenderingError::Operation { + for surface in self.state.all_outputs() { + surface.window().render_frame_if_dirty().map_err(|e| { + RenderingError::Operation { message: e.to_string(), - })?; + } + })?; } } info!("Initial configuration complete, requesting final render"); - for window in self.state.all_outputs() { - RenderableWindow::request_redraw(window.window().as_ref()); + for surface in self.state.all_outputs() { + RenderableWindow::request_redraw(surface.window().as_ref()); } update_timers_and_animations(); - for window in self.state.all_outputs() { - window + for surface in self.state.all_outputs() { + surface .window() .render_frame_if_dirty() .map_err(|e| RenderingError::Operation { @@ -668,15 +667,15 @@ impl WaylandWindowingSystem { update_timers_and_animations(); - for window in shared_data.all_outputs() { - window + for surface in shared_data.all_outputs() { + surface .window() .render_frame_if_dirty() .map_err(|e| RenderingError::Operation { message: e.to_string(), })?; - if let Some(popup_manager) = window.popup_manager() { + if let Some(popup_manager) = surface.popup_manager() { popup_manager .render_popups() .map_err(|e| RenderingError::Operation { @@ -698,10 +697,10 @@ impl WaylandWindowingSystem { .ok_or_else(|| LayerShikaError::InvalidInput { message: "No outputs available".into(), }) - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } - pub fn state(&self) -> Result<&WindowState> { + pub fn state(&self) -> Result<&SurfaceState> { self.state .primary_output() .ok_or_else(|| LayerShikaError::InvalidInput { @@ -714,9 +713,9 @@ impl WaylandWindowingSystem { } } -impl WindowingSystemPort for WaylandWindowingSystem { +impl ShellSystemPort for WaylandShellSystem { fn run(&mut self) -> CoreResult<(), DomainError> { - WaylandWindowingSystem::run(self).map_err(|e| DomainError::Adapter { + WaylandShellSystem::run(self).map_err(|e| DomainError::Adapter { source: Box::new(e), }) } diff --git a/crates/adapters/src/wayland/surfaces/app_state.rs b/crates/adapters/src/wayland/surfaces/app_state.rs index 6aaa91c..72d6279 100644 --- a/crates/adapters/src/wayland/surfaces/app_state.rs +++ b/crates/adapters/src/wayland/surfaces/app_state.rs @@ -1,5 +1,5 @@ use super::event_context::SharedPointerSerial; -use super::surface_state::WindowState; +use super::surface_state::SurfaceState; use crate::wayland::managed_proxies::ManagedWlPointer; use crate::wayland::outputs::{OutputManager, OutputMapping}; use layer_shika_domain::entities::output_registry::OutputRegistry; @@ -11,7 +11,7 @@ use std::rc::Rc; use wayland_client::Proxy; use wayland_client::backend::ObjectId; -pub type PerOutputWindow = WindowState; +pub type PerOutputSurface = SurfaceState; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ShellSurfaceKey { @@ -31,7 +31,7 @@ impl ShellSurfaceKey { pub struct AppState { output_registry: OutputRegistry, output_mapping: OutputMapping, - surfaces: HashMap, + surfaces: HashMap, surface_to_key: HashMap, _pointer: ManagedWlPointer, shared_pointer_serial: Rc, @@ -80,7 +80,7 @@ impl AppState { output_id: &ObjectId, surface_name: &str, main_surface_id: ObjectId, - surface_state: PerOutputWindow, + surface_state: PerOutputSurface, ) { let handle = self.output_mapping.get(output_id).unwrap_or_else(|| { let h = self.output_mapping.insert(output_id.clone()); @@ -101,12 +101,12 @@ impl AppState { output_id: &ObjectId, surface_name: &str, main_surface_id: ObjectId, - surface_state: PerOutputWindow, + surface_state: PerOutputSurface, ) { self.add_shell_surface(output_id, surface_name, main_surface_id, surface_state); } - pub fn remove_output(&mut self, handle: OutputHandle) -> Vec { + pub fn remove_output(&mut self, handle: OutputHandle) -> Vec { self.output_registry.remove(handle); let keys_to_remove: Vec<_> = self @@ -118,8 +118,8 @@ impl AppState { let mut removed = Vec::new(); for key in keys_to_remove { - if let Some(window) = self.surfaces.remove(&key) { - removed.push(window); + if let Some(surface) = self.surfaces.remove(&key) { + removed.push(surface); } } @@ -128,65 +128,68 @@ impl AppState { removed } - pub fn get_window_by_key(&self, key: &ShellSurfaceKey) -> Option<&PerOutputWindow> { + pub fn get_surface_by_key(&self, key: &ShellSurfaceKey) -> Option<&PerOutputSurface> { self.surfaces.get(key) } - pub fn get_window_by_key_mut(&mut self, key: &ShellSurfaceKey) -> Option<&mut PerOutputWindow> { + pub fn get_surface_by_key_mut( + &mut self, + key: &ShellSurfaceKey, + ) -> Option<&mut PerOutputSurface> { self.surfaces.get_mut(key) } - pub fn get_window_by_name( + pub fn get_surface_by_name( &self, output_handle: OutputHandle, shell_window_name: &str, - ) -> Option<&PerOutputWindow> { + ) -> Option<&PerOutputSurface> { let key = ShellSurfaceKey::new(output_handle, shell_window_name); self.surfaces.get(&key) } - pub fn get_window_by_name_mut( + pub fn get_surface_by_name_mut( &mut self, output_handle: OutputHandle, shell_window_name: &str, - ) -> Option<&mut PerOutputWindow> { + ) -> Option<&mut PerOutputSurface> { let key = ShellSurfaceKey::new(output_handle, shell_window_name); self.surfaces.get_mut(&key) } - pub fn get_output_by_output_id(&self, output_id: &ObjectId) -> Option<&PerOutputWindow> { + pub fn get_output_by_output_id(&self, output_id: &ObjectId) -> Option<&PerOutputSurface> { self.output_mapping .get(output_id) - .and_then(|handle| self.get_first_window_for_output(handle)) + .and_then(|handle| self.get_first_surface_for_output(handle)) } pub fn get_output_by_output_id_mut( &mut self, output_id: &ObjectId, - ) -> Option<&mut PerOutputWindow> { + ) -> Option<&mut PerOutputSurface> { self.output_mapping .get(output_id) - .and_then(|handle| self.get_first_window_for_output_mut(handle)) + .and_then(|handle| self.get_first_surface_for_output_mut(handle)) } - fn get_first_window_for_output(&self, handle: OutputHandle) -> Option<&PerOutputWindow> { + fn get_first_surface_for_output(&self, handle: OutputHandle) -> Option<&PerOutputSurface> { self.surfaces .iter() .find(|(k, _)| k.output_handle == handle) .map(|(_, v)| v) } - fn get_first_window_for_output_mut( + fn get_first_surface_for_output_mut( &mut self, handle: OutputHandle, - ) -> Option<&mut PerOutputWindow> { + ) -> Option<&mut PerOutputSurface> { self.surfaces .iter_mut() .find(|(k, _)| k.output_handle == handle) .map(|(_, v)| v) } - pub fn get_output_by_surface(&self, surface_id: &ObjectId) -> Option<&PerOutputWindow> { + pub fn get_output_by_surface(&self, surface_id: &ObjectId) -> Option<&PerOutputSurface> { self.surface_to_key .get(surface_id) .and_then(|key| self.surfaces.get(key)) @@ -195,7 +198,7 @@ impl AppState { pub fn get_output_by_surface_mut( &mut self, surface_id: &ObjectId, - ) -> Option<&mut PerOutputWindow> { + ) -> Option<&mut PerOutputSurface> { self.surface_to_key .get(surface_id) .and_then(|key| self.surfaces.get_mut(key)) @@ -204,10 +207,10 @@ impl AppState { pub fn get_output_by_layer_surface_mut( &mut self, layer_surface_id: &ObjectId, - ) -> Option<&mut PerOutputWindow> { + ) -> Option<&mut PerOutputSurface> { self.surfaces .values_mut() - .find(|window| window.layer_surface().as_ref().id() == *layer_surface_id) + .find(|surface| surface.layer_surface().as_ref().id() == *layer_surface_id) } pub fn get_key_by_surface(&self, surface_id: &ObjectId) -> Option<&ShellSurfaceKey> { @@ -245,46 +248,48 @@ impl AppState { self.active_surface_key.as_ref() } - pub fn active_surface_mut(&mut self) -> Option<&mut PerOutputWindow> { + pub fn active_surface_mut(&mut self) -> Option<&mut PerOutputSurface> { let key = self.active_surface_key.clone()?; self.surfaces.get_mut(&key) } - pub fn primary_output(&self) -> Option<&PerOutputWindow> { + pub fn primary_output(&self) -> Option<&PerOutputSurface> { self.output_registry .primary_handle() - .and_then(|handle| self.get_first_window_for_output(handle)) + .and_then(|handle| self.get_first_surface_for_output(handle)) } pub fn primary_output_handle(&self) -> Option { self.output_registry.primary_handle() } - pub fn active_output(&self) -> Option<&PerOutputWindow> { + pub fn active_output(&self) -> Option<&PerOutputSurface> { self.output_registry .active_handle() - .and_then(|handle| self.get_first_window_for_output(handle)) + .and_then(|handle| self.get_first_surface_for_output(handle)) } - pub fn all_outputs(&self) -> impl Iterator { + pub fn all_outputs(&self) -> impl Iterator { self.surfaces.values() } - pub fn all_outputs_mut(&mut self) -> impl Iterator { + pub fn all_outputs_mut(&mut self) -> impl Iterator { self.surfaces.values_mut() } - pub fn windows_for_output( + pub fn surfaces_for_output( &self, handle: OutputHandle, - ) -> impl Iterator { + ) -> impl Iterator { self.surfaces .iter() .filter(move |(k, _)| k.output_handle == handle) .map(|(k, v)| (k.surface_name.as_str(), v)) } - pub fn windows_with_keys(&self) -> impl Iterator { + pub fn surfaces_with_keys( + &self, + ) -> impl Iterator { self.surfaces.iter() } @@ -292,9 +297,9 @@ impl AppState { &self.shared_pointer_serial } - pub fn find_output_by_popup(&self, popup_surface_id: &ObjectId) -> Option<&PerOutputWindow> { - self.surfaces.values().find(|window| { - window + pub fn find_output_by_popup(&self, popup_surface_id: &ObjectId) -> Option<&PerOutputSurface> { + self.surfaces.values().find(|surface| { + surface .popup_manager() .as_ref() .and_then(|pm| pm.find_by_surface(popup_surface_id)) @@ -305,9 +310,9 @@ impl AppState { pub fn find_output_by_popup_mut( &mut self, popup_surface_id: &ObjectId, - ) -> Option<&mut PerOutputWindow> { - self.surfaces.values_mut().find(|window| { - window + ) -> Option<&mut PerOutputSurface> { + self.surfaces.values_mut().find(|surface| { + surface .popup_manager() .as_ref() .and_then(|pm| pm.find_by_surface(popup_surface_id)) @@ -316,8 +321,8 @@ impl AppState { } pub fn get_key_by_popup(&self, popup_surface_id: &ObjectId) -> Option<&ShellSurfaceKey> { - self.surfaces.iter().find_map(|(key, window)| { - window + self.surfaces.iter().find_map(|(key, surface)| { + surface .popup_manager() .as_ref() .and_then(|pm| pm.find_by_surface(popup_surface_id)) @@ -333,8 +338,8 @@ impl AppState { pub fn get_output_by_handle_mut( &mut self, handle: OutputHandle, - ) -> Option<&mut PerOutputWindow> { - self.get_first_window_for_output_mut(handle) + ) -> Option<&mut PerOutputSurface> { + self.get_first_surface_for_output_mut(handle) } pub fn get_output_info(&self, handle: OutputHandle) -> Option<&OutputInfo> { @@ -364,35 +369,35 @@ impl AppState { names } - pub fn surfaces_by_name(&self, surface_name: &str) -> impl Iterator { + pub fn surfaces_by_name(&self, surface_name: &str) -> impl Iterator { self.surfaces .iter() .filter(move |(k, _)| k.surface_name == surface_name) .map(|(_, v)| v) } - pub fn get_output_by_handle(&self, handle: OutputHandle) -> Option<&PerOutputWindow> { - self.get_first_window_for_output(handle) + pub fn get_output_by_handle(&self, handle: OutputHandle) -> Option<&PerOutputSurface> { + self.get_first_surface_for_output(handle) } - pub fn outputs_with_handles(&self) -> impl Iterator { + pub fn outputs_with_handles(&self) -> impl Iterator { self.surfaces .iter() - .map(|(key, window)| (key.output_handle, window)) + .map(|(key, surface)| (key.output_handle, surface)) } - pub fn outputs_with_info(&self) -> impl Iterator { + pub fn outputs_with_info(&self) -> impl Iterator { self.output_registry.all_info().filter_map(|info| { let handle = info.handle(); - self.get_first_window_for_output(handle) - .map(|window| (info, window)) + self.get_first_surface_for_output(handle) + .map(|surface| (info, surface)) }) } - pub fn all_windows_for_output_mut( + pub fn all_surfaces_for_output_mut( &mut self, output_id: &ObjectId, - ) -> Vec<&mut PerOutputWindow> { + ) -> Vec<&mut PerOutputSurface> { let Some(handle) = self.output_mapping.get(output_id) else { return Vec::new(); }; diff --git a/crates/adapters/src/wayland/surfaces/event_context.rs b/crates/adapters/src/wayland/surfaces/event_context.rs index 5c20161..9549e80 100644 --- a/crates/adapters/src/wayland/surfaces/event_context.rs +++ b/crates/adapters/src/wayland/surfaces/event_context.rs @@ -42,7 +42,7 @@ pub struct EventContext { current_pointer_position: LogicalPosition, last_pointer_serial: u32, shared_pointer_serial: Option>, - active_window: ActiveWindow, + active_surface: ActiveWindow, } impl EventContext { @@ -60,7 +60,7 @@ impl EventContext { current_pointer_position: LogicalPosition::new(0.0, 0.0), last_pointer_serial: 0, shared_pointer_serial: None, - active_window: ActiveWindow::None, + active_surface: ActiveWindow::None, } } @@ -126,7 +126,7 @@ impl EventContext { } pub fn set_entered_surface(&mut self, surface: &WlSurface) { - self.active_window = if let Some(popup_manager) = &self.popup_manager { + self.active_surface = if let Some(popup_manager) = &self.popup_manager { popup_manager.get_active_window(surface, &self.main_surface_id) } else { let surface_id = surface.id(); @@ -139,18 +139,18 @@ impl EventContext { } pub fn clear_entered_surface(&mut self) { - self.active_window = ActiveWindow::None; + self.active_surface = ActiveWindow::None; } pub fn dispatch_to_active_window(&self, event: WindowEvent) { - match self.active_window { + match self.active_surface { ActiveWindow::Main => { self.main_window.window().dispatch_event(event); } ActiveWindow::Popup(handle) => { if let Some(popup_manager) = &self.popup_manager { - if let Some(popup_window) = popup_manager.get_popup_window(handle.key()) { - popup_window.dispatch_event(event); + if let Some(popup_surface) = popup_manager.get_popup_window(handle.key()) { + popup_surface.dispatch_event(event); } } } diff --git a/crates/adapters/src/wayland/surfaces/mod.rs b/crates/adapters/src/wayland/surfaces/mod.rs index 8445cf3..442e90d 100644 --- a/crates/adapters/src/wayland/surfaces/mod.rs +++ b/crates/adapters/src/wayland/surfaces/mod.rs @@ -8,5 +8,5 @@ pub mod popup_manager; pub mod popup_surface; pub mod rendering_state; pub mod surface_builder; +pub mod surface_renderer; pub mod surface_state; -pub mod window_renderer; diff --git a/crates/adapters/src/wayland/surfaces/popup_manager.rs b/crates/adapters/src/wayland/surfaces/popup_manager.rs index 6d5b19f..f97a734 100644 --- a/crates/adapters/src/wayland/surfaces/popup_manager.rs +++ b/crates/adapters/src/wayland/surfaces/popup_manager.rs @@ -310,29 +310,30 @@ impl PopupManager { info!("Popup physical size: {popup_size:?}"); - let popup_surface = PopupSurface::create(&super::popup_surface::PopupSurfaceParams { - compositor: &self.context.compositor, - xdg_wm_base, - parent_layer_surface, - fractional_scale_manager: self.context.fractional_scale_manager.as_ref(), - viewporter: self.context.viewporter.as_ref(), - queue_handle, - popup_config, - physical_size: popup_size, - scale_factor, - }); + let wayland_popup_surface = + PopupSurface::create(&super::popup_surface::PopupSurfaceParams { + compositor: &self.context.compositor, + xdg_wm_base, + parent_layer_surface, + fractional_scale_manager: self.context.fractional_scale_manager.as_ref(), + viewporter: self.context.viewporter.as_ref(), + queue_handle, + popup_config, + physical_size: popup_size, + scale_factor, + }); if params.grab { - popup_surface.grab(&self.context.seat, params.last_pointer_serial); + wayland_popup_surface.grab(&self.context.seat, params.last_pointer_serial); } else { info!("Skipping popup grab (grab disabled in request)"); - popup_surface.surface.commit(); + wayland_popup_surface.surface.commit(); } let context = self .context .render_factory - .create_context(&popup_surface.surface.id(), popup_size)?; + .create_context(&wayland_popup_surface.surface.id(), popup_size)?; let renderer = FemtoVGRenderer::new(context) .map_err(|e| LayerShikaError::FemtoVGRendererCreation { source: e })?; @@ -359,7 +360,7 @@ impl PopupManager { state.popups.insert( popup_id, ActivePopup { - surface: popup_surface, + surface: wayland_popup_surface, window: Rc::clone(&popup_window), request, last_serial: params.last_pointer_serial, @@ -542,11 +543,11 @@ impl PopupManager { let fractional_scale_id = fractional_scale_proxy.id(); if let Some(popup_key) = self.find_popup_key_by_fractional_scale_id(&fractional_scale_id) { - if let Some(popup_window) = self.get_popup_window(popup_key) { + if let Some(popup_surface) = self.get_popup_window(popup_key) { let new_scale_factor = DisplayMetrics::scale_factor_from_120ths(scale_120ths); info!("Updating popup scale factor to {new_scale_factor} ({scale_120ths}x)"); - popup_window.set_scale_factor(new_scale_factor); - popup_window.request_redraw(); + popup_surface.set_scale_factor(new_scale_factor); + popup_surface.request_redraw(); } } } diff --git a/crates/adapters/src/wayland/surfaces/rendering_state.rs b/crates/adapters/src/wayland/surfaces/rendering_state.rs index db35c66..4e35849 100644 --- a/crates/adapters/src/wayland/surfaces/rendering_state.rs +++ b/crates/adapters/src/wayland/surfaces/rendering_state.rs @@ -1,20 +1,20 @@ use std::rc::Rc; use crate::errors::Result; use crate::rendering::femtovg::renderable_window::RenderableWindow; -use crate::wayland::surfaces::window_renderer::{WindowRenderer, WindowRendererParams}; +use crate::wayland::surfaces::surface_renderer::{SurfaceRenderer, SurfaceRendererParams}; use slint::PhysicalSize; use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1; use crate::wayland::managed_proxies::ManagedWpFractionalScaleV1; pub struct RenderingState { - renderer: WindowRenderer, + renderer: SurfaceRenderer, } impl RenderingState { #[must_use] - pub fn new(params: WindowRendererParams) -> Self { + pub fn new(params: SurfaceRendererParams) -> Self { Self { - renderer: WindowRenderer::new(params), + renderer: SurfaceRenderer::new(params), } } diff --git a/crates/adapters/src/wayland/surfaces/surface_builder.rs b/crates/adapters/src/wayland/surfaces/surface_builder.rs index dd090a3..0ff2089 100644 --- a/crates/adapters/src/wayland/surfaces/surface_builder.rs +++ b/crates/adapters/src/wayland/surfaces/surface_builder.rs @@ -13,7 +13,7 @@ use crate::errors::{LayerShikaError, Result}; use crate::rendering::femtovg::main_window::FemtoVGWindow; use crate::rendering::slint_integration::platform::CustomSlintPlatform; -use super::surface_state::WindowState; +use super::surface_state::SurfaceState; pub struct PlatformWrapper(pub Rc); @@ -23,7 +23,7 @@ impl Platform for PlatformWrapper { } } -pub struct WindowStateBuilder { +pub struct SurfaceStateBuilder { pub component_definition: Option, pub compilation_result: Option>, pub surface: Option>, @@ -41,7 +41,7 @@ pub struct WindowStateBuilder { pub exclusive_zone: i32, } -impl WindowStateBuilder { +impl SurfaceStateBuilder { #[must_use] pub fn new() -> Self { Self::default() @@ -140,7 +140,7 @@ impl WindowStateBuilder { self } - pub fn build(self) -> Result<(WindowState, Rc)> { + pub fn build(self) -> Result<(SurfaceState, Rc)> { let platform = CustomSlintPlatform::new(self.window.as_ref().ok_or_else(|| { LayerShikaError::InvalidInput { message: "Window is required".into(), @@ -149,12 +149,12 @@ impl WindowStateBuilder { set_platform(Box::new(PlatformWrapper(Rc::clone(&platform)))) .map_err(|e| LayerShikaError::PlatformSetup { source: e })?; - let state = WindowState::new(self)?; + let state = SurfaceState::new(self)?; Ok((state, platform)) } } -impl Default for WindowStateBuilder { +impl Default for SurfaceStateBuilder { fn default() -> Self { Self { component_definition: None, diff --git a/crates/adapters/src/wayland/surfaces/window_renderer.rs b/crates/adapters/src/wayland/surfaces/surface_renderer.rs similarity index 96% rename from crates/adapters/src/wayland/surfaces/window_renderer.rs rename to crates/adapters/src/wayland/surfaces/surface_renderer.rs index 7447d75..19884dc 100644 --- a/crates/adapters/src/wayland/surfaces/window_renderer.rs +++ b/crates/adapters/src/wayland/surfaces/surface_renderer.rs @@ -17,7 +17,7 @@ enum ScalingMode { Integer, } -pub struct WindowRendererParams { +pub struct SurfaceRendererParams { pub window: Rc, pub surface: ManagedWlSurface, pub layer_surface: ManagedZwlrLayerSurfaceV1, @@ -27,7 +27,7 @@ pub struct WindowRendererParams { pub size: PhysicalSize, } -pub struct WindowRenderer { +pub struct SurfaceRenderer { window: Rc, surface: ManagedWlSurface, layer_surface: ManagedZwlrLayerSurfaceV1, @@ -38,9 +38,9 @@ pub struct WindowRenderer { logical_size: PhysicalSize, } -impl WindowRenderer { +impl SurfaceRenderer { #[must_use] - pub fn new(params: WindowRendererParams) -> Self { + pub fn new(params: SurfaceRendererParams) -> Self { Self { window: params.window, surface: params.surface, diff --git a/crates/adapters/src/wayland/surfaces/surface_state.rs b/crates/adapters/src/wayland/surfaces/surface_state.rs index 72841bc..402a28c 100644 --- a/crates/adapters/src/wayland/surfaces/surface_state.rs +++ b/crates/adapters/src/wayland/surfaces/surface_state.rs @@ -1,11 +1,11 @@ use std::rc::Rc; use std::cell::RefCell; -use super::surface_builder::WindowStateBuilder; +use super::surface_builder::SurfaceStateBuilder; use super::component_state::ComponentState; use super::rendering_state::RenderingState; use super::event_context::{EventContext, SharedPointerSerial}; use super::popup_manager::PopupManager; -use super::window_renderer::WindowRendererParams; +use super::surface_renderer::SurfaceRendererParams; use super::display_metrics::{DisplayMetrics, SharedDisplayMetrics}; use crate::wayland::managed_proxies::{ ManagedWlPointer, ManagedWlSurface, ManagedZwlrLayerSurfaceV1, @@ -15,7 +15,7 @@ use crate::rendering::femtovg::main_window::FemtoVGWindow; use crate::errors::{LayerShikaError, Result}; use core::result::Result as CoreResult; use layer_shika_domain::errors::DomainError; -use layer_shika_domain::ports::windowing::ShellContextPort; +use layer_shika_domain::ports::shell::ShellContextPort; use slint::{LogicalPosition, PhysicalSize}; use slint::platform::WindowEvent; use slint_interpreter::{ComponentInstance, CompilationResult}; @@ -23,7 +23,7 @@ use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::z use wayland_client::{protocol::wl_surface::WlSurface, Proxy}; use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1; -pub struct WindowState { +pub struct SurfaceState { component: ComponentState, rendering: RenderingState, event_context: RefCell, @@ -32,8 +32,8 @@ pub struct WindowState { pointer: ManagedWlPointer, } -impl WindowState { - pub fn new(builder: WindowStateBuilder) -> Result { +impl SurfaceState { + pub fn new(builder: SurfaceStateBuilder) -> Result { let component_definition = builder .component_definition @@ -99,7 +99,7 @@ impl WindowState { Rc::clone(&display_metrics), ); - let rendering = RenderingState::new(WindowRendererParams { + let rendering = RenderingState::new(SurfaceRendererParams { window: Rc::clone(&window), surface, layer_surface, @@ -257,9 +257,9 @@ impl WindowState { } } -impl ShellContextPort for WindowState { +impl ShellContextPort for SurfaceState { fn render_frame_if_dirty(&mut self) -> CoreResult<(), DomainError> { - WindowState::render_frame_if_dirty(self).map_err(|e| DomainError::Adapter { + SurfaceState::render_frame_if_dirty(self).map_err(|e| DomainError::Adapter { source: Box::new(e), }) } diff --git a/crates/composition/src/event_loop.rs b/crates/composition/src/event_loop.rs index 9af60a0..74cf279 100644 --- a/crates/composition/src/event_loop.rs +++ b/crates/composition/src/event_loop.rs @@ -4,7 +4,7 @@ use layer_shika_adapters::platform::calloop::{ EventSource, Generic, Interest, Mode, PostAction, RegistrationToken, TimeoutAction, Timer, channel, }; -use layer_shika_adapters::{AppState, WindowingSystemFacade}; +use layer_shika_adapters::{AppState, ShellSystemFacade}; use std::cell::RefCell; use std::os::unix::io::AsFd; use std::rc::Weak; @@ -15,11 +15,11 @@ pub trait FromAppState<'a> { } pub struct EventLoopHandleBase { - system: Weak>, + system: Weak>, } impl EventLoopHandleBase { - pub fn new(system: Weak>) -> Self { + pub fn new(system: Weak>) -> Self { Self { system } } diff --git a/crates/composition/src/layer_shika.rs b/crates/composition/src/layer_shika.rs index 85fdd59..3f3e511 100644 --- a/crates/composition/src/layer_shika.rs +++ b/crates/composition/src/layer_shika.rs @@ -11,7 +11,7 @@ use layer_shika_adapters::platform::slint_interpreter::{ CompilationResult, Compiler, ComponentInstance, Value, }; use layer_shika_adapters::{ - AppState, ShellWindowConfig, WaylandWindowConfig, WindowState, WindowingSystemFacade, + AppState, ShellWindowConfig, WaylandWindowConfig, SurfaceState, ShellSystemFacade, }; use layer_shika_domain::config::WindowConfig; use layer_shika_domain::entities::output_registry::OutputRegistry; @@ -30,7 +30,7 @@ use std::rc::Rc; pub const DEFAULT_COMPONENT_NAME: &str = "Main"; #[derive(Debug, Clone)] -pub struct WindowDefinition { +pub struct SurfaceDefinition { pub component: String, pub config: WindowConfig, } @@ -43,12 +43,12 @@ enum CompilationSource { pub struct ShellBuilder { compilation: CompilationSource, - windows: Vec, + windows: Vec, } impl ShellBuilder { - pub fn window(self, component: impl Into) -> WindowConfigBuilder { - WindowConfigBuilder { + pub fn window(self, component: impl Into) -> SurfaceConfigBuilder { + SurfaceConfigBuilder { shell_builder: self, component: component.into(), config: WindowConfig::default(), @@ -56,12 +56,12 @@ impl ShellBuilder { } #[must_use] - pub fn discover_windows( + pub fn discover_surfaces( mut self, components: impl IntoIterator>, ) -> Self { for component in components { - self.windows.push(WindowDefinition { + self.surfaces.push(SurfaceDefinition { component: component.into(), config: WindowConfig::default(), }); @@ -70,13 +70,13 @@ impl ShellBuilder { } pub fn build(self) -> Result { - let windows = if self.windows.is_empty() { - vec![WindowDefinition { + let windows = if self.surfaces.is_empty() { + vec![SurfaceDefinition { component: DEFAULT_COMPONENT_NAME.to_string(), config: WindowConfig::default(), }] } else { - self.windows + self.surfaces }; let compilation_result = match self.compilation { @@ -120,13 +120,13 @@ impl ShellBuilder { } } -pub struct WindowConfigBuilder { +pub struct SurfaceConfigBuilder { shell_builder: ShellBuilder, component: String, config: WindowConfig, } -impl WindowConfigBuilder { +impl SurfaceConfigBuilder { #[must_use] pub fn size(mut self, width: u32, height: u32) -> Self { self.config.dimensions = WindowDimension::new(width, height); @@ -194,7 +194,7 @@ impl WindowConfigBuilder { } #[must_use] - pub fn window(self, component: impl Into) -> WindowConfigBuilder { + pub fn window(self, component: impl Into) -> SurfaceConfigBuilder { let shell_builder = self.complete(); shell_builder.window(component) } @@ -209,7 +209,7 @@ impl WindowConfigBuilder { } fn complete(mut self) -> ShellBuilder { - self.shell_builder.windows.push(WindowDefinition { + self.shell_builder.surfaces.push(SurfaceDefinition { component: self.component, config: self.config, }); @@ -301,8 +301,8 @@ impl LayerShika { } pub struct Runtime { - inner: Rc>, - windows: HashMap, + inner: Rc>, + windows: HashMap, compilation_result: Rc, popup_command_sender: channel::Sender, } @@ -310,7 +310,7 @@ pub struct Runtime { impl Runtime { pub(crate) fn new( compilation_result: Rc, - definitions: Vec, + definitions: Vec, ) -> Result { log::info!( "Creating LayerShika runtime with {} windows", @@ -339,7 +339,7 @@ impl Runtime { fn new_single_window( compilation_result: Rc, - definition: WindowDefinition, + definition: SurfaceDefinition, ) -> Result { let component_definition = compilation_result .component(&definition.component) @@ -358,8 +358,8 @@ impl Runtime { definition.config.clone(), ); - let inner = layer_shika_adapters::WaylandWindowingSystem::new(&wayland_config)?; - let facade = WindowingSystemFacade::new(inner); + let inner = layer_shika_adapters::WaylandShellSystem::new(&wayland_config)?; + let facade = ShellSystemFacade::new(inner); let inner_rc = Rc::new(RefCell::new(facade)); let (sender, receiver) = channel::channel(); @@ -383,7 +383,7 @@ impl Runtime { fn new_multi_window( compilation_result: Rc, - definitions: Vec, + definitions: Vec, ) -> Result { let shell_configs: Vec = definitions .iter() @@ -412,8 +412,8 @@ impl Runtime { }) .collect::>>()?; - let inner = layer_shika_adapters::WaylandWindowingSystem::new_multi(&shell_configs)?; - let facade = WindowingSystemFacade::new(inner); + let inner = layer_shika_adapters::WaylandShellSystem::new_multi(&shell_configs)?; + let facade = ShellSystemFacade::new(inner); let inner_rc = Rc::new(RefCell::new(facade)); let (sender, receiver) = channel::channel(); @@ -434,7 +434,7 @@ impl Runtime { log::info!( "LayerShika runtime created (multi-window mode) with windows: {:?}", - shell.window_names() + shell.surface_names() ); Ok(shell) @@ -489,12 +489,12 @@ impl Runtime { ShellControl::new(self.popup_command_sender.clone()) } - pub fn window_names(&self) -> Vec<&str> { - self.windows.keys().map(String::as_str).collect() + pub fn surface_names(&self) -> Vec<&str> { + self.surfaces.keys().map(String::as_str).collect() } - pub fn has_window(&self, name: &str) -> bool { - self.windows.contains_key(name) + pub fn has_surface(&self, name: &str) -> bool { + self.surfaces.contains_key(name) } pub fn event_loop_handle(&self) -> EventLoopHandle { @@ -504,17 +504,17 @@ impl Runtime { pub fn run(&mut self) -> Result<()> { log::info!( "Starting LayerShika event loop with {} windows", - self.windows.len() + self.surfaces.len() ); self.inner.borrow_mut().run()?; Ok(()) } - pub fn with_window(&self, name: &str, f: F) -> Result + pub fn with_surface(&self, name: &str, f: F) -> Result where F: FnOnce(&ComponentInstance) -> R, { - if !self.windows.contains_key(name) { + if !self.surfaces.contains_key(name) { return Err(Error::Domain(DomainError::Configuration { message: format!("Window '{}' not found", name), })); @@ -527,7 +527,7 @@ impl Runtime { .app_state() .windows_by_shell_name(name) .next() - .map(|window| f(window.component_instance())) + .map(|surface| f(surface.component_instance())) .ok_or_else(|| { Error::Domain(DomainError::Configuration { message: format!("No instance found for window '{}'", name), @@ -535,16 +535,16 @@ impl Runtime { }) } - pub fn with_all_windows(&self, mut f: F) + pub fn with_all_surfaces(&self, mut f: F) where F: FnMut(&str, &ComponentInstance), { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for name in self.windows.keys() { - for window in system.app_state().windows_by_shell_name(name) { - f(name, window.component_instance()); + for name in self.surfaces.keys() { + for surface in system.app_state().windows_by_shell_name(name) { + f(name, surface.component_instance()); } } } @@ -563,7 +563,7 @@ impl Runtime { message: format!("Output with handle {:?} not found", handle), }) })?; - Ok(f(window.component_instance())) + Ok(f(surface.component_instance())) } pub fn with_all_outputs(&self, mut f: F) @@ -572,8 +572,8 @@ impl Runtime { { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for (handle, window) in system.app_state().outputs_with_handles() { - f(handle, window.component_instance()); + for (handle, surface) in system.app_state().outputs_with_handles() { + f(handle, surface.component_instance()); } } @@ -587,14 +587,14 @@ impl Runtime { PopupBuilder::new(self, component_name.into()) } - pub fn on(&self, window_name: &str, callback_name: &str, handler: F) -> Result<()> + pub fn on(&self, surface_name: &str, callback_name: &str, handler: F) -> Result<()> where F: Fn(ShellControl) -> R + 'static, R: IntoValue, { - if !self.windows.contains_key(window_name) { + if !self.surfaces.contains_key(surface_name) { return Err(Error::Domain(DomainError::Configuration { - message: format!("Window '{}' not found", window_name), + message: format!("Window '{}' not found", surface_name), })); } @@ -603,7 +603,7 @@ impl Runtime { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().windows_by_shell_name(window_name) { + for surface in system.app_state().windows_by_shell_name(surface_name) { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); if let Err(e) = window @@ -615,7 +615,7 @@ impl Runtime { log::error!( "Failed to register callback '{}' on window '{}': {}", callback_name, - window_name, + surface_name, e ); } @@ -626,7 +626,7 @@ impl Runtime { pub fn on_with_args( &self, - window_name: &str, + surface_name: &str, callback_name: &str, handler: F, ) -> Result<()> @@ -634,9 +634,9 @@ impl Runtime { F: Fn(&[Value], ShellControl) -> R + 'static, R: IntoValue, { - if !self.windows.contains_key(window_name) { + if !self.surfaces.contains_key(surface_name) { return Err(Error::Domain(DomainError::Configuration { - message: format!("Window '{}' not found", window_name), + message: format!("Window '{}' not found", surface_name), })); } @@ -645,7 +645,7 @@ impl Runtime { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().windows_by_shell_name(window_name) { + for surface in system.app_state().windows_by_shell_name(surface_name) { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); if let Err(e) = window @@ -657,7 +657,7 @@ impl Runtime { log::error!( "Failed to register callback '{}' on window '{}': {}", callback_name, - window_name, + surface_name, e ); } @@ -676,7 +676,7 @@ impl Runtime { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { + for surface in system.app_state().all_outputs() { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); if let Err(e) = window @@ -706,7 +706,7 @@ impl Runtime { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { + for surface in system.app_state().all_outputs() { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); if let Err(e) = window @@ -726,17 +726,17 @@ impl Runtime { Ok(()) } - pub fn apply_window_config(&self, window_name: &str, f: F) + pub fn apply_surface_config(&self, surface_name: &str, f: F) where F: Fn(&ComponentInstance, LayerSurfaceHandle<'_>), { let facade = self.inner.borrow(); let system = facade.inner_ref(); - if self.windows.contains_key(window_name) { - for window in system.app_state().windows_by_shell_name(window_name) { - let surface_handle = LayerSurfaceHandle::from_window_state(window); - f(window.component_instance(), surface_handle); + if self.surfaces.contains_key(surface_name) { + for surface in system.app_state().windows_by_shell_name(surface_name) { + let surface_handle = LayerSurfaceHandle::from_window_state(surface); + f(surface.component_instance(), surface_handle); } } } @@ -748,9 +748,9 @@ impl Runtime { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { - let surface_handle = LayerSurfaceHandle::from_window_state(window); - f(window.component_instance(), surface_handle); + for surface in system.app_state().all_outputs() { + let surface_handle = LayerSurfaceHandle::from_window_state(surface); + f(surface.component_instance(), surface_handle); } } @@ -788,9 +788,9 @@ impl ShellRuntime for Runtime { let facade = self.inner.borrow(); let system = facade.inner_ref(); - if self.windows.contains_key(name) { - for window in system.app_state().windows_by_shell_name(name) { - f(window.component_instance()); + if self.surfaces.contains_key(name) { + for surface in system.app_state().windows_by_shell_name(name) { + f(surface.component_instance()); } } } @@ -802,9 +802,9 @@ impl ShellRuntime for Runtime { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for name in self.windows.keys() { - for window in system.app_state().windows_by_shell_name(name) { - f(name, window.component_instance()); + for name in self.surfaces.keys() { + for surface in system.app_state().windows_by_shell_name(name) { + f(name, surface.component_instance()); } } } @@ -828,22 +828,22 @@ impl<'a> FromAppState<'a> for EventContext<'a> { } impl EventContext<'_> { - pub fn get_window_component(&self, name: &str) -> Option<&ComponentInstance> { + pub fn get_surface_component(&self, name: &str) -> Option<&ComponentInstance> { self.app_state .windows_by_shell_name(name) .next() - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } - pub fn all_window_components(&self) -> impl Iterator { + pub fn all_surface_components(&self) -> impl Iterator { self.app_state .all_outputs() - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } pub fn render_frame_if_dirty(&mut self) -> Result<()> { - for window in self.app_state.all_outputs() { - window.render_frame_if_dirty()?; + for surface in self.app_state.all_outputs() { + surface.render_frame_if_dirty()?; } Ok(()) } @@ -865,13 +865,13 @@ impl EventContext<'_> { pub fn outputs(&self) -> impl Iterator { self.app_state .outputs_with_handles() - .map(|(handle, window)| (handle, window.component_instance())) + .map(|(handle, surface)| (handle, surface.component_instance())) } pub fn get_output_component(&self, handle: OutputHandle) -> Option<&ComponentInstance> { self.app_state .get_output_by_handle(handle) - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } pub fn get_output_info(&self, handle: OutputHandle) -> Option<&OutputInfo> { @@ -885,13 +885,13 @@ impl EventContext<'_> { pub fn outputs_with_info(&self) -> impl Iterator { self.app_state .outputs_with_info() - .map(|(info, window)| (info, window.component_instance())) + .map(|(info, surface)| (info, surface.component_instance())) } #[must_use] pub fn compilation_result(&self) -> Option> { self.app_state .primary_output() - .and_then(WindowState::compilation_result) + .and_then(SurfaceState::compilation_result) } } diff --git a/crates/composition/src/layer_surface.rs b/crates/composition/src/layer_surface.rs index 312a9b7..ec9732c 100644 --- a/crates/composition/src/layer_surface.rs +++ b/crates/composition/src/layer_surface.rs @@ -1,4 +1,4 @@ -use layer_shika_adapters::WindowState; +use layer_shika_adapters::SurfaceState; use layer_shika_adapters::platform::slint_interpreter::ComponentInstance; use layer_shika_adapters::platform::wayland::{Anchor, WaylandKeyboardInteractivity, WaylandLayer}; use layer_shika_domain::value_objects::keyboard_interactivity::KeyboardInteractivity; @@ -6,11 +6,11 @@ use layer_shika_domain::value_objects::layer::Layer; use layer_shika_domain::value_objects::margins::Margins; pub struct LayerSurfaceHandle<'a> { - window_state: &'a WindowState, + window_state: &'a SurfaceState, } impl<'a> LayerSurfaceHandle<'a> { - pub(crate) fn from_window_state(window_state: &'a WindowState) -> Self { + pub(crate) fn from_window_state(window_state: &'a SurfaceState) -> Self { Self { window_state } } diff --git a/crates/composition/src/lib.rs b/crates/composition/src/lib.rs index 8d30b46..987fa45 100644 --- a/crates/composition/src/lib.rs +++ b/crates/composition/src/lib.rs @@ -29,7 +29,7 @@ pub use layer_shika_domain::value_objects::popup_request::{ }; pub use popup_builder::PopupBuilder; pub use shell_runtime::{DEFAULT_SURFACE_NAME, ShellRuntime}; -pub use system::{EventContext, EventLoopHandle, ShellControl, SingleWindowShell}; +pub use system::{EventContext, EventLoopHandle, ShellControl, SingleSurfaceShell}; pub use value_conversion::IntoValue; pub use layer_surface::{LayerSurfaceHandle, ShellSurfaceConfigHandler, ShellSurfaceHandle}; @@ -69,7 +69,7 @@ pub mod prelude { OutputRegistry, PopupBuilder, PopupHandle, PopupPlacement, PopupPositioningMode, PopupRequest, PopupSize, PopupWindow, Result, Shell, ShellBuilder, ShellConfig, ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime, - ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleWindowShell, SurfaceComponentConfig, + ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder, SurfaceDefinition, }; diff --git a/crates/composition/src/shell.rs b/crates/composition/src/shell.rs index 9c85634..c82a7bd 100644 --- a/crates/composition/src/shell.rs +++ b/crates/composition/src/shell.rs @@ -12,7 +12,7 @@ use layer_shika_adapters::platform::slint_interpreter::{ CompilationResult, Compiler, ComponentInstance, Value, }; use layer_shika_adapters::{ - AppState, ShellSurfaceConfig, WaylandSurfaceConfig, WindowState, WindowingSystemFacade, + AppState, ShellSurfaceConfig, ShellSystemFacade, SurfaceState, WaylandSurfaceConfig, }; use layer_shika_domain::config::SurfaceConfig; use layer_shika_domain::entities::output_registry::OutputRegistry; @@ -219,7 +219,7 @@ impl SurfaceConfigBuilder { } pub struct Shell { - inner: Rc>, + inner: Rc>, surfaces: HashMap, compilation_result: Rc, popup_command_sender: channel::Sender, @@ -389,8 +389,8 @@ impl Shell { definition.config.clone(), ); - let inner = layer_shika_adapters::WaylandWindowingSystem::new(&wayland_config)?; - let facade = WindowingSystemFacade::new(inner); + let inner = layer_shika_adapters::WaylandShellSystem::new(&wayland_config)?; + let facade = ShellSystemFacade::new(inner); let inner_rc = Rc::new(RefCell::new(facade)); let (sender, receiver) = channel::channel(); @@ -444,8 +444,8 @@ impl Shell { }) .collect::>>()?; - let inner = layer_shika_adapters::WaylandWindowingSystem::new_multi(&shell_configs)?; - let facade = WindowingSystemFacade::new(inner); + let inner = layer_shika_adapters::WaylandShellSystem::new_multi(&shell_configs)?; + let facade = ShellSystemFacade::new(inner); let inner_rc = Rc::new(RefCell::new(facade)); let (sender, receiver) = channel::channel(); @@ -559,7 +559,7 @@ impl Shell { .app_state() .surfaces_by_name(name) .next() - .map(|window| f(window.component_instance())) + .map(|surface| f(surface.component_instance())) .ok_or_else(|| { Error::Domain(DomainError::Configuration { message: format!("No instance found for window '{}'", name), @@ -575,8 +575,8 @@ impl Shell { let system = facade.inner_ref(); for name in self.surfaces.keys() { - for window in system.app_state().surfaces_by_name(name) { - f(name, window.component_instance()); + for surface in system.app_state().surfaces_by_name(name) { + f(name, surface.component_instance()); } } } @@ -604,8 +604,8 @@ impl Shell { { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for (handle, window) in system.app_state().outputs_with_handles() { - f(handle, window.component_instance()); + for (handle, surface) in system.app_state().outputs_with_handles() { + f(handle, surface.component_instance()); } } @@ -619,14 +619,14 @@ impl Shell { PopupBuilder::new(self, component_name.into()) } - pub fn on(&self, window_name: &str, callback_name: &str, handler: F) -> Result<()> + pub fn on(&self, surface_name: &str, callback_name: &str, handler: F) -> Result<()> where F: Fn(ShellControl) -> R + 'static, R: IntoValue, { - if !self.surfaces.contains_key(window_name) { + if !self.surfaces.contains_key(surface_name) { return Err(Error::Domain(DomainError::Configuration { - message: format!("Window '{}' not found", window_name), + message: format!("Window '{}' not found", surface_name), })); } @@ -635,19 +635,19 @@ impl Shell { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().surfaces_by_name(window_name) { + for surface in system.app_state().surfaces_by_name(surface_name) { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); - if let Err(e) = window + if let Err(e) = surface .component_instance() .set_callback(callback_name, move |_args| { handler_rc(control_clone.clone()).into_value() }) { log::error!( - "Failed to register callback '{}' on window '{}': {}", + "Failed to register callback '{}' on surface '{}': {}", callback_name, - window_name, + surface_name, e ); } @@ -658,7 +658,7 @@ impl Shell { pub fn on_with_args( &self, - window_name: &str, + surface_name: &str, callback_name: &str, handler: F, ) -> Result<()> @@ -666,9 +666,9 @@ impl Shell { F: Fn(&[Value], ShellControl) -> R + 'static, R: IntoValue, { - if !self.surfaces.contains_key(window_name) { + if !self.surfaces.contains_key(surface_name) { return Err(Error::Domain(DomainError::Configuration { - message: format!("Window '{}' not found", window_name), + message: format!("Window '{}' not found", surface_name), })); } @@ -677,19 +677,19 @@ impl Shell { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().surfaces_by_name(window_name) { + for surface in system.app_state().surfaces_by_name(surface_name) { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); - if let Err(e) = window + if let Err(e) = surface .component_instance() .set_callback(callback_name, move |args| { handler_rc(args, control_clone.clone()).into_value() }) { log::error!( - "Failed to register callback '{}' on window '{}': {}", + "Failed to register callback '{}' on surface '{}': {}", callback_name, - window_name, + surface_name, e ); } @@ -708,10 +708,10 @@ impl Shell { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { + for surface in system.app_state().all_outputs() { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); - if let Err(e) = window + if let Err(e) = surface .component_instance() .set_callback(callback_name, move |_args| { handler_rc(control_clone.clone()).into_value() @@ -738,10 +738,10 @@ impl Shell { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { + for surface in system.app_state().all_outputs() { let handler_rc = Rc::clone(&handler); let control_clone = control.clone(); - if let Err(e) = window + if let Err(e) = surface .component_instance() .set_callback(callback_name, move |args| { handler_rc(args, control_clone.clone()).into_value() @@ -758,17 +758,17 @@ impl Shell { Ok(()) } - pub fn apply_surface_config(&self, window_name: &str, f: F) + pub fn apply_surface_config(&self, surface_name: &str, f: F) where F: Fn(&ComponentInstance, LayerSurfaceHandle<'_>), { let facade = self.inner.borrow(); let system = facade.inner_ref(); - if self.surfaces.contains_key(window_name) { - for window in system.app_state().surfaces_by_name(window_name) { - let surface_handle = LayerSurfaceHandle::from_window_state(window); - f(window.component_instance(), surface_handle); + if self.surfaces.contains_key(surface_name) { + for surface in system.app_state().surfaces_by_name(surface_name) { + let surface_handle = LayerSurfaceHandle::from_window_state(surface); + f(surface.component_instance(), surface_handle); } } } @@ -780,9 +780,9 @@ impl Shell { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { - let surface_handle = LayerSurfaceHandle::from_window_state(window); - f(window.component_instance(), surface_handle); + for surface in system.app_state().all_outputs() { + let surface_handle = LayerSurfaceHandle::from_window_state(surface); + f(surface.component_instance(), surface_handle); } } @@ -821,8 +821,8 @@ impl ShellRuntime for Shell { let system = facade.inner_ref(); if self.surfaces.contains_key(name) { - for window in system.app_state().surfaces_by_name(name) { - f(window.component_instance()); + for surface in system.app_state().surfaces_by_name(name) { + f(surface.component_instance()); } } } @@ -835,8 +835,8 @@ impl ShellRuntime for Shell { let system = facade.inner_ref(); for name in self.surfaces.keys() { - for window in system.app_state().surfaces_by_name(name) { - f(name, window.component_instance()); + for surface in system.app_state().surfaces_by_name(name) { + f(name, surface.component_instance()); } } } @@ -860,22 +860,22 @@ impl<'a> FromAppState<'a> for ShellEventContext<'a> { } impl ShellEventContext<'_> { - pub fn get_window_component(&self, name: &str) -> Option<&ComponentInstance> { + pub fn get_surface_component(&self, name: &str) -> Option<&ComponentInstance> { self.app_state .surfaces_by_name(name) .next() - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } - pub fn all_window_components(&self) -> impl Iterator { + pub fn all_surface_components(&self) -> impl Iterator { self.app_state .all_outputs() - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } pub fn render_frame_if_dirty(&mut self) -> Result<()> { - for window in self.app_state.all_outputs() { - window.render_frame_if_dirty()?; + for surface in self.app_state.all_outputs() { + surface.render_frame_if_dirty()?; } Ok(()) } @@ -897,13 +897,13 @@ impl ShellEventContext<'_> { pub fn outputs(&self) -> impl Iterator { self.app_state .outputs_with_handles() - .map(|(handle, window)| (handle, window.component_instance())) + .map(|(handle, surface)| (handle, surface.component_instance())) } pub fn get_output_component(&self, handle: OutputHandle) -> Option<&ComponentInstance> { self.app_state .get_output_by_handle(handle) - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } pub fn get_output_info(&self, handle: OutputHandle) -> Option<&OutputInfo> { @@ -917,13 +917,13 @@ impl ShellEventContext<'_> { pub fn outputs_with_info(&self) -> impl Iterator { self.app_state .outputs_with_info() - .map(|(info, window)| (info, window.component_instance())) + .map(|(info, surface)| (info, surface.component_instance())) } #[must_use] pub fn compilation_result(&self) -> Option> { self.app_state .primary_output() - .and_then(WindowState::compilation_result) + .and_then(SurfaceState::compilation_result) } } diff --git a/crates/composition/src/system.rs b/crates/composition/src/system.rs index 197a76e..50fd6fc 100644 --- a/crates/composition/src/system.rs +++ b/crates/composition/src/system.rs @@ -9,7 +9,7 @@ use layer_shika_adapters::platform::slint_interpreter::{ CompilationResult, ComponentDefinition, ComponentInstance, Value, }; use layer_shika_adapters::{ - AppState, PopupManager, WaylandSurfaceConfig, WindowState, WindowingSystemFacade, + AppState, PopupManager, ShellSystemFacade, SurfaceState, WaylandSurfaceConfig, }; use layer_shika_domain::config::SurfaceConfig; use layer_shika_domain::entities::output_registry::OutputRegistry; @@ -134,13 +134,13 @@ impl EventContext<'_> { pub fn component_instance(&self) -> Option<&ComponentInstance> { self.app_state .primary_output() - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } pub fn all_component_instances(&self) -> impl Iterator { self.app_state .all_outputs() - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } pub const fn output_registry(&self) -> &OutputRegistry { @@ -160,13 +160,13 @@ impl EventContext<'_> { pub fn outputs(&self) -> impl Iterator { self.app_state .outputs_with_handles() - .map(|(handle, window)| (handle, window.component_instance())) + .map(|(handle, surface)| (handle, surface.component_instance())) } pub fn get_output_component(&self, handle: OutputHandle) -> Option<&ComponentInstance> { self.app_state .get_output_by_handle(handle) - .map(WindowState::component_instance) + .map(SurfaceState::component_instance) } pub fn get_output_info(&self, handle: OutputHandle) -> Option<&OutputInfo> { @@ -180,18 +180,18 @@ impl EventContext<'_> { pub fn outputs_with_info(&self) -> impl Iterator { self.app_state .outputs_with_info() - .map(|(info, window)| (info, window.component_instance())) + .map(|(info, surface)| (info, surface.component_instance())) } - fn active_or_primary_output(&self) -> Option<&WindowState> { + fn active_or_primary_output(&self) -> Option<&SurfaceState> { self.app_state .active_output() .or_else(|| self.app_state.primary_output()) } pub fn render_frame_if_dirty(&mut self) -> Result<()> { - for window in self.app_state.all_outputs() { - window.render_frame_if_dirty()?; + for surface in self.app_state.all_outputs() { + surface.render_frame_if_dirty()?; } Ok(()) } @@ -200,7 +200,7 @@ impl EventContext<'_> { pub fn compilation_result(&self) -> Option> { self.app_state .primary_output() - .and_then(WindowState::compilation_result) + .and_then(SurfaceState::compilation_result) } pub fn show_popup( @@ -242,7 +242,7 @@ impl EventContext<'_> { self.close_current_popup()?; let is_using_active = self.app_state.active_output().is_some(); - let active_window = self.active_or_primary_output().ok_or_else(|| { + let active_surface = self.active_or_primary_output().ok_or_else(|| { log::error!("No active or primary output available"); Error::Domain(DomainError::Configuration { message: "No active or primary output available".to_string(), @@ -254,7 +254,7 @@ impl EventContext<'_> { if is_using_active { "active" } else { "primary" } ); - let popup_manager = active_window.popup_manager().ok_or_else(|| { + let popup_manager = active_surface.popup_manager().ok_or_else(|| { Error::Domain(DomainError::Configuration { message: "No popup manager available".to_string(), }) @@ -289,8 +289,8 @@ impl EventContext<'_> { popup_key_cell.set(popup_handle.key()); - if let Some(popup_window) = popup_manager.get_popup_window(popup_handle.key()) { - popup_window.set_component_instance(instance); + if let Some(popup_surface) = popup_manager.get_popup_window(popup_handle.key()) { + popup_surface.set_component_instance(instance); } else { return Err(Error::Domain(DomainError::Configuration { message: "Popup window not found after creation".to_string(), @@ -301,8 +301,8 @@ impl EventContext<'_> { } pub fn close_popup(&mut self, handle: PopupHandle) -> Result<()> { - if let Some(active_window) = self.active_or_primary_output() { - if let Some(popup_manager) = active_window.popup_manager() { + if let Some(active_surface) = self.active_or_primary_output() { + if let Some(popup_manager) = active_surface.popup_manager() { popup_manager.close(handle)?; } } @@ -310,8 +310,8 @@ impl EventContext<'_> { } pub fn close_current_popup(&mut self) -> Result<()> { - if let Some(active_window) = self.active_or_primary_output() { - if let Some(popup_manager) = active_window.popup_manager() { + if let Some(active_surface) = self.active_or_primary_output() { + if let Some(popup_manager) = active_surface.popup_manager() { popup_manager.close_current_popup(); } } @@ -319,13 +319,13 @@ impl EventContext<'_> { } pub fn resize_popup(&mut self, handle: PopupHandle, width: f32, height: f32) -> Result<()> { - let active_window = self.active_or_primary_output().ok_or_else(|| { + let active_surface = self.active_or_primary_output().ok_or_else(|| { Error::Domain(DomainError::Configuration { message: "No active or primary output available".to_string(), }) })?; - let popup_manager = active_window.popup_manager().ok_or_else(|| { + let popup_manager = active_surface.popup_manager().ok_or_else(|| { Error::Domain(DomainError::Configuration { message: "No popup manager available".to_string(), }) @@ -344,8 +344,8 @@ impl EventContext<'_> { current_size.is_none_or(|(w, h)| (w - width).abs() > 0.01 || (h - height).abs() > 0.01); if size_changed { - if let Some(popup_window) = popup_manager.get_popup_window(handle.key()) { - popup_window.request_resize(width, height); + if let Some(popup_surface) = popup_manager.get_popup_window(handle.key()) { + popup_surface.request_resize(width, height); #[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_wrap)] @@ -518,8 +518,8 @@ impl EventContext<'_> { ); if let Some(popup_manager) = popup_manager_weak.upgrade() { - if let Some(popup_window) = popup_manager.get_popup_window(popup_key) { - popup_window.request_resize(dimensions.width, dimensions.height); + if let Some(popup_surface) = popup_manager.get_popup_window(popup_key) { + popup_surface.request_resize(dimensions.width, dimensions.height); #[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_wrap)] @@ -552,14 +552,14 @@ impl EventContext<'_> { } } -pub struct SingleWindowShell { - inner: Rc>, +pub struct SingleSurfaceShell { + inner: Rc>, popup_command_sender: channel::Sender, - window_name: String, + surface_name: String, } #[allow(dead_code)] -impl SingleWindowShell { +impl SingleSurfaceShell { pub(crate) fn new( component_definition: ComponentDefinition, compilation_result: Option>, @@ -571,8 +571,8 @@ impl SingleWindowShell { compilation_result, config, ); - let inner = layer_shika_adapters::WaylandWindowingSystem::new(&wayland_config)?; - let facade = WindowingSystemFacade::new(inner); + let inner = layer_shika_adapters::WaylandShellSystem::new(&wayland_config)?; + let facade = ShellSystemFacade::new(inner); let inner_rc = Rc::new(RefCell::new(facade)); let (sender, receiver) = channel::channel(); @@ -580,7 +580,7 @@ impl SingleWindowShell { let shell = Self { inner: Rc::clone(&inner_rc), popup_command_sender: sender, - window_name: DEFAULT_SURFACE_NAME.to_string(), + surface_name: DEFAULT_SURFACE_NAME.to_string(), }; shell.setup_popup_command_handler(receiver)?; @@ -589,14 +589,14 @@ impl SingleWindowShell { } #[must_use] - pub fn with_window_name(mut self, name: impl Into) -> Self { - self.window_name = name.into(); + pub fn with_surface_name(mut self, name: impl Into) -> Self { + self.surface_name = name.into(); self } #[must_use] - pub fn window_name(&self) -> &str { - &self.window_name + pub fn surface_name(&self) -> &str { + &self.surface_name } fn setup_popup_command_handler(&self, receiver: channel::Channel) -> Result<()> { @@ -777,8 +777,8 @@ impl SingleWindowShell { { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { - f(window.component_instance()); + for surface in system.app_state().all_outputs() { + f(surface.component_instance()); } } @@ -805,8 +805,8 @@ impl SingleWindowShell { { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for (handle, window) in system.app_state().outputs_with_handles() { - f(handle, window.component_instance()); + for (handle, surface) in system.app_state().outputs_with_handles() { + f(handle, surface.component_instance()); } } @@ -829,7 +829,7 @@ impl SingleWindowShell { } } -impl ShellRuntime for SingleWindowShell { +impl ShellRuntime for SingleSurfaceShell { type LoopHandle = EventLoopHandle; type Context<'a> = EventContext<'a>; @@ -843,8 +843,8 @@ impl ShellRuntime for SingleWindowShell { { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { - f(window.component_instance()); + for surface in system.app_state().all_outputs() { + f(surface.component_instance()); } } @@ -854,8 +854,8 @@ impl ShellRuntime for SingleWindowShell { { let facade = self.inner.borrow(); let system = facade.inner_ref(); - for window in system.app_state().all_outputs() { - f(&self.window_name, window.component_instance()); + for surface in system.app_state().all_outputs() { + f(&self.surface_name, surface.component_instance()); } } diff --git a/crates/domain/src/ports/mod.rs b/crates/domain/src/ports/mod.rs index 797cb13..327cf1b 100644 --- a/crates/domain/src/ports/mod.rs +++ b/crates/domain/src/ports/mod.rs @@ -1 +1 @@ -pub mod windowing; +pub mod shell; diff --git a/crates/domain/src/ports/windowing.rs b/crates/domain/src/ports/shell.rs similarity index 85% rename from crates/domain/src/ports/windowing.rs rename to crates/domain/src/ports/shell.rs index 769301b..1b7a6d5 100644 --- a/crates/domain/src/ports/windowing.rs +++ b/crates/domain/src/ports/shell.rs @@ -1,6 +1,6 @@ use crate::errors::DomainError; -pub trait WindowingSystemPort { +pub trait ShellSystemPort { fn run(&mut self) -> Result<(), DomainError>; } diff --git a/examples/event-loop/src/channel.rs b/examples/event-loop/src/channel.rs index bf6ab58..a2f0316 100644 --- a/examples/event-loop/src/channel.rs +++ b/examples/event-loop/src/channel.rs @@ -33,8 +33,8 @@ fn main() -> Result<()> { let handle = shell.event_loop_handle(); let (_token, sender) = handle.add_channel(|message: UiMessage, app_state| { - for window in app_state.all_outputs() { - let component = window.component_instance(); + for surface in app_state.all_outputs() { + let component = surface.component_instance(); match &message { UiMessage::UpdateStatus(status) => { @@ -72,8 +72,8 @@ fn main() -> Result<()> { handle.add_timer(Duration::from_secs(1), |_instant, app_state| { let time_str = current_time_string(); - for window in app_state.all_outputs() { - if let Err(e) = window + for surface in app_state.all_outputs() { + if let Err(e) = surface .component_instance() .set_property("time", Value::String(time_str.clone().into())) { diff --git a/examples/event-loop/src/custom_source.rs b/examples/event-loop/src/custom_source.rs index f5a8611..777a6b2 100644 --- a/examples/event-loop/src/custom_source.rs +++ b/examples/event-loop/src/custom_source.rs @@ -56,8 +56,8 @@ fn main() -> Result<()> { let status_text = format!("Events received: {count}"); - for window in app_state.all_outputs() { - let component = window.component_instance(); + for surface in app_state.all_outputs() { + let component = surface.component_instance(); if let Err(e) = component.set_property("counter", Value::Number(f64::from(count))) { log::error!("Failed to set counter: {e}"); } @@ -88,8 +88,8 @@ fn main() -> Result<()> { handle.add_timer(Duration::from_secs(1), |_instant, app_state| { let time_str = current_time_string(); - for window in app_state.all_outputs() { - if let Err(e) = window + for surface in app_state.all_outputs() { + if let Err(e) = surface .component_instance() .set_property("time", Value::String(time_str.clone().into())) { diff --git a/examples/event-loop/src/timer.rs b/examples/event-loop/src/timer.rs index d45643d..25cca18 100644 --- a/examples/event-loop/src/timer.rs +++ b/examples/event-loop/src/timer.rs @@ -28,8 +28,8 @@ fn main() -> Result<()> { handle.add_timer(Duration::ZERO, |_instant, app_state| { let time_str = current_time_string(); - for window in app_state.all_outputs() { - if let Err(e) = window + for surface in app_state.all_outputs() { + if let Err(e) = surface .component_instance() .set_property("time", Value::String(time_str.clone().into())) { @@ -47,8 +47,8 @@ fn main() -> Result<()> { let count = counter.get() + 1; counter.set(count); - for window in app_state.all_outputs() { - if let Err(e) = window + for surface in app_state.all_outputs() { + if let Err(e) = surface .component_instance() .set_property("counter", Value::Number(f64::from(count))) { diff --git a/src/lib.rs b/src/lib.rs index 28b423b..df69b91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,7 +123,7 @@ pub use layer_shika_composition::{Error, Result}; pub use shell::{ CompiledUiSource, DEFAULT_COMPONENT_NAME, DEFAULT_SURFACE_NAME, LayerSurfaceHandle, Shell, ShellBuilder, ShellConfig, ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime, - ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleWindowShell, SurfaceComponentConfig, + ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder, SurfaceDefinition, }; diff --git a/src/prelude.rs b/src/prelude.rs index 5764fb2..7601f4f 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -11,7 +11,7 @@ pub use crate::shell::{ CompiledUiSource, DEFAULT_COMPONENT_NAME, DEFAULT_SURFACE_NAME, LayerSurfaceHandle, Shell, ShellBuilder, ShellConfig, ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime, - ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleWindowShell, SurfaceComponentConfig, + ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder, SurfaceDefinition, }; diff --git a/src/shell.rs b/src/shell.rs index 2d29ca4..d3bb5b2 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -1,6 +1,6 @@ pub use layer_shika_composition::{ CompiledUiSource, DEFAULT_COMPONENT_NAME, DEFAULT_SURFACE_NAME, LayerSurfaceHandle, Shell, ShellBuilder, ShellConfig, ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime, - ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleWindowShell, SurfaceComponentConfig, + ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder, SurfaceDefinition, };