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
11 changed files
with
200 additions
and
3 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
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
use iced_core::window::Id; | ||
use iced_futures::MaybeSend; | ||
|
||
use std::{fmt, marker::PhantomData}; | ||
|
||
/// xdg-activation Actions | ||
#[derive(Clone)] | ||
pub enum Action<T> { | ||
/// request an activation token | ||
RequestToken { | ||
/// application id | ||
app_id: Option<String>, | ||
/// window, if provided | ||
window: Option<Id>, | ||
/// phantom | ||
_phantom: PhantomData<T>, | ||
}, | ||
/// 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, | ||
_: impl Fn(T) -> A + 'static + MaybeSend + Sync, | ||
) -> Action<A> | ||
where | ||
T: 'static, | ||
{ | ||
match self { | ||
Action::RequestToken { app_id, window, .. } => { | ||
Action::RequestToken { | ||
app_id, | ||
window, | ||
_phantom: PhantomData, | ||
} | ||
} | ||
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,31 @@ | ||
use iced_runtime::command::Command; | ||
use iced_runtime::command::{ | ||
self, | ||
platform_specific::{self, wayland}, | ||
}; | ||
use iced_runtime::window::Id as SurfaceId; | ||
|
||
use std::marker::PhantomData; | ||
|
||
pub fn request_token<Message>( | ||
app_id: Option<String>, | ||
window: Option<SurfaceId>, | ||
) -> Command<Message> { | ||
Command::single(command::Action::PlatformSpecific( | ||
platform_specific::Action::Wayland(wayland::Action::Activation( | ||
wayland::activation::Action::RequestToken { | ||
app_id, | ||
window, | ||
_phantom: PhantomData, | ||
}, | ||
)), | ||
)) | ||
} | ||
|
||
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,20 @@ | ||
use sctk::{ | ||
activation::{ActivationHandler, RequestData, RequestDataExt}, | ||
delegate_activation, | ||
}; | ||
|
||
use crate::event_loop::state::SctkState; | ||
|
||
impl<T> ActivationHandler for SctkState<T> { | ||
type RequestData = RequestData; | ||
|
||
fn new_token(&mut self, token: String, data: &Self::RequestData) { | ||
self.sctk_events | ||
.push(crate::sctk_event::SctkEvent::Activation { | ||
token, | ||
window: data.surface().cloned(), | ||
}) | ||
} | ||
} | ||
|
||
delegate_activation!(@<T> SctkState<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; | ||
|
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