fix memory errors. oops!

This commit is contained in:
Stanisław Zagórowski 2023-09-13 17:49:07 +02:00
parent ff262eeb13
commit 71ade43d58

View file

@ -1,4 +1,5 @@
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <hyprland/src/Compositor.hpp> #include <hyprland/src/Compositor.hpp>
#include <hyprland/src/config/ConfigManager.hpp> #include <hyprland/src/config/ConfigManager.hpp>
#include <hyprland/src/helpers/Color.hpp> #include <hyprland/src/helpers/Color.hpp>
@ -72,17 +73,29 @@ void changeMonitor(bool quiet, std::string value)
CMonitor* nextMonitor = nullptr; CMonitor* nextMonitor = nullptr;
uint64_t monitorCount = g_pCompositor->m_vMonitors.size();
int delta = 0;
if (value == "next" || value == "+1") { if (value == "next" || value == "+1") {
nextMonitor = g_pCompositor->getMonitorFromID(monitor->ID + 1); delta = 1;
} }
else if (value == "prev" || value == "-1") { else if (value == "prev" || value == "-1") {
nextMonitor = g_pCompositor->getMonitorFromID(monitor->ID - 1); delta = -1;
} }
else { else {
Debug::log(WARN, "Invalid monitor value: %s", value.c_str()); Debug::log(WARN, "Invalid monitor value: %s", value.c_str());
return; return;
} }
int nextMonitorIndex = (monitor->ID + delta) % monitorCount;
if (nextMonitorIndex < 0) {
nextMonitorIndex += monitorCount;
}
nextMonitor = g_pCompositor->m_vMonitors[nextMonitorIndex].get();
int nextWorkspace = nextMonitor->activeWorkspace; int nextWorkspace = nextMonitor->activeWorkspace;
if (quiet) { if (quiet) {