mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2026-01-01 19:55:55 +00:00
refactor: session lock activation
This commit is contained in:
parent
4b923c88bf
commit
4ea7f11864
5 changed files with 61 additions and 40 deletions
|
|
@ -290,6 +290,8 @@ impl WaylandShellSystem {
|
||||||
Rc::clone(&shared_serial),
|
Rc::clone(&shared_serial),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app_state.set_queue_handle(event_queue.handle());
|
||||||
|
|
||||||
let render_factory =
|
let render_factory =
|
||||||
RenderContextFactory::new(Rc::clone(&global_ctx.render_context_manager));
|
RenderContextFactory::new(Rc::clone(&global_ctx.render_context_manager));
|
||||||
|
|
||||||
|
|
@ -363,6 +365,8 @@ impl WaylandShellSystem {
|
||||||
Rc::clone(&shared_serial),
|
Rc::clone(&shared_serial),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app_state.set_queue_handle(event_queue.handle());
|
||||||
|
|
||||||
let render_factory =
|
let render_factory =
|
||||||
RenderContextFactory::new(Rc::clone(&global_ctx.render_context_manager));
|
RenderContextFactory::new(Rc::clone(&global_ctx.render_context_manager));
|
||||||
|
|
||||||
|
|
@ -804,9 +808,7 @@ impl WaylandSystemOps for WaylandShellSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate_session_lock(&mut self, component_name: &str, config: LockConfig) -> Result<()> {
|
fn activate_session_lock(&mut self, component_name: &str, config: LockConfig) -> Result<()> {
|
||||||
let queue_handle = self.event_queue.handle();
|
self.state.activate_session_lock(component_name, config)
|
||||||
self.state
|
|
||||||
.activate_session_lock(component_name, config, &queue_handle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deactivate_session_lock(&mut self) -> Result<()> {
|
fn deactivate_session_lock(&mut self) -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ pub struct AppState {
|
||||||
keyboard_state: KeyboardState,
|
keyboard_state: KeyboardState,
|
||||||
lock_manager: Option<SessionLockManager>,
|
lock_manager: Option<SessionLockManager>,
|
||||||
lock_callbacks: Vec<LockCallback>,
|
lock_callbacks: Vec<LockCallback>,
|
||||||
|
queue_handle: Option<wayland_client::QueueHandle<AppState>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
|
|
@ -92,6 +93,7 @@ impl AppState {
|
||||||
keyboard_state: KeyboardState::new(),
|
keyboard_state: KeyboardState::new(),
|
||||||
lock_manager: None,
|
lock_manager: None,
|
||||||
lock_callbacks: Vec::new(),
|
lock_callbacks: Vec::new(),
|
||||||
|
queue_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,6 +106,10 @@ impl AppState {
|
||||||
self.slint_platform = Some(platform);
|
self.slint_platform = Some(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_queue_handle(&mut self, queue_handle: wayland_client::QueueHandle<AppState>) {
|
||||||
|
self.queue_handle = Some(queue_handle);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn lock_manager(&self) -> Option<&SessionLockManager> {
|
pub fn lock_manager(&self) -> Option<&SessionLockManager> {
|
||||||
self.lock_manager.as_ref()
|
self.lock_manager.as_ref()
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +149,6 @@ impl AppState {
|
||||||
&mut self,
|
&mut self,
|
||||||
component_name: &str,
|
component_name: &str,
|
||||||
config: LockConfig,
|
config: LockConfig,
|
||||||
queue_handle: &wayland_client::QueueHandle<AppState>,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if self.lock_manager.is_some() {
|
if self.lock_manager.is_some() {
|
||||||
return Err(LayerShikaError::InvalidInput {
|
return Err(LayerShikaError::InvalidInput {
|
||||||
|
|
@ -151,6 +156,12 @@ impl AppState {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let queue_handle = self.queue_handle.as_ref().ok_or_else(|| {
|
||||||
|
LayerShikaError::InvalidInput {
|
||||||
|
message: "Queue handle not initialized".to_string(),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
let context = self.create_lock_context()?;
|
let context = self.create_lock_context()?;
|
||||||
let (definition, compilation_result) = self.resolve_lock_component(component_name)?;
|
let (definition, compilation_result) = self.resolve_lock_component(component_name)?;
|
||||||
let platform =
|
let platform =
|
||||||
|
|
@ -178,13 +189,14 @@ impl AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deactivate_session_lock(&mut self) -> Result<()> {
|
pub fn deactivate_session_lock(&mut self) -> Result<()> {
|
||||||
let Some(manager) = self.lock_manager.as_mut() else {
|
let Some(mut manager) = self.lock_manager.take() else {
|
||||||
return Err(LayerShikaError::InvalidInput {
|
return Err(LayerShikaError::InvalidInput {
|
||||||
message: "No session lock active".to_string(),
|
message: "No session lock active".to_string(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
manager.deactivate()
|
manager.deactivate()?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_lock_frames(&self) -> Result<()> {
|
pub fn render_lock_frames(&self) -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -39,46 +39,26 @@ impl SessionLock {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn activate(&self) -> Result<()> {
|
pub fn activate(&self) -> Result<()> {
|
||||||
let current = self.state.get();
|
log::info!("Session lock activation called - queuing SessionLockCommand::Activate");
|
||||||
if !current.can_activate() {
|
|
||||||
return Err(Error::InvalidState {
|
|
||||||
current: format!("{current:?}"),
|
|
||||||
operation: "activate".to_string(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let system = self.system.upgrade().ok_or(Error::SystemDropped)?;
|
self.command_sender
|
||||||
system
|
.send(ShellCommand::SessionLock(SessionLockCommand::Activate {
|
||||||
.borrow_mut()
|
component_name: self.component_name.clone(),
|
||||||
.activate_session_lock(&self.component_name, self.config.clone())?;
|
config: self.config.clone(),
|
||||||
self.state.set(LockState::Locking);
|
}))
|
||||||
|
.map_err(|e| {
|
||||||
|
Error::Domain(DomainError::InvalidInput {
|
||||||
|
message: format!("Failed to send session lock command: {e:?}"),
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
log::info!("SessionLockCommand::Activate queued successfully");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deactivate(&self) -> Result<()> {
|
pub fn deactivate(&self) -> Result<()> {
|
||||||
log::info!("deactivate() called - queuing SessionLockCommand::Deactivate");
|
log::info!("Session lock deactivation called - queuing SessionLockCommand::Deactivate");
|
||||||
|
|
||||||
if let Some(system) = self.system.upgrade() {
|
|
||||||
if let Ok(borrowed) = system.try_borrow() {
|
|
||||||
if let Some(state) = borrowed.session_lock_state() {
|
|
||||||
log::info!("Syncing lock state before deactivate: {:?}", state);
|
|
||||||
self.state.set(state);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log::warn!("Could not borrow system to sync state - already borrowed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let current = self.state.get();
|
|
||||||
log::info!("Current lock state for deactivate check: {:?}", current);
|
|
||||||
if !current.can_deactivate() {
|
|
||||||
return Err(Error::InvalidState {
|
|
||||||
current: format!("{current:?}"),
|
|
||||||
operation: "deactivate".to_string(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send deactivate command via channel to be processed outside borrow context
|
|
||||||
self.command_sender
|
self.command_sender
|
||||||
.send(ShellCommand::SessionLock(SessionLockCommand::Deactivate))
|
.send(ShellCommand::SessionLock(SessionLockCommand::Deactivate))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
|
|
|
||||||
|
|
@ -619,6 +619,17 @@ impl Shell {
|
||||||
_system: &Weak<RefCell<dyn WaylandSystemOps>>,
|
_system: &Weak<RefCell<dyn WaylandSystemOps>>,
|
||||||
) {
|
) {
|
||||||
match command {
|
match command {
|
||||||
|
SessionLockCommand::Activate {
|
||||||
|
component_name,
|
||||||
|
config,
|
||||||
|
} => {
|
||||||
|
log::info!("Processing SessionLockCommand::Activate");
|
||||||
|
if let Err(e) = ctx.activate_session_lock(component_name, config.clone()) {
|
||||||
|
log::error!("Failed to activate session lock: {}", e);
|
||||||
|
} else {
|
||||||
|
log::info!("Session lock activated successfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
SessionLockCommand::Deactivate => {
|
SessionLockCommand::Deactivate => {
|
||||||
log::info!("Processing SessionLockCommand::Deactivate");
|
log::info!("Processing SessionLockCommand::Deactivate");
|
||||||
if let Err(e) = ctx.deactivate_session_lock() {
|
if let Err(e) = ctx.deactivate_session_lock() {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use layer_shika_domain::prelude::{
|
||||||
use layer_shika_domain::value_objects::dimensions::{PopupDimensions, SurfaceDimension};
|
use layer_shika_domain::value_objects::dimensions::{PopupDimensions, SurfaceDimension};
|
||||||
use layer_shika_domain::value_objects::handle::PopupHandle;
|
use layer_shika_domain::value_objects::handle::PopupHandle;
|
||||||
use layer_shika_domain::value_objects::handle::SurfaceHandle;
|
use layer_shika_domain::value_objects::handle::SurfaceHandle;
|
||||||
|
use layer_shika_domain::value_objects::lock_config::LockConfig;
|
||||||
use layer_shika_domain::value_objects::output_handle::OutputHandle;
|
use layer_shika_domain::value_objects::output_handle::OutputHandle;
|
||||||
use layer_shika_domain::value_objects::output_info::OutputInfo;
|
use layer_shika_domain::value_objects::output_info::OutputInfo;
|
||||||
use layer_shika_domain::value_objects::popup_config::PopupConfig;
|
use layer_shika_domain::value_objects::popup_config::PopupConfig;
|
||||||
|
|
@ -87,6 +88,10 @@ pub enum SurfaceCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SessionLockCommand {
|
pub enum SessionLockCommand {
|
||||||
|
Activate {
|
||||||
|
component_name: String,
|
||||||
|
config: LockConfig,
|
||||||
|
},
|
||||||
Deactivate,
|
Deactivate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -753,6 +758,17 @@ impl EventDispatchContext<'_> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Activates the session lock
|
||||||
|
pub(crate) fn activate_session_lock(
|
||||||
|
&mut self,
|
||||||
|
component_name: &str,
|
||||||
|
config: LockConfig,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.app_state
|
||||||
|
.activate_session_lock(component_name, config)
|
||||||
|
.map_err(Error::Adapter)
|
||||||
|
}
|
||||||
|
|
||||||
/// Deactivates the session lock
|
/// Deactivates the session lock
|
||||||
pub(crate) fn deactivate_session_lock(&mut self) -> Result<()> {
|
pub(crate) fn deactivate_session_lock(&mut self) -> Result<()> {
|
||||||
self.app_state
|
self.app_state
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue