From 5804339c75a888d6180f680a18655b995bedbef9 Mon Sep 17 00:00:00 2001 From: Thibault Leclercq Date: Wed, 30 Oct 2024 16:13:09 +0100 Subject: [PATCH] fix focus property in json payloads --- src/floating_window_container.cpp | 2 +- src/leaf_container.cpp | 2 +- src/parent_container.cpp | 2 +- src/policy.cpp | 5 ++++- src/workspace.cpp | 2 +- src/workspace_manager.cpp | 6 +++--- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/floating_window_container.cpp b/src/floating_window_container.cpp index 750316c..1e12ad6 100644 --- a/src/floating_window_container.cpp +++ b/src/floating_window_container.cpp @@ -367,7 +367,7 @@ nlohmann::json FloatingWindowContainer::to_json() const { "width", logical_area.size.width.as_int() }, { "height", logical_area.size.height.as_int() }, } }, - { "focused", is_focused() }, + { "focused", visible && is_focused() }, { "focus", std::vector() }, { "border", "normal" }, { "current_border_width", config->get_border_config().size }, diff --git a/src/leaf_container.cpp b/src/leaf_container.cpp index 2ffd325..64cfb50 100644 --- a/src/leaf_container.cpp +++ b/src/leaf_container.cpp @@ -422,7 +422,7 @@ nlohmann::json LeafContainer::to_json() const { "width", logical_area.size.width.as_int() }, { "height", logical_area.size.height.as_int() }, } }, - { "focused", is_focused() }, + { "focused", visible && is_focused() }, { "focus", std::vector() }, { "border", "normal" }, { "current_border_width", config->get_border_config().size }, diff --git a/src/parent_container.cpp b/src/parent_container.cpp index 8f24468..0ad26bc 100644 --- a/src/parent_container.cpp +++ b/src/parent_container.cpp @@ -809,7 +809,7 @@ nlohmann::json ParentContainer::to_json() const { "width", logical_area.size.width.as_int() }, { "height", logical_area.size.height.as_int() }, } }, - { "focused", is_focused() }, + { "focused", visible && is_focused() }, { "focus", std::vector() }, { "border", "none" }, { "current_border_width", 0 }, diff --git a/src/policy.cpp b/src/policy.cpp index 5638da8..d295582 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -456,8 +456,10 @@ void Policy::advise_output_create(miral::Output const& output) floating_window_manager, state, config, window_controller, animator); workspace_manager.request_first_available_workspace(output_content); output_list.push_back(output_content); - if (state.active_output == nullptr) + if (state.active_output == nullptr) { state.active_output = output_content; + state.active_output->set_is_active(true); + } // Let's rehome some orphan windows if we need to if (!orphaned_window_list.empty()) @@ -520,6 +522,7 @@ void Policy::advise_output_delete(miral::Output const& output) else { state.active_output = output_list.front(); + state.active_output->set_is_active(true); for (auto& window : other_output->collect_all_windows()) { state.active_output->add_immediately(window); diff --git a/src/workspace.cpp b/src/workspace.cpp index 214a505..21240c5 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -474,7 +474,7 @@ nlohmann::json Workspace::to_json() const { "type", "workspace" }, { "name", std::to_string(workspace) }, { "visible", output->is_active() && is_focused }, - { "focused", output->is_active() && is_focused && root->is_focused() }, + { "focused", output->is_active() && is_focused }, { "urgent", false }, { "output", output->get_output().name() }, { "border", "none" }, diff --git a/src/workspace_manager.cpp b/src/workspace_manager.cpp index d8207c1..f753f62 100644 --- a/src/workspace_manager.cpp +++ b/src/workspace_manager.cpp @@ -248,17 +248,17 @@ std::shared_ptr WorkspaceManager::request_focus(int key) return nullptr; auto active_screen = get_active_screen(); + int previous_workspace = -1; if (active_screen) { - int previous_workspace = active_screen->get_active_workspace_num(); + previous_workspace = active_screen->get_active_workspace_num(); last_selected = { previous_workspace, output_to_workspace_mapping[previous_workspace] }; } output_to_workspace_mapping[key]->advise_workspace_active(key); if (active_screen != nullptr) { - auto active_workspace = active_screen->get_active_workspace_num(); - registry.advise_focused(active_screen, active_workspace, output_to_workspace_mapping[key].get(), key); + registry.advise_focused(output_to_workspace_mapping[previous_workspace].get(), previous_workspace, output_to_workspace_mapping[key].get(), key); } else registry.advise_focused(nullptr, -1, output_to_workspace_mapping[key].get(), key);