diff --git a/.github/workflows/csharp-ci.yml b/.github/workflows/csharp-ci.yml index efafb36..282efd6 100644 --- a/.github/workflows/csharp-ci.yml +++ b/.github/workflows/csharp-ci.yml @@ -79,7 +79,7 @@ jobs: 9.0.x - name: Install Linux dependencies if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-4-dev libx11-dev libxi-dev - name: Configure native library run: cmake -S src/CNativeAPI/native -B build/native -DCMAKE_BUILD_TYPE=Release - name: Build native library diff --git a/.github/workflows/go-ci.yml b/.github/workflows/go-ci.yml index df59f98..dbfdc44 100644 --- a/.github/workflows/go-ci.yml +++ b/.github/workflows/go-ci.yml @@ -47,7 +47,7 @@ jobs: cache: false - name: Install Linux dependencies if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev xvfb + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-4-dev libx11-dev libxi-dev xvfb - uses: msys2/setup-msys2@v2 if: runner.os == 'Windows' with: diff --git a/.github/workflows/js-ci.yml b/.github/workflows/js-ci.yml index ab7437c..7c6c899 100644 --- a/.github/workflows/js-ci.yml +++ b/.github/workflows/js-ci.yml @@ -47,7 +47,7 @@ jobs: deno-version: v2.x - name: Install Linux dependencies if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev xvfb + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-4-dev libx11-dev libxi-dev xvfb # Installs the workspace and compiles the addon (the package's install hook). - run: npm install - name: Typecheck diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index fd97680..4af7c23 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -40,7 +40,7 @@ jobs: - uses: astral-sh/setup-uv@v6 - name: Install Linux dependencies if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev xvfb + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-4-dev libx11-dev libxi-dev xvfb - name: Lint working-directory: bindings/python run: uvx ruff check nativeapi tests --select E,F,W,B,UP,I diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index f03419e..53f7f18 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -46,7 +46,7 @@ jobs: with: components: rustfmt, clippy - name: Install native dependencies - run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-4-dev libx11-dev libxi-dev - uses: Swatinem/rust-cache@v2 - name: Check formatting run: cargo fmt --all -- --check @@ -68,7 +68,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - name: Install Linux dependencies if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-4-dev libx11-dev libxi-dev - uses: Swatinem/rust-cache@v2 - name: Build libraries and all examples run: cargo build --workspace --all-targets --release --locked diff --git a/.github/workflows/rust-release.yml b/.github/workflows/rust-release.yml index 1db84a0..d5c9017 100644 --- a/.github/workflows/rust-release.yml +++ b/.github/workflows/rust-release.yml @@ -43,7 +43,7 @@ jobs: assert not tag or tag == f'rust-v{version}', 'Tag does not match crate versions' PY - name: Install native dependencies - run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-4-dev libx11-dev libxi-dev - uses: Swatinem/rust-cache@v2 - name: Test release sources run: cargo test --workspace --release --locked diff --git a/bindings/dart/cnativeapi/hook/build.dart b/bindings/dart/cnativeapi/hook/build.dart index 74ca237..698069a 100644 --- a/bindings/dart/cnativeapi/hook/build.dart +++ b/bindings/dart/cnativeapi/hook/build.dart @@ -82,11 +82,22 @@ void main(List args) async { flags.addAll(_appleLinkerStripFlags); frameworks = ['UIKit', 'Foundation', 'CoreGraphics']; case OS.linux: + final backend = _linuxBackend(input); + final linuxPackages = [ + backend == 'gtk4' ? 'gtk4' : 'gtk+-3.0', + 'x11', + 'xi', + ]; + flags.add( + backend == 'gtk4' + ? '-DNATIVEAPI_LINUX_GTK4' + : '-DNATIVEAPI_LINUX_GTK3', + ); flags.addAll(_sizeAndVisibilityFlags); flags.addAll(_elfLinkerStripFlags); - flags.addAll(await _pkgConfig(['--cflags', ..._linuxPackages])); + flags.addAll(await _pkgConfig(['--cflags', ...linuxPackages])); // Libraries go after the sources, where --as-needed keeps them. - for (final flag in await _pkgConfig(['--libs', ..._linuxPackages])) { + for (final flag in await _pkgConfig(['--libs', ...linuxPackages])) { if (flag.startsWith('-l')) { libraries.add(flag.substring(2)); } else if (flag.startsWith('-L')) { @@ -182,7 +193,22 @@ const _elfLinkerStripFlags = [ const _appleLinkerStripFlags = ['-Wl,-dead_strip', '-Wl,-x']; -const _linuxPackages = ['gtk+-3.0', 'x11', 'xi']; +/// The Linux GTK backend to link against: `gtk3` (default, matching Flutter's +/// Linux embedder) or `gtk4`. Configured via +/// `hooks.user_defines.cnativeapi.linux_backend` or `NATIVEAPI_LINUX_BACKEND`. +String _linuxBackend(BuildInput input) { + final defined = input.userDefines['linux_backend']; + final raw = + (defined ?? Platform.environment['NATIVEAPI_LINUX_BACKEND'] ?? 'gtk3') + .toString() + .toLowerCase(); + if (raw == 'gtk3' || raw == 'gtk4') { + return raw; + } + throw FormatException( + 'hooks.user_defines.cnativeapi.linux_backend must be "gtk3" or "gtk4"; got $raw', + ); +} /// The platforms the app builds without the native library, from /// `hooks.user_defines.cnativeapi.skip_platforms` in its pubspec. diff --git a/bindings/rust/cnativeapi/Cargo.toml b/bindings/rust/cnativeapi/Cargo.toml index c825233..541f095 100644 --- a/bindings/rust/cnativeapi/Cargo.toml +++ b/bindings/rust/cnativeapi/Cargo.toml @@ -11,6 +11,11 @@ keywords = ["native", "desktop", "window", "tray", "menu"] categories = ["api-bindings", "gui", "os"] build = "build.rs" +[features] +default = [] +# Link against GTK 3 instead of core's default GTK 4 on Linux. +gtk3 = [] + [dependencies] [build-dependencies] diff --git a/bindings/rust/cnativeapi/build.rs b/bindings/rust/cnativeapi/build.rs index 8c58568..83a3211 100644 --- a/bindings/rust/cnativeapi/build.rs +++ b/bindings/rust/cnativeapi/build.rs @@ -55,8 +55,19 @@ fn main() { } "linux" => { cmake_config.define("CMAKE_SYSTEM_NAME", "Linux"); + println!("cargo:rerun-if-env-changed=NATIVEAPI_LINUX_BACKEND"); + let use_gtk3 = env::var("CARGO_FEATURE_GTK3").is_ok() + || env::var("NATIVEAPI_LINUX_BACKEND") + .map(|v| v.eq_ignore_ascii_case("GTK3")) + .unwrap_or(false); + let (backend, gtk_pkg) = if use_gtk3 { + ("GTK3", "gtk+-3.0") + } else { + ("GTK4", "gtk4") + }; + cmake_config.define("NATIVEAPI_LINUX_BACKEND", backend); // Note: Linux dependencies (GTK, X11, etc.) should be installed on the system - for library in ["gtk+-3.0", "x11", "xi"] { + for library in [gtk_pkg, "x11", "xi"] { pkg_config::Config::new().probe(library).unwrap(); } println!("cargo:rustc-link-lib=pthread"); diff --git a/bindings/rust/nativeapi/Cargo.toml b/bindings/rust/nativeapi/Cargo.toml index ebc0f75..c1e99af 100644 --- a/bindings/rust/nativeapi/Cargo.toml +++ b/bindings/rust/nativeapi/Cargo.toml @@ -10,6 +10,11 @@ readme = "../README.md" keywords = ["native", "desktop", "window", "tray", "menu"] categories = ["api-bindings", "gui", "os"] +[features] +default = [] +# Link against GTK 3 instead of core's default GTK 4 on Linux. +gtk3 = ["cnativeapi/gtk3"] + [dependencies] cnativeapi = { version = "0.5.3", path = "../cnativeapi" } thiserror = "2.0" diff --git a/bindings/swift/Package.swift b/bindings/swift/Package.swift index 7319f62..b560b7f 100644 --- a/bindings/swift/Package.swift +++ b/bindings/swift/Package.swift @@ -30,12 +30,14 @@ var excludes = [ let platformExcludes: [String] let nativeDependencies: [Target.Dependency] +let nativeCxxSettings: [CXXSetting] let nativeLinkerSettings: [LinkerSetting] let systemTargets: [Target] #if os(macOS) platformExcludes = ["android", "ios", "linux", "ohos", "wasm", "windows"] nativeDependencies = [] +nativeCxxSettings = [] nativeLinkerSettings = [ .linkedFramework("Cocoa"), .linkedFramework("CoreServices"), @@ -47,7 +49,16 @@ nativeLinkerSettings = [ systemTargets = [] #elseif os(Linux) platformExcludes = ["android", "ios", "macos", "ohos", "wasm", "windows"] -nativeDependencies = ["CGTK3", "CX11", "CXI"] +let linuxUseGtk3 = + ProcessInfo.processInfo.environment["NATIVEAPI_LINUX_BACKEND"]?.uppercased() == "GTK3" +let gtkTargetName = linuxUseGtk3 ? "CGTK3" : "CGTK4" +let gtkPkgConfig = linuxUseGtk3 ? "gtk+-3.0" : "gtk4" +let gtkAptPkg = linuxUseGtk3 ? "libgtk-3-dev" : "libgtk-4-dev" +let gtkYumPkg = linuxUseGtk3 ? "gtk3-devel" : "gtk4-devel" +nativeCxxSettings = [ + .define(linuxUseGtk3 ? "NATIVEAPI_LINUX_GTK3" : "NATIVEAPI_LINUX_GTK4") +] +nativeDependencies = [.target(name: gtkTargetName), "CX11", "CXI"] nativeLinkerSettings = [ .linkedLibrary("pthread"), .linkedLibrary("dl"), @@ -55,10 +66,10 @@ nativeLinkerSettings = [ ] systemTargets = [ .systemLibrary( - name: "CGTK3", - path: "Sources/CGTK3", - pkgConfig: "gtk+-3.0", - providers: [.apt(["libgtk-3-dev"]), .yum(["gtk3-devel"])] + name: gtkTargetName, + path: "Sources/\(gtkTargetName)", + pkgConfig: gtkPkgConfig, + providers: [.apt([gtkAptPkg]), .yum([gtkYumPkg])] ), .systemLibrary( name: "CX11", @@ -76,6 +87,7 @@ systemTargets = [ #elseif os(Windows) platformExcludes = ["android", "ios", "linux", "macos", "ohos", "wasm"] nativeDependencies = [] +nativeCxxSettings = [] nativeLinkerSettings = [ .linkedLibrary("user32"), .linkedLibrary("shell32"), @@ -105,6 +117,7 @@ excludes += [ #else platformExcludes = ["android", "ios", "linux", "macos", "ohos", "wasm", "windows"] nativeDependencies = [] +nativeCxxSettings = [] nativeLinkerSettings = [] systemTargets = [] #endif @@ -135,6 +148,7 @@ let package = Package( path: "Sources/CNativeAPI", exclude: excludes, publicHeadersPath: "include", + cxxSettings: nativeCxxSettings, linkerSettings: nativeLinkerSettings ), .target(name: "NativeAPI", dependencies: ["CNativeAPI"], path: "Sources/NativeAPI"), diff --git a/bindings/swift/Sources/CGTK4/module.modulemap b/bindings/swift/Sources/CGTK4/module.modulemap new file mode 100644 index 0000000..c1c7fb8 --- /dev/null +++ b/bindings/swift/Sources/CGTK4/module.modulemap @@ -0,0 +1,5 @@ +module CGTK4 [system] { + header "shim.h" + link "gtk-4" + export * +} diff --git a/bindings/swift/Sources/CGTK4/shim.h b/bindings/swift/Sources/CGTK4/shim.h new file mode 100644 index 0000000..3e4515b --- /dev/null +++ b/bindings/swift/Sources/CGTK4/shim.h @@ -0,0 +1 @@ +#include diff --git a/core b/core index af9b56a..217d736 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit af9b56aa591ceabe4edbce93b13ab93a629c6f4a +Subproject commit 217d7364bab4326598cc41a4a785dacfa8d81729 diff --git a/website/content/api/message_dialog.json b/website/content/api/message_dialog.json index f2fdce7..13a225f 100644 --- a/website/content/api/message_dialog.json +++ b/website/content/api/message_dialog.json @@ -111,7 +111,7 @@ "notes": [ { "kind": "note", - "text": "Platform availability:\n- macOS: ❌ Not supported.\n- Windows: ✅ WinUI3 backend.\n- Linux: ❌ Not supported.\n- Android: ❌ Not supported.\n- iOS: ❌ Not supported.\n- OpenHarmony: ✅ Native ArkUI controls after UI host initialization; API 23+." + "text": "Platform availability:\n- macOS: ✅ Supported (NSAlert; non-blocking sheet when parent window is set).\n- Windows: ✅ Supported (Win32 TaskDialogIndirect and WinUI3 backends).\n- Linux: ✅ Supported (GTK 3 GtkMessageDialog and GTK 4 GtkAlertDialog).\n- Android: ❌ Not supported.\n- iOS: ❌ Not supported.\n- OpenHarmony: ✅ Native ArkUI controls after UI host initialization; API 23+." } ] },