Fix some windows not being marked as active when opened

In some cases, the active event is arriving before the create event. We need to store the currently active address and initialize the windows accordingly
This commit is contained in:
Pol Rivero
2025-05-01 21:03:46 +02:00
parent 998fd7a192
commit 61c5dad895
4 changed files with 8 additions and 4 deletions

View File

@ -43,7 +43,7 @@ class WindowCreationPayload {
WindowCreationPayload(std::string workspace_name, WindowAddress window_address, WindowCreationPayload(std::string workspace_name, WindowAddress window_address,
WindowRepr window_repr); WindowRepr window_repr);
WindowCreationPayload(std::string workspace_name, WindowAddress window_address, WindowCreationPayload(std::string workspace_name, WindowAddress window_address,
std::string window_class, std::string window_title); std::string window_class, std::string window_title, bool is_active);
WindowCreationPayload(Json::Value const& client_data); WindowCreationPayload(Json::Value const& client_data);
int incrementTimeSpentUncreated(); int incrementTimeSpentUncreated();

View File

@ -179,6 +179,7 @@ class Workspaces : public AModule, public EventHandler {
int m_taskbarIconSize = 16; int m_taskbarIconSize = 16;
Gtk::Orientation m_taskbarOrientation = Gtk::ORIENTATION_HORIZONTAL; Gtk::Orientation m_taskbarOrientation = Gtk::ORIENTATION_HORIZONTAL;
std::string m_onClickWindow; std::string m_onClickWindow;
std::string m_currentActiveWindowAddress;
std::vector<std::regex> m_ignoreWorkspaces; std::vector<std::regex> m_ignoreWorkspaces;

View File

@ -30,10 +30,11 @@ WindowCreationPayload::WindowCreationPayload(std::string workspace_name,
WindowCreationPayload::WindowCreationPayload(std::string workspace_name, WindowCreationPayload::WindowCreationPayload(std::string workspace_name,
WindowAddress window_address, std::string window_class, WindowAddress window_address, std::string window_class,
std::string window_title) std::string window_title, bool is_active)
: m_window(std::make_pair(std::move(window_class), std::move(window_title))), : m_window(std::make_pair(std::move(window_class), std::move(window_title))),
m_windowAddress(std::move(window_address)), m_windowAddress(std::move(window_address)),
m_workspaceName(std::move(workspace_name)) { m_workspaceName(std::move(workspace_name)),
m_isActive(is_active) {
clearAddr(); clearAddr();
clearWorkspaceName(); clearWorkspaceName();
} }

View File

@ -492,7 +492,8 @@ void Workspaces::onWindowOpened(std::string const &payload) {
std::string windowTitle = payload.substr(nextCommaIdx + 1, payload.length() - nextCommaIdx); std::string windowTitle = payload.substr(nextCommaIdx + 1, payload.length() - nextCommaIdx);
m_windowsToCreate.emplace_back(workspaceName, windowAddress, windowClass, windowTitle); bool isActive = m_currentActiveWindowAddress == windowAddress;
m_windowsToCreate.emplace_back(workspaceName, windowAddress, windowClass, windowTitle, isActive);
} }
void Workspaces::onWindowClosed(std::string const &addr) { void Workspaces::onWindowClosed(std::string const &addr) {
@ -591,6 +592,7 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
void Workspaces::onActiveWindowChanged(WindowAddress const &activeWindowAddress) { void Workspaces::onActiveWindowChanged(WindowAddress const &activeWindowAddress) {
spdlog::trace("Active window changed: {}", activeWindowAddress); spdlog::trace("Active window changed: {}", activeWindowAddress);
m_currentActiveWindowAddress = activeWindowAddress;
for (auto &[address, window] : m_orphanWindowMap) { for (auto &[address, window] : m_orphanWindowMap) {
if (address == activeWindowAddress) { if (address == activeWindowAddress) {