diff options
Diffstat (limited to 'sway/input/seatop_move_tiling.c')
-rw-r--r-- | sway/input/seatop_move_tiling.c | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/sway/input/seatop_move_tiling.c b/sway/input/seatop_move_tiling.c index 223c6c08..c525b77a 100644 --- a/sway/input/seatop_move_tiling.c +++ b/sway/input/seatop_move_tiling.c | |||
@@ -1,8 +1,6 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <limits.h> | 1 | #include <limits.h> |
3 | #include <wlr/types/wlr_cursor.h> | 2 | #include <wlr/types/wlr_cursor.h> |
4 | #include <wlr/util/edges.h> | 3 | #include <wlr/util/edges.h> |
5 | #include "sway/desktop.h" | ||
6 | #include "sway/desktop/transaction.h" | 4 | #include "sway/desktop/transaction.h" |
7 | #include "sway/input/cursor.h" | 5 | #include "sway/input/cursor.h" |
8 | #include "sway/input/seat.h" | 6 | #include "sway/input/seat.h" |
@@ -24,29 +22,17 @@ struct seatop_move_tiling_event { | |||
24 | struct sway_container *con; | 22 | struct sway_container *con; |
25 | struct sway_node *target_node; | 23 | struct sway_node *target_node; |
26 | enum wlr_edges target_edge; | 24 | enum wlr_edges target_edge; |
27 | struct wlr_box drop_box; | ||
28 | double ref_lx, ref_ly; // cursor's x/y at start of op | 25 | double ref_lx, ref_ly; // cursor's x/y at start of op |
29 | bool threshold_reached; | 26 | bool threshold_reached; |
30 | bool split_target; | 27 | bool split_target; |
31 | bool insert_after_target; | 28 | bool insert_after_target; |
29 | struct wlr_scene_rect *indicator_rect; | ||
32 | }; | 30 | }; |
33 | 31 | ||
34 | static void handle_render(struct sway_seat *seat, | 32 | static void handle_end(struct sway_seat *seat) { |
35 | struct sway_output *output, pixman_region32_t *damage) { | ||
36 | struct seatop_move_tiling_event *e = seat->seatop_data; | 33 | struct seatop_move_tiling_event *e = seat->seatop_data; |
37 | if (!e->threshold_reached) { | 34 | wlr_scene_node_destroy(&e->indicator_rect->node); |
38 | return; | 35 | e->indicator_rect = NULL; |
39 | } | ||
40 | if (e->target_node && node_get_output(e->target_node) == output) { | ||
41 | float color[4]; | ||
42 | memcpy(&color, config->border_colors.focused.indicator, | ||
43 | sizeof(float) * 4); | ||
44 | premultiply_alpha(color, 0.5); | ||
45 | struct wlr_box box; | ||
46 | memcpy(&box, &e->drop_box, sizeof(struct wlr_box)); | ||
47 | scale_box(&box, output->wlr_output->scale); | ||
48 | render_rect(output, damage, &box, color); | ||
49 | } | ||
50 | } | 36 | } |
51 | 37 | ||
52 | static void handle_motion_prethreshold(struct sway_seat *seat) { | 38 | static void handle_motion_prethreshold(struct sway_seat *seat) { |
@@ -67,6 +53,7 @@ static void handle_motion_prethreshold(struct sway_seat *seat) { | |||
67 | 53 | ||
68 | // If the threshold has been exceeded, start the actual drag | 54 | // If the threshold has been exceeded, start the actual drag |
69 | if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) { | 55 | if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) { |
56 | wlr_scene_node_set_enabled(&e->indicator_rect->node, true); | ||
70 | e->threshold_reached = true; | 57 | e->threshold_reached = true; |
71 | cursor_set_image(seat->cursor, "grab", NULL); | 58 | cursor_set_image(seat->cursor, "grab", NULL); |
72 | } | 59 | } |
@@ -165,6 +152,11 @@ static bool split_titlebar(struct sway_node *node, struct sway_container *avoid, | |||
165 | return false; | 152 | return false; |
166 | } | 153 | } |
167 | 154 | ||
155 | static void update_indicator(struct seatop_move_tiling_event *e, struct wlr_box *box) { | ||
156 | wlr_scene_node_set_position(&e->indicator_rect->node, box->x, box->y); | ||
157 | wlr_scene_rect_set_size(e->indicator_rect, box->width, box->height); | ||
158 | } | ||
159 | |||
168 | static void handle_motion_postthreshold(struct sway_seat *seat) { | 160 | static void handle_motion_postthreshold(struct sway_seat *seat) { |
169 | struct seatop_move_tiling_event *e = seat->seatop_data; | 161 | struct seatop_move_tiling_event *e = seat->seatop_data; |
170 | e->split_target = false; | 162 | e->split_target = false; |
@@ -173,8 +165,6 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
173 | struct sway_cursor *cursor = seat->cursor; | 165 | struct sway_cursor *cursor = seat->cursor; |
174 | struct sway_node *node = node_at_coords(seat, | 166 | struct sway_node *node = node_at_coords(seat, |
175 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); | 167 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); |
176 | // Damage the old location | ||
177 | desktop_damage_box(&e->drop_box); | ||
178 | 168 | ||
179 | if (!node) { | 169 | if (!node) { |
180 | // Eg. hovered over a layer surface such as swaybar | 170 | // Eg. hovered over a layer surface such as swaybar |
@@ -187,8 +177,10 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
187 | // Empty workspace | 177 | // Empty workspace |
188 | e->target_node = node; | 178 | e->target_node = node; |
189 | e->target_edge = WLR_EDGE_NONE; | 179 | e->target_edge = WLR_EDGE_NONE; |
190 | workspace_get_box(node->sway_workspace, &e->drop_box); | 180 | |
191 | desktop_damage_box(&e->drop_box); | 181 | struct wlr_box drop_box; |
182 | workspace_get_box(node->sway_workspace, &drop_box); | ||
183 | update_indicator(e, &drop_box); | ||
192 | return; | 184 | return; |
193 | } | 185 | } |
194 | 186 | ||
@@ -201,11 +193,18 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
201 | return; | 193 | return; |
202 | } | 194 | } |
203 | 195 | ||
196 | struct wlr_box drop_box = { | ||
197 | .x = con->pending.content_x, | ||
198 | .y = con->pending.content_y, | ||
199 | .width = con->pending.content_width, | ||
200 | .height = con->pending.content_height, | ||
201 | }; | ||
202 | |||
204 | // Check if the cursor is over a tilebar only if the destination | 203 | // Check if the cursor is over a tilebar only if the destination |
205 | // container is not a descendant of the source container. | 204 | // container is not a descendant of the source container. |
206 | if (!surface && !container_has_ancestor(con, e->con) && | 205 | if (!surface && !container_has_ancestor(con, e->con) && |
207 | split_titlebar(node, e->con, cursor->cursor, | 206 | split_titlebar(node, e->con, cursor->cursor, |
208 | &e->drop_box, &e->insert_after_target)) { | 207 | &drop_box, &e->insert_after_target)) { |
209 | // Don't allow dropping over the source container's titlebar | 208 | // Don't allow dropping over the source container's titlebar |
210 | // to give users a chance to cancel a drag operation. | 209 | // to give users a chance to cancel a drag operation. |
211 | if (con == e->con) { | 210 | if (con == e->con) { |
@@ -215,6 +214,7 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
215 | e->split_target = true; | 214 | e->split_target = true; |
216 | } | 215 | } |
217 | e->target_edge = WLR_EDGE_NONE; | 216 | e->target_edge = WLR_EDGE_NONE; |
217 | update_indicator(e, &drop_box); | ||
218 | return; | 218 | return; |
219 | } | 219 | } |
220 | 220 | ||
@@ -256,8 +256,7 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
256 | e->target_node = node_get_parent(e->target_node); | 256 | e->target_node = node_get_parent(e->target_node); |
257 | } | 257 | } |
258 | e->target_edge = edge; | 258 | e->target_edge = edge; |
259 | e->drop_box = box; | 259 | update_indicator(e, &box); |
260 | desktop_damage_box(&e->drop_box); | ||
261 | return; | 260 | return; |
262 | } | 261 | } |
263 | con = con->pending.parent; | 262 | con = con->pending.parent; |
@@ -299,12 +298,8 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
299 | } | 298 | } |
300 | 299 | ||
301 | e->target_node = node; | 300 | e->target_node = node; |
302 | e->drop_box.x = con->pending.content_x; | 301 | resize_box(&drop_box, e->target_edge, thickness); |
303 | e->drop_box.y = con->pending.content_y; | 302 | update_indicator(e, &drop_box); |
304 | e->drop_box.width = con->pending.content_width; | ||
305 | e->drop_box.height = con->pending.content_height; | ||
306 | resize_box(&e->drop_box, e->target_edge, thickness); | ||
307 | desktop_damage_box(&e->drop_box); | ||
308 | } | 303 | } |
309 | 304 | ||
310 | static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { | 305 | static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { |
@@ -410,7 +405,7 @@ static void finalize_move(struct sway_seat *seat) { | |||
410 | 405 | ||
411 | static void handle_button(struct sway_seat *seat, uint32_t time_msec, | 406 | static void handle_button(struct sway_seat *seat, uint32_t time_msec, |
412 | struct wlr_input_device *device, uint32_t button, | 407 | struct wlr_input_device *device, uint32_t button, |
413 | enum wlr_button_state state) { | 408 | enum wl_pointer_button_state state) { |
414 | if (seat->cursor->pressed_button_count == 0) { | 409 | if (seat->cursor->pressed_button_count == 0) { |
415 | finalize_move(seat); | 410 | finalize_move(seat); |
416 | } | 411 | } |
@@ -439,7 +434,7 @@ static const struct sway_seatop_impl seatop_impl = { | |||
439 | .pointer_motion = handle_pointer_motion, | 434 | .pointer_motion = handle_pointer_motion, |
440 | .tablet_tool_tip = handle_tablet_tool_tip, | 435 | .tablet_tool_tip = handle_tablet_tool_tip, |
441 | .unref = handle_unref, | 436 | .unref = handle_unref, |
442 | .render = handle_render, | 437 | .end = handle_end, |
443 | }; | 438 | }; |
444 | 439 | ||
445 | void seatop_begin_move_tiling_threshold(struct sway_seat *seat, | 440 | void seatop_begin_move_tiling_threshold(struct sway_seat *seat, |
@@ -451,6 +446,20 @@ void seatop_begin_move_tiling_threshold(struct sway_seat *seat, | |||
451 | if (!e) { | 446 | if (!e) { |
452 | return; | 447 | return; |
453 | } | 448 | } |
449 | |||
450 | const float *indicator = config->border_colors.focused.indicator; | ||
451 | float color[4] = { | ||
452 | indicator[0] * .5, | ||
453 | indicator[1] * .5, | ||
454 | indicator[2] * .5, | ||
455 | indicator[3] * .5, | ||
456 | }; | ||
457 | e->indicator_rect = wlr_scene_rect_create(seat->scene_tree, 0, 0, color); | ||
458 | if (!e->indicator_rect) { | ||
459 | free(e); | ||
460 | return; | ||
461 | } | ||
462 | |||
454 | e->con = con; | 463 | e->con = con; |
455 | e->ref_lx = seat->cursor->cursor->x; | 464 | e->ref_lx = seat->cursor->cursor->x; |
456 | e->ref_ly = seat->cursor->cursor->y; | 465 | e->ref_ly = seat->cursor->cursor->y; |