Skip to content

Commit 89e4d68

Browse files
committed
Implement foreign-toplevel output movement
1 parent 19a601b commit 89e4d68

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src/input/cursor.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cursor.hpp"
22

33
#include "input/constraint.hpp"
4+
#include "output.hpp"
45
#include "seat.hpp"
56
#include "server.hpp"
67
#include "surface/surface.hpp"
@@ -12,7 +13,6 @@
1213
#include "wlr-wrap-start.hpp"
1314
#include <wlr/types/wlr_idle_notify_v1.h>
1415
#include <wlr/types/wlr_pointer.h>
15-
#include <wlr/types/wlr_scene.h>
1616
#include <wlr/types/wlr_seat.h>
1717
#include <wlr/util/edges.h>
1818
#include "wlr-wrap-end.hpp"
@@ -67,18 +67,22 @@ void Cursor::process_resize(const uint32_t time) const {
6767
const int new_width = new_right - new_left;
6868
const int new_height = new_bottom - new_top;
6969
view.set_size(new_width, new_height);
70+
71+
view.update_outputs();
7072
}
7173

7274
void Cursor::process_move(const uint32_t time) {
7375
(void) time;
7476

77+
set_image("fleur");
78+
7579
/* Move the grabbed view to the new position. */
76-
View* view = seat.server.grabbed_view;
77-
view->current.x = static_cast<int32_t>(std::round(wlr.x - seat.server.grab_x));
78-
view->current.y = static_cast<int32_t>(std::round(std::fmax(wlr.y - seat.server.grab_y, 0)));
80+
View& view = *seat.server.grabbed_view;
81+
const auto new_x = static_cast<int32_t>(std::round(wlr.x - seat.server.grab_x));
82+
const auto new_y = static_cast<int32_t>(std::round(std::fmax(wlr.y - seat.server.grab_y, 0)));
83+
view.set_position(new_x, new_y);
7984

80-
set_image("fleur");
81-
wlr_scene_node_set_position(view->scene_node, view->current.x, view->current.y);
85+
view.update_outputs();
8286
}
8387

8488
/* This event is forwarded by the cursor when a pointer emits an axis event,

src/surface/view.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "view.hpp"
22

3+
#include <utility>
4+
35
#include "foreign_toplevel.hpp"
46
#include "input/seat.hpp"
57
#include "output.hpp"
@@ -117,6 +119,21 @@ void View::set_size(const int new_width, const int new_height) {
117119
impl_set_size(new_width, new_height);
118120
}
119121

122+
void View::update_outputs() const {
123+
for (auto& output : std::as_const(get_server().outputs)) {
124+
wlr_box output_area = output->full_area;
125+
wlr_box prev_intersect = {}, curr_intersect = {};
126+
wlr_box_intersection(&prev_intersect, &previous, &output_area);
127+
wlr_box_intersection(&curr_intersect, &current, &output_area);
128+
129+
if (wlr_box_empty(&prev_intersect) && !wlr_box_empty(&curr_intersect)) {
130+
toplevel_handle->output_enter(*output);
131+
} else if (!wlr_box_empty(&prev_intersect) && wlr_box_empty(&curr_intersect)) {
132+
toplevel_handle->output_leave(*output);
133+
}
134+
}
135+
}
136+
120137
void View::set_activated(const bool activated) {
121138
impl_set_activated(activated);
122139

@@ -168,6 +185,7 @@ void View::stack() {
168185
impl_set_maximized(false);
169186
impl_set_fullscreen(false);
170187
set_position(previous.x, previous.y);
188+
update_outputs();
171189
}
172190

173191
bool View::maximize() {
@@ -181,6 +199,7 @@ bool View::maximize() {
181199
impl_set_fullscreen(false);
182200
impl_set_maximized(true);
183201
set_position(output_box.x, output_box.y);
202+
update_outputs();
184203

185204
return true;
186205
}
@@ -195,6 +214,7 @@ bool View::fullscreen() {
195214
set_size(output_box.width, output_box.height);
196215
impl_set_fullscreen(true);
197216
set_position(output_box.x, output_box.y);
217+
update_outputs();
198218

199219
return true;
200220
}

src/surface/view.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ struct View : Surface {
1818
ViewPlacement prev_placement = VIEW_PLACEMENT_STACKING;
1919
ViewPlacement curr_placement = VIEW_PLACEMENT_STACKING;
2020
bool is_minimized = false;
21-
wlr_box current;
22-
wlr_box pending;
23-
wlr_box previous;
21+
wlr_box current = {};
22+
wlr_box previous = {};
2423
std::optional<ForeignToplevelHandle> toplevel_handle = {};
2524

2625
~View() noexcept override = default;
@@ -36,6 +35,7 @@ struct View : Surface {
3635
void begin_interactive(CursorMode mode, uint32_t edges);
3736
void set_position(int new_x, int new_y);
3837
void set_size(int new_width, int new_height);
38+
void update_outputs() const;
3939
void set_activated(bool activated);
4040
void set_placement(ViewPlacement new_placement, bool force = false);
4141
void set_minimized(bool minimized);

src/surface/xdg_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ wlr_box XdgView::get_geometry() const {
197197

198198
void XdgView::map() {
199199
if (pending_map) {
200-
previous = {0, 0, 0, 0};
200+
wlr_xdg_surface_get_geometry(xdg_toplevel.base, &previous);
201201
wlr_xdg_surface_get_geometry(xdg_toplevel.base, &current);
202202

203203
if (!server.outputs.empty()) {

0 commit comments

Comments
 (0)