diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 1654b42..970d79f 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -652,6 +652,10 @@ Overseer::Overseer() : epsc(this){ if(FAILED(deviceEnumerator->RegisterEndpointNotificationCallback(((IMMNotificationClient*)&epsc)))) { log_debugcpp("when no enchufas......"); } } +void Overseer::populateSystemValues() { + updateDarkMode(); +} + void Overseer::openControlPanel() { STARTUPINFOEXW startupConfig; PROCESS_INFORMATION processInfo; @@ -678,6 +682,40 @@ void Overseer::openControlPanel() { } } +ProcessedNativeEvent Overseer::processTopLevelWindowMessage(void* msg) { +#ifdef WIN32 + MSG *message = static_cast(msg); + switch(message->message) { + case WM_SETTINGCHANGE: + if(!wcscmp(((wchar_t*)message->lParam), L"ImmersiveColorSet")) + return updateDarkMode(); + break; + default: + return ProcessedNativeEvent::NONE; + break; + } + return ProcessedNativeEvent::NONE; + //if (message->message != WM_SETTINGCHANGE) {return false;} +#endif +} + +ProcessedNativeEvent Overseer::updateDarkMode(){ + // DwmGetColorizationColor( WM_DWMCOLORIZATIONCOLORCHANGED + DWORD value = 0; + DWORD size = sizeof(DWORD); + + LSTATUS result; + + result = RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", L"AppsUseLightTheme", RRF_RT_REG_DWORD, nullptr, &value, &size); + + this->lightMode = (bool)value; + return ProcessedNativeEvent::LIGHT_MODE; +} + +bool Overseer::isLightMode() { + return this->lightMode; +} + NGuid Overseer::getGuid() { return guid; } diff --git a/src/back/backlasses.h b/src/back/backlasses.h index bcc3306..9edc779 100644 --- a/src/back/backlasses.h +++ b/src/back/backlasses.h @@ -109,14 +109,20 @@ class Overseer { public: Overseer(); + NGuid getGuid(); + void populateSystemValues(); void openControlPanel(); + ProcessedNativeEvent processTopLevelWindowMessage(void* msg); + ProcessedNativeEvent updateDarkMode(); + bool isLightMode(); + std::vector getPlaybackEndpoints(); std::vector getCaptureEndpoints(); void updateEndpointInfo(std::wstring endpointId); void reloadEndpoints(Flows flow); Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow); - NGuid getGuid(); + //void setEndpointStatusCallback(); //void setEndpointStatusCallback(); @@ -131,6 +137,7 @@ class Overseer { void initCOMLibrary(); NGuid guid; + bool lightMode; IMMDeviceEnumerator *deviceEnumerator; EndpointSituationCallback epsc; diff --git a/src/back/msinclude.h b/src/back/msinclude.h index 6f21ae1..f9ab1b4 100644 --- a/src/back/msinclude.h +++ b/src/back/msinclude.h @@ -1,6 +1,7 @@ #pragma once #define _WIN32_WINNT 0x0A00 + #include //done by qt by def #define UNICODE diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index fb0e22a..75df484 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -205,10 +205,22 @@ OverseerHandler::OverseerHandler() { this->os = new Overseer(); } +void OverseerHandler::populateSystemValues() { + this->os->populateSystemValues(); +} + void OverseerHandler::openControlPanel() { this->os->openControlPanel(); } +ProcessedNativeEvent OverseerHandler::processTopLevelWindowMessage(void* msg) { + return this->os->processTopLevelWindowMessage(msg); +} + +bool OverseerHandler::isLightMode() { + return this->os->isLightMode(); +} + std::vector OverseerHandler::getPlaybackEndpoints() { return this->os->getPlaybackEndpoints(); } diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index e147394..cb3230a 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -97,7 +97,10 @@ class OverseerHandler { public: OverseerHandler(); + void populateSystemValues(); void openControlPanel(); + ProcessedNativeEvent processTopLevelWindowMessage(void* msg); + bool isLightMode(); //void setChangeFrontDefaultsFunction(std::function changeFrontDefaults); //void changeFrontDefaultsCallback(Roles role, std::wstring endpointId); diff --git a/src/global.h b/src/global.h index 4c22755..9cecbfd 100644 --- a/src/global.h +++ b/src/global.h @@ -36,6 +36,11 @@ #define LSTRING_UNNAMED_SESSION L"Unnamed session" //INIT BACK +enum ProcessedNativeEvent { + NONE = 0, + LIGHT_MODE = (1 << 0), +}; + enum AudioChannel { CHANNEL_LEFT = (1 << 0), CHANNEL_RIGHT = (1 << 1), diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 8692897..835daff 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -1,7 +1,29 @@ #include "qtclasses.h" #include "meterslider.h" + #define POLLING_RATE 2 +bool DarkModeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) { + if (eventType == "windows_generic_MSG") { + ProcessedNativeEvent event = osh->processTopLevelWindowMessage(message); + switch(event) { + case LIGHT_MODE: + StylingHelper::setBackgroundColor(osh->isLightMode()); + return true; + break; + default: + break; + } + /* + * if ([event type] == NSKeyDown) { + * // Handle key event + * qDebug() << QString::fromNSString([event characters]); + * } + */ + } + return false; +} + template CustomWidgetEvent::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(type){ this->payload = payload; diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 8b77923..3b60cff 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -22,6 +22,12 @@ enum CustomQEvent { EndpointRoleChange = 1007 }; +class DarkModeEventFilter : public QAbstractNativeEventFilter { + +public: + bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override; +}; + template class CustomWidgetEvent : public QEvent { @@ -31,10 +37,6 @@ public: }; //Q_DECLARE_METATYPE(EndpointWidgetEvent) - -//todo: TEST. TEST. -//#include "qtvisuals.h" - class ExtendedCheckBox : public QCheckBox { Q_OBJECT protected: @@ -47,7 +49,6 @@ public: //B(int x) : A(x) { } }; - class SessionWidget : public QWidget { Q_OBJECT diff --git a/src/qt/qtcommon.h b/src/qt/qtcommon.h index b7a7245..afd7929 100644 --- a/src/qt/qtcommon.h +++ b/src/qt/qtcommon.h @@ -42,6 +42,8 @@ #include #include #include +#include +#include //#include //#include /* @@ -62,6 +64,20 @@ enum CustomComplexControl { }; namespace StylingHelper { + + static inline void setBackgroundColor(bool lightMode) { + //QApplication* app = (QApplication*)QApplication::instance(); + QPalette pal = QGuiApplication::palette(); + if(lightMode) { + pal.setColor(QPalette::Window, Qt::white); + pal.setColor(QPalette::WindowText, Qt::black); + } else { + pal.setColor(QPalette::Window, Qt::black); + pal.setColor(QPalette::WindowText, Qt::white); + } + QGuiApplication::setPalette(pal); + } + static inline QLatin1String operator""_L1(const char* ch, uint64_t) { return QLatin1String(ch); } diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp index 490608d..387df74 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -46,14 +46,6 @@ int main (int argc, char* argv[]) { * log_debugcpp(a.toStdString()); * } */ - - QApplication::setStyle(new MixerStyle(QStyleFactory::create("Fusion"))); - //QApplication::setFont(font); - QPalette palette = QGuiApplication::palette(); - //todo: ez full apply os accent colorw - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(255, 192, 203, 200));//QColor(30,30,30,100)); - QGuiApplication::setPalette(palette); - initialize_file_log(); atexit(closeDebugFileLog); @@ -64,7 +56,17 @@ int main (int argc, char* argv[]) { startSingleInstanceServer("Mixer"); else exit(0); + + QApplication::setStyle(new MixerStyle(QStyleFactory::create("Fusion"))); + //QApplication::setFont(font); + //QPalette palette = QGuiApplication::palette(); + //todo: ez full apply os accent colorw + //palette.setColor(QPalette::Active, QPalette::Highlight, QColor(255, 192, 203, 200)); + //QColor(30,30,30,100)); + //QGuiApplication::setPalette(palette); osh = new OverseerHandler(); + osh->populateSystemValues(); + StylingHelper::setBackgroundColor(osh->isLightMode()); //qRegisterMetaType(); //INIT CONT @@ -78,6 +80,10 @@ int main (int argc, char* argv[]) { MainWindow window = MainWindow(); //window.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::QSizePolicy::MinimumExpanding) QApplication::setQuitOnLastWindowClosed(false); + + DarkModeEventFilter* darkMode = new DarkModeEventFilter(); + QAbstractEventDispatcher::instance()->installNativeEventFilter(darkMode); + /* * QFile styleFile(":/assets/style.qss"); * styleFile.open(QFile::ReadOnly);