wip: dark/light mode adaptation
This commit is contained in:
parent
0bf8b321ae
commit
13855c2e6f
10 changed files with 125 additions and 14 deletions
|
|
@ -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 *>(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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,14 +109,20 @@ class Overseer {
|
|||
|
||||
public:
|
||||
Overseer();
|
||||
NGuid getGuid();
|
||||
void populateSystemValues();
|
||||
void openControlPanel();
|
||||
ProcessedNativeEvent processTopLevelWindowMessage(void* msg);
|
||||
ProcessedNativeEvent updateDarkMode();
|
||||
bool isLightMode();
|
||||
|
||||
std::vector<Endpoint*> getPlaybackEndpoints();
|
||||
std::vector<Endpoint*> 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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#define _WIN32_WINNT 0x0A00
|
||||
|
||||
#include <sdkddkver.h>
|
||||
|
||||
//done by qt by def #define UNICODE
|
||||
|
|
|
|||
|
|
@ -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<Endpoint*> OverseerHandler::getPlaybackEndpoints() {
|
||||
return this->os->getPlaybackEndpoints();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,10 @@ class OverseerHandler {
|
|||
|
||||
public:
|
||||
OverseerHandler();
|
||||
void populateSystemValues();
|
||||
void openControlPanel();
|
||||
ProcessedNativeEvent processTopLevelWindowMessage(void* msg);
|
||||
bool isLightMode();
|
||||
|
||||
//void setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults);
|
||||
//void changeFrontDefaultsCallback(Roles role, std::wstring endpointId);
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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 <typename T>
|
||||
CustomWidgetEvent<T>::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(type){
|
||||
this->payload = payload;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ enum CustomQEvent {
|
|||
EndpointRoleChange = 1007
|
||||
};
|
||||
|
||||
class DarkModeEventFilter : public QAbstractNativeEventFilter {
|
||||
|
||||
public:
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@
|
|||
#include <QLatin1Char>
|
||||
#include <QLatin1String>
|
||||
#include <QFontDatabase>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QAbstractEventDispatcher>
|
||||
//#include <QScrollbarStyleAnimation>
|
||||
//#include <QScrollBar>
|
||||
/*
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<EndpointWidgetEvent>();
|
||||
|
||||
//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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue