mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-12-12 14:25:54 +00:00
refactor: remove facade and use trait contract to reduce indirection
This commit is contained in:
parent
318ac1439b
commit
8e96e49c76
7 changed files with 83 additions and 76 deletions
|
|
@ -7,7 +7,7 @@ pub(crate) mod wayland;
|
||||||
pub use rendering::femtovg::popup_window::PopupWindow;
|
pub use rendering::femtovg::popup_window::PopupWindow;
|
||||||
|
|
||||||
pub use wayland::config::{MultiSurfaceConfig, ShellSurfaceConfig, WaylandSurfaceConfig};
|
pub use wayland::config::{MultiSurfaceConfig, ShellSurfaceConfig, WaylandSurfaceConfig};
|
||||||
pub use wayland::facade::ShellSystemFacade;
|
pub use wayland::ops::WaylandSystemOps;
|
||||||
pub use wayland::shell_adapter::WaylandShellSystem;
|
pub use wayland::shell_adapter::WaylandShellSystem;
|
||||||
pub use wayland::surfaces::app_state::AppState;
|
pub use wayland::surfaces::app_state::AppState;
|
||||||
pub use wayland::surfaces::popup_manager::PopupManager;
|
pub use wayland::surfaces::popup_manager::PopupManager;
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
use crate::errors::Result;
|
|
||||||
use crate::wayland::shell_adapter::WaylandShellSystem;
|
|
||||||
use slint_interpreter::ComponentInstance;
|
|
||||||
|
|
||||||
pub struct ShellSystemFacade {
|
|
||||||
inner: WaylandShellSystem,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ShellSystemFacade {
|
|
||||||
pub fn new(inner: WaylandShellSystem) -> Self {
|
|
||||||
Self { inner }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inner_ref(&self) -> &WaylandShellSystem {
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inner_mut(&mut self) -> &mut WaylandShellSystem {
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn component_instance(&self) -> Result<&ComponentInstance> {
|
|
||||||
self.inner.component_instance()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run(&mut self) -> Result<()> {
|
|
||||||
self.inner.run()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
pub(crate) mod config;
|
pub(crate) mod config;
|
||||||
pub(crate) mod event_handling;
|
pub(crate) mod event_handling;
|
||||||
pub(crate) mod facade;
|
|
||||||
pub(crate) mod globals;
|
pub(crate) mod globals;
|
||||||
pub(crate) mod managed_proxies;
|
pub(crate) mod managed_proxies;
|
||||||
|
pub mod ops;
|
||||||
pub(crate) mod outputs;
|
pub(crate) mod outputs;
|
||||||
pub(crate) mod shell_adapter;
|
pub(crate) mod shell_adapter;
|
||||||
pub(crate) mod surfaces;
|
pub(crate) mod surfaces;
|
||||||
|
|
|
||||||
22
crates/adapters/src/wayland/ops.rs
Normal file
22
crates/adapters/src/wayland/ops.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
use crate::errors::Result;
|
||||||
|
use crate::wayland::config::ShellSurfaceConfig;
|
||||||
|
use crate::wayland::surfaces::app_state::AppState;
|
||||||
|
use layer_shika_domain::value_objects::output_handle::OutputHandle;
|
||||||
|
use slint_interpreter::ComponentInstance;
|
||||||
|
use smithay_client_toolkit::reexports::calloop::LoopHandle;
|
||||||
|
|
||||||
|
pub trait WaylandSystemOps {
|
||||||
|
fn run(&mut self) -> Result<()>;
|
||||||
|
|
||||||
|
fn spawn_surface(&mut self, config: &ShellSurfaceConfig) -> Result<Vec<OutputHandle>>;
|
||||||
|
|
||||||
|
fn despawn_surface(&mut self, name: &str) -> Result<()>;
|
||||||
|
|
||||||
|
fn app_state(&self) -> &AppState;
|
||||||
|
|
||||||
|
fn app_state_mut(&mut self) -> &mut AppState;
|
||||||
|
|
||||||
|
fn event_loop_handle(&self) -> LoopHandle<'static, AppState>;
|
||||||
|
|
||||||
|
fn component_instance(&self) -> Result<&ComponentInstance>;
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ use crate::wayland::{
|
||||||
config::{LayerSurfaceConfig, ShellSurfaceConfig, WaylandSurfaceConfig},
|
config::{LayerSurfaceConfig, ShellSurfaceConfig, WaylandSurfaceConfig},
|
||||||
globals::context::GlobalContext,
|
globals::context::GlobalContext,
|
||||||
managed_proxies::ManagedWlPointer,
|
managed_proxies::ManagedWlPointer,
|
||||||
|
ops::WaylandSystemOps,
|
||||||
outputs::{OutputManager, OutputManagerContext},
|
outputs::{OutputManager, OutputManagerContext},
|
||||||
surfaces::layer_surface::{SurfaceCtx, SurfaceSetupParams},
|
surfaces::layer_surface::{SurfaceCtx, SurfaceSetupParams},
|
||||||
surfaces::popup_manager::{PopupContext, PopupManager},
|
surfaces::popup_manager::{PopupContext, PopupManager},
|
||||||
|
|
@ -756,3 +757,33 @@ impl ShellSystemPort for WaylandShellSystem {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WaylandSystemOps for WaylandShellSystem {
|
||||||
|
fn run(&mut self) -> Result<()> {
|
||||||
|
WaylandShellSystem::run(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_surface(&mut self, config: &ShellSurfaceConfig) -> Result<Vec<OutputHandle>> {
|
||||||
|
WaylandShellSystem::spawn_surface(self, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn despawn_surface(&mut self, name: &str) -> Result<()> {
|
||||||
|
WaylandShellSystem::despawn_surface(self, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn app_state(&self) -> &AppState {
|
||||||
|
WaylandShellSystem::app_state(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn app_state_mut(&mut self) -> &mut AppState {
|
||||||
|
WaylandShellSystem::app_state_mut(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn event_loop_handle(&self) -> LoopHandle<'static, AppState> {
|
||||||
|
WaylandShellSystem::event_loop_handle(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn component_instance(&self) -> Result<&ComponentInstance> {
|
||||||
|
WaylandShellSystem::component_instance(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use layer_shika_adapters::platform::calloop::{
|
||||||
EventSource, Generic, Interest, Mode, PostAction, RegistrationToken, TimeoutAction, Timer,
|
EventSource, Generic, Interest, Mode, PostAction, RegistrationToken, TimeoutAction, Timer,
|
||||||
channel,
|
channel,
|
||||||
};
|
};
|
||||||
use layer_shika_adapters::{AppState, ShellSystemFacade};
|
use layer_shika_adapters::{AppState, WaylandSystemOps};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::os::unix::io::AsFd;
|
use std::os::unix::io::AsFd;
|
||||||
use std::rc::Weak;
|
use std::rc::Weak;
|
||||||
|
|
@ -15,11 +15,11 @@ pub trait FromAppState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventLoopHandleBase {
|
pub struct EventLoopHandleBase {
|
||||||
system: Weak<RefCell<ShellSystemFacade>>,
|
system: Weak<RefCell<dyn WaylandSystemOps>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventLoopHandleBase {
|
impl EventLoopHandleBase {
|
||||||
pub fn new(system: Weak<RefCell<ShellSystemFacade>>) -> Self {
|
pub fn new(system: Weak<RefCell<dyn WaylandSystemOps>>) -> Self {
|
||||||
Self { system }
|
Self { system }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ impl EventLoopHandleBase {
|
||||||
F: FnMut(S::Event, &mut S::Metadata, &mut AppState) -> R + 'static,
|
F: FnMut(S::Event, &mut S::Metadata, &mut AppState) -> R + 'static,
|
||||||
{
|
{
|
||||||
let system = self.system.upgrade().ok_or(Error::SystemDropped)?;
|
let system = self.system.upgrade().ok_or(Error::SystemDropped)?;
|
||||||
let loop_handle = system.borrow().inner_ref().event_loop_handle();
|
let loop_handle = system.borrow().event_loop_handle();
|
||||||
|
|
||||||
loop_handle.insert_source(source, callback).map_err(|e| {
|
loop_handle.insert_source(source, callback).map_err(|e| {
|
||||||
Error::Adapter(
|
Error::Adapter(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use layer_shika_adapters::platform::slint_interpreter::{
|
||||||
CompilationResult, Compiler, ComponentInstance, Value,
|
CompilationResult, Compiler, ComponentInstance, Value,
|
||||||
};
|
};
|
||||||
use layer_shika_adapters::{
|
use layer_shika_adapters::{
|
||||||
AppState, ShellSurfaceConfig, ShellSystemFacade, SurfaceState, WaylandSurfaceConfig,
|
AppState, ShellSurfaceConfig, SurfaceState, WaylandSurfaceConfig, WaylandSystemOps,
|
||||||
};
|
};
|
||||||
use layer_shika_domain::config::SurfaceConfig;
|
use layer_shika_domain::config::SurfaceConfig;
|
||||||
use layer_shika_domain::entities::output_registry::OutputRegistry;
|
use layer_shika_domain::entities::output_registry::OutputRegistry;
|
||||||
|
|
@ -223,7 +223,7 @@ type OutputConnectedHandler = Box<dyn Fn(&OutputInfo)>;
|
||||||
type OutputDisconnectedHandler = Box<dyn Fn(OutputHandle)>;
|
type OutputDisconnectedHandler = Box<dyn Fn(OutputHandle)>;
|
||||||
|
|
||||||
pub struct Shell {
|
pub struct Shell {
|
||||||
inner: Rc<RefCell<ShellSystemFacade>>,
|
inner: Rc<RefCell<dyn WaylandSystemOps>>,
|
||||||
surfaces: HashMap<String, SurfaceDefinition>,
|
surfaces: HashMap<String, SurfaceDefinition>,
|
||||||
surface_handles: HashMap<SurfaceHandle, String>,
|
surface_handles: HashMap<SurfaceHandle, String>,
|
||||||
compilation_result: Rc<CompilationResult>,
|
compilation_result: Rc<CompilationResult>,
|
||||||
|
|
@ -397,8 +397,7 @@ impl Shell {
|
||||||
);
|
);
|
||||||
|
|
||||||
let inner = layer_shika_adapters::WaylandShellSystem::new(&wayland_config)?;
|
let inner = layer_shika_adapters::WaylandShellSystem::new(&wayland_config)?;
|
||||||
let facade = ShellSystemFacade::new(inner);
|
let inner_rc: Rc<RefCell<dyn WaylandSystemOps>> = Rc::new(RefCell::new(inner));
|
||||||
let inner_rc = Rc::new(RefCell::new(facade));
|
|
||||||
|
|
||||||
let (sender, receiver) = channel::channel();
|
let (sender, receiver) = channel::channel();
|
||||||
|
|
||||||
|
|
@ -458,8 +457,7 @@ impl Shell {
|
||||||
.collect::<Result<Vec<_>>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
let inner = layer_shika_adapters::WaylandShellSystem::new_multi(&shell_configs)?;
|
let inner = layer_shika_adapters::WaylandShellSystem::new_multi(&shell_configs)?;
|
||||||
let facade = ShellSystemFacade::new(inner);
|
let inner_rc: Rc<RefCell<dyn WaylandSystemOps>> = Rc::new(RefCell::new(inner));
|
||||||
let inner_rc = Rc::new(RefCell::new(facade));
|
|
||||||
|
|
||||||
let (sender, receiver) = channel::channel();
|
let (sender, receiver) = channel::channel();
|
||||||
|
|
||||||
|
|
@ -492,7 +490,7 @@ impl Shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_popup_command_handler(&self, receiver: channel::Channel<PopupCommand>) -> Result<()> {
|
fn setup_popup_command_handler(&self, receiver: channel::Channel<PopupCommand>) -> Result<()> {
|
||||||
let loop_handle = self.inner.borrow().inner_ref().event_loop_handle();
|
let loop_handle = self.inner.borrow().event_loop_handle();
|
||||||
let control = self.control();
|
let control = self.control();
|
||||||
|
|
||||||
loop_handle
|
loop_handle
|
||||||
|
|
@ -586,8 +584,8 @@ impl Shell {
|
||||||
config: wayland_config,
|
config: wayland_config,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut facade = self.inner.borrow_mut();
|
let mut system = self.inner.borrow_mut();
|
||||||
let handles = facade.inner_mut().spawn_surface(&shell_config)?;
|
let handles = system.spawn_surface(&shell_config)?;
|
||||||
|
|
||||||
let surface_handle = SurfaceHandle::new();
|
let surface_handle = SurfaceHandle::new();
|
||||||
self.surface_handles
|
self.surface_handles
|
||||||
|
|
@ -613,8 +611,8 @@ impl Shell {
|
||||||
|
|
||||||
self.surfaces.remove(&surface_name);
|
self.surfaces.remove(&surface_name);
|
||||||
|
|
||||||
let mut facade = self.inner.borrow_mut();
|
let mut system = self.inner.borrow_mut();
|
||||||
facade.inner_mut().despawn_surface(&surface_name)?;
|
system.despawn_surface(&surface_name)?;
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"Despawned surface '{}' with handle {:?}",
|
"Despawned surface '{}' with handle {:?}",
|
||||||
|
|
@ -666,8 +664,7 @@ impl Shell {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
system
|
system
|
||||||
.app_state()
|
.app_state()
|
||||||
|
|
@ -685,8 +682,7 @@ impl Shell {
|
||||||
where
|
where
|
||||||
F: FnMut(&str, &ComponentInstance),
|
F: FnMut(&str, &ComponentInstance),
|
||||||
{
|
{
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
for name in self.surfaces.keys() {
|
for name in self.surfaces.keys() {
|
||||||
for surface in system.app_state().surfaces_by_name(name) {
|
for surface in system.app_state().surfaces_by_name(name) {
|
||||||
|
|
@ -699,8 +695,7 @@ impl Shell {
|
||||||
where
|
where
|
||||||
F: FnOnce(&ComponentInstance) -> R,
|
F: FnOnce(&ComponentInstance) -> R,
|
||||||
{
|
{
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
let window = system
|
let window = system
|
||||||
.app_state()
|
.app_state()
|
||||||
.get_output_by_handle(handle)
|
.get_output_by_handle(handle)
|
||||||
|
|
@ -716,8 +711,7 @@ impl Shell {
|
||||||
where
|
where
|
||||||
F: FnMut(OutputHandle, &ComponentInstance),
|
F: FnMut(OutputHandle, &ComponentInstance),
|
||||||
{
|
{
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
for (handle, surface) in system.app_state().outputs_with_handles() {
|
for (handle, surface) in system.app_state().outputs_with_handles() {
|
||||||
f(handle, surface.component_instance());
|
f(handle, surface.component_instance());
|
||||||
}
|
}
|
||||||
|
|
@ -746,8 +740,7 @@ impl Shell {
|
||||||
|
|
||||||
let control = self.control();
|
let control = self.control();
|
||||||
let handler = Rc::new(handler);
|
let handler = Rc::new(handler);
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
for surface in system.app_state().surfaces_by_name(surface_name) {
|
for surface in system.app_state().surfaces_by_name(surface_name) {
|
||||||
let handler_rc = Rc::clone(&handler);
|
let handler_rc = Rc::clone(&handler);
|
||||||
|
|
@ -788,8 +781,7 @@ impl Shell {
|
||||||
|
|
||||||
let control = self.control();
|
let control = self.control();
|
||||||
let handler = Rc::new(handler);
|
let handler = Rc::new(handler);
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
for surface in system.app_state().surfaces_by_name(surface_name) {
|
for surface in system.app_state().surfaces_by_name(surface_name) {
|
||||||
let handler_rc = Rc::clone(&handler);
|
let handler_rc = Rc::clone(&handler);
|
||||||
|
|
@ -819,8 +811,7 @@ impl Shell {
|
||||||
{
|
{
|
||||||
let control = self.control();
|
let control = self.control();
|
||||||
let handler = Rc::new(handler);
|
let handler = Rc::new(handler);
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
for surface in system.app_state().all_outputs() {
|
for surface in system.app_state().all_outputs() {
|
||||||
let handler_rc = Rc::clone(&handler);
|
let handler_rc = Rc::clone(&handler);
|
||||||
|
|
@ -849,8 +840,7 @@ impl Shell {
|
||||||
{
|
{
|
||||||
let control = self.control();
|
let control = self.control();
|
||||||
let handler = Rc::new(handler);
|
let handler = Rc::new(handler);
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
for surface in system.app_state().all_outputs() {
|
for surface in system.app_state().all_outputs() {
|
||||||
let handler_rc = Rc::clone(&handler);
|
let handler_rc = Rc::clone(&handler);
|
||||||
|
|
@ -876,8 +866,7 @@ impl Shell {
|
||||||
where
|
where
|
||||||
F: Fn(&ComponentInstance, LayerSurfaceHandle<'_>),
|
F: Fn(&ComponentInstance, LayerSurfaceHandle<'_>),
|
||||||
{
|
{
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
if self.surfaces.contains_key(surface_name) {
|
if self.surfaces.contains_key(surface_name) {
|
||||||
for surface in system.app_state().surfaces_by_name(surface_name) {
|
for surface in system.app_state().surfaces_by_name(surface_name) {
|
||||||
|
|
@ -891,8 +880,7 @@ impl Shell {
|
||||||
where
|
where
|
||||||
F: Fn(&ComponentInstance, LayerSurfaceHandle<'_>),
|
F: Fn(&ComponentInstance, LayerSurfaceHandle<'_>),
|
||||||
{
|
{
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
for surface in system.app_state().all_outputs() {
|
for surface in system.app_state().all_outputs() {
|
||||||
let surface_handle = LayerSurfaceHandle::from_window_state(surface);
|
let surface_handle = LayerSurfaceHandle::from_window_state(surface);
|
||||||
|
|
@ -901,20 +889,17 @@ impl Shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output_registry(&self) -> OutputRegistry {
|
pub fn output_registry(&self) -> OutputRegistry {
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
system.app_state().output_registry().clone()
|
system.app_state().output_registry().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_output_info(&self, handle: OutputHandle) -> Option<OutputInfo> {
|
pub fn get_output_info(&self, handle: OutputHandle) -> Option<OutputInfo> {
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
system.app_state().get_output_info(handle).cloned()
|
system.app_state().get_output_info(handle).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_output_info(&self) -> Vec<OutputInfo> {
|
pub fn all_output_info(&self) -> Vec<OutputInfo> {
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
system.app_state().all_output_info().cloned().collect()
|
system.app_state().all_output_info().cloned().collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -931,8 +916,7 @@ impl ShellRuntime for Shell {
|
||||||
where
|
where
|
||||||
F: FnMut(&ComponentInstance),
|
F: FnMut(&ComponentInstance),
|
||||||
{
|
{
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
if self.surfaces.contains_key(name) {
|
if self.surfaces.contains_key(name) {
|
||||||
for surface in system.app_state().surfaces_by_name(name) {
|
for surface in system.app_state().surfaces_by_name(name) {
|
||||||
|
|
@ -945,8 +929,7 @@ impl ShellRuntime for Shell {
|
||||||
where
|
where
|
||||||
F: FnMut(&str, &ComponentInstance),
|
F: FnMut(&str, &ComponentInstance),
|
||||||
{
|
{
|
||||||
let facade = self.inner.borrow();
|
let system = self.inner.borrow();
|
||||||
let system = facade.inner_ref();
|
|
||||||
|
|
||||||
for name in self.surfaces.keys() {
|
for name in self.surfaces.keys() {
|
||||||
for surface in system.app_state().surfaces_by_name(name) {
|
for surface in system.app_state().surfaces_by_name(name) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue