From 05d52574e5337bd53bee10d95405ca739af7233a Mon Sep 17 00:00:00 2001 From: der richter Date: Thu, 26 Dec 2024 17:38:11 +0100 Subject: [PATCH 1/2] mac/title: use enum for appearance values instead of generic integers --- osdep/mac/app_bridge.h | 12 ++++++++++++ osdep/mac/app_bridge.m | 14 +++++++++----- video/out/mac/title_bar.swift | 20 ++++++++++---------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/osdep/mac/app_bridge.h b/osdep/mac/app_bridge.h index edc6cc0b74b59..0e10c5bc5bdab 100644 --- a/osdep/mac/app_bridge.h +++ b/osdep/mac/app_bridge.h @@ -35,6 +35,18 @@ enum { RENDER_TIMER_PRECISE, }; +enum { + MAC_APPEAR_AUTO = 0, + MAC_APPEAR_AQUA, + MAC_APPEAR_DARK_AQUA, + MAC_APPEAR_VIBRANT_LIGHT, + MAC_APPEAR_VIBRANT_DARK, + MAC_APPEAR_AQUA_HC, + MAC_APPEAR_DARK_AQUA_HC, + MAC_APPEAR_VIBRANT_LIGHT_HC, + MAC_APPEAR_VIBRANT_DARK_HC, +}; + enum { MAC_CSP_AUTO = -1, MAC_CSP_DISPLAY_P3, diff --git a/osdep/mac/app_bridge.m b/osdep/mac/app_bridge.m index 530fa2dd3168f..e11b5635f30d4 100644 --- a/osdep/mac/app_bridge.m +++ b/osdep/mac/app_bridge.m @@ -27,11 +27,15 @@ const struct m_sub_options macos_conf = { .opts = (const struct m_option[]) { {"macos-title-bar-appearance", OPT_CHOICE(macos_title_bar_appearance, - {"auto", 0}, {"aqua", 1}, {"darkAqua", 2}, - {"vibrantLight", 3}, {"vibrantDark", 4}, - {"aquaHighContrast", 5}, {"darkAquaHighContrast", 6}, - {"vibrantLightHighContrast", 7}, - {"vibrantDarkHighContrast", 8})}, + {"auto", MAC_APPEAR_AUTO}, + {"aqua", MAC_APPEAR_AQUA}, + {"darkAqua", MAC_APPEAR_DARK_AQUA}, + {"vibrantLight", MAC_APPEAR_VIBRANT_LIGHT}, + {"vibrantDark", MAC_APPEAR_VIBRANT_DARK}, + {"aquaHighContrast", MAC_APPEAR_AQUA_HC}, + {"darkAquaHighContrast", MAC_APPEAR_DARK_AQUA_HC}, + {"vibrantLightHighContrast", MAC_APPEAR_VIBRANT_LIGHT_HC}, + {"vibrantDarkHighContrast", MAC_APPEAR_VIBRANT_DARK_HC})}, {"macos-title-bar-material", OPT_CHOICE(macos_title_bar_material, {"titlebar", 0}, {"selection", 1}, {"menu", 2}, {"popover", 3}, {"sidebar", 4}, {"headerView", 5}, diff --git a/video/out/mac/title_bar.swift b/video/out/mac/title_bar.swift index 5d31b1615c4bc..ff8f86b1c420d 100644 --- a/video/out/mac/title_bar.swift +++ b/video/out/mac/title_bar.swift @@ -92,16 +92,16 @@ class TitleBar: NSVisualEffectView { } func set(appearance: Int32) { - window?.appearance = { switch appearance { - case 1: return NSAppearance(named: .aqua) - case 2: return NSAppearance(named: .darkAqua) - case 3: return NSAppearance(named: .vibrantLight) - case 4: return NSAppearance(named: .vibrantDark) - case 5: return NSAppearance(named: .accessibilityHighContrastAqua) - case 6: return NSAppearance(named: .accessibilityHighContrastDarkAqua) - case 7: return NSAppearance(named: .accessibilityHighContrastVibrantLight) - case 8: return NSAppearance(named: .accessibilityHighContrastVibrantDark) - case 0: return nil + window?.appearance = { switch Int(appearance) { + case MAC_APPEAR_AQUA: return NSAppearance(named: .aqua) + case MAC_APPEAR_DARK_AQUA: return NSAppearance(named: .darkAqua) + case MAC_APPEAR_VIBRANT_LIGHT: return NSAppearance(named: .vibrantLight) + case MAC_APPEAR_VIBRANT_DARK: return NSAppearance(named: .vibrantDark) + case MAC_APPEAR_AQUA_HC: return NSAppearance(named: .accessibilityHighContrastAqua) + case MAC_APPEAR_DARK_AQUA_HC: return NSAppearance(named: .accessibilityHighContrastDarkAqua) + case MAC_APPEAR_VIBRANT_LIGHT_HC: return NSAppearance(named: .accessibilityHighContrastVibrantLight) + case MAC_APPEAR_VIBRANT_DARK_HC: return NSAppearance(named: .accessibilityHighContrastVibrantDark) + case MAC_APPEAR_AUTO: return nil default: return nil } }() From 5a823d619218adf134b5d2c1d3aaff0051c2592c Mon Sep 17 00:00:00 2001 From: der richter Date: Thu, 26 Dec 2024 17:47:44 +0100 Subject: [PATCH 2/2] mac/title: use enum for material values instead of generic integers --- osdep/mac/app_bridge.h | 21 +++++++++++++++++++ osdep/mac/app_bridge.m | 25 ++++++++++++++++------- video/out/mac/title_bar.swift | 38 +++++++++++++++++------------------ 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/osdep/mac/app_bridge.h b/osdep/mac/app_bridge.h index 0e10c5bc5bdab..961b01ca8b2bb 100644 --- a/osdep/mac/app_bridge.h +++ b/osdep/mac/app_bridge.h @@ -47,6 +47,27 @@ enum { MAC_APPEAR_VIBRANT_DARK_HC, }; +enum { + MAC_MAT_TITLEBAR = 0, + MAC_MAT_SELECTION, + MAC_MAT_MENU, + MAC_MAT_POPOVER, + MAC_MAT_SIDEBAR, + MAC_MAT_HEADER_VIEW, + MAC_MAT_SHEET, + MAC_MAT_WINDOW_BACKGROUND, + MAC_MAT_HUD_WINDOW, + MAC_MAT_FULL_SCREEN, + MAC_MAT_TOOL_TIP, + MAC_MAT_CONTENT_BACKGROUND, + MAC_MAT_UNDER_WINDOW_BACKGROUND, + MAC_MAT_UNDER_PAGE_BACKGROUND, + MAC_MAT_DARK, + MAC_MAT_LIGHT, + MAC_MAT_MEDIUM_LIGHT, + MAC_MAT_ULTRA_DARK, +}; + enum { MAC_CSP_AUTO = -1, MAC_CSP_DISPLAY_P3, diff --git a/osdep/mac/app_bridge.m b/osdep/mac/app_bridge.m index e11b5635f30d4..8f256034e1743 100644 --- a/osdep/mac/app_bridge.m +++ b/osdep/mac/app_bridge.m @@ -37,13 +37,24 @@ {"vibrantLightHighContrast", MAC_APPEAR_VIBRANT_LIGHT_HC}, {"vibrantDarkHighContrast", MAC_APPEAR_VIBRANT_DARK_HC})}, {"macos-title-bar-material", OPT_CHOICE(macos_title_bar_material, - {"titlebar", 0}, {"selection", 1}, {"menu", 2}, - {"popover", 3}, {"sidebar", 4}, {"headerView", 5}, - {"sheet", 6}, {"windowBackground", 7}, {"hudWindow", 8}, - {"fullScreen", 9}, {"toolTip", 10}, {"contentBackground", 11}, - {"underWindowBackground", 12}, {"underPageBackground", 13}, - {"dark", 14}, {"light", 15}, {"mediumLight", 16}, - {"ultraDark", 17})}, + {"titlebar", MAC_MAT_TITLEBAR}, + {"selection", MAC_MAT_SELECTION}, + {"menu", MAC_MAT_MENU}, + {"popover", MAC_MAT_POPOVER}, + {"sidebar", MAC_MAT_SIDEBAR}, + {"headerView", MAC_MAT_HEADER_VIEW}, + {"sheet", MAC_MAT_SHEET}, + {"windowBackground", MAC_MAT_WINDOW_BACKGROUND}, + {"hudWindow", MAC_MAT_HUD_WINDOW}, + {"fullScreen", MAC_MAT_FULL_SCREEN}, + {"toolTip", MAC_MAT_TOOL_TIP}, + {"contentBackground", MAC_MAT_CONTENT_BACKGROUND}, + {"underWindowBackground", MAC_MAT_UNDER_WINDOW_BACKGROUND}, + {"underPageBackground", MAC_MAT_UNDER_PAGE_BACKGROUND}, + {"dark", MAC_MAT_DARK}, + {"light", MAC_MAT_LIGHT}, + {"mediumLight", MAC_MAT_MEDIUM_LIGHT}, + {"ultraDark", MAC_MAT_ULTRA_DARK})}, {"macos-title-bar-color", OPT_COLOR(macos_title_bar_color)}, {"macos-fs-animation-duration", OPT_CHOICE(macos_fs_animation_duration, {"default", -1}), diff --git a/video/out/mac/title_bar.swift b/video/out/mac/title_bar.swift index ff8f86b1c420d..f2408fd1d057e 100644 --- a/video/out/mac/title_bar.swift +++ b/video/out/mac/title_bar.swift @@ -108,25 +108,25 @@ class TitleBar: NSVisualEffectView { } func set(material: Int32) { - self.material = { switch material { - case 0: return .titlebar - case 1: return .selection - case 2: return .menu - case 3: return .popover - case 4: return .sidebar - case 5: return .headerView - case 6: return .sheet - case 7: return .windowBackground - case 8: return .hudWindow - case 9: return .fullScreenUI - case 10: return .toolTip - case 11: return .contentBackground - case 12: return .underWindowBackground - case 13: return .underPageBackground - case 14: return .dark - case 15: return .light - case 16: return .mediumLight - case 17: return .ultraDark + self.material = { switch Int(material) { + case MAC_MAT_TITLEBAR: return .titlebar + case MAC_MAT_SELECTION: return .selection + case MAC_MAT_MENU: return .menu + case MAC_MAT_POPOVER: return .popover + case MAC_MAT_SIDEBAR: return .sidebar + case MAC_MAT_HEADER_VIEW: return .headerView + case MAC_MAT_SHEET: return .sheet + case MAC_MAT_WINDOW_BACKGROUND: return .windowBackground + case MAC_MAT_HUD_WINDOW: return .hudWindow + case MAC_MAT_FULL_SCREEN: return .fullScreenUI + case MAC_MAT_TOOL_TIP: return .toolTip + case MAC_MAT_CONTENT_BACKGROUND: return .contentBackground + case MAC_MAT_UNDER_WINDOW_BACKGROUND: return .underWindowBackground + case MAC_MAT_UNDER_PAGE_BACKGROUND: return .underPageBackground + case MAC_MAT_DARK: return .dark + case MAC_MAT_LIGHT: return .light + case MAC_MAT_MEDIUM_LIGHT: return .mediumLight + case MAC_MAT_ULTRA_DARK: return .ultraDark default: return .titlebar } }()