Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdk4-macos: manually implement native_window method #1938

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
sdroege marked this conversation as resolved.
Show resolved Hide resolved

[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"]
3 changes: 2 additions & 1 deletion gdk4-macos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you want to track the bleeding edge, use the git dependency instead:

```toml
[dependencies]
gdk-wayland = { git = "https://github.com/gtk-rs/gtk4-rs.git", package = "gdk4-wayland" }
gdk-macos = { git = "https://github.com/gtk-rs/gtk4-rs.git", package = "gdk4-macos" }
```

Avoid mixing versioned and git crates like this:
Expand All @@ -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
}
}
}
Loading