From e8c02d04aef8d45724938d9373d6617eca59f146 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Sat, 21 Mar 2026 15:57:03 +0100 Subject: [PATCH] fix: linux titlebar height on non-GNOME DEs --- linux/runner/my_application.cc | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/linux/runner/my_application.cc b/linux/runner/my_application.cc index 0cbf5d60..1c575a42 100644 --- a/linux/runner/my_application.cc +++ b/linux/runner/my_application.cc @@ -1,10 +1,6 @@ #include "my_application.h" #include -#ifdef GDK_WINDOWING_X11 -#include -#endif - #include "flutter/generated_plugin_registrant.h" #include "mpv/mpv_plugin.h" @@ -22,23 +18,12 @@ 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; - } + // Default to traditional titlebar. Set GTK_CSD=1 to use a header bar. + gboolean use_header_bar = FALSE; + const gchar* gtk_csd = g_getenv("GTK_CSD"); + if (gtk_csd != nullptr && g_strcmp0(gtk_csd, "1") == 0) { + use_header_bar = TRUE; } -#endif if (use_header_bar) { GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar));