Skip to content

An open-source, self-hosted system for apps built with web technologies.

Closing a Window never leaves a hidden Taskbar showing

zohayrslilehb975318628c4
diff --git a/source/client/view/structure/desktop/desktop-focus.ts b/source/client/view/structure/desktop/desktop-focus.ts
index 7dc1886..08376d7 100644
--- a/source/client/view/structure/desktop/desktop-focus.ts
+++ b/source/client/view/structure/desktop/desktop-focus.ts
@@ -23,7 +23,7 @@ export default function useDesktopFocus(desktop: RefObject<HTMLDivElement | null
const focusTaskbar = useCallback(function (record: Process) {
- focusAfterMinimize(desktop.current, taskbarItems.current.get(record.identity), taskbarOverlay)
+ focusAfterWindow(desktop.current, taskbarItems.current.get(record.identity), taskbarOverlay)
}, [desktop, taskbarOverlay])
@@ -37,11 +37,9 @@ export default function useDesktopFocus(desktop: RefObject<HTMLDivElement | null
const target = candidates.map(entry => taskbarItems.current.get(entry.identity)).find(element => element)
- if (target) target.focus()
+ focusAfterWindow(desktop.current, target, taskbarOverlay)
- else desktop.current?.focus()
-
- }, [desktop])
+ }, [desktop, taskbarOverlay])
const remember = useCallback(function (event: FocusEvent<HTMLDivElement>) {
@@ -85,11 +83,16 @@ export default function useDesktopFocus(desktop: RefObject<HTMLDivElement | null
return { taskbarItem, remember, unavailable, minimize, close }
}
-export function focusAfterMinimize(desktop: HTMLDivElement | null, taskbarItem: HTMLButtonElement | undefined, taskbarOverlay: boolean) {
- if (taskbarOverlay) {
+/**
+ * Where focus goes when a Window leaves interaction: its Taskbar item, or the Desktop when the
+ * Taskbar hides as an overlay or there is no item. Focus never scrolls the Shell: a focused item of
+ * a hidden Taskbar would otherwise be scrolled into view and hold it there.
+ */
+export function focusAfterWindow(desktop: HTMLDivElement | null, taskbarItem: HTMLButtonElement | undefined, taskbarOverlay: boolean) {
+ if (taskbarOverlay || !taskbarItem) {
desktop?.focus({ preventScroll: true })
return
}
- taskbarItem?.focus()
+ taskbarItem.focus({ preventScroll: true })
}
diff --git a/source/client/view/structure/desktop/layers/desktop-layers.tsx b/source/client/view/structure/desktop/layers/desktop-layers.tsx
index 27f8c16..301ae44 100644
--- a/source/client/view/structure/desktop/layers/desktop-layers.tsx
+++ b/source/client/view/structure/desktop/layers/desktop-layers.tsx
@@ -14,23 +14,26 @@ export default function DesktopLayers({ wallpaper, underWindows, windows, shared
return <div
data-desktop-layers=""
- className="absolute inset-0 isolate overflow-hidden"
+ className="absolute inset-0 isolate overflow-clip"
style={{ "--desktop-gutter": `${spacing}px`, "--desktop-scale": scale } as CSSProperties}
>
- <div data-desktop-layer="wallpaper" className="absolute inset-0 z-0 overflow-hidden">
+ {/* Each layer clips what passes its edges and never scrolls: focus moved to something out of
+ view, such as an item of a hidden Taskbar, would otherwise scroll it into view and hold it there. */}
+
+ <div data-desktop-layer="wallpaper" className="absolute inset-0 z-0 overflow-clip">
{wallpaper}
</div>
- <div data-desktop-layer="under" className="pointer-events-none absolute inset-0 z-1 overflow-hidden">
+ <div data-desktop-layer="under" className="pointer-events-none absolute inset-0 z-1 overflow-clip">
{underWindows}
</div>
- <div data-desktop-layer="window" className="pointer-events-none absolute inset-0 z-2 overflow-hidden">
+ <div data-desktop-layer="window" className="pointer-events-none absolute inset-0 z-2 overflow-clip">
{/* Standard Windows measure in the whole view, like every other layer; the margins
around them are painted, not measured. */}
@@ -40,13 +43,13 @@ export default function DesktopLayers({ wallpaper, underWindows, windows, shared
</div>
- <div data-desktop-layer="over" className="pointer-events-none absolute inset-0 z-3 overflow-hidden">
+ <div data-desktop-layer="over" className="pointer-events-none absolute inset-0 z-3 overflow-clip">
{overWindows}
</div>
- <div data-desktop-layer="shell" className="pointer-events-none absolute inset-0 z-4 overflow-hidden">
+ <div data-desktop-layer="shell" className="pointer-events-none absolute inset-0 z-4 overflow-clip">
{shell}
diff --git a/tests/desktop-focus.test.ts b/tests/desktop-focus.test.ts
index 20740f7..f202e3b 100644
--- a/tests/desktop-focus.test.ts
+++ b/tests/desktop-focus.test.ts
@@ -1,11 +1,11 @@
import { expect, test, vi } from "vitest"
-import { focusAfterMinimize } from "@client/view/structure/desktop/desktop-focus"
+import { focusAfterWindow } from "@client/view/structure/desktop/desktop-focus"
-test("minimizing from a Window does not focus an overlay Taskbar", () => {
+test("a Window leaving interaction does not focus an overlay Taskbar", () => {
const desktopFocus = vi.fn()
const taskbarFocus = vi.fn()
- focusAfterMinimize(
+ focusAfterWindow(
{ focus: desktopFocus } as unknown as HTMLDivElement,
{ focus: taskbarFocus } as unknown as HTMLButtonElement,
true
@@ -15,16 +15,24 @@ test("minimizing from a Window does not focus an overlay Taskbar", () => {
expect(taskbarFocus).not.toHaveBeenCalled()
})
-test("minimizing from a Window focuses its visible non-overlay Taskbar item", () => {
+test("a Window leaving interaction focuses a visible Taskbar item without scrolling", () => {
const desktopFocus = vi.fn()
const taskbarFocus = vi.fn()
- focusAfterMinimize(
+ focusAfterWindow(
{ focus: desktopFocus } as unknown as HTMLDivElement,
{ focus: taskbarFocus } as unknown as HTMLButtonElement,
false
)
expect(desktopFocus).not.toHaveBeenCalled()
- expect(taskbarFocus).toHaveBeenCalledOnce()
+ expect(taskbarFocus).toHaveBeenCalledWith({ preventScroll: true })
+})
+
+test("with no Taskbar item left, focus goes to the Desktop", () => {
+ const desktopFocus = vi.fn()
+
+ focusAfterWindow({ focus: desktopFocus } as unknown as HTMLDivElement, undefined, false)
+
+ expect(desktopFocus).toHaveBeenCalledWith({ preventScroll: true })
})