From 4ff5e04e846181485cc8eeab6d09033d8ed47733 Mon Sep 17 00:00:00 2001 From: Khaled Date: Sun, 2 Aug 2026 15:26:06 +0100 Subject: [PATCH 1/2] Fix Hyprland startup Ozone platform --- electron/gpuSwitches.test.ts | 60 +++++++++++++++++++++++++++++++++++- electron/gpuSwitches.ts | 25 +++++++++++++-- electron/main.ts | 15 ++++++--- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/electron/gpuSwitches.test.ts b/electron/gpuSwitches.test.ts index 4cbb1cdf4..e7fdc7917 100644 --- a/electron/gpuSwitches.test.ts +++ b/electron/gpuSwitches.test.ts @@ -1,6 +1,11 @@ import { describe, expect, it } from "vitest"; -import { getGpuSwitches, shouldForceLinuxEgl } from "./gpuSwitches"; +import { + getGpuSwitches, + getLinuxOzonePlatformOverride, + isHyprlandSession, + shouldForceLinuxEgl, +} from "./gpuSwitches"; describe("shouldForceLinuxEgl", () => { it("does not force EGL in a Wayland session", () => { @@ -65,3 +70,56 @@ describe("getGpuSwitches", () => { }); }); }); + +describe("isHyprlandSession", () => { + it("detects Hyprland from the compositor instance signature", () => { + expect(isHyprlandSession({ HYPRLAND_INSTANCE_SIGNATURE: "abc" })).toBe(true); + }); + + it("detects Hyprland from XDG_CURRENT_DESKTOP", () => { + expect(isHyprlandSession({ XDG_CURRENT_DESKTOP: "Hyprland" })).toBe(true); + expect(isHyprlandSession({ XDG_CURRENT_DESKTOP: "sway:Hyprland" })).toBe(true); + }); + + it("ignores non-Hyprland sessions", () => { + expect(isHyprlandSession({ XDG_CURRENT_DESKTOP: "GNOME" })).toBe(false); + }); +}); + +describe("getLinuxOzonePlatformOverride", () => { + it("defaults Hyprland to X11/Ozone", () => { + expect( + getLinuxOzonePlatformOverride({ + XDG_SESSION_TYPE: "wayland", + XDG_CURRENT_DESKTOP: "Hyprland", + }), + ).toBe("x11"); + }); + + it("does not override an explicit Wayland request", () => { + expect( + getLinuxOzonePlatformOverride({ + XDG_CURRENT_DESKTOP: "Hyprland", + ELECTRON_OZONE_PLATFORM_HINT: "wayland", + }), + ).toBeNull(); + }); + + it("does not override an explicit X11 request", () => { + expect( + getLinuxOzonePlatformOverride({ + XDG_CURRENT_DESKTOP: "Hyprland", + OZONE_PLATFORM: "x11", + }), + ).toBeNull(); + }); + + it("does not affect other Linux desktops", () => { + expect( + getLinuxOzonePlatformOverride({ + XDG_SESSION_TYPE: "wayland", + XDG_CURRENT_DESKTOP: "GNOME", + }), + ).toBeNull(); + }); +}); diff --git a/electron/gpuSwitches.ts b/electron/gpuSwitches.ts index 7b7c81ee8..fa239847c 100644 --- a/electron/gpuSwitches.ts +++ b/electron/gpuSwitches.ts @@ -4,7 +4,9 @@ export interface GpuSwitches { disableFeatures?: string[]; } -function normalizeLinuxWindowSystem(value: string | undefined): "wayland" | "x11" | null { +export type LinuxOzonePlatform = "wayland" | "x11"; + +function normalizeLinuxWindowSystem(value: string | undefined): LinuxOzonePlatform | null { const normalized = value?.trim().toLowerCase(); if (normalized === "wayland" || normalized === "x11") { return normalized; @@ -13,13 +15,32 @@ function normalizeLinuxWindowSystem(value: string | undefined): "wayland" | "x11 return null; } -function getForcedLinuxWindowSystem(env: NodeJS.ProcessEnv): "wayland" | "x11" | null { +function getForcedLinuxWindowSystem(env: NodeJS.ProcessEnv): LinuxOzonePlatform | null { return ( normalizeLinuxWindowSystem(env.OZONE_PLATFORM) ?? normalizeLinuxWindowSystem(env.ELECTRON_OZONE_PLATFORM_HINT) ); } +export function isHyprlandSession(env: NodeJS.ProcessEnv): boolean { + const currentDesktop = env.XDG_CURRENT_DESKTOP?.toLowerCase() ?? ""; + const desktopSession = env.DESKTOP_SESSION?.toLowerCase() ?? ""; + + return Boolean( + env.HYPRLAND_INSTANCE_SIGNATURE || + currentDesktop.split(":").includes("hyprland") || + desktopSession.includes("hyprland"), + ); +} + +export function getLinuxOzonePlatformOverride(env: NodeJS.ProcessEnv): LinuxOzonePlatform | null { + if (getForcedLinuxWindowSystem(env)) { + return null; + } + + return isHyprlandSession(env) ? "x11" : null; +} + export function shouldForceLinuxEgl(env: NodeJS.ProcessEnv): boolean { const forcedWindowSystem = getForcedLinuxWindowSystem(env); if (forcedWindowSystem === "wayland") { diff --git a/electron/main.ts b/electron/main.ts index 38f4333ff..ccbdb5616 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -19,7 +19,7 @@ import { import { RECORDINGS_DIR } from "./appPaths"; import { showCursor } from "./cursorHider"; import { registerExtensionIpcHandlers } from "./extensions/extensionIpc"; -import { getGpuSwitches } from "./gpuSwitches"; +import { getGpuSwitches, getLinuxOzonePlatformOverride } from "./gpuSwitches"; import { cleanupAllExportStreams, cleanupNativeVideoExportSessions, @@ -30,10 +30,7 @@ import { import { ensureMediaServer } from "./mediaServer"; import { shouldGrantDisplayCapture, shouldGrantMediaPermission } from "./permissionPolicy"; import { ensurePackagedRendererServer, getPackagedRendererBaseUrl } from "./rendererServer"; -import { - hardenWebContentsNavigation, - shouldHardenWebContentsType, -} from "./navigationPolicy"; +import { hardenWebContentsNavigation, shouldHardenWebContentsType } from "./navigationPolicy"; import type { UpdateToastPayload } from "./updater"; import { checkForAppUpdates, @@ -89,6 +86,14 @@ app.on("web-contents-created", (_event, contents) => { }); function configureGpuAccelerationSwitches() { + if (process.platform === "linux" && !app.commandLine.hasSwitch("ozone-platform")) { + const ozonePlatform = getLinuxOzonePlatformOverride(process.env); + if (ozonePlatform) { + process.env.ELECTRON_OZONE_PLATFORM_HINT = ozonePlatform; + app.commandLine.appendSwitch("ozone-platform", ozonePlatform); + } + } + const { useAngle, useGl, disableFeatures } = getGpuSwitches(process.platform, process.env); if (useAngle) { app.commandLine.appendSwitch("use-angle", useAngle); From a49743cc64ac5ffb93053a1547a46e8575c9bd77 Mon Sep 17 00:00:00 2001 From: Khaled Date: Sun, 2 Aug 2026 15:41:45 +0100 Subject: [PATCH 2/2] Address Ozone override review --- electron/gpuSwitches.test.ts | 13 ++++++------- electron/gpuSwitches.ts | 5 +---- electron/main.ts | 1 - 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/electron/gpuSwitches.test.ts b/electron/gpuSwitches.test.ts index e7fdc7917..8ff7dfb5c 100644 --- a/electron/gpuSwitches.test.ts +++ b/electron/gpuSwitches.test.ts @@ -26,24 +26,23 @@ describe("shouldForceLinuxEgl", () => { ).toBe(false); }); - it("falls back to Electron's ozone hint when OZONE_PLATFORM is invalid", () => { + it("ignores invalid OZONE_PLATFORM values", () => { expect( shouldForceLinuxEgl({ OZONE_PLATFORM: "auto", - ELECTRON_OZONE_PLATFORM_HINT: "wayland", XDG_SESSION_TYPE: "x11", }), - ).toBe(false); + ).toBe(true); }); it("forces EGL in an X11 session", () => { expect(shouldForceLinuxEgl({ XDG_SESSION_TYPE: "x11" })).toBe(true); }); - it("forces EGL when x11 is explicitly requested via Electron's ozone hint", () => { + it("forces EGL when X11 is explicitly requested via OZONE_PLATFORM", () => { expect( shouldForceLinuxEgl({ - ELECTRON_OZONE_PLATFORM_HINT: "x11", + OZONE_PLATFORM: "x11", WAYLAND_DISPLAY: "wayland-0", }), ).toBe(true); @@ -96,11 +95,11 @@ describe("getLinuxOzonePlatformOverride", () => { ).toBe("x11"); }); - it("does not override an explicit Wayland request", () => { + it("does not override an explicit Wayland request via OZONE_PLATFORM", () => { expect( getLinuxOzonePlatformOverride({ XDG_CURRENT_DESKTOP: "Hyprland", - ELECTRON_OZONE_PLATFORM_HINT: "wayland", + OZONE_PLATFORM: "wayland", }), ).toBeNull(); }); diff --git a/electron/gpuSwitches.ts b/electron/gpuSwitches.ts index fa239847c..82f4a870b 100644 --- a/electron/gpuSwitches.ts +++ b/electron/gpuSwitches.ts @@ -16,10 +16,7 @@ function normalizeLinuxWindowSystem(value: string | undefined): LinuxOzonePlatfo } function getForcedLinuxWindowSystem(env: NodeJS.ProcessEnv): LinuxOzonePlatform | null { - return ( - normalizeLinuxWindowSystem(env.OZONE_PLATFORM) ?? - normalizeLinuxWindowSystem(env.ELECTRON_OZONE_PLATFORM_HINT) - ); + return normalizeLinuxWindowSystem(env.OZONE_PLATFORM); } export function isHyprlandSession(env: NodeJS.ProcessEnv): boolean { diff --git a/electron/main.ts b/electron/main.ts index ccbdb5616..fbb2fee8e 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -89,7 +89,6 @@ function configureGpuAccelerationSwitches() { if (process.platform === "linux" && !app.commandLine.hasSwitch("ozone-platform")) { const ozonePlatform = getLinuxOzonePlatformOverride(process.env); if (ozonePlatform) { - process.env.ELECTRON_OZONE_PLATFORM_HINT = ozonePlatform; app.commandLine.appendSwitch("ozone-platform", ozonePlatform); } }