set focus after scrolling with the touchpad gesture

Co-authored-by: Grafcube <grafcube@disroot.org>
This commit is contained in:
Peter Fajdiga
2025-12-20 21:59:59 +01:00
parent 60bee26e29
commit 6f69252001
2 changed files with 16 additions and 2 deletions

View File

@@ -141,8 +141,20 @@ class Desktop {
this.setScroll(this.gestureScrollXInitial + this.config.gestureScrollStep * amount, false);
}
public gestureScrollFinish() {
public gestureScrollFinish(focusedWindow: Window|null) {
const scrolledRight = this.scrollX > this.gestureScrollXInitial!;
this.gestureScrollXInitial = null;
const visibleRange = this.getCurrentVisibleRange();
if (focusedWindow !== null && !Range.contains(visibleRange, focusedWindow.column)) {
// the focused window is no longer visible, find a new window to focus
const focusTargetColumn = scrolledRight ?
this.grid.getLeftmostVisibleColumn(visibleRange) :
this.grid.getRightmostVisibleColumn(visibleRange);
if (focusTargetColumn !== null) {
focusTargetColumn.getWindowToFocus().focus();
}
}
}
public arrange() {

View File

@@ -158,9 +158,11 @@ class World {
public gestureScrollFinish() {
this.do((clientManager, desktopManager) => {
const focusedWindow = Workspace.activeWindow === null ? null : clientManager.findTiledWindow(Workspace.activeWindow);
const currentDesktop = desktopManager.getCurrentDesktop();
if (currentDesktop !== undefined) {
currentDesktop.gestureScrollFinish();
console.assert(focusedWindow === null || focusedWindow.column.grid.desktop === currentDesktop);
currentDesktop.gestureScrollFinish(focusedWindow);
}
});
}