[gnome-control-center] universal-access: Add Cursor Size selection dialogue



commit 922c6588d3ebecc21565d985d22ac8c82c0f0101
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Mar 6 17:28:33 2017 +0100

    universal-access: Add Cursor Size selection dialogue
    
    The dialogue offers the 5 separate cursor sizes that adwaita's cursor
    theme supports, aligned in a row.
    
    The cursor sizes are described in a way that doesn't judge their
    respective sizes, but simply describes them.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=608231

 panels/universal-access/cc-ua-panel.c              |  118 ++++++++++++++++++++
 panels/universal-access/left_ptr_24px.png          |  Bin 0 -> 762 bytes
 panels/universal-access/left_ptr_32px.png          |  Bin 0 -> 1081 bytes
 panels/universal-access/left_ptr_48px.png          |  Bin 0 -> 1766 bytes
 panels/universal-access/left_ptr_64px.png          |  Bin 0 -> 2447 bytes
 panels/universal-access/left_ptr_96px.png          |  Bin 0 -> 3995 bytes
 panels/universal-access/uap.ui                     |  111 ++++++++++++++++++
 .../universal-access.gresource.xml                 |    5 +
 8 files changed, 234 insertions(+), 0 deletions(-)
---
diff --git a/panels/universal-access/cc-ua-panel.c b/panels/universal-access/cc-ua-panel.c
index 88e55e6..1985f77 100644
--- a/panels/universal-access/cc-ua-panel.c
+++ b/panels/universal-access/cc-ua-panel.c
@@ -50,6 +50,7 @@
 #define KEY_ICON_THEME               "icon-theme"
 #define KEY_CURSOR_BLINKING          "cursor-blink"
 #define KEY_CURSOR_BLINKING_TIME     "cursor-blink-time"
+#define KEY_MOUSE_CURSOR_SIZE        "cursor-size"
 
 /* application settings */
 #define APPLICATION_SETTINGS         "org.gnome.desktop.a11y.applications"
@@ -178,6 +179,67 @@ zoom_options_launch (CcUaPanel *self)
                             GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
 }
 
+/* cursor size dialog */
+static void
+cursor_size_toggled (GtkWidget *button,
+                     CcUaPanel *self)
+{
+  CcUaPanelPrivate *priv = self->priv;
+  guint cursor_size;
+
+  if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+    return;
+
+  cursor_size = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "cursor-size"));
+  g_settings_set_int (priv->interface_settings, KEY_MOUSE_CURSOR_SIZE, cursor_size);
+  g_debug ("Setting cursor size to %d", cursor_size);
+}
+
+static void
+cursor_size_setup (CcUaPanel *self)
+{
+  guint cursor_sizes[] = { 24, 32, 48, 64, 96 };
+  guint current_cursor_size, i;
+  CcUaPanelPrivate *priv = self->priv;
+  GtkWidget *grid;
+  GtkSizeGroup *size_group;
+  GtkWidget *last_radio_button = NULL;
+
+  grid = WID ("cursor_size_grid");
+  gtk_style_context_add_class (gtk_widget_get_style_context (grid), "linked");
+
+  current_cursor_size = g_settings_get_int (priv->interface_settings,
+                                            KEY_MOUSE_CURSOR_SIZE);
+  size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
+
+  for (i = 0; i < G_N_ELEMENTS(cursor_sizes); i++)
+    {
+      GtkWidget *image, *button;
+      char *cursor_image_name;
+
+      cursor_image_name = g_strdup_printf ("/org/gnome/control-center/universal-access/left_ptr_%dpx.png", 
cursor_sizes[i]);
+      image = gtk_image_new_from_resource (cursor_image_name);
+      g_free (cursor_image_name);
+
+      button = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (last_radio_button));
+      last_radio_button = button;
+      gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
+      g_object_set_data (G_OBJECT (button), "cursor-size", GUINT_TO_POINTER (cursor_sizes[i]));
+
+      gtk_container_add (GTK_CONTAINER (button), image);
+      gtk_grid_attach (GTK_GRID (grid), button, i, 0, 1, 1);
+      gtk_size_group_add_widget (size_group, button);
+
+      g_signal_connect (button, "toggled",
+                        G_CALLBACK (cursor_size_toggled), self);
+
+      if (current_cursor_size == cursor_sizes[i])
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+    }
+
+  gtk_widget_show_all (grid);
+}
+
 /* seeing section */
 
 static gboolean
@@ -271,6 +333,45 @@ on_off_label_mapping_get (GValue   *value,
   return TRUE;
 }
 
+static gboolean
+cursor_size_label_mapping_get (GValue   *value,
+                               GVariant *variant,
+                               gpointer  user_data)
+{
+  char *label;
+  int cursor_size;
+
+  cursor_size = g_variant_get_int32 (variant);
+
+  switch (cursor_size)
+    {
+      case 24:
+        /* translators: the labels will read:
+         * Cursor Size: Default */
+        label = g_strdup (C_("cursor size", "Default"));
+        break;
+      case 32:
+        label = g_strdup (C_("cursor size", "Medium"));
+        break;
+      case 48:
+        label = g_strdup (C_("cursor size", "Large"));
+        break;
+      case 64:
+        label = g_strdup (C_("cursor size", "Larger"));
+        break;
+      case 96:
+        label = g_strdup (C_("cursor size", "Largest"));
+        break;
+      default:
+        label = g_strdup_printf (_("%d pixels"), g_variant_get_int32 (variant));
+        break;
+    }
+
+  g_value_take_string (value, label);
+
+  return TRUE;
+}
+
 static void
 add_separators (GtkListBox *list)
 {
@@ -434,6 +535,23 @@ cc_ua_panel_init_seeing (CcUaPanel *self)
                                 priv->interface_settings,
                                 NULL);
 
+  /* cursor size */
+
+  cursor_size_setup (self);
+
+  g_settings_bind_with_mapping (priv->interface_settings, KEY_MOUSE_CURSOR_SIZE,
+                                WID ("value_cursor_size"),
+                                "label", G_SETTINGS_BIND_GET,
+                                cursor_size_label_mapping_get,
+                                NULL, NULL, NULL);
+
+  dialog = WID ("cursor_size_dialog");
+  priv->toplevels = g_slist_prepend (priv->toplevels, dialog);
+
+  g_object_set_data (G_OBJECT (WID ("row_cursor_size")), "dialog", dialog);
+  g_signal_connect (dialog, "delete-event",
+                    G_CALLBACK (gtk_widget_hide_on_delete), NULL);
+
   /* zoom */
 
   g_settings_bind_with_mapping (priv->application_settings, "screen-magnifier-enabled",
diff --git a/panels/universal-access/left_ptr_24px.png b/panels/universal-access/left_ptr_24px.png
new file mode 100644
index 0000000..46f7760
Binary files /dev/null and b/panels/universal-access/left_ptr_24px.png differ
diff --git a/panels/universal-access/left_ptr_32px.png b/panels/universal-access/left_ptr_32px.png
new file mode 100644
index 0000000..5d9ba96
Binary files /dev/null and b/panels/universal-access/left_ptr_32px.png differ
diff --git a/panels/universal-access/left_ptr_48px.png b/panels/universal-access/left_ptr_48px.png
new file mode 100644
index 0000000..51b1dc2
Binary files /dev/null and b/panels/universal-access/left_ptr_48px.png differ
diff --git a/panels/universal-access/left_ptr_64px.png b/panels/universal-access/left_ptr_64px.png
new file mode 100644
index 0000000..4cf77a4
Binary files /dev/null and b/panels/universal-access/left_ptr_64px.png differ
diff --git a/panels/universal-access/left_ptr_96px.png b/panels/universal-access/left_ptr_96px.png
new file mode 100644
index 0000000..5897a7c
Binary files /dev/null and b/panels/universal-access/left_ptr_96px.png differ
diff --git a/panels/universal-access/uap.ui b/panels/universal-access/uap.ui
index 636b774..ab0c0c4 100644
--- a/panels/universal-access/uap.ui
+++ b/panels/universal-access/uap.ui
@@ -224,6 +224,53 @@
                               </object>
                             </child>
                             <child>
+                              <object class="GtkListBoxRow" id="row_cursor_size">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <child>
+                                  <object class="GtkBox" id="box_cursor_size">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <child>
+                                      <object class="GtkLabel" id="heading_cursor_size">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="margin_start">20</property>
+                                        <property name="margin_end">20</property>
+                                        <property name="margin_top">6</property>
+                                        <property name="margin_bottom">6</property>
+                                        <property name="label" translatable="yes">C_ursor Size</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="xalign">0</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="value_cursor_size">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="margin_start">20</property>
+                                        <property name="margin_end">20</property>
+                                        <property name="margin_top">6</property>
+                                        <property name="margin_bottom">6</property>
+                                        <property name="label">24 pixels</property>
+                                        <property name="xalign">1</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child>
                               <object class="GtkListBoxRow" id="row_zoom">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
@@ -952,6 +999,7 @@
     <widgets>
       <widget name="row_highcontrast"/>
       <widget name="row_large_text"/>
+      <widget name="row_cursor_size"/>
       <widget name="row_zoom"/>
       <widget name="row_screen_reader"/>
       <widget name="row_sound_keys"/>
@@ -962,6 +1010,69 @@
       <widget name="row_click_assist"/>
     </widgets>
   </object>
+  <object class="GtkDialog" id="cursor_size_dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Cursor Size</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox7">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can_focus">False</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="cursor_size_blurb">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">12</property>
+            <property name="margin_end">6</property>
+            <property name="margin_top">6</property>
+            <property name="margin_bottom">6</property>
+            <property name="label" translatable="yes">Cursor size can be combined with zoom to make it 
easier to see the cursor.</property>
+            <property name="wrap">True</property>
+            <property name="max_width_chars">45</property>
+            <property name="xalign">0</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="cursor_size_grid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child>
+      <placeholder/>
+    </child>
+    <child internal-child="headerbar">
+      <object class="GtkHeaderBar">
+        <property name="can_focus">False</property>
+      </object>
+    </child>
+  </object>
   <object class="GtkDialog" id="screen_reader_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
diff --git a/panels/universal-access/universal-access.gresource.xml 
b/panels/universal-access/universal-access.gresource.xml
index bc07b35..d7f2e33 100644
--- a/panels/universal-access/universal-access.gresource.xml
+++ b/panels/universal-access/universal-access.gresource.xml
@@ -3,5 +3,10 @@
   <gresource prefix="/org/gnome/control-center/universal-access">
     <file preprocess="xml-stripblanks">uap.ui</file>
     <file preprocess="xml-stripblanks">zoom-options.ui</file>
+    <file>left_ptr_24px.png</file>
+    <file>left_ptr_32px.png</file>
+    <file>left_ptr_48px.png</file>
+    <file>left_ptr_64px.png</file>
+    <file>left_ptr_96px.png</file>
   </gresource>
 </gresources>


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