wip: dark/light mode adaptation

This commit is contained in:
Hane 2024-11-20 19:21:37 +01:00
commit 13855c2e6f
10 changed files with 125 additions and 14 deletions

View file

@ -652,6 +652,10 @@ Overseer::Overseer() : epsc(this){
if(FAILED(deviceEnumerator->RegisterEndpointNotificationCallback(((IMMNotificationClient*)&epsc)))) { log_debugcpp("when no enchufas......"); } if(FAILED(deviceEnumerator->RegisterEndpointNotificationCallback(((IMMNotificationClient*)&epsc)))) { log_debugcpp("when no enchufas......"); }
} }
void Overseer::populateSystemValues() {
updateDarkMode();
}
void Overseer::openControlPanel() { void Overseer::openControlPanel() {
STARTUPINFOEXW startupConfig; STARTUPINFOEXW startupConfig;
PROCESS_INFORMATION processInfo; PROCESS_INFORMATION processInfo;
@ -678,6 +682,40 @@ void Overseer::openControlPanel() {
} }
} }
ProcessedNativeEvent Overseer::processTopLevelWindowMessage(void* msg) {
#ifdef WIN32
MSG *message = static_cast<MSG *>(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() { NGuid Overseer::getGuid() {
return guid; return guid;
} }

View file

@ -109,14 +109,20 @@ class Overseer {
public: public:
Overseer(); Overseer();
NGuid getGuid();
void populateSystemValues();
void openControlPanel(); void openControlPanel();
ProcessedNativeEvent processTopLevelWindowMessage(void* msg);
ProcessedNativeEvent updateDarkMode();
bool isLightMode();
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
std::vector<Endpoint*> getCaptureEndpoints(); std::vector<Endpoint*> getCaptureEndpoints();
void updateEndpointInfo(std::wstring endpointId); void updateEndpointInfo(std::wstring endpointId);
void reloadEndpoints(Flows flow); void reloadEndpoints(Flows flow);
Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow); Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow);
NGuid getGuid();
//void setEndpointStatusCallback(); //void setEndpointStatusCallback();
//void setEndpointStatusCallback(); //void setEndpointStatusCallback();
@ -131,6 +137,7 @@ class Overseer {
void initCOMLibrary(); void initCOMLibrary();
NGuid guid; NGuid guid;
bool lightMode;
IMMDeviceEnumerator *deviceEnumerator; IMMDeviceEnumerator *deviceEnumerator;
EndpointSituationCallback epsc; EndpointSituationCallback epsc;

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#define _WIN32_WINNT 0x0A00 #define _WIN32_WINNT 0x0A00
#include <sdkddkver.h> #include <sdkddkver.h>
//done by qt by def #define UNICODE //done by qt by def #define UNICODE

View file

@ -205,10 +205,22 @@ OverseerHandler::OverseerHandler() {
this->os = new Overseer(); this->os = new Overseer();
} }
void OverseerHandler::populateSystemValues() {
this->os->populateSystemValues();
}
void OverseerHandler::openControlPanel() { void OverseerHandler::openControlPanel() {
this->os->openControlPanel(); this->os->openControlPanel();
} }
ProcessedNativeEvent OverseerHandler::processTopLevelWindowMessage(void* msg) {
return this->os->processTopLevelWindowMessage(msg);
}
bool OverseerHandler::isLightMode() {
return this->os->isLightMode();
}
std::vector<Endpoint*> OverseerHandler::getPlaybackEndpoints() { std::vector<Endpoint*> OverseerHandler::getPlaybackEndpoints() {
return this->os->getPlaybackEndpoints(); return this->os->getPlaybackEndpoints();
} }

View file

@ -97,7 +97,10 @@ class OverseerHandler {
public: public:
OverseerHandler(); OverseerHandler();
void populateSystemValues();
void openControlPanel(); void openControlPanel();
ProcessedNativeEvent processTopLevelWindowMessage(void* msg);
bool isLightMode();
//void setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults); //void setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults);
//void changeFrontDefaultsCallback(Roles role, std::wstring endpointId); //void changeFrontDefaultsCallback(Roles role, std::wstring endpointId);

View file

@ -36,6 +36,11 @@
#define LSTRING_UNNAMED_SESSION L"Unnamed session" #define LSTRING_UNNAMED_SESSION L"Unnamed session"
//INIT BACK //INIT BACK
enum ProcessedNativeEvent {
NONE = 0,
LIGHT_MODE = (1 << 0),
};
enum AudioChannel { enum AudioChannel {
CHANNEL_LEFT = (1 << 0), CHANNEL_LEFT = (1 << 0),
CHANNEL_RIGHT = (1 << 1), CHANNEL_RIGHT = (1 << 1),

View file

@ -1,7 +1,29 @@
#include "qtclasses.h" #include "qtclasses.h"
#include "meterslider.h" #include "meterslider.h"
#define POLLING_RATE 2 #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 <typename T> template <typename T>
CustomWidgetEvent<T>::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(type){ CustomWidgetEvent<T>::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(type){
this->payload = payload; this->payload = payload;

View file

@ -22,6 +22,12 @@ enum CustomQEvent {
EndpointRoleChange = 1007 EndpointRoleChange = 1007
}; };
class DarkModeEventFilter : public QAbstractNativeEventFilter {
public:
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override;
};
template <typename T> template <typename T>
class CustomWidgetEvent : public QEvent { class CustomWidgetEvent : public QEvent {
@ -31,10 +37,6 @@ public:
}; };
//Q_DECLARE_METATYPE(EndpointWidgetEvent) //Q_DECLARE_METATYPE(EndpointWidgetEvent)
//todo: TEST. TEST.
//#include "qtvisuals.h"
class ExtendedCheckBox : public QCheckBox { class ExtendedCheckBox : public QCheckBox {
Q_OBJECT Q_OBJECT
protected: protected:
@ -47,7 +49,6 @@ public:
//B(int x) : A(x) { } //B(int x) : A(x) { }
}; };
class SessionWidget : public QWidget { class SessionWidget : public QWidget {
Q_OBJECT Q_OBJECT

View file

@ -42,6 +42,8 @@
#include <QLatin1Char> #include <QLatin1Char>
#include <QLatin1String> #include <QLatin1String>
#include <QFontDatabase> #include <QFontDatabase>
#include <QAbstractNativeEventFilter>
#include <QAbstractEventDispatcher>
//#include <QScrollbarStyleAnimation> //#include <QScrollbarStyleAnimation>
//#include <QScrollBar> //#include <QScrollBar>
/* /*
@ -62,6 +64,20 @@ enum CustomComplexControl {
}; };
namespace StylingHelper { 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) { static inline QLatin1String operator""_L1(const char* ch, uint64_t) {
return QLatin1String(ch); return QLatin1String(ch);
} }

View file

@ -46,14 +46,6 @@ int main (int argc, char* argv[]) {
* log_debugcpp(a.toStdString()); * 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(); initialize_file_log();
atexit(closeDebugFileLog); atexit(closeDebugFileLog);
@ -64,7 +56,17 @@ int main (int argc, char* argv[]) {
startSingleInstanceServer("Mixer"); startSingleInstanceServer("Mixer");
else exit(0); 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 = new OverseerHandler();
osh->populateSystemValues();
StylingHelper::setBackgroundColor(osh->isLightMode());
//qRegisterMetaType<EndpointWidgetEvent>(); //qRegisterMetaType<EndpointWidgetEvent>();
//INIT CONT //INIT CONT
@ -78,6 +80,10 @@ int main (int argc, char* argv[]) {
MainWindow window = MainWindow(); MainWindow window = MainWindow();
//window.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::QSizePolicy::MinimumExpanding) //window.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::QSizePolicy::MinimumExpanding)
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
DarkModeEventFilter* darkMode = new DarkModeEventFilter();
QAbstractEventDispatcher::instance()->installNativeEventFilter(darkMode);
/* /*
* QFile styleFile(":/assets/style.qss"); * QFile styleFile(":/assets/style.qss");
* styleFile.open(QFile::ReadOnly); * styleFile.open(QFile::ReadOnly);