#[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 portalsOr 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 portalsImplementations§
Source§impl WindowIdentifier
impl WindowIdentifier
Sourcepub async fn from_native(native: &impl IsA<Native>) -> Option<Self>
Available on crate features gtk4_wayland or gtk4_x11 only.
pub async fn from_native(native: &impl IsA<Native>) -> Option<Self>
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.
Sourcepub async fn from_raw_handle(
window_handle: &RawWindowHandle,
display_handle: Option<&RawDisplayHandle>,
) -> Option<Self>
Available on crate feature raw_handle only.
pub async fn from_raw_handle( window_handle: &RawWindowHandle, display_handle: Option<&RawDisplayHandle>, ) -> Option<Self>
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.
Sourcepub fn from_xid(xid: c_ulong) -> Self
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
impl Debug for WindowIdentifier
Source§impl Display for WindowIdentifier
impl Display for WindowIdentifier
Source§impl HasDisplayHandle for WindowIdentifier
Available on crate features raw_handle and gtk4 only.
impl HasDisplayHandle for WindowIdentifier
raw_handle and gtk4 only.Source§fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
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.
impl HasWindowHandle for WindowIdentifier
raw_handle and gtk4 only.Source§fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
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
impl Serialize for WindowIdentifier
Source§impl Type for WindowIdentifier
impl Type for WindowIdentifier
impl Send for WindowIdentifier
impl Sync for WindowIdentifier
Auto Trait Implementations§
impl Freeze for WindowIdentifier
impl RefUnwindSafe for WindowIdentifier
impl Unpin for WindowIdentifier
impl UnwindSafe for WindowIdentifier
Blanket Implementations§
Source§impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
Source§fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
HasDisplayHandle insteadSource§impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
Source§fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
HasWindowHandle instead