Skip to main content

WindowIdentifier

Enum WindowIdentifier 

Source
#[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

Implementations§

Source§

impl WindowIdentifier

Source

pub async fn from_native(native: &impl IsA<Native>) -> Option<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>, ) -> Option<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.

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 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

Available on crate features raw_handle and gtk4 only.
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

Available on crate features raw_handle and gtk4 only.
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§

const SIGNATURE: &'static Signature

The signature for the implementing type, in parsed format. Read more
Source§

impl Send for WindowIdentifier

Source§

impl Sync for WindowIdentifier

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

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

👎Deprecated: Use HasDisplayHandle instead
Source§

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

Source§

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

👎Deprecated: Use HasWindowHandle instead
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
Source§

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

Source§

fn signature(&self) -> Signature

The type signature for self. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> ToString for T
where T: Display + ?Sized,

Source§

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>,

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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