Skip to content

Commit e362597

Browse files
authored
Improve scratch window behaviours (for mouse-dragging windows and new 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
2 parents faaf59e + 23e6dac commit e362597

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ PaperWM currently works best using the workspaces span monitors preference, this
164164
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.
165165
When the scratch layer is active it will float above the tiled windows, when hidden the windows will be minimized.
166166
167-
Opening a window when the scratch layer is active will make it float automatically.
168-
169167
Pressing <kbd>Super</kbd><kbd>Escape</kbd> toggles between showing and hiding the windows in the scratch layer.
170168
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.
171169
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: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ export class MoveGrab {
101101
}
102102

103103
beginDnD({ center } = {}) {
104-
if (this.dnd)
104+
if (this.dnd) {
105105
return;
106+
}
107+
106108
this.center = center;
107109
this.dnd = true;
108110
console.debug("#grab", "begin DnD");
@@ -241,6 +243,7 @@ export class MoveGrab {
241243
if (x < colX)
242244
continue;
243245

246+
// vertically tiled
244247
for (let i = 0; i < column.length + 1; i++) {
245248
let clone;
246249
if (i < column.length) {
@@ -278,19 +281,20 @@ export class MoveGrab {
278281
}
279282
}
280283

281-
function sameTarget(a, b) {
284+
const sameTarget = (a, b) => {
282285
if (a === b)
283286
return true;
284287
if (!a || !b)
285288
return false;
286289
return a.space === b.space && a.position[0] === b.position[0] && a.position[1] === b.position[1];
287-
}
290+
};
288291

289-
// TODO: rename dndTarget to selectedZone ?
290292
if (!sameTarget(target, this.dndTarget)) {
291-
this.dndTarget && this.deactivateDndTarget(this.dndTarget);
292-
if (target)
293+
// deactivate only if target exists
294+
if (target) {
295+
this.deactivateDndTarget(this.dndTarget);
293296
this.activateDndTarget(target, initial);
297+
}
294298
}
295299
}
296300

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

408412
Utils.actor_raise(clone);
409-
} else {
413+
}
414+
else {
410415
metaWindow.move_frame(true, clone.x, clone.y);
411416
Scratch.makeScratch(metaWindow);
412417
this.initialSpace.moveDone();
@@ -418,14 +423,22 @@ export class MoveGrab {
418423
clone.set_scale(1, 1);
419424
clone.set_pivot_point(0, 0);
420425

421-
params.onStopped = () => {
422-
actor.set_pivot_point(0, 0);
426+
const halftime = 0.5 * Settings.prefs.animation_time;
427+
params.time = halftime;
428+
params.onComplete = () => {
429+
Easer.addEase(actor, {
430+
time: halftime,
431+
onComplete: () => {
432+
Scratch.unmakeScratch(metaWindow);
433+
},
434+
});
423435
};
424436
Easer.addEase(actor, params);
425437
}
426438

427439
Navigator.getNavigator().accept();
428-
} else if (this.initialSpace.indexOf(metaWindow) !== -1) {
440+
}
441+
else if (this.initialSpace.indexOf(metaWindow) !== -1) {
429442
let space = this.initialSpace;
430443
space.targetX = space.cloneContainer.x;
431444

@@ -486,24 +499,26 @@ export class MoveGrab {
486499
}
487500

488501
activateDndTarget(zone, first) {
489-
function mkZoneActor(props) {
502+
const mkZoneActor = props => {
490503
let actor = new St.Widget({ style_class: "tile-preview" });
491504
actor.x = props.x ?? 0;
492505
actor.y = props.y ?? 0;
493506
actor.width = props.width ?? 0;
494507
actor.height = props.height ?? 0;
495508
return actor;
496-
}
509+
};
497510

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

500513
this.dndTarget = zone;
501514
this.zoneActors.add(zone.actor);
515+
const raise = () => Utils.actor_raise(zone.actor);
502516

503517
let params = {
504518
time: Settings.prefs.animation_time,
505519
[zone.originProp]: zone.center - zone.marginA,
506520
[zone.sizeProp]: zone.marginA + zone.marginB,
521+
onComplete: raise,
507522
};
508523

509524
if (first) {
@@ -523,7 +538,7 @@ export class MoveGrab {
523538
zone.space.cloneContainer.add_child(zone.actor);
524539
zone.space.selection.hide();
525540
zone.actor.show();
526-
Utils.actor_raise(zone.actor);
541+
raise();
527542
Easer.addEase(zone.actor, params);
528543
}
529544

tiling.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,12 +3282,7 @@ export function insertWindow(metaWindow, { existing }) {
32823282
focusWindow = mru[1];
32833283
}
32843284

3285-
// Scratch if have scratch windows on this space and focused window is also scratch
3286-
let scratchIsFocused =
3287-
Scratch.getScratchWindows().length > 0 &&
3288-
space === spaces.spaceOfWindow(focusWindow) &&
3289-
Scratch.isScratchWindow(focusWindow);
3290-
let addToScratch = scratchIsFocused;
3285+
let addToScratch = false;
32913286

32923287
let winprop = Settings.find_winprop(metaWindow);
32933288
if (winprop) {
@@ -3309,9 +3304,7 @@ export function insertWindow(metaWindow, { existing }) {
33093304
if (addToScratch) {
33103305
connectSizeChanged();
33113306
Scratch.makeScratch(metaWindow);
3312-
if (scratchIsFocused) {
3313-
activateWindowAfterRendered(actor, metaWindow);
3314-
}
3307+
activateWindowAfterRendered(actor, metaWindow);
33153308
return;
33163309
}
33173310
}

0 commit comments

Comments
 (0)