Skip to content

Commit

Permalink
mac/title: use enum for appearance values instead of generic integers
Browse files Browse the repository at this point in the history
  • Loading branch information
Akemi committed Dec 28, 2024
1 parent e696b75 commit 4063cdf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
12 changes: 12 additions & 0 deletions osdep/mac/app_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions osdep/mac/app_bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
20 changes: 10 additions & 10 deletions video/out/mac/title_bar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}()
Expand Down

0 comments on commit 4063cdf

Please sign in to comment.