From ff5b65349a9e377d17946ccb29b764f19c3bef7e Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Tue, 06 Nov 2012 18:13:12 +0000
Subject: keyboard: Prevent potential infinite loop

XKB would notify us in the same way if the lockedMods
changed because of a programmatic, or a physical/human change.

This causes us changing the Num-Lock state generating another
event on top of the one we just processed, and might cause
infinite loops and 100% CPU usage.

Instead, we now only apply the settings:
- on startup
- when remember-num-lock is changed to true

https://bugzilla.gnome.org/show_bug.cgi?id=679151

Conflicts:
	plugins/keyboard/gsd-keyboard-manager.c
---
Index: gnome-settings-daemon-3.4.2/plugins/keyboard/gsd-keyboard-manager.c
===================================================================
--- gnome-settings-daemon-3.4.2.orig/plugins/keyboard/gsd-keyboard-manager.c	2012-11-12 16:06:25.000000000 +0100
+++ gnome-settings-daemon-3.4.2/plugins/keyboard/gsd-keyboard-manager.c	2012-11-12 16:07:27.085398939 +0100
@@ -213,6 +213,9 @@
         GsdBellMode      bell_mode;
         gboolean         rnumlock;
 
+        if (g_strcmp0 (key, KEY_NUMLOCK_STATE) == 0)
+                return;
+
         repeat        = g_settings_get_boolean  (settings, KEY_REPEAT);
         click         = g_settings_get_boolean  (settings, KEY_CLICK);
         interval      = _gsd_settings_get_uint  (settings, KEY_INTERVAL);
@@ -224,8 +227,6 @@
         bell_mode = g_settings_get_enum (settings, KEY_BELL_MODE);
         bell_volume   = (bell_mode == GSD_BELL_MODE_ON) ? 50 : 0;
 
-        rnumlock      = g_settings_get_boolean  (settings, "remember-numlock-state");
-
         gdk_error_trap_push ();
         if (repeat) {
                 gboolean rate_set = FALSE;
@@ -255,10 +256,14 @@
                                 KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration,
                                 &kbdcontrol);
 
-        manager->priv->old_state = g_settings_get_enum (manager->priv->settings, KEY_NUMLOCK_STATE);
+	if (g_strcmp0 (key, "remember-numlock-state") == 0 || key == NULL) {
+		rnumlock      = g_settings_get_boolean  (settings, "remember-numlock-state");
+
+		manager->priv->old_state = g_settings_get_enum (manager->priv->settings, KEY_NUMLOCK_STATE);
 
-        if (manager->priv->have_xkb && rnumlock)
-                numlock_set_xkb_state (manager->priv->old_state);
+		if (manager->priv->have_xkb && rnumlock)
+			numlock_set_xkb_state (manager->priv->old_state);
+	}
 
         XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE);
         gdk_error_trap_pop_ignored ();
