-
Notifications
You must be signed in to change notification settings - Fork 1.6k
make t3code look cool on windows and linux (custom&overlay title bar) #1929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tarik02
wants to merge
15
commits into
pingdotgg:main
Choose a base branch
from
tarik02:feature/linux-titlebar-platform-layout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
599e65c
make t3code look cool on linux
tarik02 4c0715b
reviews update
tarik02 a5aed5e
cast desktop bridge return values
tarik02 bdbf006
rm dead code
tarik02 1e634c5
update sidebar styles
tarik02 9a2bc17
improve overlay background color
tarik02 c1d1ae4
refactor
tarik02 fb5fe4a
wip
tarik02 1d23e06
Merge remote-tracking branch 'upstream/main' into feature/linux-title…
tarik02 eb7eb91
refactor once more
tarik02 fbb485d
fix
tarik02 437fd1c
upd
tarik02 2319904
fix css env vars
tarik02 a921e81
wip
tarik02 2e59768
support for windows os
tarik02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { getWindowControlsLayout } from "./env"; | ||
|
|
||
| vi.mock("./linuxWindowControls", () => ({ | ||
| getLinuxWindowControlsLayout: vi.fn().mockReturnValue({ | ||
| left: [], | ||
| right: ["minimize", "maximize", "close"], | ||
| }), | ||
| })); | ||
|
|
||
| describe("getWindowControlsLayout", () => { | ||
| it("uses the standard macOS traffic-light placement in ltr locales", () => { | ||
| expect(getWindowControlsLayout({ locale: "en-US", platform: "macos" })).toEqual({ | ||
| left: ["close", "minimize", "maximize"], | ||
| right: [], | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps macOS traffic lights left-aligned in rtl locales", () => { | ||
| expect(getWindowControlsLayout({ locale: "ar", platform: "macos" })).toEqual({ | ||
| left: ["close", "minimize", "maximize"], | ||
| right: [], | ||
| }); | ||
| }); | ||
|
|
||
| it("uses the standard Windows control layout in ltr locales", () => { | ||
| expect(getWindowControlsLayout({ locale: "en-US", platform: "windows" })).toEqual({ | ||
| left: [], | ||
| right: ["minimize", "maximize", "close"], | ||
| }); | ||
| }); | ||
|
|
||
| it("mirrors Windows controls in rtl locales", () => { | ||
| expect(getWindowControlsLayout({ locale: "he", platform: "windows" })).toEqual({ | ||
| left: ["close", "maximize", "minimize"], | ||
| right: [], | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps Linux layout unchanged even in rtl locales", () => { | ||
| expect(getWindowControlsLayout({ locale: "ar", platform: "linux" })).toEqual({ | ||
| left: [], | ||
| right: ["minimize", "maximize", "close"], | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import type { DesktopPlatform, DesktopWindowControlsLayout } from "@t3tools/contracts"; | ||
| import type { LinuxTitleBarMode } from "@t3tools/contracts/settings"; | ||
| import { getLinuxWindowControlsLayout } from "./linuxWindowControls"; | ||
|
|
||
| const DESKTOP_TITLEBAR_HEIGHT = 52; | ||
| const RTL_LANGUAGES = new Set(["ar", "dv", "fa", "he", "ku", "ps", "sd", "ug", "ur", "yi"]); | ||
| const MACOS_WINDOW_CONTROLS_LAYOUT: DesktopWindowControlsLayout = { | ||
| left: ["close", "minimize", "maximize"], | ||
| right: [], | ||
| }; | ||
| const WINDOWS_WINDOW_CONTROLS_LAYOUT: DesktopWindowControlsLayout = { | ||
| left: [], | ||
| right: ["minimize", "maximize", "close"], | ||
| }; | ||
|
|
||
| export const platform: DesktopPlatform = (() => { | ||
| switch (process.platform) { | ||
| case "darwin": | ||
| return "macos"; | ||
| case "win32": | ||
| return "windows"; | ||
| case "linux": | ||
| return "linux"; | ||
| default: | ||
| throw new Error(`Unsupported desktop platform: ${process.platform}`); | ||
| } | ||
| })(); | ||
|
|
||
| function isRightToLeftLocale(locale: string | undefined): boolean { | ||
| if (!locale) { | ||
| return false; | ||
| } | ||
|
|
||
| const language = locale.split(/[-_]/, 1)[0]?.toLowerCase(); | ||
| return language !== undefined && RTL_LANGUAGES.has(language); | ||
| } | ||
|
|
||
| function mirrorWindowControlsLayout( | ||
| layout: DesktopWindowControlsLayout, | ||
| ): DesktopWindowControlsLayout { | ||
| return { | ||
| left: layout.right.toReversed(), | ||
| right: layout.left.toReversed(), | ||
| }; | ||
| } | ||
|
|
||
| export function getWindowControlsLayout(options?: { | ||
| locale?: string; | ||
| platform?: DesktopPlatform; | ||
| }): DesktopWindowControlsLayout { | ||
| const resolvedPlatform = options?.platform ?? platform; | ||
| if (resolvedPlatform === "linux") { | ||
| return getLinuxWindowControlsLayout(); | ||
| } | ||
|
|
||
| const rtl = isRightToLeftLocale(options?.locale); | ||
| const layout = | ||
| resolvedPlatform === "macos" ? MACOS_WINDOW_CONTROLS_LAYOUT : WINDOWS_WINDOW_CONTROLS_LAYOUT; | ||
|
|
||
| if (!rtl || resolvedPlatform === "macos") { | ||
| return layout; | ||
| } | ||
|
|
||
| return mirrorWindowControlsLayout(layout); | ||
| } | ||
|
|
||
| export function getWindowChromeOptions(linuxTitleBarMode: LinuxTitleBarMode): { | ||
| titleBarStyle?: "hiddenInset" | "hidden"; | ||
| titleBarOverlay?: { height: number }; | ||
| trafficLightPosition?: { x: number; y: number }; | ||
| } { | ||
| if (platform === "macos") { | ||
| return { | ||
| titleBarStyle: "hiddenInset", | ||
| trafficLightPosition: { x: 16, y: 18 }, | ||
| }; | ||
| } | ||
|
|
||
| if (platform === "linux") { | ||
| if (linuxTitleBarMode === "native") { | ||
| return {}; | ||
| } | ||
|
|
||
| if (linuxTitleBarMode === "overlay") { | ||
| return { | ||
| titleBarStyle: "hidden", | ||
| titleBarOverlay: { | ||
| height: DESKTOP_TITLEBAR_HEIGHT, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| titleBarStyle: "hidden", | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| titleBarStyle: "hidden", | ||
| titleBarOverlay: { | ||
| height: DESKTOP_TITLEBAR_HEIGHT, | ||
| }, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { getLinuxWindowControlsLayout } from "./linuxWindowControls"; | ||
|
|
||
| describe("getLinuxWindowControlsLayout", () => { | ||
| it("reads KDE button placement from kwinrc", () => { | ||
| const layout = getLinuxWindowControlsLayout({ | ||
| existsSync: vi.fn().mockReturnValue(true), | ||
| homeDir: "/home/tester", | ||
| readFileSync: vi | ||
| .fn() | ||
| .mockReturnValue("[org.kde.kdecoration2]\nButtonsOnLeft=XIA\nButtonsOnRight=M\n"), | ||
| spawnSync: vi.fn(), | ||
| }); | ||
|
|
||
| expect(layout).toEqual({ | ||
| left: ["close", "minimize", "maximize"], | ||
| right: [], | ||
| }); | ||
| }); | ||
|
|
||
| it("falls back to GNOME button placement when KDE config is unavailable", () => { | ||
| const layout = getLinuxWindowControlsLayout({ | ||
| existsSync: vi.fn().mockReturnValue(false), | ||
| homeDir: "/home/tester", | ||
| readFileSync: vi.fn(), | ||
| spawnSync: vi.fn().mockReturnValue({ | ||
| status: 0, | ||
| stdout: "'close,minimize:maximize'\n", | ||
| }), | ||
| }); | ||
|
|
||
| expect(layout).toEqual({ | ||
| left: ["close", "minimize"], | ||
| right: ["maximize"], | ||
| }); | ||
| }); | ||
|
|
||
| it("falls back when kwinrc exists but does not define button placement", () => { | ||
| const layout = getLinuxWindowControlsLayout({ | ||
| existsSync: vi.fn().mockReturnValue(true), | ||
| homeDir: "/home/tester", | ||
| readFileSync: vi.fn().mockReturnValue("[org.kde.kdecoration2]\n"), | ||
| spawnSync: vi.fn().mockReturnValue({ | ||
| status: 0, | ||
| stdout: "'close,minimize:maximize'\n", | ||
| }), | ||
| }); | ||
|
|
||
| expect(layout).toEqual({ | ||
| left: ["close", "minimize"], | ||
| right: ["maximize"], | ||
| }); | ||
| }); | ||
|
|
||
| it("falls back to GNOME when reading kwinrc throws", () => { | ||
| const layout = getLinuxWindowControlsLayout({ | ||
| existsSync: vi.fn().mockReturnValue(true), | ||
| homeDir: "/home/tester", | ||
| readFileSync: vi.fn().mockImplementation(() => { | ||
| throw new Error("permission denied"); | ||
| }), | ||
| spawnSync: vi.fn().mockReturnValue({ | ||
| status: 0, | ||
| stdout: "'close,minimize:maximize'\n", | ||
| }), | ||
| }); | ||
|
|
||
| expect(layout).toEqual({ | ||
| left: ["close", "minimize"], | ||
| right: ["maximize"], | ||
| }); | ||
| }); | ||
|
|
||
| it("uses the default right-side controls when no desktop layout is available", () => { | ||
| const layout = getLinuxWindowControlsLayout({ | ||
| existsSync: vi.fn().mockReturnValue(false), | ||
| homeDir: "/home/tester", | ||
| readFileSync: vi.fn(), | ||
| spawnSync: vi.fn().mockReturnValue({ | ||
| status: 1, | ||
| stdout: "", | ||
| }), | ||
| }); | ||
|
|
||
| expect(layout).toEqual({ | ||
| left: [], | ||
| right: ["minimize", "maximize", "close"], | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.