From 221a39614392c1e107fe5da1b24837d33c5cdd97 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 13 Sep 2022 15:52:48 -0400 Subject: [PATCH 1/3] added get_previous_layout to 'output-layout' --- src/api/wayfire/output-layout.hpp | 7 +++++++ src/core/output-layout.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/api/wayfire/output-layout.hpp b/src/api/wayfire/output-layout.hpp index fa6e83e3..cadbe9f4 100644 --- a/src/api/wayfire/output-layout.hpp +++ b/src/api/wayfire/output-layout.hpp @@ -105,6 +105,13 @@ class output_layout_t : public wf::signal_provider_t */ wf::output_t *get_next_output(wf::output_t *output); + /** + * @return the "previous" output in the layout. It is guaranteed that starting + * with any output in the layout, and successively calling this function + * will iterate over all outputs + */ + wf::output_t *get_previous_output(wf::output_t *output); + /** * @return the output_t associated with the wlr_output, or null if the * output isn't found diff --git a/src/core/output-layout.cpp b/src/core/output-layout.cpp index 732bda82..e146fe66 100644 --- a/src/core/output-layout.cpp +++ b/src/core/output-layout.cpp @@ -1577,6 +1577,20 @@ class output_layout_t::impl } } + wf::output_t *get_previous_output(wf::output_t *output) + { + auto os = get_outputs(); + + auto it = std::find(os.rbegin(), os.rend(), output); + if ((it == os.rend()) || (std::next(it) == os.rend())) + { + return os[0]; + } else + { + return *(++it); + } + } + wf::output_t *get_output_coords_at(const wf::pointf_t& origin, wf::pointf_t& closest) { -- 2.37.3 From 933b40d5fa77ecbb19d984712ae5f051f72fdadf Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 13 Sep 2022 19:10:27 -0400 Subject: [PATCH 2/3] Added previous_output and previous_output_with_win to 'oswitch' plugin --- metadata/oswitch.xml | 10 ++++++ plugins/single_plugins/oswitch.cpp | 50 ++++++++++++++++++++++++++++++ src/core/output-layout.cpp | 5 +++ 3 files changed, 65 insertions(+) diff --git a/metadata/oswitch.xml b/metadata/oswitch.xml index 209ee0f0..c6779c77 100644 --- a/metadata/oswitch.xml +++ b/metadata/oswitch.xml @@ -14,5 +14,15 @@ <_long>Moves focus to the next output with the focused window with the specified activator. <super> <shift> KEY_O + + diff --git a/plugins/single_plugins/oswitch.cpp b/plugins/single_plugins/oswitch.cpp index 61b7ef2f..b7cb2f87 100644 --- a/plugins/single_plugins/oswitch.cpp +++ b/plugins/single_plugins/oswitch.cpp @@ -23,6 +23,7 @@ class wayfire_output_manager : public wf::plugin_interface_t return true; }; + wf::activator_callback switch_output_with_window = [=] (auto) { auto next = @@ -45,6 +46,46 @@ class wayfire_output_manager : public wf::plugin_interface_t return true; }; + wf::wl_idle_call idle_previous_output; + + wf::activator_callback switch_output_previous = [=] (auto) + { + /* when we switch the output, the oswitch keybinding + * may be activated for the previous output, which we don't want, + * so we postpone the switch */ + auto previous = + wf::get_core().output_layout->get_previous_output(output); + idle_previous_output.run_once([=] () + { + wf::get_core().focus_output(previous); + }); + + return true; + }; + + + wf::activator_callback switch_output_with_window_previous = [=] (auto) + { + auto previous = + wf::get_core().output_layout->get_previous_output(output); + auto view = output->get_active_view(); + + if (!view) + { + switch_output_previous(wf::activator_data_t{}); + + return true; + } + + wf::get_core().move_view_to_output(view, previous, true); + idle_previous_output.run_once([=] () + { + wf::get_core().focus_output(previous); + }); + + return true; + }; + public: void init() { @@ -57,13 +98,22 @@ class wayfire_output_manager : public wf::plugin_interface_t output->add_activator( wf::option_wrapper_t{"oswitch/next_output_with_win"}, &switch_output_with_window); + output->add_activator( + wf::option_wrapper_t{"oswitch/previous_output"}, + &switch_output_previous); + output->add_activator( + wf::option_wrapper_t{"oswitch/previous_output_with_win"}, + &switch_output_with_window_previous); } void fini() { output->rem_binding(&switch_output); output->rem_binding(&switch_output_with_window); + output->rem_binding(&switch_output_previous); + output->rem_binding(&switch_output_with_window_previous); idle_next_output.disconnect(); + idle_previous_output.disconnect(); } }; diff --git a/src/core/output-layout.cpp b/src/core/output-layout.cpp index e146fe66..82455fec 100644 --- a/src/core/output-layout.cpp +++ b/src/core/output-layout.cpp @@ -1670,6 +1670,11 @@ wf::output_t*output_layout_t::get_next_output(wf::output_t *output) return pimpl->get_next_output(output); } +wf::output_t*output_layout_t::get_previous_output(wf::output_t *output) +{ + return pimpl->get_previous_output(output); +} + wf::output_t*output_layout_t::find_output(wlr_output *output) { return pimpl->find_output(output); -- 2.37.3 From 51a1ddac3352d9315ac53bf13cbbb5d76721c8ba Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 13 Sep 2022 19:33:45 -0400 Subject: [PATCH 3/3] prev output now wraps appropriately --- src/core/output-layout.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/output-layout.cpp b/src/core/output-layout.cpp index 82455fec..6d930971 100644 --- a/src/core/output-layout.cpp +++ b/src/core/output-layout.cpp @@ -11,6 +11,7 @@ #include "seat/cursor.hpp" #include "core-impl.hpp" +#include #include #include #include @@ -1580,15 +1581,17 @@ class output_layout_t::impl wf::output_t *get_previous_output(wf::output_t *output) { auto os = get_outputs(); + std::reverse(os.begin(), os.end()); - auto it = std::find(os.rbegin(), os.rend(), output); - if ((it == os.rend()) || (std::next(it) == os.rend())) + auto it = std::find(os.begin(), os.end(), output); + if ((it == os.end()) || (std::next(it) == os.end())) { return os[0]; } else { return *(++it); } + } wf::output_t *get_output_coords_at(const wf::pointf_t& origin, -- 2.37.3