[gnome-settings-daemon] wacom: Use the OSD window to edit the tablets' buttons



commit e4df87580db38444a85e72c45d129ce78ff51db6
Author: Joaquim Rocha <jrocha redhat com>
Date:   Fri Jun 21 17:34:06 2013 +0200

    wacom: Use the OSD window to edit the tablets' buttons
    
    This adds a new edition mode to the OSD window and a new widget to edit the tablets' buttons.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701200

 plugins/wacom/Makefile.am                     |   12 +
 plugins/wacom/gsd-wacom-button-editor.c       |  550 +++++++++++++++++++++
 plugins/wacom/gsd-wacom-button-editor.h       |   69 +++
 plugins/wacom/gsd-wacom-key-shortcut-button.c |  635 +++++++++++++++++++++++++
 plugins/wacom/gsd-wacom-key-shortcut-button.h |   70 +++
 plugins/wacom/gsd-wacom-manager.c             |   31 ++-
 plugins/wacom/gsd-wacom-osd-window.c          |  338 +++++++++++---
 plugins/wacom/gsd-wacom-osd-window.h          |    1 +
 8 files changed, 1649 insertions(+), 57 deletions(-)
---
diff --git a/plugins/wacom/Makefile.am b/plugins/wacom/Makefile.am
index 817db69..7ba8164 100644
--- a/plugins/wacom/Makefile.am
+++ b/plugins/wacom/Makefile.am
@@ -6,6 +6,10 @@ libgsdwacom_la_SOURCES =       \
        gsd-wacom-plugin.c      \
        gsd-wacom-manager.h     \
        gsd-wacom-manager.c     \
+       gsd-wacom-key-shortcut-button.h \
+       gsd-wacom-key-shortcut-button.c \
+       gsd-wacom-button-editor.h       \
+       gsd-wacom-button-editor.c       \
        gsd-wacom-osd-window.h  \
        gsd-wacom-osd-window.c  \
        gsd-wacom-oled.h        \
@@ -87,6 +91,10 @@ gsd_test_wacom_SOURCES =     \
        test-wacom.c            \
        gsd-wacom-manager.c     \
        gsd-wacom-manager.h     \
+       gsd-wacom-key-shortcut-button.h \
+       gsd-wacom-key-shortcut-button.c \
+       gsd-wacom-button-editor.h       \
+       gsd-wacom-button-editor.c       \
        gsd-wacom-osd-window.h  \
        gsd-wacom-osd-window.c  \
        gsd-wacom-oled.h        \
@@ -151,6 +159,10 @@ gsd_list_wacom_LDADD =                                             \
 
 gsd_test_wacom_osd_SOURCES =                                   \
        test-osd-window.c                                       \
+       gsd-wacom-key-shortcut-button.h                         \
+       gsd-wacom-key-shortcut-button.c                         \
+       gsd-wacom-button-editor.h                               \
+       gsd-wacom-button-editor.c                               \
        gsd-wacom-osd-window.h                                  \
        gsd-wacom-osd-window.c                                  \
        gsd-wacom-device.c                                      \
diff --git a/plugins/wacom/gsd-wacom-button-editor.c b/plugins/wacom/gsd-wacom-button-editor.c
new file mode 100644
index 0000000..e715cea
--- /dev/null
+++ b/plugins/wacom/gsd-wacom-button-editor.c
@@ -0,0 +1,550 @@
+/*
+ * Copyright © 2013 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Joaquim Rocha <jrocha redhat com>
+ */
+
+#include "config.h"
+#include <glib/gi18n.h>
+#include <math.h>
+#include "gsd-enums.h"
+#include "gsd-wacom-key-shortcut-button.h"
+#include "gsd-wacom-device.h"
+#include "gsd-wacom-button-editor.h"
+
+#define BACK_OPACITY                0.8
+#define DEFAULT_ROW_SPACING         12
+#define ACTION_TYPE_KEY             "action-type"
+#define CUSTOM_ACTION_KEY           "custom-action"
+#define CUSTOM_ELEVATOR_ACTION_KEY  "custom-elevator-action"
+
+#define GSD_WACOM_BUTTON_EDITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), 
GSD_WACOM_BUTTON_EDITOR_TYPE, GsdWacomButtonEditorPrivate))
+
+G_DEFINE_TYPE (GsdWacomButtonEditor, gsd_wacom_button_editor, GTK_TYPE_GRID);
+
+enum {
+  BUTTON_EDITED,
+  DONE_EDITING,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static struct {
+  GsdWacomActionType  action_type;
+  const gchar        *action_name;
+} action_table[] = {
+  { GSD_WACOM_ACTION_TYPE_NONE,           NC_("Wacom action-type", "None")                },
+  { GSD_WACOM_ACTION_TYPE_CUSTOM,         NC_("Wacom action-type", "Send Keystroke")      },
+  { GSD_WACOM_ACTION_TYPE_SWITCH_MONITOR, NC_("Wacom action-type", "Switch Monitor")      },
+  { GSD_WACOM_ACTION_TYPE_HELP,           NC_("Wacom action-type", "Show On-Screen Help") }
+};
+
+#define WACOM_C(x) g_dpgettext2(NULL, "Wacom action-type", x)
+
+enum {
+  ACTION_NAME_COLUMN,
+  ACTION_TYPE_COLUMN,
+  ACTION_N_COLUMNS
+};
+
+struct _GsdWacomButtonEditorPrivate
+{
+  GsdWacomTabletButton *button;
+  GtkDirectionType direction;
+  GtkComboBox *action_combo;
+  GtkWidget *shortcut_button;
+};
+
+static void
+assign_custom_key_to_dir_button (GsdWacomButtonEditor *self,
+                                 gchar                *custom_key)
+{
+  GsdWacomTabletButton *button;
+  GtkDirectionType dir;
+  char *strs[3];
+  char **strv;
+
+  button = self->priv->button;
+  dir = self->priv->direction;
+
+  strs[2] = NULL;
+  strs[0] = strs[1] = "";
+  strv = g_settings_get_strv (button->settings, CUSTOM_ELEVATOR_ACTION_KEY);
+
+  if (g_strv_length (strv) >= 1)
+    strs[0] = strv[0];
+  if (g_strv_length (strv) >= 2)
+    strs[1] = strv[1];
+
+  if (dir == GTK_DIR_UP)
+    strs[0] = custom_key;
+  else
+    strs[1] = custom_key;
+
+  g_settings_set_strv (button->settings,
+                       CUSTOM_ELEVATOR_ACTION_KEY,
+                       (const gchar * const*) strs);
+
+  g_strfreev (strv);
+}
+
+static void
+change_button_action_type (GsdWacomButtonEditor *self,
+                           GsdWacomActionType    type)
+{
+  GsdWacomActionType    current_type;
+  GsdWacomTabletButton *button;
+
+  button = self->priv->button;
+
+  if (button == NULL)
+    return;
+
+  current_type = g_settings_get_enum (self->priv->button->settings, ACTION_TYPE_KEY);
+
+  if (button->type == WACOM_TABLET_BUTTON_TYPE_STRIP ||
+      button->type == WACOM_TABLET_BUTTON_TYPE_RING)
+    {
+      if (type == GSD_WACOM_ACTION_TYPE_NONE)
+        assign_custom_key_to_dir_button (self, "");
+      else if (type == GSD_WACOM_ACTION_TYPE_CUSTOM)
+        {
+          guint           keyval;
+          GdkModifierType mask;
+          char            *custom_key;
+
+          g_object_get (self->priv->shortcut_button,
+                        "key-value", &keyval,
+                        "key-mods", &mask,
+                        NULL);
+
+          mask &= ~GDK_LOCK_MASK;
+
+          custom_key = gtk_accelerator_name (keyval, mask);
+          assign_custom_key_to_dir_button (self, custom_key);
+          g_settings_set_enum (button->settings, ACTION_TYPE_KEY, type);
+
+          g_free (custom_key);
+        }
+    }
+  else if (current_type != type)
+    {
+      g_settings_set_enum (button->settings, ACTION_TYPE_KEY, type);
+    }
+
+  gtk_widget_set_visible (self->priv->shortcut_button,
+                          type == GSD_WACOM_ACTION_TYPE_CUSTOM);
+}
+
+static void
+update_action_combo (GsdWacomButtonEditor *self,
+                     GsdWacomActionType    new_type)
+{
+  GtkTreeIter iter;
+  GsdWacomActionType type;
+  gboolean iter_valid;
+  GtkTreeModel *model;
+
+  model = gtk_combo_box_get_model (self->priv->action_combo);
+
+  for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
+       iter_valid;
+       iter_valid = gtk_tree_model_iter_next (model, &iter))
+    {
+      gtk_tree_model_get (model, &iter,
+                          ACTION_TYPE_COLUMN, &type,
+                          -1);
+
+      if (new_type == type)
+        {
+          gtk_combo_box_set_active_iter (self->priv->action_combo, &iter);
+          break;
+        }
+    }
+}
+
+static void
+reset_shortcut_button_label (GsdWacomButtonEditor *self)
+{
+  gtk_button_set_label (GTK_BUTTON (self->priv->shortcut_button), NC_("keyboard shortcut", "None"));
+}
+
+static void
+on_key_shortcut_cleared (GsdWacomKeyShortcutButton  *shortcut_button,
+                         GsdWacomButtonEditor       *self)
+{
+  update_action_combo (self, GSD_WACOM_ACTION_TYPE_NONE);
+
+  reset_shortcut_button_label (self);
+
+  g_signal_emit (self, signals[BUTTON_EDITED], 0);
+}
+
+static void
+on_key_shortcut_edited (GsdWacomKeyShortcutButton  *shortcut_button,
+                        GsdWacomButtonEditor       *self)
+{
+  GsdWacomTabletButton *button;
+  GtkDirectionType dir;
+  char *custom_key;
+  guint keyval;
+  GdkModifierType mask;
+
+  button = self->priv->button;
+
+  if (button == NULL)
+    return;
+
+  dir = self->priv->direction;
+
+  change_button_action_type (self, GSD_WACOM_ACTION_TYPE_CUSTOM);
+
+  g_object_get (self->priv->shortcut_button,
+                "key-value", &keyval,
+                "key-mods", &mask,
+                NULL);
+
+  if (keyval == 0 && mask == 0)
+    reset_shortcut_button_label (self);
+
+  mask &= ~GDK_LOCK_MASK;
+
+  custom_key = gtk_accelerator_name (keyval, mask);
+
+  if (button->type == WACOM_TABLET_BUTTON_TYPE_STRIP ||
+      button->type == WACOM_TABLET_BUTTON_TYPE_RING)
+    {
+      char *strs[3];
+      char **strv;
+
+      strs[2] = NULL;
+      strs[0] = strs[1] = "";
+      strv = g_settings_get_strv (button->settings, CUSTOM_ELEVATOR_ACTION_KEY);
+
+      if (g_strv_length (strv) >= 1)
+        strs[0] = strv[0];
+      if (g_strv_length (strv) >= 2)
+        strs[1] = strv[1];
+
+      if (dir == GTK_DIR_UP)
+        strs[0] = custom_key;
+      else
+        strs[1] = custom_key;
+
+      g_settings_set_strv (button->settings,
+                           CUSTOM_ELEVATOR_ACTION_KEY,
+                           (const gchar * const*) strs);
+
+      g_strfreev (strv);
+    }
+  else
+    g_settings_set_string (button->settings, CUSTOM_ACTION_KEY, custom_key);
+
+  g_free (custom_key);
+
+  g_signal_emit (self, signals[BUTTON_EDITED], 0);
+}
+
+static void
+on_combo_box_changed (GtkComboBox          *combo,
+                      GsdWacomButtonEditor *self)
+{
+  GsdWacomActionType type;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  if (!gtk_combo_box_get_active_iter (combo, &iter))
+    return;
+
+  model = gtk_combo_box_get_model (combo);
+  gtk_tree_model_get (model, &iter, ACTION_TYPE_COLUMN, &type, -1);
+
+  change_button_action_type (self, type);
+
+  g_signal_emit (self, signals[BUTTON_EDITED], 0);
+}
+
+static void
+on_finish_button_clicked (GtkWidget *button, GsdWacomButtonEditor *self)
+{
+  g_signal_emit (self, signals[DONE_EDITING], 0);
+}
+
+static gboolean
+action_type_is_allowed (GsdWacomTabletButton *button, GsdWacomActionType action_type)
+{
+  if (button->type != WACOM_TABLET_BUTTON_TYPE_STRIP && button->type != WACOM_TABLET_BUTTON_TYPE_RING)
+    return TRUE;
+
+  if (action_type == GSD_WACOM_ACTION_TYPE_NONE || action_type == GSD_WACOM_ACTION_TYPE_CUSTOM)
+    return TRUE;
+
+  return FALSE;
+}
+
+static void
+reset_action_combo_model (GsdWacomButtonEditor *self)
+{
+  GtkListStore *model;
+  GtkTreeIter iter;
+  GsdWacomTabletButton *button;
+  gint i;
+
+  if (self->priv->button == NULL)
+    return;
+
+  button = self->priv->button;
+
+  model = GTK_LIST_STORE (gtk_combo_box_get_model (self->priv->action_combo));
+
+  gtk_list_store_clear (model);
+
+  for (i = 0; i < G_N_ELEMENTS (action_table); i++)
+    {
+      if (!action_type_is_allowed (button, action_table[i].action_type))
+        continue;
+
+      gtk_list_store_append (model, &iter);
+      gtk_list_store_set (model, &iter,
+                          ACTION_NAME_COLUMN, WACOM_C(action_table[i].action_name),
+                          ACTION_TYPE_COLUMN, action_table[i].action_type, -1);
+    }
+}
+
+static void
+update_button (GsdWacomButtonEditor *self)
+{
+  GsdWacomTabletButton *button;
+  GtkDirectionType dir;
+  GsdWacomActionType current_type;
+  gchar *shortcut = NULL;
+  guint keyval;
+  GdkModifierType mask;
+
+  button = self->priv->button;
+
+  if (button == NULL)
+    return;
+
+  dir = self->priv->direction;
+
+  if (button->type == WACOM_TABLET_BUTTON_TYPE_STRIP ||
+      button->type == WACOM_TABLET_BUTTON_TYPE_RING)
+    {
+      char *str;
+      char **strv;
+
+      strv = g_settings_get_strv (button->settings, CUSTOM_ELEVATOR_ACTION_KEY);
+      if (strv != NULL)
+        {
+          if (dir == GTK_DIR_UP)
+            str = strv[0];
+          else
+            str = strv[1];
+
+          shortcut = g_strdup (str);
+          if (g_strcmp0 (shortcut, "") == 0)
+            current_type = GSD_WACOM_ACTION_TYPE_NONE;
+          else
+            current_type = GSD_WACOM_ACTION_TYPE_CUSTOM;
+
+          g_strfreev (strv);
+        }
+
+    }
+  else
+    {
+      current_type = g_settings_get_enum (button->settings, ACTION_TYPE_KEY);
+      if (current_type == GSD_WACOM_ACTION_TYPE_CUSTOM)
+        shortcut = g_settings_get_string (button->settings, CUSTOM_ACTION_KEY);
+    }
+
+  if (shortcut != NULL && current_type == GSD_WACOM_ACTION_TYPE_CUSTOM)
+    {
+      gtk_accelerator_parse (shortcut, &keyval, &mask);
+
+      g_object_set (self->priv->shortcut_button,
+                    "key-value", keyval,
+                    "key-mods", mask,
+                    NULL);
+
+      g_free (shortcut);
+    }
+  else
+    {
+      g_object_set (self->priv->shortcut_button,
+                    "key-value", 0,
+                    "key-mods", 0,
+                    NULL);
+
+      reset_shortcut_button_label (self);
+    }
+
+  update_action_combo (self, current_type);
+}
+
+static void
+gsd_wacom_button_editor_init (GsdWacomButtonEditor *self)
+{
+  gint i;
+  GtkStyleContext *style_context;
+  GtkListStore *model;
+  GtkTreeIter iter;
+  GsdWacomButtonEditorPrivate *priv;
+  GtkCellRenderer *renderer;
+  GtkWidget *action_combo, *shortcut_button, *finish_button;
+
+  style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
+  gtk_style_context_add_class (style_context, "osd");
+
+  priv = GSD_WACOM_BUTTON_EDITOR_GET_PRIVATE (self);
+  self->priv = priv;
+
+  model = gtk_list_store_new (ACTION_N_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
+
+  for (i = 0; i < G_N_ELEMENTS (action_table); i++) {
+    gtk_list_store_append (model, &iter);
+    gtk_list_store_set (model, &iter,
+                        ACTION_NAME_COLUMN, WACOM_C(action_table[i].action_name),
+                        ACTION_TYPE_COLUMN, action_table[i].action_type, -1);
+  }
+
+  action_combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
+  self->priv->action_combo = GTK_COMBO_BOX (action_combo);
+
+  renderer = gtk_cell_renderer_text_new ();
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (action_combo), renderer, TRUE);
+  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (action_combo), renderer,
+                                  "text", ACTION_NAME_COLUMN, NULL);
+
+  g_signal_connect (action_combo, "changed",
+                    G_CALLBACK (on_combo_box_changed),
+                    self);
+
+  gtk_grid_attach (GTK_GRID (self), action_combo, 0, 0, 1, 1);
+
+  shortcut_button = gsd_wacom_key_shortcut_button_new ();
+  /* Accept all shortcuts and disable the cancel key (by default: Escape)
+   * because we might want to assign it too */
+  g_object_set (shortcut_button,
+                "mode", GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_ALL,
+                "cancel-key", 0,
+                NULL);
+  self->priv->shortcut_button = shortcut_button;
+
+  g_signal_connect (shortcut_button, "key-shortcut-cleared",
+                    G_CALLBACK (on_key_shortcut_cleared),
+                    self);
+  g_signal_connect (shortcut_button, "key-shortcut-edited",
+                    G_CALLBACK (on_key_shortcut_edited),
+                    self);
+
+  gtk_grid_attach (GTK_GRID (self), shortcut_button, 1, 0, 1, 1);
+
+  finish_button = gtk_button_new_with_label (_("Done"));
+
+  g_signal_connect (finish_button, "clicked",
+                    G_CALLBACK (on_finish_button_clicked),
+                    self);
+
+  gtk_grid_attach (GTK_GRID (self), finish_button, 2, 0, 1, 1);
+
+  gtk_grid_set_row_spacing (GTK_GRID (self), DEFAULT_ROW_SPACING);
+  gtk_grid_set_column_spacing (GTK_GRID (self), DEFAULT_ROW_SPACING);
+
+  g_object_set (self,
+                "halign", GTK_ALIGN_START,
+                "valign", GTK_ALIGN_START,
+                NULL);
+
+  gtk_widget_show_all (GTK_WIDGET (self));
+  gtk_widget_hide (GTK_WIDGET (self));
+}
+
+static gboolean
+gsd_wacom_button_editor_key_press (GtkWidget   *widget,
+                                   GdkEventKey *event)
+{
+  GTK_WIDGET_CLASS (gsd_wacom_button_editor_parent_class)->key_press_event (widget, event);
+
+  return FALSE;
+}
+
+static void
+gsd_wacom_button_editor_class_init (GsdWacomButtonEditorClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  signals[BUTTON_EDITED] = g_signal_new ("button-edited",
+                                         GSD_WACOM_BUTTON_EDITOR_TYPE,
+                                         G_SIGNAL_RUN_LAST,
+                                         G_STRUCT_OFFSET (GsdWacomButtonEditorClass, button_edited),
+                                         NULL, NULL,
+                                         g_cclosure_marshal_VOID__VOID,
+                                         G_TYPE_NONE, 0);
+
+  signals[DONE_EDITING] = g_signal_new ("done-editing",
+                                         GSD_WACOM_BUTTON_EDITOR_TYPE,
+                                         G_SIGNAL_RUN_LAST,
+                                         G_STRUCT_OFFSET (GsdWacomButtonEditorClass, done_editing),
+                                         NULL, NULL,
+                                         g_cclosure_marshal_VOID__VOID,
+                                         G_TYPE_NONE, 0);
+
+  widget_class->key_press_event = gsd_wacom_button_editor_key_press;
+
+  g_type_class_add_private (klass, sizeof (GsdWacomButtonEditorPrivate));
+}
+
+void
+gsd_wacom_button_editor_set_button (GsdWacomButtonEditor *self,
+                                    GsdWacomTabletButton *button,
+                                    GtkDirectionType      direction)
+{
+  gboolean reset = TRUE;
+
+  g_return_if_fail (GSD_WACOM_IS_BUTTON_EDITOR (self));
+
+  if (self->priv->button && button && self->priv->button->type == button->type)
+    reset = FALSE;
+
+  self->priv->button = button;
+  self->priv->direction = direction;
+
+  if (reset)
+    reset_action_combo_model (self);
+
+  update_button (self);
+}
+
+GsdWacomTabletButton *
+gsd_wacom_button_editor_get_button (GsdWacomButtonEditor *self,
+                                    GtkDirectionType     *direction)
+{
+  g_return_val_if_fail (GSD_WACOM_IS_BUTTON_EDITOR (self), NULL);
+
+  *direction = self->priv->direction;
+
+  return self->priv->button;
+}
+
+GtkWidget *
+gsd_wacom_button_editor_new (void)
+{
+  return g_object_new (GSD_WACOM_BUTTON_EDITOR_TYPE, NULL);
+}
diff --git a/plugins/wacom/gsd-wacom-button-editor.h b/plugins/wacom/gsd-wacom-button-editor.h
new file mode 100644
index 0000000..7a5f8b9
--- /dev/null
+++ b/plugins/wacom/gsd-wacom-button-editor.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2013 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Joaquim Rocha <jrocha redhat com>
+ */
+
+#ifndef __GSD_WACOM_BUTTON_EDITOR_H__
+#define __GSD_WACOM_BUTTON_EDITOR_H__
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GSD_WACOM_BUTTON_EDITOR_TYPE            (gsd_wacom_button_editor_get_type ())
+#define GSD_WACOM_BUTTON_EDITOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GSD_WACOM_BUTTON_EDITOR_TYPE, GsdWacomButtonEditor))
+#define GSD_WACOM_IS_BUTTON_EDITOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GSD_WACOM_BUTTON_EDITOR_TYPE))
+#define GSD_WACOM_BUTTON_EDITOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GSD_WACOM_BUTTON_EDITOR_TYPE, GsdWacomButtonEditorClass))
+#define GSD_WACOM_IS_BUTTON_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GSD_WACOM_BUTTON_EDITOR_TYPE))
+#define GSD_WACOM_BUTTON_EDITOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GSD_WACOM_BUTTON_EDITOR_TYPE, GsdWacomButtonEditorClass))
+
+typedef struct _GsdWacomButtonEditor      GsdWacomButtonEditor;
+typedef struct _GsdWacomButtonEditorClass GsdWacomButtonEditorClass;
+typedef struct _GsdWacomButtonEditorPrivate GsdWacomButtonEditorPrivate;
+
+
+struct _GsdWacomButtonEditor
+{
+  GtkGrid parent_instance;
+
+  /*< private >*/
+  GsdWacomButtonEditorPrivate *priv;
+};
+
+struct _GsdWacomButtonEditorClass
+{
+  GtkGridClass parent_class;
+
+  void (* button_edited) (void);
+  void (* done_editing) (void);
+};
+
+GtkWidget    * gsd_wacom_button_editor_new      (void);
+
+void           gsd_wacom_button_editor_set_button (GsdWacomButtonEditor *self,
+                                                   GsdWacomTabletButton *button,
+                                                   GtkDirectionType      direction);
+
+GsdWacomTabletButton * gsd_wacom_button_editor_get_button (GsdWacomButtonEditor *self,
+                                                           GtkDirectionType     *direction);
+
+
+GType          gsd_wacom_button_editor_get_type (void);
+
+#endif /* __GSD_WACOM_BUTTON_EDITOR_H__ */
diff --git a/plugins/wacom/gsd-wacom-key-shortcut-button.c b/plugins/wacom/gsd-wacom-key-shortcut-button.c
new file mode 100644
index 0000000..63378f6
--- /dev/null
+++ b/plugins/wacom/gsd-wacom-key-shortcut-button.c
@@ -0,0 +1,635 @@
+/*
+ * gsd-wacom-key-shortcut-button.c
+ *
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * Author: Joaquim Rocha <jrocha redhat com>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#include "gsd-wacom-key-shortcut-button.h"
+
+/**
+ * SECTION:gsd-wacom-key-shortcut-button
+ * @short_description: A button which captures and displays a keyboard shortcut
+ * @title: GsdWacomKeyShortcutButton
+ *
+ * GsdWacomKeyShortcutButton is a button which, when clicked, captures a keyboard
+ * shortcut and displays it.
+ * It works in a similar way to #GtkCellRendererAccel but, being a #GtkWidget,
+ * can be added to e.g. containers.
+ */
+
+#define DEFAULT_CANCEL_KEY GDK_KEY_Escape
+#define DEFAULT_CLEAR_KEY  GDK_KEY_BackSpace
+
+#define GSD_WACOM_KEY_SHORTCUT_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), 
GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON, GsdWacomKeyShortcutButtonPrivate))
+
+G_DEFINE_TYPE (GsdWacomKeyShortcutButton, gsd_wacom_key_shortcut_button, GTK_TYPE_BUTTON);
+
+enum {
+  KEY_SHORTCUT_EDITED,
+  KEY_SHORTCUT_CLEARED,
+  LAST_SIGNAL
+};
+
+enum {
+  PROP_0,
+  PROP_SHORTCUT_KEY_VAL,
+  PROP_SHORTCUT_KEY_MODS,
+  PROP_SHORTCUT_MODE,
+  PROP_SHORTCUT_CANCEL_KEY,
+  PROP_SHORTCUT_CLEAR_KEY,
+  N_PROPERTIES
+};
+
+struct _GsdWacomKeyShortcutButtonPrivate
+{
+  gboolean editing_mode;
+
+  GdkDevice *grab_keyboard;
+  GdkDevice *grab_pointer;
+
+  guint keyval;
+  guint keycode;
+  GdkModifierType mods;
+
+  /* Temporary shortcut info used for allowing
+   * modifier-only shortcuts */
+  guint tmp_shortcut_keyval;
+  GdkModifierType tmp_shortcut_mods;
+  guint32 tmp_shortcut_time;
+
+  GsdWacomKeyShortcutButtonMode mode;
+
+  guint cancel_keyval;
+  guint clear_keyval;
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
+
+static void gsd_wacom_key_shortcut_button_changed (GsdWacomKeyShortcutButton *self);
+
+static void
+gsd_wacom_key_shortcut_button_set_property (GObject      *object,
+                                            guint         property_id,
+                                            const GValue *value,
+                                            GParamSpec   *pspec)
+{
+  GsdWacomKeyShortcutButton *self = GSD_WACOM_KEY_SHORTCUT_BUTTON (object);
+  gboolean changed = FALSE;
+
+  switch (property_id)
+    {
+    case PROP_SHORTCUT_KEY_VAL:
+      self->priv->keyval = g_value_get_uint (value);
+      changed = TRUE;
+      break;
+
+    case PROP_SHORTCUT_KEY_MODS:
+      self->priv->mods = g_value_get_uint (value);
+      changed = TRUE;
+      break;
+
+    case PROP_SHORTCUT_MODE:
+      self->priv->mode = g_value_get_enum (value);
+      break;
+
+    case PROP_SHORTCUT_CANCEL_KEY:
+      self->priv->cancel_keyval = g_value_get_uint (value);
+      break;
+
+    case PROP_SHORTCUT_CLEAR_KEY:
+      self->priv->clear_keyval = g_value_get_uint (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+
+  if (changed)
+    gsd_wacom_key_shortcut_button_changed (self);
+}
+
+static void
+gsd_wacom_key_shortcut_button_get_property (GObject      *object,
+                                            guint         property_id,
+                                            GValue       *value,
+                                            GParamSpec   *pspec)
+{
+  GsdWacomKeyShortcutButton *self = GSD_WACOM_KEY_SHORTCUT_BUTTON (object);
+
+  switch (property_id)
+    {
+    case PROP_SHORTCUT_KEY_VAL:
+      g_value_set_uint (value, self->priv->keyval);
+      break;
+
+    case PROP_SHORTCUT_KEY_MODS:
+      g_value_set_uint (value, self->priv->mods);
+      break;
+
+    case PROP_SHORTCUT_MODE:
+      g_value_set_enum (value, self->priv->mode);
+      break;
+
+    case PROP_SHORTCUT_CANCEL_KEY:
+      g_value_set_uint (value, self->priv->cancel_keyval);
+      break;
+
+    case PROP_SHORTCUT_CLEAR_KEY:
+      g_value_set_uint (value, self->priv->clear_keyval);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gsd_wacom_key_shortcut_set_editing_mode (GsdWacomKeyShortcutButton *self,
+                                         GdkEvent                  *event)
+{
+  GsdWacomKeyShortcutButtonPrivate *priv;
+  GdkDevice *kbd = NULL, *pointer = NULL;
+  GdkDeviceManager *device_manager;
+  GdkDisplay *display;
+  GList *devices, *l;
+  GdkWindow *window;
+  guint32 time;
+
+  priv = GSD_WACOM_KEY_SHORTCUT_BUTTON (self)->priv;
+
+  priv->editing_mode = TRUE;
+  gsd_wacom_key_shortcut_button_changed (self);
+
+  window = gtk_widget_get_window (GTK_WIDGET (self));
+
+  g_return_if_fail (window != NULL);
+
+  display = gtk_widget_get_display (GTK_WIDGET (self));
+  device_manager = gdk_display_get_device_manager (display);
+  devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
+
+  for (l = devices; l != NULL; l = l->next)
+    {
+      GdkDevice *current_device;
+
+      current_device = l->data;
+      if (!kbd && gdk_device_get_source (current_device) == GDK_SOURCE_KEYBOARD)
+        kbd = current_device;
+      else if (!pointer && gdk_device_get_source (current_device) == GDK_SOURCE_MOUSE)
+        pointer = current_device;
+
+      if (kbd && pointer)
+        break;
+    }
+  g_list_free (devices);
+
+  time = gdk_event_get_time (event);
+
+  if (gdk_device_grab (kbd, window,
+                       GDK_OWNERSHIP_WINDOW, FALSE,
+                       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+                       NULL, time) != GDK_GRAB_SUCCESS)
+    return;
+
+  if (gdk_device_grab (pointer, window,
+                       GDK_OWNERSHIP_WINDOW, FALSE,
+                       GDK_BUTTON_PRESS_MASK,
+                       NULL, time) != GDK_GRAB_SUCCESS)
+    {
+      gdk_device_ungrab (kbd, time);
+      return;
+    }
+
+  gtk_widget_grab_focus (GTK_WIDGET (self));
+
+  priv->grab_keyboard = kbd;
+  priv->grab_pointer = pointer;
+}
+
+static void
+gsd_wacom_key_shortcut_remove_editing_mode (GsdWacomKeyShortcutButton *self)
+{
+  GsdWacomKeyShortcutButtonPrivate *priv;
+
+  priv = GSD_WACOM_KEY_SHORTCUT_BUTTON (self)->priv;
+
+  priv->editing_mode = FALSE;
+
+  if (priv->grab_keyboard != NULL)
+    {
+      gdk_device_ungrab (priv->grab_keyboard, GDK_CURRENT_TIME);
+      priv->grab_keyboard = NULL;
+    }
+  if (priv->grab_pointer != NULL)
+    {
+      gdk_device_ungrab (priv->grab_pointer, GDK_CURRENT_TIME);
+      priv->grab_pointer = NULL;
+    }
+
+  priv->tmp_shortcut_keyval = 0;
+  priv->tmp_shortcut_mods = 0;
+  priv->tmp_shortcut_time = 0;
+}
+
+static void
+gsd_wacom_key_shortcut_button_changed (GsdWacomKeyShortcutButton *self)
+{
+  gchar *text;
+
+  if (self->priv->editing_mode)
+    {
+      gtk_button_set_label (GTK_BUTTON (self), _("New shortcut…"));
+
+      gtk_widget_set_state_flags (GTK_WIDGET (self),
+                                  GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT,
+                                  FALSE);
+
+      return;
+    }
+
+  if (self->priv->keyval == 0 && self->priv->mods == 0)
+    {
+      gtk_button_set_label (GTK_BUTTON (self), "");
+      return;
+    }
+
+  text = gtk_accelerator_get_label (self->priv->keyval, self->priv->mods);
+  gtk_button_set_label (GTK_BUTTON (self), text);
+  g_free (text);
+}
+
+static void
+gsd_wacom_key_shortcut_button_activate (GtkButton *self)
+{
+  gsd_wacom_key_shortcut_set_editing_mode (GSD_WACOM_KEY_SHORTCUT_BUTTON (self), NULL);
+
+  GTK_BUTTON_CLASS (gsd_wacom_key_shortcut_button_parent_class)->activate (self);
+}
+
+static void
+gsd_wacom_key_shortcut_button_init (GsdWacomKeyShortcutButton *self)
+{
+  self->priv = GSD_WACOM_KEY_SHORTCUT_BUTTON_GET_PRIVATE (self);
+
+  gtk_button_set_relief (GTK_BUTTON (self), GTK_RELIEF_NONE);
+
+  self->priv->cancel_keyval = DEFAULT_CANCEL_KEY;
+  self->priv->clear_keyval = DEFAULT_CLEAR_KEY;
+}
+
+static void
+key_shortcut_finished_editing (GsdWacomKeyShortcutButton *self,
+                               guint32                    time)
+{
+  GsdWacomKeyShortcutButtonPrivate *priv = self->priv;
+
+  gdk_device_ungrab (priv->grab_keyboard, time);
+  gdk_device_ungrab (priv->grab_pointer, time);
+
+  priv->grab_keyboard = NULL;
+  priv->grab_pointer = NULL;
+
+  priv->editing_mode = FALSE;
+
+  gsd_wacom_key_shortcut_remove_editing_mode (self);
+
+  gsd_wacom_key_shortcut_button_changed (self);
+}
+
+static gboolean
+gsd_wacom_key_shortcut_button_key_release (GtkWidget            *widget,
+                                           GdkEventKey          *event)
+{
+  GsdWacomKeyShortcutButton *self = GSD_WACOM_KEY_SHORTCUT_BUTTON (widget);
+  GsdWacomKeyShortcutButtonPrivate *priv = self->priv;
+
+  if (priv->tmp_shortcut_keyval == 0)
+    {
+      GTK_WIDGET_CLASS (gsd_wacom_key_shortcut_button_parent_class)->key_release_event (widget, event);
+
+      return FALSE;
+    }
+
+  priv->keyval = priv->tmp_shortcut_keyval;
+  priv->mods = priv->tmp_shortcut_mods;
+
+  key_shortcut_finished_editing (self, priv->tmp_shortcut_time);
+
+  g_signal_emit (self, signals[KEY_SHORTCUT_EDITED], 0);
+
+  return TRUE;
+}
+
+static gboolean
+gsd_wacom_key_shortcut_button_key_press (GtkWidget   *widget,
+                                         GdkEventKey *event)
+{
+  /* This code is based on the gtk_cell_renderer_accel_start_editing */
+  GsdWacomKeyShortcutButton *self;
+  GsdWacomKeyShortcutButtonPrivate *priv;
+  GdkModifierType mods = 0;
+  guint shortcut_keyval;
+  guint keyval;
+  gboolean edited;
+  gboolean cleared;
+
+  self = GSD_WACOM_KEY_SHORTCUT_BUTTON (widget);
+  priv = self->priv;
+
+  /* GTK and OTHER modes don't allow modifier keyvals */
+  if (event->is_modifier && priv->mode != GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_ALL)
+    return TRUE;
+
+  if (!priv->editing_mode)
+    {
+      GTK_WIDGET_CLASS (gsd_wacom_key_shortcut_button_parent_class)->key_press_event (widget, event);
+
+      return FALSE;
+    }
+
+  edited = FALSE;
+  cleared = FALSE;
+
+  mods = event->state;
+
+  keyval = event->keyval;
+  if (keyval == GDK_KEY_Sys_Req &&
+      (mods & GDK_MOD1_MASK) != 0)
+    {
+      /* HACK: we don't want to use SysRq as a keybinding (but we do
+       * want Alt+Print), so we avoid translation from Alt+Print to SysRq
+       */
+      keyval = GDK_KEY_Print;
+    }
+
+  shortcut_keyval = gdk_keyval_to_lower (keyval);
+
+  if (shortcut_keyval == GDK_KEY_ISO_Left_Tab)
+    shortcut_keyval = GDK_KEY_Tab;
+
+  mods &= gtk_accelerator_get_default_mod_mask ();
+
+  /* Put shift back if it changed the case of the key, not otherwise.
+   */
+  if (shortcut_keyval != keyval)
+    mods |= GDK_SHIFT_MASK;
+
+  if (mods == 0)
+    {
+      if (keyval == priv->cancel_keyval)
+        {
+          /* cancel the edition */
+          goto out;
+        }
+      else if (keyval == priv->clear_keyval)
+        {
+         /* clear the current shortcut */
+         cleared = TRUE;
+         goto out;
+       }
+    }
+
+  priv->tmp_shortcut_keyval = 0;
+  priv->tmp_shortcut_mods = 0;
+  priv->tmp_shortcut_time = 0;
+
+  if (event->is_modifier)
+    {
+      /* when the user presses a non-modifier key, it readily assigns the
+       * shortcut but since we also support modifiers-only shortcuts, we
+       * cannot assign the shortcut right when the user presses a modifier
+       * key because the user might assign e.g. Alt, Alt+Ctrl, Alt+Ctrl+Shift, etc.
+       * So, we keep track of the pressed shortcut's (keyval, mods and time) if
+       * it is a modifier shortcut and assign them when a key-release happens */
+      priv->tmp_shortcut_keyval = shortcut_keyval;
+      priv->tmp_shortcut_mods = mods;
+      priv->tmp_shortcut_time = event->time;
+
+      return TRUE;
+    }
+
+  edited = TRUE;
+
+ out:
+
+  if (edited)
+    {
+      priv->keyval = shortcut_keyval;
+      priv->mods = mods;
+    }
+
+  if (cleared)
+    {
+      priv->keyval = 0;
+      priv->mods = 0;
+    }
+
+  key_shortcut_finished_editing (GSD_WACOM_KEY_SHORTCUT_BUTTON (widget), event->time);
+
+  if (edited)
+    g_signal_emit (self, signals[KEY_SHORTCUT_EDITED], 0);
+  else if (cleared)
+    g_signal_emit (self, signals[KEY_SHORTCUT_CLEARED], 0);
+
+  return TRUE;
+}
+
+static gboolean
+gsd_wacom_key_shortcut_button_button_press (GtkWidget      *widget,
+                                            GdkEventButton *event)
+{
+  GsdWacomKeyShortcutButton *self;
+
+  self = GSD_WACOM_KEY_SHORTCUT_BUTTON (widget);
+
+  if (self->priv->editing_mode)
+    return TRUE;
+
+  gsd_wacom_key_shortcut_set_editing_mode (self, NULL);
+
+  GTK_WIDGET_CLASS (gsd_wacom_key_shortcut_button_parent_class)->button_press_event (widget,
+                                                                              event);
+
+  return TRUE;
+}
+
+static void
+gsd_wacom_key_shortcut_button_unrealize (GtkWidget *widget)
+{
+  GsdWacomKeyShortcutButton *self;
+
+  self = GSD_WACOM_KEY_SHORTCUT_BUTTON (widget);
+
+  gsd_wacom_key_shortcut_remove_editing_mode (self);
+
+  GTK_WIDGET_CLASS (gsd_wacom_key_shortcut_button_parent_class)->unrealize (widget);
+}
+
+static void
+gsd_wacom_key_shortcut_button_class_init (GsdWacomKeyShortcutButtonClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
+
+  gobject_class->set_property = gsd_wacom_key_shortcut_button_set_property;
+  gobject_class->get_property = gsd_wacom_key_shortcut_button_get_property;
+
+  obj_properties[PROP_SHORTCUT_KEY_VAL] =
+    g_param_spec_uint ("key-value",
+                       "The key value",
+                       "The key value of the shortcut currently set",
+                       0,
+                       G_MAXUINT,
+                       0,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  obj_properties[PROP_SHORTCUT_KEY_MODS] =
+    g_param_spec_uint ("key-mods",
+                       "The key modifiers",
+                       "The key modifiers of the shortcut currently set",
+                       0,
+                       G_MAXUINT,
+                       0,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  obj_properties[PROP_SHORTCUT_CANCEL_KEY] =
+    g_param_spec_uint ("cancel-key",
+                       "The cancel key",
+                       "The key which cancels the edition of the shortcut",
+                       0,
+                       G_MAXUINT,
+                       DEFAULT_CANCEL_KEY,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  obj_properties[PROP_SHORTCUT_CLEAR_KEY] =
+    g_param_spec_uint ("clear-key",
+                       "The clear key",
+                       "The key which clears the currently set shortcut",
+                       0,
+                       G_MAXUINT,
+                       DEFAULT_CLEAR_KEY,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  /**
+   * GsdWacomKeyShortcutButton:mode:
+   *
+   * Determines which type of keys are allowed in the captured shortcuts.
+   * %GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_ALL is the same as
+   * %GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_OTHER but allows shortcuts composed of
+   * only modifier keys.
+   */
+  obj_properties[PROP_SHORTCUT_MODE] =
+    g_param_spec_enum ("mode",
+                       "The shortcut mode",
+                       "The mode with which the shortcuts are captured",
+                       GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON_MODE,
+                       GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_OTHER,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class,
+                                     N_PROPERTIES,
+                                     obj_properties);
+
+  widget_class->key_press_event = gsd_wacom_key_shortcut_button_key_press;
+  widget_class->button_press_event = gsd_wacom_key_shortcut_button_button_press;
+  widget_class->key_release_event = gsd_wacom_key_shortcut_button_key_release;
+  widget_class->unrealize = gsd_wacom_key_shortcut_button_unrealize;
+
+  button_class->activate = gsd_wacom_key_shortcut_button_activate;
+
+  /**
+   * GsdWacomKeyShortcutButton::key-shortcut-edited:
+   * @keyshortcutbutton: the #GsdWacomKeyShortcutButton
+   *
+   * Emitted when the key shortcut of the @keyshortcutbutton is edited.
+   *
+   * The new shortcut can be retrieved by using the #GsdWacomKeyShortcutButton:key-value
+   * and #GsdWacomKeyShortcutButton:key-mods properties.
+   */
+  signals[KEY_SHORTCUT_EDITED] = g_signal_new ("key-shortcut-edited",
+                                               GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON,
+                                               G_SIGNAL_RUN_LAST,
+                                               G_STRUCT_OFFSET (GsdWacomKeyShortcutButtonClass,
+                                                                key_shortcut_edited),
+                                               NULL, NULL,
+                                               g_cclosure_marshal_VOID__VOID,
+                                               G_TYPE_NONE, 0);
+
+  /**
+   * GsdWacomKeyShortcutButton::key-shortcut-cleared:
+   * @keyshortcutbutton: the #GsdWacomKeyShortcutButton
+   *
+   * Emitted when the key shortcut of the @keyshortcutbutton is cleared.
+   */
+  signals[KEY_SHORTCUT_CLEARED] = g_signal_new ("key-shortcut-cleared",
+                                                GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON,
+                                                G_SIGNAL_RUN_LAST,
+                                                G_STRUCT_OFFSET (GsdWacomKeyShortcutButtonClass,
+                                                                 key_shortcut_cleared),
+                                                NULL, NULL,
+                                                g_cclosure_marshal_VOID__VOID,
+                                                G_TYPE_NONE, 0);
+
+  g_type_class_add_private (klass, sizeof (GsdWacomKeyShortcutButtonPrivate));
+}
+
+/**
+ * gsd_wacom_key_shortcut_button_new:
+ *
+ * Creates a new #GsdWacomKeyShortcutButton.
+ *
+ * Returns: a new #GsdWacomKeyShortcutButton object.
+ *
+ * Since: 3.10
+ */
+GtkWidget *
+gsd_wacom_key_shortcut_button_new (void)
+{
+  return g_object_new (GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON, NULL);
+}
+
+GType
+gsd_wacom_key_shortcut_button_mode_type (void)
+{
+  static GType enum_type_id = 0;
+  if (G_UNLIKELY (!enum_type_id))
+    {
+      static const GEnumValue values[] =
+        {
+          { GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_OTHER, "OTHER", "other" },
+          { GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_ALL, "ALL", "all" },
+          { 0, NULL, NULL }
+        };
+      enum_type_id = g_enum_register_static ("GsdWacomKeyShortcutButtonMode", values);
+    }
+  return enum_type_id;
+}
diff --git a/plugins/wacom/gsd-wacom-key-shortcut-button.h b/plugins/wacom/gsd-wacom-key-shortcut-button.h
new file mode 100644
index 0000000..720d113
--- /dev/null
+++ b/plugins/wacom/gsd-wacom-key-shortcut-button.h
@@ -0,0 +1,70 @@
+/*
+ * gsd-wacom-key-shortcut-button.h
+ *
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * Author: Joaquim Rocha <jrocha redhat com>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GSD_WACOM_KEY_SHORTCUT_BUTTON_H__
+#define __GSD_WACOM_KEY_SHORTCUT_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON            (gsd_wacom_key_shortcut_button_get_type ())
+#define GSD_WACOM_KEY_SHORTCUT_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON, GsdWacomKeyShortcutButton))
+#define GSD_WACOM_IS_KEY_SHORTCUT_BUTTON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON))
+#define GSD_WACOM_KEY_SHORTCUT_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON, GsdWacomKeyShortcutButtonClass))
+#define GSD_WACOM_IS_KEY_SHORTCUT_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON))
+#define GSD_WACOM_KEY_SHORTCUT_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON, GsdWacomKeyShortcutButtonClass))
+
+typedef struct _GsdWacomKeyShortcutButton        GsdWacomKeyShortcutButton;
+typedef struct _GsdWacomKeyShortcutButtonClass   GsdWacomKeyShortcutButtonClass;
+typedef struct _GsdWacomKeyShortcutButtonPrivate GsdWacomKeyShortcutButtonPrivate;
+
+GType gsd_wacom_key_shortcut_button_mode_type (void) G_GNUC_CONST;
+#define GSD_WACOM_TYPE_KEY_SHORTCUT_BUTTON_MODE (gsd_wacom_key_shortcut_button_mode_type())
+
+typedef enum
+{
+  GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_OTHER,
+  GSD_WACOM_KEY_SHORTCUT_BUTTON_MODE_ALL
+} GsdWacomKeyShortcutButtonMode;
+
+struct _GsdWacomKeyShortcutButton
+{
+  GtkButton parent_instance;
+
+  /*< private >*/
+  GsdWacomKeyShortcutButtonPrivate *priv;
+};
+
+struct _GsdWacomKeyShortcutButtonClass
+{
+  GtkButtonClass parent_class;
+
+  void (* key_shortcut_edited)  (GsdWacomKeyShortcutButton *key_shortcut_button);
+
+  void (* key_shortcut_cleared) (GsdWacomKeyShortcutButton *key_shortcut_button);
+};
+
+GType          gsd_wacom_key_shortcut_button_get_type        (void) G_GNUC_CONST;
+GtkWidget    * gsd_wacom_key_shortcut_button_new             (void);
+
+#endif /* __GSD_WACOM_KEY_SHORTCUT_BUTTON_H__ */
diff --git a/plugins/wacom/gsd-wacom-manager.c b/plugins/wacom/gsd-wacom-manager.c
index 20fd033..abab928 100644
--- a/plugins/wacom/gsd-wacom-manager.c
+++ b/plugins/wacom/gsd-wacom-manager.c
@@ -920,6 +920,13 @@ osd_window_on_key_release_event (GtkWidget   *widget,
                                  GdkEventKey *event,
                                  GsdWacomManager *manager)
 {
+       gboolean editing_mode;
+
+       /* If it's in edition mode, we don't destroy the window */
+       g_object_get (widget, "edition-mode", &editing_mode, NULL);
+
+       if (editing_mode)
+               return FALSE;
 
        if (event->type != GDK_KEY_RELEASE)
                return FALSE;
@@ -936,7 +943,14 @@ osd_window_on_focus_out_event (GtkWidget *widget,
                                GdkEvent  *event,
                                GsdWacomManager *manager)
 {
-       /* If the OSD window loses focus, hide it */
+       GsdWacomOSDWindow *osd_window;
+
+        osd_window = GSD_WACOM_OSD_WINDOW (widget);
+
+       /* If the OSD window loses focus, hide it unless it is in edition mode */
+       if (gsd_wacom_osd_window_get_edition_mode (osd_window))
+               return FALSE;
+
        osd_window_destroy (manager);
 
        return FALSE;
@@ -1372,6 +1386,21 @@ filter_button_events (XEvent          *xevent,
                return GDK_FILTER_REMOVE;
        }
 
+       if (manager->priv->osd_window != NULL) {
+               GsdWacomDevice *osd_window_device;
+               gboolean edition_mode;
+
+               g_object_get (manager->priv->osd_window,
+                              "wacom-device", &osd_window_device,
+                              "edition-mode", &edition_mode, NULL);
+
+               if (osd_window_device && device == osd_window_device && edition_mode) {
+                       osd_window_update_viewable (manager, wbutton, dir, xiev);
+
+                       return GDK_FILTER_REMOVE;
+               }
+       }
+
        /* Update OSD window if shown */
        emulate = osd_window_update_viewable (manager, wbutton, dir, xiev);
 
diff --git a/plugins/wacom/gsd-wacom-osd-window.c b/plugins/wacom/gsd-wacom-osd-window.c
index 8fe8537..03918c5 100644
--- a/plugins/wacom/gsd-wacom-osd-window.c
+++ b/plugins/wacom/gsd-wacom-osd-window.c
@@ -30,6 +30,7 @@
 
 #include "gsd-wacom-osd-window.h"
 #include "gsd-wacom-device.h"
+#include "gsd-wacom-button-editor.h"
 #include "gsd-enums.h"
 
 #define ROTATION_KEY                "rotation"
@@ -39,6 +40,7 @@
 #define RES_PATH                    "/org/gnome/settings-daemon/plugins/wacom/"
 
 #define BACK_OPACITY           0.8
+#define OPACITY_IN_EDITION     "0.5"
 #define INACTIVE_COLOR         "#ededed"
 #define ACTIVE_COLOR           "#729fcf"
 #define STROKE_COLOR           "#000000"
@@ -742,7 +744,8 @@ gsd_wacom_osd_button_draw_label (GsdWacomOSDButton *osd_button,
 enum {
   PROP_OSD_WINDOW_0,
   PROP_OSD_WINDOW_MESSAGE,
-  PROP_OSD_WINDOW_GSD_WACOM_DEVICE
+  PROP_OSD_WINDOW_GSD_WACOM_DEVICE,
+  PROP_OSD_WINDOW_EDITION_MODE
 };
 
 #define GSD_WACOM_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
@@ -758,8 +761,14 @@ struct GsdWacomOSDWindowPrivate
        GdkRectangle              monitor_area;
        GdkRectangle              tablet_area;
        char                     *message;
+       char                     *edition_mode_message;
+       char                     *regular_mode_message;
        GList                    *buttons;
        guint                     cursor_timeout;
+       gboolean                  edition_mode;
+       GsdWacomOSDButton        *current_button;
+       GtkWidget                *editor;
+       GtkWidget                *change_mode_button;
 };
 
 static void     gsd_wacom_osd_window_class_init  (GsdWacomOSDWindowClass *klass);
@@ -768,6 +777,12 @@ static void     gsd_wacom_osd_window_finalize    (GObject                *object
 
 G_DEFINE_TYPE (GsdWacomOSDWindow, gsd_wacom_osd_window, GTK_TYPE_WINDOW)
 
+static gboolean
+osd_window_editing_button (GsdWacomOSDWindow *self)
+{
+       return self->priv->edition_mode && gtk_widget_get_visible (self->priv->editor);
+}
+
 static void
 gsd_wacom_osd_window_update (GsdWacomOSDWindow *osd_window)
 {
@@ -805,23 +820,35 @@ gsd_wacom_osd_window_update (GsdWacomOSDWindow *osd_window)
        buttons_section = g_strdup ("");
        for (l = osd_window->priv->buttons; l != NULL; l = l->next) {
                gchar *color_str;
+               const gchar *css;
                GsdWacomOSDButton *osd_button = l->data;
 
                if (osd_button->priv->visible == FALSE)
                        continue;
 
-               color_str = gsd_wacom_osd_button_get_color_str (osd_button);
-               buttons_section = g_strconcat (buttons_section,
-                                              ".", osd_button->priv->class, " {\n"
-                                              "      stroke:   ",
-                                              color_str,
-                                              " !important;\n"
-                                              "      fill:     ",
-                                              color_str,
-                                              " !important;\n",
-                                              "    }\n",
-                                              NULL);
-               g_free (color_str);
+               if (osd_window_editing_button (osd_window) &&
+                   osd_button != osd_window->priv->current_button) {
+                       css = "%s.%s {\n"
+                               "      opacity: %s\n"
+                               "}\n";
+                       buttons_section = g_strdup_printf (css,
+                                                          buttons_section,
+                                                          osd_button->priv->class,
+                                                          OPACITY_IN_EDITION,
+                                                          NULL);
+               } else {
+                       color_str = gsd_wacom_osd_button_get_color_str (osd_button);
+                       css = "%s.%s {\n"
+                               "      stroke: %s !important;\n"
+                               "      fill: %s !important;\n"
+                               "}\n";
+                       buttons_section = g_strdup_printf (css,
+                                                          buttons_section,
+                                                          osd_button->priv->class,
+                                                          color_str,
+                                                          color_str);
+                       g_free (color_str);
+               }
        }
        replace_string (&css_string, "buttons_section", buttons_section);
        g_free (buttons_section);
@@ -861,7 +888,7 @@ gsd_wacom_osd_window_draw_message (GsdWacomOSDWindow   *osd_window,
        double x;
        double y;
 
-       if (osd_window->priv->message == NULL)
+       if (osd_window->priv->message == NULL || osd_window_editing_button (osd_window))
                return;
 
        layout = pango_layout_new (pango_context);
@@ -1209,6 +1236,15 @@ get_elevator_current_mode (GsdWacomOSDWindow    *osd_window,
        return mode;
 }
 
+static void
+redraw_window (GsdWacomOSDWindow *self)
+{
+       GdkWindow *window;
+
+       window = gtk_widget_get_window (GTK_WIDGET (self));
+       gdk_window_invalidate_rect (window, NULL, FALSE);
+}
+
 static GsdWacomOSDButton *
 gsd_wacom_osd_window_add_button_with_dir (GsdWacomOSDWindow    *osd_window,
                                           GsdWacomTabletButton *tablet_button,
@@ -1274,48 +1310,57 @@ gsd_wacom_osd_window_add_tablet_button (GsdWacomOSDWindow    *osd_window,
        }
 }
 
-static gboolean
-call_device_configuration (GsdWacomDevice *device)
-{
-       gboolean success;
-       gchar *command;
-       const gchar *device_name;
-       GError *error = NULL;
-
-       device_name = gsd_wacom_device_get_name (device);
-       command = g_strdup_printf ("gnome-control-center wacom \"%s\"", device_name);
-       success = g_spawn_command_line_async (command, &error);
-       if (!success) {
-               g_warning ("Failure launching gnome-control-center: %s\n%s",
-                          error->message, command);
-               g_error_free (error);
-       }
-       g_free (command);
+static char *
+get_regular_mode_message (GsdWacomOSDWindow *osd_window)
+{
+       const gchar *name;
+       gchar       *message;
+
+       name = gsd_wacom_device_get_name (osd_window->priv->pad);
+       message = g_strdup_printf ("<big><b>%s</b></big>\n<span foreground=\"%s\">%s</span>",
+                                  name, INACTIVE_COLOR, _("(press any key to exit)"));
+
+       return message;
+}
 
-       return success;
+static char *
+get_edition_mode_message (GsdWacomOSDWindow *osd_window)
+{
+       return g_strdup_printf ("<big><b>%s</b></big>\n<span foreground=\"%s\">%s</span>",
+                               _("Push a button to configure"), INACTIVE_COLOR, _("(Esc to cancel)"));
 }
 
 static void
-on_configure_button_clicked (GtkButton         *button,
-                            GsdWacomOSDWindow *window)
+close_editor (GsdWacomOSDWindow *self)
 {
-       if (call_device_configuration (window->priv->pad))
-               gtk_widget_destroy (GTK_WIDGET (window));
+       if (self->priv->current_button)
+               self->priv->current_button->priv->visible = TRUE;
+
+       gtk_widget_hide (self->priv->editor);
+       self->priv->current_button = NULL;
 }
 
-static GtkWidget *
-create_osd_configure_button (GsdWacomOSDWindow *window)
+static void
+edition_mode_changed (GsdWacomOSDWindow *self)
 {
-       GtkWidget *configure_button;
-       GtkStyleContext *style_context;
+       if (self->priv->edition_mode)
+               gsd_wacom_osd_window_set_message (self, self->priv->edition_mode_message);
+       else {
+               gsd_wacom_osd_window_set_message (self, self->priv->regular_mode_message);
 
-       configure_button = gtk_button_new_with_label (_("Configure device"));
-       g_object_set (configure_button, "halign", GTK_ALIGN_CENTER, NULL);
+               close_editor (self);
+       }
 
-       style_context = gtk_widget_get_style_context (configure_button);
-       gtk_style_context_add_class (style_context, "osd");
+       redraw_window (self);
+}
+
+static void
+on_change_mode_button_clicked (GtkButton         *button,
+                              GsdWacomOSDWindow *window)
+{
+       window->priv->edition_mode = !window->priv->edition_mode;
 
-       return configure_button;
+       edition_mode_changed (window);
 }
 
 static void
@@ -1461,6 +1506,74 @@ gsd_wacom_osd_window_show (GtkWidget *widget)
 }
 
 static void
+on_button_edited (GsdWacomButtonEditor *editor,
+                 GsdWacomOSDWindow    *self)
+{
+       GsdWacomTabletButton *button;
+       GtkDirectionType      dir;
+       char                 *str;
+
+       button = gsd_wacom_button_editor_get_button (editor, &dir);
+
+       if (button == NULL || self->priv->current_button == NULL)
+               return;
+
+       str = get_tablet_button_label (self->priv->pad, button, dir);
+       gsd_wacom_osd_button_set_label (self->priv->current_button, str);
+       g_free (str);
+
+       gsd_wacom_osd_button_redraw (self->priv->current_button);
+}
+
+static void
+on_button_editing_done (GtkWidget         *editor,
+                       GsdWacomOSDWindow *self)
+{
+       close_editor (self);
+       redraw_window (self);
+       grab_keyboard (self);
+}
+
+static gboolean
+on_get_child_position (GtkOverlay        *overlay,
+                      GtkWidget         *widget,
+                      GdkRectangle      *allocation,
+                      GsdWacomOSDWindow *self)
+{
+       GsdWacomOSDButton       *button;
+       GtkRequisition           requisition;
+       GsdWacomTabletButtonPos  position;
+
+       button = self->priv->current_button;
+
+       if (button == NULL)
+               return FALSE;
+
+       gtk_widget_get_preferred_size (widget, NULL, &requisition);
+
+       allocation->x = button->priv->label_x;
+       allocation->y = button->priv->label_y;
+       allocation->width = requisition.width;
+       allocation->height = requisition.height;
+
+       position = get_actual_position (button->priv->position, self->priv->rotation);
+
+       if (position == WACOM_TABLET_BUTTON_POS_LEFT) {
+               allocation->y -= requisition.height / 2.0;
+       } else if (position == WACOM_TABLET_BUTTON_POS_RIGHT) {
+               allocation->x -= requisition.width;
+               allocation->y -= requisition.height / 2.0;
+       } else if (position == WACOM_TABLET_BUTTON_POS_BOTTOM) {
+               allocation->x -= requisition.width / 2.0;
+               allocation->y -= requisition.height;
+       } else if (position == WACOM_TABLET_BUTTON_POS_TOP) {
+               allocation->x -= requisition.width / 2.0;
+       }
+
+       return TRUE;
+}
+
+static void
 gsd_wacom_osd_window_realized (GtkWidget *widget,
                                gpointer   data)
 {
@@ -1564,6 +1677,10 @@ gsd_wacom_osd_window_set_device (GsdWacomOSDWindow *osd_window,
                gsd_wacom_osd_window_add_tablet_button (osd_window, tablet_button);
        }
        g_list_free (list);
+
+       g_clear_pointer (&osd_window->priv->regular_mode_message, g_free);
+       osd_window->priv->regular_mode_message = get_regular_mode_message (osd_window);
+
 }
 
 GsdWacomDevice *
@@ -1606,6 +1723,9 @@ gsd_wacom_osd_window_set_property (GObject        *object,
        case PROP_OSD_WINDOW_MESSAGE:
                gsd_wacom_osd_window_set_message (osd_window, g_value_get_string (value));
                break;
+       case PROP_OSD_WINDOW_EDITION_MODE:
+               osd_window->priv->edition_mode = g_value_get_boolean (value);
+               break;
        case PROP_OSD_WINDOW_GSD_WACOM_DEVICE:
                gsd_wacom_osd_window_set_device (osd_window, g_value_get_object (value));
                break;
@@ -1629,6 +1749,9 @@ gsd_wacom_osd_window_get_property (GObject        *object,
        case PROP_OSD_WINDOW_MESSAGE:
                g_value_set_string (value, osd_window->priv->message);
                break;
+       case PROP_OSD_WINDOW_EDITION_MODE:
+               g_value_set_boolean (value, osd_window->priv->edition_mode);
+               break;
        case PROP_OSD_WINDOW_GSD_WACOM_DEVICE:
                g_value_set_object (value, (GObject*) osd_window->priv->pad);
                break;
@@ -1644,19 +1767,45 @@ gsd_wacom_osd_window_set_active (GsdWacomOSDWindow    *osd_window,
                                 GtkDirectionType      dir,
                                 gboolean              active)
 {
+       GsdWacomOSDWindowPrivate *priv;
        GList     *l;
        gchar     *id;
 
        g_return_if_fail (GSD_IS_WACOM_OSD_WINDOW (osd_window));
        g_return_if_fail (button != NULL);
 
+       priv = osd_window->priv;
+
+       if (priv->current_button)
+               priv->current_button->priv->visible = TRUE;
+
        id = get_tablet_button_id_name (button, dir);
-       for (l = osd_window->priv->buttons; l != NULL; l = l->next) {
+       for (l = priv->buttons; l != NULL; l = l->next) {
                GsdWacomOSDButton *osd_button = l->data;
-               if (MATCH_ID (osd_button, id))
-                       gsd_wacom_osd_button_set_active (osd_button, active);
+               if (MATCH_ID (osd_button, id)) {
+                       if (priv->edition_mode && button->type != WACOM_TABLET_BUTTON_TYPE_HARDCODED)
+                               priv->current_button = osd_button;
+                       else
+                               gsd_wacom_osd_button_set_active (osd_button, active);
+               }
        }
        g_free (id);
+
+       if (priv->edition_mode) {
+               if (priv->current_button)
+                       priv->current_button->priv->visible = FALSE;
+
+               if (button->type == WACOM_TABLET_BUTTON_TYPE_HARDCODED)
+                       return;
+
+               gtk_widget_hide (priv->editor);
+               gsd_wacom_button_editor_set_button (GSD_WACOM_BUTTON_EDITOR (priv->editor), button, dir);
+               gtk_widget_show (priv->editor);
+
+               redraw_window (osd_window);
+
+               return;
+       }
 }
 
 void
@@ -1685,8 +1834,27 @@ gsd_wacom_osd_window_set_mode (GsdWacomOSDWindow    *osd_window,
                        GsdWacomOSDButton *osd_button = l2->data;
                        gboolean           visible = (tablet_button->idx == mode - 1);
 
-                       if (MATCH_ID (osd_button, id_up) || MATCH_ID (osd_button, id_down))
+                       if (MATCH_ID (osd_button, id_up) || MATCH_ID (osd_button, id_down)) {
                                gsd_wacom_osd_button_set_visible (osd_button, visible);
+
+                               if (osd_window->priv->current_button) {
+                                       gchar *current_id;
+                                       GtkDirectionType dir;
+
+                                       gsd_wacom_button_editor_get_button (GSD_WACOM_BUTTON_EDITOR 
(osd_window->priv->editor), &dir);
+                                       current_id = get_tablet_button_id_name (tablet_button, dir);
+
+                                       if (MATCH_ID (osd_button, current_id) && visible) {
+                                               osd_window->priv->current_button = osd_button;
+
+                                               gtk_widget_hide (osd_window->priv->editor);
+                                               gsd_wacom_button_editor_set_button (GSD_WACOM_BUTTON_EDITOR 
(osd_window->priv->editor), tablet_button, dir);
+                                               gtk_widget_show (osd_window->priv->editor);
+                                       }
+                               }
+
+                               redraw_window (osd_window);
+                       }
                }
 
                g_free (id_up);
@@ -1696,6 +1864,14 @@ gsd_wacom_osd_window_set_mode (GsdWacomOSDWindow    *osd_window,
        g_list_free (list);
 }
 
+gboolean
+gsd_wacom_osd_window_get_edition_mode (GsdWacomOSDWindow *osd_window)
+{
+       g_return_val_if_fail (GSD_IS_WACOM_OSD_WINDOW (osd_window), FALSE);
+
+       return osd_window->priv->edition_mode;
+}
+
 GtkWidget *
 gsd_wacom_osd_window_new (GsdWacomDevice       *pad,
                           const gchar          *message)
@@ -1703,7 +1879,8 @@ gsd_wacom_osd_window_new (GsdWacomDevice       *pad,
        GsdWacomOSDWindow *osd_window;
        GdkScreen         *screen;
        GdkVisual         *visual;
-       GtkWidget         *configure_button, *box;
+       GtkWidget         *button, *box, *overlay;
+       GtkStyleContext   *style_context;
 
        osd_window = GSD_WACOM_OSD_WINDOW (g_object_new (GSD_TYPE_WACOM_OSD_WINDOW,
                                                         "type",              GTK_WINDOW_POPUP,
@@ -1725,21 +1902,51 @@ gsd_wacom_osd_window_new (GsdWacomDevice       *pad,
                visual = gdk_screen_get_system_visual (screen);
        gtk_widget_set_visual (GTK_WIDGET (osd_window), visual);
 
+       osd_window->priv->editor = gsd_wacom_button_editor_new ();
+       g_signal_connect (osd_window->priv->editor, "button-edited",
+                         G_CALLBACK (on_button_edited),
+                         osd_window);
+       g_signal_connect (osd_window->priv->editor, "done-editing",
+                         G_CALLBACK (on_button_editing_done),
+                         osd_window);
+
        g_signal_connect (GTK_WIDGET (osd_window), "realize",
                          G_CALLBACK (gsd_wacom_osd_window_realized),
                          NULL);
 
-       configure_button = create_osd_configure_button (osd_window);
+       overlay = gtk_overlay_new ();
+       gtk_container_add (GTK_CONTAINER (osd_window), overlay);
 
        box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-       gtk_container_add (GTK_CONTAINER (osd_window), box);
-       gtk_box_pack_end (GTK_BOX (box), configure_button, FALSE, FALSE, 12);
-       gtk_widget_show_all(box);
+       gtk_container_add (GTK_CONTAINER (overlay), box);
+
+       gtk_overlay_add_overlay (GTK_OVERLAY (overlay), osd_window->priv->editor);
+
+       button = gtk_toggle_button_new_with_label (_("Edit"));
+       g_object_set (button, "halign", GTK_ALIGN_CENTER, NULL);
+
+       style_context = gtk_widget_get_style_context (button);
+       gtk_style_context_add_class (style_context, "osd");
 
-       g_signal_connect (configure_button, "clicked",
-                         G_CALLBACK (on_configure_button_clicked),
+       gtk_box_pack_end (GTK_BOX (box), button, FALSE, FALSE, 12);
+       osd_window->priv->change_mode_button = button;
+
+       gtk_widget_show (overlay);
+       gtk_widget_show (box);
+       gtk_widget_show (osd_window->priv->change_mode_button);
+
+       g_signal_connect (osd_window->priv->change_mode_button, "clicked",
+                         G_CALLBACK (on_change_mode_button_clicked),
+                         osd_window);
+
+       g_signal_connect (overlay, "get-child-position",
+                         G_CALLBACK (on_get_child_position),
                          osd_window);
 
+       osd_window->priv->regular_mode_message = get_regular_mode_message (osd_window);
+
+       edition_mode_changed (osd_window);
+
        return GTK_WIDGET (osd_window);
 }
 
@@ -1774,15 +1981,32 @@ gsd_wacom_osd_window_class_init (GsdWacomOSDWindowClass *klass)
                                                              GSD_TYPE_WACOM_DEVICE,
                                                              G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
 
+       g_object_class_install_property (gobject_class,
+                                        PROP_OSD_WINDOW_EDITION_MODE,
+                                        g_param_spec_boolean ("edition-mode",
+                                                              "Edition mode",
+                                                              "The edition mode of the OSD Window.",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
+
+
        g_type_class_add_private (klass, sizeof (GsdWacomOSDWindowPrivate));
 }
 
 static void
 gsd_wacom_osd_window_init (GsdWacomOSDWindow *osd_window)
 {
+       GtkSettings *settings;
        osd_window->priv = GSD_WACOM_OSD_WINDOW_GET_PRIVATE (osd_window);
        osd_window->priv->cursor_timeout = 0;
        gtk_widget_add_events (GTK_WIDGET (osd_window), GDK_POINTER_MOTION_MASK);
+
+       osd_window->priv->edition_mode = FALSE;
+
+       osd_window->priv->edition_mode_message = get_edition_mode_message (osd_window);
+
+       settings = gtk_settings_get_default ();
+       g_object_set (G_OBJECT (settings), "gtk-application-prefer-dark-theme", TRUE, NULL);
 }
 
 static void
@@ -1801,6 +2025,8 @@ gsd_wacom_osd_window_finalize (GObject *object)
        cursor_timeout_stop (osd_window);
        g_clear_object (&priv->handle);
        g_clear_pointer (&priv->message, g_free);
+       g_clear_pointer (&priv->regular_mode_message, g_free);
+       g_clear_pointer (&priv->edition_mode_message, g_free);
        if (priv->buttons) {
                g_list_free_full (priv->buttons, g_object_unref);
                priv->buttons = NULL;
diff --git a/plugins/wacom/gsd-wacom-osd-window.h b/plugins/wacom/gsd-wacom-osd-window.h
index 616c10e..6bd1fd7 100644
--- a/plugins/wacom/gsd-wacom-osd-window.h
+++ b/plugins/wacom/gsd-wacom-osd-window.h
@@ -58,6 +58,7 @@ void                      gsd_wacom_osd_window_set_active      (GsdWacomOSDWindo
 void                      gsd_wacom_osd_window_set_mode        (GsdWacomOSDWindow        *osd_window,
                                                                 gint                      group_id,
                                                                 gint                      mode);
+gboolean                  gsd_wacom_osd_window_get_edition_mode (GsdWacomOSDWindow        *osd_window);
 GtkWidget *               gsd_wacom_osd_window_new             (GsdWacomDevice           *pad,
                                                                 const gchar              *message);
 


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