Initial implementation of active window
TODO: - Sometimes the active event arrives before the create, in which case the window is not activated. - The window title event also looks unreliable in some cases, will need to investigate
This commit is contained in:
@ -341,6 +341,8 @@ void Workspaces::onEvent(const std::string &ev) {
|
||||
onWorkspaceRenamed(payload);
|
||||
} else if (eventName == "windowtitlev2") {
|
||||
onWindowTitleEvent(payload);
|
||||
} else if (eventName == "activewindowv2") {
|
||||
onActiveWindowChanged(payload);
|
||||
} else if (eventName == "configreloaded") {
|
||||
onConfigReloaded();
|
||||
}
|
||||
@ -561,9 +563,10 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
|
||||
(*windowWorkspace)->insertWindow(std::move(wcp));
|
||||
};
|
||||
} else {
|
||||
auto queuedWindow = std::ranges::find_if(m_windowsToCreate, [payload](auto &windowPayload) {
|
||||
return windowPayload.getAddress() == payload;
|
||||
});
|
||||
auto queuedWindow =
|
||||
std::ranges::find_if(m_windowsToCreate, [&windowAddress](auto &windowPayload) {
|
||||
return windowPayload.getAddress() == windowAddress;
|
||||
});
|
||||
|
||||
// If the window was queued, rename it in the queue
|
||||
if (queuedWindow != m_windowsToCreate.end()) {
|
||||
@ -586,6 +589,28 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onActiveWindowChanged(WindowAddress const &activeWindowAddress) {
|
||||
spdlog::trace("Active window changed: {}", activeWindowAddress);
|
||||
|
||||
for (auto &[address, window] : m_orphanWindowMap) {
|
||||
if (address == activeWindowAddress) {
|
||||
window.setActive(true);
|
||||
} else {
|
||||
window.setActive(false);
|
||||
}
|
||||
}
|
||||
for (auto const &workspace : m_workspaces) {
|
||||
workspace->setActiveWindow(activeWindowAddress);
|
||||
}
|
||||
for (auto &window : m_windowsToCreate) {
|
||||
if (window.getAddress() == activeWindowAddress) {
|
||||
window.setActive(true);
|
||||
} else {
|
||||
window.setActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onConfigReloaded() {
|
||||
spdlog::info("Hyprland config reloaded, reinitializing hyprland/workspaces module...");
|
||||
init();
|
||||
@ -701,6 +726,7 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
|
||||
}
|
||||
|
||||
populateBoolConfig(workspaceTaskbar, "enable", m_enableTaskbar);
|
||||
populateBoolConfig(workspaceTaskbar, "update-active-window", m_updateActiveWindow);
|
||||
|
||||
if (workspaceTaskbar["format"].isString()) {
|
||||
/* The user defined a format string, use it */
|
||||
@ -765,6 +791,12 @@ auto Workspaces::registerIpc() -> void {
|
||||
"rewrite rule uses the 'title' field.");
|
||||
m_ipc.registerForIPC("windowtitlev2", this);
|
||||
}
|
||||
if (m_updateActiveWindow) {
|
||||
spdlog::info(
|
||||
"Registering for Hyprland's 'activewindowv2' events because 'update-active-window' is set "
|
||||
"to true.");
|
||||
m_ipc.registerForIPC("activewindowv2", this);
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::removeWorkspacesToRemove() {
|
||||
|
Reference in New Issue
Block a user