summaryrefslogtreecommitdiffstats
path: root/sway/desktop
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2019-01-10 22:04:42 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2019-01-10 22:04:42 +1000
commited5aafd90bd850ad27dcb36ac4438ed926480394 (patch)
tree46d0b5fe8488e5d9415cbc9a732e86c1e7100ffe /sway/desktop
parentMerge pull request #3341 from RedSoxFan/mouse-bindings-improved (diff)
downloadsway-ed5aafd90bd850ad27dcb36ac4438ed926480394.tar.gz
sway-ed5aafd90bd850ad27dcb36ac4438ed926480394.tar.zst
sway-ed5aafd90bd850ad27dcb36ac4438ed926480394.zip
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
Diffstat (limited to 'sway/desktop')
-rw-r--r--sway/desktop/output.c2
-rw-r--r--sway/desktop/render.c27
-rw-r--r--sway/desktop/transaction.c2
-rw-r--r--sway/desktop/xdg_shell.c4
-rw-r--r--sway/desktop/xdg_shell_v6.c4
-rw-r--r--sway/desktop/xwayland.c4
6 files changed, 13 insertions, 30 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 79ad7faa..04c9b4f6 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -300,7 +300,7 @@ static int scale_length(int length, int offset, float scale) {
300 return round((offset + length) * scale) - round(offset * scale); 300 return round((offset + length) * scale) - round(offset * scale);
301} 301}
302 302
303static void scale_box(struct wlr_box *box, float scale) { 303void scale_box(struct wlr_box *box, float scale) {
304 box->width = scale_length(box->width, box->x, scale); 304 box->width = scale_length(box->width, box->x, scale);
305 box->height = scale_length(box->height, box->y, scale); 305 box->height = scale_length(box->height, box->y, scale);
306 box->x = round(box->x * scale); 306 box->x = round(box->x * scale);
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 6c9fe23c..a38c6a07 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -49,13 +49,6 @@ static int scale_length(int length, int offset, float scale) {
49 return round((offset + length) * scale) - round(offset * scale); 49 return round((offset + length) * scale) - round(offset * scale);
50} 50}
51 51
52static void scale_box(struct wlr_box *box, float scale) {
53 box->width = scale_length(box->width, box->x, scale);
54 box->height = scale_length(box->height, box->y, scale);
55 box->x = round(box->x * scale);
56 box->y = round(box->y * scale);
57}
58
59static void scissor_output(struct wlr_output *wlr_output, 52static void scissor_output(struct wlr_output *wlr_output,
60 pixman_box32_t *rect) { 53 pixman_box32_t *rect) {
61 struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); 54 struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
@@ -164,7 +157,7 @@ static void render_drag_icons(struct sway_output *output,
164 157
165// _box.x and .y are expected to be layout-local 158// _box.x and .y are expected to be layout-local
166// _box.width and .height are expected to be output-buffer-local 159// _box.width and .height are expected to be output-buffer-local
167static void render_rect(struct wlr_output *wlr_output, 160void render_rect(struct wlr_output *wlr_output,
168 pixman_region32_t *output_damage, const struct wlr_box *_box, 161 pixman_region32_t *output_damage, const struct wlr_box *_box,
169 float color[static 4]) { 162 float color[static 4]) {
170 struct wlr_renderer *renderer = 163 struct wlr_renderer *renderer =
@@ -197,7 +190,7 @@ damage_finish:
197 pixman_region32_fini(&damage); 190 pixman_region32_fini(&damage);
198} 191}
199 192
200static void premultiply_alpha(float color[4], float opacity) { 193void premultiply_alpha(float color[4], float opacity) {
201 color[3] *= opacity; 194 color[3] *= opacity;
202 color[0] *= color[3]; 195 color[0] *= color[3];
203 color[1] *= color[3]; 196 color[1] *= color[3];
@@ -949,21 +942,11 @@ static void render_floating(struct sway_output *soutput,
949 } 942 }
950} 943}
951 944
952static void render_dropzones(struct sway_output *output, 945static void render_seatops(struct sway_output *output,
953 pixman_region32_t *damage) { 946 pixman_region32_t *damage) {
954 struct sway_seat *seat; 947 struct sway_seat *seat;
955 wl_list_for_each(seat, &server.input->seats, link) { 948 wl_list_for_each(seat, &server.input->seats, link) {
956 if (seat->operation == OP_MOVE_TILING && seat->op_target_node 949 seatop_render(seat, output, damage);
957 && node_get_output(seat->op_target_node) == output) {
958 float color[4];
959 memcpy(&color, config->border_colors.focused.indicator,
960 sizeof(float) * 4);
961 premultiply_alpha(color, 0.5);
962 struct wlr_box box;
963 memcpy(&box, &seat->op_drop_box, sizeof(struct wlr_box));
964 scale_box(&box, output->wlr_output->scale);
965 render_rect(output->wlr_output, damage, &box, color);
966 }
967 } 950 }
968} 951}
969 952
@@ -1060,7 +1043,7 @@ void output_render(struct sway_output *output, struct timespec *when,
1060 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); 1043 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
1061 } 1044 }
1062 1045
1063 render_dropzones(output, damage); 1046 render_seatops(output, damage);
1064 1047
1065 struct sway_seat *seat = input_manager_current_seat(); 1048 struct sway_seat *seat = input_manager_current_seat();
1066 struct sway_container *focus = seat_get_focused_container(seat); 1049 struct sway_container *focus = seat_get_focused_container(seat);
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index f46938e2..1cdd7c6d 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -299,7 +299,7 @@ static void transaction_apply(struct sway_transaction *transaction) {
299 if (root->outputs->length) { 299 if (root->outputs->length) {
300 struct sway_seat *seat; 300 struct sway_seat *seat;
301 wl_list_for_each(seat, &server.input->seats, link) { 301 wl_list_for_each(seat, &server.input->seats, link) {
302 if (seat->operation == OP_NONE) { 302 if (!seat_doing_seatop(seat)) {
303 cursor_rebase(seat->cursor); 303 cursor_rebase(seat->cursor);
304 } 304 }
305 } 305 }
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 801dcee0..f05e156f 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -360,7 +360,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
360 struct wlr_xdg_toplevel_move_event *e = data; 360 struct wlr_xdg_toplevel_move_event *e = data;
361 struct sway_seat *seat = e->seat->seat->data; 361 struct sway_seat *seat = e->seat->seat->data;
362 if (e->serial == seat->last_button_serial) { 362 if (e->serial == seat->last_button_serial) {
363 seat_begin_move_floating(seat, view->container, seat->last_button); 363 seatop_begin_move_floating(seat, view->container, seat->last_button);
364 } 364 }
365} 365}
366 366
@@ -374,7 +374,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
374 struct wlr_xdg_toplevel_resize_event *e = data; 374 struct wlr_xdg_toplevel_resize_event *e = data;
375 struct sway_seat *seat = e->seat->seat->data; 375 struct sway_seat *seat = e->seat->seat->data;
376 if (e->serial == seat->last_button_serial) { 376 if (e->serial == seat->last_button_serial) {
377 seat_begin_resize_floating(seat, view->container, 377 seatop_begin_resize_floating(seat, view->container,
378 seat->last_button, e->edges); 378 seat->last_button, e->edges);
379 } 379 }
380} 380}
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 4bc83b8e..9f6741c8 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -357,7 +357,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
357 struct wlr_xdg_toplevel_v6_move_event *e = data; 357 struct wlr_xdg_toplevel_v6_move_event *e = data;
358 struct sway_seat *seat = e->seat->seat->data; 358 struct sway_seat *seat = e->seat->seat->data;
359 if (e->serial == seat->last_button_serial) { 359 if (e->serial == seat->last_button_serial) {
360 seat_begin_move_floating(seat, view->container, seat->last_button); 360 seatop_begin_move_floating(seat, view->container, seat->last_button);
361 } 361 }
362} 362}
363 363
@@ -371,7 +371,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
371 struct wlr_xdg_toplevel_v6_resize_event *e = data; 371 struct wlr_xdg_toplevel_v6_resize_event *e = data;
372 struct sway_seat *seat = e->seat->seat->data; 372 struct sway_seat *seat = e->seat->seat->data;
373 if (e->serial == seat->last_button_serial) { 373 if (e->serial == seat->last_button_serial) {
374 seat_begin_resize_floating(seat, view->container, 374 seatop_begin_resize_floating(seat, view->container,
375 seat->last_button, e->edges); 375 seat->last_button, e->edges);
376 } 376 }
377} 377}
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 1838ad32..080f6c41 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -470,7 +470,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
470 return; 470 return;
471 } 471 }
472 struct sway_seat *seat = input_manager_current_seat(); 472 struct sway_seat *seat = input_manager_current_seat();
473 seat_begin_move_floating(seat, view->container, seat->last_button); 473 seatop_begin_move_floating(seat, view->container, seat->last_button);
474} 474}
475 475
476static void handle_request_resize(struct wl_listener *listener, void *data) { 476static 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) {
486 } 486 }
487 struct wlr_xwayland_resize_event *e = data; 487 struct wlr_xwayland_resize_event *e = data;
488 struct sway_seat *seat = input_manager_current_seat(); 488 struct sway_seat *seat = input_manager_current_seat();
489 seat_begin_resize_floating(seat, view->container, 489 seatop_begin_resize_floating(seat, view->container,
490 seat->last_button, e->edges); 490 seat->last_button, e->edges);
491} 491}
492 492