Skip to content

Commit

Permalink
gdk4-macos: manually implement native_window method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nacho committed Dec 9, 2024
1 parent 3a99628 commit be2391a
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 10 deletions.
116 changes: 116 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gdk4-macos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gdk.workspace = true
gio.workspace = true
glib.workspace = true
libc.workspace = true
cocoa = "0.26"

[dev-dependencies]
gir-format-check.workspace = true
Expand Down
10 changes: 8 additions & 2 deletions gdk4-macos/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ generate = [
"GdkMacos.MacosGLContext",
"GdkMacos.MacosKeymap",
"GdkMacos.MacosSeat",
"GdkMacos.MacosSurface",
]

manual = [
Expand All @@ -36,4 +35,11 @@ name = "GdkMacos.MacosMonitor"
status = "generate"
[[object.function]]
name = "get_geometry"
ignore = true # The function does not exists
ignore = true # The function does not exists

[[object]]
name = "GdkMacos.MacosSurface"
status = "generate"
[[object.function]]
name = "get_native_window"
manual = true
8 changes: 0 additions & 8 deletions gdk4-macos/src/auto/macos_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ glib::wrapper! {
}

impl MacosSurface {
//#[cfg(feature = "v4_8")]
//#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
//#[doc(alias = "gdk_macos_surface_get_native_window")]
//#[doc(alias = "get_native_window")]
//pub fn native_window(&self) -> /*Unimplemented*/Option<Basic: Pointer> {
// unsafe { TODO: call ffi:gdk_macos_surface_get_native_window() }
//}

//pub fn native(&self) -> /*Unimplemented*/Basic: Pointer {
// ObjectExt::property(self, "native")
//}
Expand Down
2 changes: 2 additions & 0 deletions gdk4-macos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ mod auto;
pub mod prelude;

pub use auto::*;

mod macos_surface;
26 changes: 26 additions & 0 deletions gdk4-macos/src/macos_surface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(feature = "v4_8")]
use crate::ffi;
use crate::MacosSurface;
#[cfg(feature = "v4_8")]
use cocoa::base::id;
#[cfg(feature = "v4_8")]
use glib::translate::*;

impl MacosSurface {
#[cfg(feature = "v4_8")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
#[doc(alias = "gdk_macos_surface_get_native_window")]
#[doc(alias = "get_native_window")]
pub fn native_window(&self) -> Option<id> {
unsafe {
let native_window_ptr = ffi::gdk_macos_surface_get_native_window(self.to_glib_none().0);
if native_window_ptr.is_null() {
None
} else {
Some(native_window_ptr as id)
}
}
}
}

0 comments on commit be2391a

Please sign in to comment.