[gnome-shell] Magnifier: don't listen for focus/tracker events if the magnifier is not active
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] Magnifier: don't listen for focus/tracker events if the magnifier is not active
- Date: Thu, 13 Feb 2014 18:43:53 +0000 (UTC)
commit 3a92aa751fb0517e48e7320159b71196428a7e97
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Thu Feb 13 16:25:24 2014 +0100
Magnifier: don't listen for focus/tracker events if the magnifier is not active
In addition to checking the current settings, check also if the
zoom region is active before registering the event listener.
This way, we avoid DBus traffic for events we're not interested in.
Also, make FocusCaretTracker resilient to multiple register/deregister
calls (which can now happen).
https://bugzilla.gnome.org/show_bug.cgi?id=724305
js/ui/focusCaretTracker.js | 34 ++++++++++++++++++++++++++++------
js/ui/magnifier.js | 29 +++++++++++++++++++++++------
2 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/js/ui/focusCaretTracker.js b/js/ui/focusCaretTracker.js
index 5af8d37..beaf2de 100644
--- a/js/ui/focusCaretTracker.js
+++ b/js/ui/focusCaretTracker.js
@@ -34,7 +34,11 @@ const FocusCaretTracker = new Lang.Class({
_init: function() {
Atspi.init();
Atspi.set_timeout(250, 250);
+
this._atspiListener = Atspi.EventListener.new(Lang.bind(this, this._onChanged));
+
+ this._focusListenerRegistered = false;
+ this._caretListenerRegistered = false;
},
_onChanged: function(event) {
@@ -45,21 +49,39 @@ const FocusCaretTracker = new Lang.Class({
},
registerFocusListener: function() {
- return this._atspiListener.register(STATECHANGED + ':focused') &&
- this._atspiListener.register(STATECHANGED + ':selected');
+ if (this._focusListenerRegistered)
+ return;
+
+ // Ignore the return value, we get an exception if they fail
+ // And they should never fail
+ this._atspiListener.register(STATECHANGED + ':focused');
+ this._atspiListener.register(STATECHANGED + ':selected');
+ this._focusListenerRegistered = true;
},
registerCaretListener: function() {
- return this._atspiListener.register(CARETMOVED);
+ if (this._caretListenerRegistered)
+ return;
+
+ this._atspiListener.register(CARETMOVED);
+ this._caretListenerRegistered = true;
},
deregisterFocusListener: function() {
- return this._atspiListener.deregister(STATECHANGED + ':focused') &&
- this._atspiListener.deregister(STATECHANGED + ':selected');
+ if (!this._focusListenerRegistered)
+ return;
+
+ this._atspiListener.deregister(STATECHANGED + ':focused');
+ this._atspiListener.deregister(STATECHANGED + ':selected');
+ this._focusListenerRegistered = false;
},
deregisterCaretListener: function() {
- return this._atspiListener.deregister(CARETMOVED);
+ if (!this._caretListenerRegistered)
+ return;
+
+ this._atspiListener.deregister(CARETMOVED);
+ this._caretListenerRegistered = false;
}
});
Signals.addSignalMethods(FocusCaretTracker.prototype);
diff --git a/js/ui/magnifier.js b/js/ui/magnifier.js
index b02b114..f64ac3b 100644
--- a/js/ui/magnifier.js
+++ b/js/ui/magnifier.js
@@ -766,6 +766,9 @@ const ZoomRegion = new Lang.Class({
} else {
this._destroyActors();
}
+
+ this._syncCaretTracking();
+ this._syncFocusTracking();
},
/**
@@ -825,10 +828,7 @@ const ZoomRegion = new Lang.Class({
*/
setFocusTrackingMode: function(mode) {
this._focusTrackingMode = mode;
- if (this._focusTrackingMode == GDesktopEnums.MagnifierFocusTrackingMode.NONE)
- this._focusCaretTracker.deregisterFocusListener();
- else
- this._focusCaretTracker.registerFocusListener();
+ this._syncFocusTracking();
},
/**
@@ -837,10 +837,27 @@ const ZoomRegion = new Lang.Class({
*/
setCaretTrackingMode: function(mode) {
this._caretTrackingMode = mode;
- if (this._caretTrackingMode == GDesktopEnums.MagnifierCaretTrackingMode.NONE)
- this._focusCaretTracker.deregisterCaretListener();
+ this._syncCaretTracking();
+ },
+
+ _syncFocusTracking: function() {
+ let enabled = this._focusTrackingMode != GDesktopEnums.MagnifierFocusTrackingMode.NONE &&
+ this.isActive();
+
+ if (enabled)
+ this._focusCaretTracker.registerFocusListener();
else
+ this._focusCaretTracker.deregisterFocusListener();
+ },
+
+ _syncCaretTracking: function() {
+ let enabled = this._caretTrackingMode != GDesktopEnums.MagnifierCaretTrackingMode.NONE &&
+ this.isActive();
+
+ if (enabled)
this._focusCaretTracker.registerCaretListener();
+ else
+ this._focusCaretTracker.deregisterCaretListener();
},
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]