Use ext-session-lock protocol

This commit is contained in:
Ian Douglas Scott 2023-10-26 15:10:09 -07:00
parent a497ed8b1e
commit 3eac044e9c
4 changed files with 382 additions and 253 deletions

565
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -616,7 +616,7 @@ impl cosmic::Application for App {
column = column.push( column = column.push(
//TODO: use button //TODO: use button
widget::pick_list( iced::widget::pick_list(
&self.session_names, &self.session_names,
Some(self.selected_session.clone()), Some(self.selected_session.clone()),
Message::Session, Message::Session,

View file

@ -122,7 +122,7 @@ where
viewport: &Rectangle, viewport: &Rectangle,
) { ) {
match &self.image_opt { match &self.image_opt {
Some(image) => draw(renderer, layout, image, self.content_fit), Some(image) => draw(renderer, layout, image, self.content_fit, [0.0, 0.0, 0.0, 0.0]),
None => {} None => {}
} }

View file

@ -6,14 +6,14 @@ use cosmic::{
executor, executor,
iced::{ iced::{
self, alignment, self, alignment,
event::wayland::{Event as WaylandEvent, LayerEvent, OutputEvent}, event::wayland::{Event as WaylandEvent, OutputEvent, SessionLockEvent},
futures::{self, SinkExt}, futures::{self, SinkExt},
subscription, subscription,
wayland::{ wayland::session_lock::{
actions::layer_surface::{IcedMargin, IcedOutput, SctkLayerSurfaceSettings}, get_lock_surface,
layer_surface::{ lock,
destroy_layer_surface, get_layer_surface, Anchor, KeyboardInteractivity, Layer, destroy_lock_surface,
}, unlock,
}, },
Length, Subscription, Length, Subscription,
}, },
@ -26,7 +26,6 @@ use std::{
ffi::{CStr, CString}, ffi::{CStr, CString},
fs, fs,
path::Path, path::Path,
process,
}; };
use tokio::{sync::mpsc, task, time}; use tokio::{sync::mpsc, task, time};
use wayland_client::{protocol::wl_output::WlOutput, Proxy}; use wayland_client::{protocol::wl_output::WlOutput, Proxy};
@ -197,7 +196,7 @@ pub struct Flags {
pub enum Message { pub enum Message {
None, None,
OutputEvent(OutputEvent, WlOutput), OutputEvent(OutputEvent, WlOutput),
LayerEvent(LayerEvent, SurfaceId), SessionLockEvent(SessionLockEvent),
Channel(mpsc::Sender<String>), Channel(mpsc::Sender<String>),
Prompt(String, bool, Option<String>), Prompt(String, bool, Option<String>),
Submit, Submit,
@ -263,7 +262,7 @@ impl cosmic::Application for App {
error_opt: None, error_opt: None,
exited: false, exited: false,
}, },
Command::none(), lock(),
) )
} }
@ -337,24 +336,7 @@ impl cosmic::Application for App {
} }
return Command::batch([ return Command::batch([
get_layer_surface(SctkLayerSurfaceSettings { get_lock_surface(surface_id, output),
id: surface_id,
layer: Layer::Overlay,
keyboard_interactivity: KeyboardInteractivity::Exclusive,
pointer_interactivity: true,
anchor: Anchor::TOP | Anchor::BOTTOM | Anchor::LEFT | Anchor::RIGHT,
output: IcedOutput::Output(output),
namespace: "cosmic-locker".into(),
size: Some((None, None)),
margin: IcedMargin {
top: 0,
bottom: 0,
left: 0,
right: 0,
},
exclusive_zone: -1,
size_limits: iced::Limits::NONE.min_width(1.0).min_height(1.0),
}),
widget::text_input::focus(text_input_id(surface_id)), widget::text_input::focus(text_input_id(surface_id)),
]); ]);
} }
@ -363,7 +345,7 @@ impl cosmic::Application for App {
match self.surface_ids.remove(&output) { match self.surface_ids.remove(&output) {
Some(surface_id) => { Some(surface_id) => {
self.surface_images.remove(&surface_id); self.surface_images.remove(&surface_id);
return destroy_layer_surface(surface_id); return destroy_lock_surface(surface_id);
} }
None => { None => {
log::warn!("output {}: no surface found", output.id()); log::warn!("output {}: no surface found", output.id());
@ -375,18 +357,16 @@ impl cosmic::Application for App {
} }
} }
} }
Message::LayerEvent(layer_event, surface_id) => match layer_event { Message::SessionLockEvent(session_lock_event) => match session_lock_event {
LayerEvent::Focused => { SessionLockEvent::Focused(_, surface_id) => {
log::info!("focus surface {}", surface_id.0); log::info!("focus surface {}", surface_id.0);
self.active_surface_id_opt = Some(surface_id); self.active_surface_id_opt = Some(surface_id);
return widget::text_input::focus(text_input_id(surface_id)); return widget::text_input::focus(text_input_id(surface_id));
} }
LayerEvent::Unfocused => { SessionLockEvent::Unlocked => {
log::info!("unfocus surface {}", surface_id.0); self.exited = true;
}
LayerEvent::Done => {
log::info!("done with surface {}", surface_id.0);
} }
_ => {}
}, },
Message::Channel(value_tx) => { Message::Channel(value_tx) => {
self.value_tx_opt = Some(value_tx); self.value_tx_opt = Some(value_tx);
@ -422,21 +402,23 @@ impl cosmic::Application for App {
self.error_opt = Some(error); self.error_opt = Some(error);
} }
Message::Exit => { Message::Exit => {
self.exited = true;
let mut commands = Vec::new(); let mut commands = Vec::new();
for (_output, surface_id) in self.surface_ids.drain() { for (_output, surface_id) in self.surface_ids.drain() {
self.surface_images.remove(&surface_id); self.surface_images.remove(&surface_id);
commands.push(destroy_layer_surface(surface_id)); commands.push(destroy_lock_surface(surface_id));
} }
//TODO: cleaner method to exit? commands.push(unlock());
commands.push(Command::perform(async { process::exit(0) }, |x| x)); // Wait to exit until `Unlocked` event, when server has processed unlock
return Command::batch(commands); return Command::batch(commands);
} }
} }
Command::none() Command::none()
} }
fn should_exit(&self) -> bool {
self.exited
}
// Not used for layer surface window // Not used for layer surface window
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<Self::Message> {
unimplemented!() unimplemented!()
@ -630,9 +612,7 @@ impl cosmic::Application for App {
WaylandEvent::Output(output_event, output) => { WaylandEvent::Output(output_event, output) => {
Some(Message::OutputEvent(output_event, output)) Some(Message::OutputEvent(output_event, output))
} }
WaylandEvent::Layer(layer_event, _surface, surface_id) => { WaylandEvent::SessionLock(evt) => Some(Message::SessionLockEvent(evt)),
Some(Message::LayerEvent(layer_event, surface_id))
}
_ => None, _ => None,
}, },
_ => None, _ => None,