wip chex still buggy + customEvent

This commit is contained in:
Hane 2023-09-07 21:50:45 +02:00
commit a15037c5f2
6 changed files with 145 additions and 28 deletions

View file

@ -141,19 +141,16 @@ HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) {
return S_OK; return S_OK;
} }
HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) { HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) {
std::wstring endpointId = std::wstring(pwstrDeviceId);
switch (dwNewState){ switch (dwNewState){
case DEVICE_STATE_ACTIVE: case DEVICE_STATE_ACTIVE:
osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_ACTIVE);
break; break;
case DEVICE_STATE_DISABLED: case DEVICE_STATE_DISABLED:
break;
case DEVICE_STATE_NOTPRESENT: case DEVICE_STATE_NOTPRESENT:
break;
case DEVICE_STATE_UNPLUGGED: case DEVICE_STATE_UNPLUGGED:
osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_DISABLED);
break; break;
} }
@ -161,16 +158,15 @@ HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, D
} }
HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) { HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) {
/*
* printf(" -->Changed device property " log_debugcpp(" -->Changed device property " <<
* "{%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x}#%d\n", key.fmtid.Data1 << key.fmtid.Data2 << key.fmtid.Data3 << "\n" <<
* key.fmtid.Data1, key.fmtid.Data2, key.fmtid.Data3, key.fmtid.Data4[0]<< key.fmtid.Data4[1]<< "\n"<<
* key.fmtid.Data4[0], key.fmtid.Data4[1], key.fmtid.Data4[2]<< key.fmtid.Data4[3] << "\n"<<
* key.fmtid.Data4[2], key.fmtid.Data4[3], key.fmtid.Data4[4]<< key.fmtid.Data4[5] << "\n"<<
* key.fmtid.Data4[4], key.fmtid.Data4[5], key.fmtid.Data4[6]<< key.fmtid.Data4[7]<< "\n"<<
* key.fmtid.Data4[6], key.fmtid.Data4[7], " pid " << key.pid);
* key.pid);
*/
return S_OK; return S_OK;
} }
@ -391,7 +387,7 @@ void Overseer::reloadEndpoints() {
IMMDeviceCollection *deviceCollection; IMMDeviceCollection *deviceCollection;
// | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED // | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED
// NOTPRESENT shows a lot of garbage, unnamed devices. // NOTPRESENT shows a lot of garbage, unnamed devices.
if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED, &deviceCollection) )) if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED, &deviceCollection) ))
{ log_debugcpp("si"); }; { log_debugcpp("si"); };
/* /*

View file

@ -19,6 +19,19 @@ EndpointHandler::EndpointHandler(uint64_t idx) {
} }
} }
void EndpointHandler::setFrontVisibilityInfo(EndpointState state, uint64_t frontIdx){
ephfv.visibility = state;
ephfv.frontIdx = frontIdx;
}
uint64_t EndpointHandler::getFrontVisibilityIndex(){
return ephfv.frontIdx;
}
EndpointState EndpointHandler::getFrontVisibilityState(){
return ephfv.visibility;
}
/* these two, currently unused. If I use them, I should feel bad. /* these two, currently unused. If I use them, I should feel bad.
* Endpoint* EndpointHandler::getEndpoint() { * Endpoint* EndpointHandler::getEndpoint() {
* return this->ep; * return this->ep;
@ -152,7 +165,32 @@ void OverseerHandler::setChangeFrontDefaultsFunction(std::function<void(Roles, s
void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpointId) { void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpointId) {
this->changeFrontDefaults(role, endpointId); this->changeFrontDefaults(role, endpointId);
} }
void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) {
EndpointHandler* affected = nullptr;
for (auto eph : this->endpointHandlers) {
if (eph->getId() == endpointId) {
affected = eph;
break;
}
}
//todo:
if(EndpointState::ENDPOINT_ACTIVE & state) {
//todo:
return;
} else if (affected->getFrontVisibilityState() == EndpointState::ENDPOINT_ACTIVE){
this->removeEndpointWidget(affected->getFrontVisibilityIndex());
affected->setFrontVisibilityInfo(EndpointState::ENDPOINT_ALL, INT_MAX);
}
return;
//this->reviseEndpointShowing(endpointId, role);
}
void OverseerHandler::setRemoveEndpointWidgetFunction(std::function<void(uint64_t)> removeEndpointWidget){
this->removeEndpointWidget = removeEndpointWidget;
}
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){ void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){
this->endpointHandlers = ephs; this->endpointHandlers = ephs;

View file

@ -76,7 +76,11 @@ public:
std::wstring getName(); std::wstring getName();
std::wstring getId(); std::wstring getId();
void setFrontVisibilityInfo(EndpointState state, uint64_t frontIdx);
uint64_t getFrontVisibilityIndex();
EndpointState getFrontVisibilityState();
float getVolume(int channel); float getVolume(int channel);
bool getMute(); bool getMute();
size_t getState(); size_t getState();
@ -95,6 +99,11 @@ private:
Endpoint *ep = nullptr; Endpoint *ep = nullptr;
EndpointVolumeCallback *epc = nullptr; EndpointVolumeCallback *epc = nullptr;
BackEndpointVolumeCallbackInfo callbackInfo; BackEndpointVolumeCallbackInfo callbackInfo;
struct EndpointHandlerFrontVisibility {
EndpointState visibility = EndpointState::ENDPOINT_ALL;
uint64_t frontIdx = INT_MAX;
};
EndpointHandlerFrontVisibility ephfv;
//QSlider *slidy; //QSlider *slidy;
}; };
@ -105,7 +114,10 @@ public:
OverseerHandler(); OverseerHandler();
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);
//void setReviseEndpointShowingFunction(std::function<void(std::wstring, EndpointState)> reviseEndpointShowing);
void reviseEndpointShowing(std::wstring endpointId, EndpointState state);
void setRemoveEndpointWidgetFunction(std::function<void(uint64_t)> removeEndpointWidget);
void setEndpointHandlers(std::vector<EndpointHandler*> ephs); void setEndpointHandlers(std::vector<EndpointHandler*> ephs);
std::vector<EndpointHandler*> getEndpointHandlers(); std::vector<EndpointHandler*> getEndpointHandlers();
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
@ -116,7 +128,8 @@ public:
private: private:
Overseer *os; Overseer *os;
std::vector<EndpointHandler*> endpointHandlers; std::vector<EndpointHandler*> endpointHandlers;
std::function<void(Roles, std::wstring)> changeFrontDefaults; std::function<void(Roles, std::wstring /* endpointid */)> changeFrontDefaults;
std::function<void(uint64_t /* epw id */)> removeEndpointWidget;
//std::function<void(uint64_t /* device */, uint32_t /* channel */, float /* value */)> updateFrontVolumeCallback; //std::function<void(uint64_t /* device */, uint32_t /* channel */, float /* value */)> updateFrontVolumeCallback;
//std::function<void(uint64_t /* device */, bool /* mute */)> updateFrontMuteCallback; //std::function<void(uint64_t /* device */, bool /* mute */)> updateFrontMuteCallback;

View file

@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <bitset> #include <bitset>
#include <climits>
#include "debug.h" #include "debug.h"

View file

@ -1,9 +1,12 @@
#include "qtclasses.h" #include "qtclasses.h"
EndpointWidgetEvent::EndpointWidgetEvent(QEvent::Type type, int idx) : QEvent(type){
this->idx = idx;
}
bool ExtendedCheckBox::event(QEvent* ev) { bool ExtendedCheckBox::event(QEvent* ev) {
if (ev->type() == QEvent::User) { if (ev->type() == QEvent::User) {
//todo: still prone to bugs; whack-a-mole to come
this->blockSignals(true); this->blockSignals(true);
if (this->isEnabled()) { if (this->isEnabled()) {
this->setCheckState(Qt::Checked); this->setCheckState(Qt::Checked);
@ -19,11 +22,11 @@ bool ExtendedCheckBox::event(QEvent* ev) {
return QCheckBox::event(ev); return QCheckBox::event(ev);
} }
EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent) : QWidget(parent){ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent) : QWidget(parent){
//todo: based on qgridlayout, name+mute should be its own widget, same with channels //todo: based on qgridlayout, name+mute should be its own widget, same with channels
this->idx = idx; this->idx = idx;
this->eph = eph; this->eph = eph;
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, idx);
layout = new QGridLayout(this); layout = new QGridLayout(this);
//this->setLayout(layout); //this->setLayout(layout);
log_debugcpp("epw main layout parent: "<< layout->parent()); log_debugcpp("epw main layout parent: "<< layout->parent());
@ -178,6 +181,31 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
log_debugcpp("ENDPOINT_WIDGETED"); log_debugcpp("ENDPOINT_WIDGETED");
} }
void MainWindow::customEvent(QEvent* ev) {
if (ev->type() == (QEvent::Type)CustomQEvent::EndpointWidgetObsolete) {
this->removeEndpointWidget((EndpointWidgetEvent*)ev);
return;
}
// Make sure the rest of events are handled
return QMainWindow::customEvent(ev);
}
void MainWindow::removeEndpointWidget(EndpointWidgetEvent* ev){
uint64_t i = ev->idx;
this->ews.at(i)->setParent(nullptr);
this->layout->removeWidget(ews.at(i));
uint64_t saisu = ews.size();
//delete ews.at(index);
while ((i + 1) < ews.size()) {
ews.at(i) = ews.at(i + 1);
ews.at(i)->updateEndpointHandlerFrontInfo(i);
i++;
}
ews.pop_back();
return;
}
void EndpointWidget::updateMute(int checked){ void EndpointWidget::updateMute(int checked){
bool muted = (checked == 2 ? true : false); bool muted = (checked == 2 ? true : false);
this->eph->setMute(osh->getGuid(), muted); this->eph->setMute(osh->getGuid(), muted);
@ -223,6 +251,11 @@ EndpointHandler* EndpointWidget::getEndpointHandler(){
return this->eph; return this->eph;
} }
void EndpointWidget::updateEndpointHandlerFrontInfo(uint64_t index){
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, index);
}
void EndpointWidget::setIndex(uint64_t idx){ void EndpointWidget::setIndex(uint64_t idx){
this->idx = idx; this->idx = idx;
} }
@ -234,18 +267,24 @@ uint64_t EndpointWidget::getIndex(){
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
// setWindowState(Qt::WindowFullScreen); // setWindowState(Qt::WindowFullScreen);
// setCentralWidget(centralWidget); // setCentralWidget(centralWidget);
/*
* Registering needed custom events
*/
QEvent::registerEventType(CustomQEvent::EndpointWidgetObsolete);
widget = new QWidget(); widget = new QWidget();
layout = new QGridLayout(); layout = new QGridLayout();
trayIcon = new QSystemTrayIcon(); trayIcon = new QSystemTrayIcon();
trayIconMenu = new QMenu(); trayIconMenu = new QMenu();
trayIconMenuQuit = new QAction(STRING_QUIT); trayIconMenuQuit = new QAction(STRING_QUIT);
changeDefaultCheckboxEnablement = new QEvent(QEvent::User); changeDefaultCheckboxEnablement = new QEvent(QEvent::User);
changeDefaultCheckboxEnablement->setAccepted(true); changeDefaultCheckboxEnablement->setAccepted(true);
widget->setLayout(layout); widget->setLayout(layout);
setCentralWidget(widget); setCentralWidget(widget);
//layout->addWidget(pintas, 0, 0); //layout->addWidget(pintas, 0, 0);
setWindowTitle(STRING_TITLE); setWindowTitle(STRING_TITLE);
reloadEndpointWidgets(); reloadEndpointWidgets();
@ -266,7 +305,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated); connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated);
/* /*
* Set of function callback definitinos for EndpointSituationCallback * Set of function callback definitons for EndpointSituationCallback
*/ */
osh->setChangeFrontDefaultsFunction([this](Roles role, std::wstring endpointId) { osh->setChangeFrontDefaultsFunction([this](Roles role, std::wstring endpointId) {
for (auto epw : this->ews) { for (auto epw : this->ews) {
@ -306,8 +345,23 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
} }
} }
}); });
osh->setRemoveEndpointWidgetFunction([this](uint64_t index) {
EndpointWidgetEvent removeObsoleteEndpointWidget((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index);
removeObsoleteEndpointWidget.setAccepted(true);
QCoreApplication::instance()->postEvent(this, &removeObsoleteEndpointWidget);
});
/*
* osh->setReviseEndpointShowingFunction([this](std::wstring endpointId, Roles role){
*
*
* });
*/
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
if (!event->spontaneous() || !isVisible()) return; if (!event->spontaneous() || !isVisible()) return;
@ -338,7 +392,7 @@ void MainWindow::reloadEndpointWidgets() {
osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid(); osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid();
EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getEndpointHandlers().at(i), widget); EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getEndpointHandlers().at(i), widget);
epwIndex++; epwIndex++;
//TODO: ALWAYS PUSH BACK??? PSZ CHANGE DIS WHEN IMPLEMENTING DYN ENDPOINT DET //alfinal estoes solopara inicializarlmao
ews.push_back(epw); ews.push_back(epw);
layout->addWidget(epw, i, 0); layout->addWidget(epw, i, 0);
} }

View file

@ -56,7 +56,17 @@
* ToggleButton(QWidget *parent = nullptr); * ToggleButton(QWidget *parent = nullptr);
* }; * };
*/ */
enum CustomQEvent {
EndpointWidgetObsolete = 1001,
};
class EndpointWidgetEvent : public QEvent {
Q_OBJECT
public:
EndpointWidgetEvent(QEvent::Type type, int idx);
uint64_t idx;
};
class ExtendedCheckBox : public QCheckBox { class ExtendedCheckBox : public QCheckBox {
Q_OBJECT Q_OBJECT
@ -76,6 +86,8 @@ public:
EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr); EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr);
EndpointHandler* getEndpointHandler(); EndpointHandler* getEndpointHandler();
void updateEndpointHandlerFrontInfo(uint64_t index);
void setIndex(uint64_t idx); void setIndex(uint64_t idx);
uint64_t getIndex(); uint64_t getIndex();
@ -124,9 +136,11 @@ public:
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
void customEvent(QEvent* ev) override;
private slots: private slots:
void trayIconActivated(QSystemTrayIcon::ActivationReason reason); void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
void removeEndpointWidget(EndpointWidgetEvent* ev);
//TODO: destroy/empty existing EndpointWidgets //TODO: destroy/empty existing EndpointWidgets
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs); //void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
@ -140,6 +154,7 @@ private:
QMenu *trayIconMenu; QMenu *trayIconMenu;
QAction *trayIconMenuQuit; QAction *trayIconMenuQuit;
QEvent* changeDefaultCheckboxEnablement; QEvent* changeDefaultCheckboxEnablement;
//public slots: //public slots:
// void setEndpointHandlers(std::vector<EndpointHandler*> *ephs); // void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);