2019-01-10 13:04:42 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <wlr/types/wlr_cursor.h>
|
2019-01-14 12:22:53 +01:00
|
|
|
#include <wlr/util/edges.h>
|
2019-01-10 13:04:42 +01:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/input/cursor.h"
|
|
|
|
#include "sway/input/seat.h"
|
|
|
|
|
|
|
|
struct seatop_resize_tiling_event {
|
2019-01-14 12:22:53 +01:00
|
|
|
struct sway_container *con; // leaf container
|
|
|
|
|
|
|
|
// con, or ancestor of con which will be resized horizontally/vertically
|
|
|
|
struct sway_container *h_con;
|
|
|
|
struct sway_container *v_con;
|
|
|
|
|
2019-01-10 13:04:42 +01:00
|
|
|
enum wlr_edges edge;
|
2019-01-14 12:22:53 +01:00
|
|
|
enum wlr_edges edge_x, edge_y;
|
2019-01-10 13:04:42 +01:00
|
|
|
double ref_lx, ref_ly; // cursor's x/y at start of op
|
2019-01-14 12:22:53 +01:00
|
|
|
double h_con_orig_width; // width of the horizontal ancestor at start
|
|
|
|
double v_con_orig_height; // height of the vertical ancestor at start
|
2019-01-10 13:04:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
|
|
|
struct seatop_resize_tiling_event *e = seat->seatop_data;
|
|
|
|
int amount_x = 0;
|
|
|
|
int amount_y = 0;
|
|
|
|
int moved_x = seat->cursor->cursor->x - e->ref_lx;
|
|
|
|
int moved_y = seat->cursor->cursor->y - e->ref_ly;
|
2019-01-14 12:22:53 +01:00
|
|
|
|
|
|
|
if (e->h_con) {
|
|
|
|
if (e->edge & WLR_EDGE_LEFT) {
|
|
|
|
amount_x = (e->h_con_orig_width - moved_x) - e->h_con->width;
|
|
|
|
} else if (e->edge & WLR_EDGE_RIGHT) {
|
|
|
|
amount_x = (e->h_con_orig_width + moved_x) - e->h_con->width;
|
|
|
|
}
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
2019-01-14 12:22:53 +01:00
|
|
|
if (e->v_con) {
|
|
|
|
if (e->edge & WLR_EDGE_TOP) {
|
|
|
|
amount_y = (e->v_con_orig_height - moved_y) - e->v_con->height;
|
|
|
|
} else if (e->edge & WLR_EDGE_BOTTOM) {
|
|
|
|
amount_y = (e->v_con_orig_height + moved_y) - e->v_con->height;
|
|
|
|
}
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (amount_x != 0) {
|
2019-01-14 12:22:53 +01:00
|
|
|
container_resize_tiled(e->h_con, e->edge_x, amount_x);
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
if (amount_y != 0) {
|
2019-01-14 12:22:53 +01:00
|
|
|
container_resize_tiled(e->v_con, e->edge_y, amount_y);
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_finish(struct sway_seat *seat) {
|
|
|
|
cursor_set_image(seat->cursor, "left_ptr", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_abort(struct sway_seat *seat) {
|
|
|
|
cursor_set_image(seat->cursor, "left_ptr", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_unref(struct sway_seat *seat, struct sway_container *con) {
|
|
|
|
struct seatop_resize_tiling_event *e = seat->seatop_data;
|
|
|
|
if (e->con == con) {
|
|
|
|
seatop_abort(seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sway_seatop_impl seatop_impl = {
|
|
|
|
.motion = handle_motion,
|
|
|
|
.finish = handle_finish,
|
|
|
|
.abort = handle_abort,
|
|
|
|
.unref = handle_unref,
|
|
|
|
};
|
|
|
|
|
|
|
|
void seatop_begin_resize_tiling(struct sway_seat *seat,
|
|
|
|
struct sway_container *con, uint32_t button, enum wlr_edges edge) {
|
|
|
|
seatop_abort(seat);
|
|
|
|
|
|
|
|
struct seatop_resize_tiling_event *e =
|
|
|
|
calloc(1, sizeof(struct seatop_resize_tiling_event));
|
|
|
|
if (!e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e->con = con;
|
|
|
|
e->edge = edge;
|
|
|
|
|
|
|
|
e->ref_lx = seat->cursor->cursor->x;
|
|
|
|
e->ref_ly = seat->cursor->cursor->y;
|
2019-01-14 12:22:53 +01:00
|
|
|
|
|
|
|
if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) {
|
|
|
|
e->edge_x = edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT);
|
|
|
|
e->h_con = container_find_resize_parent(e->con, e->edge_x);
|
|
|
|
|
|
|
|
if (e->h_con) {
|
|
|
|
e->h_con_orig_width = e->h_con->width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)) {
|
|
|
|
e->edge_y = edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM);
|
|
|
|
e->v_con = container_find_resize_parent(e->con, e->edge_y);
|
|
|
|
|
|
|
|
if (e->v_con) {
|
|
|
|
e->v_con_orig_height = e->v_con->height;
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 13:04:42 +01:00
|
|
|
|
|
|
|
seat->seatop_impl = &seatop_impl;
|
|
|
|
seat->seatop_data = e;
|
|
|
|
seat->seatop_button = button;
|
|
|
|
}
|