mirror of
https://github.com/swaywm/sway.git
synced 2025-11-25 06:59:48 -05:00
Refactor seat operations to use an interface
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_box
This commit is contained in:
parent
15ac580b28
commit
ed5aafd90b
19 changed files with 924 additions and 646 deletions
|
|
@ -300,7 +300,7 @@ static int scale_length(int length, int offset, float scale) {
|
|||
return round((offset + length) * scale) - round(offset * scale);
|
||||
}
|
||||
|
||||
static void scale_box(struct wlr_box *box, float scale) {
|
||||
void scale_box(struct wlr_box *box, float scale) {
|
||||
box->width = scale_length(box->width, box->x, scale);
|
||||
box->height = scale_length(box->height, box->y, scale);
|
||||
box->x = round(box->x * scale);
|
||||
|
|
|
|||
|
|
@ -49,13 +49,6 @@ static int scale_length(int length, int offset, float scale) {
|
|||
return round((offset + length) * scale) - round(offset * scale);
|
||||
}
|
||||
|
||||
static void scale_box(struct wlr_box *box, float scale) {
|
||||
box->width = scale_length(box->width, box->x, scale);
|
||||
box->height = scale_length(box->height, box->y, scale);
|
||||
box->x = round(box->x * scale);
|
||||
box->y = round(box->y * scale);
|
||||
}
|
||||
|
||||
static void scissor_output(struct wlr_output *wlr_output,
|
||||
pixman_box32_t *rect) {
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||
|
|
@ -164,7 +157,7 @@ static void render_drag_icons(struct sway_output *output,
|
|||
|
||||
// _box.x and .y are expected to be layout-local
|
||||
// _box.width and .height are expected to be output-buffer-local
|
||||
static void render_rect(struct wlr_output *wlr_output,
|
||||
void render_rect(struct wlr_output *wlr_output,
|
||||
pixman_region32_t *output_damage, const struct wlr_box *_box,
|
||||
float color[static 4]) {
|
||||
struct wlr_renderer *renderer =
|
||||
|
|
@ -197,7 +190,7 @@ damage_finish:
|
|||
pixman_region32_fini(&damage);
|
||||
}
|
||||
|
||||
static void premultiply_alpha(float color[4], float opacity) {
|
||||
void premultiply_alpha(float color[4], float opacity) {
|
||||
color[3] *= opacity;
|
||||
color[0] *= color[3];
|
||||
color[1] *= color[3];
|
||||
|
|
@ -949,21 +942,11 @@ static void render_floating(struct sway_output *soutput,
|
|||
}
|
||||
}
|
||||
|
||||
static void render_dropzones(struct sway_output *output,
|
||||
static void render_seatops(struct sway_output *output,
|
||||
pixman_region32_t *damage) {
|
||||
struct sway_seat *seat;
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (seat->operation == OP_MOVE_TILING && seat->op_target_node
|
||||
&& node_get_output(seat->op_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, &seat->op_drop_box, sizeof(struct wlr_box));
|
||||
scale_box(&box, output->wlr_output->scale);
|
||||
render_rect(output->wlr_output, damage, &box, color);
|
||||
}
|
||||
seatop_render(seat, output, damage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1060,7 +1043,7 @@ void output_render(struct sway_output *output, struct timespec *when,
|
|||
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
|
||||
}
|
||||
|
||||
render_dropzones(output, damage);
|
||||
render_seatops(output, damage);
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_container *focus = seat_get_focused_container(seat);
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ static void transaction_apply(struct sway_transaction *transaction) {
|
|||
if (root->outputs->length) {
|
||||
struct sway_seat *seat;
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (seat->operation == OP_NONE) {
|
||||
if (!seat_doing_seatop(seat)) {
|
||||
cursor_rebase(seat->cursor);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
|
|||
struct wlr_xdg_toplevel_move_event *e = data;
|
||||
struct sway_seat *seat = e->seat->seat->data;
|
||||
if (e->serial == seat->last_button_serial) {
|
||||
seat_begin_move_floating(seat, view->container, seat->last_button);
|
||||
seatop_begin_move_floating(seat, view->container, seat->last_button);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -374,7 +374,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|||
struct wlr_xdg_toplevel_resize_event *e = data;
|
||||
struct sway_seat *seat = e->seat->seat->data;
|
||||
if (e->serial == seat->last_button_serial) {
|
||||
seat_begin_resize_floating(seat, view->container,
|
||||
seatop_begin_resize_floating(seat, view->container,
|
||||
seat->last_button, e->edges);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
|
|||
struct wlr_xdg_toplevel_v6_move_event *e = data;
|
||||
struct sway_seat *seat = e->seat->seat->data;
|
||||
if (e->serial == seat->last_button_serial) {
|
||||
seat_begin_move_floating(seat, view->container, seat->last_button);
|
||||
seatop_begin_move_floating(seat, view->container, seat->last_button);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|||
struct wlr_xdg_toplevel_v6_resize_event *e = data;
|
||||
struct sway_seat *seat = e->seat->seat->data;
|
||||
if (e->serial == seat->last_button_serial) {
|
||||
seat_begin_resize_floating(seat, view->container,
|
||||
seatop_begin_resize_floating(seat, view->container,
|
||||
seat->last_button, e->edges);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -470,7 +470,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
|
|||
return;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
seat_begin_move_floating(seat, view->container, seat->last_button);
|
||||
seatop_begin_move_floating(seat, view->container, seat->last_button);
|
||||
}
|
||||
|
||||
static void handle_request_resize(struct wl_listener *listener, void *data) {
|
||||
|
|
@ -486,7 +486,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|||
}
|
||||
struct wlr_xwayland_resize_event *e = data;
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
seat_begin_resize_floating(seat, view->container,
|
||||
seatop_begin_resize_floating(seat, view->container,
|
||||
seat->last_button, e->edges);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue