Skip to content

Commit

Permalink
Bump raw_window_handle / wayland crates
Browse files Browse the repository at this point in the history
This requires switching gtk4-rs to main git for now until a new release
is done
  • Loading branch information
bilelmoussaoui committed Jan 7, 2024
1 parent 9c2c955 commit f757271
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 58 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ async-net = { version = "2.0.0", optional = true }
enumflags2 = "0.7"
futures-channel = "0.3"
futures-util = "0.3"
gdk4wayland = { package = "gdk4-wayland", version = "0.7", optional = true }
gdk4x11 = { package = "gdk4-x11", version = "0.7", optional = true }
gtk4 = { version = "0.7", optional = true }
gdk4wayland = { git = "https://github.com/gtk-rs/gtk4-rs", package = "gdk4-wayland", version = "0.8", optional = true }
gdk4x11 = { git = "https://github.com/gtk-rs/gtk4-rs", package = "gdk4-x11", version = "0.8", optional = true }
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs", version = "0.8", optional = true }
libc = { version = "0.2", optional = true }
once_cell = "1.14"
pw = { package = "pipewire", version = "0.7", optional = true }
rand = { version = "0.8", default-features = false }
raw-window-handle = { version = "0.5", optional = true }
raw-window-handle = { version = "0.6", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_repr = "0.1"
tokio = { version = "1.21", features = [
Expand All @@ -44,11 +44,11 @@ tokio = { version = "1.21", features = [
], optional = true, default-features = false }
tracing = { version = "0.1", optional = true }
url = { version = "2.3", features = ["serde"] }
wayland-backend = { version = "0.1", optional = true, features = [
wayland-backend = { version = "0.3", optional = true, features = [
"client_system",
] }
wayland-client = { version = "0.30", optional = true }
wayland-protocols = { version = "0.30", optional = true, features = [
wayland-client = { version = "0.31", optional = true }
wayland-protocols = { version = "0.31", optional = true, features = [
"unstable",
"client",
] }
Expand Down
81 changes: 41 additions & 40 deletions src/window_identifier/gtk4.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt;
#[cfg(feature = "gtk4_wayland")]
use std::sync::Arc;
use std::{fmt, ptr::NonNull};

#[cfg(feature = "gtk4_wayland")]
use futures_util::lock::Mutex;
Expand All @@ -10,8 +10,8 @@ use glib::translate::ToGlibPtr;
use gtk4::{gdk, glib, prelude::*};
#[cfg(feature = "raw_handle")]
use raw_window_handle::{
RawDisplayHandle, RawWindowHandle, WaylandDisplayHandle, WaylandWindowHandle,
XlibDisplayHandle, XlibWindowHandle,
DisplayHandle, RawDisplayHandle, RawWindowHandle, WaylandDisplayHandle, WaylandWindowHandle,
WindowHandle, XlibDisplayHandle, XlibWindowHandle,
};

use super::WindowIdentifierType;
Expand Down Expand Up @@ -84,65 +84,66 @@ impl Gtk4WindowIdentifier {
}

#[cfg(feature = "raw_handle")]
pub fn as_raw_window_handle(&self) -> RawWindowHandle {
pub fn as_raw_window_handle(&self) -> WindowHandle<'_> {
unsafe {
match self.type_ {
let raw_handle = match self.type_ {
#[cfg(feature = "gtk4_wayland")]
WindowIdentifierType::Wayland(_) => {
let surface = self.native.surface();
let mut wayland_handle = WaylandWindowHandle::empty();
wayland_handle.surface = gdk4wayland::ffi::gdk_wayland_surface_get_wl_surface(
surface
.downcast_ref::<gdk4wayland::WaylandSurface>()
.unwrap()
.to_glib_none()
.0,
);

RawWindowHandle::Wayland(wayland_handle)
RawWindowHandle::Wayland(WaylandWindowHandle::new(
NonNull::new(gdk4wayland::ffi::gdk_wayland_surface_get_wl_surface(
surface
.downcast_ref::<gdk4wayland::WaylandSurface>()
.unwrap()
.to_glib_none()
.0,
))
.expect("Identifier must be attached to a wl_surface"),
))
}
#[cfg(feature = "gtk4_x11")]
WindowIdentifierType::X11(xid) => {
let mut x11_handle = XlibWindowHandle::empty();
x11_handle.window = xid;

RawWindowHandle::Xlib(x11_handle)
}
}
WindowIdentifierType::X11(xid) => RawWindowHandle::Xlib(XlibWindowHandle::new(xid)),
};
WindowHandle::borrow_raw(raw_handle)
}
}

#[cfg(feature = "raw_handle")]
pub fn as_raw_display_handle(&self) -> RawDisplayHandle {
pub fn as_raw_display_handle(&self) -> DisplayHandle<'_> {
let surface = self.native.surface();
let display = surface.display();
unsafe {
match self.type_ {
let raw_handle = match self.type_ {
#[cfg(feature = "gtk4_wayland")]
WindowIdentifierType::Wayland(_) => {
let mut wayland_handle = WaylandDisplayHandle::empty();
wayland_handle.display = gdk4wayland::ffi::gdk_wayland_display_get_wl_display(
display
.downcast_ref::<gdk4wayland::WaylandDisplay>()
.unwrap()
.to_glib_none()
.0,
);
RawDisplayHandle::Wayland(wayland_handle)
RawDisplayHandle::Wayland(WaylandDisplayHandle::new(
NonNull::new(gdk4wayland::ffi::gdk_wayland_display_get_wl_display(
display
.downcast_ref::<gdk4wayland::WaylandDisplay>()
.unwrap()
.to_glib_none()
.0,
))
.expect("Identifier must be attached to a wl_display"),
))
}
#[cfg(feature = "gtk4_x11")]
WindowIdentifierType::X11(_xid) => {
let mut x11_handle = XlibDisplayHandle::empty();
x11_handle.display = gdk4x11::ffi::gdk_x11_display_get_xdisplay(
WindowIdentifierType::X11(_xid) => RawDisplayHandle::Xlib(XlibDisplayHandle::new(
NonNull::new(gdk4x11::ffi::gdk_x11_display_get_xdisplay(
display
.downcast_ref::<gdk4x11::X11Display>()
.unwrap()
.to_glib_none()
.0,
);
RawDisplayHandle::Xlib(x11_handle)
}
}
)),
display
.downcast_ref::<gdk4x11::X11Display>()
.unwrap()
.screen()
.screen_number(),
)),
};
DisplayHandle::borrow_raw(raw_handle)
}
}
}
Expand Down
24 changes: 13 additions & 11 deletions src/window_identifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::{fmt, str::FromStr};

#[cfg(all(feature = "raw_handle", feature = "gtk4"))]
use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, WindowHandle,
};
use serde::{ser::Serializer, Deserialize, Serialize};
use zbus::zvariant::Type;
Expand Down Expand Up @@ -165,19 +166,20 @@ impl WindowIdentifier {
/// This method is only async and requires a `RawDisplayHandle` only for
/// Wayland handles.
pub async fn from_raw_handle(
window_handle: &raw_window_handle::RawWindowHandle,
display_handle: Option<&raw_window_handle::RawDisplayHandle>,
window_handle: &RawWindowHandle,
display_handle: Option<&RawDisplayHandle>,
) -> Self {
use raw_window_handle::{
RawDisplayHandle::Wayland as DisplayHandle,
RawWindowHandle::{Wayland, Xcb, Xlib},
};
match (window_handle, display_handle) {
(Wayland(wl_handle), Some(DisplayHandle(wl_display))) => unsafe {
Self::from_wayland_raw(wl_handle.surface, wl_display.display).await
Self::from_wayland_raw(wl_handle.surface.as_ptr(), wl_display.display.as_ptr())
.await
},
(Xlib(x_handle), _) => Self::from_xid(x_handle.window),
(Xcb(x_handle), _) => Self::from_xid(x_handle.window.into()),
(Xcb(x_handle), _) => Self::from_xid(x_handle.window.get().into()),
_ => Self::default(), // Fallback to default
}
}
Expand Down Expand Up @@ -218,7 +220,7 @@ impl WindowIdentifier {
}

#[cfg(all(feature = "raw_handle", feature = "gtk4"))]
unsafe impl HasRawDisplayHandle for WindowIdentifier {
impl HasDisplayHandle for WindowIdentifier {
/// Convert a [`WindowIdentifier`] to
/// [`RawDisplayHandle`](raw_window_handle::RawDisplayHandle`).
///
Expand All @@ -227,17 +229,17 @@ unsafe impl HasRawDisplayHandle for WindowIdentifier {
/// If you attempt to convert a [`WindowIdentifier`] created from a
/// [`RawDisplayHandle`](raw_window_handle::RawDisplayHandle`) instead of
/// the gtk4 constructors.
fn raw_display_handle(&self) -> RawDisplayHandle {
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
match self {
#[cfg(feature = "gtk4")]
Self::Gtk4(identifier) => identifier.as_raw_display_handle(),
Self::Gtk4(identifier) => Ok(identifier.as_raw_display_handle()),
_ => unreachable!(),
}
}
}

#[cfg(all(feature = "raw_handle", feature = "gtk4"))]
unsafe impl HasRawWindowHandle for WindowIdentifier {
impl HasWindowHandle for WindowIdentifier {
/// Convert a [`WindowIdentifier`] to
/// [`RawWindowHandle`](raw_window_handle::RawWindowHandle`).
///
Expand All @@ -246,10 +248,10 @@ unsafe impl HasRawWindowHandle for WindowIdentifier {
/// If you attempt to convert a [`WindowIdentifier`] created from a
/// [`RawWindowHandle`](raw_window_handle::RawWindowHandle`) instead of
/// the gtk4 constructors.
fn raw_window_handle(&self) -> RawWindowHandle {
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
match self {
#[cfg(feature = "gtk4")]
Self::Gtk4(identifier) => identifier.as_raw_window_handle(),
Self::Gtk4(identifier) => Ok(identifier.as_raw_window_handle()),
_ => unreachable!(),
}
}
Expand Down

0 comments on commit f757271

Please sign in to comment.