Skip to content

Commit

Permalink
Remove ClickOverlay enterMonitor actor implementation. Replace this
Browse files Browse the repository at this point in the history
with simple `PointerWatcher` approach.  Repurpose ClickOverlay to only for for left/right stackoverlay
(left/right window previews).
  • Loading branch information
jtaala committed Jan 14, 2024
1 parent 71c9a03 commit 8b5b711
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 163 deletions.
4 changes: 0 additions & 4 deletions grab.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export class MoveGrab {
this.dispatcher = new Navigator.getActionDispatcher(Clutter.GrabState.POINTER);
this.actor = this.dispatcher.actor;

for (let [monitor, $] of Tiling.spaces.monitors) {
monitor.clickOverlay.deactivate();
}

let metaWindow = this.window;
let actor = metaWindow.get_compositor_private();
let clone = metaWindow.clone;
Expand Down
3 changes: 0 additions & 3 deletions navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,6 @@ class NavigatorClass {
let visible = [];
for (let monitor of Main.layoutManager.monitors) {
visible.push(Tiling.spaces.monitors.get(monitor));
if (monitor === this.monitor)
continue;
monitor.clickOverlay.activate();
}

if (!visible.includes(space) && this.monitor !== this.space.monitor) {
Expand Down
4 changes: 1 addition & 3 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ export function makeScratch(metaWindow) {
}
}

let monitor = Tiling.focusMonitor();
if (monitor.clickOverlay)
monitor.clickOverlay.hide();
Tiling.focusMonitor()?.clickOverlay?.hide();
}

export function unmakeScratch(metaWindow) {
Expand Down
168 changes: 25 additions & 143 deletions stackoverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,31 @@ export function multimonitorDragDropSupport() {
export function enableMultimonitorDragDropSupport() {
pointerWatch = PointerWatcher.getPointerWatcher().addWatch(100,
() => {
Tiling.spaces?.clickOverlays?.forEach(c => {
c.monitorActiveCheck();
});
// check if in the midst of a window resize action
if (Tiling.inGrab && Tiling.inGrab instanceof Grab.ResizeGrab) {
const window = global.display?.focus_window;
if (window) {
Scratch.makeScratch(window);
}
}

/**
* stop navigation before activating workspace. Avoids an issue
* in multimonitors where workspaces can get snapped to another monitor.
*/
Navigator.finishDispatching();
Navigator.finishNavigation(true);

const monitor = Utils.monitorAtCurrentPoint();
const space = Tiling.spaces.monitors.get(monitor);

// if space is already active, do nothing
if (Tiling.spaces.isActiveSpace(space)) {
return;
}

const selected = space?.selectedWindow;
space?.activateWithFocus(selected, false, false);
});
console.debug('paperwm multimonitor drag/drop support is ENABLED');
}
Expand Down Expand Up @@ -102,139 +124,6 @@ export class ClickOverlay {
this.onlyOnPrimary = onlyOnPrimary;
this.left = new StackOverlay(Meta.MotionDirection.LEFT, monitor);
this.right = new StackOverlay(Meta.MotionDirection.RIGHT, monitor);

let enterMonitor = new Clutter.Actor({ reactive: true });
this.enterMonitor = enterMonitor;
enterMonitor.set_position(monitor.x, monitor.y);

// Uncomment to debug the overlays
// enterMonitor.background_color = Clutter.color_from_string('green')[1];
// enterMonitor.opacity = 100;

Main.uiGroup.add_actor(enterMonitor);
Main.layoutManager.trackChrome(enterMonitor);

this.signals = new Utils.Signals();

this._lastPointer = [];
this._lastPointerTimeout = null;

this.signals.connect(enterMonitor, 'touch-event', () => {
if (Tiling.inPreview)
return;
this.select();
});

this.signals.connect(enterMonitor, 'enter-event', () => {
if (Tiling.inPreview)
return;
this.select();
});

this.signals.connect(enterMonitor, 'button-press-event', () => {
if (Tiling.inPreview)
return;
this.select();
return Clutter.EVENT_STOP;
});

this.signals.connect(Main.overview, 'showing', () => {
this.deactivate();
this.hide();
});

this.signals.connect(Main.overview, 'hidden', () => {
this.activate();
this.show();
});

/**
* Handle grabbed (drag & drop) windows in ClickOverlay. If a window is
* grabbed-dragged-and-dropped on a monitor, then select() on this ClickOverlay
* (which deactivates ClickOverlay and immediately activates/selects the dropped window.
*/
this.signals.connect(global.display, 'grab-op-end', (display, mw, type) => {
if (this.monitor === this.mouseMonitor) {
this.select();
}
});
}

/**
* Returns the space of this ClickOverlay instance.
*/
get space() {
return Tiling.spaces.monitors.get(this.monitor);
}

/**
* Returns the monitor the mouse is currently on.
*/
get mouseMonitor() {
return Utils.monitorAtCurrentPoint();
}

monitorActiveCheck() {
// if clickoverlay not active (space is already selected), then nothing to do
if (!this.active) {
return;
}

if (Main.overview.visible || Tiling.inPreview) {
return;
}

// if mouse on me, select
if (this.monitor === this.mouseMonitor) {
this.select();
}
}

select() {
// if clickoverlay not active (space is already selected), then nothing to do
if (!this.active) {
return;
}

// check if in the midst of a window resize action
if (Tiling.inGrab && Tiling.inGrab instanceof Grab.ResizeGrab) {
const window = global.display?.focus_window;
if (window) {
Scratch.makeScratch(window);
}
}

/**
* stop navigation before activating workspace. Avoids an issue
* in multimonitors where workspaces can get snapped to another monitor.
*/
Navigator.finishDispatching();
Navigator.finishNavigation(true);
this.deactivate();
let selected = this.space.selectedWindow;
this.space.activateWithFocus(selected, false, false);
}

activate() {
if (this.onlyOnPrimary || Main.overview.visible)
return;

let spaces = Tiling.spaces;
let active = global.workspace_manager.get_active_workspace();
let monitor = this.monitor;
// Never activate the clickoverlay of the active monitor
if (spaces && spaces.monitors.get(monitor) === spaces.get(active))
return;

this.active = true;
this.space?.setSelectionInactive();
this.enterMonitor.set_position(monitor.x, monitor.y);
this.enterMonitor.set_size(monitor.width, monitor.height);
}

deactivate() {
this.active = false;
this.enterMonitor.set_size(0, 0);
}

reset() {
Expand All @@ -255,10 +144,6 @@ export class ClickOverlay {
}

destroy() {
Utils.timeout_remove(this._lastPointerTimeout);
this._lastPointerTimeout = null;
this.signals.destroy();
this.signals = null;
for (let overlay of [this.left, this.right]) {
let actor = overlay.overlay;
overlay.signals.destroy();
Expand All @@ -269,9 +154,6 @@ export class ClickOverlay {
}
actor.destroy();
}

Main.layoutManager.untrackChrome(this.enterMonitor);
this.enterMonitor.destroy();
}
}

Expand Down
10 changes: 0 additions & 10 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,6 @@ export const Spaces = class Spaces extends Map {
for (let monitor of monitors) {
let overlay = new ClickOverlay(monitor, this.onlyOnPrimary);
monitor.clickOverlay = overlay;
overlay.activate();
this.clickOverlays.push(overlay);
}

Expand All @@ -1977,7 +1976,6 @@ export const Spaces = class Spaces extends Map {
});

this.spaceContainer.show();
activeSpace.monitor.clickOverlay.deactivate();
Topbar.refreshWorkspaceIndicator();
this.setSpaceTopbarElementsVisible();
Stackoverlay.multimonitorDragDropSupport();
Expand Down Expand Up @@ -2295,14 +2293,6 @@ export const Spaces = class Spaces extends Map {
fromSpace,
doAnimate);

toSpace.monitor?.clickOverlay.deactivate();

for (let monitor of Main.layoutManager.monitors) {
if (monitor === toSpace.monitor)
continue;
monitor.clickOverlay.activate();
}

// Update panel to handle target workspace
signals.disconnect(Main.panel, this.touchSignal);
this.touchSignal = signals.connect(Main.panel, "captured-event", Gestures.horizontalTouchScroll.bind(toSpace));
Expand Down

0 comments on commit 8b5b711

Please sign in to comment.