[gnome-settings-daemon] software LED indicators
- From: Sergey V. Udaltsov <svu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] software LED indicators
- Date: Mon, 26 Apr 2010 20:57:15 +0000 (UTC)
commit cd494ae66176087931488db823e217b2f49389f8
Author: Sergey V. Udaltsov <svu gnome org>
Date: Mon Apr 26 21:55:33 2010 +0100
software LED indicators
https://bugzilla.gnome.org/show_bug.cgi?id=616380
plugins/keyboard/Makefile.am | 4 +-
plugins/keyboard/caps.off.png | Bin 0 -> 1650 bytes
plugins/keyboard/caps.on.png | Bin 0 -> 1488 bytes
plugins/keyboard/gsd-keyboard-xkb.c | 103 ++++++++++++++++++++++++++++++++++-
plugins/keyboard/num.off.png | Bin 0 -> 1742 bytes
plugins/keyboard/num.on.png | Bin 0 -> 1591 bytes
plugins/keyboard/scroll.off.png | Bin 0 -> 1467 bytes
plugins/keyboard/scroll.on.png | Bin 0 -> 1337 bytes
8 files changed, 105 insertions(+), 2 deletions(-)
---
diff --git a/plugins/keyboard/Makefile.am b/plugins/keyboard/Makefile.am
index 1b7bc3e..98ff5fe 100644
--- a/plugins/keyboard/Makefile.am
+++ b/plugins/keyboard/Makefile.am
@@ -5,7 +5,9 @@ plugin_LTLIBRARIES = \
$(NULL)
uidir = $(pkgdatadir)
-ui_DATA = modmap-dialog.ui show-layout.ui
+ui_DATA = modmap-dialog.ui show-layout.ui \
+ caps.off.png num.off.png scroll.off.png \
+ caps.on.png num.on.png scroll.on.png
libkeyboard_la_SOURCES = \
gsd-keyboard-plugin.h \
diff --git a/plugins/keyboard/caps.off.png b/plugins/keyboard/caps.off.png
new file mode 100755
index 0000000..828cfa8
Binary files /dev/null and b/plugins/keyboard/caps.off.png differ
diff --git a/plugins/keyboard/caps.on.png b/plugins/keyboard/caps.on.png
new file mode 100755
index 0000000..32ea0c9
Binary files /dev/null and b/plugins/keyboard/caps.on.png differ
diff --git a/plugins/keyboard/gsd-keyboard-xkb.c b/plugins/keyboard/gsd-keyboard-xkb.c
index c2109e3..278ab81 100644
--- a/plugins/keyboard/gsd-keyboard-xkb.c
+++ b/plugins/keyboard/gsd-keyboard-xkb.c
@@ -69,12 +69,32 @@ static const char KNOWN_FILES_KEY[] =
static const char DISABLE_INDICATOR_KEY[] =
"/desktop/gnome/peripherals/keyboard/general/disable_indicator";
+static const char DUPLICATE_LEDS_KEY[] =
+ "/desktop/gnome/peripherals/keyboard/general/duplicate_leds";
+
static const char *gdm_keyboard_layout = NULL;
static GtkStatusIcon *icon = NULL;
static GHashTable *preview_dialogs = NULL;
+static Atom caps_lock;
+static Atom num_lock;
+static Atom scroll_lock;
+
+static GtkStatusIcon *indicator_icons[3];
+static const gchar *indicator_on_icon_names[] = {
+ DATADIR "/scroll.on.png",
+ DATADIR "/num.on.png",
+ DATADIR "/caps.on.png"
+};
+
+static const gchar *indicator_off_icon_names[] = {
+ DATADIR "/scroll.off.png",
+ DATADIR "/num.off.png",
+ DATADIR "/caps.off.png"
+};
+
#define noGSDKX
#ifdef GSDKX
@@ -142,6 +162,9 @@ activation_error (void)
static void
apply_desktop_settings (void)
{
+ GConfClient *conf_client;
+ gboolean show_leds;
+ int i;
if (!inited_ok)
return;
@@ -150,6 +173,16 @@ apply_desktop_settings (void)
/* again, probably it would be nice to compare things
before activating them */
gkbd_desktop_config_activate (¤t_config);
+
+ conf_client = gconf_client_get_default ();
+ show_leds =
+ gconf_client_get_bool (conf_client, DUPLICATE_LEDS_KEY, NULL);
+ g_object_unref (conf_client);
+ for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]);
+ --i >= 0;) {
+ gtk_status_icon_set_visible (indicator_icons[i],
+ show_leds);
+ }
}
static void
@@ -848,11 +881,68 @@ gsd_keyboard_new_device (XklEngine * engine)
apply_xkb_settings ();
}
+static void
+gsd_keyboard_update_indicator_icons ()
+{
+ Bool state;
+ int new_state, i;
+ Display *display = GDK_DISPLAY ();
+ XkbGetNamedIndicator (display, caps_lock, NULL, &state,
+ NULL, NULL);
+ new_state = state ? 1 : 0;
+ XkbGetNamedIndicator (display, num_lock, NULL, &state, NULL, NULL);
+ new_state <<= 1;
+ new_state |= (state ? 1 : 0);
+ XkbGetNamedIndicator (display, scroll_lock, NULL, &state,
+ NULL, NULL);
+ new_state <<= 1;
+ new_state |= (state ? 1 : 0);
+ xkl_debug (160, "Indicators state: %d\n", new_state);
+
+
+ for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]);
+ --i >= 0;) {
+ gtk_status_icon_set_from_file (indicator_icons[i],
+ (new_state & (1 << i)) ?
+ indicator_on_icon_names[i] :
+ indicator_off_icon_names
+ [i]);
+ }
+}
+
+static void
+gsd_keyboard_state_changed (XklEngine * engine, XklEngineStateChange type,
+ gint new_group, gboolean restore)
+{
+ xkl_debug (160,
+ "State changed: type %d, new group: %d, restore: %d.\n",
+ type, new_group, restore);
+ if (type == INDICATORS_CHANGED) {
+ gsd_keyboard_update_indicator_icons ();
+ }
+}
+
void
gsd_keyboard_xkb_init (GConfClient * client,
GsdKeyboardManager * kbd_manager)
{
+ int i;
+ Display *display = GDK_DISPLAY ();
gnome_settings_profile_start (NULL);
+
+ caps_lock = XInternAtom (display, "Caps Lock", False);
+ num_lock = XInternAtom (display, "Num Lock", False);
+ scroll_lock = XInternAtom (display, "Scroll Lock", False);
+
+ for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]);
+ --i >= 0;) {
+ indicator_icons[i] =
+ gtk_status_icon_new_from_file (indicator_off_icon_names
+ [i]);
+ }
+
+ gsd_keyboard_update_indicator_icons ();
+
#ifdef GSDKX
xkl_set_debug_level (200);
logfile = fopen ("/tmp/gsdkx.log", "a");
@@ -860,7 +950,7 @@ gsd_keyboard_xkb_init (GConfClient * client,
#endif
manager = kbd_manager;
gnome_settings_profile_start ("xkl_engine_get_instance");
- xkl_engine = xkl_engine_get_instance (GDK_DISPLAY ());
+ xkl_engine = xkl_engine_get_instance (display);
gnome_settings_profile_end ("xkl_engine_get_instance");
if (xkl_engine) {
inited_ok = TRUE;
@@ -899,6 +989,9 @@ gsd_keyboard_xkb_init (GConfClient * client,
g_signal_connect (xkl_engine, "X-new-device",
G_CALLBACK
(gsd_keyboard_new_device), NULL);
+ g_signal_connect (xkl_engine, "X-state-changed",
+ G_CALLBACK
+ (gsd_keyboard_state_changed), NULL);
gnome_settings_profile_start ("xkl_engine_start_listen");
xkl_engine_start_listen (xkl_engine,
@@ -914,6 +1007,7 @@ gsd_keyboard_xkb_init (GConfClient * client,
gnome_settings_profile_end ("apply_xkb_settings");
}
preview_dialogs = g_hash_table_new (g_direct_hash, g_direct_equal);
+
gnome_settings_profile_end (NULL);
}
@@ -921,11 +1015,18 @@ void
gsd_keyboard_xkb_shutdown (void)
{
GConfClient *client;
+ int i;
pa_callback = NULL;
pa_callback_user_data = NULL;
manager = NULL;
+ for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]);
+ --i >= 0;) {
+ g_object_unref (G_OBJECT (indicator_icons[i]));
+ indicator_icons[i] = NULL;
+ }
+
g_hash_table_destroy (preview_dialogs);
if (!inited_ok)
diff --git a/plugins/keyboard/num.off.png b/plugins/keyboard/num.off.png
new file mode 100755
index 0000000..21cac59
Binary files /dev/null and b/plugins/keyboard/num.off.png differ
diff --git a/plugins/keyboard/num.on.png b/plugins/keyboard/num.on.png
new file mode 100755
index 0000000..bd9b9fc
Binary files /dev/null and b/plugins/keyboard/num.on.png differ
diff --git a/plugins/keyboard/scroll.off.png b/plugins/keyboard/scroll.off.png
new file mode 100755
index 0000000..2ff8748
Binary files /dev/null and b/plugins/keyboard/scroll.off.png differ
diff --git a/plugins/keyboard/scroll.on.png b/plugins/keyboard/scroll.on.png
new file mode 100755
index 0000000..77a4794
Binary files /dev/null and b/plugins/keyboard/scroll.on.png differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]