[gnome-settings-daemon] xsettings: Set Gtk/DecorationLayout from wm preferences



commit dc5619f07abc478b51642d03e243f3ba805f0500
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu May 29 18:49:57 2014 +0200

    xsettings: Set Gtk/DecorationLayout from wm preferences
    
    GTK+'s client-side decorations follow an XSetting to determine
    which standard window buttons to show, similar to mutter's
    button-layout setting in org.gnome.desktop.wm.preferences.
    Keeping both mechanisms completely separate obviously means we
    can end up with unwanted inconsistency, so use the GSetting
    to back the XSetting on GNOME, just like we already do for
    other settings (though it's a bit more involved, as the
    possible values differ between mutter and GTK+).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730629

 .gitignore                                         |    1 +
 plugins/xsettings/Makefile.am                      |   21 +++++
 plugins/xsettings/gsd-xsettings-manager.c          |   25 ++++++-
 .../xsettings/test-wm-button-layout-translations.c |   54 ++++++++++++
 plugins/xsettings/wm-button-layout-translation.c   |   88 ++++++++++++++++++++
 plugins/xsettings/wm-button-layout-translation.h   |   26 ++++++
 6 files changed, 214 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index c542d01..a1e6f36 100644
--- a/.gitignore
+++ b/.gitignore
@@ -119,5 +119,6 @@ plugins/xrandr/gsd-test-xrandr
 plugins/xrandr/gsd-xrandr-manager-glue.h
 plugins/xsettings/gsd-test-xsettings
 plugins/xsettings/test-gtk-modules
+plugins/xsettings/test-wm-button-layout-translations
 tests/shiftkey
 test-driver
diff --git a/plugins/xsettings/Makefile.am b/plugins/xsettings/Makefile.am
index bb7ee14..da490b2 100644
--- a/plugins/xsettings/Makefile.am
+++ b/plugins/xsettings/Makefile.am
@@ -27,6 +27,23 @@ test_gtk_modules_CPPFLAGS =                          \
        -DGTK_MODULES_DIRECTORY=\""$(libdir)/gnome-settings-daemon- GSD_API_VERSION@/gtk-modules/"\" \
        $(AM_CPPFLAGS)
 
+noinst_PROGRAMS += test-wm-button-layout-translations
+
+test_wm_button_layout_translations_SOURCES =   \
+       test-wm-button-layout-translations.c    \
+       wm-button-layout-translation.c          \
+       wm-button-layout-translation.h          \
+       $(NULL)
+
+test_wm_button_layout_translations_CFLAGS =    \
+       $(XSETTINGS_CFLAGS)                     \
+       $(AM_CFLAGS)                            \
+       $(NULL)
+
+test_wm_button_layout_translations_LDADD =     \
+       $(XSETTINGS_LIBS)                       \
+       $(NULL)
+
 libexec_PROGRAMS = gsd-test-xsettings
 
 gsd_test_xsettings_SOURCES =   \
@@ -42,6 +59,8 @@ gsd_test_xsettings_SOURCES =  \
        fontconfig-monitor.h    \
        gsd-remote-display-manager.c \
        gsd-remote-display-manager.h \
+       wm-button-layout-translation.c  \
+       wm-button-layout-translation.h  \
        test-xsettings.c
 
 gsd_test_xsettings_CFLAGS = $(libxsettings_la_CFLAGS) $(PLUGIN_CFLAGS)
@@ -66,6 +85,8 @@ libxsettings_la_SOURCES =     \
        gsd-remote-display-manager.h \
        fontconfig-monitor.h    \
        fontconfig-monitor.c    \
+       wm-button-layout-translation.c  \
+       wm-button-layout-translation.h  \
        $(NULL)
 
 libxsettings_la_CPPFLAGS =                                     \
diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index 75176b5..035ed50 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -50,6 +50,7 @@
 #include "xsettings-manager.h"
 #include "fontconfig-monitor.h"
 #include "gsd-remote-display-manager.h"
+#include "wm-button-layout-translation.h"
 
 #define GNOME_XSETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), 
GNOME_TYPE_XSETTINGS_MANAGER, GnomeXSettingsManagerPrivate))
 
@@ -58,6 +59,7 @@
 #define INTERFACE_SETTINGS_SCHEMA "org.gnome.desktop.interface"
 #define SOUND_SETTINGS_SCHEMA     "org.gnome.desktop.sound"
 #define PRIVACY_SETTINGS_SCHEMA     "org.gnome.desktop.privacy"
+#define WM_SETTINGS_SCHEMA        "org.gnome.desktop.wm.preferences"
 
 #define XSETTINGS_PLUGIN_SCHEMA "org.gnome.settings-daemon.plugins.xsettings"
 #define XSETTINGS_OVERRIDE_KEY  "overrides"
@@ -329,6 +331,24 @@ translate_string_string (GnomeXSettingsManager *manager,
 }
 
 static void
+translate_button_layout (GnomeXSettingsManager *manager,
+                         TranslationEntry      *trans,
+                         GVariant              *value)
+{
+        char *layout = g_variant_dup_string (value, NULL);
+        int i;
+
+        translate_wm_button_layout_to_gtk (layout);
+
+        for (i = 0; manager->priv->managers [i]; i++)
+                xsettings_manager_set_string (manager->priv->managers [i],
+                                              trans->xsetting_name,
+                                              layout);
+
+        g_free (layout);
+}
+
+static void
 fixed_false_int (GnomeXSettingsManager *manager,
                  FixedEntry            *fixed)
 {
@@ -384,7 +404,8 @@ static TranslationEntry translations [] = {
         { "org.gnome.desktop.sound", "input-feedback-sounds",      "Net/EnableInputFeedbackSounds", 
translate_bool_int },
 
         { "org.gnome.desktop.privacy", "recent-files-max-age",      "Gtk/RecentFilesMaxAge", 
translate_int_int },
-        { "org.gnome.desktop.privacy", "remember-recent-files",    "Gtk/RecentFilesEnabled", 
translate_bool_int }
+        { "org.gnome.desktop.privacy", "remember-recent-files",    "Gtk/RecentFilesEnabled", 
translate_bool_int },
+        { "org.gnome.desktop.wm.preferences", "button-layout",     "Gtk/DecorationLayout", 
translate_button_layout }
 };
 
 static gboolean
@@ -1122,6 +1143,8 @@ gnome_xsettings_manager_start (GnomeXSettingsManager *manager,
                              SOUND_SETTINGS_SCHEMA, g_settings_new (SOUND_SETTINGS_SCHEMA));
         g_hash_table_insert (manager->priv->settings,
                              PRIVACY_SETTINGS_SCHEMA, g_settings_new (PRIVACY_SETTINGS_SCHEMA));
+        g_hash_table_insert (manager->priv->settings,
+                             WM_SETTINGS_SCHEMA, g_settings_new (WM_SETTINGS_SCHEMA));
 
         g_signal_connect (G_OBJECT (g_hash_table_lookup (manager->priv->settings, 
INTERFACE_SETTINGS_SCHEMA)), "changed::enable-animations",
                           G_CALLBACK (enable_animations_changed_cb), manager);
diff --git a/plugins/xsettings/test-wm-button-layout-translations.c 
b/plugins/xsettings/test-wm-button-layout-translations.c
new file mode 100644
index 0000000..5ab140a
--- /dev/null
+++ b/plugins/xsettings/test-wm-button-layout-translations.c
@@ -0,0 +1,54 @@
+#include <glib.h>
+
+#include "wm-button-layout-translation.h"
+
+static void
+test_button_layout_translations (void)
+{
+  static struct {
+    char *layout;
+    char *expected;
+  } tests[] = {
+    { "", "" },
+    { "invalid", "" },
+
+    { ":", ":" },
+    { ":invalid", ":" },
+    { "invalid:", ":" },
+    { "invalid:invalid", ":" },
+
+    { "appmenu", "menu" },
+    { "appmenu:", "menu:" },
+    { ":menu", ":icon" },
+    { "appmenu:close", "menu:close" },
+    { "appmenu:minimize,maximize,close", "menu:minimize,maximize,close" },
+    { "menu,appmenu:minimize,maximize,close", "icon,menu:minimize,maximize,close" },
+
+    { "close,close,close:close,close,close", "close,close,close:close,close,close" },
+
+    { "invalid,appmenu:invalid,minimize", "menu:minimize" },
+    { "appmenu,invalid:minimize,invalid", "menu:minimize" },
+    { "invalidmenu:invalidclose", ":" },
+    { "invalid,invalid,invalid:invalid,minimize,maximize,close", ":minimize,maximize,close" },
+  };
+  int i;
+
+  for (i = 0; i < G_N_ELEMENTS (tests); i++)
+    {
+      char *layout = g_strdup (tests[i].layout);
+
+      translate_wm_button_layout_to_gtk (layout);
+      g_assert_cmpstr (layout, ==, tests[i].expected);
+      g_free (layout);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/layout-translations", test_button_layout_translations);
+
+  return g_test_run ();
+}
diff --git a/plugins/xsettings/wm-button-layout-translation.c 
b/plugins/xsettings/wm-button-layout-translation.c
new file mode 100644
index 0000000..0fa4d2c
--- /dev/null
+++ b/plugins/xsettings/wm-button-layout-translation.c
@@ -0,0 +1,88 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:  Florian Müllner <fmuellner gnome org>
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include "wm-button-layout-translation.h"
+
+static void
+translate_buttons (char *layout, int *len_p)
+{
+  char *strp = layout, *button;
+  int len = 0;
+
+  if (!layout || !*layout)
+    goto out;
+
+  while ((button = strsep (&strp, ",")))
+    {
+      char *gtkbutton;
+
+      if (strcmp (button, "menu") == 0)
+        gtkbutton = "icon";
+      else if (strcmp (button, "appmenu") == 0)
+        gtkbutton = "menu";
+      else if (strcmp (button, "minimize") == 0)
+        gtkbutton = "minimize";
+      else if (strcmp (button, "maximize") == 0)
+        gtkbutton = "maximize";
+      else if  (strcmp (button, "close") == 0)
+        gtkbutton = "close";
+      else
+        continue;
+
+      if (len)
+        layout[len++] = ',';
+
+      strcpy (layout + len, gtkbutton);
+      len += strlen (gtkbutton);
+    }
+  layout[len] = '\0';
+
+out:
+  if (len_p)
+    *len_p = len;
+}
+
+void
+translate_wm_button_layout_to_gtk (char *layout)
+{
+  char *strp = layout, *left_buttons, *right_buttons;
+  int left_len, right_len = 0;
+
+  left_buttons = strsep (&strp, ":");
+  right_buttons = strp;
+
+  translate_buttons (left_buttons, &left_len);
+  memmove (layout, left_buttons, left_len);
+
+  if (strp == NULL)
+    goto out; /* no ":" in layout */
+
+  layout[left_len++] = ':';
+
+  translate_buttons (right_buttons, &right_len);
+  memmove (layout + left_len, right_buttons, right_len);
+
+out:
+  layout[left_len + right_len] = '\0';
+}
diff --git a/plugins/xsettings/wm-button-layout-translation.h 
b/plugins/xsettings/wm-button-layout-translation.h
new file mode 100644
index 0000000..87210b6
--- /dev/null
+++ b/plugins/xsettings/wm-button-layout-translation.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:  Florian Müllner <fmuellner gnome org>
+ */
+
+#ifndef __WM_BUTTON_LAYOUT_TRANSLATION__
+#define __WM_BUTTON_LAYOUT_TRANSLATION__
+
+void translate_wm_button_layout_to_gtk (char *layout);
+
+#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]