From 2d7e2c8345e0b77740f02566ad34cefdae91c983 Mon Sep 17 00:00:00 2001 From: Hanna Date: Thu, 2 Nov 2023 21:29:29 -0700 Subject: [PATCH] Integrate libadwaita for the gtk backend (#792) * When using gtk as the backend, link libadwaita * Update c.zig * Use libadwaita's theme manager for gtk * update the documentation for window-theme * build: add libadwaita to the nix devshell * forgot to properly import libadwaita * apprt/gtk: adwaita style change --------- Co-authored-by: Mitchell Hashimoto --- build.zig | 1 + nix/devshell.nix | 3 +++ src/apprt/gtk/App.zig | 13 +++++++++++++ src/apprt/gtk/c.zig | 1 + src/config/Config.zig | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index cc914dca2..7b7f0ce94 100644 --- a/build.zig +++ b/build.zig @@ -814,6 +814,7 @@ fn addDeps( .gtk => { step.linkSystemLibrary2("gtk4", dynamic_link_opts); + step.linkSystemLibrary2("adwaita-1", dynamic_link_opts); }, } } diff --git a/nix/devshell.nix b/nix/devshell.nix index 78d8de6fb..5804cceb5 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -28,6 +28,7 @@ , freetype , glib , gtk4 +, libadwaita , harfbuzz , libpng , libGL @@ -59,6 +60,7 @@ let libXi libXrandr + libadwaita gtk4 glib ]; @@ -120,6 +122,7 @@ in mkShell rec { libXrandr # Only needed for GTK builds + libadwaita gtk4 glib ]; diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 47e69eba3..f5f93c38f 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -52,6 +52,9 @@ running: bool = true, pub fn init(core_app: *CoreApp, opts: Options) !App { _ = opts; + // Initialize libadwaita + c.adw_init(); + // Load our configuration var config = try Config.load(core_app.alloc); errdefer config.deinit(); @@ -63,6 +66,16 @@ pub fn init(core_app: *CoreApp, opts: Options) !App { } } + // Set the style based on our configuration file + c.adw_style_manager_set_color_scheme( + c.adw_style_manager_get_default(), + switch (config.@"window-theme") { + .system => c.ADW_COLOR_SCHEME_PREFER_LIGHT, + .dark => c.ADW_COLOR_SCHEME_FORCE_DARK, + .light => c.ADW_COLOR_SCHEME_FORCE_LIGHT, + }, + ); + // The "none" cursor is used for hiding the cursor const cursor_none = c.gdk_cursor_new_from_name("none", null); errdefer if (cursor_none) |cursor| c.g_object_unref(cursor); diff --git a/src/apprt/gtk/c.zig b/src/apprt/gtk/c.zig index c5952d321..7eb19233f 100644 --- a/src/apprt/gtk/c.zig +++ b/src/apprt/gtk/c.zig @@ -1,5 +1,6 @@ const c = @cImport({ @cInclude("gtk/gtk.h"); + @cInclude("libadwaita-1/adwaita.h"); }); pub usingnamespace c; diff --git a/src/config/Config.zig b/src/config/Config.zig index dc47fd5bd..7f2218ef0 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -378,7 +378,7 @@ keybind: Keybinds = .{}, /// also be set to "light" or "dark" to force a specific theme regardless /// of the system settings. /// -/// This is currently only supported on macOS. +/// This is currently only supported on macOS and linux. @"window-theme": WindowTheme = .system, /// The initial window size. This size is in terminal grid cells by default.