[gnome-control-center] region: Use a GtkPopover instead of GtkDialog for input options



commit a86cf1eca2734b5ce8b250a7b16db3328945cf42
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Sep 7 14:28:31 2018 +1200

    region: Use a GtkPopover instead of GtkDialog for input options
    
    As per design:
    https://wiki.gnome.org/Design/SystemSettings/RegionAndLanguage

 panels/region/cc-input-options.c   | 173 -------------------------------
 panels/region/cc-input-options.h   |  36 -------
 panels/region/cc-region-panel.c    | 105 ++++++++++++++++---
 panels/region/input-options.ui     | 200 -----------------------------------
 panels/region/meson.build          |   2 -
 panels/region/region.gresource.xml |   1 -
 panels/region/region.ui            | 207 ++++++++++++++++++++++++++++++++++++-
 po/POTFILES.in                     |   1 -
 8 files changed, 296 insertions(+), 429 deletions(-)
---
diff --git a/panels/region/cc-region-panel.c b/panels/region/cc-region-panel.c
index c733592e8..30b1b9d31 100644
--- a/panels/region/cc-region-panel.c
+++ b/panels/region/cc-region-panel.c
@@ -32,7 +32,6 @@
 #include "cc-language-chooser.h"
 #include "cc-format-chooser.h"
 #include "cc-input-chooser.h"
-#include "cc-input-options.h"
 #include "cc-input-row.h"
 
 #include "cc-common-language.h"
@@ -109,6 +108,14 @@ struct _CcRegionPanel {
         GtkWidget *show_layout;
         GtkWidget *restart_button;
         GtkWidget *language_list;
+        GtkWidget *same_source;
+        GtkWidget *per_window_source;
+        GtkWidget *previous_source;
+        GtkWidget *previous_source_label;
+        GtkWidget *next_source;
+        GtkWidget *next_source_label;
+        GtkWidget *alt_next_source;
+        GtkWidget *alt_next_source_label;
 
         GSettings *input_settings;
         GnomeXkbInfo *xkb_info;
@@ -1241,25 +1248,72 @@ show_selected_layout (CcRegionPanel *self)
 }
 
 static void
-options_response (GtkDialog     *options,
-                  gint           response_id,
-                  CcRegionPanel *self)
+update_shortcut_label (GtkWidget   *widget,
+                       const gchar *value)
 {
-        gtk_widget_destroy (GTK_WIDGET (options));
+        g_autofree gchar *text = NULL;
+        guint accel_key;
+        g_autofree guint *keycode = NULL;
+        GdkModifierType mods;
+
+        if (value == NULL || *value == '\0') {
+                gtk_widget_hide (widget);
+                return;
+        }
+
+        gtk_accelerator_parse_with_keycode (value, &accel_key, &keycode, &mods);
+        if (accel_key == 0 && keycode == NULL && mods == 0) {
+                g_warning ("Failed to parse keyboard shortcut: '%s'", value);
+                gtk_widget_hide (widget);
+                return;
+        }
+
+        text = gtk_accelerator_get_label_with_keycode (gtk_widget_get_display (widget), accel_key, *keycode, 
mods);
+        gtk_label_set_text (GTK_LABEL (widget), text);
 }
 
+static void
+update_shortcuts (CcRegionPanel *self)
+{
+        g_auto(GStrv) previous = NULL;
+        g_auto(GStrv) next = NULL;
+        g_autofree gchar *previous_shortcut = NULL;
+        g_autoptr(GSettings) settings = NULL;
+
+        settings = g_settings_new ("org.gnome.desktop.wm.keybindings");
+
+        previous = g_settings_get_strv (settings, "switch-input-source-backward");
+        next = g_settings_get_strv (settings, "switch-input-source");
+
+        previous_shortcut = g_strdup (previous[0]);
+
+        update_shortcut_label (self->previous_source, previous_shortcut);
+        update_shortcut_label (self->next_source, next[0]);
+}
 
 static void
-show_input_options (CcRegionPanel *self)
+update_modifiers_shortcut (CcRegionPanel *self)
 {
-        GtkWidget *toplevel;
-        GtkWidget *options;
+        g_auto(GStrv) options = NULL;
+        gchar **p;
+        g_autoptr(GSettings) settings = NULL;
+        g_autoptr(GnomeXkbInfo) xkb_info = NULL;
+        const gchar *text;
+
+        xkb_info = gnome_xkb_info_new ();
+        settings = g_settings_new ("org.gnome.desktop.input-sources");
+        options = g_settings_get_strv (settings, "xkb-options");
+
+        for (p = options; p && *p; ++p)
+                if (g_str_has_prefix (*p, "grp:"))
+                        break;
 
-        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
-        options = cc_input_options_new (toplevel);
-        g_signal_connect (options, "response",
-                          G_CALLBACK (options_response), self);
-        gtk_window_present (GTK_WINDOW (options));
+        if (p && *p) {
+                text = gnome_xkb_info_description_for_option (xkb_info, "grp", *p);
+                gtk_label_set_text (GTK_LABEL (self->alt_next_source), text);
+        } else {
+                gtk_widget_hide (self->alt_next_source);
+        }
 }
 
 static void
@@ -1298,6 +1352,23 @@ setup_input_section (CcRegionPanel *self)
 
         add_input_sources_from_settings (self);
         update_buttons (self);
+
+        g_object_bind_property (self->previous_source, "visible",
+                                self->previous_source_label, "visible",
+                                G_BINDING_DEFAULT);
+        g_object_bind_property (self->next_source, "visible",
+                                self->next_source_label, "visible",
+                                G_BINDING_DEFAULT);
+
+        g_settings_bind (self->input_settings, "per-window",
+                         self->per_window_source, "active",
+                         G_SETTINGS_BIND_DEFAULT);
+        g_settings_bind (self->input_settings, "per-window",
+                         self->same_source, "active",
+                         G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);
+
+        update_shortcuts (self);
+        update_modifiers_shortcut (self);
 }
 
 static void
@@ -1627,9 +1698,15 @@ cc_region_panel_class_init (CcRegionPanelClass * klass)
         gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, restart_button);
         gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, login_label);
         gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, language_list);
+        gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, same_source);
+        gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, per_window_source);
+        gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, previous_source);
+        gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, previous_source_label);
+        gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, next_source);
+        gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, next_source_label);
+        gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, alt_next_source);
 
         gtk_widget_class_bind_template_callback (widget_class, restart_now);
-        gtk_widget_class_bind_template_callback (widget_class, show_input_options);
         gtk_widget_class_bind_template_callback (widget_class, add_input);
         gtk_widget_class_bind_template_callback (widget_class, remove_selected_input);
         gtk_widget_class_bind_template_callback (widget_class, move_selected_input_up);
diff --git a/panels/region/meson.build b/panels/region/meson.build
index 1ab0019d5..fd1872cf7 100644
--- a/panels/region/meson.build
+++ b/panels/region/meson.build
@@ -22,14 +22,12 @@ sources = files(
   'cc-format-chooser.c',
   'cc-ibus-utils.c',
   'cc-input-chooser.c',
-  'cc-input-options.c',
   'cc-input-row.c',
 )
 
 resource_data = files(
   'cc-format-chooser.ui',
   'input-chooser.ui',
-  'input-options.ui',
   'region.ui'
 )
 
diff --git a/panels/region/region.gresource.xml b/panels/region/region.gresource.xml
index b896bd701..f1072ec1d 100644
--- a/panels/region/region.gresource.xml
+++ b/panels/region/region.gresource.xml
@@ -4,7 +4,6 @@
     <file preprocess="xml-stripblanks">region.ui</file>
     <file preprocess="xml-stripblanks">cc-format-chooser.ui</file>
     <file preprocess="xml-stripblanks">cc-input-row.ui</file>
-    <file preprocess="xml-stripblanks">input-options.ui</file>
     <file preprocess="xml-stripblanks">input-chooser.ui</file>
   </gresource>
 </gresources>
diff --git a/panels/region/region.ui b/panels/region/region.ui
index 53ebb4836..34d7b4989 100644
--- a/panels/region/region.ui
+++ b/panels/region/region.ui
@@ -244,13 +244,13 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkButton" id="options_button">
+                      <object class="GtkMenuButton" id="options_button">
                         <property name="label" translatable="yes">_Options</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
                         <property name="use_underline">True</property>
-                        <signal name="clicked" handler="show_input_options" object="CcRegionPanel" 
swapped="yes"/>
+                        <property name="popover">options_popover</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -549,4 +549,207 @@
       </object>
     </child>
   </template>
+  <object class="GtkPopover" id="options_popover">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">6</property>
+            <property name="margin_end">6</property>
+            <property name="margin_top">6</property>
+            <property name="margin_bottom">6</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_top">6</property>
+                <property name="label" translatable="yes">Input Source Options</property>
+                <property name="margin_bottom">6</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="same_source">
+                <property name="label" translatable="yes">Use the _same source for all windows</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="per_window_source">
+                <property name="label" translatable="yes">Allow _different sources for each window</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">same_source</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_top">12</property>
+                <property name="margin_bottom">6</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Keyboard Shortcuts</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="previous_source_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">Previous source</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">4</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="previous_source">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="hexpand">True</property>
+                <property name="label" translatable="yes">Super+Shift+Space</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">4</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="next_source_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">Next source</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">5</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="next_source">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="hexpand">True</property>
+                <property name="label" translatable="yes">Super+Space</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">5</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="alt_next_source">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="hexpand">True</property>
+                <property name="label" translatable="yes">Left+Right Alt</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">6</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_top">12</property>
+                <property name="wrap">True</property>
+                <property name="max_width_chars">40</property>
+                <property name="label" translatable="yes">These keyboard shortcuts can be changed in the 
keyboard settings</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">7</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 43c542b69..af349d46f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -160,7 +160,6 @@ panels/region/cc-input-chooser.c
 panels/region/cc-region-panel.c
 panels/region/gnome-region-panel.desktop.in.in
 panels/region/input-chooser.ui
-panels/region/input-options.ui
 panels/region/region.ui
 panels/search/cc-search-locations-dialog.c
 panels/search/cc-search-panel.c


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