From be944ff2dcc2bbe25152c0736c20d8045a5581e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 3 Jan 2024 03:04:46 +0100 Subject: [PATCH] status/backlight: Fix keyboard backlight infinite loop The logic could enter an infinite loop because it tried to propagate local changes to g-s-d that were caused by signals sent by g-s-d. For example: 1. slider is set to 50 2. Set(50) dbus call is sent 3. slider is set to 51 4. Set(51) dbus call is sent 5. PropertiesChanged arrives due to Set(50) 6. this._sliderItem.value is set to 50 7. notify::value is emitted from this._sliderItem 8. Set(50) dbus call is sent 9. PropertiesChanged arrives due to Set(51) 10. this._sliderItem.value is set to 51 11. notify::value is emitted from this._sliderItem 12. Set(51) dbus call is sent To alleviate this issue, block signal handlers when the local state is changed due to a remote event. Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7111 Part-of: --- js/ui/status/backlight.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/ui/status/backlight.js b/js/ui/status/backlight.js index f35791848..ca901d547 100644 --- a/js/ui/status/backlight.js +++ b/js/ui/status/backlight.js @@ -177,10 +177,10 @@ class KeyboardBrightnessToggle extends QuickMenuToggle { this._discreteItem, 'value', GObject.BindingFlags.SYNC_CREATE); - this._sliderItem.connect('notify::value', + this._sliderItemChangedId = this._sliderItem.connect('notify::value', () => (this._proxy.Brightness = this._sliderItem.value)); - this._discreteItem.connect('notify::value', + this._discreteItemChangedId = this._discreteItem.connect('notify::value', () => (this._proxy.Brightness = this._discreteItem.value)); } @@ -194,6 +194,9 @@ class KeyboardBrightnessToggle extends QuickMenuToggle { this.checked = brightness > 0; const useSlider = this._proxy.Steps >= 4; + this._sliderItem.block_signal_handler(this._sliderItemChangedId); + this._discreteItem.block_signal_handler(this._discreteItemChangedId); + this._sliderItem.set({ visible: useSlider, value: brightness, @@ -201,6 +204,9 @@ class KeyboardBrightnessToggle extends QuickMenuToggle { if (!useSlider) this._discreteItem.nLevels = this._proxy.Steps; + + this._sliderItem.unblock_signal_handler(this._sliderItemChangedId); + this._discreteItem.unblock_signal_handler(this._discreteItemChangedId); } });