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),
|
||||
);
|
||||
|
||||
app_state.set_queue_handle(event_queue.handle());
|
||||
|
||||
let render_factory =
|
||||
RenderContextFactory::new(Rc::clone(&global_ctx.render_context_manager));
|
||||
|
||||
|
|
@ -363,6 +365,8 @@ impl WaylandShellSystem {
|
|||
Rc::clone(&shared_serial),
|
||||
);
|
||||
|
||||
app_state.set_queue_handle(event_queue.handle());
|
||||
|
||||
let render_factory =
|
||||
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<()> {
|
||||
let queue_handle = self.event_queue.handle();
|
||||
self.state
|
||||
.activate_session_lock(component_name, config, &queue_handle)
|
||||
self.state.activate_session_lock(component_name, config)
|
||||
}
|
||||
|
||||
fn deactivate_session_lock(&mut self) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ pub struct AppState {
|
|||
keyboard_state: KeyboardState,
|
||||
lock_manager: Option<SessionLockManager>,
|
||||
lock_callbacks: Vec<LockCallback>,
|
||||
queue_handle: Option<wayland_client::QueueHandle<AppState>>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
|
|
@ -92,6 +93,7 @@ impl AppState {
|
|||
keyboard_state: KeyboardState::new(),
|
||||
lock_manager: None,
|
||||
lock_callbacks: Vec::new(),
|
||||
queue_handle: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +106,10 @@ impl AppState {
|
|||
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> {
|
||||
self.lock_manager.as_ref()
|
||||
}
|
||||
|
|
@ -143,7 +149,6 @@ impl AppState {
|
|||
&mut self,
|
||||
component_name: &str,
|
||||
config: LockConfig,
|
||||
queue_handle: &wayland_client::QueueHandle<AppState>,
|
||||
) -> Result<()> {
|
||||
if self.lock_manager.is_some() {
|
||||
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 (definition, compilation_result) = self.resolve_lock_component(component_name)?;
|
||||
let platform =
|
||||
|
|
@ -178,13 +189,14 @@ impl AppState {
|
|||
}
|
||||
|
||||
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 {
|
||||
message: "No session lock active".to_string(),
|
||||
});
|
||||
};
|
||||
|
||||
manager.deactivate()
|
||||
manager.deactivate()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render_lock_frames(&self) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -39,46 +39,26 @@ impl SessionLock {
|
|||
}
|
||||
|
||||
pub fn activate(&self) -> Result<()> {
|
||||
let current = self.state.get();
|
||||
if !current.can_activate() {
|
||||
return Err(Error::InvalidState {
|
||||
current: format!("{current:?}"),
|
||||
operation: "activate".to_string(),
|
||||
});
|
||||
}
|
||||
log::info!("Session lock activation called - queuing SessionLockCommand::Activate");
|
||||
|
||||
let system = self.system.upgrade().ok_or(Error::SystemDropped)?;
|
||||
system
|
||||
.borrow_mut()
|
||||
.activate_session_lock(&self.component_name, self.config.clone())?;
|
||||
self.state.set(LockState::Locking);
|
||||
self.command_sender
|
||||
.send(ShellCommand::SessionLock(SessionLockCommand::Activate {
|
||||
component_name: self.component_name.clone(),
|
||||
config: self.config.clone(),
|
||||
}))
|
||||
.map_err(|e| {
|
||||
Error::Domain(DomainError::InvalidInput {
|
||||
message: format!("Failed to send session lock command: {e:?}"),
|
||||
})
|
||||
})?;
|
||||
|
||||
log::info!("SessionLockCommand::Activate queued successfully");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
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
|
||||
.send(ShellCommand::SessionLock(SessionLockCommand::Deactivate))
|
||||
.map_err(|e| {
|
||||
|
|
|
|||
|
|
@ -619,6 +619,17 @@ impl Shell {
|
|||
_system: &Weak<RefCell<dyn WaylandSystemOps>>,
|
||||
) {
|
||||
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 => {
|
||||
log::info!("Processing SessionLockCommand::Deactivate");
|
||||
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::handle::PopupHandle;
|
||||
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_info::OutputInfo;
|
||||
use layer_shika_domain::value_objects::popup_config::PopupConfig;
|
||||
|
|
@ -87,6 +88,10 @@ pub enum SurfaceCommand {
|
|||
}
|
||||
|
||||
pub enum SessionLockCommand {
|
||||
Activate {
|
||||
component_name: String,
|
||||
config: LockConfig,
|
||||
},
|
||||
Deactivate,
|
||||
}
|
||||
|
||||
|
|
@ -753,6 +758,17 @@ impl EventDispatchContext<'_> {
|
|||
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
|
||||
pub(crate) fn deactivate_session_lock(&mut self) -> Result<()> {
|
||||
self.app_state
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue