Skip to content

Commit

Permalink
WIP ext session lock
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Oct 27, 2023
1 parent 8a9d836 commit ded8b4f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 63 deletions.
98 changes: 76 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ features = ["tokio", "wayland"]
[dependencies.tokio]
version = "1.33.0"
features = ["full"]

[patch."https://github.com/pop-os/libcosmic"]
iced = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_runtime = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_renderer = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_core = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_widget = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_futures = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_tiny_skia = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_style = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
iced_sctk = { git = "https://github.com/pop-os/iced//", branch = "sctk-session-lock" }
2 changes: 1 addition & 1 deletion src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ impl cosmic::Application for App {

column = column.push(
//TODO: use button
widget::pick_list(
iced::widget::pick_list(
&self.session_names,
Some(self.selected_session.clone()),
Message::Session,
Expand Down
57 changes: 17 additions & 40 deletions src/locker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use cosmic::{
executor,
iced::{
self, alignment,
event::wayland::{Event as WaylandEvent, LayerEvent, OutputEvent},
event::wayland::{Event as WaylandEvent, OutputEvent, SessionLockEvent},
futures::{self, SinkExt},
subscription,
wayland::{
actions::layer_surface::{IcedMargin, IcedOutput, SctkLayerSurfaceSettings},
layer_surface::{
destroy_layer_surface, get_layer_surface, Anchor, KeyboardInteractivity, Layer,
},
wayland::session_lock::{
get_lock_surface,
lock,
destroy_lock_surface,
unlock,
},
Length, Subscription,
},
Expand Down Expand Up @@ -197,7 +197,7 @@ pub struct Flags {
pub enum Message {
None,
OutputEvent(OutputEvent, WlOutput),
LayerEvent(LayerEvent, SurfaceId),
SessionLockEvent(SessionLockEvent),
Channel(mpsc::Sender<String>),
Prompt(String, bool, Option<String>),
Submit,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl cosmic::Application for App {
error_opt: None,
exited: false,
},
Command::none(),
lock(),
)
}

Expand Down Expand Up @@ -337,24 +337,7 @@ impl cosmic::Application for App {
}

return Command::batch([
get_layer_surface(SctkLayerSurfaceSettings {
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),
}),
get_lock_surface(surface_id, output),
widget::text_input::focus(text_input_id(surface_id)),
]);
}
Expand All @@ -363,7 +346,7 @@ impl cosmic::Application for App {
match self.surface_ids.remove(&output) {
Some(surface_id) => {
self.surface_images.remove(&surface_id);
return destroy_layer_surface(surface_id);
return destroy_lock_surface(surface_id);
}
None => {
log::warn!("output {}: no surface found", output.id());
Expand All @@ -375,18 +358,13 @@ impl cosmic::Application for App {
}
}
}
Message::LayerEvent(layer_event, surface_id) => match layer_event {
LayerEvent::Focused => {
Message::SessionLockEvent(session_lock_event) => match session_lock_event {
SessionLockEvent::Focused(_, surface_id) => {
log::info!("focus surface {}", surface_id.0);
self.active_surface_id_opt = Some(surface_id);
return widget::text_input::focus(text_input_id(surface_id));
}
LayerEvent::Unfocused => {
log::info!("unfocus surface {}", surface_id.0);
}
LayerEvent::Done => {
log::info!("done with surface {}", surface_id.0);
}
_ => {}
},
Message::Channel(value_tx) => {
self.value_tx_opt = Some(value_tx);
Expand Down Expand Up @@ -427,10 +405,11 @@ impl cosmic::Application for App {
let mut commands = Vec::new();
for (_output, surface_id) in self.surface_ids.drain() {
self.surface_images.remove(&surface_id);
commands.push(destroy_layer_surface(surface_id));
commands.push(destroy_lock_surface(surface_id));
}
commands.push(unlock());
//TODO: cleaner method to exit?
commands.push(Command::perform(async { process::exit(0) }, |x| x));
// commands.push(Command::perform(async { process::exit(0) }, |x| x));
return Command::batch(commands);
}
}
Expand Down Expand Up @@ -630,9 +609,7 @@ impl cosmic::Application for App {
WaylandEvent::Output(output_event, output) => {
Some(Message::OutputEvent(output_event, output))
}
WaylandEvent::Layer(layer_event, _surface, surface_id) => {
Some(Message::LayerEvent(layer_event, surface_id))
}
WaylandEvent::SessionLock(evt) => Some(Message::SessionLockEvent(evt)),
_ => None,
},
_ => None,
Expand Down

0 comments on commit ded8b4f

Please sign in to comment.