2019-01-10 13:04:42 +01:00
|
|
|
#include <limits.h>
|
|
|
|
#include <wlr/types/wlr_cursor.h>
|
|
|
|
#include <wlr/util/edges.h>
|
2021-02-08 02:03:01 +01:00
|
|
|
#include "sway/desktop/transaction.h"
|
2019-01-10 13:04:42 +01:00
|
|
|
#include "sway/input/cursor.h"
|
|
|
|
#include "sway/input/seat.h"
|
2020-10-02 21:42:48 +02:00
|
|
|
#include "sway/ipc-server.h"
|
2019-01-10 13:04:42 +01:00
|
|
|
#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
|
|
|
|
|
2021-04-23 05:01:09 +02:00
|
|
|
// Thickness of indicator when dropping onto a titlebar. This should be a
|
|
|
|
// multiple of 2.
|
|
|
|
#define DROP_SPLIT_INDICATOR 10
|
|
|
|
|
2019-01-10 13:04:42 +01:00
|
|
|
struct seatop_move_tiling_event {
|
|
|
|
struct sway_container *con;
|
|
|
|
struct sway_node *target_node;
|
|
|
|
enum wlr_edges target_edge;
|
|
|
|
double ref_lx, ref_ly; // cursor's x/y at start of op
|
|
|
|
bool threshold_reached;
|
2021-04-23 05:01:09 +02:00
|
|
|
bool split_target;
|
|
|
|
bool insert_after_target;
|
2023-11-22 01:19:01 +01:00
|
|
|
struct wlr_scene_rect *indicator_rect;
|
2019-01-10 13:04:42 +01:00
|
|
|
};
|
|
|
|
|
2023-11-22 01:19:01 +01:00
|
|
|
static void handle_end(struct sway_seat *seat) {
|
2019-01-10 13:04:42 +01:00
|
|
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
2023-11-22 01:19:01 +01:00
|
|
|
wlr_scene_node_destroy(&e->indicator_rect->node);
|
|
|
|
e->indicator_rect = NULL;
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2023-11-22 01:19:01 +01:00
|
|
|
wlr_scene_node_set_enabled(&e->indicator_rect->node, true);
|
2019-01-10 13:04:42 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 05:01:09 +02:00
|
|
|
static void split_border(double pos, int offset, int len, int n_children,
|
|
|
|
int avoid, int *out_pos, bool *out_after) {
|
|
|
|
int region = 2 * n_children * (pos - offset) / len;
|
|
|
|
// If the cursor is over the right side of a left-adjacent titlebar, or the
|
|
|
|
// left side of a right-adjacent titlebar, it's position when dropped will
|
|
|
|
// be the same. To avoid this, shift the region for adjacent containers.
|
|
|
|
if (avoid >= 0) {
|
|
|
|
if (region == 2 * avoid - 1 || region == 2 * avoid) {
|
|
|
|
region--;
|
|
|
|
} else if (region == 2 * avoid + 1 || region == 2 * avoid + 2) {
|
|
|
|
region++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int child_index = (region + 1) / 2;
|
|
|
|
*out_after = region % 2;
|
|
|
|
// When dropping at the beginning or end of a container, show the drop
|
|
|
|
// region within the container boundary, otherwise show it on top of the
|
|
|
|
// border between two titlebars.
|
|
|
|
if (child_index == 0) {
|
|
|
|
*out_pos = offset;
|
|
|
|
} else if (child_index == n_children) {
|
|
|
|
*out_pos = offset + len - DROP_SPLIT_INDICATOR;
|
|
|
|
} else {
|
|
|
|
*out_pos = offset + child_index * len / n_children -
|
|
|
|
DROP_SPLIT_INDICATOR / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool split_titlebar(struct sway_node *node, struct sway_container *avoid,
|
|
|
|
struct wlr_cursor *cursor, struct wlr_box *title_box, bool *after) {
|
|
|
|
struct sway_container *con = node->sway_container;
|
|
|
|
struct sway_node *parent = &con->pending.parent->node;
|
|
|
|
int title_height = container_titlebar_height();
|
|
|
|
struct wlr_box box;
|
|
|
|
int n_children, avoid_index;
|
|
|
|
enum sway_container_layout layout =
|
|
|
|
parent ? node_get_layout(parent) : L_NONE;
|
|
|
|
if (layout == L_TABBED || layout == L_STACKED) {
|
|
|
|
node_get_box(parent, &box);
|
|
|
|
n_children = node_get_children(parent)->length;
|
|
|
|
avoid_index = list_find(node_get_children(parent), avoid);
|
|
|
|
} else {
|
|
|
|
node_get_box(node, &box);
|
|
|
|
n_children = 1;
|
|
|
|
avoid_index = -1;
|
|
|
|
}
|
|
|
|
if (layout == L_STACKED && cursor->y < box.y + title_height * n_children) {
|
|
|
|
// Drop into stacked titlebars.
|
|
|
|
title_box->width = box.width;
|
|
|
|
title_box->height = DROP_SPLIT_INDICATOR;
|
|
|
|
title_box->x = box.x;
|
|
|
|
split_border(cursor->y, box.y, title_height * n_children,
|
|
|
|
n_children, avoid_index, &title_box->y, after);
|
|
|
|
return true;
|
|
|
|
} else if (layout != L_STACKED && cursor->y < box.y + title_height) {
|
|
|
|
// Drop into side-by-side titlebars.
|
|
|
|
title_box->width = DROP_SPLIT_INDICATOR;
|
|
|
|
title_box->height = title_height;
|
|
|
|
title_box->y = box.y;
|
|
|
|
split_border(cursor->x, box.x, box.width, n_children,
|
|
|
|
avoid_index, &title_box->x, after);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-22 01:19:01 +01:00
|
|
|
static void update_indicator(struct seatop_move_tiling_event *e, struct wlr_box *box) {
|
|
|
|
wlr_scene_node_set_position(&e->indicator_rect->node, box->x, box->y);
|
|
|
|
wlr_scene_rect_set_size(e->indicator_rect, box->width, box->height);
|
|
|
|
}
|
|
|
|
|
2019-01-10 13:04:42 +01:00
|
|
|
static void handle_motion_postthreshold(struct sway_seat *seat) {
|
|
|
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
2021-04-23 05:01:09 +02:00
|
|
|
e->split_target = false;
|
2019-01-10 13:04:42 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
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) {
|
2019-03-29 09:29:34 +01:00
|
|
|
// Empty workspace
|
2019-01-10 13:04:42 +01:00
|
|
|
e->target_node = node;
|
|
|
|
e->target_edge = WLR_EDGE_NONE;
|
2023-11-22 01:19:01 +01:00
|
|
|
|
|
|
|
struct wlr_box drop_box;
|
|
|
|
workspace_get_box(node->sway_workspace, &drop_box);
|
|
|
|
update_indicator(e, &drop_box);
|
2019-01-10 13:04:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deny moving within own workspace if this is the only child
|
|
|
|
struct sway_container *con = node->sway_container;
|
2021-02-12 23:22:51 +01:00
|
|
|
if (workspace_num_tiling_views(e->con->pending.workspace) == 1 &&
|
|
|
|
con->pending.workspace == e->con->pending.workspace) {
|
2019-01-10 13:04:42 +01:00
|
|
|
e->target_node = NULL;
|
|
|
|
e->target_edge = WLR_EDGE_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-22 01:19:01 +01:00
|
|
|
struct wlr_box drop_box = {
|
|
|
|
.x = con->pending.content_x,
|
|
|
|
.y = con->pending.content_y,
|
|
|
|
.width = con->pending.content_width,
|
|
|
|
.height = con->pending.content_height,
|
|
|
|
};
|
|
|
|
|
2021-04-23 05:01:09 +02:00
|
|
|
// Check if the cursor is over a tilebar only if the destination
|
|
|
|
// container is not a descendant of the source container.
|
|
|
|
if (!surface && !container_has_ancestor(con, e->con) &&
|
|
|
|
split_titlebar(node, e->con, cursor->cursor,
|
2023-11-22 01:19:01 +01:00
|
|
|
&drop_box, &e->insert_after_target)) {
|
2021-04-23 05:01:09 +02:00
|
|
|
// Don't allow dropping over the source container's titlebar
|
|
|
|
// to give users a chance to cancel a drag operation.
|
|
|
|
if (con == e->con) {
|
|
|
|
e->target_node = NULL;
|
|
|
|
} else {
|
|
|
|
e->target_node = node;
|
|
|
|
e->split_target = true;
|
|
|
|
}
|
|
|
|
e->target_edge = WLR_EDGE_NONE;
|
2023-11-22 01:19:01 +01:00
|
|
|
update_indicator(e, &drop_box);
|
2021-04-23 05:01:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-10 13:04:42 +01:00
|
|
|
// Traverse the ancestors, trying to find a layout container perpendicular
|
|
|
|
// to the edge. Eg. close to the top or bottom of a horiz layout.
|
2021-04-23 05:01:09 +02:00
|
|
|
int thresh_top = con->pending.content_y + DROP_LAYOUT_BORDER;
|
|
|
|
int thresh_bottom = con->pending.content_y +
|
|
|
|
con->pending.content_height - DROP_LAYOUT_BORDER;
|
|
|
|
int thresh_left = con->pending.content_x + DROP_LAYOUT_BORDER;
|
|
|
|
int thresh_right = con->pending.content_x +
|
|
|
|
con->pending.content_width - DROP_LAYOUT_BORDER;
|
2019-01-10 13:04:42 +01:00
|
|
|
while (con) {
|
|
|
|
enum wlr_edges edge = WLR_EDGE_NONE;
|
|
|
|
enum sway_container_layout layout = container_parent_layout(con);
|
2021-04-23 05:01:09 +02:00
|
|
|
struct wlr_box box;
|
|
|
|
node_get_box(node_get_parent(&con->node), &box);
|
2019-01-10 13:04:42 +01:00
|
|
|
if (layout == L_HORIZ || layout == L_TABBED) {
|
2021-04-23 05:01:09 +02:00
|
|
|
if (cursor->cursor->y < thresh_top) {
|
2019-01-10 13:04:42 +01:00
|
|
|
edge = WLR_EDGE_TOP;
|
2021-04-23 05:01:09 +02:00
|
|
|
box.height = thresh_top - box.y;
|
|
|
|
} else if (cursor->cursor->y > thresh_bottom) {
|
2019-01-10 13:04:42 +01:00
|
|
|
edge = WLR_EDGE_BOTTOM;
|
2021-04-23 05:01:09 +02:00
|
|
|
box.height = box.y + box.height - thresh_bottom;
|
|
|
|
box.y = thresh_bottom;
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
} else if (layout == L_VERT || layout == L_STACKED) {
|
2021-04-23 05:01:09 +02:00
|
|
|
if (cursor->cursor->x < thresh_left) {
|
2019-01-10 13:04:42 +01:00
|
|
|
edge = WLR_EDGE_LEFT;
|
2021-04-23 05:01:09 +02:00
|
|
|
box.width = thresh_left - box.x;
|
|
|
|
} else if (cursor->cursor->x > thresh_right) {
|
2019-01-10 13:04:42 +01:00
|
|
|
edge = WLR_EDGE_RIGHT;
|
2021-04-23 05:01:09 +02:00
|
|
|
box.width = box.x + box.width - thresh_right;
|
|
|
|
box.x = thresh_right;
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (edge) {
|
|
|
|
e->target_node = node_get_parent(&con->node);
|
2019-02-13 20:32:47 +01:00
|
|
|
if (e->target_node == &e->con->node) {
|
|
|
|
e->target_node = node_get_parent(e->target_node);
|
|
|
|
}
|
2019-01-10 13:04:42 +01:00
|
|
|
e->target_edge = edge;
|
2023-11-22 01:19:01 +01:00
|
|
|
update_indicator(e, &box);
|
2019-01-10 13:04:42 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-02-12 23:22:51 +01:00
|
|
|
con = con->pending.parent;
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use the hovered view - but we must be over the actual surface
|
|
|
|
con = node->sway_container;
|
2019-03-29 09:29:34 +01:00
|
|
|
if (!con->view || !con->view->surface || node == &e->con->node
|
2019-02-14 04:38:30 +01:00
|
|
|
|| node_has_ancestor(node, &e->con->node)) {
|
2019-01-10 13:04:42 +01:00
|
|
|
e->target_node = NULL;
|
|
|
|
e->target_edge = WLR_EDGE_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the closest edge
|
2021-02-12 23:22:51 +01:00
|
|
|
size_t thickness = fmin(con->pending.content_width, con->pending.content_height) * 0.3;
|
2019-01-10 13:04:42 +01:00
|
|
|
size_t closest_dist = INT_MAX;
|
|
|
|
size_t dist;
|
|
|
|
e->target_edge = WLR_EDGE_NONE;
|
2021-02-12 23:22:51 +01:00
|
|
|
if ((dist = cursor->cursor->y - con->pending.y) < closest_dist) {
|
2019-01-10 13:04:42 +01:00
|
|
|
closest_dist = dist;
|
|
|
|
e->target_edge = WLR_EDGE_TOP;
|
|
|
|
}
|
2021-02-12 23:22:51 +01:00
|
|
|
if ((dist = cursor->cursor->x - con->pending.x) < closest_dist) {
|
2019-01-10 13:04:42 +01:00
|
|
|
closest_dist = dist;
|
|
|
|
e->target_edge = WLR_EDGE_LEFT;
|
|
|
|
}
|
2021-02-12 23:22:51 +01:00
|
|
|
if ((dist = con->pending.x + con->pending.width - cursor->cursor->x) < closest_dist) {
|
2019-01-10 13:04:42 +01:00
|
|
|
closest_dist = dist;
|
|
|
|
e->target_edge = WLR_EDGE_RIGHT;
|
|
|
|
}
|
2021-02-12 23:22:51 +01:00
|
|
|
if ((dist = con->pending.y + con->pending.height - cursor->cursor->y) < closest_dist) {
|
2019-01-10 13:04:42 +01:00
|
|
|
closest_dist = dist;
|
|
|
|
e->target_edge = WLR_EDGE_BOTTOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closest_dist > thickness) {
|
|
|
|
e->target_edge = WLR_EDGE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
e->target_node = node;
|
2023-11-22 01:19:01 +01:00
|
|
|
resize_box(&drop_box, e->target_edge, thickness);
|
|
|
|
update_indicator(e, &drop_box);
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
2020-10-31 22:56:21 +01:00
|
|
|
static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) {
|
2019-01-10 13:04:42 +01:00
|
|
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
|
|
|
if (e->threshold_reached) {
|
|
|
|
handle_motion_postthreshold(seat);
|
|
|
|
} else {
|
|
|
|
handle_motion_prethreshold(seat);
|
|
|
|
}
|
2021-02-08 02:03:01 +01:00
|
|
|
transaction_commit_dirty();
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-04 21:58:17 +02:00
|
|
|
static void finalize_move(struct sway_seat *seat) {
|
2019-01-10 13:04:42 +01:00
|
|
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
|
|
|
|
|
|
|
if (!e->target_node) {
|
Introduce default seatop
This introduces a `default` seat operation which is used when no mouse
buttons are being held. This means there is now always a seat operation
in progress. It allows us to separate `default` code from the standard
cursor management code.
The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and
`end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are
only used by the default seatop. `end` is called when a seatop is being
replaced by another one and allows the seatop to free any resources,
though no seatop currently needs to do this. `finish` is no longer
required, as each seatop can gracefully finish in their `button`
callback. And `abort` is not needed, as calling `end` would achieve the
same thing. The struct has also gained a bool named allow_set_cursor
which allows the client to set a new cursor during `default` and `down`
seatops.
Seatops would previously store which button they were started with and
stop when that button was released. This behaviour is changed so that it
only ends once all buttons are released. So you can start a drag with
$mod+left, then click and hold right, release left and it'll continue
dragging while the right button is held.
The motion callback now accepts dx and dy. Most seatops don't use this
as they store the cursor position when the seatop is started and compare
it with the current cursor position. This approach doesn't make sense
for the default seatop though, hence why dx and dy are needed.
The pressed_buttons array has been moved from the sway_cursor struct to
the default seatop's data. This is only used for the default seatop to
check bindings. The total pressed button count remains in the
sway_cursor struct though, because all the other seatops check it to
know if they should end.
The `down` seatop no longer has a `moved` property. This was used to
track if the cursor moved and to recheck focus_follows_mouse, but seems
to work without it.
The logic for focus_follows_mouse has been refactored. As part of this
I've removed the call to wlr_seat_keyboard_has_grab as we don't appear
to use keyboard grabs.
The functions for handling relative motion, absolute motion and tool
axis have been changed. Previously the handler functions were
handle_cursor_motion, handle_cursor_motion_absolute and
handle_tool_axis. The latter two both called cursor_motion_absolute.
Both handle_cursor_motion and cursor_motion_absolute did very similar
things. These are now simplified into three handlers and a single common
function called cursor_motion. All three handlers call cursor_motion. As
cursor_motion works with relative distances, the absolute and tool axis
handlers convert them to relative first.
2019-03-16 08:47:39 +01:00
|
|
|
seatop_begin_default(seat);
|
2019-01-10 13:04:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_container *con = e->con;
|
2021-02-12 23:22:51 +01:00
|
|
|
struct sway_container *old_parent = con->pending.parent;
|
|
|
|
struct sway_workspace *old_ws = con->pending.workspace;
|
2019-01-10 13:04:42 +01:00
|
|
|
struct sway_node *target_node = e->target_node;
|
|
|
|
struct sway_workspace *new_ws = target_node->type == N_WORKSPACE ?
|
2021-02-12 23:22:51 +01:00
|
|
|
target_node->sway_workspace : target_node->sway_container->pending.workspace;
|
2019-01-10 13:04:42 +01:00
|
|
|
enum wlr_edges edge = e->target_edge;
|
|
|
|
int after = edge != WLR_EDGE_TOP && edge != WLR_EDGE_LEFT;
|
2021-04-23 05:01:09 +02:00
|
|
|
bool swap = edge == WLR_EDGE_NONE && target_node->type == N_CONTAINER &&
|
|
|
|
!e->split_target;
|
2019-07-08 22:29:04 +02:00
|
|
|
|
|
|
|
if (!swap) {
|
|
|
|
container_detach(con);
|
|
|
|
}
|
2019-01-10 13:04:42 +01:00
|
|
|
|
|
|
|
// Moving container into empty workspace
|
|
|
|
if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) {
|
2020-10-25 22:20:11 +01:00
|
|
|
con = workspace_add_tiling(new_ws, con);
|
2021-04-23 05:01:09 +02:00
|
|
|
} else if (e->split_target) {
|
|
|
|
struct sway_container *target = target_node->sway_container;
|
|
|
|
enum sway_container_layout layout = container_parent_layout(target);
|
|
|
|
if (layout != L_TABBED && layout != L_STACKED) {
|
|
|
|
container_split(target, L_TABBED);
|
|
|
|
}
|
|
|
|
container_add_sibling(target, con, e->insert_after_target);
|
|
|
|
ipc_event_window(con, "move");
|
2019-01-10 13:04:42 +01:00
|
|
|
} else if (target_node->type == N_CONTAINER) {
|
|
|
|
// Moving container before/after another
|
|
|
|
struct sway_container *target = target_node->sway_container;
|
2019-07-08 22:29:04 +02:00
|
|
|
if (swap) {
|
|
|
|
container_swap(target_node->sway_container, con);
|
|
|
|
} else {
|
|
|
|
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);
|
2020-10-02 21:42:48 +02:00
|
|
|
ipc_event_window(con, "move");
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
} 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];
|
2021-02-12 23:22:51 +01:00
|
|
|
con->pending.width = sibling->pending.width;
|
|
|
|
con->pending.height = sibling->pending.height;
|
2019-06-28 23:21:20 +02:00
|
|
|
con->width_fraction = sibling->width_fraction;
|
|
|
|
con->height_fraction = sibling->height_fraction;
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
arrange_workspace(old_ws);
|
|
|
|
if (new_ws != old_ws) {
|
|
|
|
arrange_workspace(new_ws);
|
|
|
|
}
|
|
|
|
|
2021-02-08 02:03:01 +01:00
|
|
|
transaction_commit_dirty();
|
Introduce default seatop
This introduces a `default` seat operation which is used when no mouse
buttons are being held. This means there is now always a seat operation
in progress. It allows us to separate `default` code from the standard
cursor management code.
The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and
`end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are
only used by the default seatop. `end` is called when a seatop is being
replaced by another one and allows the seatop to free any resources,
though no seatop currently needs to do this. `finish` is no longer
required, as each seatop can gracefully finish in their `button`
callback. And `abort` is not needed, as calling `end` would achieve the
same thing. The struct has also gained a bool named allow_set_cursor
which allows the client to set a new cursor during `default` and `down`
seatops.
Seatops would previously store which button they were started with and
stop when that button was released. This behaviour is changed so that it
only ends once all buttons are released. So you can start a drag with
$mod+left, then click and hold right, release left and it'll continue
dragging while the right button is held.
The motion callback now accepts dx and dy. Most seatops don't use this
as they store the cursor position when the seatop is started and compare
it with the current cursor position. This approach doesn't make sense
for the default seatop though, hence why dx and dy are needed.
The pressed_buttons array has been moved from the sway_cursor struct to
the default seatop's data. This is only used for the default seatop to
check bindings. The total pressed button count remains in the
sway_cursor struct though, because all the other seatops check it to
know if they should end.
The `down` seatop no longer has a `moved` property. This was used to
track if the cursor moved and to recheck focus_follows_mouse, but seems
to work without it.
The logic for focus_follows_mouse has been refactored. As part of this
I've removed the call to wlr_seat_keyboard_has_grab as we don't appear
to use keyboard grabs.
The functions for handling relative motion, absolute motion and tool
axis have been changed. Previously the handler functions were
handle_cursor_motion, handle_cursor_motion_absolute and
handle_tool_axis. The latter two both called cursor_motion_absolute.
Both handle_cursor_motion and cursor_motion_absolute did very similar
things. These are now simplified into three handlers and a single common
function called cursor_motion. All three handlers call cursor_motion. As
cursor_motion works with relative distances, the absolute and tool axis
handlers convert them to relative first.
2019-03-16 08:47:39 +01:00
|
|
|
seatop_begin_default(seat);
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
2020-06-04 21:58:17 +02:00
|
|
|
static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|
|
|
struct wlr_input_device *device, uint32_t button,
|
|
|
|
enum wlr_button_state state) {
|
|
|
|
if (seat->cursor->pressed_button_count == 0) {
|
|
|
|
finalize_move(seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_tablet_tool_tip(struct sway_seat *seat,
|
|
|
|
struct sway_tablet_tool *tool, uint32_t time_msec,
|
|
|
|
enum wlr_tablet_tool_tip_state state) {
|
|
|
|
if (state == WLR_TABLET_TOOL_TIP_UP) {
|
|
|
|
finalize_move(seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 13:04:42 +01:00
|
|
|
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
|
Introduce default seatop
This introduces a `default` seat operation which is used when no mouse
buttons are being held. This means there is now always a seat operation
in progress. It allows us to separate `default` code from the standard
cursor management code.
The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and
`end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are
only used by the default seatop. `end` is called when a seatop is being
replaced by another one and allows the seatop to free any resources,
though no seatop currently needs to do this. `finish` is no longer
required, as each seatop can gracefully finish in their `button`
callback. And `abort` is not needed, as calling `end` would achieve the
same thing. The struct has also gained a bool named allow_set_cursor
which allows the client to set a new cursor during `default` and `down`
seatops.
Seatops would previously store which button they were started with and
stop when that button was released. This behaviour is changed so that it
only ends once all buttons are released. So you can start a drag with
$mod+left, then click and hold right, release left and it'll continue
dragging while the right button is held.
The motion callback now accepts dx and dy. Most seatops don't use this
as they store the cursor position when the seatop is started and compare
it with the current cursor position. This approach doesn't make sense
for the default seatop though, hence why dx and dy are needed.
The pressed_buttons array has been moved from the sway_cursor struct to
the default seatop's data. This is only used for the default seatop to
check bindings. The total pressed button count remains in the
sway_cursor struct though, because all the other seatops check it to
know if they should end.
The `down` seatop no longer has a `moved` property. This was used to
track if the cursor moved and to recheck focus_follows_mouse, but seems
to work without it.
The logic for focus_follows_mouse has been refactored. As part of this
I've removed the call to wlr_seat_keyboard_has_grab as we don't appear
to use keyboard grabs.
The functions for handling relative motion, absolute motion and tool
axis have been changed. Previously the handler functions were
handle_cursor_motion, handle_cursor_motion_absolute and
handle_tool_axis. The latter two both called cursor_motion_absolute.
Both handle_cursor_motion and cursor_motion_absolute did very similar
things. These are now simplified into three handlers and a single common
function called cursor_motion. All three handlers call cursor_motion. As
cursor_motion works with relative distances, the absolute and tool axis
handlers convert them to relative first.
2019-03-16 08:47:39 +01:00
|
|
|
seatop_begin_default(seat);
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sway_seatop_impl seatop_impl = {
|
Introduce default seatop
This introduces a `default` seat operation which is used when no mouse
buttons are being held. This means there is now always a seat operation
in progress. It allows us to separate `default` code from the standard
cursor management code.
The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and
`end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are
only used by the default seatop. `end` is called when a seatop is being
replaced by another one and allows the seatop to free any resources,
though no seatop currently needs to do this. `finish` is no longer
required, as each seatop can gracefully finish in their `button`
callback. And `abort` is not needed, as calling `end` would achieve the
same thing. The struct has also gained a bool named allow_set_cursor
which allows the client to set a new cursor during `default` and `down`
seatops.
Seatops would previously store which button they were started with and
stop when that button was released. This behaviour is changed so that it
only ends once all buttons are released. So you can start a drag with
$mod+left, then click and hold right, release left and it'll continue
dragging while the right button is held.
The motion callback now accepts dx and dy. Most seatops don't use this
as they store the cursor position when the seatop is started and compare
it with the current cursor position. This approach doesn't make sense
for the default seatop though, hence why dx and dy are needed.
The pressed_buttons array has been moved from the sway_cursor struct to
the default seatop's data. This is only used for the default seatop to
check bindings. The total pressed button count remains in the
sway_cursor struct though, because all the other seatops check it to
know if they should end.
The `down` seatop no longer has a `moved` property. This was used to
track if the cursor moved and to recheck focus_follows_mouse, but seems
to work without it.
The logic for focus_follows_mouse has been refactored. As part of this
I've removed the call to wlr_seat_keyboard_has_grab as we don't appear
to use keyboard grabs.
The functions for handling relative motion, absolute motion and tool
axis have been changed. Previously the handler functions were
handle_cursor_motion, handle_cursor_motion_absolute and
handle_tool_axis. The latter two both called cursor_motion_absolute.
Both handle_cursor_motion and cursor_motion_absolute did very similar
things. These are now simplified into three handlers and a single common
function called cursor_motion. All three handlers call cursor_motion. As
cursor_motion works with relative distances, the absolute and tool axis
handlers convert them to relative first.
2019-03-16 08:47:39 +01:00
|
|
|
.button = handle_button,
|
2020-05-02 18:15:39 +02:00
|
|
|
.pointer_motion = handle_pointer_motion,
|
2020-06-04 21:58:17 +02:00
|
|
|
.tablet_tool_tip = handle_tablet_tool_tip,
|
2019-01-10 13:04:42 +01:00
|
|
|
.unref = handle_unref,
|
2023-11-22 01:19:01 +01:00
|
|
|
.end = handle_end,
|
2019-01-10 13:04:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void seatop_begin_move_tiling_threshold(struct sway_seat *seat,
|
Introduce default seatop
This introduces a `default` seat operation which is used when no mouse
buttons are being held. This means there is now always a seat operation
in progress. It allows us to separate `default` code from the standard
cursor management code.
The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and
`end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are
only used by the default seatop. `end` is called when a seatop is being
replaced by another one and allows the seatop to free any resources,
though no seatop currently needs to do this. `finish` is no longer
required, as each seatop can gracefully finish in their `button`
callback. And `abort` is not needed, as calling `end` would achieve the
same thing. The struct has also gained a bool named allow_set_cursor
which allows the client to set a new cursor during `default` and `down`
seatops.
Seatops would previously store which button they were started with and
stop when that button was released. This behaviour is changed so that it
only ends once all buttons are released. So you can start a drag with
$mod+left, then click and hold right, release left and it'll continue
dragging while the right button is held.
The motion callback now accepts dx and dy. Most seatops don't use this
as they store the cursor position when the seatop is started and compare
it with the current cursor position. This approach doesn't make sense
for the default seatop though, hence why dx and dy are needed.
The pressed_buttons array has been moved from the sway_cursor struct to
the default seatop's data. This is only used for the default seatop to
check bindings. The total pressed button count remains in the
sway_cursor struct though, because all the other seatops check it to
know if they should end.
The `down` seatop no longer has a `moved` property. This was used to
track if the cursor moved and to recheck focus_follows_mouse, but seems
to work without it.
The logic for focus_follows_mouse has been refactored. As part of this
I've removed the call to wlr_seat_keyboard_has_grab as we don't appear
to use keyboard grabs.
The functions for handling relative motion, absolute motion and tool
axis have been changed. Previously the handler functions were
handle_cursor_motion, handle_cursor_motion_absolute and
handle_tool_axis. The latter two both called cursor_motion_absolute.
Both handle_cursor_motion and cursor_motion_absolute did very similar
things. These are now simplified into three handlers and a single common
function called cursor_motion. All three handlers call cursor_motion. As
cursor_motion works with relative distances, the absolute and tool axis
handlers convert them to relative first.
2019-03-16 08:47:39 +01:00
|
|
|
struct sway_container *con) {
|
|
|
|
seatop_end(seat);
|
2019-01-10 13:04:42 +01:00
|
|
|
|
|
|
|
struct seatop_move_tiling_event *e =
|
|
|
|
calloc(1, sizeof(struct seatop_move_tiling_event));
|
|
|
|
if (!e) {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-22 01:19:01 +01:00
|
|
|
|
|
|
|
const float *indicator = config->border_colors.focused.indicator;
|
|
|
|
float color[4] = {
|
|
|
|
indicator[0] * .5,
|
|
|
|
indicator[1] * .5,
|
|
|
|
indicator[2] * .5,
|
|
|
|
indicator[3] * .5,
|
|
|
|
};
|
|
|
|
e->indicator_rect = wlr_scene_rect_create(seat->scene_tree, 0, 0, color);
|
|
|
|
if (!e->indicator_rect) {
|
|
|
|
free(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-10 13:04:42 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
container_raise_floating(con);
|
2021-02-08 02:03:01 +01:00
|
|
|
transaction_commit_dirty();
|
2020-05-21 03:20:19 +02:00
|
|
|
wlr_seat_pointer_notify_clear_focus(seat->wlr_seat);
|
2019-01-10 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void seatop_begin_move_tiling(struct sway_seat *seat,
|
Introduce default seatop
This introduces a `default` seat operation which is used when no mouse
buttons are being held. This means there is now always a seat operation
in progress. It allows us to separate `default` code from the standard
cursor management code.
The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and
`end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are
only used by the default seatop. `end` is called when a seatop is being
replaced by another one and allows the seatop to free any resources,
though no seatop currently needs to do this. `finish` is no longer
required, as each seatop can gracefully finish in their `button`
callback. And `abort` is not needed, as calling `end` would achieve the
same thing. The struct has also gained a bool named allow_set_cursor
which allows the client to set a new cursor during `default` and `down`
seatops.
Seatops would previously store which button they were started with and
stop when that button was released. This behaviour is changed so that it
only ends once all buttons are released. So you can start a drag with
$mod+left, then click and hold right, release left and it'll continue
dragging while the right button is held.
The motion callback now accepts dx and dy. Most seatops don't use this
as they store the cursor position when the seatop is started and compare
it with the current cursor position. This approach doesn't make sense
for the default seatop though, hence why dx and dy are needed.
The pressed_buttons array has been moved from the sway_cursor struct to
the default seatop's data. This is only used for the default seatop to
check bindings. The total pressed button count remains in the
sway_cursor struct though, because all the other seatops check it to
know if they should end.
The `down` seatop no longer has a `moved` property. This was used to
track if the cursor moved and to recheck focus_follows_mouse, but seems
to work without it.
The logic for focus_follows_mouse has been refactored. As part of this
I've removed the call to wlr_seat_keyboard_has_grab as we don't appear
to use keyboard grabs.
The functions for handling relative motion, absolute motion and tool
axis have been changed. Previously the handler functions were
handle_cursor_motion, handle_cursor_motion_absolute and
handle_tool_axis. The latter two both called cursor_motion_absolute.
Both handle_cursor_motion and cursor_motion_absolute did very similar
things. These are now simplified into three handlers and a single common
function called cursor_motion. All three handlers call cursor_motion. As
cursor_motion works with relative distances, the absolute and tool axis
handlers convert them to relative first.
2019-03-16 08:47:39 +01:00
|
|
|
struct sway_container *con) {
|
|
|
|
seatop_begin_move_tiling_threshold(seat, con);
|
2019-01-10 13:04:42 +01:00
|
|
|
struct seatop_move_tiling_event *e = seat->seatop_data;
|
|
|
|
if (e) {
|
|
|
|
e->threshold_reached = true;
|
|
|
|
cursor_set_image(seat->cursor, "grab", NULL);
|
|
|
|
}
|
|
|
|
}
|