Minor code cleanup

This commit is contained in:
Pol Rivero
2025-05-02 14:29:27 +02:00
parent 61c5dad895
commit c9215ad818
2 changed files with 6 additions and 17 deletions

View File

@ -105,11 +105,7 @@ void Workspace::initializeWindowMap(const Json::Value &clients_data) {
void Workspace::setActiveWindow(WindowAddress const &addr) { void Workspace::setActiveWindow(WindowAddress const &addr) {
for (auto &window : m_windowMap) { for (auto &window : m_windowMap) {
if (window.address == addr) { window.setActive(window.address == addr);
window.setActive(true);
} else {
window.setActive(false);
}
} }
} }
@ -244,6 +240,7 @@ void Workspace::update(const std::string &workspace_icon) {
m_labelBefore.set_markup(fmt::format(fmt::runtime(formatBefore), fmt::arg("id", id()), m_labelBefore.set_markup(fmt::format(fmt::runtime(formatBefore), fmt::arg("id", id()),
fmt::arg("name", name()), fmt::arg("icon", workspace_icon), fmt::arg("name", name()), fmt::arg("icon", workspace_icon),
fmt::arg("windows", windows))); fmt::arg("windows", windows)));
m_labelBefore.get_style_context()->add_class("workspace-label");
if (m_workspaceManager.enableTaskbar()) { if (m_workspaceManager.enableTaskbar()) {
updateTaskbar(workspace_icon); updateTaskbar(workspace_icon);
@ -261,7 +258,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
for (const auto &window_repr : m_windowMap) { for (const auto &window_repr : m_windowMap) {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
} else { } else if (m_workspaceManager.getWindowSeparator() != "") {
auto windowSeparator = Gtk::make_managed<Gtk::Label>(m_workspaceManager.getWindowSeparator()); auto windowSeparator = Gtk::make_managed<Gtk::Label>(m_workspaceManager.getWindowSeparator());
m_content.pack_start(*windowSeparator, false, false); m_content.pack_start(*windowSeparator, false, false);
windowSeparator->show(); windowSeparator->show();

View File

@ -595,21 +595,13 @@ void Workspaces::onActiveWindowChanged(WindowAddress const &activeWindowAddress)
m_currentActiveWindowAddress = activeWindowAddress; m_currentActiveWindowAddress = activeWindowAddress;
for (auto &[address, window] : m_orphanWindowMap) { for (auto &[address, window] : m_orphanWindowMap) {
if (address == activeWindowAddress) { window.setActive(address == activeWindowAddress);
window.setActive(true);
} else {
window.setActive(false);
}
} }
for (auto const &workspace : m_workspaces) { for (auto const &workspace : m_workspaces) {
workspace->setActiveWindow(activeWindowAddress); workspace->setActiveWindow(activeWindowAddress);
} }
for (auto &window : m_windowsToCreate) { for (auto &window : m_windowsToCreate) {
if (window.getAddress() == activeWindowAddress) { window.setActive(window.getAddress() == activeWindowAddress);
window.setActive(true);
} else {
window.setActive(false);
}
} }
} }
@ -953,7 +945,7 @@ auto Workspaces::update() -> void {
void Workspaces::updateWindowCount() { void Workspaces::updateWindowCount() {
const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces"); const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces");
for (auto &workspace : m_workspaces) { for (auto const &workspace : m_workspaces) {
auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) { auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) {
return x["name"].asString() == workspace->name() || return x["name"].asString() == workspace->name() ||
(workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name()); (workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name());