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 18, 2024
1 parent 0dd2564 commit 316e3ce
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --features v4_8 --manifest-path ./gdk4-macos/Cargo.toml
args: --features cocoa,v4_8 --manifest-path ./gdk4-macos/Cargo.toml
- name: Clippy gdk4-macos
uses: actions-rs/cargo@v1
with:
command: clippy
args: --features v4_8 --manifest-path ./gdk4-macos/Cargo.toml
args: --features cocoa,v4_8 --manifest-path ./gdk4-macos/Cargo.toml
- name: Tests gdk4-macos
uses: actions-rs/cargo@v1
with:
command: test
args: --features v4_8 --manifest-path ./gdk4-macos/Cargo.toml
args: --features cocoa,v4_8 --manifest-path ./gdk4-macos/Cargo.toml
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.

2 changes: 2 additions & 0 deletions gdk4-macos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ version.workspace = true

[features]
v4_8 = ["gdk4-macos-sys/v4_8"]
cocoa = ["dep:cocoa"]

[dependencies]
gdk4-macos-sys.workspace = true
gdk.workspace = true
gio.workspace = true
glib.workspace = true
libc.workspace = true
cocoa = { version = "0.26", default-features = false, optional = true }

[dev-dependencies]
gir-format-check.workspace = true
Expand Down
14 changes: 12 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,15 @@ 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
rename = "native"
[[object.property]]
name = "native"
generate = ["notify"]
1 change: 1 addition & 0 deletions gdk4-macos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gdk-wayland = { git = "https://github.com/gtk-rs/gtk4-rs.git", package = "gdk4-w
| Feature | Description |
| --- | ----------- |
| `v4_8` | Enable the new APIs part of GTK 4.8 |
| `cocoa` | Integration with the [cocoa](https://crates.io/crates/cocoa) crate |

### See Also

Expand Down
12 changes: 0 additions & 12 deletions gdk4-macos/src/auto/macos_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +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")
//}

#[doc(alias = "native")]
pub fn connect_native_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_native_trampoline<F: Fn(&MacosSurface) + 'static>(
Expand Down
12 changes: 12 additions & 0 deletions gdk4-macos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#![allow(deprecated)]
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(not(feature = "cocoa"))]
use std::ffi::c_void;

pub use gdk;
pub use gdk4_macos_sys as ffi;
pub use gio;
Expand All @@ -16,3 +19,12 @@ mod auto;
pub mod prelude;

pub use auto::*;

mod macos_surface;

#[cfg(not(feature = "cocoa"))]
#[allow(non_camel_case_types)]
pub type id = *mut c_void;

#[cfg(feature = "cocoa")]
pub use cocoa::base::id;
29 changes: 29 additions & 0 deletions gdk4-macos/src/macos_surface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(feature = "v4_8")]
use crate::ffi;
#[cfg(not(feature = "v4_8"))]
use crate::prelude::*;
use crate::{id, MacosSurface};
#[cfg(feature = "v4_8")]
use glib::translate::*;
#[cfg(not(feature = "v4_8"))]
use std::ffi::c_void;

impl MacosSurface {
#[doc(alias = "gdk_macos_surface_get_native_window")]
#[doc(alias = "get_native_window")]
pub fn native(&self) -> id {
#[cfg(feature = "v4_8")]
unsafe {
let native_window_ptr = ffi::gdk_macos_surface_get_native_window(self.to_glib_none().0);
native_window_ptr as id
}

#[cfg(not(feature = "v4_8"))]
{
let native_window_ptr: *mut c_void = ObjectExt::property(self, "native");
native_window_ptr as id
}
}
}

0 comments on commit 316e3ce

Please sign in to comment.