mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-10-28 16:24:23 +00:00
refactor: wayland objects proxy
This commit is contained in:
parent
ccf49145a0
commit
6621db62c8
5 changed files with 247 additions and 22 deletions
|
|
@ -2,6 +2,7 @@ pub mod builder;
|
||||||
mod config;
|
mod config;
|
||||||
mod globals;
|
mod globals;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
mod proxies;
|
||||||
mod state;
|
mod state;
|
||||||
mod surface;
|
mod surface;
|
||||||
mod surface_dimensions;
|
mod surface_dimensions;
|
||||||
|
|
|
||||||
194
src/windowing/proxies.rs
Normal file
194
src/windowing/proxies.rs
Normal file
|
|
@ -0,0 +1,194 @@
|
||||||
|
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_protocols::wp::{
|
||||||
|
fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1,
|
||||||
|
viewporter::client::wp_viewport::WpViewport,
|
||||||
|
};
|
||||||
|
use std::{ops::Deref, rc::Rc};
|
||||||
|
use log::{debug, error};
|
||||||
|
|
||||||
|
pub struct ManagedWlPointer {
|
||||||
|
pointer: Rc<WlPointer>,
|
||||||
|
connection: Rc<Connection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ManagedWlPointer {
|
||||||
|
pub const fn new(pointer: Rc<WlPointer>, connection: Rc<Connection>) -> Self {
|
||||||
|
Self {
|
||||||
|
pointer,
|
||||||
|
connection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub const fn inner(&self) -> &Rc<WlPointer> {
|
||||||
|
&self.pointer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for ManagedWlPointer {
|
||||||
|
type Target = WlPointer;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.pointer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ManagedWlPointer {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
debug!("Releasing WlPointer");
|
||||||
|
self.pointer.release();
|
||||||
|
if let Err(e) = self.connection.flush() {
|
||||||
|
error!("Failed to flush after releasing WlPointer: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ManagedWlSurface {
|
||||||
|
surface: Rc<WlSurface>,
|
||||||
|
connection: Rc<Connection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ManagedWlSurface {
|
||||||
|
pub const fn new(surface: Rc<WlSurface>, connection: Rc<Connection>) -> Self {
|
||||||
|
Self {
|
||||||
|
surface,
|
||||||
|
connection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn inner(&self) -> &Rc<WlSurface> {
|
||||||
|
&self.surface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for ManagedWlSurface {
|
||||||
|
type Target = WlSurface;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.surface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ManagedWlSurface {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
debug!("Destroying WlSurface");
|
||||||
|
self.surface.destroy();
|
||||||
|
if let Err(e) = self.connection.flush() {
|
||||||
|
error!("Failed to flush after destroying WlSurface: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ManagedZwlrLayerSurfaceV1 {
|
||||||
|
layer_surface: Rc<ZwlrLayerSurfaceV1>,
|
||||||
|
connection: Rc<Connection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ManagedZwlrLayerSurfaceV1 {
|
||||||
|
pub const fn new(layer_surface: Rc<ZwlrLayerSurfaceV1>, connection: Rc<Connection>) -> Self {
|
||||||
|
Self {
|
||||||
|
layer_surface,
|
||||||
|
connection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn inner(&self) -> &Rc<ZwlrLayerSurfaceV1> {
|
||||||
|
&self.layer_surface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for ManagedZwlrLayerSurfaceV1 {
|
||||||
|
type Target = ZwlrLayerSurfaceV1;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.layer_surface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ManagedZwlrLayerSurfaceV1 {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
debug!("Destroying ZwlrLayerSurfaceV1");
|
||||||
|
self.layer_surface.destroy();
|
||||||
|
if let Err(e) = self.connection.flush() {
|
||||||
|
error!("Failed to flush after destroying ZwlrLayerSurfaceV1: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ManagedWpFractionalScaleV1 {
|
||||||
|
fractional_scale: Rc<WpFractionalScaleV1>,
|
||||||
|
connection: Rc<Connection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ManagedWpFractionalScaleV1 {
|
||||||
|
pub const fn new(
|
||||||
|
fractional_scale: Rc<WpFractionalScaleV1>,
|
||||||
|
connection: Rc<Connection>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
fractional_scale,
|
||||||
|
connection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub const fn inner(&self) -> &Rc<WpFractionalScaleV1> {
|
||||||
|
&self.fractional_scale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for ManagedWpFractionalScaleV1 {
|
||||||
|
type Target = WpFractionalScaleV1;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.fractional_scale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ManagedWpFractionalScaleV1 {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
debug!("Destroying WpFractionalScaleV1");
|
||||||
|
self.fractional_scale.destroy();
|
||||||
|
if let Err(e) = self.connection.flush() {
|
||||||
|
error!("Failed to flush after destroying WpFractionalScaleV1: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ManagedWpViewport {
|
||||||
|
viewport: Rc<WpViewport>,
|
||||||
|
connection: Rc<Connection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ManagedWpViewport {
|
||||||
|
pub const fn new(viewport: Rc<WpViewport>, connection: Rc<Connection>) -> Self {
|
||||||
|
Self {
|
||||||
|
viewport,
|
||||||
|
connection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub const fn inner(&self) -> &Rc<WpViewport> {
|
||||||
|
&self.viewport
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for ManagedWpViewport {
|
||||||
|
type Target = WpViewport;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.viewport
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ManagedWpViewport {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
debug!("Destroying WpViewport");
|
||||||
|
self.viewport.destroy();
|
||||||
|
if let Err(e) = self.connection.flush() {
|
||||||
|
error!("Failed to flush after destroying WpViewport: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ use std::rc::Rc;
|
||||||
use slint::{platform::set_platform, PhysicalSize};
|
use slint::{platform::set_platform, PhysicalSize};
|
||||||
use slint_interpreter::ComponentDefinition;
|
use slint_interpreter::ComponentDefinition;
|
||||||
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_output::WlOutput, wl_pointer::WlPointer, wl_surface::WlSurface};
|
use wayland_client::{protocol::{wl_output::WlOutput, 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;
|
||||||
use wayland_protocols::wp::viewporter::client::wp_viewport::WpViewport;
|
use wayland_protocols::wp::viewporter::client::wp_viewport::WpViewport;
|
||||||
use crate::{errors::{LayerShikaError, Result}, rendering::{femtovg_window::FemtoVGWindow, slint_platform::CustomSlintPlatform}};
|
use crate::{errors::{LayerShikaError, Result}, rendering::{femtovg_window::FemtoVGWindow, slint_platform::CustomSlintPlatform}};
|
||||||
|
|
@ -20,6 +20,7 @@ pub struct WindowStateBuilder {
|
||||||
pub pointer: Option<Rc<WlPointer>>,
|
pub pointer: Option<Rc<WlPointer>>,
|
||||||
pub output: Option<Rc<WlOutput>>,
|
pub output: Option<Rc<WlOutput>>,
|
||||||
pub window: Option<Rc<FemtoVGWindow>>,
|
pub window: Option<Rc<FemtoVGWindow>>,
|
||||||
|
pub connection: Option<Rc<Connection>>,
|
||||||
pub scale_factor: f32,
|
pub scale_factor: f32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
pub exclusive_zone: i32,
|
pub exclusive_zone: i32,
|
||||||
|
|
@ -109,6 +110,12 @@ impl WindowStateBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_connection(mut self, connection: Rc<Connection>) -> Self {
|
||||||
|
self.connection = Some(connection);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(self) -> Result<WindowState> {
|
pub fn build(self) -> Result<WindowState> {
|
||||||
let platform = CustomSlintPlatform::new(
|
let platform = CustomSlintPlatform::new(
|
||||||
self.window
|
self.window
|
||||||
|
|
@ -136,6 +143,7 @@ impl Default for WindowStateBuilder {
|
||||||
pointer: None,
|
pointer: None,
|
||||||
output: None,
|
output: None,
|
||||||
window: None,
|
window: None,
|
||||||
|
connection: None,
|
||||||
scale_factor: 1.0,
|
scale_factor: 1.0,
|
||||||
height: 30,
|
height: 30,
|
||||||
exclusive_zone: -1,
|
exclusive_zone: -1,
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@ use log::info;
|
||||||
use slint::{LogicalPosition, PhysicalSize, ComponentHandle};
|
use slint::{LogicalPosition, PhysicalSize, ComponentHandle};
|
||||||
use slint_interpreter::ComponentInstance;
|
use slint_interpreter::ComponentInstance;
|
||||||
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_output::WlOutput, wl_pointer::WlPointer, wl_surface::WlSurface};
|
use wayland_client::protocol::{wl_output::WlOutput, wl_surface::WlSurface};
|
||||||
use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1;
|
|
||||||
use wayland_protocols::wp::viewporter::client::wp_viewport::WpViewport;
|
|
||||||
use crate::rendering::femtovg_window::FemtoVGWindow;
|
use crate::rendering::femtovg_window::FemtoVGWindow;
|
||||||
use crate::errors::{LayerShikaError, Result};
|
use crate::errors::{LayerShikaError, Result};
|
||||||
use crate::windowing::surface_dimensions::SurfaceDimensions;
|
use crate::windowing::surface_dimensions::SurfaceDimensions;
|
||||||
|
use crate::windowing::proxies::{
|
||||||
|
ManagedWlPointer, ManagedWlSurface, ManagedZwlrLayerSurfaceV1,
|
||||||
|
ManagedWpFractionalScaleV1, ManagedWpViewport,
|
||||||
|
};
|
||||||
|
|
||||||
pub mod builder;
|
pub mod builder;
|
||||||
pub mod dispatches;
|
pub mod dispatches;
|
||||||
|
|
@ -23,12 +25,12 @@ enum ScalingMode {
|
||||||
|
|
||||||
pub struct WindowState {
|
pub struct WindowState {
|
||||||
component_instance: ComponentInstance,
|
component_instance: ComponentInstance,
|
||||||
surface: Rc<WlSurface>,
|
viewport: Option<ManagedWpViewport>,
|
||||||
layer_surface: Rc<ZwlrLayerSurfaceV1>,
|
fractional_scale: Option<ManagedWpFractionalScaleV1>,
|
||||||
fractional_scale: Option<Rc<WpFractionalScaleV1>>,
|
layer_surface: ManagedZwlrLayerSurfaceV1,
|
||||||
viewport: Option<Rc<WpViewport>>,
|
surface: ManagedWlSurface,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pointer: Rc<WlPointer>,
|
pointer: ManagedWlPointer,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
output: Rc<WlOutput>,
|
output: Rc<WlOutput>,
|
||||||
size: PhysicalSize,
|
size: PhysicalSize,
|
||||||
|
|
@ -58,19 +60,38 @@ impl WindowState {
|
||||||
|
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
|
|
||||||
|
let connection = builder
|
||||||
|
.connection
|
||||||
|
.ok_or_else(|| LayerShikaError::InvalidInput("Connection is required".into()))?;
|
||||||
|
|
||||||
|
let surface_rc = builder
|
||||||
|
.surface
|
||||||
|
.ok_or_else(|| LayerShikaError::InvalidInput("Surface is required".into()))?;
|
||||||
|
let layer_surface_rc = builder
|
||||||
|
.layer_surface
|
||||||
|
.ok_or_else(|| LayerShikaError::InvalidInput("Layer surface is required".into()))?;
|
||||||
|
let pointer_rc = builder
|
||||||
|
.pointer
|
||||||
|
.ok_or_else(|| LayerShikaError::InvalidInput("Pointer is required".into()))?;
|
||||||
|
|
||||||
|
let viewport = builder
|
||||||
|
.viewport
|
||||||
|
.map(|vp| ManagedWpViewport::new(vp, Rc::clone(&connection)));
|
||||||
|
let fractional_scale = builder
|
||||||
|
.fractional_scale
|
||||||
|
.map(|fs| ManagedWpFractionalScaleV1::new(fs, Rc::clone(&connection)));
|
||||||
|
let layer_surface =
|
||||||
|
ManagedZwlrLayerSurfaceV1::new(layer_surface_rc, Rc::clone(&connection));
|
||||||
|
let surface = ManagedWlSurface::new(surface_rc, Rc::clone(&connection));
|
||||||
|
let pointer = ManagedWlPointer::new(pointer_rc, connection);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
component_instance,
|
component_instance,
|
||||||
surface: builder
|
viewport,
|
||||||
.surface
|
fractional_scale,
|
||||||
.ok_or_else(|| LayerShikaError::InvalidInput("Surface is required".into()))?,
|
layer_surface,
|
||||||
layer_surface: builder
|
surface,
|
||||||
.layer_surface
|
pointer,
|
||||||
.ok_or_else(|| LayerShikaError::InvalidInput("Layer surface is required".into()))?,
|
|
||||||
fractional_scale: builder.fractional_scale,
|
|
||||||
viewport: builder.viewport,
|
|
||||||
pointer: builder
|
|
||||||
.pointer
|
|
||||||
.ok_or_else(|| LayerShikaError::InvalidInput("Pointer is required".into()))?,
|
|
||||||
output: builder
|
output: builder
|
||||||
.output
|
.output
|
||||||
.ok_or_else(|| LayerShikaError::InvalidInput("Output is required".into()))?,
|
.ok_or_else(|| LayerShikaError::InvalidInput("Output is required".into()))?,
|
||||||
|
|
@ -202,11 +223,11 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layer_surface(&self) -> Rc<ZwlrLayerSurfaceV1> {
|
pub fn layer_surface(&self) -> Rc<ZwlrLayerSurfaceV1> {
|
||||||
Rc::clone(&self.layer_surface)
|
Rc::clone(self.layer_surface.inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn surface(&self) -> Rc<WlSurface> {
|
pub fn surface(&self) -> Rc<WlSurface> {
|
||||||
Rc::clone(&self.surface)
|
Rc::clone(self.surface.inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn height(&self) -> u32 {
|
pub const fn height(&self) -> u32 {
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ impl WindowingSystem {
|
||||||
.with_scale_factor(config.scale_factor)
|
.with_scale_factor(config.scale_factor)
|
||||||
.with_height(config.height)
|
.with_height(config.height)
|
||||||
.with_exclusive_zone(config.exclusive_zone)
|
.with_exclusive_zone(config.exclusive_zone)
|
||||||
|
.with_connection(Rc::new(connection.clone()))
|
||||||
.with_window(window);
|
.with_window(window);
|
||||||
|
|
||||||
if let Some(fs) = &surface_ctx.fractional_scale {
|
if let Some(fs) = &surface_ctx.fractional_scale {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue