Skip to content

Commit 71e5086

Browse files
gdk-wayland: Manually implement WaylandToplevel.get_xdg_toplevel
1 parent 2523636 commit 71e5086

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gdk4-wayland/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ v4_12 = ["gdk4-wayland-sys/v4_12", "v4_10", "gdk/v4_12"]
2020
v4_16 = ["gdk4-wayland-sys/v4_16", "v4_12", "gdk/v4_16"]
2121
v4_18 = ["gdk4-wayland-sys/v4_18", "v4_16", "gdk/v4_18"]
2222
v4_20 = ["gdk4-wayland-sys/v4_20", "v4_18", "gdk/v4_20"]
23-
wayland_crate = ["wayland-client", "wayland-backend"]
23+
wayland_crate = ["wayland-client", "wayland-backend", "wayland-protocols"]
2424
egl = ["khronos-egl"]
2525

2626
[dependencies]
@@ -31,6 +31,7 @@ glib.workspace = true
3131
libc.workspace = true
3232
wayland-client = {version = "0.31.10", optional = true}
3333
wayland-backend = {version = "0.3.0", optional = true, features = ["client_system"]}
34+
wayland-protocols = {version = "0.32", optional = true, features = ["client"]}
3435
khronos-egl = {version = "6.0", optional = true}
3536

3637
[dev-dependencies]

gdk4-wayland/Gir.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@ name = "GdkWayland.WaylandToplevel"
113113
status = "generate"
114114
[[object.function]]
115115
name = "export_handle"
116-
manual = true
116+
manual = true
117+
[[object.function]]
118+
name = "get_xdg_toplevel"
119+
rename = "xdg_toplevel"
120+
manual = true

gdk4-wayland/src/auto/wayland_toplevel.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ impl WaylandToplevel {
2828
}
2929
}
3030

31-
//#[cfg(feature = "v4_20")]
32-
//#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
33-
//#[doc(alias = "gdk_wayland_toplevel_get_xdg_toplevel")]
34-
//#[doc(alias = "get_xdg_toplevel")]
35-
//pub fn xdg_toplevel(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
36-
// unsafe { TODO: call ffi:gdk_wayland_toplevel_get_xdg_toplevel() }
37-
//}
38-
3931
#[doc(alias = "gdk_wayland_toplevel_set_application_id")]
4032
pub fn set_application_id(&self, application_id: &str) {
4133
unsafe {

gdk4-wayland/src/wayland_toplevel.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,35 @@ use crate::{ffi, WaylandToplevel};
44
use glib::translate::*;
55
use std::boxed::Box as Box_;
66

7+
#[cfg(all(feature = "v4_20", feature = "wayland_crate"))]
8+
#[cfg_attr(docsrs, doc(cfg(all(feature = "v4_20", feature = "wayland_crate"))))]
9+
use wayland_client::{backend::ObjectId, Proxy};
10+
#[cfg(all(feature = "v4_20", feature = "wayland_crate"))]
11+
#[cfg_attr(docsrs, doc(cfg(all(feature = "v4_20", feature = "wayland_crate"))))]
12+
use wayland_protocols::xdg::shell::client::xdg_toplevel::XdgToplevel;
13+
714
impl WaylandToplevel {
15+
#[cfg(all(feature = "v4_20", feature = "wayland_crate"))]
16+
#[cfg_attr(docsrs, doc(cfg(all(feature = "v4_20", feature = "wayland_crate"))))]
17+
#[doc(alias = "gdk_wayland_toplevel_get_xdg_toplevel")]
18+
#[doc(alias = "get_xdg_toplevel")]
19+
pub fn xdg_toplevel(&self) -> Option<XdgToplevel> {
20+
use gdk::prelude::*;
21+
let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
22+
unsafe {
23+
let toplevel_ptr = ffi::gdk_wayland_toplevel_get_xdg_toplevel(self.to_glib_none().0);
24+
if toplevel_ptr.is_null() {
25+
None
26+
} else {
27+
let cnx = display.connection();
28+
let id =
29+
ObjectId::from_ptr(XdgToplevel::interface(), toplevel_ptr as *mut _).unwrap();
30+
31+
XdgToplevel::from_id(&cnx, id).ok()
32+
}
33+
}
34+
}
35+
836
#[doc(alias = "gdk_wayland_toplevel_export_handle")]
937
pub fn export_handle<P: Fn(&WaylandToplevel, Result<&str, glib::BoolError>) + 'static>(
1038
&self,

0 commit comments

Comments
 (0)