diff options
-rw-r--r-- | src/app.c | 36 | ||||
-rw-r--r-- | src/prefs.c | 1 | ||||
-rw-r--r-- | src/prefs.h | 1 |
3 files changed, 31 insertions, 7 deletions
@@ -124,6 +124,7 @@ struct Impl_App { | |||
124 | uint32_t elapsedSinceLastTicker; | 124 | uint32_t elapsedSinceLastTicker; |
125 | iBool isRunning; | 125 | iBool isRunning; |
126 | iBool isRunningUnderWindowSystem; | 126 | iBool isRunningUnderWindowSystem; |
127 | iBool isDarkSystemTheme; | ||
127 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) | 128 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
128 | iBool isIdling; | 129 | iBool isIdling; |
129 | uint32_t lastEventTime; | 130 | uint32_t lastEventTime; |
@@ -246,7 +247,10 @@ static iString *serializePrefs_App_(const iApp *d) { | |||
246 | appendFormat_String(str, "quoteicon.set arg:%d\n", d->prefs.quoteIcon ? 1 : 0); | 247 | appendFormat_String(str, "quoteicon.set arg:%d\n", d->prefs.quoteIcon ? 1 : 0); |
247 | appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme); | 248 | appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme); |
248 | appendFormat_String(str, "accent.set arg:%d\n", d->prefs.accent); | 249 | appendFormat_String(str, "accent.set arg:%d\n", d->prefs.accent); |
249 | appendFormat_String(str, "ostheme arg:%d\n", d->prefs.useSystemTheme); | 250 | appendFormat_String(str, "ostheme arg:%d preferdark:%d preferlight:%d\n", |
251 | d->prefs.useSystemTheme, | ||
252 | d->prefs.systemPreferredColorTheme[0], | ||
253 | d->prefs.systemPreferredColorTheme[1]); | ||
250 | appendFormat_String(str, "doctheme.dark.set arg:%d\n", d->prefs.docThemeDark); | 254 | appendFormat_String(str, "doctheme.dark.set arg:%d\n", d->prefs.docThemeDark); |
251 | appendFormat_String(str, "doctheme.light.set arg:%d\n", d->prefs.docThemeLight); | 255 | appendFormat_String(str, "doctheme.light.set arg:%d\n", d->prefs.docThemeLight); |
252 | appendFormat_String(str, "saturation.set arg:%d\n", (int) ((d->prefs.saturation * 100) + 0.5f)); | 256 | appendFormat_String(str, "saturation.set arg:%d\n", (int) ((d->prefs.saturation * 100) + 0.5f)); |
@@ -657,6 +661,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
657 | #else | 661 | #else |
658 | d->isRunningUnderWindowSystem = iTrue; | 662 | d->isRunningUnderWindowSystem = iTrue; |
659 | #endif | 663 | #endif |
664 | d->isDarkSystemTheme = iTrue; /* will be updated by system later on, if supported */ | ||
660 | init_CommandLine(&d->args, argc, argv); | 665 | init_CommandLine(&d->args, argc, argv); |
661 | /* Where was the app started from? We ask SDL first because the command line alone is | 666 | /* Where was the app started from? We ask SDL first because the command line alone is |
662 | not a reliable source of this information, particularly when it comes to different | 667 | not a reliable source of this information, particularly when it comes to different |
@@ -1847,7 +1852,7 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | |||
1847 | else if (equal_Command(cmd, "theme.changed")) { | 1852 | else if (equal_Command(cmd, "theme.changed")) { |
1848 | updatePrefsThemeButtons_(d); | 1853 | updatePrefsThemeButtons_(d); |
1849 | if (!argLabel_Command(cmd, "auto")) { | 1854 | if (!argLabel_Command(cmd, "auto")) { |
1850 | setToggle_Widget(findChild_Widget(d, "prefs.ostheme"), iFalse); | 1855 | setToggle_Widget(findChild_Widget(d, "prefs.ostheme"), prefs_App()->useSystemTheme); |
1851 | } | 1856 | } |
1852 | } | 1857 | } |
1853 | else if (equalWidget_Command(cmd, d, "input.resized")) { | 1858 | else if (equalWidget_Command(cmd, d, "input.resized")) { |
@@ -2266,7 +2271,15 @@ iBool handleCommand_App(const char *cmd) { | |||
2266 | const int isAuto = argLabel_Command(cmd, "auto"); | 2271 | const int isAuto = argLabel_Command(cmd, "auto"); |
2267 | d->prefs.theme = arg_Command(cmd); | 2272 | d->prefs.theme = arg_Command(cmd); |
2268 | if (!isAuto) { | 2273 | if (!isAuto) { |
2269 | postCommand_App("ostheme arg:0"); | 2274 | if (isDark_ColorTheme(d->prefs.theme) && d->isDarkSystemTheme) { |
2275 | d->prefs.systemPreferredColorTheme[0] = d->prefs.theme; | ||
2276 | } | ||
2277 | else if (!isDark_ColorTheme(d->prefs.theme) && !d->isDarkSystemTheme) { | ||
2278 | d->prefs.systemPreferredColorTheme[1] = d->prefs.theme; | ||
2279 | } | ||
2280 | else { | ||
2281 | postCommand_App("ostheme arg:0"); | ||
2282 | } | ||
2270 | } | 2283 | } |
2271 | setThemePalette_Color(d->prefs.theme); | 2284 | setThemePalette_Color(d->prefs.theme); |
2272 | postCommandf_App("theme.changed auto:%d", isAuto); | 2285 | postCommandf_App("theme.changed auto:%d", isAuto); |
@@ -2282,6 +2295,12 @@ iBool handleCommand_App(const char *cmd) { | |||
2282 | } | 2295 | } |
2283 | else if (equal_Command(cmd, "ostheme")) { | 2296 | else if (equal_Command(cmd, "ostheme")) { |
2284 | d->prefs.useSystemTheme = arg_Command(cmd); | 2297 | d->prefs.useSystemTheme = arg_Command(cmd); |
2298 | if (hasLabel_Command(cmd, "preferdark")) { | ||
2299 | d->prefs.systemPreferredColorTheme[0] = argLabel_Command(cmd, "preferdark"); | ||
2300 | } | ||
2301 | if (hasLabel_Command(cmd, "preferlight")) { | ||
2302 | d->prefs.systemPreferredColorTheme[1] = argLabel_Command(cmd, "preferlight"); | ||
2303 | } | ||
2285 | return iTrue; | 2304 | return iTrue; |
2286 | } | 2305 | } |
2287 | else if (equal_Command(cmd, "doctheme.dark.set")) { | 2306 | else if (equal_Command(cmd, "doctheme.dark.set")) { |
@@ -2944,12 +2963,15 @@ iBool handleCommand_App(const char *cmd) { | |||
2944 | return iFalse; | 2963 | return iFalse; |
2945 | } | 2964 | } |
2946 | else if (equal_Command(cmd, "os.theme.changed")) { | 2965 | else if (equal_Command(cmd, "os.theme.changed")) { |
2966 | const int dark = argLabel_Command(cmd, "dark"); | ||
2967 | d->isDarkSystemTheme = dark; | ||
2947 | if (d->prefs.useSystemTheme) { | 2968 | if (d->prefs.useSystemTheme) { |
2948 | const int dark = argLabel_Command(cmd, "dark"); | 2969 | const int contrast = argLabel_Command(cmd, "contrast"); |
2949 | const int contrast = argLabel_Command(cmd, "contrast"); | 2970 | const int preferred = d->prefs.systemPreferredColorTheme[dark ^ 1]; |
2950 | postCommandf_App("theme.set arg:%d auto:1", | 2971 | postCommandf_App("theme.set arg:%d auto:1", |
2951 | dark ? (contrast ? pureBlack_ColorTheme : dark_ColorTheme) | 2972 | preferred >= 0 ? preferred |
2952 | : (contrast ? pureWhite_ColorTheme : light_ColorTheme)); | 2973 | : dark ? (contrast ? pureBlack_ColorTheme : dark_ColorTheme) |
2974 | : (contrast ? pureWhite_ColorTheme : light_ColorTheme)); | ||
2953 | } | 2975 | } |
2954 | return iFalse; | 2976 | return iFalse; |
2955 | } | 2977 | } |
diff --git a/src/prefs.c b/src/prefs.c index 4d079402..f7179ad7 100644 --- a/src/prefs.c +++ b/src/prefs.c | |||
@@ -32,6 +32,7 @@ void init_Prefs(iPrefs *d) { | |||
32 | d->langFrom = 3; /* fr */ | 32 | d->langFrom = 3; /* fr */ |
33 | d->langTo = 2; /* en */ | 33 | d->langTo = 2; /* en */ |
34 | d->useSystemTheme = iTrue; | 34 | d->useSystemTheme = iTrue; |
35 | d->systemPreferredColorTheme[0] = d->systemPreferredColorTheme[1] = -1; | ||
35 | d->theme = dark_ColorTheme; | 36 | d->theme = dark_ColorTheme; |
36 | d->accent = cyan_ColorAccent; | 37 | d->accent = cyan_ColorAccent; |
37 | d->customFrame = iFalse; /* needs some more work to be default */ | 38 | d->customFrame = iFalse; /* needs some more work to be default */ |
diff --git a/src/prefs.h b/src/prefs.h index 1ba3a2ab..3431305d 100644 --- a/src/prefs.h +++ b/src/prefs.h | |||
@@ -62,6 +62,7 @@ struct Impl_Prefs { | |||
62 | int langTo; | 62 | int langTo; |
63 | /* Window */ | 63 | /* Window */ |
64 | iBool useSystemTheme; | 64 | iBool useSystemTheme; |
65 | enum iColorTheme systemPreferredColorTheme[2]; /* dark, light */ | ||
65 | enum iColorTheme theme; | 66 | enum iColorTheme theme; |
66 | enum iColorAccent accent; | 67 | enum iColorAccent accent; |
67 | iBool customFrame; /* when LAGRANGE_ENABLE_CUSTOM_FRAME is defined */ | 68 | iBool customFrame; /* when LAGRANGE_ENABLE_CUSTOM_FRAME is defined */ |