From cf9297b0ab2b1ded7bc847dab721f4aacf3ac6f6 Mon Sep 17 00:00:00 2001 From: Jganenokk Date: Sat, 15 Aug 2026 16:30:22 +0700 Subject: [PATCH] =?UTF-8?q?fix(linux):=20PR=20#68=20=D0=BD=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D0=B2=D0=BD=D1=8B=D0=B9=20=D0=B4=D0=B5=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=20=D0=BE=D0=BA=D0=BE=D0=BD=20=D0=BF=D0=BE=20=D0=BE=D0=BA=D1=80?= =?UTF-8?q?=D1=83=D0=B6=D0=B5=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linux/runner/main.cc | 1 + linux/runner/my_application.cc | 48 +++++++++++++++++++--------------- linux/runner/my_application.h | 2 ++ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/linux/runner/main.cc b/linux/runner/main.cc index e7c5c54..92a23a7 100644 --- a/linux/runner/main.cc +++ b/linux/runner/main.cc @@ -1,6 +1,7 @@ #include "my_application.h" int main(int argc, char** argv) { + my_application_configure_windowing(); g_autoptr(MyApplication) app = my_application_new(); return g_application_run(G_APPLICATION(app), argc, argv); } diff --git a/linux/runner/my_application.cc b/linux/runner/my_application.cc index 832e416..43eb6be 100644 --- a/linux/runner/my_application.cc +++ b/linux/runner/my_application.cc @@ -1,9 +1,6 @@ #include "my_application.h" #include -#ifdef GDK_WINDOWING_X11 -#include -#endif #include "flutter/generated_plugin_registrant.h" @@ -14,6 +11,32 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) +static gboolean desktop_uses_gtk_header_bar() { + const gchar* desktops = g_getenv("XDG_CURRENT_DESKTOP"); + if (desktops == nullptr || *desktops == '\0') { + desktops = g_getenv("DESKTOP_SESSION"); + } + + if (desktops == nullptr) { + return FALSE; + } + + g_auto(GStrv) values = g_strsplit(desktops, ":", -1); + for (gchar** value = values; *value != nullptr; value++) { + if (g_ascii_strcasecmp(*value, "unity") == 0 || + g_ascii_strcasecmp(*value, "gnome") == 0 || + g_ascii_strncasecmp(*value, "gnome-", 6) == 0) { + return TRUE; + } + } + + return FALSE; +} + +void my_application_configure_windowing() { + g_setenv("GTK_CSD", desktop_uses_gtk_header_bar() ? "1" : "0", TRUE); +} + // Called when first Flutter frame received. static void first_frame_cb(MyApplication* self, FlView* view) { gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view))); @@ -25,24 +48,7 @@ static void my_application_activate(GApplication* application) { GtkWindow* window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); - // Use a header bar when running in GNOME as this is the common style used - // by applications and is the setup most users will be using (e.g. Ubuntu - // desktop). - // If running on X and not using GNOME then just use a traditional title bar - // in case the window manager does more exotic layout, e.g. tiling. - // If running on Wayland assume the header bar will work (may need changing - // if future cases occur). - gboolean use_header_bar = TRUE; -#ifdef GDK_WINDOWING_X11 - GdkScreen* screen = gtk_window_get_screen(window); - if (GDK_IS_X11_SCREEN(screen)) { - const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); - if (g_strcmp0(wm_name, "GNOME Shell") != 0) { - use_header_bar = FALSE; - } - } -#endif - if (use_header_bar) { + if (desktop_uses_gtk_header_bar()) { GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); gtk_header_bar_set_title(header_bar, "Komet"); diff --git a/linux/runner/my_application.h b/linux/runner/my_application.h index db16367..157b5eb 100644 --- a/linux/runner/my_application.h +++ b/linux/runner/my_application.h @@ -9,6 +9,8 @@ G_DECLARE_FINAL_TYPE(MyApplication, APPLICATION, GtkApplication) +void my_application_configure_windowing(); + /** * my_application_new: *