Skip to content

Commit 6f66dd1

Browse files
nachobilelmoussaoui
authored andcommitted
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 b5edcb4 commit 6f66dd1

File tree

8 files changed

+175
-17
lines changed

8 files changed

+175
-17
lines changed

.github/workflows/macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ jobs:
5959
uses: actions-rs/cargo@v1
6060
with:
6161
command: build
62-
args: --features v4_8 --manifest-path ./gdk4-macos/Cargo.toml
62+
args: --features cocoa,v4_8 --manifest-path ./gdk4-macos/Cargo.toml
6363
- name: Clippy gdk4-macos
6464
uses: actions-rs/cargo@v1
6565
with:
6666
command: clippy
67-
args: --features v4_8 --manifest-path ./gdk4-macos/Cargo.toml
67+
args: --features cocoa,v4_8 --manifest-path ./gdk4-macos/Cargo.toml
6868
- name: Tests gdk4-macos
6969
uses: actions-rs/cargo@v1
7070
with:
7171
command: test
72-
args: --features v4_8 --manifest-path ./gdk4-macos/Cargo.toml
72+
args: --features cocoa,v4_8 --manifest-path ./gdk4-macos/Cargo.toml

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+
cocoa = ["dep: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", default-features = false, optional = true }
2527

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

gdk4-macos/Gir.toml

Lines changed: 12 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,15 @@ 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+
rename = "native"
47+
[[object.property]]
48+
name = "native"
49+
generate = ["notify"]

gdk4-macos/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ gdk-wayland = { git = "https://github.com/gtk-rs/gtk4-rs.git", package = "gdk4-w
4444
| Feature | Description |
4545
| --- | ----------- |
4646
| `v4_8` | Enable the new APIs part of GTK 4.8 |
47+
| `cocoa` | Integration with the [cocoa](https://crates.io/crates/cocoa) crate |
4748

4849
### See Also
4950

gdk4-macos/src/auto/macos_surface.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ glib::wrapper! {
2020
}
2121

2222
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-
3523
#[doc(alias = "native")]
3624
pub fn connect_native_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
3725
unsafe extern "C" fn notify_native_trampoline<F: Fn(&MacosSurface) + 'static>(

gdk4-macos/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#![allow(deprecated)]
55
#![cfg_attr(docsrs, feature(doc_cfg))]
66

7+
#[cfg(not(feature = "cocoa"))]
8+
use std::ffi::c_void;
9+
710
pub use gdk;
811
pub use gdk4_macos_sys as ffi;
912
pub use gio;
@@ -16,3 +19,12 @@ mod auto;
1619
pub mod prelude;
1720

1821
pub use auto::*;
22+
23+
mod macos_surface;
24+
25+
#[cfg(not(feature = "cocoa"))]
26+
#[allow(non_camel_case_types)]
27+
pub type id = *mut c_void;
28+
29+
#[cfg(feature = "cocoa")]
30+
pub use cocoa::base::id;

gdk4-macos/src/macos_surface.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
#[cfg(not(feature = "v4_8"))]
6+
use crate::prelude::*;
7+
use crate::{id, MacosSurface};
8+
#[cfg(feature = "v4_8")]
9+
use glib::translate::*;
10+
#[cfg(not(feature = "v4_8"))]
11+
use std::ffi::c_void;
12+
13+
impl MacosSurface {
14+
#[doc(alias = "gdk_macos_surface_get_native_window")]
15+
#[doc(alias = "get_native_window")]
16+
pub fn native(&self) -> id {
17+
#[cfg(feature = "v4_8")]
18+
unsafe {
19+
let native_window_ptr = ffi::gdk_macos_surface_get_native_window(self.to_glib_none().0);
20+
native_window_ptr as id
21+
}
22+
23+
#[cfg(not(feature = "v4_8"))]
24+
{
25+
let native_window_ptr: *mut c_void = ObjectExt::property(self, "native");
26+
native_window_ptr as id
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)