[gnome-settings-daemon] media-keys: Add key bindings to switch input sources



commit fc58c347900f906e304591135ca6c13d9950ab4d
Author: Rui Matos <tiagomatos gmail com>
Date:   Tue May 29 15:43:54 2012 +0200

    media-keys: Add key bindings to switch input sources
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676102

 ...ngs-daemon.plugins.media-keys.gschema.xml.in.in |   10 +++++
 plugins/media-keys/gsd-media-keys-manager.c        |   42 ++++++++++++++++++++
 plugins/media-keys/shortcuts-list.h                |    4 ++
 3 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.settings-daemon.plugins.media-keys.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.media-keys.gschema.xml.in.in
index 6a63236..5d8209f 100644
--- a/data/org.gnome.settings-daemon.plugins.media-keys.gschema.xml.in.in
+++ b/data/org.gnome.settings-daemon.plugins.media-keys.gschema.xml.in.in
@@ -175,6 +175,16 @@
       <_summary>Magnifier zoom out</_summary>
       <_description>Binding for the magnifier to zoom out</_description>
     </key>
+    <key name="switch-input-source" type="s">
+      <default>''</default>
+      <_summary>Switch input source</_summary>
+      <_description>Binding to select the next input source</_description>
+    </key>
+    <key name="switch-input-source-backward" type="s">
+      <default>''</default>
+      <_summary>Switch input source backward</_summary>
+      <_description>Binding to select the previous input source</_description>
+    </key>
   </schema>
 
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.plugins.media-keys.custom-keybinding">
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 7694d6c..7578ff2 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -100,6 +100,10 @@ static const gchar introspection_xml[] =
 #define VOLUME_STEP 6           /* percents for one volume button press */
 #define MAX_VOLUME 65536.0
 
+#define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources"
+#define KEY_CURRENT_INPUT_SOURCE "current"
+#define KEY_INPUT_SOURCES        "sources"
+
 #define GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerPrivate))
 
 typedef struct {
@@ -1776,6 +1780,40 @@ do_keyboard_brightness_action (GsdMediaKeysManager *manager,
 }
 
 static void
+do_switch_input_source_action (GsdMediaKeysManager *manager,
+                               MediaKeyType         type)
+{
+        GSettings *settings;
+        GVariant *sources;
+        gint i, n;
+
+        settings = g_settings_new (GNOME_DESKTOP_INPUT_SOURCES_DIR);
+        sources = g_settings_get_value (settings, KEY_INPUT_SOURCES);
+
+        n = g_variant_n_children (sources);
+        if (n < 2)
+                goto out;
+
+        i = g_settings_get_uint (settings, KEY_CURRENT_INPUT_SOURCE);
+
+        if (type == SWITCH_INPUT_SOURCE_KEY)
+                i += 1;
+        else
+                i -= 1;
+
+        if (i < 0)
+                i = n - 1;
+        else if (i >= n)
+                i = 0;
+
+        g_settings_set_uint (settings, KEY_CURRENT_INPUT_SOURCE, i);
+
+ out:
+        g_variant_unref (sources);
+        g_object_unref (settings);
+}
+
+static void
 do_custom_action (GsdMediaKeysManager *manager,
                   MediaKey            *key,
                   gint64               timestamp)
@@ -1938,6 +1976,10 @@ do_action (GsdMediaKeysManager *manager,
         case BATTERY_KEY:
                 do_execute_desktop (manager, "gnome-power-statistics.desktop", timestamp);
                 break;
+        case SWITCH_INPUT_SOURCE_KEY:
+        case SWITCH_INPUT_SOURCE_BACKWARD_KEY:
+                do_switch_input_source_action (manager, type);
+                break;
         /* Note, no default so compiler catches missing keys */
         case CUSTOM_KEY:
                 g_assert_not_reached ();
diff --git a/plugins/media-keys/shortcuts-list.h b/plugins/media-keys/shortcuts-list.h
index 437ed2c..a16d0e7 100644
--- a/plugins/media-keys/shortcuts-list.h
+++ b/plugins/media-keys/shortcuts-list.h
@@ -80,6 +80,8 @@ typedef enum {
         KEYBOARD_BRIGHTNESS_DOWN_KEY,
         KEYBOARD_BRIGHTNESS_TOGGLE_KEY,
         BATTERY_KEY,
+        SWITCH_INPUT_SOURCE_KEY,
+        SWITCH_INPUT_SOURCE_BACKWARD_KEY,
         CUSTOM_KEY
 } MediaKeyType;
 
@@ -146,6 +148,8 @@ static struct {
         { KEYBOARD_BRIGHTNESS_UP_KEY, NULL, "XF86KbdBrightnessUp" },
         { KEYBOARD_BRIGHTNESS_DOWN_KEY, NULL, "XF86KbdBrightnessDown" },
         { KEYBOARD_BRIGHTNESS_TOGGLE_KEY, NULL, "XF86KbdLightOnOff" },
+        { SWITCH_INPUT_SOURCE_KEY, "switch-input-source", NULL },
+        { SWITCH_INPUT_SOURCE_BACKWARD_KEY, "switch-input-source-backward", NULL },
         { BATTERY_KEY, NULL, "XF86Battery" },
 };
 



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