#[non_exhaustive]
pub enum WindowIdentifier { }
Expand description

Most portals interact with the user by showing dialogs. These dialogs should generally be placed on top of the application window that triggered them. To arrange this, the compositor needs to know about the application window. Many portal requests expect a WindowIdentifier for this reason.

Under X11, the WindowIdentifier should have the form x11:XID, where XID is the XID of the application window in hexadecimal. Under Wayland, it should have the form wayland:HANDLE, where HANDLE is a surface handle obtained with the xdg-foreign protocol.

See also Parent window identifiers.

§Usage

§From an X11 XID

let identifier = WindowIdentifier::from_xid(212321);

/// Open some portals

§From a Wayland Surface

The wayland feature must be enabled. The exported surface handle will be unexported on Drop.

// let wl_surface = some_surface;
// let identifier = WindowIdentifier::from_wayland(wl_surface).await;

/// Open some portals

Or using a raw wl_surface pointer

// let wl_surface_ptr = some_surface;
// let wl_display_ptr = corresponding_display;
// let identifier = WindowIdentifier::from_wayland_raw(wl_surface_ptr, wl_display_ptr).await;

/// Open some portals

§With GTK 4

The feature gtk4 must be enabled. You can get a WindowIdentifier from a IsA<gtk4::Native> using WindowIdentifier::from_native

let widget = gtk4::Button::new();

let ctx = glib::MainContext::default();
ctx.spawn_async(async move {
    let identifier = WindowIdentifier::from_native(&widget.native().unwrap()).await;

    /// Open some portals
});

The constructor should return a valid identifier under both X11 and Wayland and fallback to the Default implementation otherwise.

§Other Toolkits

If you have access to RawWindowHandle you can convert it to a WindowIdentifier with

let handle = RawWindowHandle::Xlib(XlibHandle::empty());
let identifier = WindowIdentifier::from_raw_handle(handle, None);

/// Open some portals

In case you don’t have access to a WindowIdentifier:

use ashpd::WindowIdentifier;

let identifier = WindowIdentifier::default();

Implementations§

source§

impl WindowIdentifier

source

pub async fn from_native(native: &impl IsA<Native>) -> Self

Available on crate features gtk4_wayland or gtk4_x11 only.

Creates a WindowIdentifier from a gtk4::Native.

The constructor returns a valid handle under both Wayland & x11.

Note the function has to be async as the Wayland handle retrieval API is async as well.

source

pub async fn from_raw_handle( window_handle: &RawWindowHandle, display_handle: Option<&RawDisplayHandle> ) -> Self

Available on crate feature raw_handle only.

Create an instance of WindowIdentifier from a RawWindowHandle.

The constructor returns a valid handle under both Wayland & X11.

This method is only async and requires a RawDisplayHandle only for Wayland handles.

source

pub fn from_xid(xid: c_ulong) -> Self

Create an instance of WindowIdentifier from an X11 window’s XID.

source

pub async unsafe fn from_wayland_raw( surface_ptr: *mut c_void, display_ptr: *mut c_void ) -> Self

Available on crate feature wayland only.

Create an instance of WindowIdentifier from a Wayland surface.

§Safety

Both pointers have to be valid surface and display pointers. You must ensure the display_ptr lives longer than the returned WindowIdentifier.

source

pub async fn from_wayland(surface: &WlSurface) -> Self

Available on crate feature wayland only.

Create an instance of WindowIdentifier from a Wayland surface.

Trait Implementations§

source§

impl Debug for WindowIdentifier

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for WindowIdentifier

source§

fn default() -> WindowIdentifier

Returns the “default value” for a type. Read more
source§

impl Display for WindowIdentifier

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl HasDisplayHandle for WindowIdentifier

source§

fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>

Convert a WindowIdentifier to RawDisplayHandle.

§Panics

If you attempt to convert a WindowIdentifier created from a RawDisplayHandle instead of the gtk4 constructors.

source§

impl HasWindowHandle for WindowIdentifier

source§

fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>

Convert a WindowIdentifier to RawWindowHandle.

§Panics

If you attempt to convert a WindowIdentifier created from a RawWindowHandle instead of the gtk4 constructors.

source§

impl Serialize for WindowIdentifier

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Type for WindowIdentifier

source§

fn signature() -> Signature<'static>

Get the signature for the implementing type. Read more
source§

impl Send for WindowIdentifier

source§

impl Sync for WindowIdentifier

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> DynamicType for T
where T: Type + ?Sized,

source§

fn dynamic_signature(&self) -> Signature<'_>

Get the signature for the implementing type. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> HasRawDisplayHandle for T
where T: HasDisplayHandle + ?Sized,

§

fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>

👎Deprecated: Use HasDisplayHandle instead
§

impl<T> HasRawWindowHandle for T
where T: HasWindowHandle + ?Sized,

§

fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>

👎Deprecated: Use HasWindowHandle instead
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

source§

fn null_value() -> T

The none-equivalent value.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more