summaryrefslogtreecommitdiff
path: root/gui-wm/wayfire/files/oswitch.patch
blob: 5afbbf77ae8c545c6da32274d28ea9c343dd07a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
From 221a39614392c1e107fe5da1b24837d33c5cdd97 Mon Sep 17 00:00:00 2001
From: daniel <dvrlabs.tv@gmail.com>
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 <dvrlabs.tv@gmail.com>
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.</_long>
 			<default>&lt;super&gt; &lt;shift&gt; KEY_O</default>
 		</option>
+		<option name="previous_output" type="activator">
+			<_short>previous output</_short>
+			<_long>Moves focus to the previous output with the specified activator.</_long>
+			<default>&lt;super&gt; KEY_P</default>
+		</option>
+		<option name="previous_output_with_win" type="activator">
+			<_short>previous output with window</_short>
+			<_long>Moves focus to the previous output with the focused window with the specified activator.</_long>
+			<default>&lt;super&gt; &lt;shift&gt; KEY_P</default>
+		</option>
 	</plugin>
 </wayfire>
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<wf::activatorbinding_t>{"oswitch/next_output_with_win"},
             &switch_output_with_window);
+        output->add_activator(
+            wf::option_wrapper_t<wf::activatorbinding_t>{"oswitch/previous_output"},
+            &switch_output_previous);
+        output->add_activator(
+            wf::option_wrapper_t<wf::activatorbinding_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 <dvrlabs.tv@gmail.com>
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 <algorithm>
 #include <xf86drmMode.h>
 #include <sstream>
 #include <cstring>
@@ -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