diff options
Diffstat (limited to 'src/desktop/window.tsx')
| -rw-r--r-- | src/desktop/window.tsx | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/desktop/window.tsx b/src/desktop/window.tsx index ef5cdab..a493bcf 100644 --- a/src/desktop/window.tsx +++ b/src/desktop/window.tsx @@ -3,8 +3,6 @@ import { useLiveSignal } from "@preact/signals/utils"; import { ComponentChildren, Ref, RefObject } from "preact"; import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks"; import { Task } from "."; -import { flushSync } from "preact/compat"; - type UseDragFunction = (onStartDrag: (e: MouseEvent) => void, onUpdatePosition: (e: MouseEvent) => void) => [Signal<Boolean>, (e: MouseEvent) => void] @@ -25,7 +23,7 @@ export function Window(props: Window.Props) { }, [onUpdatePosition]); const startDrag = useCallback((e: MouseEvent) => { - if (e.button === 0 && !maximized.value.value) { + if (e.button === 0) { if (dragTimeout.current !== null) { clearTimeout(dragTimeout.current); dragTimeout.current = null; @@ -44,6 +42,7 @@ export function Window(props: Window.Props) { }, [props]) const windowRef: Ref<HTMLDivElement> = useRef(null); + const titlebarRef: Ref<HTMLDivElement> = useRef(null); const source = useLiveSignal(props.task.source); const title = useLiveSignal(props.task.title); @@ -73,6 +72,15 @@ export function Window(props: Window.Props) { // Naturally, I have to add the border width here, because offset* uses padding-edge for the calculations initialOffsetX.current = e.offsetX + BORDER_WIDTH + (e.target as HTMLDivElement).offsetLeft initialOffsetY.current = e.offsetY + BORDER_WIDTH + (e.target as HTMLDivElement).offsetTop + if (maximized.value.value) { + maximized.value.value = false + const w: number = width.value as number / 2 + const h: number = titlebarRef.current!.getBoundingClientRect().height as number / 2 + x.value = initialOffsetX.current - w + y.value = initialOffsetY.current - h + initialOffsetX.current = w + initialOffsetY.current = h + } document.getSelection()?.empty() }, []) @@ -197,7 +205,7 @@ export function Window(props: Window.Props) { } onPointerDown={onFocus} > - <div class="titlebar" onPointerDown={startWindowMove}> + <div ref={titlebarRef} class="titlebar" onPointerDown={startWindowMove}> <img src={`/assets/${source.value.value.type}.png`} /> <div class="title">{title.value.value ?? "[404 Title Not Found]"}</div> <div class="buttons" onPointerDown={onPointerDownButton}> |
