Add dark mode support and os_detector

This commit is contained in:
daleclack 2022-12-18 21:11:17 +08:00
parent c6972513ec
commit 9b9df72744
5 changed files with 38 additions and 2 deletions

View File

@ -27,6 +27,7 @@ set(SOURCES src/main.cc src/MyWin.cc src/MyPrefs.cc
#Compile resources with GCR_CMake
set(RESOURCE_LIST
style.css
style_dark.css
STRIPBLANKS menubar.xml
STRIPBLANKS prefs.ui
icons/16x16/actions/open-menu.png

View File

@ -0,0 +1,10 @@
/*
您可以在这里输入任何 GTK+ 可识别的 CSS 规则
您可以点击上面的暂停按钮来暂时停用这个自定义 CSS
变更会立即应用到全局影响整个应用程序
*/
box{
background-color:rgba(34, 34, 35, 0.5);
}

View File

@ -17,7 +17,8 @@ MyWin::MyWin()
: btn_box(Gtk::Orientation::VERTICAL, 5),
btn_ver("Xe-Ver"),
cfg_box(Gtk::Orientation::VERTICAL, 5),
msg_dialog(*this)
msg_dialog(*this),
dark_mode(true)
{
// Initalize window
set_icon_name("Xe-Release");
@ -78,7 +79,11 @@ MyWin::MyWin()
// Create Style for widgets
provider = Gtk::CssProvider::create();
provider->load_from_resource("/org/gtk/daleclack/style.css");
if(dark_mode){
provider->load_from_resource("/org/gtk/daleclack/style_dark.css");
}else{
provider->load_from_resource("/org/gtk/daleclack/style.css");
}
auto style1 = btn_box.get_style_context();
style1->add_provider(provider, 1);
auto style2 = prefs->get_style_context();

View File

@ -29,6 +29,7 @@ private:
void titlebar_init();
// Css Style
bool dark_mode;
Glib::RefPtr<Gtk::CssProvider> provider;
// Config Page

View File

@ -0,0 +1,19 @@
// Defining the OS
enum class OS_Type{
Linux,
macOS,
Windows
};
static inline OS_Type os_detector(){
#if defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
// #define COMPILED_IN_LINUX
return OS_Type::Linux;
#elif defined(__APPLE__) && defined(__MACH__)
// #define COMPILED_IN_MACOS
return OS_Type::macOS;
#elif defined(_WIN32) || defined(_WIN64)
// #define COMPILED_IN_WINDOWS
return OS_Type::Windows;
#endif
}