summarylogtreecommitdiffstats
path: root/0000-fix-wayland-gtk-csd.patch
blob: c27e5f28b2a5d313479b2452de9fd6aadfeec22c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--- a/linux/my_application.cc
+++ b/linux/my_application.cc
@@ -20,22 +20,25 @@
   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;
-  // Lines added to the template start
-  // Please re-add these lines after updating the linux build files
-  // If the user explicitly requests to disable the header bar, switch back to 
-  // using a traditional title bar
+  // Enable header bar (CSD) only if GTK_CSD is not "0",
+  // we're running under GNOME, and the libhandy theme resource exists.
+  gboolean use_header_bar = FALSE;
   const gchar* gtk_csd_env = g_getenv("GTK_CSD");
-  if (gtk_csd_env != nullptr && g_strcmp0(gtk_csd_env, "1") != 0)
-    use_header_bar = FALSE;
-  // Lines added to the template end
+  const gchar* desktop_env = g_getenv("XDG_CURRENT_DESKTOP");
+
+  if ((gtk_csd_env == NULL || g_strcmp0(gtk_csd_env, "0") != 0) &&
+      desktop_env != NULL &&
+      g_strrstr(desktop_env, "GNOME") != NULL &&
+      g_resources_get_info("/org/gtk/libhandy/theme/Adwaita.css",
+                           G_RESOURCE_LOOKUP_FLAGS_NONE,
+                           NULL, NULL, NULL)) {
+    use_header_bar = TRUE;
+  } else {
+    g_setenv("GTK_CSD", "0", TRUE);
+  }
+
+// On X11, disable CSD if the window manager is not GNOME Shell,
+// even though XDG_CURRENT_DESKTOP may report GNOME.
 #ifdef GDK_WINDOWING_X11
   GdkScreen* screen = gtk_window_get_screen(window);
   if (GDK_IS_X11_SCREEN(screen)) {