Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | window: Check if we can use CSD before enabling them |
| 2 | |
| 3 | Upstream-Status: Backport |
| 4 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
| 5 | |
| 6 | |
| 7 | From c5e5ee67490e7e7af56052d8f8beb75db002c2f1 Mon Sep 17 00:00:00 2001 |
| 8 | From: Emmanuele Bassi <ebassi@gnome.org> |
| 9 | Date: Wed, 3 Jun 2015 14:07:29 +0100 |
| 10 | Subject: window: Check if we can use CSD before enabling them |
| 11 | |
| 12 | The change in 03213b9509fc1df16c66194ea168aed6c15110e9 changed the rules |
| 13 | as to when CSD can be enabled, but it also unconditionally enables CSD |
| 14 | with the implicit assumption that client-side shadows were the real |
| 15 | issue, and that we could work around that by drawing our own borders. |
| 16 | This also means that setting a titlebar for a GtkWindow will enable CSD |
| 17 | unconditionally. |
| 18 | |
| 19 | In reality, some window managers (like Matchbox) *only* support |
| 20 | server-side decorations, and will ignore all hints to the contrary, to |
| 21 | the point of drawing decorations at random locations on top of the |
| 22 | window. |
| 23 | |
| 24 | Since CSD are enabled unconditionally, the GTK_CSD environment variable |
| 25 | is also not a suitable escape hatch. |
| 26 | |
| 27 | In the grand tradition of asking ourselves if we should do something |
| 28 | just because we can, we should split the environment checks from the |
| 29 | checks on what the user requested; by doing that, we can also check |
| 30 | when enabling client-side decorations, and ideally bail out if needed. |
| 31 | |
| 32 | https://bugzilla.gnome.org/show_bug.cgi?id=750343 |
| 33 | |
| 34 | diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c |
| 35 | index 423c6bd..9fe882f 100644 |
| 36 | --- a/gtk/gtkwindow.c |
| 37 | +++ b/gtk/gtkwindow.c |
| 38 | @@ -4056,6 +4056,32 @@ gtk_window_supports_client_shadow (GtkWindow *window) |
| 39 | return TRUE; |
| 40 | } |
| 41 | |
| 42 | +static gboolean |
| 43 | +gtk_window_can_use_csd (GtkWindow *window) |
| 44 | +{ |
| 45 | + const gchar *csd_env; |
| 46 | + |
| 47 | +#ifdef GDK_WINDOWING_BROADWAY |
| 48 | + if (GDK_IS_BROADWAY_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window)))) |
| 49 | + return TRUE; |
| 50 | +#endif |
| 51 | + |
| 52 | +#ifdef GDK_WINDOWING_WAYLAND |
| 53 | + if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window)))) |
| 54 | + return TRUE; |
| 55 | +#endif |
| 56 | + |
| 57 | +#ifdef GDK_WINDOWING_MIR |
| 58 | + if (GDK_IS_MIR_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window)))) |
| 59 | + return TRUE; |
| 60 | +#endif |
| 61 | + |
| 62 | + csd_env = g_getenv ("GTK_CSD"); |
| 63 | + |
| 64 | + /* If GTK_CSD is unset we default to CSD support */ |
| 65 | + return csd_env == NULL || (strcmp (csd_env, "1") == 0); |
| 66 | +} |
| 67 | + |
| 68 | static void |
| 69 | gtk_window_enable_csd (GtkWindow *window) |
| 70 | { |
| 71 | @@ -4063,6 +4089,10 @@ gtk_window_enable_csd (GtkWindow *window) |
| 72 | GtkWidget *widget = GTK_WIDGET (window); |
| 73 | GdkVisual *visual; |
| 74 | |
| 75 | + /* If the environment does not support CSD, then there's no point in enabling them */ |
| 76 | + if (!gtk_window_can_use_csd (window)) |
| 77 | + return; |
| 78 | + |
| 79 | /* We need a visual with alpha for client shadows */ |
| 80 | if (priv->use_client_shadow) |
| 81 | { |
| 82 | @@ -5839,7 +5869,6 @@ static gboolean |
| 83 | gtk_window_should_use_csd (GtkWindow *window) |
| 84 | { |
| 85 | GtkWindowPrivate *priv = window->priv; |
| 86 | - const gchar *csd_env; |
| 87 | |
| 88 | if (priv->csd_requested) |
| 89 | return TRUE; |
| 90 | @@ -5850,24 +5879,7 @@ gtk_window_should_use_csd (GtkWindow *window) |
| 91 | if (priv->type == GTK_WINDOW_POPUP) |
| 92 | return FALSE; |
| 93 | |
| 94 | -#ifdef GDK_WINDOWING_BROADWAY |
| 95 | - if (GDK_IS_BROADWAY_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window)))) |
| 96 | - return TRUE; |
| 97 | -#endif |
| 98 | - |
| 99 | -#ifdef GDK_WINDOWING_WAYLAND |
| 100 | - if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window)))) |
| 101 | - return TRUE; |
| 102 | -#endif |
| 103 | - |
| 104 | -#ifdef GDK_WINDOWING_MIR |
| 105 | - if (GDK_IS_MIR_DISPLAY (gtk_widget_get_display (GTK_WIDGET (window)))) |
| 106 | - return TRUE; |
| 107 | -#endif |
| 108 | - |
| 109 | - csd_env = g_getenv ("GTK_CSD"); |
| 110 | - |
| 111 | - return (g_strcmp0 (csd_env, "1") == 0); |
| 112 | + return gtk_window_can_use_csd (window); |
| 113 | } |
| 114 | |
| 115 | static void |
| 116 | -- |
| 117 | cgit v0.10.2 |
| 118 | |