Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/csharp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/js-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 29 additions & 3 deletions bindings/dart/cnativeapi/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,22 @@ void main(List<String> 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')) {
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions bindings/rust/cnativeapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 12 additions & 1 deletion bindings/rust/cnativeapi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions bindings/rust/nativeapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 19 additions & 5 deletions bindings/swift/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -47,18 +49,27 @@ 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"),
.linkedLibrary("m"),
]
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",
Expand All @@ -76,6 +87,7 @@ systemTargets = [
#elseif os(Windows)
platformExcludes = ["android", "ios", "linux", "macos", "ohos", "wasm"]
nativeDependencies = []
nativeCxxSettings = []
nativeLinkerSettings = [
.linkedLibrary("user32"),
.linkedLibrary("shell32"),
Expand Down Expand Up @@ -105,6 +117,7 @@ excludes += [
#else
platformExcludes = ["android", "ios", "linux", "macos", "ohos", "wasm", "windows"]
nativeDependencies = []
nativeCxxSettings = []
nativeLinkerSettings = []
systemTargets = []
#endif
Expand Down Expand Up @@ -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"),
Expand Down
5 changes: 5 additions & 0 deletions bindings/swift/Sources/CGTK4/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module CGTK4 [system] {
header "shim.h"
link "gtk-4"
export *
}
1 change: 1 addition & 0 deletions bindings/swift/Sources/CGTK4/shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <gtk/gtk.h>
2 changes: 1 addition & 1 deletion core
Submodule core updated 50 files
+28 −5 .github/workflows/build.yml
+1 −1 README.md
+58 −0 docs/linux-gtk.md
+1 −4 examples/menu_c_example/CMakeLists.txt
+1 −4 examples/menu_example/CMakeLists.txt
+20 −1 examples/tray_color_example/main.cpp
+1 −4 examples/tray_stats_example/CMakeLists.txt
+1 −4 examples/tray_view_example/CMakeLists.txt
+1 −4 examples/view_example/CMakeLists.txt
+4 −0 examples/window_lifecycle_example/main.cpp
+1 −4 examples/window_taskbar_example/CMakeLists.txt
+15 −1 src/CMakeLists.txt
+3 −3 src/message_dialog.h
+2 −2 src/platform/linux/accessibility_manager_linux.cpp
+8 −2 src/platform/linux/application_linux.cpp
+452 −9 src/platform/linux/clipboard_linux.cpp
+20 −3 src/platform/linux/display_linux.cpp
+78 −2 src/platform/linux/display_manager_linux.cpp
+181 −5 src/platform/linux/drag_source_linux.cpp
+195 −4 src/platform/linux/drop_target_linux.cpp
+149 −5 src/platform/linux/file_dialog_linux.cpp
+75 −0 src/platform/linux/gtk_compat_linux.h
+17 −0 src/platform/linux/gtk_x11_compat_linux.h
+537 −1 src/platform/linux/menu_linux.cpp
+379 −51 src/platform/linux/message_dialog_linux.cpp
+3 −2 src/platform/linux/shortcut_manager_linux.cpp
+171 −3 src/platform/linux/tray_icon_linux.cpp
+54 −2 src/platform/linux/view_controls_linux.cpp
+11 −2 src/platform/linux/view_internal_linux.h
+245 −6 src/platform/linux/view_linux.cpp
+60 −5 src/platform/linux/window_close_linux.cpp
+56 −6 src/platform/linux/window_drag_session_linux.cpp
+1,090 −12 src/platform/linux/window_linux.cpp
+599 −2 src/platform/linux/window_manager_linux.cpp
+130 −15 src/platform/linux/window_shadow_linux.h
+263 −71 src/platform/macos/message_dialog_macos.mm
+272 −17 src/platform/windows/message_dialog_windows.cpp
+36 −11 tests/CMakeLists.txt
+35 −0 tests/gtk_test_compat.h
+70 −0 tests/message_dialog_extended_test.cpp
+132 −0 tests/message_dialog_macos_sheet_test.mm
+10 −2 tests/tray_context_menu_linux_test.cpp
+2 −2 tests/view_api_test.cpp
+30 −4 tests/window_close_linux_test.cpp
+7 −3 tests/window_close_manager_first_linux_test.cpp
+2 −2 tests/window_content_protection_test.cpp
+2 −2 tests/window_corner_preference_unsupported_test.cpp
+18 −8 tests/window_manager_hooks_linux_test.cpp
+3 −3 tests/window_occlusion_test.cpp
+6 −4 tests/window_property_changed_test.cpp
2 changes: 1 addition & 1 deletion website/content/api/message_dialog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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+."
}
]
},
Expand Down
Loading