forked from iced-rs/iced
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sctk: WIP session lock surface support
- Loading branch information
Showing
14 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// session lock events | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum SessionLockEvent { | ||
/// Compositor has activated lock | ||
Locked, | ||
/// Lock rejected / canceled by compositor | ||
Finished, | ||
/// Session lock protocol not supported | ||
NotSupported, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "sctk_session_lock" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "828b1eb" } | ||
iced = { path = "../..", default-features = false, features = ["wayland", "debug", "a11y"] } | ||
iced_runtime = { path = "../../runtime" } | ||
env_logger = "0.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use iced::{ | ||
Check failure on line 1 in examples/sctk_session_lock/src/main.rs GitHub Actions / all
|
||
event::wayland::{Event as WaylandEvent, OutputEvent, SessionLockEvent}, | ||
subscription, | ||
wayland::InitialSurface, | ||
widget::{column, container, text}, | ||
Check failure on line 5 in examples/sctk_session_lock/src/main.rs GitHub Actions / all
|
||
window, Application, Color, Command, Element, Length, Subscription, Theme, | ||
}; | ||
use iced_runtime::{ | ||
window::Id as SurfaceId, | ||
}; | ||
use iced::wayland::session_lock; | ||
|
||
fn main() { | ||
let mut settings = iced::Settings::default(); | ||
settings.initial_surface = InitialSurface::None; | ||
DndTest::run(settings).unwrap(); | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
struct DndTest { | ||
max_surface_id: u128, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Message { | ||
WaylandEvent(WaylandEvent), | ||
Ignore, | ||
} | ||
|
||
impl DndTest { | ||
fn next_surface_id(&mut self) -> SurfaceId { | ||
self.max_surface_id += 1; | ||
SurfaceId(self.max_surface_id) | ||
} | ||
} | ||
|
||
impl Application for DndTest { | ||
type Executor = iced::executor::Default; | ||
type Message = Message; | ||
type Flags = (); | ||
type Theme = Theme; | ||
|
||
fn new(_flags: ()) -> (DndTest, Command<Self::Message>) { | ||
( | ||
DndTest { | ||
..DndTest::default() | ||
}, | ||
session_lock::lock(), | ||
) | ||
} | ||
|
||
fn title(&self) -> String { | ||
String::from("DndTest") | ||
} | ||
|
||
fn update(&mut self, message: Self::Message) -> Command<Self::Message> { | ||
match message { | ||
Message::WaylandEvent(evt) => { | ||
match evt { | ||
// TODO handle creation/removal after lock | ||
Check failure on line 60 in examples/sctk_session_lock/src/main.rs GitHub Actions / all
|
||
WaylandEvent::Output(evt, output) => match evt { | ||
OutputEvent::Created(_) => { | ||
return session_lock::get_lock_surface(self.next_surface_id(), output); | ||
} | ||
OutputEvent::Removed => {} | ||
_ => {} | ||
} | ||
Check failure on line 67 in examples/sctk_session_lock/src/main.rs GitHub Actions / all
|
||
WaylandEvent::SessionLock(evt) => match evt { | ||
SessionLockEvent::Locked => { | ||
} | ||
_ => {} // TODO | ||
} | ||
_ => {} | ||
} | ||
} | ||
Message::Ignore => {} | ||
} | ||
Command::none() | ||
} | ||
|
||
fn view(&self, id: window::Id) -> Element<Self::Message> { | ||
text("Lock").into() | ||
} | ||
|
||
Check failure on line 84 in examples/sctk_session_lock/src/main.rs GitHub Actions / all
|
||
fn subscription(&self) -> Subscription<Self::Message> { | ||
iced::subscription::events_with(|evt, _| { | ||
if let iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(evt)) = evt | ||
{ | ||
Some(Message::WaylandEvent(evt)) | ||
} else { | ||
None | ||
} | ||
}) | ||
} | ||
|
||
fn close_requested(&self, _id: window::Id) -> Self::Message { | ||
Message::Ignore | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
runtime/src/command/platform_specific/wayland/session_lock.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::{fmt, marker::PhantomData}; | ||
|
||
use iced_core::window::Id; | ||
use iced_futures::MaybeSend; | ||
|
||
use sctk::reexports::client::protocol::wl_output::WlOutput; | ||
|
||
/// Session lock action | ||
#[derive(Clone)] | ||
pub enum Action<T> { | ||
/// Request a session lock | ||
Lock, | ||
/// Destroy lock | ||
Unlock, | ||
/// Create lock surface for output | ||
LockSurface { | ||
/// unique id for surface | ||
id: Id, | ||
/// output | ||
output: WlOutput, | ||
/// phantom | ||
_phantom: PhantomData<T>, | ||
}, | ||
} | ||
|
||
impl<T> Action<T> { | ||
/// Maps the output of a window [`Action`] using the provided closure. | ||
pub fn map<A>( | ||
self, | ||
_: impl Fn(T) -> A + 'static + MaybeSend + Sync, | ||
) -> Action<A> | ||
where | ||
T: 'static, | ||
{ | ||
match self { | ||
Action::Lock => Action::Lock, | ||
Action::Unlock => Action::Unlock, | ||
Action::LockSurface { | ||
id, | ||
output, | ||
_phantom, | ||
} => Action::LockSurface { | ||
id, | ||
output, | ||
_phantom: PhantomData, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl<T> fmt::Debug for Action<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Action::Lock => write!(f, "Action::SessionLock::Lock"), | ||
Action::Unlock => write!(f, "Action::SessionLock::Unlock"), | ||
Action::LockSurface { | ||
id, | ||
output, | ||
_phantom, | ||
} => write!( | ||
f, | ||
"Action::SessionLock::Unlock {{ id: {:?}, output: {:?} }}", | ||
id, output | ||
), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
pub mod data_device; | ||
pub mod layer_surface; | ||
pub mod popup; | ||
pub mod session_lock; | ||
pub mod window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use iced_runtime::command::Command; | ||
use iced_runtime::command::{ | ||
self, | ||
platform_specific::{ | ||
self, | ||
wayland::{self, popup::SctkPopupSettings}, | ||
}, | ||
}; | ||
use iced_runtime::window::Id as SurfaceId; | ||
use sctk::reexports::client::protocol::wl_output::WlOutput; | ||
|
||
use std::marker::PhantomData; | ||
|
||
pub fn lock<Message>() -> Command<Message> { | ||
Command::single(command::Action::PlatformSpecific( | ||
platform_specific::Action::Wayland(wayland::Action::SessionLock( | ||
wayland::session_lock::Action::Lock, | ||
)), | ||
)) | ||
} | ||
|
||
pub fn unlock<Message>() -> Command<Message> { | ||
Command::single(command::Action::PlatformSpecific( | ||
platform_specific::Action::Wayland(wayland::Action::SessionLock( | ||
wayland::session_lock::Action::Unlock, | ||
)), | ||
)) | ||
} | ||
|
||
pub fn get_lock_surface<Message>( | ||
id: SurfaceId, | ||
output: WlOutput, | ||
) -> Command<Message> { | ||
Command::single(command::Action::PlatformSpecific( | ||
platform_specific::Action::Wayland(wayland::Action::SessionLock( | ||
wayland::session_lock::Action::LockSurface { | ||
id, | ||
output, | ||
_phantom: PhantomData, | ||
}, | ||
)), | ||
)) | ||
} |
Oops, something went wrong.