mirror of
https://github.com/Boof2015/prism.git
synced 2026-08-19 12:04:18 +02:00
initial transparency
This commit is contained in:
@@ -4,6 +4,7 @@ interface WindowCapabilityResolutionOptions {
|
||||
platform: string
|
||||
argv?: readonly string[]
|
||||
env?: Record<string, string | undefined>
|
||||
osVersion?: string
|
||||
}
|
||||
|
||||
export const DEFAULT_WINDOW_CAPABILITIES: WindowCapabilities = {
|
||||
@@ -11,6 +12,21 @@ export const DEFAULT_WINDOW_CAPABILITIES: WindowCapabilities = {
|
||||
useNativeDragRegions: false,
|
||||
supportsProgrammaticReposition: true,
|
||||
supportsGeometryPersistence: true,
|
||||
supportsBlurredBackground: false,
|
||||
}
|
||||
|
||||
// Blurred mode uses accent-policy acrylic (SetWindowCompositionAttribute),
|
||||
// which technically exists since Windows 10 1803, but drag/repaint performance
|
||||
// is only dependable on Windows 11 22H2 (build 22621) — gate it there.
|
||||
const WINDOWS_ACRYLIC_MIN_BUILD = 22621
|
||||
|
||||
function windowsBuildSupportsAcrylic(osVersion: string | undefined): boolean {
|
||||
if (!osVersion) {
|
||||
return false
|
||||
}
|
||||
|
||||
const build = Number.parseInt(osVersion.split('.')[2] ?? '', 10)
|
||||
return Number.isFinite(build) && build >= WINDOWS_ACRYLIC_MIN_BUILD
|
||||
}
|
||||
|
||||
function readSwitchValue(argv: readonly string[], switchName: string): string | null {
|
||||
@@ -80,6 +96,8 @@ export function resolveWindowCapabilities(options: WindowCapabilityResolutionOpt
|
||||
return {
|
||||
...DEFAULT_WINDOW_CAPABILITIES,
|
||||
useNativeDragRegions: true,
|
||||
supportsBlurredBackground: options.platform === 'darwin'
|
||||
|| windowsBuildSupportsAcrylic(options.osVersion),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,5 +113,6 @@ export function resolveWindowCapabilities(options: WindowCapabilityResolutionOpt
|
||||
useNativeDragRegions: isNativeWayland,
|
||||
supportsProgrammaticReposition: !isNativeWayland,
|
||||
supportsGeometryPersistence: !isNativeWayland,
|
||||
supportsBlurredBackground: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,36 @@ import {
|
||||
WINDOW_LOCAL_STATE_FORMAT,
|
||||
WINDOW_LOCAL_STATE_VERSION,
|
||||
type PrismWindowLocalStateV1,
|
||||
type WindowBackgroundMode,
|
||||
type WindowBackgroundState,
|
||||
} from '../types/windowState'
|
||||
|
||||
const WINDOW_BACKGROUND_MODES: readonly WindowBackgroundMode[] = ['solid', 'blurred', 'clear']
|
||||
|
||||
export function createDefaultWindowBackgroundState(): WindowBackgroundState {
|
||||
return {
|
||||
mode: 'solid',
|
||||
transparency: 50,
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeWindowBackgroundState(raw: unknown): WindowBackgroundState {
|
||||
const fallback = createDefaultWindowBackgroundState()
|
||||
if (typeof raw !== 'object' || raw === null) {
|
||||
return fallback
|
||||
}
|
||||
|
||||
const candidate = raw as Partial<WindowBackgroundState>
|
||||
const mode = WINDOW_BACKGROUND_MODES.includes(candidate.mode as WindowBackgroundMode)
|
||||
? candidate.mode as WindowBackgroundMode
|
||||
: fallback.mode
|
||||
const transparency = typeof candidate.transparency === 'number' && Number.isFinite(candidate.transparency)
|
||||
? Math.min(100, Math.max(0, Math.round(candidate.transparency)))
|
||||
: fallback.transparency
|
||||
|
||||
return { mode, transparency }
|
||||
}
|
||||
|
||||
export function createEmptyWindowLocalState(): PrismWindowLocalStateV1 {
|
||||
return {
|
||||
format: WINDOW_LOCAL_STATE_FORMAT,
|
||||
@@ -13,6 +41,7 @@ export function createEmptyWindowLocalState(): PrismWindowLocalStateV1 {
|
||||
mainAlwaysOnTop: false,
|
||||
popoutAlwaysOnTop: {},
|
||||
nowPlayingConfigWindowBounds: undefined,
|
||||
windowBackground: createDefaultWindowBackgroundState(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,5 +66,6 @@ export function normalizeWindowLocalState(raw: unknown): PrismWindowLocalStateV1
|
||||
mainAlwaysOnTop: parsed.mainAlwaysOnTop === true,
|
||||
popoutAlwaysOnTop,
|
||||
nowPlayingConfigWindowBounds: normalizeWindowBounds(parsed.nowPlayingConfigWindowBounds),
|
||||
windowBackground: normalizeWindowBackgroundState(parsed.windowBackground),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user