Skip to content

Commit 8ab2721

Browse files
committed
gdk4-macos: manually implement native_window method
For now we need to depend on the cocoa crate in order to implement this method since it is the only decent crate implementing the cocoa api.
1 parent 3a99628 commit 8ab2721

File tree

6 files changed

+159
-44
lines changed

6 files changed

+159
-44
lines changed

Cargo.lock

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

gdk4-macos/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ version.workspace = true
1515

1616
[features]
1717
v4_8 = ["gdk4-macos-sys/v4_8"]
18+
macos_cocoa = ["cocoa"]
1819

1920
[dependencies]
2021
gdk4-macos-sys.workspace = true
2122
gdk.workspace = true
2223
gio.workspace = true
2324
glib.workspace = true
2425
libc.workspace = true
26+
cocoa = { version = "0.26", optional = true }
2527

2628
[dev-dependencies]
2729
gir-format-check.workspace = true

gdk4-macos/Gir.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ generate = [
1717
"GdkMacos.MacosGLContext",
1818
"GdkMacos.MacosKeymap",
1919
"GdkMacos.MacosSeat",
20-
"GdkMacos.MacosSurface",
2120
]
2221

2322
manual = [
@@ -36,4 +35,14 @@ name = "GdkMacos.MacosMonitor"
3635
status = "generate"
3736
[[object.function]]
3837
name = "get_geometry"
39-
ignore = true # The function does not exists
38+
ignore = true # The function does not exists
39+
40+
[[object]]
41+
name = "GdkMacos.MacosSurface"
42+
status = "generate"
43+
[[object.function]]
44+
name = "get_native_window"
45+
manual = true
46+
[[object.property]]
47+
name = "native"
48+
ignore = true # Same as native_window

gdk4-macos/src/auto/macos_surface.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
// DO NOT EDIT
44

55
use crate::ffi;
6-
use glib::{
7-
prelude::*,
8-
signal::{connect_raw, SignalHandlerId},
9-
translate::*,
10-
};
11-
use std::boxed::Box as Box_;
126

137
glib::wrapper! {
148
#[doc(alias = "GdkMacosSurface")]
@@ -19,39 +13,4 @@ glib::wrapper! {
1913
}
2014
}
2115

22-
impl MacosSurface {
23-
//#[cfg(feature = "v4_8")]
24-
//#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
25-
//#[doc(alias = "gdk_macos_surface_get_native_window")]
26-
//#[doc(alias = "get_native_window")]
27-
//pub fn native_window(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
28-
// unsafe { TODO: call ffi:gdk_macos_surface_get_native_window() }
29-
//}
30-
31-
//pub fn native(&self) -> /*Unimplemented*/Basic: Pointer {
32-
// ObjectExt::property(self, "native")
33-
//}
34-
35-
#[doc(alias = "native")]
36-
pub fn connect_native_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
37-
unsafe extern "C" fn notify_native_trampoline<F: Fn(&MacosSurface) + 'static>(
38-
this: *mut ffi::GdkMacosSurface,
39-
_param_spec: glib::ffi::gpointer,
40-
f: glib::ffi::gpointer,
41-
) {
42-
let f: &F = &*(f as *const F);
43-
f(&from_glib_borrow(this))
44-
}
45-
unsafe {
46-
let f: Box_<F> = Box_::new(f);
47-
connect_raw(
48-
self.as_ptr() as *mut _,
49-
b"notify::native\0".as_ptr() as *const _,
50-
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
51-
notify_native_trampoline::<F> as *const (),
52-
)),
53-
Box_::into_raw(f),
54-
)
55-
}
56-
}
57-
}
16+
impl MacosSurface {}

gdk4-macos/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ mod auto;
1616
pub mod prelude;
1717

1818
pub use auto::*;
19+
20+
#[cfg(feature = "macos_cocoa")]
21+
mod macos_surface;

gdk4-macos/src/macos_surface.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
#[cfg(feature = "v4_8")]
4+
use crate::ffi;
5+
use crate::MacosSurface;
6+
#[cfg(feature = "v4_8")]
7+
use cocoa::base::id;
8+
#[cfg(feature = "v4_8")]
9+
use glib::translate::*;
10+
11+
impl MacosSurface {
12+
#[cfg(feature = "v4_8")]
13+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
14+
#[doc(alias = "gdk_macos_surface_get_native_window")]
15+
#[doc(alias = "get_native_window")]
16+
pub fn native_window(&self) -> Option<id> {
17+
unsafe {
18+
let native_window_ptr = ffi::gdk_macos_surface_get_native_window(self.to_glib_none().0);
19+
if native_window_ptr.is_null() {
20+
None
21+
} else {
22+
Some(native_window_ptr as id)
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)