Skip to content

Commit

Permalink
fix: handle inexistent workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
WhySoBad committed Nov 25, 2024
1 parent 8486445 commit 525670f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/VirtualDesk.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "VirtualDesk.hpp"
#include "src/Compositor.hpp"
#include <numeric>
#include <algorithm>
#include <unordered_set>
Expand Down Expand Up @@ -121,10 +122,13 @@ CSharedPointer<CMonitor> VirtualDesk::firstAvailableMonitor(const std::vector<CS
int n = INT_MAX;
CSharedPointer<CMonitor> newMonitor;
for (const auto& mon : currentlyEnabledMonitors()) {
auto n_on_mon = g_pCompositor->getWorkspaceByID(mon->activeWorkspaceID())->getWindows();
if (n_on_mon < n) {
n = n_on_mon;
newMonitor = mon;
auto workspace = g_pCompositor->getWorkspaceByID(mon->activeWorkspaceID());
if (workspace) {
auto n_on_mon = workspace->getWindows();
if (n_on_mon < n) {
n = n_on_mon;
newMonitor = mon;
}
}
}
return newMonitor;
Expand Down
10 changes: 8 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ std::string printStateDispatch(eHyprCtlOutputFormat format, std::string arg) {
std::string workspaces;
bool first = true;
for (auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
windows += g_pCompositor->getWorkspaceByID(workspaceId)->getWindows();
auto workspace = g_pCompositor->getWorkspaceByID(workspaceId);
if (workspace) {
windows += workspace->getWindows();
}
if (!first)
workspaces += ", ";
else
Expand All @@ -204,7 +207,10 @@ std::string printStateDispatch(eHyprCtlOutputFormat format, std::string arg) {
std::string workspaces;
bool first = true;
for (auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
windows += g_pCompositor->getWorkspaceByID(workspaceId)->getWindows();
auto workspace = g_pCompositor->getWorkspaceByID(workspaceId);
if (workspace) {
windows += workspace->getWindows();
}
if (!first)
workspaces += ", ";
else
Expand Down

0 comments on commit 525670f

Please sign in to comment.