Skip to content
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

mac/title: use enum values instead of generic integers #15583

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions osdep/mac/app_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ 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_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,
Expand Down
39 changes: 27 additions & 12 deletions osdep/mac/app_bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,34 @@
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},
{"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}),
Expand Down
58 changes: 29 additions & 29 deletions video/out/mac/title_bar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,41 +92,41 @@ 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
}
}()
}

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
}
}()
Expand Down
Loading