mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-12-12 14:25:54 +00:00
refactor: unify naming patterns between app and shell
This commit is contained in:
parent
e6a087a385
commit
dc9374b76d
6 changed files with 130 additions and 6 deletions
|
|
@ -4,6 +4,7 @@ mod builder;
|
|||
mod popup_builder;
|
||||
mod shell;
|
||||
mod shell_composition;
|
||||
mod shell_runtime;
|
||||
mod system;
|
||||
mod value_conversion;
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ pub use layer_shika_domain::value_objects::popup_request::{
|
|||
PopupHandle, PopupPlacement, PopupRequest, PopupSize,
|
||||
};
|
||||
pub use popup_builder::PopupBuilder;
|
||||
pub use shell_runtime::{DEFAULT_WINDOW_NAME, ShellRuntime};
|
||||
pub use system::{EventContext, EventLoopHandle, ShellControl, SingleWindowShell};
|
||||
|
||||
pub use shell::{
|
||||
|
|
@ -57,10 +59,11 @@ pub enum Error {
|
|||
|
||||
pub mod prelude {
|
||||
pub use crate::{
|
||||
AnchorEdges, AnchorStrategy, EventContext, EventLoopHandle, KeyboardInteractivity, Layer,
|
||||
LayerShika, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy, OutputRegistry,
|
||||
PopupBuilder, PopupHandle, PopupPlacement, PopupPositioningMode, PopupRequest, PopupSize,
|
||||
PopupWindow, Result, ShellControl, SingleWindowShell,
|
||||
AnchorEdges, AnchorStrategy, DEFAULT_WINDOW_NAME, EventContext, EventLoopHandle,
|
||||
KeyboardInteractivity, Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo,
|
||||
OutputPolicy, OutputRegistry, PopupBuilder, PopupHandle, PopupPlacement,
|
||||
PopupPositioningMode, PopupRequest, PopupSize, PopupWindow, Result, ShellControl,
|
||||
ShellRuntime, SingleWindowShell,
|
||||
};
|
||||
|
||||
pub use crate::{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::shell_composition::ShellWindowDefinition;
|
||||
use crate::shell_runtime::ShellRuntime;
|
||||
use crate::system::{EventContext, PopupCommand, ShellControl};
|
||||
use crate::{Error, Result};
|
||||
use layer_shika_adapters::errors::EventLoopError;
|
||||
|
|
@ -335,6 +336,54 @@ impl Shell {
|
|||
}
|
||||
}
|
||||
|
||||
impl ShellRuntime for Shell {
|
||||
type LoopHandle = ShellEventLoopHandle;
|
||||
type Context<'a> = ShellEventContext<'a>;
|
||||
|
||||
fn event_loop_handle(&self) -> Self::LoopHandle {
|
||||
ShellEventLoopHandle {
|
||||
system: Rc::downgrade(&self.inner),
|
||||
}
|
||||
}
|
||||
|
||||
fn with_component<F>(&self, name: &str, mut f: F)
|
||||
where
|
||||
F: FnMut(&ComponentInstance),
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn with_all_components<F>(&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() {
|
||||
if let Some(window) = system.app_state().primary_output() {
|
||||
f(name, window.component_instance());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&mut self) -> Result<()> {
|
||||
log::info!(
|
||||
"Starting shell event loop with {} windows",
|
||||
self.windows.len()
|
||||
);
|
||||
self.inner.borrow_mut().run()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ShellEventLoopHandle {
|
||||
system: Weak<RefCell<WindowingSystemFacade>>,
|
||||
}
|
||||
|
|
|
|||
20
crates/composition/src/shell_runtime.rs
Normal file
20
crates/composition/src/shell_runtime.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use layer_shika_adapters::platform::slint_interpreter::ComponentInstance;
|
||||
|
||||
pub const DEFAULT_WINDOW_NAME: &str = "main";
|
||||
|
||||
pub trait ShellRuntime {
|
||||
type LoopHandle;
|
||||
type Context<'a>;
|
||||
|
||||
fn event_loop_handle(&self) -> Self::LoopHandle;
|
||||
|
||||
fn with_component<F>(&self, name: &str, f: F)
|
||||
where
|
||||
F: FnMut(&ComponentInstance);
|
||||
|
||||
fn with_all_components<F>(&self, f: F)
|
||||
where
|
||||
F: FnMut(&str, &ComponentInstance);
|
||||
|
||||
fn run(&mut self) -> crate::Result<()>;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::popup_builder::PopupBuilder;
|
||||
use crate::shell_runtime::{DEFAULT_WINDOW_NAME, ShellRuntime};
|
||||
use crate::value_conversion::IntoValue;
|
||||
use crate::{Error, Result};
|
||||
use layer_shika_adapters::errors::EventLoopError;
|
||||
|
|
@ -646,6 +647,7 @@ impl EventContext<'_> {
|
|||
pub struct SingleWindowShell {
|
||||
inner: Rc<RefCell<WindowingSystemFacade>>,
|
||||
popup_command_sender: channel::Sender<PopupCommand>,
|
||||
window_name: String,
|
||||
}
|
||||
|
||||
impl SingleWindowShell {
|
||||
|
|
@ -668,6 +670,7 @@ impl SingleWindowShell {
|
|||
let shell = Self {
|
||||
inner: Rc::clone(&inner_rc),
|
||||
popup_command_sender: sender,
|
||||
window_name: DEFAULT_WINDOW_NAME.to_string(),
|
||||
};
|
||||
|
||||
shell.setup_popup_command_handler(receiver)?;
|
||||
|
|
@ -675,6 +678,17 @@ impl SingleWindowShell {
|
|||
Ok(shell)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_window_name(mut self, name: impl Into<String>) -> Self {
|
||||
self.window_name = name.into();
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn window_name(&self) -> &str {
|
||||
&self.window_name
|
||||
}
|
||||
|
||||
fn setup_popup_command_handler(&self, receiver: channel::Channel<PopupCommand>) -> Result<()> {
|
||||
let loop_handle = self.inner.borrow().inner_ref().event_loop_handle();
|
||||
let control = self.control();
|
||||
|
|
@ -857,3 +871,41 @@ impl SingleWindowShell {
|
|||
system.app_state().output_registry().clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl ShellRuntime for SingleWindowShell {
|
||||
type LoopHandle = EventLoopHandle;
|
||||
type Context<'a> = EventContext<'a>;
|
||||
|
||||
fn event_loop_handle(&self) -> Self::LoopHandle {
|
||||
EventLoopHandle {
|
||||
system: Rc::downgrade(&self.inner),
|
||||
}
|
||||
}
|
||||
|
||||
fn with_component<F>(&self, _name: &str, mut f: F)
|
||||
where
|
||||
F: FnMut(&ComponentInstance),
|
||||
{
|
||||
let facade = self.inner.borrow();
|
||||
let system = facade.inner_ref();
|
||||
for window in system.app_state().all_outputs() {
|
||||
f(window.component_instance());
|
||||
}
|
||||
}
|
||||
|
||||
fn with_all_components<F>(&self, mut f: F)
|
||||
where
|
||||
F: FnMut(&str, &ComponentInstance),
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&mut self) -> Result<()> {
|
||||
self.inner.borrow_mut().run()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ pub use layer_shika_composition::{
|
|||
AnchorEdges, AnchorStrategy, Error, EventContext, EventLoopHandle, KeyboardInteractivity,
|
||||
Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy, OutputRegistry,
|
||||
PopupHandle, PopupPlacement, PopupPositioningMode, PopupRequest, PopupSize, PopupWindow,
|
||||
Result, ShellControl, SingleWindowShell,
|
||||
Result, ShellControl, ShellRuntime, SingleWindowShell, DEFAULT_WINDOW_NAME,
|
||||
};
|
||||
|
||||
pub use layer_shika_composition::{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
pub use crate::{
|
||||
Error, EventContext, EventLoopHandle, LayerShika, PopupWindow, Result, ShellControl,
|
||||
SingleWindowShell,
|
||||
ShellRuntime, SingleWindowShell, DEFAULT_WINDOW_NAME,
|
||||
};
|
||||
|
||||
pub use crate::{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue