Fix issue with cursor appearing under menus

This commit is contained in:
wheaney 2024-04-09 15:14:21 -07:00
parent 8cb73e3a43
commit fb01689871
2 changed files with 46 additions and 21 deletions

View File

@ -1,5 +1,3 @@
import Clutter from 'gi://Clutter'; import Clutter from 'gi://Clutter';
import GLib from 'gi://GLib'; import GLib from 'gi://GLib';
import Meta from 'gi://Meta'; import Meta from 'gi://Meta';
@ -23,6 +21,7 @@ export class CursorManager {
this._cursorActor = null; this._cursorActor = null;
this._cursorWatcher = null; this._cursorWatcher = null;
this._cursorSeat = null; this._cursorSeat = null;
// Set/destroyed by _startCloningMouse / _stopCloningMouse // Set/destroyed by _startCloningMouse / _stopCloningMouse
this._cursorWatch = null; this._cursorWatch = null;
this._cursorChangedConnection = null; this._cursorChangedConnection = null;
@ -64,9 +63,18 @@ export class CursorManager {
} }
stopCloning() { stopCloning() {
this._stopCloningShowMouse(); if (!this._cursorWantedVisible) {
this._stopCloningMouse();
}
} }
// After this:
// * real cursor is disabled
// * cloning is "on"
// * cloned cursor not visible, but ready for _startCloningMouse to make it visible
//
// okay if _startCloningMouse is not immediately called since set_pointer_visible is bound to our replacement function
// and will trigger _startCloningMouse when the cursor should be shown
_enableCloningMouse() { _enableCloningMouse() {
this._cursorTracker = Meta.CursorTracker.get_for_display(global.display); this._cursorTracker = Meta.CursorTracker.get_for_display(global.display);
this._cursorWantedVisible = this._cursorTracker.get_pointer_visible(); this._cursorWantedVisible = this._cursorTracker.get_pointer_visible();
@ -85,10 +93,16 @@ export class CursorManager {
this._cursorSeat = Clutter.get_default_backend().get_default_seat(); this._cursorSeat = Clutter.get_default_backend().get_default_seat();
} }
// After this:
// * real cursor enabled, manages its own visibility
// * cloning is "off"
// * no cloned cursor
//
// completely reverts _enableCloningMouse
_disableCloningMouse() { _disableCloningMouse() {
this._cursorTrackerSetPointerVisibleBound(this._cursorWantedVisible); this._stopCloningMouse();
this._stopCloningShowMouse();
Meta.CursorTracker.prototype.set_pointer_visible = this._cursorTrackerSetPointerVisible; Meta.CursorTracker.prototype.set_pointer_visible = this._cursorTrackerSetPointerVisible;
this._cursorTracker.set_pointer_visible(this._cursorWantedVisible);
this._cursorWantedVisible = null; this._cursorWantedVisible = null;
this._cursorTracker = null; this._cursorTracker = null;
@ -100,6 +114,8 @@ export class CursorManager {
this._cursorSeat = null; this._cursorSeat = null;
} }
// bound to Meta.CursorTracker.prototype.set_pointer_visible when cloning is "on"
// original function available in this._cursorTrackerSetPointerVisibleBound
_cursorTrackerSetPointerVisibleReplacement(visible) { _cursorTrackerSetPointerVisibleReplacement(visible) {
this._cursorWantedVisible = visible; this._cursorWantedVisible = visible;
if (visible) { if (visible) {
@ -109,6 +125,13 @@ export class CursorManager {
} }
} }
// After this:
// * real cursor is hidden
// * cloning is "on"
// * clone cursor is visible
//
// add the clone cursor actor, watch for pointer movement and cursor changes, reflect them in the cloned cursor
// prereqs: setup in _enableCloningMouse, _cursorWantedVisible is true
_startCloningMouse() { _startCloningMouse() {
if (this._cursorWatch == null) { if (this._cursorWatch == null) {
this._mainActor.add_actor(this._cursorActor); this._mainActor.add_actor(this._cursorActor);
@ -129,19 +152,12 @@ export class CursorManager {
} }
} }
_stopCloningShowMouse() { // After this:
this._stopCloningMouse(); // * real cursor is hidden
this._cursorTrackerSetPointerVisibleBound(this._cursorWantedVisible); // * cloning is "on"
// * cloned cursor not visible, but ready for _startCloningMouse to make it visible
if (this._cursorTracker.set_keep_focus_while_hidden) { //
this._cursorTracker.set_keep_focus_while_hidden(false); // completely reverts _startCloningMouse
}
if (this._cursorSeat.is_unfocus_inhibited()) {
this._cursorSeat.uninhibit_unfocus();
}
}
_stopCloningMouse() { _stopCloningMouse() {
if (this._cursorWatch != null) { if (this._cursorWatch != null) {
this._cursorWatch.remove(); this._cursorWatch.remove();
@ -155,6 +171,14 @@ export class CursorManager {
this._mainActor.remove_actor(this._cursorActor); this._mainActor.remove_actor(this._cursorActor);
} }
if (this._cursorTracker.set_keep_focus_while_hidden) {
this._cursorTracker.set_keep_focus_while_hidden(false);
}
if (this._cursorSeat.is_unfocus_inhibited()) {
this._cursorSeat.uninhibit_unfocus();
}
} }
_updateMousePosition(x, y) { _updateMousePosition(x, y) {
@ -175,6 +199,7 @@ export class CursorManager {
translation_x: -xHot, translation_x: -xHot,
translation_y: -yHot, translation_y: -yHot,
}); });
this._mainActor.set_child_above_sibling(this._cursorActor, null);
this._cursorTrackerSetPointerVisibleBound(false); this._cursorTrackerSetPointerVisibleBound(false);
} }
} }

View File

@ -242,7 +242,7 @@ export default class BreezyDesktopExtension extends Extension {
} }
_effect_enable() { _effect_enable() {
if (!this._cursorManager) this._cursorManager = new CursorManager(Main.uiGroup); if (!this._cursorManager) this._cursorManager = new CursorManager(Main.layoutManager.uiGroup);
this._cursorManager.enable(); this._cursorManager.enable();
if (!this._overlay) { if (!this._overlay) {
@ -255,7 +255,7 @@ export default class BreezyDesktopExtension extends Extension {
this._overlay.set_size(this._targetMonitor.width, this._targetMonitor.height); this._overlay.set_size(this._targetMonitor.width, this._targetMonitor.height);
const overlayContent = new Clutter.Actor({clip_to_allocation: true}); const overlayContent = new Clutter.Actor({clip_to_allocation: true});
const uiClone = new Clutter.Clone({ source: Main.uiGroup, clip_to_allocation: true }); const uiClone = new Clutter.Clone({ source: Main.layoutManager.uiGroup, clip_to_allocation: true });
overlayContent.add_actor(uiClone); overlayContent.add_actor(uiClone);
this._overlay.set_child(overlayContent); this._overlay.set_child(overlayContent);
@ -337,7 +337,7 @@ export default class BreezyDesktopExtension extends Extension {
GLib.source_remove(this._running_poller_id); GLib.source_remove(this._running_poller_id);
} else { } else {
Meta.enable_unredirect_for_display(global.display); Meta.enable_unredirect_for_display(global.display);
global.stage.remove_effect_by_name('xr-desktop'); this._overlay.remove_effect_by_name('xr-desktop');
this._cursorManager.disable(); this._cursorManager.disable();
this._cursorManager = null; this._cursorManager = null;
} }