[gnome-builder/wip/chergert/shortcuts: 6/24] shortcuts: make ctrl/shift/alt keys the same size



commit 0c487da0b8d6c5ac3e29ccadbf3db4ce0aa2f0e4
Author: Christian Hergert <christian hergert me>
Date:   Wed Aug 26 17:56:18 2015 -0700

    shortcuts: make ctrl/shift/alt keys the same size

 src/keybindings/gb-accel-label.c      |   29 +++++++++++++++++++++++++++--
 src/keybindings/gb-shortcuts-window.c |    4 ++++
 2 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/src/keybindings/gb-accel-label.c b/src/keybindings/gb-accel-label.c
index 0ded358..89ada5e 100644
--- a/src/keybindings/gb-accel-label.c
+++ b/src/keybindings/gb-accel-label.c
@@ -21,9 +21,10 @@
 
 struct _GbAccelLabel
 {
-  GtkBox  parent_instance;
+  GtkBox        parent_instance;
 
-  gchar  *accelerator;
+  gchar        *accelerator;
+  GtkSizeGroup *size_group;
 };
 
 G_DEFINE_TYPE (GbAccelLabel, gb_accel_label, GTK_TYPE_BOX)
@@ -31,6 +32,7 @@ G_DEFINE_TYPE (GbAccelLabel, gb_accel_label, GTK_TYPE_BOX)
 enum {
   PROP_0,
   PROP_ACCELERATOR,
+  PROP_SIZE_GROUP,
   LAST_PROP
 };
 
@@ -84,6 +86,17 @@ gb_accel_label_rebuild (GbAccelLabel *self)
                             NULL);
       gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (frame));
 
+      /*
+       * FIXME: Check if the item is a modifier.
+       *
+       * If we have a size group, size everything the same except for the
+       * last item. This has the side effect of basically matching all
+       * modifiers together. Not always the case, but simple and easy
+       * hack.
+       */
+      if ((self->size_group != NULL) && (keys [i + 1] != NULL))
+        gtk_size_group_add_widget (self->size_group, GTK_WIDGET (frame));
+
       disp = g_object_new (GTK_TYPE_LABEL,
                            "label", keys [i],
                            "visible", TRUE,
@@ -98,6 +111,7 @@ gb_accel_label_finalize (GObject *object)
   GbAccelLabel *self = (GbAccelLabel *)object;
 
   g_clear_pointer (&self->accelerator, g_free);
+  g_clear_object (&self->size_group);
 
   G_OBJECT_CLASS (gb_accel_label_parent_class)->finalize (object);
 }
@@ -135,6 +149,10 @@ gb_accel_label_set_property (GObject      *object,
       gb_accel_label_set_accelerator (self, g_value_get_string (value));
       break;
 
+    case PROP_SIZE_GROUP:
+      self->size_group = g_value_dup_object (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -156,6 +174,13 @@ gb_accel_label_class_init (GbAccelLabelClass *klass)
                          NULL,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  gParamSpecs [PROP_SIZE_GROUP] =
+    g_param_spec_object ("size-group",
+                         "Size Group",
+                         "Size Group",
+                         GTK_TYPE_SIZE_GROUP,
+                         (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 }
 
diff --git a/src/keybindings/gb-shortcuts-window.c b/src/keybindings/gb-shortcuts-window.c
index 7b399cb..5238097 100644
--- a/src/keybindings/gb-shortcuts-window.c
+++ b/src/keybindings/gb-shortcuts-window.c
@@ -128,6 +128,7 @@ gb_shortcuts_window_build (GbShortcutsWindow *self)
   { \
     GtkBox *column; \
     GtkSizeGroup *size_group; \
+    GtkSizeGroup *mod_key_group; \
     column = g_object_new (GTK_TYPE_BOX, \
                            "orientation", GTK_ORIENTATION_VERTICAL, \
                            "spacing", 22, \
@@ -135,8 +136,10 @@ gb_shortcuts_window_build (GbShortcutsWindow *self)
                            NULL); \
     gtk_container_add (GTK_CONTAINER (page), GTK_WIDGET (column)); \
     size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); \
+    mod_key_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); \
     _groups \
     g_clear_object (&size_group); \
+    g_clear_object (&mod_key_group); \
   }
 #define GROUP(_group_name, _shortcuts) \
   { \
@@ -171,6 +174,7 @@ gb_shortcuts_window_build (GbShortcutsWindow *self)
     gtk_container_add (GTK_CONTAINER (group), GTK_WIDGET (shortcut)); \
     accel = g_object_new (GB_TYPE_ACCEL_LABEL, \
                           "accelerator", _accel, \
+                          "size-group", mod_key_group, \
                           "halign", GTK_ALIGN_START, \
                           "visible", TRUE, \
                           NULL); \


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