mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-12-12 13:25:54 +00:00
refactor: consolidate handle types
This commit is contained in:
parent
21e636aabf
commit
f843d931e5
12 changed files with 147 additions and 69 deletions
|
|
@ -49,7 +49,7 @@ impl PopupId {
|
|||
|
||||
#[must_use]
|
||||
const fn to_handle(self) -> PopupHandle {
|
||||
PopupHandle::new(self.0)
|
||||
PopupHandle::from_raw(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -491,25 +491,25 @@ impl PopupManager {
|
|||
#[must_use]
|
||||
pub fn find_by_surface(&self, surface_id: &ObjectId) -> Option<PopupHandle> {
|
||||
self.find_popup_key_by_surface_id(surface_id)
|
||||
.map(PopupHandle::new)
|
||||
.map(PopupHandle::from_raw)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn find_by_fractional_scale(&self, fractional_scale_id: &ObjectId) -> Option<PopupHandle> {
|
||||
self.find_popup_key_by_fractional_scale_id(fractional_scale_id)
|
||||
.map(PopupHandle::new)
|
||||
.map(PopupHandle::from_raw)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn find_by_xdg_popup(&self, xdg_popup_id: &ObjectId) -> Option<PopupHandle> {
|
||||
self.find_popup_key_by_xdg_popup_id(xdg_popup_id)
|
||||
.map(PopupHandle::new)
|
||||
.map(PopupHandle::from_raw)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn find_by_xdg_surface(&self, xdg_surface_id: &ObjectId) -> Option<PopupHandle> {
|
||||
self.find_popup_key_by_xdg_surface_id(xdg_surface_id)
|
||||
.map(PopupHandle::new)
|
||||
.map(PopupHandle::from_raw)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -526,7 +526,7 @@ impl PopupManager {
|
|||
|
||||
if let Some(popup_handle) = self
|
||||
.find_popup_key_by_surface_id(&surface_id)
|
||||
.map(PopupHandle::new)
|
||||
.map(PopupHandle::from_raw)
|
||||
{
|
||||
return ActiveWindow::Popup(popup_handle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,8 +73,3 @@ where
|
|||
self(instance, surface);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ShellSurfaceHandle {
|
||||
pub name: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ pub use layer_shika_adapters::platform::{slint, slint_interpreter};
|
|||
pub use layer_shika_domain::entities::output_registry::OutputRegistry;
|
||||
pub use layer_shika_domain::prelude::AnchorStrategy;
|
||||
pub use layer_shika_domain::value_objects::anchor::AnchorEdges;
|
||||
pub use layer_shika_domain::value_objects::handle::{Handle, SurfaceHandle};
|
||||
pub use layer_shika_domain::value_objects::keyboard_interactivity::KeyboardInteractivity;
|
||||
pub use layer_shika_domain::value_objects::layer::Layer;
|
||||
pub use layer_shika_domain::value_objects::output_handle::OutputHandle;
|
||||
|
|
@ -32,7 +33,7 @@ pub use shell_runtime::{DEFAULT_SURFACE_NAME, ShellRuntime};
|
|||
pub use system::{EventContext, EventLoopHandle, ShellControl, SingleSurfaceShell};
|
||||
pub use value_conversion::IntoValue;
|
||||
|
||||
pub use layer_surface::{LayerSurfaceHandle, ShellSurfaceConfigHandler, ShellSurfaceHandle};
|
||||
pub use layer_surface::{LayerSurfaceHandle, ShellSurfaceConfigHandler};
|
||||
|
||||
pub use shell::{
|
||||
DEFAULT_COMPONENT_NAME, Shell, ShellBuilder, ShellEventContext, ShellEventLoopHandle,
|
||||
|
|
@ -64,13 +65,13 @@ pub enum Error {
|
|||
pub mod prelude {
|
||||
pub use crate::{
|
||||
AnchorEdges, AnchorStrategy, CompiledUiSource, DEFAULT_COMPONENT_NAME,
|
||||
DEFAULT_SURFACE_NAME, EventContext, EventLoopHandle, IntoValue, KeyboardInteractivity,
|
||||
Layer, LayerSurfaceHandle, OutputGeometry, OutputHandle, OutputInfo, OutputPolicy,
|
||||
OutputRegistry, PopupBuilder, PopupHandle, PopupPlacement, PopupPositioningMode,
|
||||
PopupRequest, PopupSize, PopupWindow, Result, Shell, ShellBuilder, ShellConfig,
|
||||
ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime,
|
||||
ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleSurfaceShell, SurfaceComponentConfig,
|
||||
SurfaceConfigBuilder, SurfaceDefinition,
|
||||
DEFAULT_SURFACE_NAME, EventContext, EventLoopHandle, Handle, IntoValue,
|
||||
KeyboardInteractivity, Layer, LayerSurfaceHandle, OutputGeometry, OutputHandle, OutputInfo,
|
||||
OutputPolicy, OutputRegistry, PopupBuilder, PopupHandle, PopupPlacement,
|
||||
PopupPositioningMode, PopupRequest, PopupSize, PopupWindow, Result, Shell, ShellBuilder,
|
||||
ShellConfig, ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime,
|
||||
ShellSurfaceConfigHandler, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder,
|
||||
SurfaceDefinition, SurfaceHandle,
|
||||
};
|
||||
|
||||
pub use crate::calloop::{Generic, Interest, Mode, PostAction, RegistrationToken, Timer};
|
||||
|
|
|
|||
|
|
@ -480,7 +480,7 @@ impl EventContext<'_> {
|
|||
|
||||
if control
|
||||
.resize_popup(
|
||||
PopupHandle::new(popup_key),
|
||||
PopupHandle::from_raw(popup_key),
|
||||
dimensions.width,
|
||||
dimensions.height,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ pub use crate::surface_dimensions::SurfaceDimensions;
|
|||
pub use crate::value_objects::anchor::AnchorEdges;
|
||||
pub use crate::value_objects::anchor_strategy::AnchorStrategy;
|
||||
pub use crate::value_objects::dimensions::{PopupDimensions, SurfaceDimension};
|
||||
pub use crate::value_objects::handle::{Handle, OutputHandle, PopupHandle, SurfaceHandle};
|
||||
pub use crate::value_objects::keyboard_interactivity::KeyboardInteractivity;
|
||||
pub use crate::value_objects::layer::Layer;
|
||||
pub use crate::value_objects::margins::Margins;
|
||||
pub use crate::value_objects::output_handle::OutputHandle;
|
||||
pub use crate::value_objects::output_info::{OutputGeometry, OutputInfo};
|
||||
pub use crate::value_objects::output_policy::OutputPolicy;
|
||||
pub use crate::value_objects::ui_source::UiSource;
|
||||
|
|
|
|||
116
crates/domain/src/value_objects/handle.rs
Normal file
116
crates/domain/src/value_objects/handle.rs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
use std::fmt::{Debug, Formatter, Result as FmtResult};
|
||||
use std::hash::Hash;
|
||||
use std::hash::Hasher;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
static NEXT_HANDLE_ID: AtomicUsize = AtomicUsize::new(1);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct HandleId(usize);
|
||||
|
||||
impl HandleId {
|
||||
fn new() -> Self {
|
||||
Self(NEXT_HANDLE_ID.fetch_add(1, Ordering::Relaxed))
|
||||
}
|
||||
|
||||
const fn from_raw(id: usize) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
|
||||
pub const fn as_usize(&self) -> usize {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for HandleId {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Output;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Popup;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Surface;
|
||||
|
||||
pub struct Handle<T> {
|
||||
id: HandleId,
|
||||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> Debug for Handle<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.debug_struct("Handle").field("id", &self.id).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Handle<T> {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
id: HandleId::new(),
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn from_raw(id: usize) -> Self {
|
||||
Self {
|
||||
id: HandleId::from_raw(id),
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn id(&self) -> usize {
|
||||
self.id.as_usize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for Handle<T> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::non_canonical_clone_impl)]
|
||||
impl<T> Clone for Handle<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
id: self.id,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Copy for Handle<T> {}
|
||||
|
||||
impl<T> PartialEq for Handle<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Handle<T> {}
|
||||
|
||||
impl<T> Hash for Handle<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.id.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Popup> {
|
||||
#[must_use]
|
||||
pub const fn key(self) -> usize {
|
||||
self.id()
|
||||
}
|
||||
}
|
||||
|
||||
pub type OutputHandle = Handle<Output>;
|
||||
pub type PopupHandle = Handle<Popup>;
|
||||
pub type SurfaceHandle = Handle<Surface>;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
pub mod anchor;
|
||||
pub mod anchor_strategy;
|
||||
pub mod dimensions;
|
||||
pub mod handle;
|
||||
pub mod keyboard_interactivity;
|
||||
pub mod layer;
|
||||
pub mod margins;
|
||||
|
|
|
|||
|
|
@ -1,26 +1,3 @@
|
|||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
#![allow(clippy::pub_use)]
|
||||
|
||||
static NEXT_OUTPUT_ID: AtomicUsize = AtomicUsize::new(1);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct OutputHandle {
|
||||
id: usize,
|
||||
}
|
||||
|
||||
impl OutputHandle {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
id: NEXT_OUTPUT_ID.fetch_add(1, Ordering::Relaxed),
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn id(&self) -> usize {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for OutputHandle {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
pub use super::handle::OutputHandle;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,8 @@
|
|||
#![allow(clippy::pub_use)]
|
||||
|
||||
pub use super::handle::PopupHandle;
|
||||
use super::popup_positioning_mode::PopupPositioningMode;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct PopupHandle(usize);
|
||||
|
||||
impl PopupHandle {
|
||||
#[must_use]
|
||||
pub const fn new(key: usize) -> Self {
|
||||
Self(key)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn key(self) -> usize {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PopupRequest {
|
||||
pub component: String,
|
||||
|
|
|
|||
|
|
@ -118,13 +118,13 @@ pub mod shell;
|
|||
pub mod slint_integration;
|
||||
pub mod window;
|
||||
|
||||
pub use layer_shika_composition::{Error, Result};
|
||||
pub use layer_shika_composition::{Error, Handle, Result, SurfaceHandle};
|
||||
|
||||
pub use shell::{
|
||||
CompiledUiSource, DEFAULT_COMPONENT_NAME, DEFAULT_SURFACE_NAME, LayerSurfaceHandle, Shell,
|
||||
ShellBuilder, ShellConfig, ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime,
|
||||
ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleSurfaceShell, SurfaceComponentConfig,
|
||||
SurfaceConfigBuilder, SurfaceDefinition,
|
||||
ShellSurfaceConfigHandler, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder,
|
||||
SurfaceDefinition,
|
||||
};
|
||||
|
||||
pub use window::{
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
pub use crate::shell::{
|
||||
CompiledUiSource, DEFAULT_COMPONENT_NAME, DEFAULT_SURFACE_NAME, LayerSurfaceHandle, Shell,
|
||||
ShellBuilder, ShellConfig, ShellControl, ShellEventContext, ShellEventLoopHandle, ShellRuntime,
|
||||
ShellSurfaceConfigHandler, ShellSurfaceHandle, SingleSurfaceShell, SurfaceComponentConfig,
|
||||
SurfaceConfigBuilder, SurfaceDefinition,
|
||||
ShellSurfaceConfigHandler, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder,
|
||||
SurfaceDefinition,
|
||||
};
|
||||
|
||||
pub use crate::window::{
|
||||
|
|
@ -26,7 +26,7 @@ pub use crate::event::{EventContext, EventLoopHandle};
|
|||
|
||||
pub use crate::slint_integration::{PopupWindow, slint, slint_interpreter};
|
||||
|
||||
pub use crate::{Error, Result};
|
||||
pub use crate::{Error, Handle, Result, SurfaceHandle};
|
||||
|
||||
pub use layer_shika_composition::prelude::{
|
||||
Anchor, LogicalSize, Margins, PhysicalSize, ScaleFactor, SurfaceConfig, SurfaceDimension,
|
||||
|
|
|
|||
|
|
@ -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, SingleSurfaceShell, SurfaceComponentConfig,
|
||||
SurfaceConfigBuilder, SurfaceDefinition,
|
||||
ShellSurfaceConfigHandler, SingleSurfaceShell, SurfaceComponentConfig, SurfaceConfigBuilder,
|
||||
SurfaceDefinition,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue