summaryrefslogtreecommitdiff
path: root/gtk3-stackrpms/gtk3-nocsd/gtk3-nocsd-gh-c64505268575e60322de682ea751660eba8d0e71.patch
blob: 782699fb9b1af56d061468fbcd03bec3a5e6dbf1 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From c64505268575e60322de682ea751660eba8d0e71 Mon Sep 17 00:00:00 2001
From: Christian Seiler <christian@iwakd.de>
Date: Wed, 1 Jun 2016 07:50:38 +0000
Subject: [PATCH] Only cache gtk version check result if Gtk is loaded

If in a dynamical program (e.g. using python-gi) Glib is loaded before
Gtk, then the Gtk version check is executed before Gtk is even loaded,
returning FALSE and caching it. This will not disable CSD if Gtk is
loaded later. To circumvent this, cache the value only if we know that
Gtk is loaded.

Fixes github issue #16.
---
 ChangeLog    |  7 +++++++
 gtk3-nocsd.c | 27 ++++++++++++++++++++++-----
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2f98771..53cbd33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
 gtk3-nocsd ChangeLog
 ====================
 
+New in version 4 (unreleased)
+-----------------------------
+
+  * Support python-gi again by not caching the result of the version
+    check if Gtk is not yet loaded. (python-gi loads Glib before it
+    loads Gtk.)
+
 New in version 3
 ----------------
 
diff --git a/gtk3-nocsd.c b/gtk3-nocsd.c
index 08844c6..804fbd5 100644
--- a/gtk3-nocsd.c
+++ b/gtk3-nocsd.c
@@ -374,7 +374,7 @@ static void static_g_log(const gchar *log_domain, GLogLevelFlags log_level, cons
     va_end (args);
 }
 
-static gboolean is_gtk_version_larger_or_equal(guint major, guint minor, guint micro) {
+static gboolean is_gtk_version_larger_or_equal2(guint major, guint minor, guint micro, int* gtk_loaded) {
     static gtk_check_version_t orig_func = NULL;
     if(!orig_func)
         orig_func = (gtk_check_version_t)find_orig_function(0, GTK_LIBRARY, "gtk_check_version");
@@ -388,9 +388,19 @@ static gboolean is_gtk_version_larger_or_equal(guint major, guint minor, guint m
      * will give us a reference to gtk_check_version. But since
      * that symbol is compatible with gtk3, this doesn't hurt.
      */
-     if (orig_func)
+     if (orig_func) {
+         if (gtk_loaded)
+             *gtk_loaded = TRUE;
         return (orig_func(major, minor, micro) == NULL);
-    return FALSE;
+     } else {
+         if (gtk_loaded)
+             *gtk_loaded = FALSE;
+        return FALSE;
+     }
+}
+
+static gboolean is_gtk_version_larger_or_equal(guint major, guint minor, guint micro) {
+    return is_gtk_version_larger_or_equal2(major, minor, micro, NULL);
 }
 
 static gboolean are_csd_disabled() {
@@ -408,15 +418,22 @@ static gboolean is_compatible_gtk_version() {
      * memory barriers. */
     static volatile gboolean checked = FALSE;
     static volatile gboolean compatible = FALSE;
+    int gtk_loaded = FALSE;
 
     if(G_UNLIKELY(!checked)) {
-        if (!is_gtk_version_larger_or_equal(3, 10, 0)) {
+        if (!is_gtk_version_larger_or_equal2(3, 10, 0, &gtk_loaded)) {
             /* CSD was introduced there */
             compatible = FALSE;
         } else {
             compatible = TRUE;
         }
-        checked = TRUE;
+        /* If in a dynamical program (e.g. using python-gi) Glib is loaded before
+         * Gtk, then the Gtk version check is executed before Gtk is even loaded,
+         * returning FALSE and caching it. This will not disable CSD if Gtk is
+         * loaded later. To circumvent this, cache the value only if we know that
+         * Gtk is loaded. */
+        if (gtk_loaded)
+            checked = TRUE;
     }
 
     return compatible;
bgstack15