Skip to content

Commit 411942c

Browse files
authored
Improve scratch window behaviours for Gnone-44 (#724)
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
2 parents 1c9c25b + b14a1af commit 411942c

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ PaperWM currently works best using the workspaces span monitors preference, this
159159
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.
160160
When the scratch layer is active it will float above the tiled windows, when hidden the windows will be minimized.
161161
162-
Opening a window when the scratch layer is active will make it float automatically.
163-
164162
Pressing <kbd>Super</kbd><kbd>Escape</kbd> toggles between showing and hiding the windows in the scratch layer.
165163
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.
166164
When the tiling is active <kbd>Super</kbd><kbd>Shift</kbd><kbd>Tab</kbd> selects the most recently used scratch window.

grab.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ var MoveGrab = class MoveGrab {
105105
}
106106

107107
beginDnD({ center } = {}) {
108-
if (this.dnd)
108+
if (this.dnd) {
109109
return;
110+
}
111+
110112
this.center = center;
111113
this.dnd = true;
112114
Utils.debug("#grab", "begin DnD");
@@ -245,6 +247,7 @@ var MoveGrab = class MoveGrab {
245247
if (x < colX)
246248
continue;
247249

250+
// vertically tiled
248251
for (let i = 0; i < column.length + 1; i++) {
249252
let clone;
250253
if (i < column.length) {
@@ -282,19 +285,20 @@ var MoveGrab = class MoveGrab {
282285
}
283286
}
284287

285-
function sameTarget(a, b) {
288+
const sameTarget = (a, b) => {
286289
if (a === b)
287290
return true;
288291
if (!a || !b)
289292
return false;
290293
return a.space === b.space && a.position[0] === b.position[0] && a.position[1] === b.position[1];
291-
}
294+
};
292295

293-
// TODO: rename dndTarget to selectedZone ?
294296
if (!sameTarget(target, this.dndTarget)) {
295-
this.dndTarget && this.deactivateDndTarget(this.dndTarget);
296-
if (target)
297+
// deactivate only if target exists
298+
if (target) {
299+
this.deactivateDndTarget(this.dndTarget);
297300
this.activateDndTarget(target, initial);
301+
}
298302
}
299303
}
300304

@@ -410,7 +414,8 @@ var MoveGrab = class MoveGrab {
410414
Tiling.ensureViewport(metaWindow, space);
411415

412416
Utils.actor_raise(clone);
413-
} else {
417+
}
418+
else {
414419
metaWindow.move_frame(true, clone.x, clone.y);
415420
Scratch.makeScratch(metaWindow);
416421
this.initialSpace.moveDone();
@@ -422,12 +427,22 @@ var MoveGrab = class MoveGrab {
422427
clone.set_scale(1, 1);
423428
clone.set_pivot_point(0, 0);
424429

425-
params.onStopped = () => { actor.set_pivot_point(0, 0); };
430+
const halftime = 0.5 * Settings.prefs.animation_time;
431+
params.time = halftime;
432+
params.onComplete = () => {
433+
Easer.addEase(actor, {
434+
time: halftime,
435+
onComplete: () => {
436+
Scratch.unmakeScratch(metaWindow);
437+
},
438+
});
439+
};
426440
Easer.addEase(actor, params);
427441
}
428442

429443
Navigator.getNavigator().accept();
430-
} else if (this.initialSpace.indexOf(metaWindow) !== -1) {
444+
}
445+
else if (this.initialSpace.indexOf(metaWindow) !== -1) {
431446
let space = this.initialSpace;
432447
space.targetX = space.cloneContainer.x;
433448

@@ -490,24 +505,26 @@ var MoveGrab = class MoveGrab {
490505
}
491506

492507
activateDndTarget(zone, first) {
493-
function mkZoneActor(props) {
508+
const mkZoneActor = props => {
494509
let actor = new St.Widget({ style_class: "tile-preview" });
495510
actor.x = props.x ?? 0;
496511
actor.y = props.y ?? 0;
497512
actor.width = props.width ?? 0;
498513
actor.height = props.height ?? 0;
499514
return actor;
500-
}
515+
};
501516

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

504519
this.dndTarget = zone;
505520
this.zoneActors.add(zone.actor);
521+
const raise = () => Utils.actor_raise(zone.actor);
506522

507523
let params = {
508524
time: Settings.prefs.animation_time,
509525
[zone.originProp]: zone.center - zone.marginA,
510526
[zone.sizeProp]: zone.marginA + zone.marginB,
527+
onComplete: raise,
511528
};
512529

513530
if (first) {
@@ -527,7 +544,7 @@ var MoveGrab = class MoveGrab {
527544
zone.space.cloneContainer.add_child(zone.actor);
528545
zone.space.selection.hide();
529546
zone.actor.show();
530-
Utils.actor_raise(zone.actor);
547+
raise();
531548
Easer.addEase(zone.actor, params);
532549
}
533550

tiling.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,12 +3271,7 @@ function insertWindow(metaWindow, { existing }) {
32713271
focusWindow = mru[1];
32723272
}
32733273

3274-
// Scratch if have scratch windows on this space and focused window is also scratch
3275-
let scratchIsFocused =
3276-
Scratch.getScratchWindows().length > 0 &&
3277-
space === spaces.spaceOfWindow(focusWindow) &&
3278-
Scratch.isScratchWindow(focusWindow);
3279-
let addToScratch = scratchIsFocused;
3274+
let addToScratch = false;
32803275

32813276
let winprop = Settings.find_winprop(metaWindow);
32823277
if (winprop) {
@@ -3298,9 +3293,7 @@ function insertWindow(metaWindow, { existing }) {
32983293
if (addToScratch) {
32993294
connectSizeChanged();
33003295
Scratch.makeScratch(metaWindow);
3301-
if (scratchIsFocused) {
3302-
activateWindowAfterRendered(actor, metaWindow);
3303-
}
3296+
activateWindowAfterRendered(actor, metaWindow);
33043297
return;
33053298
}
33063299
}

0 commit comments

Comments
 (0)