[Xfce4-commits] [xfce/xfce4-settings] 01/01: Implement new helper for gtk decorations layout
noreply at xfce.org
noreply at xfce.org
Fri Dec 19 20:48:43 CET 2014
This is an automated email from the git hooks/post-receive script.
olivier pushed a commit to branch master
in repository xfce/xfce4-settings.
commit 6a812b203769fc440267a0486f2775d2405bdc3d
Author: Olivier Fourdan <fourdan at xfce.org>
Date: Fri Dec 19 20:47:03 2014 +0100
Implement new helper for gtk decorations layout
So that CSD windows in GTK/GNOME share the same
layout as xfwm4.
Signed-off-by: Olivier Fourdan <fourdan at xfce.org>
---
xfsettingsd/Makefile.am | 2 +
xfsettingsd/gtk-decorations.c | 157 +++++++++++++++++++++++++++++++++++++++++
xfsettingsd/gtk-decorations.h | 35 +++++++++
xfsettingsd/main.c | 4 ++
xfsettingsd/xsettings.xml | 1 +
5 files changed, 199 insertions(+)
diff --git a/xfsettingsd/Makefile.am b/xfsettingsd/Makefile.am
index 941bdc4..a04fbd2 100644
--- a/xfsettingsd/Makefile.am
+++ b/xfsettingsd/Makefile.am
@@ -21,6 +21,8 @@ xfsettingsd_SOURCES = \
debug.h \
clipboard-manager.c \
clipboard-manager.h \
+ gtk-decorations.c \
+ gtk-decorations.h \
keyboards.c \
keyboards.h \
keyboard-shortcuts.c \
diff --git a/xfsettingsd/gtk-decorations.c b/xfsettingsd/gtk-decorations.c
new file mode 100644
index 0000000..d910f62
--- /dev/null
+++ b/xfsettingsd/gtk-decorations.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2014 Olivier Fourdan <fourdan at xfce.org>
+ *
+ * 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <xfconf/xfconf.h>
+#include <libxfce4util/libxfce4util.h>
+#include "gtk-decorations.h"
+
+#define DEFAULT_LAYOUT "O|HMC"
+
+static void xfce_decorations_helper_finalize (GObject *object);
+static void xfce_decorations_helper_channel_property_changed (XfconfChannel *channel,
+ const gchar *property_name,
+ const GValue *value,
+ XfceDecorationsHelper *helper);
+
+struct _XfceDecorationsHelperClass
+{
+ GObjectClass __parent__;
+};
+
+struct _XfceDecorationsHelper
+{
+ GObject __parent__;
+
+ /* xfconf channel */
+ XfconfChannel *wm_channel;
+ XfconfChannel *xsettings_channel;
+};
+
+G_DEFINE_TYPE (XfceDecorationsHelper, xfce_decorations_helper, G_TYPE_OBJECT)
+
+static void
+xfce_decorations_helper_class_init (XfceDecorationsHelperClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = xfce_decorations_helper_finalize;
+}
+
+static const gchar *
+xfce_decorations_button_layout_xlate (char c)
+{
+ switch (c)
+ {
+ case 'O':
+ return "menu";
+ break;
+ case 'H':
+ return "minimize";
+ break;
+ case 'M':
+ return "maximize";
+ break;
+ case 'C':
+ return "close";
+ break;
+ case '|':
+ return ":";
+ break;
+ default:
+ return NULL;
+ }
+ return NULL;
+}
+
+static void
+xfce_decorations_set_decoration_layout (XfceDecorationsHelper *helper,
+ const gchar *value)
+{
+ GString *join;
+ const gchar *gtk_name;
+ gchar *gtk_decoration_layout;
+ gboolean add_comma;
+ int len, i;
+
+ add_comma = FALSE;
+ len = strlen (value);
+ join = g_string_new (NULL);
+ for (i = 0; i < len; i++)
+ {
+ gtk_name = xfce_decorations_button_layout_xlate(value[i]);
+ if (gtk_name)
+ {
+ if (add_comma && value[i] != '|')
+ join = g_string_append (join, ",");
+ join = g_string_append (join, gtk_name);
+ add_comma = (value[i] != '|');
+ }
+ }
+
+ gtk_decoration_layout = g_string_free (join, FALSE);
+ xfconf_channel_set_string (helper->xsettings_channel,
+ "/Gtk/DecorationLayout", gtk_decoration_layout);
+ g_free (gtk_decoration_layout);
+}
+
+static void
+xfce_decorations_helper_channel_property_changed (XfconfChannel *channel,
+ const gchar *property_name,
+ const GValue *value,
+ XfceDecorationsHelper *helper)
+{
+ if (strcmp (property_name, "/general/button_layout") == 0)
+ {
+ xfce_decorations_set_decoration_layout (helper, g_value_get_string (value));
+ }
+}
+
+static void
+xfce_decorations_helper_init (XfceDecorationsHelper *helper)
+{
+ const gchar *layout;
+
+ helper->wm_channel = xfconf_channel_get ("xfwm4");
+ helper->xsettings_channel = xfconf_channel_get ("xsettings");
+
+ layout = xfconf_channel_get_string (helper->wm_channel,
+ "/general/button_layout", DEFAULT_LAYOUT);
+ xfce_decorations_set_decoration_layout (helper, layout);
+
+ /* monitor WM channel changes */
+ g_signal_connect (G_OBJECT (helper->wm_channel), "property-changed",
+ G_CALLBACK (xfce_decorations_helper_channel_property_changed), helper);
+}
+
+static void
+xfce_decorations_helper_finalize (GObject *object)
+{
+ XfceDecorationsHelper *helper = XFCE_DECORATIONS_HELPER (object);
+
+ (*G_OBJECT_CLASS (xfce_decorations_helper_parent_class)->finalize) (object);
+}
+
diff --git a/xfsettingsd/gtk-decorations.h b/xfsettingsd/gtk-decorations.h
new file mode 100644
index 0000000..a631570
--- /dev/null
+++ b/xfsettingsd/gtk-decorations.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014 Olivier Fourdan <fourdan at xfce.org>
+ *
+ * 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef __GTK_DECORATIONS_H__
+#define __GTK_DECORATIONS_H__
+
+typedef struct _XfceDecorationsHelperClass XfceDecorationsHelperClass;
+typedef struct _XfceDecorationsHelper XfceDecorationsHelper;
+
+#define XFCE_TYPE_DECORATIONS_HELPER (xfce_decorations_helper_get_type ())
+#define XFCE_DECORATIONS_HELPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_DECORATIONS_HELPER, XfceDecorationsHelper))
+#define XFCE_DECORATIONS_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_DECORATIONS_HELPER, XfceDecorationsHelperClass))
+#define XFCE_IS_DECORATIONS_HELPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_DECORATIONS_HELPER))
+#define XFCE_IS_DECORATIONS_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_DECORATIONS_HELPER))
+#define XFCE_DECORATIONS_HELPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_DECORATIONS_HELPER, XfceDecorationsHelperClass))
+
+GType xfce_decorations_helper_get_type (void) G_GNUC_CONST;
+
+#endif /* !__GTK_DECORATIONS_H__ */
diff --git a/xfsettingsd/main.c b/xfsettingsd/main.c
index d34a2cc..388a757 100644
--- a/xfsettingsd/main.c
+++ b/xfsettingsd/main.c
@@ -57,6 +57,7 @@
#include "keyboard-shortcuts.h"
#include "workspaces.h"
#include "clipboard-manager.h"
+#include "gtk-decorations.h"
#include "xsettings.h"
#ifdef HAVE_XRANDR
@@ -159,6 +160,7 @@ main (gint argc, gchar **argv)
GObject *accessibility_helper;
GObject *shortcuts_helper;
GObject *keyboard_layout_helper;
+ GObject *gtk_decorations_helper;
GObject *xsettings_helper;
GObject *clipboard_daemon = NULL;
#ifdef HAVE_XRANDR
@@ -298,6 +300,7 @@ main (gint argc, gchar **argv)
shortcuts_helper = g_object_new (XFCE_TYPE_KEYBOARD_SHORTCUTS_HELPER, NULL);
keyboard_layout_helper = g_object_new (XFCE_TYPE_KEYBOARD_LAYOUT_HELPER, NULL);
workspaces_helper = g_object_new (XFCE_TYPE_WORKSPACES_HELPER, NULL);
+ gtk_decorations_helper = g_object_new (XFCE_TYPE_DECORATIONS_HELPER, NULL);
if (g_getenv ("XFSETTINGSD_NO_CLIPBOARD") == NULL)
{
@@ -339,6 +342,7 @@ main (gint argc, gchar **argv)
g_object_unref (G_OBJECT (shortcuts_helper));
g_object_unref (G_OBJECT (keyboard_layout_helper));
g_object_unref (G_OBJECT (workspaces_helper));
+ g_object_unref (G_OBJECT (gtk_decorations_helper));
if (G_LIKELY (clipboard_daemon != NULL))
{
diff --git a/xfsettingsd/xsettings.xml b/xfsettingsd/xsettings.xml
index ef56c59..8f6ef3b 100644
--- a/xfsettingsd/xsettings.xml
+++ b/xfsettingsd/xsettings.xml
@@ -41,5 +41,6 @@
<property name="MenuBarAccel" type="string" value="F10"/>
<property name="CursorThemeName" type="string" value=""/>
<property name="CursorThemeSize" type="int" value="0"/>
+ <property name="DecorationLayout" type="string" value="menu:minimize,maximize,close"/>
</property>
</channel>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list