diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-26 09:10:54 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-26 09:10:54 +0300 |
commit | fe5c4c70cc19c1636af7b00ddbcbb6ae347acdf9 (patch) | |
tree | 1b0196d1b673b787dd54f018b2522f338408b22d | |
parent | 5843195683f56797d0f637205851f69289047343 (diff) |
macOS: Experiment with system accent color
This doesn't quite fit in the palette system currently, but it would be a nice addition later.
-rw-r--r-- | src/macos.m | 8 | ||||
-rw-r--r-- | src/prefs.h | 2 | ||||
-rw-r--r-- | src/ui/color.c | 11 | ||||
-rw-r--r-- | src/ui/color.h | 3 | ||||
-rw-r--r-- | src/ui/util.c | 4 |
5 files changed, 27 insertions, 1 deletions
diff --git a/src/macos.m b/src/macos.m index 78b964ae..658acb05 100644 --- a/src/macos.m +++ b/src/macos.m | |||
@@ -684,3 +684,11 @@ void showPopupMenu_MacOS(iWidget *source, iInt2 windowCoord, const iMenuItem *it | |||
684 | } | 684 | } |
685 | } | 685 | } |
686 | 686 | ||
687 | iColor systemAccent_Color(void) { | ||
688 | NSColor *accent = [[NSColor controlAccentColor] colorUsingColorSpace: | ||
689 | [NSColorSpace deviceRGBColorSpace]]; | ||
690 | return (iColor){ iClamp([accent redComponent] * 255, 0, 255), | ||
691 | iClamp([accent greenComponent] * 255, 0, 255), | ||
692 | iClamp([accent blueComponent] * 255, 0, 255), | ||
693 | 255 }; | ||
694 | } | ||
diff --git a/src/prefs.h b/src/prefs.h index 87c9a6e6..37aeb260 100644 --- a/src/prefs.h +++ b/src/prefs.h | |||
@@ -43,7 +43,7 @@ struct Impl_Prefs { | |||
43 | /* Window */ | 43 | /* Window */ |
44 | iString uiLanguage; | 44 | iString uiLanguage; |
45 | iBool useSystemTheme; | 45 | iBool useSystemTheme; |
46 | enum iColorTheme theme; | 46 | enum iColorTheme theme; |
47 | enum iColorAccent accent; | 47 | enum iColorAccent accent; |
48 | iBool customFrame; /* when LAGRANGE_ENABLE_CUSTOM_FRAME is defined */ | 48 | iBool customFrame; /* when LAGRANGE_ENABLE_CUSTOM_FRAME is defined */ |
49 | iBool retainWindowSize; | 49 | iBool retainWindowSize; |
diff --git a/src/ui/color.c b/src/ui/color.c index 9da49531..4f275ae5 100644 --- a/src/ui/color.c +++ b/src/ui/color.c | |||
@@ -81,6 +81,11 @@ iLocalDef void copy_(enum iColorId dst, enum iColorId src) { | |||
81 | void setThemePalette_Color(enum iColorTheme theme) { | 81 | void setThemePalette_Color(enum iColorTheme theme) { |
82 | const iPrefs *prefs = prefs_App(); | 82 | const iPrefs *prefs = prefs_App(); |
83 | memcpy(uiPalette_, isDark_ColorTheme(theme) ? darkPalette_ : lightPalette_, sizeof(darkPalette_)); | 83 | memcpy(uiPalette_, isDark_ColorTheme(theme) ? darkPalette_ : lightPalette_, sizeof(darkPalette_)); |
84 | if (prefs->accent == system_ColorAccent) { | ||
85 | iColor systemColor = systemAccent_Color(); | ||
86 | memcpy(&uiPalette_[cyan_ColorId], &systemColor, sizeof(iColor)); | ||
87 | memcpy(&uiPalette_[orange_ColorId], &systemColor, sizeof(iColor)); | ||
88 | } | ||
84 | const int accentHi = (prefs->accent == cyan_ColorAccent ? cyan_ColorId : orange_ColorId); | 89 | const int accentHi = (prefs->accent == cyan_ColorAccent ? cyan_ColorId : orange_ColorId); |
85 | const int accentLo = (prefs->accent == cyan_ColorAccent ? teal_ColorId : brown_ColorId); | 90 | const int accentLo = (prefs->accent == cyan_ColorAccent ? teal_ColorId : brown_ColorId); |
86 | const int altAccentHi = (prefs->accent == cyan_ColorAccent ? orange_ColorId : cyan_ColorId); | 91 | const int altAccentHi = (prefs->accent == cyan_ColorAccent ? orange_ColorId : cyan_ColorId); |
@@ -903,3 +908,9 @@ iBool loadPalette_Color(const char *path) { | |||
903 | iRelease(f); | 908 | iRelease(f); |
904 | return wasLoaded; | 909 | return wasLoaded; |
905 | } | 910 | } |
911 | |||
912 | #if !defined (iPlatformAppleDesktop) | ||
913 | iColor systemAccent_Color(void) { | ||
914 | return (iColor){ 255, 255, 255, 255 }; | ||
915 | } | ||
916 | #endif | ||
diff --git a/src/ui/color.h b/src/ui/color.h index b6571c86..179db3e9 100644 --- a/src/ui/color.h +++ b/src/ui/color.h | |||
@@ -36,6 +36,7 @@ enum iColorTheme { | |||
36 | enum iColorAccent { | 36 | enum iColorAccent { |
37 | cyan_ColorAccent, | 37 | cyan_ColorAccent, |
38 | orange_ColorAccent, | 38 | orange_ColorAccent, |
39 | system_ColorAccent, | ||
39 | max_ColorAccent | 40 | max_ColorAccent |
40 | }; | 41 | }; |
41 | 42 | ||
@@ -251,3 +252,5 @@ void setThemePalette_Color (enum iColorTheme theme); | |||
251 | iColor ansiForeground_Color (iRangecc escapeSequence, int fallback); | 252 | iColor ansiForeground_Color (iRangecc escapeSequence, int fallback); |
252 | const char * escape_Color (int color); | 253 | const char * escape_Color (int color); |
253 | enum iColorId parseEscape_Color (const char *cstr, const char **endp); | 254 | enum iColorId parseEscape_Color (const char *cstr, const char **endp); |
255 | |||
256 | iColor systemAccent_Color (void); /* platform-specific impl */ | ||
diff --git a/src/ui/util.c b/src/ui/util.c index 872a91ab..2a0c89dc 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -2416,6 +2416,10 @@ iWidget *makePreferences_Widget(void) { | |||
2416 | iWidget *accent = new_Widget(); { | 2416 | iWidget *accent = new_Widget(); { |
2417 | setId_Widget(addChild_Widget(accent, iClob(new_LabelWidget("${prefs.accent.teal}", "accent.set arg:0"))), "prefs.accent.0"); | 2417 | setId_Widget(addChild_Widget(accent, iClob(new_LabelWidget("${prefs.accent.teal}", "accent.set arg:0"))), "prefs.accent.0"); |
2418 | setId_Widget(addChild_Widget(accent, iClob(new_LabelWidget("${prefs.accent.orange}", "accent.set arg:1"))), "prefs.accent.1"); | 2418 | setId_Widget(addChild_Widget(accent, iClob(new_LabelWidget("${prefs.accent.orange}", "accent.set arg:1"))), "prefs.accent.1"); |
2419 | #if defined (iPlatformApple) | ||
2420 | /* TODO: Needs some tweaking. */ | ||
2421 | // setId_Widget(addChild_Widget(accent, iClob(new_LabelWidget("${prefs.accent.system}", "accent.set arg:2"))), "prefs.accent.2"); | ||
2422 | #endif | ||
2419 | } | 2423 | } |
2420 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.accent}"))); | 2424 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.accent}"))); |
2421 | addChildFlags_Widget(values, iClob(accent), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); | 2425 | addChildFlags_Widget(values, iClob(accent), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); |