app: client-side xdg-activation token requests
Adds an outbound path so an app can obtain an `xdg-activation-v1` token from the compositor and hand it to a child it is about to launch (the `$XDG_ACTIVATION_TOKEN` convention). Until now ltk only honoured inbound activation (self-activating the main surface from an inherited token); requesting a token for another app was out of scope. Two new `App` trait methods, both defaulting to no-op: `take_activation_requests` returns the tags the app wants tokens for this iteration, and `on_activation_token` delivers the issued token paired with its tag. The run loop drains the requests right after `poll_external` and calls `ActivationState::request_token`, carrying the tag in `RequestData::app_id`; `ActivationHandler::new_token` reads the tag back out and routes the token to the app through `on_activation_token`. When the compositor never advertised the activation global, each request is answered immediately with an empty token so the caller still proceeds and can fall back to its own matching instead of stalling.
This commit is contained in:
@@ -468,16 +468,25 @@ smithay_client_toolkit::delegate_data_device!( @<A: App> AppData<A> );
|
||||
|
||||
// --- `xdg-activation-v1` handler ---
|
||||
//
|
||||
// We only honour inbound activation here: when a token issued for our
|
||||
// own request gets delivered, we activate the main surface. Outbound
|
||||
// requests (so the app can pass a token to another app) are out of
|
||||
// scope for now — adding them only requires a new public method on
|
||||
// `AppData` and an extra trait method on `App`.
|
||||
// A token carrying a `RequestData::app_id` was requested by the app via
|
||||
// [`App::take_activation_requests`]: echo the tag + token back through
|
||||
// [`App::on_activation_token`] so the app can pass it to a child it is
|
||||
// launching. A token with no tag was issued for our own surface, so we
|
||||
// self-activate.
|
||||
impl<A: App> smithay_client_toolkit::activation::ActivationHandler for AppData<A>
|
||||
{
|
||||
type RequestData = smithay_client_toolkit::activation::RequestData;
|
||||
fn new_token( &mut self, token: String, _data: &Self::RequestData )
|
||||
fn new_token( &mut self, token: String, data: &Self::RequestData )
|
||||
{
|
||||
use smithay_client_toolkit::activation::RequestDataExt;
|
||||
if let Some( tag ) = data.app_id()
|
||||
{
|
||||
if let Some( msg ) = self.app.on_activation_token( tag.to_string(), token )
|
||||
{
|
||||
self.pending_msgs.push( msg );
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let ( Some( ref activation ), Some( wl ) ) = ( self.activation_state.as_ref(), self.main.surface.try_wl_surface() )
|
||||
{
|
||||
activation.activate::<Self>( &wl, token );
|
||||
|
||||
Reference in New Issue
Block a user