fix(window): align macOS traffic light controls
This commit is contained in:
7 files changed
+238
-6
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { shouldDrawDesktopWindowFrame, shouldReserveMacTrafficLightInset, shouldShowWindowControls } from "@/composables/useWindowControls";
|
||||
import { macTrafficLightInsetPaddingForScale, macTrafficLightPositionForScale, shouldDrawDesktopWindowFrame, shouldReserveMacTrafficLightInset, shouldShowWindowControls } from "@/composables/useWindowControls";
|
||||
|
||||
describe("window controls", () => {
|
||||
it("shows custom controls for non-macOS desktop windows", () => {
|
||||
@@ -26,4 +26,17 @@ describe("window controls", () => {
|
||||
expect(shouldReserveMacTrafficLightInset(false, false, true)).toBe(false);
|
||||
expect(shouldReserveMacTrafficLightInset(true, false, false)).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps the macOS traffic light reserve visually stable across UI scales", () => {
|
||||
expect(macTrafficLightInsetPaddingForScale(1)).toBe("70px");
|
||||
expect(macTrafficLightInsetPaddingForScale(0.9)).toBe("78px");
|
||||
expect(macTrafficLightInsetPaddingForScale(1.25)).toBe("56px");
|
||||
});
|
||||
|
||||
it("adjusts macOS traffic lights vertically with the UI scale", () => {
|
||||
expect(macTrafficLightPositionForScale(1)).toEqual({ x: 16, y: 18 });
|
||||
expect(macTrafficLightPositionForScale(0.9)).toEqual({ x: 16, y: 16 });
|
||||
expect(macTrafficLightPositionForScale(1.1)).toEqual({ x: 16, y: 20 });
|
||||
expect(macTrafficLightPositionForScale(1.25)).toEqual({ x: 16, y: 23 });
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,30 @@ import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import { isMacOS } from "@/lib/backend/platform";
|
||||
import * as api from "@/lib/backend/api";
|
||||
|
||||
const MIN_UI_SCALE = 0.75;
|
||||
const MAX_UI_SCALE = 2;
|
||||
export const MAC_TRAFFIC_LIGHT_X = 16;
|
||||
export const MAC_TRAFFIC_LIGHT_BASE_Y = 18;
|
||||
const MAC_TRAFFIC_LIGHT_SCALE_DELTA_Y = 20;
|
||||
const MAC_TRAFFIC_LIGHT_RESERVED_INSET = 70;
|
||||
|
||||
function normalizeTrafficLightUiScale(scale: number): number {
|
||||
return Number.isFinite(scale) ? Math.min(MAX_UI_SCALE, Math.max(MIN_UI_SCALE, scale)) : 1;
|
||||
}
|
||||
|
||||
export function macTrafficLightPositionForScale(scale: number): { x: number; y: number } {
|
||||
const normalizedScale = normalizeTrafficLightUiScale(scale);
|
||||
return {
|
||||
x: MAC_TRAFFIC_LIGHT_X,
|
||||
y: Math.round(MAC_TRAFFIC_LIGHT_BASE_Y + (normalizedScale - 1) * MAC_TRAFFIC_LIGHT_SCALE_DELTA_Y),
|
||||
};
|
||||
}
|
||||
|
||||
export function macTrafficLightInsetPaddingForScale(scale: number): string {
|
||||
const normalizedScale = normalizeTrafficLightUiScale(scale);
|
||||
return `${Math.ceil(MAC_TRAFFIC_LIGHT_RESERVED_INSET / normalizedScale)}px`;
|
||||
}
|
||||
|
||||
export function shouldReserveMacTrafficLightInset(isMac: boolean, isFullscreen: boolean, isDesktop = true): boolean {
|
||||
return isDesktop && isMac && !isFullscreen;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user