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: Implement xdg-activation support
- Loading branch information
Showing
9 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
runtime/src/command/platform_specific/wayland/activation.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 iced_core::window::Id; | ||
use iced_futures::MaybeSend; | ||
|
||
use std::fmt; | ||
|
||
/// xdg-activation Actions | ||
pub enum Action<T> { | ||
/// request an activation token | ||
RequestToken { | ||
/// application id | ||
app_id: Option<String>, | ||
/// window, if provided | ||
window: Option<Id>, | ||
/// message generation | ||
message: Box<dyn FnOnce(Option<String>) -> T + Send + Sync + 'static>, | ||
}, | ||
/// request a window to be activated | ||
Activate { | ||
/// window to activate | ||
window: Id, | ||
/// activation token | ||
token: String, | ||
}, | ||
} | ||
|
||
impl<T> Action<T> { | ||
/// Maps the output of a window [`Action`] using the provided closure. | ||
pub fn map<A>( | ||
self, | ||
mapper: impl Fn(T) -> A + 'static + MaybeSend + Sync, | ||
) -> Action<A> | ||
where | ||
T: 'static, | ||
{ | ||
match self { | ||
Action::RequestToken { | ||
app_id, | ||
window, | ||
message, | ||
} => Action::RequestToken { | ||
app_id, | ||
window, | ||
message: Box::new(move |token| mapper(message(token))), | ||
}, | ||
Action::Activate { window, token } => { | ||
Action::Activate { window, token } | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<T> fmt::Debug for Action<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Action::RequestToken { app_id, window, .. } => write!( | ||
f, | ||
"Action::ActivationAction::RequestToken {{ app_id: {:?}, window: {:?} }}", | ||
app_id, window, | ||
), | ||
Action::Activate { window, token } => write!( | ||
f, | ||
"Action::ActivationAction::Activate {{ window: {:?}, token: {:?} }}", | ||
window, token, | ||
) | ||
} | ||
} | ||
} |
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
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,30 @@ | ||
use iced_runtime::command::Command; | ||
use iced_runtime::command::{ | ||
self, | ||
platform_specific::{self, wayland}, | ||
}; | ||
use iced_runtime::window::Id as SurfaceId; | ||
|
||
pub fn request_token<Message>( | ||
app_id: Option<String>, | ||
window: Option<SurfaceId>, | ||
to_message: impl FnOnce(Option<String>) -> Message + Send + Sync + 'static, | ||
) -> Command<Message> { | ||
Command::single(command::Action::PlatformSpecific( | ||
platform_specific::Action::Wayland(wayland::Action::Activation( | ||
wayland::activation::Action::RequestToken { | ||
app_id, | ||
window, | ||
message: Box::new(to_message), | ||
}, | ||
)), | ||
)) | ||
} | ||
|
||
pub fn activate<Message>(window: SurfaceId, token: String) -> Command<Message> { | ||
Command::single(command::Action::PlatformSpecific( | ||
platform_specific::Action::Wayland(wayland::Action::Activation( | ||
wayland::activation::Action::Activate { window, token }, | ||
)), | ||
)) | ||
} |
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
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,60 @@ | ||
use std::sync::Mutex; | ||
|
||
use sctk::{ | ||
activation::{ActivationHandler, RequestData, RequestDataExt}, | ||
delegate_activation, | ||
reexports::client::protocol::{wl_seat::WlSeat, wl_surface::WlSurface}, | ||
}; | ||
|
||
use crate::event_loop::state::SctkState; | ||
|
||
pub struct IcedRequestData<T> { | ||
data: RequestData, | ||
message: Mutex< | ||
Option<Box<dyn FnOnce(Option<String>) -> T + Send + Sync + 'static>>, | ||
>, | ||
} | ||
|
||
impl<T> IcedRequestData<T> { | ||
pub fn new( | ||
data: RequestData, | ||
message: Box<dyn FnOnce(Option<String>) -> T + Send + Sync + 'static>, | ||
) -> IcedRequestData<T> { | ||
IcedRequestData { | ||
data, | ||
message: Mutex::new(Some(message)), | ||
} | ||
} | ||
} | ||
|
||
impl<T> RequestDataExt for IcedRequestData<T> { | ||
fn app_id(&self) -> Option<&str> { | ||
self.data.app_id() | ||
} | ||
|
||
fn seat_and_serial(&self) -> Option<(&WlSeat, u32)> { | ||
self.data.seat_and_serial() | ||
} | ||
|
||
fn surface(&self) -> Option<&WlSurface> { | ||
self.data.surface() | ||
} | ||
} | ||
|
||
impl<T> ActivationHandler for SctkState<T> { | ||
type RequestData = IcedRequestData<T>; | ||
|
||
fn new_token(&mut self, token: String, data: &Self::RequestData) { | ||
if let Some(message) = data.message.lock().unwrap().take() { | ||
self.pending_user_events.push( | ||
crate::application::Event::SctkEvent( | ||
crate::sctk_event::IcedSctkEvent::UserEvent(message(Some( | ||
token, | ||
))), | ||
), | ||
); | ||
} // else the compositor send two tokens??? | ||
} | ||
} | ||
|
||
delegate_activation!(@<T> SctkState<T>, IcedRequestData<T>); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// handlers | ||
pub mod activation; | ||
pub mod compositor; | ||
pub mod data_device; | ||
pub mod output; | ||
|