more cleanup
This commit is contained in:
@@ -28,8 +28,9 @@ class __declspec(uuid("3bc52579-15fd-43bb-9686-6273c238535e")) TrayGUID;
|
|||||||
UINT const WMAPP_NOTIFYCALLBACK = WM_APP + 1;
|
UINT const WMAPP_NOTIFYCALLBACK = WM_APP + 1;
|
||||||
UINT const WMAPP_HIDEFLYOUT = WM_APP + 2;
|
UINT const WMAPP_HIDEFLYOUT = WM_APP + 2;
|
||||||
|
|
||||||
DrawData* hackyDrawData;
|
// Globals for use in callbacks
|
||||||
ApplicationData* hackyAppData;
|
DrawData* gDrawData;
|
||||||
|
ApplicationData* gAppData;
|
||||||
bool justDocked = false;
|
bool justDocked = false;
|
||||||
bool isHidden = false;
|
bool isHidden = false;
|
||||||
|
|
||||||
@@ -45,32 +46,11 @@ int main()
|
|||||||
startImgui(callbacks, "Audio Thingy", 600, 400);
|
startImgui(callbacks, "Audio Thingy", 600, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
if (code >= 0)
|
|
||||||
{
|
|
||||||
CWPSTRUCT* data = (CWPSTRUCT*)lParam;
|
|
||||||
|
|
||||||
if (data->message == WMAPP_NOTIFYCALLBACK)
|
|
||||||
{
|
|
||||||
switch (data->lParam)
|
|
||||||
{
|
|
||||||
case NIN_SELECT:
|
|
||||||
glfwShowWindow(hackyDrawData->window);
|
|
||||||
glfwRestoreWindow(hackyDrawData->window);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return CallNextHookEx(NULL, code, wParam, lParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
void init(DrawData& drawData, ApplicationData& appData)
|
void init(DrawData& drawData, ApplicationData& appData)
|
||||||
{
|
{
|
||||||
// sad :(
|
// sad :(
|
||||||
hackyDrawData = &drawData;
|
gDrawData = &drawData;
|
||||||
hackyAppData = &appData;
|
gAppData = &appData;
|
||||||
|
|
||||||
// Load text font
|
// Load text font
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
@@ -118,7 +98,7 @@ void init(DrawData& drawData, ApplicationData& appData)
|
|||||||
|
|
||||||
// Set window minimize behavior
|
// Set window minimize behavior
|
||||||
glfwSetWindowIconifyCallback(drawData.window, [](GLFWwindow* window, int isIconified) {
|
glfwSetWindowIconifyCallback(drawData.window, [](GLFWwindow* window, int isIconified) {
|
||||||
if (isIconified && hackyAppData->settings.docked)
|
if (isIconified && gAppData->settings.docked)
|
||||||
{
|
{
|
||||||
glfwHideWindow(window);
|
glfwHideWindow(window);
|
||||||
}
|
}
|
||||||
@@ -126,7 +106,7 @@ void init(DrawData& drawData, ApplicationData& appData)
|
|||||||
});
|
});
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(drawData.window, [](GLFWwindow* window, int isFocused) {
|
glfwSetWindowFocusCallback(drawData.window, [](GLFWwindow* window, int isFocused) {
|
||||||
if (!isFocused && hackyAppData->settings.docked && !justDocked)
|
if (!isFocused && gAppData->settings.docked && !justDocked)
|
||||||
{
|
{
|
||||||
glfwIconifyWindow(window);
|
glfwIconifyWindow(window);
|
||||||
}
|
}
|
||||||
@@ -136,18 +116,7 @@ void init(DrawData& drawData, ApplicationData& appData)
|
|||||||
initSettings(drawData, appData);
|
initSettings(drawData, appData);
|
||||||
|
|
||||||
// Set up audio device api
|
// Set up audio device api
|
||||||
HRESULT audioResult;
|
initAudio(appData);
|
||||||
audioResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
||||||
isError(audioResult, "Failed to initialize COM: ");
|
|
||||||
|
|
||||||
audioResult = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&appData.audioData->deviceEnumerator));
|
|
||||||
isError(audioResult, "Failed to set up audio device enumerator: ");
|
|
||||||
|
|
||||||
appData.audioData->audioNotificationListener = new AudioNotificationListener(appData.audioData);
|
|
||||||
audioResult = appData.audioData->deviceEnumerator->RegisterEndpointNotificationCallback(appData.audioData->audioNotificationListener);
|
|
||||||
isError(audioResult, "Failed to register audio notification listener: ");
|
|
||||||
|
|
||||||
reloadDeviceLists(*appData.audioData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(DrawData& drawData, ApplicationData& appData)
|
void draw(DrawData& drawData, ApplicationData& appData)
|
||||||
@@ -155,8 +124,8 @@ void draw(DrawData& drawData, ApplicationData& appData)
|
|||||||
justDocked = false;
|
justDocked = false;
|
||||||
|
|
||||||
// sad :(
|
// sad :(
|
||||||
hackyDrawData = &drawData;
|
gDrawData = &drawData;
|
||||||
hackyAppData = &appData;
|
gAppData = &appData;
|
||||||
|
|
||||||
// Actual Drawing
|
// Actual Drawing
|
||||||
if (isHidden)
|
if (isHidden)
|
||||||
@@ -400,3 +369,24 @@ void drawCircle(float radius, ImU32 color)
|
|||||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
ImVec2 windowPos = ImGui::GetWindowPos();
|
||||||
drawList->AddCircleFilled(ImVec2(cursorPos.x + windowPos.x, cursorPos.y + windowPos.y + ImGui::GetTextLineHeight() / 2.), radius, color);
|
drawList->AddCircleFilled(ImVec2(cursorPos.x + windowPos.x, cursorPos.y + windowPos.y + ImGui::GetTextLineHeight() / 2.), radius, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
if (code >= 0)
|
||||||
|
{
|
||||||
|
CWPSTRUCT* data = (CWPSTRUCT*)lParam;
|
||||||
|
|
||||||
|
if (data->message == WMAPP_NOTIFYCALLBACK)
|
||||||
|
{
|
||||||
|
switch (data->lParam)
|
||||||
|
{
|
||||||
|
case NIN_SELECT:
|
||||||
|
glfwShowWindow(gDrawData->window);
|
||||||
|
glfwRestoreWindow(gDrawData->window);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CallNextHookEx(NULL, code, wParam, lParam);
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,3 +12,5 @@ void cleanup(DrawData& drawData, ApplicationData& appData);
|
|||||||
ImVec2 menuBar(DrawData& drawData, ApplicationData& appData);
|
ImVec2 menuBar(DrawData& drawData, ApplicationData& appData);
|
||||||
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
||||||
void drawCircle(float radius, ImU32 color);
|
void drawCircle(float radius, ImU32 color);
|
||||||
|
|
||||||
|
LRESULT trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam);
|
||||||
|
|||||||
@@ -47,9 +47,6 @@
|
|||||||
<ClInclude Include="Util.h">
|
<ClInclude Include="Util.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="PolicyConfig.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="ApplicationData.h">
|
<ClInclude Include="ApplicationData.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -65,6 +62,9 @@
|
|||||||
<ClInclude Include="Settings.h">
|
<ClInclude Include="Settings.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="PolicyConfig.h">
|
||||||
|
<Filter>Header Files\Audio</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CopyFileToFolders Include="Montserrat-Regular.ttf">
|
<CopyFileToFolders Include="Montserrat-Regular.ttf">
|
||||||
|
|||||||
@@ -10,31 +10,20 @@
|
|||||||
#include "AudioApi.h"
|
#include "AudioApi.h"
|
||||||
#include "PolicyConfig.h"
|
#include "PolicyConfig.h"
|
||||||
|
|
||||||
HRESULT getDeviceProperty(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData)
|
void initAudio(ApplicationData& appData)
|
||||||
{
|
{
|
||||||
PropVariantInit(outData);
|
HRESULT audioResult;
|
||||||
HRESULT nameResult = propertyStore->GetValue(propertyKey, outData);
|
audioResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||||
return nameResult;
|
isError(audioResult, "Failed to initialize COM: ");
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT getDevicePropertyString(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData, const wchar_t*& outString, const wchar_t* defaultStr)
|
audioResult = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&appData.audioData->deviceEnumerator));
|
||||||
{
|
isError(audioResult, "Failed to set up audio device enumerator: ");
|
||||||
HRESULT result = getDeviceProperty(propertyStore, propertyKey, outData);
|
|
||||||
outString = outData->vt != VT_LPWSTR ? defaultStr : outData->pwszVal;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole role)
|
appData.audioData->audioNotificationListener = new AudioNotificationListener(appData.audioData);
|
||||||
{
|
audioResult = appData.audioData->deviceEnumerator->RegisterEndpointNotificationCallback(appData.audioData->audioNotificationListener);
|
||||||
IPolicyConfigVista* pPolicyConfig;
|
isError(audioResult, "Failed to register audio notification listener: ");
|
||||||
|
|
||||||
HRESULT hr = CoCreateInstance(__uuidof(CPolicyConfigVistaClient), NULL, CLSCTX_ALL, __uuidof(IPolicyConfigVista), (LPVOID*)&pPolicyConfig);
|
reloadDeviceLists(*appData.audioData);
|
||||||
if (!isError(hr, "Failed to set default audio device: "))
|
|
||||||
{
|
|
||||||
hr = pPolicyConfig->SetDefaultEndpoint(deviceId, role);
|
|
||||||
pPolicyConfig->Release();
|
|
||||||
reloadDeviceLists(audioData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList, EDataFlow deviceType)
|
void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList, EDataFlow deviceType)
|
||||||
@@ -145,6 +134,33 @@ void reloadDeviceLists(AudioData& audioData)
|
|||||||
loadAudioDevices(audioData, audioData.recordingDevices, EDataFlow::eCapture);
|
loadAudioDevices(audioData, audioData.recordingDevices, EDataFlow::eCapture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT getDeviceProperty(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData)
|
||||||
|
{
|
||||||
|
PropVariantInit(outData);
|
||||||
|
HRESULT nameResult = propertyStore->GetValue(propertyKey, outData);
|
||||||
|
return nameResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT getDevicePropertyString(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData, const wchar_t*& outString, const wchar_t* defaultStr)
|
||||||
|
{
|
||||||
|
HRESULT result = getDeviceProperty(propertyStore, propertyKey, outData);
|
||||||
|
outString = outData->vt != VT_LPWSTR ? defaultStr : outData->pwszVal;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole role)
|
||||||
|
{
|
||||||
|
IPolicyConfigVista* pPolicyConfig;
|
||||||
|
|
||||||
|
HRESULT hr = CoCreateInstance(__uuidof(CPolicyConfigVistaClient), NULL, CLSCTX_ALL, __uuidof(IPolicyConfigVista), (LPVOID*)&pPolicyConfig);
|
||||||
|
if (!isError(hr, "Failed to set default audio device: "))
|
||||||
|
{
|
||||||
|
hr = pPolicyConfig->SetDefaultEndpoint(deviceId, role);
|
||||||
|
pPolicyConfig->Release();
|
||||||
|
reloadDeviceLists(audioData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float getVolume(IAudioEndpointVolume* volumeInterface)
|
float getVolume(IAudioEndpointVolume* volumeInterface)
|
||||||
{
|
{
|
||||||
float volume;
|
float volume;
|
||||||
|
|||||||
@@ -4,11 +4,14 @@
|
|||||||
|
|
||||||
#include "ApplicationData.h"
|
#include "ApplicationData.h"
|
||||||
|
|
||||||
|
void initAudio(ApplicationData& appData);
|
||||||
|
void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList, EDataFlow deviceType);
|
||||||
|
void reloadDeviceLists(AudioData& audioData);
|
||||||
|
|
||||||
HRESULT getDeviceProperty(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData);
|
HRESULT getDeviceProperty(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData);
|
||||||
HRESULT getDevicePropertyString(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData, const wchar_t*& outString, const wchar_t* defaultStr = L"Unknown");
|
HRESULT getDevicePropertyString(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData, const wchar_t*& outString, const wchar_t* defaultStr = L"Unknown");
|
||||||
void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole role);
|
void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole role);
|
||||||
void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList, EDataFlow deviceType);
|
|
||||||
void reloadDeviceLists(AudioData& audioData);
|
|
||||||
float getVolume(IAudioEndpointVolume* volumeInterface);
|
float getVolume(IAudioEndpointVolume* volumeInterface);
|
||||||
void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume);
|
void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume);
|
||||||
float getMeterValue(IAudioMeterInformation* meterInterface);
|
float getMeterValue(IAudioMeterInformation* meterInterface);
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
extern bool justDocked;
|
extern bool justDocked;
|
||||||
extern DrawData* hackyDrawData;
|
extern DrawData* gDrawData;
|
||||||
extern ApplicationData* hackyAppData;
|
extern ApplicationData* gAppData;
|
||||||
|
|
||||||
void initSettings(DrawData& drawData, ApplicationData& appData)
|
void initSettings(DrawData& drawData, ApplicationData& appData)
|
||||||
{
|
{
|
||||||
@@ -22,7 +22,7 @@ void initSettings(DrawData& drawData, ApplicationData& appData)
|
|||||||
|
|
||||||
void* settingsReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name)
|
void* settingsReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name)
|
||||||
{
|
{
|
||||||
ApplicationSettings* settings = &hackyAppData->settings;
|
ApplicationSettings* settings = &gAppData->settings;
|
||||||
*settings = ApplicationSettings();
|
*settings = ApplicationSettings();
|
||||||
return (void*)settings;
|
return (void*)settings;
|
||||||
}
|
}
|
||||||
@@ -46,8 +46,8 @@ void settingsReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* en
|
|||||||
void settingsWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* outBuf)
|
void settingsWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* outBuf)
|
||||||
{
|
{
|
||||||
outBuf->appendf("[%s][%s]\n", "ApplicationSettings", "ApplicationSettings");
|
outBuf->appendf("[%s][%s]\n", "ApplicationSettings", "ApplicationSettings");
|
||||||
outBuf->appendf("docked=%i\n", (int)hackyAppData->settings.docked);
|
outBuf->appendf("docked=%i\n", (int)gAppData->settings.docked);
|
||||||
outBuf->appendf("autostart=%i\n", (int)hackyAppData->settings.autostart);
|
outBuf->appendf("autostart=%i\n", (int)gAppData->settings.autostart);
|
||||||
outBuf->append("\n");
|
outBuf->append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user