Skip to content

Commit 580822a

Browse files
authored
Auto-delete snap group with 1 window if not populated in 6 seconds
1 parent 826c818 commit 580822a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

contents/ui/code/windows.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,18 @@ function removeWindowFromTrack(windowId, callback){
323323
if (i > -1) {
324324
snappedWindowGroups[i].windows.splice(i2, 1);
325325
if (callback) callback(snappedWindowGroups[i]);
326-
if (snappedWindowGroups[i].windows.length < 1) snappedWindowGroups.splice(i, 1);
326+
const remainingWindowsCount = snappedWindowGroups[i].windows.length;
327+
if (remainingWindowsCount < 1) snappedWindowGroups.splice(i, 1); /// delete empty group
328+
else if (remainingWindowsCount === 1) {
329+
/// set timer to delete group if not populated in few seconds
330+
331+
const remainingWindowId = snappedWindowGroups[i].windows[0];
332+
setOneTimeTimeout(function(){
333+
/// group index may have changed
334+
const i3 = snappedWindowGroups.findIndex((group) => group.windows.indexOf(remainingWindowId) > -1 && group.windows.length < 2);
335+
if (i3 > -1) snappedWindowGroups.splice(i3, 1);
336+
}, 6000);
337+
}
327338
}
328339
}
329340

@@ -453,3 +464,19 @@ function sortClientsByLastActive() {
453464
return activationTime[windowIdA] - activationTime[windowIdB];
454465
});
455466
}
467+
468+
/// One-time timer, when we want multiple timers run in parallel
469+
function setOneTimeTimeout(cb, delayTime){
470+
function Timer() {
471+
return Qt.createQmlObject("import QtQuick 2.0; Timer {}", main);
472+
}
473+
474+
const timer = new Timer();
475+
timer.interval = delayTime;
476+
timer.repeat = false;
477+
timer.triggered.connect(function(){
478+
cb();
479+
timer.destroy();
480+
});
481+
timer.start();
482+
}

contents/ui/main.qml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,8 @@ Window {
365365
}
366366
}
367367

368-
/// Timer to delay snap assist reveal.
369-
/// Delay is added to get the updated snapped window's size and location,
370-
/// which sometimes differs from the half of the screen
368+
/// Reusable timer,
369+
/// used for regular actions on each assist reveal and hide
371370
Timer {
372371
id: timer
373372
function setTimeout(cb, delayTime) {

0 commit comments

Comments
 (0)