docked mode

This commit is contained in:
2022-07-15 19:14:59 +02:00
parent 5c785ac4e7
commit 4c73dba8ad
3 changed files with 35 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ public:
class ApplicationSettings { class ApplicationSettings {
public: public:
bool docked = false;
bool showDisabledDevices = false; bool showDisabledDevices = false;
bool fitWindowHeight = true; bool fitWindowHeight = true;
bool minimizeToTray = true; bool minimizeToTray = true;

View File

@@ -116,7 +116,6 @@ void init(DrawData& drawData, ApplicationData& appData)
nid.uVersion = NOTIFYICON_VERSION_4; nid.uVersion = NOTIFYICON_VERSION_4;
Shell_NotifyIcon(NIM_SETVERSION, &nid); Shell_NotifyIcon(NIM_SETVERSION, &nid);
// TODO: Add a different kind of hook, that gets mouse events (or other?)
if (!SetWindowsHookEx(WH_CALLWNDPROC, trayIconEventHandler, instance, GetCurrentThreadId())) if (!SetWindowsHookEx(WH_CALLWNDPROC, trayIconEventHandler, instance, GetCurrentThreadId()))
{ {
std::cout << "Failed to hook tray icon events: " << std::hex << GetLastError() << std::endl; std::cout << "Failed to hook tray icon events: " << std::hex << GetLastError() << std::endl;
@@ -137,7 +136,7 @@ void draw(DrawData& drawData, ApplicationData& appData)
ImVec2 viewportSize = ImGui::GetMainViewport()->Size; ImVec2 viewportSize = ImGui::GetMainViewport()->Size;
// Menu Bar // Menu Bar
customYCursor += menuBar(appData).y; customYCursor += menuBar(drawData, appData).y;
// Playback Devices // Playback Devices
ImGui::SetNextWindowPos(ImVec2(0, customYCursor)); ImGui::SetNextWindowPos(ImVec2(0, customYCursor));
@@ -156,6 +155,13 @@ void draw(DrawData& drawData, ApplicationData& appData)
{ {
drawData.window_size.y = customYCursor; drawData.window_size.y = customYCursor;
} }
if (appData.settings.docked)
{
int monitorX, monitorY, monitorW, monitorH;
glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &monitorX, &monitorY, &monitorW, &monitorH);
glfwSetWindowPos(drawData.window, monitorX + monitorW - drawData.window_size.x, monitorY + monitorH - drawData.window_size.y);
}
} }
void cleanup(DrawData& drawData, ApplicationData& appData) void cleanup(DrawData& drawData, ApplicationData& appData)
@@ -167,7 +173,7 @@ void cleanup(DrawData& drawData, ApplicationData& appData)
bool test = Shell_NotifyIcon(NIM_DELETE, &nid); bool test = Shell_NotifyIcon(NIM_DELETE, &nid);
} }
ImVec2 menuBar(ApplicationData& appData) ImVec2 menuBar(DrawData& drawData, ApplicationData& appData)
{ {
ImVec2 size{}; ImVec2 size{};
@@ -175,6 +181,13 @@ ImVec2 menuBar(ApplicationData& appData)
{ {
if (ImGui::BeginMenu("Settings")) if (ImGui::BeginMenu("Settings"))
{ {
bool prevDocked = appData.settings.docked;
ImGui::Checkbox("Docked", &appData.settings.docked);
if (appData.settings.docked != prevDocked)
{
glfwSetWindowAttrib(drawData.window, GLFW_DECORATED, !appData.settings.docked);
}
ImGui::Checkbox("Show Disabled Devices", &appData.settings.showDisabledDevices); ImGui::Checkbox("Show Disabled Devices", &appData.settings.showDisabledDevices);
ImGui::Checkbox("Fit Window Height", &appData.settings.fitWindowHeight); ImGui::Checkbox("Fit Window Height", &appData.settings.fitWindowHeight);
ImGui::Checkbox("Minimize To Tray", &appData.settings.minimizeToTray); ImGui::Checkbox("Minimize To Tray", &appData.settings.minimizeToTray);
@@ -189,6 +202,23 @@ ImVec2 menuBar(ApplicationData& appData)
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (appData.settings.docked)
{
ImVec2 availableSpace = ImGui::GetContentRegionAvail();
ImVec2 cursorPos = ImGui::GetCursorPos();
ImGui::SetCursorPosX(cursorPos.x + availableSpace.x - 33.);
if (ImGui::SmallButton("-"))
{
glfwIconifyWindow(drawData.window);
}
if (ImGui::SmallButton("x"))
{
glfwSetWindowShouldClose(drawData.window, GLFW_TRUE);
}
}
size = ImGui::GetWindowSize(); size = ImGui::GetWindowSize();
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
} }

View File

@@ -8,6 +8,6 @@
void init(DrawData& drawData, ApplicationData& customData); void init(DrawData& drawData, ApplicationData& customData);
void draw(DrawData& drawData, ApplicationData& customData); void draw(DrawData& drawData, ApplicationData& customData);
void cleanup(DrawData& drawData, ApplicationData& appData); void cleanup(DrawData& drawData, ApplicationData& appData);
ImVec2 menuBar(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);