This splits each seat operation (drag/move tiling/floating etc) into a separate file and introduces a struct sway_seatop_impl to abstract the operation. The move_tiling_threshold operation has been merged into move_tiling. The main logic for each operation is untouched aside from variable renames. The following previously-static functions have been made public: * node_at_coords * container_raise_floating * render_rect * premultiply_alpha * scale_boxmaster
parent
15ac580b28
commit
ed5aafd90b
@ -0,0 +1,77 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include "sway/input/cursor.h"
|
||||||
|
#include "sway/input/seat.h"
|
||||||
|
#include "sway/tree/view.h"
|
||||||
|
|
||||||
|
struct seatop_down_event {
|
||||||
|
struct sway_container *con;
|
||||||
|
double ref_lx, ref_ly; // cursor's x/y at start of op
|
||||||
|
double ref_con_lx, ref_con_ly; // container's x/y at start of op
|
||||||
|
bool moved;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
||||||
|
struct seatop_down_event *e = seat->seatop_data;
|
||||||
|
struct sway_container *con = e->con;
|
||||||
|
if (seat_is_input_allowed(seat, con->view->surface)) {
|
||||||
|
double moved_x = seat->cursor->cursor->x - e->ref_lx;
|
||||||
|
double moved_y = seat->cursor->cursor->y - e->ref_ly;
|
||||||
|
double sx = e->ref_con_lx + moved_x;
|
||||||
|
double sy = e->ref_con_ly + moved_y;
|
||||||
|
wlr_seat_pointer_notify_motion(seat->wlr_seat, time_msec, sx, sy);
|
||||||
|
}
|
||||||
|
e->moved = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_finish(struct sway_seat *seat) {
|
||||||
|
struct seatop_down_event *e = seat->seatop_data;
|
||||||
|
// Set the cursor's previous coords to the x/y at the start of the
|
||||||
|
// operation, so the container change will be detected if using
|
||||||
|
// focus_follows_mouse and the cursor moved off the original container
|
||||||
|
// during the operation.
|
||||||
|
seat->cursor->previous.x = e->ref_lx;
|
||||||
|
seat->cursor->previous.y = e->ref_ly;
|
||||||
|
if (e->moved) {
|
||||||
|
cursor_send_pointer_motion(seat->cursor, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_down_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_down(struct sway_seat *seat,
|
||||||
|
struct sway_container *con, uint32_t button, int sx, int sy) {
|
||||||
|
seatop_abort(seat);
|
||||||
|
|
||||||
|
struct seatop_down_event *e =
|
||||||
|
calloc(1, sizeof(struct seatop_down_event));
|
||||||
|
if (!e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e->con = con;
|
||||||
|
e->ref_lx = seat->cursor->cursor->x;
|
||||||
|
e->ref_ly = seat->cursor->cursor->y;
|
||||||
|
e->ref_con_lx = sx;
|
||||||
|
e->ref_con_ly = sy;
|
||||||
|
e->moved = false;
|
||||||
|
|
||||||
|
seat->seatop_impl = &seatop_impl;
|
||||||
|
seat->seatop_data = e;
|
||||||
|
seat->seatop_button = button;
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include "sway/desktop.h"
|
||||||
|
#include "sway/input/cursor.h"
|
||||||
|
#include "sway/input/seat.h"
|
||||||
|
|
||||||
|
struct seatop_move_floating_event {
|
||||||
|
struct sway_container *con;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
||||||
|
struct seatop_move_floating_event *e = seat->seatop_data;
|
||||||
|
desktop_damage_whole_container(e->con);
|
||||||
|
container_floating_translate(e->con,
|
||||||
|
seat->cursor->cursor->x - seat->cursor->previous.x,
|
||||||
|
seat->cursor->cursor->y - seat->cursor->previous.y);
|
||||||
|
desktop_damage_whole_container(e->con);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_finish(struct sway_seat *seat) {
|
||||||
|
struct seatop_move_floating_event *e = seat->seatop_data;
|
||||||
|
|
||||||
|
// We "move" the container to its own location
|
||||||
|
// so it discovers its output again.
|
||||||
|
container_floating_move_to(e->con, e->con->x, e->con->y);
|
||||||
|
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_move_floating_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_move_floating(struct sway_seat *seat,
|
||||||
|
struct sway_container *con, uint32_t button) {
|
||||||
|
seatop_abort(seat);
|
||||||
|
|
||||||
|
struct seatop_move_floating_event *e =
|
||||||
|
calloc(1, sizeof(struct seatop_move_floating_event));
|
||||||
|
if (!e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e->con = con;
|
||||||
|
|
||||||
|
seat->seatop_impl = &seatop_impl;
|
||||||
|
seat->seatop_data = e;
|
||||||
|
seat->seatop_button = button;
|
||||||
|
|
||||||
|
container_raise_floating(con);
|
||||||
|
|
||||||
|
cursor_set_image(seat->cursor, "grab", NULL);
|
||||||
|
}
|
@ -0,0 +1,335 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <limits.h>
|
||||||
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include <wlr/util/edges.h>
|
||||||
|
#include "sway/desktop.h"
|
||||||
|
#include "sway/input/cursor.h"
|
||||||
|
#include "sway/input/seat.h"
|
||||||
|
#include "sway/output.h"
|
||||||
|
#include "sway/tree/arrange.h"
|
||||||
|
#include "sway/tree/node.h"
|
||||||
|
#include "sway/tree/view.h"
|
||||||
|
#include "sway/tree/workspace.h"
|
||||||
|
|
||||||
|
// Thickness of the dropzone when dragging to the edge of a layout container
|
||||||
|
#define DROP_LAYOUT_BORDER 30
|
||||||
|
|
||||||
|
struct seatop_move_tiling_event {
|
||||||
|
struct sway_container *con;
|
||||||
|
struct sway_node *target_node;
|
||||||
|
enum wlr_edges target_edge;
|
||||||
|
struct wlr_box drop_box;
|
||||||
|
double ref_lx, ref_ly; // cursor's x/y at start of op
|
||||||
|
bool threshold_reached;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void handle_render(struct sway_seat *seat,
|
||||||
|
struct sway_output *output, pixman_region32_t *damage) {
|
||||||
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
||||||
|
if (!e->threshold_reached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e->target_node && node_get_output(e->target_node) == output) {
|
||||||
|
float color[4];
|
||||||
|
memcpy(&color, config->border_colors.focused.indicator,
|
||||||
|
sizeof(float) * 4);
|
||||||
|
premultiply_alpha(color, 0.5);
|
||||||
|
struct wlr_box box;
|
||||||
|
memcpy(&box, &e->drop_box, sizeof(struct wlr_box));
|
||||||
|
scale_box(&box, output->wlr_output->scale);
|
||||||
|
render_rect(output->wlr_output, damage, &box, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_motion_prethreshold(struct sway_seat *seat) {
|
||||||
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
||||||
|
double cx = seat->cursor->cursor->x;
|
||||||
|
double cy = seat->cursor->cursor->y;
|
||||||
|
double sx = e->ref_lx;
|
||||||
|
double sy = e->ref_ly;
|
||||||
|
|
||||||
|
// Get the scaled threshold for the output. Even if the operation goes
|
||||||
|
// across multiple outputs of varying scales, just use the scale for the
|
||||||
|
// output that the cursor is currently on for simplicity.
|
||||||
|
struct wlr_output *wlr_output = wlr_output_layout_output_at(
|
||||||
|
root->output_layout, cx, cy);
|
||||||
|
double output_scale = wlr_output ? wlr_output->scale : 1;
|
||||||
|
double threshold = config->tiling_drag_threshold * output_scale;
|
||||||
|
threshold *= threshold;
|
||||||
|
|
||||||
|
// If the threshold has been exceeded, start the actual drag
|
||||||
|
if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) {
|
||||||
|
e->threshold_reached = true;
|
||||||
|
cursor_set_image(seat->cursor, "grab", NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resize_box(struct wlr_box *box, enum wlr_edges edge,
|
||||||
|
int thickness) {
|
||||||
|
switch (edge) {
|
||||||
|
case WLR_EDGE_TOP:
|
||||||
|
box->height = thickness;
|
||||||
|
break;
|
||||||
|
case WLR_EDGE_LEFT:
|
||||||
|
box->width = thickness;
|
||||||
|
break;
|
||||||
|
case WLR_EDGE_RIGHT:
|
||||||
|
box->x = box->x + box->width - thickness;
|
||||||
|
box->width = thickness;
|
||||||
|
break;
|
||||||
|
case WLR_EDGE_BOTTOM:
|
||||||
|
box->y = box->y + box->height - thickness;
|
||||||
|
box->height = thickness;
|
||||||
|
break;
|
||||||
|
case WLR_EDGE_NONE:
|
||||||
|
box->x += thickness;
|
||||||
|
box->y += thickness;
|
||||||
|
box->width -= thickness * 2;
|
||||||
|
box->height -= thickness * 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_motion_postthreshold(struct sway_seat *seat) {
|
||||||
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
||||||
|
struct wlr_surface *surface = NULL;
|
||||||
|
double sx, sy;
|
||||||
|
struct sway_cursor *cursor = seat->cursor;
|
||||||
|
struct sway_node *node = node_at_coords(seat,
|
||||||
|
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
||||||
|
// Damage the old location
|
||||||
|
desktop_damage_box(&e->drop_box);
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
// Eg. hovered over a layer surface such as swaybar
|
||||||
|
e->target_node = NULL;
|
||||||
|
e->target_edge = WLR_EDGE_NONE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node->type == N_WORKSPACE) {
|
||||||
|
// Emtpy workspace
|
||||||
|
e->target_node = node;
|
||||||
|
e->target_edge = WLR_EDGE_NONE;
|
||||||
|
workspace_get_box(node->sway_workspace, &e->drop_box);
|
||||||
|
desktop_damage_box(&e->drop_box);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deny moving within own workspace if this is the only child
|
||||||
|
struct sway_container *con = node->sway_container;
|
||||||
|
if (workspace_num_tiling_views(e->con->workspace) == 1 &&
|
||||||
|
con->workspace == e->con->workspace) {
|
||||||
|
e->target_node = NULL;
|
||||||
|
e->target_edge = WLR_EDGE_NONE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traverse the ancestors, trying to find a layout container perpendicular
|
||||||
|
// to the edge. Eg. close to the top or bottom of a horiz layout.
|
||||||
|
while (con) {
|
||||||
|
enum wlr_edges edge = WLR_EDGE_NONE;
|
||||||
|
enum sway_container_layout layout = container_parent_layout(con);
|
||||||
|
struct wlr_box parent;
|
||||||
|
con->parent ? container_get_box(con->parent, &parent) :
|
||||||
|
workspace_get_box(con->workspace, &parent);
|
||||||
|
if (layout == L_HORIZ || layout == L_TABBED) {
|
||||||
|
if (cursor->cursor->y < parent.y + DROP_LAYOUT_BORDER) {
|
||||||
|
edge = WLR_EDGE_TOP;
|
||||||
|
} else if (cursor->cursor->y > parent.y + parent.height
|
||||||
|
- DROP_LAYOUT_BORDER) {
|
||||||
|
edge = WLR_EDGE_BOTTOM;
|
||||||
|
}
|
||||||
|
} else if (layout == L_VERT || layout == L_STACKED) {
|
||||||
|
if (cursor->cursor->x < parent.x + DROP_LAYOUT_BORDER) {
|
||||||
|
edge = WLR_EDGE_LEFT;
|
||||||
|
} else if (cursor->cursor->x > parent.x + parent.width
|
||||||
|
- DROP_LAYOUT_BORDER) {
|
||||||
|
edge = WLR_EDGE_RIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (edge) {
|
||||||
|
e->target_node = node_get_parent(&con->node);
|
||||||
|
e->target_edge = edge;
|
||||||
|
node_get_box(e->target_node, &e->drop_box);
|
||||||
|
resize_box(&e->drop_box, edge, DROP_LAYOUT_BORDER);
|
||||||
|
desktop_damage_box(&e->drop_box);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
con = con->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the hovered view - but we must be over the actual surface
|
||||||
|
con = node->sway_container;
|
||||||
|
if (!con->view->surface || node == &e->con->node) {
|
||||||
|
e->target_node = NULL;
|
||||||
|
e->target_edge = WLR_EDGE_NONE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the closest edge
|
||||||
|
size_t thickness = fmin(con->content_width, con->content_height) * 0.3;
|
||||||
|
size_t closest_dist = INT_MAX;
|
||||||
|
size_t dist;
|
||||||
|
e->target_edge = WLR_EDGE_NONE;
|
||||||
|
if ((dist = cursor->cursor->y - con->y) < closest_dist) {
|
||||||
|
closest_dist = dist;
|
||||||
|
e->target_edge = WLR_EDGE_TOP;
|
||||||
|
}
|
||||||
|
if ((dist = cursor->cursor->x - con->x) < closest_dist) {
|
||||||
|
closest_dist = dist;
|
||||||
|
e->target_edge = WLR_EDGE_LEFT;
|
||||||
|
}
|
||||||
|
if ((dist = con->x + con->width - cursor->cursor->x) < closest_dist) {
|
||||||
|
closest_dist = dist;
|
||||||
|
e->target_edge = WLR_EDGE_RIGHT;
|
||||||
|
}
|
||||||
|
if ((dist = con->y + con->height - cursor->cursor->y) < closest_dist) {
|
||||||
|
closest_dist = dist;
|
||||||
|
e->target_edge = WLR_EDGE_BOTTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (closest_dist > thickness) {
|
||||||
|
e->target_edge = WLR_EDGE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
e->target_node = node;
|
||||||
|
e->drop_box.x = con->content_x;
|
||||||
|
e->drop_box.y = con->content_y;
|
||||||
|
e->drop_box.width = con->content_width;
|
||||||
|
e->drop_box.height = con->content_height;
|
||||||
|
resize_box(&e->drop_box, e->target_edge, thickness);
|
||||||
|
desktop_damage_box(&e->drop_box);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
||||||
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
||||||
|
if (e->threshold_reached) {
|
||||||
|
handle_motion_postthreshold(seat);
|
||||||
|
} else {
|
||||||
|
handle_motion_prethreshold(seat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_abort(struct sway_seat *seat) {
|
||||||
|
cursor_set_image(seat->cursor, "left_ptr", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_parallel(enum sway_container_layout layout,
|
||||||
|
enum wlr_edges edge) {
|
||||||
|
bool layout_is_horiz = layout == L_HORIZ || layout == L_TABBED;
|
||||||
|
bool edge_is_horiz = edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT;
|
||||||
|
return layout_is_horiz == edge_is_horiz;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_finish(struct sway_seat *seat) {
|
||||||
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
||||||
|
|
||||||
|
if (!e->target_node) {
|
||||||
|
handle_abort(seat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sway_container *con = e->con;
|
||||||
|
struct sway_container *old_parent = con->parent;
|
||||||
|
struct sway_workspace *old_ws = con->workspace;
|
||||||
|
struct sway_node *target_node = e->target_node;
|
||||||
|
struct sway_workspace *new_ws = target_node->type == N_WORKSPACE ?
|
||||||
|
target_node->sway_workspace : target_node->sway_container->workspace;
|
||||||
|
enum wlr_edges edge = e->target_edge;
|
||||||
|
int after = edge != WLR_EDGE_TOP && edge != WLR_EDGE_LEFT;
|
||||||
|
|
||||||
|
container_detach(con);
|
||||||
|
|
||||||
|
// Moving container into empty workspace
|
||||||
|
if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) {
|
||||||
|
workspace_add_tiling(new_ws, con);
|
||||||
|
} else if (target_node->type == N_CONTAINER) {
|
||||||
|
// Moving container before/after another
|
||||||
|
struct sway_container *target = target_node->sway_container;
|
||||||
|
enum sway_container_layout layout = container_parent_layout(target);
|
||||||
|
if (edge && !is_parallel(layout, edge)) {
|
||||||
|
enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
|
||||||
|
edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
|
||||||
|
container_split(target, new_layout);
|
||||||
|
}
|
||||||
|
container_add_sibling(target, con, after);
|
||||||
|
} else {
|
||||||
|
// Target is a workspace which requires splitting
|
||||||
|
enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
|
||||||
|
edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
|
||||||
|
workspace_split(new_ws, new_layout);
|
||||||
|
workspace_insert_tiling(new_ws, con, after);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old_parent) {
|
||||||
|
container_reap_empty(old_parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a bit dirty, but we'll set the dimensions to that of a sibling.
|
||||||
|
// I don't think there's any other way to make it consistent without
|
||||||
|
// changing how we auto-size containers.
|
||||||
|
list_t *siblings = container_get_siblings(con);
|
||||||
|
if (siblings->length > 1) {
|
||||||
|
int index = list_find(siblings, con);
|
||||||
|
struct sway_container *sibling = index == 0 ?
|
||||||
|
siblings->items[1] : siblings->items[index - 1];
|
||||||
|
con->width = sibling->width;
|
||||||
|
con->height = sibling->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
arrange_workspace(old_ws);
|
||||||
|
if (new_ws != old_ws) {
|
||||||
|
arrange_workspace(new_ws);
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor_set_image(seat->cursor, "left_ptr", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_unref(struct sway_seat *seat, struct sway_container *con) {
|
||||||
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
||||||
|
if (e->target_node == &con->node) { // Drop target
|
||||||
|
e->target_node = NULL;
|
||||||
|
}
|
||||||
|
if (e->con == con) { // The container being moved
|
||||||
|
seatop_abort(seat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct sway_seatop_impl seatop_impl = {
|
||||||
|
.motion = handle_motion,
|
||||||
|
.finish = handle_finish,
|
||||||
|
.abort = handle_abort,
|
||||||
|
.unref = handle_unref,
|
||||||
|
.render = handle_render,
|
||||||
|
};
|
||||||
|
|
||||||
|
void seatop_begin_move_tiling_threshold(struct sway_seat *seat,
|
||||||
|
struct sway_container *con, uint32_t button) {
|
||||||
|
seatop_abort(seat);
|
||||||
|
|
||||||
|
struct seatop_move_tiling_event *e =
|
||||||
|
calloc(1, sizeof(struct seatop_move_tiling_event));
|
||||||
|
if (!e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e->con = con;
|
||||||
|
e->ref_lx = seat->cursor->cursor->x;
|
||||||
|
e->ref_ly = seat->cursor->cursor->y;
|
||||||
|
|
||||||
|
seat->seatop_impl = &seatop_impl;
|
||||||
|
seat->seatop_data = e;
|
||||||
|
seat->seatop_button = button;
|
||||||
|
|
||||||
|
container_raise_floating(con);
|
||||||
|
}
|
||||||
|
|
||||||
|
void seatop_begin_move_tiling(struct sway_seat *seat,
|
||||||
|
struct sway_container *con, uint32_t button) {
|
||||||
|
seatop_begin_move_tiling_threshold(seat, con, button);
|
||||||
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
||||||
|
if (e) {
|
||||||
|
e->threshold_reached = true;
|
||||||
|
cursor_set_image(seat->cursor, "grab", NULL);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,199 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <limits.h>
|
||||||
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include <wlr/types/wlr_xcursor_manager.h>
|
||||||
|
#include "sway/input/cursor.h"
|
||||||
|
#include "sway/input/seat.h"
|
||||||
|
#include "sway/tree/arrange.h"
|
||||||
|
#include "sway/tree/view.h"
|
||||||
|
#include "sway/tree/workspace.h"
|
||||||
|
|
||||||
|
struct seatop_resize_floating_event {
|
||||||
|
struct sway_container *con;
|
||||||
|
enum wlr_edges edge;
|
||||||
|
bool preserve_ratio;
|
||||||
|
double ref_lx, ref_ly; // cursor's x/y at start of op
|
||||||
|
double ref_width, ref_height; // container's size at start of op
|
||||||
|
double ref_con_lx, ref_con_ly; // container's x/y at start of op
|
||||||
|
};
|
||||||
|
|
||||||
|
static void calculate_floating_constraints(struct sway_container *con,
|
||||||
|
int *min_width, int *max_width, int *min_height, int *max_height) {
|
||||||
|
if (config->floating_minimum_width == -1) { // no minimum
|
||||||
|
*min_width = 0;
|
||||||
|
} else if (config->floating_minimum_width == 0) { // automatic
|
||||||
|
*min_width = 75;
|
||||||
|
} else {
|
||||||
|
*min_width = config->floating_minimum_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->floating_minimum_height == -1) { // no minimum
|
||||||
|
*min_height = 0;
|
||||||
|
} else if (config->floating_minimum_height == 0) { // automatic
|
||||||
|
*min_height = 50;
|
||||||
|
} else {
|
||||||
|
*min_height = config->floating_minimum_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->floating_maximum_width == -1) { // no maximum
|
||||||
|
*max_width = INT_MAX;
|
||||||
|
} else if (config->floating_maximum_width == 0) { // automatic
|
||||||
|
*max_width = con->workspace->width;
|
||||||
|
} else {
|
||||||
|
*max_width = config->floating_maximum_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->floating_maximum_height == -1) { // no maximum
|
||||||
|
*max_height = INT_MAX;
|
||||||
|
} else if (config->floating_maximum_height == 0) { // automatic
|
||||||
|
*max_height = con->workspace->height;
|
||||||
|
} else {
|
||||||
|
*max_height = config->floating_maximum_height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
|
||||||
|
struct seatop_resize_floating_event *e = seat->seatop_data;
|
||||||
|
struct sway_container *con = e->con;
|
||||||
|
enum wlr_edges edge = e->edge;
|
||||||
|
struct sway_cursor *cursor = seat->cursor;
|
||||||
|
|
||||||
|
// The amount the mouse has moved since the start of the resize operation
|
||||||
|
// Positive is down/right
|
||||||
|
double mouse_move_x = cursor->cursor->x - e->ref_lx;
|
||||||
|
double mouse_move_y = cursor->cursor->y - e->ref_ly;
|
||||||
|
|
||||||
|
if (edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM) {
|
||||||
|
mouse_move_x = 0;
|
||||||
|
}
|
||||||
|
if (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT) {
|
||||||
|
mouse_move_y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double grow_width = edge & WLR_EDGE_LEFT ? -mouse_move_x : mouse_move_x;
|
||||||
|
double grow_height = edge & WLR_EDGE_TOP ? -mouse_move_y : mouse_move_y;
|
||||||
|
|
||||||
|
if (e->preserve_ratio) {
|
||||||
|
double x_multiplier = grow_width / e->ref_width;
|
||||||
|
double y_multiplier = grow_height / e->ref_height;
|
||||||
|
double max_multiplier = fmax(x_multiplier, y_multiplier);
|
||||||
|
grow_width = e->ref_width * max_multiplier;
|
||||||
|
grow_height = e->ref_height * max_multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine new width/height, and accommodate for floating min/max values
|
||||||
|
double width = e->ref_width + grow_width;
|
||||||
|
double height = e->ref_height + grow_height;
|
||||||
|
int min_width, max_width, min_height, max_height;
|
||||||
|
calculate_floating_constraints(con, &min_width, &max_width,
|
||||||
|
&min_height, &max_height);
|
||||||
|
width = fmax(min_width, fmin(width, max_width));
|
||||||
|
height = fmax(min_height, fmin(height, max_height));
|
||||||
|
|
||||||
|
// Apply the view's min/max size
|
||||||
|
if (con->view) {
|
||||||
|
double view_min_width, view_max_width, view_min_height, view_max_height;
|
||||||
|
view_get_constraints(con->view, &view_min_width, &view_max_width,
|
||||||
|
&view_min_height, &view_max_height);
|
||||||
|
width = fmax(view_min_width, fmin(width, view_max_width));
|
||||||
|
height = fmax(view_min_height, fmin(height, view_max_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalculate these, in case we hit a min/max limit
|
||||||
|
grow_width = width - e->ref_width;
|
||||||
|
grow_height = height - e->ref_height;
|
||||||
|
|
||||||
|
// Determine grow x/y values - these are relative to the container's x/y at
|
||||||
|
// the start of the resize operation.
|
||||||
|
double grow_x = 0, grow_y = 0;
|
||||||
|
if (edge & WLR_EDGE_LEFT) {
|
||||||
|
grow_x = -grow_width;
|
||||||
|
} else if (edge & WLR_EDGE_RIGHT) {
|
||||||
|
grow_x = 0;
|
||||||
|
} else {
|
||||||
|
grow_x = -grow_width / 2;
|
||||||
|
}
|
||||||
|
if (edge & WLR_EDGE_TOP) {
|
||||||
|
grow_y = -grow_height;
|
||||||
|
} else if (edge & WLR_EDGE_BOTTOM) {
|
||||||
|
grow_y = 0;
|
||||||
|
} else {
|
||||||
|
grow_y = -grow_height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the amounts we need to bump everything relative to the current
|
||||||
|
// size.
|
||||||
|
int relative_grow_width = width - con->width;
|
||||||
|
int relative_grow_height = height - con->height;
|
||||||
|
int relative_grow_x = (e->ref_con_lx + grow_x) - con->x;
|
||||||
|
int relative_grow_y = (e->ref_con_ly + grow_y) - con->y;
|
||||||
|
|
||||||
|
// Actually resize stuff
|
||||||
|
con->x += relative_grow_x;
|
||||||
|
con->y += relative_grow_y;
|
||||||
|
con->width += relative_grow_width;
|
||||||
|
con->height += relative_grow_height;
|
||||||
|
|
||||||
|
con->content_x += relative_grow_x;
|
||||||
|
con->content_y += relative_grow_y;
|
||||||
|
con->content_width += relative_grow_width;
|
||||||
|
con->content_height += relative_grow_height;
|
||||||
|
|
||||||
|
arrange_container(con);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_floating_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_floating(struct sway_seat *seat,
|
||||||
|
struct sway_container *con, uint32_t button, enum wlr_edges edge) {
|
||||||
|
seatop_abort(seat);
|
||||||
|
|
||||||
|
struct seatop_resize_floating_event *e =
|
||||||
|
calloc(1, sizeof(struct seatop_resize_floating_event));
|
||||||
|
if (!e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e->con = con;
|
||||||
|
|
||||||
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
||||||
|
e->preserve_ratio = keyboard &&
|
||||||
|
(wlr_keyboard_get_modifiers(keyboard) & WLR_MODIFIER_SHIFT);
|
||||||
|
|
||||||
|
e->edge = edge == WLR_EDGE_NONE ? WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT : edge;
|
||||||
|
e->ref_lx = seat->cursor->cursor->x;
|
||||||
|
e->ref_ly = seat->cursor->cursor->y;
|
||||||
|
e->ref_con_lx = con->x;
|
||||||
|
e->ref_con_ly = con->y;
|
||||||
|
e->ref_width = con->width;
|
||||||
|
e->ref_height = con->height;
|
||||||
|
|
||||||
|
seat->seatop_impl = &seatop_impl;
|
||||||
|
seat->seatop_data = e;
|
||||||
|
seat->seatop_button = button;
|
||||||
|
|
||||||
|
container_raise_floating(con);
|
||||||
|
|
||||||
|
const char *image = edge == WLR_EDGE_NONE ?
|
||||||
|
"se-resize" : wlr_xcursor_get_resize_name(edge);
|
||||||
|
cursor_set_image(seat->cursor, image, NULL);
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/input/cursor.h"
|
||||||
|
#include "sway/input/seat.h"
|
||||||
|
|
||||||
|
struct seatop_resize_tiling_event {
|
||||||
|
struct sway_container *con;
|
||||||
|
enum wlr_edges edge;
|
||||||
|
double ref_lx, ref_ly; // cursor's x/y at start of op
|
||||||
|
double ref_width, ref_height; // container's size at start of op
|
||||||
|
double ref_con_lx, ref_con_ly; // container's x/y at start of op
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
enum wlr_edges edge_x = WLR_EDGE_NONE;
|
||||||
|
enum wlr_edges edge_y = WLR_EDGE_NONE;
|
||||||
|
struct sway_container *con = e->con;
|
||||||
|
|
||||||
|
if (e->edge & WLR_EDGE_TOP) {
|
||||||
|
amount_y = (e->ref_height - moved_y) - con->height;
|
||||||
|
edge_y = WLR_EDGE_TOP;
|
||||||
|
} else if (e->edge & WLR_EDGE_BOTTOM) {
|
||||||
|
amount_y = (e->ref_height + moved_y) - con->height;
|
||||||
|
edge_y = WLR_EDGE_BOTTOM;
|
||||||
|
}
|
||||||
|
if (e->edge & WLR_EDGE_LEFT) {
|
||||||
|
amount_x = (e->ref_width - moved_x) - con->width;
|
||||||
|
edge_x = WLR_EDGE_LEFT;
|
||||||
|
} else if (e->edge & WLR_EDGE_RIGHT) {
|
||||||
|
amount_x = (e->ref_width + moved_x) - con->width;
|
||||||
|
edge_x = WLR_EDGE_RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount_x != 0) {
|
||||||
|
container_resize_tiled(e->con, edge_x, amount_x);
|
||||||
|
}
|
||||||
|
if (amount_y != 0) {
|
||||||
|
container_resize_tiled(e->con, edge_y, amount_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
e->ref_con_lx = con->x;
|
||||||
|
e->ref_con_ly = con->y;
|
||||||
|
e->ref_width = con->width;
|
||||||
|
e->ref_height = con->height;
|
||||||
|
|
||||||
|
seat->seatop_impl = &seatop_impl;
|
||||||
|
seat->seatop_data = e;
|
||||||
|
seat->seatop_button = button;
|
||||||
|
}
|
Loading…
Reference in new issue