Mercurial > minori
comparison src/gui/theme.cc @ 232:ff0061e75f0f
theme: add OS detection with glib
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 13 Jan 2024 11:06:16 -0500 |
parents | 2f5a9247e501 |
children | 4d461ef7d424 |
comparison
equal
deleted
inserted
replaced
231:69f4768a820c | 232:ff0061e75f0f |
---|---|
7 #include <QStyleFactory> | 7 #include <QStyleFactory> |
8 #ifdef MACOSX | 8 #ifdef MACOSX |
9 # include "sys/osx/dark_theme.h" | 9 # include "sys/osx/dark_theme.h" |
10 #elif WIN32 | 10 #elif WIN32 |
11 # include "sys/win32/dark_theme.h" | 11 # include "sys/win32/dark_theme.h" |
12 #else | |
13 # ifdef GLIB | |
14 # include "sys/glib/dark_theme.h" | |
15 # endif | |
12 #endif | 16 #endif |
13 | 17 |
14 /* Weird quirks of this implementation: | 18 /* Weird quirks of this implementation: |
15 * 1. Dark mode stuff in Qt changes a lot and Qt 5 and Qt 6 are massively different | 19 * 1. Dark mode stuff in Qt changes a lot and Qt 5 and Qt 6 are massively different |
16 * 2. Some widgets, i.e. QTabWidget, QTabBar, etc., just completely IGNORE the QPalette setting | 20 * 2. Some widgets, i.e. QTabWidget, QTabBar, etc., just completely IGNORE the QPalette setting |
35 if (osx::DarkThemeAvailable()) | 39 if (osx::DarkThemeAvailable()) |
36 return osx::IsInDarkTheme(); | 40 return osx::IsInDarkTheme(); |
37 #elif defined(WIN32) | 41 #elif defined(WIN32) |
38 if (win32::DarkThemeAvailable()) | 42 if (win32::DarkThemeAvailable()) |
39 return win32::IsInDarkTheme(); | 43 return win32::IsInDarkTheme(); |
44 #else | |
45 # ifdef GLIB | |
46 return glib::IsInDarkTheme(); | |
47 # endif | |
40 #endif | 48 #endif |
41 return (theme == Themes::DARK); | 49 return (theme == Themes::DARK); |
42 } | 50 } |
43 | 51 |
44 void Theme::SetToDarkTheme() { | 52 void Theme::SetToDarkTheme() { |
66 #endif | 74 #endif |
67 SetStyleSheet(Themes::LIGHT); | 75 SetStyleSheet(Themes::LIGHT); |
68 } | 76 } |
69 | 77 |
70 Themes Theme::GetCurrentOSTheme() const { | 78 Themes Theme::GetCurrentOSTheme() const { |
71 #ifdef MACOSX | 79 return IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; |
72 if (osx::DarkThemeAvailable()) | 80 |
73 return osx::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; | |
74 #elif defined(WIN32) | |
75 if (win32::DarkThemeAvailable()) | |
76 return win32::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; | |
77 #endif | |
78 /* Currently OS detection only supports Windows and macOS. | 81 /* Currently OS detection only supports Windows and macOS. |
79 Please don't be shy if you're willing to port it to other OSes | 82 Please don't be shy if you're willing to port it to other OSes |
80 (or desktop environments, or window managers) */ | 83 (or desktop environments, or window managers) */ |
81 return Themes::LIGHT; | 84 return Themes::LIGHT; |
82 } | 85 } |