Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ClickOverlay enterMonitor reactive actor approach with much simpler implementation #751

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
192 changes: 39 additions & 153 deletions stackoverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,69 @@ import { Settings, Utils, Tiling, Navigator, Grab, Scratch } from './imports.js'
restack loops)
*/

let pointerWatch;
let pointerWatch, lastSpace;
export function enable(extension) {

}

export function disable() {
disableMultimonitorDragDropSupport();
disableMultimonitorSupport();
lastSpace = null;
}

/**
* Checks for multiple monitors and if so, then enables multimonitor
* drag/drop support in PaperWM.
* support in PaperWM.
*/
export function multimonitorDragDropSupport() {
export function multimonitorSupport() {
// if only one monitor, return
if (Tiling.spaces.monitors?.size > 1) {
enableMultimonitorDragDropSupport();
enableMultimonitorSupport();
}
else {
disableMultimonitorDragDropSupport();
disableMultimonitorSupport();
}
}

export function enableMultimonitorDragDropSupport() {
export function enableMultimonitorSupport() {
pointerWatch = PointerWatcher.getPointerWatcher().addWatch(100,
Lythenas marked this conversation as resolved.
Show resolved Hide resolved
() => {
Tiling.spaces?.clickOverlays?.forEach(c => {
c.monitorActiveCheck();
});
const monitor = Utils.monitorAtCurrentPoint();
const space = Tiling.spaces.monitors.get(monitor);

// same space
if (space === lastSpace) {
return;
}
// update to space
lastSpace = space;

// 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);
}
return;
}

// if drag/grabbing window, do simple activate
if (Tiling.inGrab) {
space?.activate(false, false);
return;
}

const selected = space?.selectedWindow;
space?.activateWithFocus(selected, false, false);
});
console.debug('paperwm multimonitor drag/drop support is ENABLED');
console.debug('paperwm multimonitor support is ENABLED');
}

export function disableMultimonitorDragDropSupport() {
export function disableMultimonitorSupport() {
pointerWatch?.remove();
pointerWatch = null;
console.debug('paperwm multimonitor drag/drop support is DISABLED');
console.debug('paperwm multimonitor support is DISABLED');
}

export function createAppIcon(metaWindow, size) {
Expand All @@ -102,139 +128,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 +148,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 +158,6 @@ export class ClickOverlay {
}
actor.destroy();
}

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

Expand Down
12 changes: 1 addition & 11 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,10 +1976,9 @@ export const Spaces = class Spaces extends Map {
});

this.spaceContainer.show();
activeSpace.monitor.clickOverlay.deactivate();
Topbar.refreshWorkspaceIndicator();
this.setSpaceTopbarElementsVisible();
Stackoverlay.multimonitorDragDropSupport();
Stackoverlay.multimonitorSupport();
};

if (this.onlyOnPrimary) {
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