mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-10-28 23:04:22 +00:00
refactor: keep pointer and output alive
This commit is contained in:
parent
98c506dfd2
commit
18d1827415
3 changed files with 24 additions and 3 deletions
|
|
@ -73,9 +73,10 @@ impl WindowingSystem {
|
||||||
let global_ctx = Self::initialize_globals(&connection, &event_queue.handle())
|
let global_ctx = Self::initialize_globals(&connection, &event_queue.handle())
|
||||||
.map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?;
|
.map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?;
|
||||||
|
|
||||||
|
let output_ref = &global_ctx.output;
|
||||||
let surface_ctx = Self::setup_surface(
|
let surface_ctx = Self::setup_surface(
|
||||||
&global_ctx.compositor,
|
&global_ctx.compositor,
|
||||||
&global_ctx.output,
|
output_ref,
|
||||||
&global_ctx.layer_shell,
|
&global_ctx.layer_shell,
|
||||||
global_ctx.fractional_scale_manager.as_ref(),
|
global_ctx.fractional_scale_manager.as_ref(),
|
||||||
global_ctx.viewporter.as_ref(),
|
global_ctx.viewporter.as_ref(),
|
||||||
|
|
@ -84,6 +85,7 @@ impl WindowingSystem {
|
||||||
);
|
);
|
||||||
|
|
||||||
let pointer = Rc::new(global_ctx.seat.get_pointer(&event_queue.handle(), ()));
|
let pointer = Rc::new(global_ctx.seat.get_pointer(&event_queue.handle(), ()));
|
||||||
|
let output = Rc::new(global_ctx.output);
|
||||||
let window =
|
let window =
|
||||||
Self::initialize_renderer(&surface_ctx.surface, &connection.display(), &config)
|
Self::initialize_renderer(&surface_ctx.surface, &connection.display(), &config)
|
||||||
.map_err(|e| LayerShikaError::EGLContextCreation(e.to_string()))?;
|
.map_err(|e| LayerShikaError::EGLContextCreation(e.to_string()))?;
|
||||||
|
|
@ -93,6 +95,7 @@ impl WindowingSystem {
|
||||||
.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_pointer(Rc::clone(&pointer))
|
.with_pointer(Rc::clone(&pointer))
|
||||||
|
.with_output(Rc::clone(&output))
|
||||||
.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)
|
||||||
|
|
|
||||||
|
|
@ -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_pointer::WlPointer, wl_surface::WlSurface};
|
use wayland_client::protocol::{wl_output::WlOutput, wl_pointer::WlPointer, wl_surface::WlSurface};
|
||||||
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}};
|
||||||
|
|
@ -18,6 +18,7 @@ pub struct WindowStateBuilder {
|
||||||
pub size: Option<PhysicalSize>,
|
pub size: Option<PhysicalSize>,
|
||||||
pub output_size: Option<PhysicalSize>,
|
pub output_size: Option<PhysicalSize>,
|
||||||
pub pointer: Option<Rc<WlPointer>>,
|
pub pointer: Option<Rc<WlPointer>>,
|
||||||
|
pub output: Option<Rc<WlOutput>>,
|
||||||
pub window: Option<Rc<FemtoVGWindow>>,
|
pub window: Option<Rc<FemtoVGWindow>>,
|
||||||
pub scale_factor: f32,
|
pub scale_factor: f32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
|
|
@ -60,6 +61,12 @@ impl WindowStateBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_output(mut self, output: Rc<WlOutput>) -> Self {
|
||||||
|
self.output = Some(output);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_window(mut self, window: Rc<FemtoVGWindow>) -> Self {
|
pub fn with_window(mut self, window: Rc<FemtoVGWindow>) -> Self {
|
||||||
self.window = Some(window);
|
self.window = Some(window);
|
||||||
|
|
@ -127,6 +134,7 @@ impl Default for WindowStateBuilder {
|
||||||
size: None,
|
size: None,
|
||||||
output_size: None,
|
output_size: None,
|
||||||
pointer: None,
|
pointer: None,
|
||||||
|
output: None,
|
||||||
window: None,
|
window: None,
|
||||||
scale_factor: 1.0,
|
scale_factor: 1.0,
|
||||||
height: 30,
|
height: 30,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ 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_surface::WlSurface;
|
use wayland_client::protocol::{wl_output::WlOutput, wl_pointer::WlPointer, wl_surface::WlSurface};
|
||||||
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::rendering::femtovg_window::FemtoVGWindow;
|
use crate::rendering::femtovg_window::FemtoVGWindow;
|
||||||
|
|
@ -19,6 +19,10 @@ pub struct WindowState {
|
||||||
layer_surface: Rc<ZwlrLayerSurfaceV1>,
|
layer_surface: Rc<ZwlrLayerSurfaceV1>,
|
||||||
fractional_scale: Option<Rc<WpFractionalScaleV1>>,
|
fractional_scale: Option<Rc<WpFractionalScaleV1>>,
|
||||||
viewport: Option<Rc<WpViewport>>,
|
viewport: Option<Rc<WpViewport>>,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pointer: Rc<WlPointer>,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
output: Rc<WlOutput>,
|
||||||
size: PhysicalSize,
|
size: PhysicalSize,
|
||||||
logical_size: PhysicalSize,
|
logical_size: PhysicalSize,
|
||||||
output_size: PhysicalSize,
|
output_size: PhysicalSize,
|
||||||
|
|
@ -56,6 +60,12 @@ impl WindowState {
|
||||||
.ok_or_else(|| LayerShikaError::InvalidInput("Layer surface is required".into()))?,
|
.ok_or_else(|| LayerShikaError::InvalidInput("Layer surface is required".into()))?,
|
||||||
fractional_scale: builder.fractional_scale,
|
fractional_scale: builder.fractional_scale,
|
||||||
viewport: builder.viewport,
|
viewport: builder.viewport,
|
||||||
|
pointer: builder
|
||||||
|
.pointer
|
||||||
|
.ok_or_else(|| LayerShikaError::InvalidInput("Pointer is required".into()))?,
|
||||||
|
output: builder
|
||||||
|
.output
|
||||||
|
.ok_or_else(|| LayerShikaError::InvalidInput("Output is required".into()))?,
|
||||||
size: builder.size.unwrap_or_default(),
|
size: builder.size.unwrap_or_default(),
|
||||||
logical_size: PhysicalSize::default(),
|
logical_size: PhysicalSize::default(),
|
||||||
output_size: builder.output_size.unwrap_or_default(),
|
output_size: builder.output_size.unwrap_or_default(),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue