Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit e9db20a

Browse files
Update wayland-client version to 0.30
1 parent 6f27d77 commit e9db20a

File tree

5 files changed

+114
-26
lines changed

5 files changed

+114
-26
lines changed

gdkwayland/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ ffi = { path = "./sys", package = "gdkwayland-sys" }
2525
gdk = { path = "../gdk" }
2626
glib = { git = "https://github.com/gtk-rs/gtk-rs-core" }
2727
libc = "0.2"
28-
wayland-client = { version = "0.29", features = ["use_system_lib"] }
28+
wayland-client = "0.30"
29+
wayland-backend = { version = "0.1", features = ["client_system"] }
2930

3031
[dev-dependencies]
3132
gir-format-check = "^0.1"

gdkwayland/src/wayland_device.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3+
use gdk::prelude::*;
34
use gdk::DevicePadFeature;
45
use glib::translate::*;
56

7+
use wayland_client::backend::ObjectId;
68
use wayland_client::protocol::{wl_keyboard::WlKeyboard, wl_pointer::WlPointer, wl_seat::WlSeat};
7-
use wayland_client::sys::client::wl_proxy;
89
use wayland_client::Proxy;
910

1011
glib::wrapper! {
@@ -31,28 +32,53 @@ impl WaylandDevice {
3132

3233
#[doc(alias = "gdk_wayland_device_get_wl_seat")]
3334
#[doc(alias = "get_wl_seat")]
34-
pub fn wl_seat(&self) -> WlSeat {
35+
pub fn wl_seat(&self) -> Option<WlSeat> {
3536
unsafe {
36-
let ptr = ffi::gdk_wayland_device_get_wl_seat(self.to_glib_none().0);
37-
Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
37+
let seat_ptr = ffi::gdk_wayland_device_get_wl_seat(self.to_glib_none().0);
38+
if seat_ptr.is_null() {
39+
None
40+
} else {
41+
let display = self.display().unsafe_cast::<crate::WaylandDisplay>();
42+
let cnx = display.connection();
43+
let id = ObjectId::from_ptr(WlSeat::interface(), seat_ptr as *mut _).unwrap();
44+
45+
WlSeat::from_id(&cnx, id).ok()
46+
}
3847
}
3948
}
4049

4150
#[doc(alias = "gdk_wayland_device_get_wl_keyboard")]
4251
#[doc(alias = "get_wl_keyboard")]
43-
pub fn wl_keyboard(&self) -> WlKeyboard {
52+
pub fn wl_keyboard(&self) -> Option<WlKeyboard> {
53+
let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
4454
unsafe {
45-
let ptr = ffi::gdk_wayland_device_get_wl_keyboard(self.to_glib_none().0);
46-
Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
55+
let keyboard_ptr = ffi::gdk_wayland_device_get_wl_keyboard(self.to_glib_none().0);
56+
if keyboard_ptr.is_null() {
57+
None
58+
} else {
59+
let cnx = display.connection();
60+
let id =
61+
ObjectId::from_ptr(WlKeyboard::interface(), keyboard_ptr as *mut _).unwrap();
62+
63+
WlKeyboard::from_id(&cnx, id).ok()
64+
}
4765
}
4866
}
4967

5068
#[doc(alias = "gdk_wayland_device_get_wl_pointer")]
5169
#[doc(alias = "get_wl_pointer")]
52-
pub fn wl_pointer(&self) -> WlPointer {
70+
pub fn wl_pointer(&self) -> Option<WlPointer> {
71+
let display = self.display().downcast::<crate::WaylandDisplay>().unwrap();
5372
unsafe {
54-
let ptr = ffi::gdk_wayland_device_get_wl_pointer(self.to_glib_none().0);
55-
Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
73+
let pointer_ptr = ffi::gdk_wayland_device_get_wl_pointer(self.to_glib_none().0);
74+
if pointer_ptr.is_null() {
75+
None
76+
} else {
77+
let cnx = display.connection();
78+
let id = ObjectId::from_ptr(WlPointer::interface(), pointer_ptr as *mut _).unwrap();
79+
80+
WlPointer::from_id(&cnx, id).ok()
81+
}
5682
}
5783
}
5884
}

gdkwayland/src/wayland_display.rs

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3+
use glib::once_cell::sync::Lazy;
34
use glib::translate::*;
5+
use glib::{ObjectExt, Quark};
46

7+
use wayland_client::backend::ObjectId;
58
use wayland_client::protocol::{wl_compositor::WlCompositor, wl_display::WlDisplay};
6-
use wayland_client::sys::client::wl_proxy;
79
use wayland_client::Proxy;
810

11+
static WAYLAND_DISPLAY_CONNECTION_QUARK: Lazy<Quark> =
12+
Lazy::new(|| Quark::from_str("gtk-rs-wayland-display-connection-quark"));
13+
914
glib::wrapper! {
1015
#[doc(alias = "GdkWaylandDisplay")]
1116
pub struct WaylandDisplay(Object<ffi::GdkWaylandDisplay>) @extends gdk::Display;
@@ -18,19 +23,34 @@ glib::wrapper! {
1823
impl WaylandDisplay {
1924
#[doc(alias = "gdk_wayland_display_get_wl_compositor")]
2025
#[doc(alias = "get_wl_compositor")]
21-
pub fn wl_compositor(&self) -> WlCompositor {
26+
pub fn wl_compositor(&self) -> Option<WlCompositor> {
2227
unsafe {
23-
let ptr = ffi::gdk_wayland_display_get_wl_compositor(self.to_glib_none().0);
24-
Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
28+
let compositor_ptr = ffi::gdk_wayland_display_get_wl_compositor(self.to_glib_none().0);
29+
if compositor_ptr.is_null() {
30+
None
31+
} else {
32+
let cnx = self.connection();
33+
let id = ObjectId::from_ptr(WlCompositor::interface(), compositor_ptr as *mut _)
34+
.unwrap();
35+
36+
WlCompositor::from_id(&cnx, id).ok()
37+
}
2538
}
2639
}
2740

2841
#[doc(alias = "gdk_wayland_display_get_wl_display")]
2942
#[doc(alias = "get_wl_display")]
30-
pub fn wl_display(&self) -> WlDisplay {
43+
pub fn wl_display(&self) -> Option<WlDisplay> {
3144
unsafe {
32-
let ptr = ffi::gdk_wayland_display_get_wl_display(self.to_glib_none().0);
33-
Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
45+
let display_ptr = ffi::gdk_wayland_display_get_wl_display(self.to_glib_none().0);
46+
if display_ptr.is_null() {
47+
None
48+
} else {
49+
let cnx = self.connection();
50+
let id = ObjectId::from_ptr(WlDisplay::interface(), display_ptr as *mut _).unwrap();
51+
52+
WlDisplay::from_id(&cnx, id).ok()
53+
}
3454
}
3555
}
3656

@@ -69,4 +89,25 @@ impl WaylandDisplay {
6989
))
7090
}
7191
}
92+
93+
pub(crate) fn connection(&self) -> wayland_client::Connection {
94+
unsafe {
95+
match self
96+
.qdata::<Option<wayland_client::Connection>>(*WAYLAND_DISPLAY_CONNECTION_QUARK)
97+
{
98+
Some(conn) => conn.as_ref().clone().unwrap(),
99+
None => {
100+
let display_ptr =
101+
ffi::gdk_wayland_display_get_wl_display(self.to_glib_none().0);
102+
let backend = wayland_backend::sys::client::Backend::from_foreign_display(
103+
display_ptr as *mut _,
104+
);
105+
let conn = wayland_client::Connection::from_backend(backend);
106+
self.set_qdata(*WAYLAND_DISPLAY_CONNECTION_QUARK, conn.clone());
107+
108+
conn
109+
}
110+
}
111+
}
112+
}
72113
}

gdkwayland/src/wayland_monitor.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3+
use gdk::prelude::*;
34
use glib::translate::ToGlibPtr;
5+
6+
use wayland_client::backend::ObjectId;
47
use wayland_client::protocol::wl_output::WlOutput;
5-
use wayland_client::sys::client::wl_proxy;
68
use wayland_client::Proxy;
79

810
glib::wrapper! {
@@ -17,10 +19,18 @@ glib::wrapper! {
1719
impl WaylandMonitor {
1820
#[doc(alias = "gdk_wayland_monitor_get_wl_output")]
1921
#[doc(alias = "get_wl_output")]
20-
pub fn wl_output(&self) -> WlOutput {
22+
pub fn wl_output(&self) -> Option<WlOutput> {
2123
unsafe {
22-
let ptr = ffi::gdk_wayland_monitor_get_wl_output(self.to_glib_none().0);
23-
Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
24+
let output_ptr = ffi::gdk_wayland_monitor_get_wl_output(self.to_glib_none().0);
25+
if output_ptr.is_null() {
26+
None
27+
} else {
28+
let display = self.display()?.unsafe_cast::<crate::WaylandDisplay>();
29+
let cnx = display.connection();
30+
let id = ObjectId::from_ptr(WlOutput::interface(), output_ptr as *mut _).unwrap();
31+
32+
WlOutput::from_id(&cnx, id).ok()
33+
}
2434
}
2535
}
2636
}

gdkwayland/src/wayland_seat.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3+
use gdk::prelude::*;
34
use glib::translate::ToGlibPtr;
5+
6+
use wayland_client::backend::ObjectId;
47
use wayland_client::protocol::wl_seat::WlSeat;
5-
use wayland_client::sys::client::wl_proxy;
68
use wayland_client::Proxy;
79

810
glib::wrapper! {
@@ -17,10 +19,18 @@ glib::wrapper! {
1719
impl WaylandSeat {
1820
#[doc(alias = "gdk_wayland_seat_get_wl_seat")]
1921
#[doc(alias = "get_wl_seat")]
20-
pub fn wl_seat(&self) -> WlSeat {
22+
pub fn wl_seat(&self) -> Option<WlSeat> {
2123
unsafe {
22-
let ptr = ffi::gdk_wayland_seat_get_wl_seat(self.to_glib_none().0);
23-
Proxy::from_c_ptr(ptr as *mut wl_proxy).into()
24+
let seat_ptr = ffi::gdk_wayland_seat_get_wl_seat(self.to_glib_none().0);
25+
if seat_ptr.is_null() {
26+
None
27+
} else {
28+
let display = self.display()?.unsafe_cast::<crate::WaylandDisplay>();
29+
let cnx = display.connection();
30+
let id = ObjectId::from_ptr(WlSeat::interface(), seat_ptr as *mut _).unwrap();
31+
32+
WlSeat::from_id(&cnx, id).ok()
33+
}
2434
}
2535
}
2636
}

0 commit comments

Comments
 (0)