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
This commit is contained in:
parent
6882273aa0
commit
3a92aa751f
@ -34,7 +34,11 @@ const FocusCaretTracker = new Lang.Class({
|
|||||||
_init: function() {
|
_init: function() {
|
||||||
Atspi.init();
|
Atspi.init();
|
||||||
Atspi.set_timeout(250, 250);
|
Atspi.set_timeout(250, 250);
|
||||||
|
|
||||||
this._atspiListener = Atspi.EventListener.new(Lang.bind(this, this._onChanged));
|
this._atspiListener = Atspi.EventListener.new(Lang.bind(this, this._onChanged));
|
||||||
|
|
||||||
|
this._focusListenerRegistered = false;
|
||||||
|
this._caretListenerRegistered = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
_onChanged: function(event) {
|
_onChanged: function(event) {
|
||||||
@ -45,21 +49,39 @@ const FocusCaretTracker = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
registerFocusListener: function() {
|
registerFocusListener: function() {
|
||||||
return this._atspiListener.register(STATECHANGED + ':focused') &&
|
if (this._focusListenerRegistered)
|
||||||
this._atspiListener.register(STATECHANGED + ':selected');
|
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() {
|
registerCaretListener: function() {
|
||||||
return this._atspiListener.register(CARETMOVED);
|
if (this._caretListenerRegistered)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this._atspiListener.register(CARETMOVED);
|
||||||
|
this._caretListenerRegistered = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
deregisterFocusListener: function() {
|
deregisterFocusListener: function() {
|
||||||
return this._atspiListener.deregister(STATECHANGED + ':focused') &&
|
if (!this._focusListenerRegistered)
|
||||||
this._atspiListener.deregister(STATECHANGED + ':selected');
|
return;
|
||||||
|
|
||||||
|
this._atspiListener.deregister(STATECHANGED + ':focused');
|
||||||
|
this._atspiListener.deregister(STATECHANGED + ':selected');
|
||||||
|
this._focusListenerRegistered = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
deregisterCaretListener: function() {
|
deregisterCaretListener: function() {
|
||||||
return this._atspiListener.deregister(CARETMOVED);
|
if (!this._caretListenerRegistered)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this._atspiListener.deregister(CARETMOVED);
|
||||||
|
this._caretListenerRegistered = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Signals.addSignalMethods(FocusCaretTracker.prototype);
|
Signals.addSignalMethods(FocusCaretTracker.prototype);
|
||||||
|
@ -766,6 +766,9 @@ const ZoomRegion = new Lang.Class({
|
|||||||
} else {
|
} else {
|
||||||
this._destroyActors();
|
this._destroyActors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._syncCaretTracking();
|
||||||
|
this._syncFocusTracking();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -825,10 +828,7 @@ const ZoomRegion = new Lang.Class({
|
|||||||
*/
|
*/
|
||||||
setFocusTrackingMode: function(mode) {
|
setFocusTrackingMode: function(mode) {
|
||||||
this._focusTrackingMode = mode;
|
this._focusTrackingMode = mode;
|
||||||
if (this._focusTrackingMode == GDesktopEnums.MagnifierFocusTrackingMode.NONE)
|
this._syncFocusTracking();
|
||||||
this._focusCaretTracker.deregisterFocusListener();
|
|
||||||
else
|
|
||||||
this._focusCaretTracker.registerFocusListener();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -837,10 +837,27 @@ const ZoomRegion = new Lang.Class({
|
|||||||
*/
|
*/
|
||||||
setCaretTrackingMode: function(mode) {
|
setCaretTrackingMode: function(mode) {
|
||||||
this._caretTrackingMode = mode;
|
this._caretTrackingMode = mode;
|
||||||
if (this._caretTrackingMode == GDesktopEnums.MagnifierCaretTrackingMode.NONE)
|
this._syncCaretTracking();
|
||||||
this._focusCaretTracker.deregisterCaretListener();
|
},
|
||||||
|
|
||||||
|
_syncFocusTracking: function() {
|
||||||
|
let enabled = this._focusTrackingMode != GDesktopEnums.MagnifierFocusTrackingMode.NONE &&
|
||||||
|
this.isActive();
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
this._focusCaretTracker.registerFocusListener();
|
||||||
else
|
else
|
||||||
|
this._focusCaretTracker.deregisterFocusListener();
|
||||||
|
},
|
||||||
|
|
||||||
|
_syncCaretTracking: function() {
|
||||||
|
let enabled = this._caretTrackingMode != GDesktopEnums.MagnifierCaretTrackingMode.NONE &&
|
||||||
|
this.isActive();
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
this._focusCaretTracker.registerCaretListener();
|
this._focusCaretTracker.registerCaretListener();
|
||||||
|
else
|
||||||
|
this._focusCaretTracker.deregisterCaretListener();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user