Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): add custom maximize handler to Windows caption controls

Richie McIlroy9bc686ba7e43
diff --git a/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx b/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx
index 680e1b62c..d55b689bd 100644
--- a/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx
+++ b/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx
@@ -13,11 +13,25 @@ import titlebarState from "~/utils/titlebar-state";
import { WindowControlButton as ControlButton } from "./WindowControlButton";
export default function (
- props: ComponentProps<"div"> & { maximizable?: boolean },
+ props: ComponentProps<"div"> & {
+ maximizable?: boolean;
+ maximized?: boolean;
+ onMaximize?: () => void;
+ },
) {
- const [local, otherProps] = splitProps(props, ["class"]);
+ const [local, otherProps] = splitProps(props, [
+ "class",
+ "maximizable",
+ "maximized",
+ "onMaximize",
+ ]);
const currentWindow = getCurrentWindow();
const [focused, setFocus] = createSignal(true);
+ const hasCustomMaximize = () => local.onMaximize !== undefined;
+ const maximizable = () =>
+ local.maximizable !== false &&
+ (hasCustomMaximize() || titlebarState.maximizable);
+ const maximized = () => local.maximized ?? titlebarState.maximized;
let unlisten: (() => void) | undefined;
onMount(async () => {
@@ -54,19 +68,16 @@ export default function (
<icons.minimizeWin />
</ControlButton>
<Show
- when={
- titlebarState.maximizable ||
- !titlebarState.hideMaximize ||
- props.maximizable
- }
+ when={maximizable() || !titlebarState.hideMaximize || local.maximizable}
>
<ControlButton
- disabled={!titlebarState.maximizable || props.maximizable === false}
+ disabled={!maximizable()}
onClick={
- titlebarState.maximizable
- ? titlebarState.maximized
- ? currentWindow.unmaximize
- : currentWindow.maximize
+ maximizable()
+ ? (local.onMaximize ??
+ (maximized()
+ ? currentWindow.unmaximize
+ : currentWindow.maximize))
: undefined
}
class={cx(
@@ -75,11 +86,7 @@ export default function (
"disabled:hover:bg-transparent dark:disabled:hover:bg-transparent disabled:text-black-transparent-40",
)}
>
- {titlebarState.maximized ? (
- <icons.maximizeRestoreWin />
- ) : (
- <icons.maximizeWin />
- )}
+ {maximized() ? <icons.maximizeRestoreWin /> : <icons.maximizeWin />}
</ControlButton>
</Show>
<ControlButton