Skip to content

Commit

Permalink
Improve scratch window behaviours (for mouse-dragging windows and new…
Browse files Browse the repository at this point in the history
… windows when a scratch window is selected) (#718)

This PR changes several widow behaviours related to scratch windows. It
seeks to make scratch windows more predictable (in how one scratches a
window) and try to minimise instances of "accidentally/unexpectedly"
scratching windows.

Users (especially new users) seem to struggle with some of the
behaviours for scratch windows.

See some example comments here:

- #680 (comment)
- #700 (comment)
- #700 (comment)

On review, a couple of behaviours are rather unintuitive with scratch
windows:

1. when a scratch window is selected, any new window opened will also be
scratched. I understand the thought here, but this is rarely what's
wanted (for me anyway) and often leads to confusion. This PR undoes
this. New windows will be tiled (regardless of whether a scratch window
is currently selected).

2. Dragging a window (with mouse) and NOT dropping on a target now
re-tiles that window (previously it scratched that window). I've had two
user reports in the last few weeks of this (reported as a bug). In any
case, it seems the more intuitive option of for that window to be
re-tiled:


https://github.com/paperwm/PaperWM/assets/30424662/9c4a20d6-52e3-408f-9c0a-62ee0ceb6244
  • Loading branch information
jtaala authored Nov 28, 2023
2 parents faaf59e + 23e6dac commit e362597
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ PaperWM currently works best using the workspaces span monitors preference, this
The scratch layer is an escape hatch to a familiar floating layout. This layer is intended to store windows that are globally useful like chat applications and in general serve as the kitchen sink.
When the scratch layer is active it will float above the tiled windows, when hidden the windows will be minimized.
Opening a window when the scratch layer is active will make it float automatically.
Pressing <kbd>Super</kbd><kbd>Escape</kbd> toggles between showing and hiding the windows in the scratch layer.
Activating windows in the scratch layer is done using <kbd>Super</kbd><kbd>Tab</kbd>, the floating windows having priority in the list while active.
When the tiling is active <kbd>Super</kbd><kbd>Shift</kbd><kbd>Tab</kbd> selects the most recently used scratch window.
Expand Down
41 changes: 28 additions & 13 deletions grab.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ export class MoveGrab {
}

beginDnD({ center } = {}) {
if (this.dnd)
if (this.dnd) {
return;
}

this.center = center;
this.dnd = true;
console.debug("#grab", "begin DnD");
Expand Down Expand Up @@ -241,6 +243,7 @@ export class MoveGrab {
if (x < colX)
continue;

// vertically tiled
for (let i = 0; i < column.length + 1; i++) {
let clone;
if (i < column.length) {
Expand Down Expand Up @@ -278,19 +281,20 @@ export class MoveGrab {
}
}

function sameTarget(a, b) {
const sameTarget = (a, b) => {
if (a === b)
return true;
if (!a || !b)
return false;
return a.space === b.space && a.position[0] === b.position[0] && a.position[1] === b.position[1];
}
};

// TODO: rename dndTarget to selectedZone ?
if (!sameTarget(target, this.dndTarget)) {
this.dndTarget && this.deactivateDndTarget(this.dndTarget);
if (target)
// deactivate only if target exists
if (target) {
this.deactivateDndTarget(this.dndTarget);
this.activateDndTarget(target, initial);
}
}
}

Expand Down Expand Up @@ -406,7 +410,8 @@ export class MoveGrab {
Tiling.ensureViewport(metaWindow, space);

Utils.actor_raise(clone);
} else {
}
else {
metaWindow.move_frame(true, clone.x, clone.y);
Scratch.makeScratch(metaWindow);
this.initialSpace.moveDone();
Expand All @@ -418,14 +423,22 @@ export class MoveGrab {
clone.set_scale(1, 1);
clone.set_pivot_point(0, 0);

params.onStopped = () => {
actor.set_pivot_point(0, 0);
const halftime = 0.5 * Settings.prefs.animation_time;
params.time = halftime;
params.onComplete = () => {
Easer.addEase(actor, {
time: halftime,
onComplete: () => {
Scratch.unmakeScratch(metaWindow);
},
});
};
Easer.addEase(actor, params);
}

Navigator.getNavigator().accept();
} else if (this.initialSpace.indexOf(metaWindow) !== -1) {
}
else if (this.initialSpace.indexOf(metaWindow) !== -1) {
let space = this.initialSpace;
space.targetX = space.cloneContainer.x;

Expand Down Expand Up @@ -486,24 +499,26 @@ export class MoveGrab {
}

activateDndTarget(zone, first) {
function mkZoneActor(props) {
const mkZoneActor = props => {
let actor = new St.Widget({ style_class: "tile-preview" });
actor.x = props.x ?? 0;
actor.y = props.y ?? 0;
actor.width = props.width ?? 0;
actor.height = props.height ?? 0;
return actor;
}
};

zone.actor = mkZoneActor({ ...zone.actorParams });

this.dndTarget = zone;
this.zoneActors.add(zone.actor);
const raise = () => Utils.actor_raise(zone.actor);

let params = {
time: Settings.prefs.animation_time,
[zone.originProp]: zone.center - zone.marginA,
[zone.sizeProp]: zone.marginA + zone.marginB,
onComplete: raise,
};

if (first) {
Expand All @@ -523,7 +538,7 @@ export class MoveGrab {
zone.space.cloneContainer.add_child(zone.actor);
zone.space.selection.hide();
zone.actor.show();
Utils.actor_raise(zone.actor);
raise();
Easer.addEase(zone.actor, params);
}

Expand Down
11 changes: 2 additions & 9 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -3282,12 +3282,7 @@ export function insertWindow(metaWindow, { existing }) {
focusWindow = mru[1];
}

// Scratch if have scratch windows on this space and focused window is also scratch
let scratchIsFocused =
Scratch.getScratchWindows().length > 0 &&
space === spaces.spaceOfWindow(focusWindow) &&
Scratch.isScratchWindow(focusWindow);
let addToScratch = scratchIsFocused;
let addToScratch = false;

let winprop = Settings.find_winprop(metaWindow);
if (winprop) {
Expand All @@ -3309,9 +3304,7 @@ export function insertWindow(metaWindow, { existing }) {
if (addToScratch) {
connectSizeChanged();
Scratch.makeScratch(metaWindow);
if (scratchIsFocused) {
activateWindowAfterRendered(actor, metaWindow);
}
activateWindowAfterRendered(actor, metaWindow);
return;
}
}
Expand Down

0 comments on commit e362597

Please sign in to comment.