Skip to content

Commit

Permalink
Implement foreign-toplevel output movement
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Nov 19, 2023
1 parent 19a601b commit 89e4d68
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/input/cursor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cursor.hpp"

#include "input/constraint.hpp"
#include "output.hpp"
#include "seat.hpp"
#include "server.hpp"
#include "surface/surface.hpp"
Expand All @@ -12,7 +13,6 @@
#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/edges.h>
#include "wlr-wrap-end.hpp"
Expand Down Expand Up @@ -67,18 +67,22 @@ void Cursor::process_resize(const uint32_t time) const {
const int new_width = new_right - new_left;
const int new_height = new_bottom - new_top;
view.set_size(new_width, new_height);

view.update_outputs();
}

void Cursor::process_move(const uint32_t time) {
(void) time;

set_image("fleur");

/* Move the grabbed view to the new position. */
View* view = seat.server.grabbed_view;
view->current.x = static_cast<int32_t>(std::round(wlr.x - seat.server.grab_x));
view->current.y = static_cast<int32_t>(std::round(std::fmax(wlr.y - seat.server.grab_y, 0)));
View& view = *seat.server.grabbed_view;
const auto new_x = static_cast<int32_t>(std::round(wlr.x - seat.server.grab_x));
const auto new_y = static_cast<int32_t>(std::round(std::fmax(wlr.y - seat.server.grab_y, 0)));
view.set_position(new_x, new_y);

set_image("fleur");
wlr_scene_node_set_position(view->scene_node, view->current.x, view->current.y);
view.update_outputs();
}

/* This event is forwarded by the cursor when a pointer emits an axis event,
Expand Down
20 changes: 20 additions & 0 deletions src/surface/view.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "view.hpp"

#include <utility>

#include "foreign_toplevel.hpp"
#include "input/seat.hpp"
#include "output.hpp"
Expand Down Expand Up @@ -117,6 +119,21 @@ void View::set_size(const int new_width, const int new_height) {
impl_set_size(new_width, new_height);
}

void View::update_outputs() const {
for (auto& output : std::as_const(get_server().outputs)) {
wlr_box output_area = output->full_area;
wlr_box prev_intersect = {}, curr_intersect = {};
wlr_box_intersection(&prev_intersect, &previous, &output_area);
wlr_box_intersection(&curr_intersect, &current, &output_area);

if (wlr_box_empty(&prev_intersect) && !wlr_box_empty(&curr_intersect)) {
toplevel_handle->output_enter(*output);
} else if (!wlr_box_empty(&prev_intersect) && wlr_box_empty(&curr_intersect)) {
toplevel_handle->output_leave(*output);
}
}
}

void View::set_activated(const bool activated) {
impl_set_activated(activated);

Expand Down Expand Up @@ -168,6 +185,7 @@ void View::stack() {
impl_set_maximized(false);
impl_set_fullscreen(false);
set_position(previous.x, previous.y);
update_outputs();
}

bool View::maximize() {
Expand All @@ -181,6 +199,7 @@ bool View::maximize() {
impl_set_fullscreen(false);
impl_set_maximized(true);
set_position(output_box.x, output_box.y);
update_outputs();

return true;
}
Expand All @@ -195,6 +214,7 @@ bool View::fullscreen() {
set_size(output_box.width, output_box.height);
impl_set_fullscreen(true);
set_position(output_box.x, output_box.y);
update_outputs();

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/surface/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ struct View : Surface {
ViewPlacement prev_placement = VIEW_PLACEMENT_STACKING;
ViewPlacement curr_placement = VIEW_PLACEMENT_STACKING;
bool is_minimized = false;
wlr_box current;
wlr_box pending;
wlr_box previous;
wlr_box current = {};
wlr_box previous = {};
std::optional<ForeignToplevelHandle> toplevel_handle = {};

~View() noexcept override = default;
Expand All @@ -36,6 +35,7 @@ struct View : Surface {
void begin_interactive(CursorMode mode, uint32_t edges);
void set_position(int new_x, int new_y);
void set_size(int new_width, int new_height);
void update_outputs() const;
void set_activated(bool activated);
void set_placement(ViewPlacement new_placement, bool force = false);
void set_minimized(bool minimized);
Expand Down
2 changes: 1 addition & 1 deletion src/surface/xdg_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ wlr_box XdgView::get_geometry() const {

void XdgView::map() {
if (pending_map) {
previous = {0, 0, 0, 0};
wlr_xdg_surface_get_geometry(xdg_toplevel.base, &previous);
wlr_xdg_surface_get_geometry(xdg_toplevel.base, &current);

if (!server.outputs.empty()) {
Expand Down

0 comments on commit 89e4d68

Please sign in to comment.