mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-11-03 22:34:23 +00:00
feat: store compilation result
This commit is contained in:
parent
0b43e5e7b6
commit
898568f358
6 changed files with 91 additions and 20 deletions
|
|
@ -2,11 +2,12 @@ use layer_shika_domain::prelude::{
|
||||||
AnchorEdges, KeyboardInteractivity as DomainKeyboardInteractivity, Layer, Margins,
|
AnchorEdges, KeyboardInteractivity as DomainKeyboardInteractivity, Layer, Margins,
|
||||||
WindowConfig as DomainWindowConfig,
|
WindowConfig as DomainWindowConfig,
|
||||||
};
|
};
|
||||||
use slint_interpreter::ComponentDefinition;
|
use slint_interpreter::{ComponentDefinition, CompilationResult};
|
||||||
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::{
|
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::{
|
||||||
zwlr_layer_shell_v1::{self},
|
zwlr_layer_shell_v1::{self},
|
||||||
zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity as WaylandKeyboardInteractivity},
|
zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity as WaylandKeyboardInteractivity},
|
||||||
};
|
};
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub(crate) struct LayerSurfaceParams {
|
pub(crate) struct LayerSurfaceParams {
|
||||||
|
|
@ -28,12 +29,14 @@ pub struct WaylandWindowConfig {
|
||||||
pub scale_factor: f32,
|
pub scale_factor: f32,
|
||||||
pub namespace: String,
|
pub namespace: String,
|
||||||
pub component_definition: ComponentDefinition,
|
pub component_definition: ComponentDefinition,
|
||||||
|
pub compilation_result: Option<Rc<CompilationResult>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WaylandWindowConfig {
|
impl WaylandWindowConfig {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_domain_config(
|
pub fn from_domain_config(
|
||||||
component_definition: ComponentDefinition,
|
component_definition: ComponentDefinition,
|
||||||
|
compilation_result: Option<Rc<CompilationResult>>,
|
||||||
domain_config: DomainWindowConfig,
|
domain_config: DomainWindowConfig,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -48,6 +51,7 @@ impl WaylandWindowConfig {
|
||||||
scale_factor: domain_config.scale_factor,
|
scale_factor: domain_config.scale_factor,
|
||||||
namespace: domain_config.namespace,
|
namespace: domain_config.namespace,
|
||||||
component_definition,
|
component_definition,
|
||||||
|
compilation_result,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ impl WaylandWindowingSystem {
|
||||||
|
|
||||||
let mut builder = WindowStateBuilder::new()
|
let mut builder = WindowStateBuilder::new()
|
||||||
.with_component_definition(config.component_definition)
|
.with_component_definition(config.component_definition)
|
||||||
|
.with_compilation_result(config.compilation_result)
|
||||||
.with_surface(Rc::clone(&surface_ctx.surface))
|
.with_surface(Rc::clone(&surface_ctx.surface))
|
||||||
.with_layer_surface(Rc::clone(&surface_ctx.layer_surface))
|
.with_layer_surface(Rc::clone(&surface_ctx.layer_surface))
|
||||||
.with_scale_factor(config.scale_factor)
|
.with_scale_factor(config.scale_factor)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use slint::{
|
||||||
platform::{set_platform, Platform, WindowAdapter},
|
platform::{set_platform, Platform, WindowAdapter},
|
||||||
PhysicalSize, PlatformError,
|
PhysicalSize, PlatformError,
|
||||||
};
|
};
|
||||||
use slint_interpreter::ComponentDefinition;
|
use slint_interpreter::{ComponentDefinition, CompilationResult};
|
||||||
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
|
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
|
||||||
use wayland_client::{protocol::{wl_pointer::WlPointer, wl_surface::WlSurface}, Connection};
|
use wayland_client::{protocol::{wl_pointer::WlPointer, wl_surface::WlSurface}, Connection};
|
||||||
use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1;
|
use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1;
|
||||||
|
|
@ -25,6 +25,7 @@ impl Platform for PlatformWrapper {
|
||||||
|
|
||||||
pub struct WindowStateBuilder {
|
pub struct WindowStateBuilder {
|
||||||
pub component_definition: Option<ComponentDefinition>,
|
pub component_definition: Option<ComponentDefinition>,
|
||||||
|
pub compilation_result: Option<Rc<CompilationResult>>,
|
||||||
pub surface: Option<Rc<WlSurface>>,
|
pub surface: Option<Rc<WlSurface>>,
|
||||||
pub layer_surface: Option<Rc<ZwlrLayerSurfaceV1>>,
|
pub layer_surface: Option<Rc<ZwlrLayerSurfaceV1>>,
|
||||||
pub fractional_scale: Option<Rc<WpFractionalScaleV1>>,
|
pub fractional_scale: Option<Rc<WpFractionalScaleV1>>,
|
||||||
|
|
@ -105,6 +106,12 @@ impl WindowStateBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_compilation_result(mut self, compilation_result: Option<Rc<CompilationResult>>) -> Self {
|
||||||
|
self.compilation_result = compilation_result;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_fractional_scale(mut self, fractional_scale: Rc<WpFractionalScaleV1>) -> Self {
|
pub fn with_fractional_scale(mut self, fractional_scale: Rc<WpFractionalScaleV1>) -> Self {
|
||||||
self.fractional_scale = Some(fractional_scale);
|
self.fractional_scale = Some(fractional_scale);
|
||||||
|
|
@ -141,6 +148,7 @@ impl Default for WindowStateBuilder {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
component_definition: None,
|
component_definition: None,
|
||||||
|
compilation_result: None,
|
||||||
surface: None,
|
surface: None,
|
||||||
layer_surface: None,
|
layer_surface: None,
|
||||||
fractional_scale: None,
|
fractional_scale: None,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use layer_shika_domain::surface_dimensions::SurfaceDimensions;
|
||||||
use log::info;
|
use log::info;
|
||||||
use slint::{LogicalPosition, PhysicalSize, ComponentHandle};
|
use slint::{LogicalPosition, PhysicalSize, ComponentHandle};
|
||||||
use slint::platform::{WindowAdapter, WindowEvent};
|
use slint::platform::{WindowAdapter, WindowEvent};
|
||||||
use slint_interpreter::ComponentInstance;
|
use slint_interpreter::{ComponentInstance, CompilationResult};
|
||||||
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
|
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
|
||||||
use wayland_client::{protocol::wl_surface::WlSurface, Proxy};
|
use wayland_client::{protocol::wl_surface::WlSurface, Proxy};
|
||||||
use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1;
|
use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1;
|
||||||
|
|
@ -89,6 +89,7 @@ impl MutableWindowState {
|
||||||
|
|
||||||
pub struct WindowState {
|
pub struct WindowState {
|
||||||
component_instance: ComponentInstance,
|
component_instance: ComponentInstance,
|
||||||
|
compilation_result: Option<Rc<CompilationResult>>,
|
||||||
viewport: Option<ManagedWpViewport>,
|
viewport: Option<ManagedWpViewport>,
|
||||||
fractional_scale: Option<ManagedWpFractionalScaleV1>,
|
fractional_scale: Option<ManagedWpFractionalScaleV1>,
|
||||||
layer_surface: ManagedZwlrLayerSurfaceV1,
|
layer_surface: ManagedZwlrLayerSurfaceV1,
|
||||||
|
|
@ -160,6 +161,7 @@ impl WindowState {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
component_instance,
|
component_instance,
|
||||||
|
compilation_result: builder.compilation_result,
|
||||||
viewport,
|
viewport,
|
||||||
fractional_scale,
|
fractional_scale,
|
||||||
layer_surface,
|
layer_surface,
|
||||||
|
|
@ -317,6 +319,11 @@ impl WindowState {
|
||||||
&self.component_instance
|
&self.component_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn compilation_result(&self) -> Option<Rc<CompilationResult>> {
|
||||||
|
self.compilation_result.as_ref().map(Rc::clone)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_frame_if_dirty(&self) -> Result<()> {
|
pub fn render_frame_if_dirty(&self) -> Result<()> {
|
||||||
self.window.render_frame_if_dirty()
|
self.window.render_frame_if_dirty()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,20 @@
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::system::WindowingSystem;
|
use crate::system::WindowingSystem;
|
||||||
use layer_shika_adapters::platform::slint_interpreter::{Compiler, ComponentDefinition};
|
use layer_shika_adapters::platform::slint_interpreter::{
|
||||||
|
CompilationResult, Compiler, ComponentDefinition,
|
||||||
|
};
|
||||||
use layer_shika_domain::errors::DomainError;
|
use layer_shika_domain::errors::DomainError;
|
||||||
use layer_shika_domain::prelude::{
|
use layer_shika_domain::prelude::{
|
||||||
AnchorEdges, KeyboardInteractivity, Layer, Margins, WindowConfig,
|
AnchorEdges, KeyboardInteractivity, Layer, Margins, WindowConfig,
|
||||||
};
|
};
|
||||||
use spin_on::spin_on;
|
use spin_on::spin_on;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub struct NeedsComponent;
|
pub struct NeedsComponent;
|
||||||
pub struct HasComponent {
|
pub struct HasComponent {
|
||||||
component_definition: ComponentDefinition,
|
component_definition: ComponentDefinition,
|
||||||
|
compilation_result: Option<Rc<CompilationResult>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LayerShika<State> {
|
pub struct LayerShika<State> {
|
||||||
|
|
@ -24,6 +28,7 @@ impl LayerShika<NeedsComponent> {
|
||||||
LayerShika {
|
LayerShika {
|
||||||
state: HasComponent {
|
state: HasComponent {
|
||||||
component_definition,
|
component_definition,
|
||||||
|
compilation_result: None,
|
||||||
},
|
},
|
||||||
config: WindowConfig::default(),
|
config: WindowConfig::default(),
|
||||||
}
|
}
|
||||||
|
|
@ -59,17 +64,23 @@ impl LayerShika<NeedsComponent> {
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let definition = compilation_result.component(component_name).ok_or_else(|| {
|
let definition = compilation_result
|
||||||
DomainError::Configuration {
|
.component(component_name)
|
||||||
|
.ok_or_else(|| DomainError::Configuration {
|
||||||
message: format!(
|
message: format!(
|
||||||
"Component '{}' not found in Slint file '{}'",
|
"Component '{}' not found in Slint file '{}'",
|
||||||
component_name,
|
component_name,
|
||||||
path.as_ref().display()
|
path.as_ref().display()
|
||||||
),
|
),
|
||||||
}
|
})?;
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(Self::new(definition))
|
Ok(LayerShika {
|
||||||
|
state: HasComponent {
|
||||||
|
component_definition: definition,
|
||||||
|
compilation_result: Some(Rc::new(compilation_result)),
|
||||||
|
},
|
||||||
|
config: WindowConfig::default(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_source(
|
pub fn from_source(
|
||||||
|
|
@ -103,17 +114,32 @@ impl LayerShika<NeedsComponent> {
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let definition = compilation_result.component(component_name).ok_or_else(|| {
|
let definition = compilation_result
|
||||||
DomainError::Configuration {
|
.component(component_name)
|
||||||
message: format!("Component '{}' not found in Slint source code", component_name),
|
.ok_or_else(|| DomainError::Configuration {
|
||||||
}
|
message: format!(
|
||||||
})?;
|
"Component '{}' not found in Slint source code",
|
||||||
|
component_name
|
||||||
|
),
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(Self::new(definition))
|
Ok(LayerShika {
|
||||||
|
state: HasComponent {
|
||||||
|
component_definition: definition,
|
||||||
|
compilation_result: Some(Rc::new(compilation_result)),
|
||||||
|
},
|
||||||
|
config: WindowConfig::default(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayerShika<HasComponent> {
|
impl LayerShika<HasComponent> {
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_compilation_result(mut self, compilation_result: Rc<CompilationResult>) -> Self {
|
||||||
|
self.state.compilation_result = Some(compilation_result);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn with_height(mut self, height: u32) -> Self {
|
pub const fn with_height(mut self, height: u32) -> Self {
|
||||||
self.config.height = height;
|
self.config.height = height;
|
||||||
|
|
@ -168,6 +194,10 @@ impl LayerShika<HasComponent> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self) -> Result<WindowingSystem> {
|
pub fn build(self) -> Result<WindowingSystem> {
|
||||||
WindowingSystem::new(self.state.component_definition, self.config)
|
WindowingSystem::new(
|
||||||
|
self.state.component_definition,
|
||||||
|
self.state.compilation_result,
|
||||||
|
self.config,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ 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::platform::slint_interpreter::{ComponentDefinition, ComponentInstance};
|
use layer_shika_adapters::platform::slint_interpreter::{
|
||||||
|
CompilationResult, ComponentDefinition, ComponentInstance,
|
||||||
|
};
|
||||||
use layer_shika_adapters::wayland::{
|
use layer_shika_adapters::wayland::{
|
||||||
config::WaylandWindowConfig, shell_adapter::WaylandWindowingSystem,
|
config::WaylandWindowConfig, shell_adapter::WaylandWindowingSystem,
|
||||||
surfaces::surface_state::WindowState,
|
surfaces::surface_state::WindowState,
|
||||||
|
|
@ -68,7 +70,10 @@ impl EventLoopHandle {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_channel<T, F>(&self, mut callback: F) -> Result<(RegistrationToken, channel::Sender<T>)>
|
pub fn add_channel<T, F>(
|
||||||
|
&self,
|
||||||
|
mut callback: F,
|
||||||
|
) -> Result<(RegistrationToken, channel::Sender<T>)>
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
F: FnMut(T, RuntimeState<'_>) + 'static,
|
F: FnMut(T, RuntimeState<'_>) + 'static,
|
||||||
|
|
@ -82,7 +87,13 @@ impl EventLoopHandle {
|
||||||
Ok((token, sender))
|
Ok((token, sender))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_fd<F, T>(&self, fd: T, interest: Interest, mode: Mode, mut callback: F) -> Result<RegistrationToken>
|
pub fn add_fd<F, T>(
|
||||||
|
&self,
|
||||||
|
fd: T,
|
||||||
|
interest: Interest,
|
||||||
|
mode: Mode,
|
||||||
|
mut callback: F,
|
||||||
|
) -> Result<RegistrationToken>
|
||||||
where
|
where
|
||||||
T: AsFd + 'static,
|
T: AsFd + 'static,
|
||||||
F: FnMut(RuntimeState<'_>) + 'static,
|
F: FnMut(RuntimeState<'_>) + 'static,
|
||||||
|
|
@ -108,6 +119,11 @@ impl RuntimeState<'_> {
|
||||||
pub fn render_frame_if_dirty(&mut self) -> Result<()> {
|
pub fn render_frame_if_dirty(&mut self) -> Result<()> {
|
||||||
Ok(self.window_state.render_frame_if_dirty()?)
|
Ok(self.window_state.render_frame_if_dirty()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn compilation_result(&self) -> Option<Rc<CompilationResult>> {
|
||||||
|
self.window_state.compilation_result()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WindowingSystem {
|
pub struct WindowingSystem {
|
||||||
|
|
@ -117,9 +133,14 @@ pub struct WindowingSystem {
|
||||||
impl WindowingSystem {
|
impl WindowingSystem {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
component_definition: ComponentDefinition,
|
component_definition: ComponentDefinition,
|
||||||
|
compilation_result: Option<Rc<CompilationResult>>,
|
||||||
config: WindowConfig,
|
config: WindowConfig,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let wayland_config = WaylandWindowConfig::from_domain_config(component_definition, config);
|
let wayland_config = WaylandWindowConfig::from_domain_config(
|
||||||
|
component_definition,
|
||||||
|
compilation_result,
|
||||||
|
config,
|
||||||
|
);
|
||||||
let inner = WaylandWindowingSystem::new(wayland_config)?;
|
let inner = WaylandWindowingSystem::new(wayland_config)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue