diff options
author | Alexander Orzechowski <alex@ozal.ski> | 2023-11-21 19:19:01 -0500 |
---|---|---|
committer | Kirill Primak <vyivel@eclair.cafe> | 2024-01-18 18:36:54 +0300 |
commit | 0639bde9fb5637fbe63c65bfe85660745f159b96 (patch) | |
tree | 455a5207abd0f603d709aa16e51989dafffbbf8f | |
parent | scene_graph: Port seat drag icons (diff) | |
download | sway-0639bde9fb5637fbe63c65bfe85660745f159b96.tar.gz sway-0639bde9fb5637fbe63c65bfe85660745f159b96.tar.zst sway-0639bde9fb5637fbe63c65bfe85660745f159b96.zip |
scene_graph: Port seatop_move_tiling indicators
-rw-r--r-- | sway/input/seatop_move_tiling.c | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/sway/input/seatop_move_tiling.c b/sway/input/seatop_move_tiling.c index 26704d0d..7de39ff6 100644 --- a/sway/input/seatop_move_tiling.c +++ b/sway/input/seatop_move_tiling.c | |||
@@ -2,7 +2,6 @@ | |||
2 | #include <limits.h> | 2 | #include <limits.h> |
3 | #include <wlr/types/wlr_cursor.h> | 3 | #include <wlr/types/wlr_cursor.h> |
4 | #include <wlr/util/edges.h> | 4 | #include <wlr/util/edges.h> |
5 | #include "sway/desktop.h" | ||
6 | #include "sway/desktop/transaction.h" | 5 | #include "sway/desktop/transaction.h" |
7 | #include "sway/input/cursor.h" | 6 | #include "sway/input/cursor.h" |
8 | #include "sway/input/seat.h" | 7 | #include "sway/input/seat.h" |
@@ -24,28 +23,17 @@ struct seatop_move_tiling_event { | |||
24 | struct sway_container *con; | 23 | struct sway_container *con; |
25 | struct sway_node *target_node; | 24 | struct sway_node *target_node; |
26 | enum wlr_edges target_edge; | 25 | 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 | 26 | double ref_lx, ref_ly; // cursor's x/y at start of op |
29 | bool threshold_reached; | 27 | bool threshold_reached; |
30 | bool split_target; | 28 | bool split_target; |
31 | bool insert_after_target; | 29 | bool insert_after_target; |
30 | struct wlr_scene_rect *indicator_rect; | ||
32 | }; | 31 | }; |
33 | 32 | ||
34 | static void handle_render(struct sway_seat *seat, struct render_context *ctx) { | 33 | static void handle_end(struct sway_seat *seat) { |
35 | struct seatop_move_tiling_event *e = seat->seatop_data; | 34 | struct seatop_move_tiling_event *e = seat->seatop_data; |
36 | if (!e->threshold_reached) { | 35 | wlr_scene_node_destroy(&e->indicator_rect->node); |
37 | return; | 36 | e->indicator_rect = NULL; |
38 | } | ||
39 | if (e->target_node && node_get_output(e->target_node) == ctx->output) { | ||
40 | float color[4]; | ||
41 | memcpy(&color, config->border_colors.focused.indicator, | ||
42 | sizeof(float) * 4); | ||
43 | premultiply_alpha(color, 0.5); | ||
44 | struct wlr_box box; | ||
45 | memcpy(&box, &e->drop_box, sizeof(struct wlr_box)); | ||
46 | scale_box(&box, ctx->output->wlr_output->scale); | ||
47 | render_rect(ctx, &box, color); | ||
48 | } | ||
49 | } | 37 | } |
50 | 38 | ||
51 | static void handle_motion_prethreshold(struct sway_seat *seat) { | 39 | static void handle_motion_prethreshold(struct sway_seat *seat) { |
@@ -66,6 +54,7 @@ static void handle_motion_prethreshold(struct sway_seat *seat) { | |||
66 | 54 | ||
67 | // If the threshold has been exceeded, start the actual drag | 55 | // If the threshold has been exceeded, start the actual drag |
68 | if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) { | 56 | if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) { |
57 | wlr_scene_node_set_enabled(&e->indicator_rect->node, true); | ||
69 | e->threshold_reached = true; | 58 | e->threshold_reached = true; |
70 | cursor_set_image(seat->cursor, "grab", NULL); | 59 | cursor_set_image(seat->cursor, "grab", NULL); |
71 | } | 60 | } |
@@ -164,6 +153,11 @@ static bool split_titlebar(struct sway_node *node, struct sway_container *avoid, | |||
164 | return false; | 153 | return false; |
165 | } | 154 | } |
166 | 155 | ||
156 | static void update_indicator(struct seatop_move_tiling_event *e, struct wlr_box *box) { | ||
157 | wlr_scene_node_set_position(&e->indicator_rect->node, box->x, box->y); | ||
158 | wlr_scene_rect_set_size(e->indicator_rect, box->width, box->height); | ||
159 | } | ||
160 | |||
167 | static void handle_motion_postthreshold(struct sway_seat *seat) { | 161 | static void handle_motion_postthreshold(struct sway_seat *seat) { |
168 | struct seatop_move_tiling_event *e = seat->seatop_data; | 162 | struct seatop_move_tiling_event *e = seat->seatop_data; |
169 | e->split_target = false; | 163 | e->split_target = false; |
@@ -172,8 +166,6 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
172 | struct sway_cursor *cursor = seat->cursor; | 166 | struct sway_cursor *cursor = seat->cursor; |
173 | struct sway_node *node = node_at_coords(seat, | 167 | struct sway_node *node = node_at_coords(seat, |
174 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); | 168 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); |
175 | // Damage the old location | ||
176 | desktop_damage_box(&e->drop_box); | ||
177 | 169 | ||
178 | if (!node) { | 170 | if (!node) { |
179 | // Eg. hovered over a layer surface such as swaybar | 171 | // Eg. hovered over a layer surface such as swaybar |
@@ -186,8 +178,10 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
186 | // Empty workspace | 178 | // Empty workspace |
187 | e->target_node = node; | 179 | e->target_node = node; |
188 | e->target_edge = WLR_EDGE_NONE; | 180 | e->target_edge = WLR_EDGE_NONE; |
189 | workspace_get_box(node->sway_workspace, &e->drop_box); | 181 | |
190 | desktop_damage_box(&e->drop_box); | 182 | struct wlr_box drop_box; |
183 | workspace_get_box(node->sway_workspace, &drop_box); | ||
184 | update_indicator(e, &drop_box); | ||
191 | return; | 185 | return; |
192 | } | 186 | } |
193 | 187 | ||
@@ -200,11 +194,18 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
200 | return; | 194 | return; |
201 | } | 195 | } |
202 | 196 | ||
197 | struct wlr_box drop_box = { | ||
198 | .x = con->pending.content_x, | ||
199 | .y = con->pending.content_y, | ||
200 | .width = con->pending.content_width, | ||
201 | .height = con->pending.content_height, | ||
202 | }; | ||
203 | |||
203 | // Check if the cursor is over a tilebar only if the destination | 204 | // Check if the cursor is over a tilebar only if the destination |
204 | // container is not a descendant of the source container. | 205 | // container is not a descendant of the source container. |
205 | if (!surface && !container_has_ancestor(con, e->con) && | 206 | if (!surface && !container_has_ancestor(con, e->con) && |
206 | split_titlebar(node, e->con, cursor->cursor, | 207 | split_titlebar(node, e->con, cursor->cursor, |
207 | &e->drop_box, &e->insert_after_target)) { | 208 | &drop_box, &e->insert_after_target)) { |
208 | // Don't allow dropping over the source container's titlebar | 209 | // Don't allow dropping over the source container's titlebar |
209 | // to give users a chance to cancel a drag operation. | 210 | // to give users a chance to cancel a drag operation. |
210 | if (con == e->con) { | 211 | if (con == e->con) { |
@@ -214,6 +215,7 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
214 | e->split_target = true; | 215 | e->split_target = true; |
215 | } | 216 | } |
216 | e->target_edge = WLR_EDGE_NONE; | 217 | e->target_edge = WLR_EDGE_NONE; |
218 | update_indicator(e, &drop_box); | ||
217 | return; | 219 | return; |
218 | } | 220 | } |
219 | 221 | ||
@@ -255,8 +257,7 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
255 | e->target_node = node_get_parent(e->target_node); | 257 | e->target_node = node_get_parent(e->target_node); |
256 | } | 258 | } |
257 | e->target_edge = edge; | 259 | e->target_edge = edge; |
258 | e->drop_box = box; | 260 | update_indicator(e, &box); |
259 | desktop_damage_box(&e->drop_box); | ||
260 | return; | 261 | return; |
261 | } | 262 | } |
262 | con = con->pending.parent; | 263 | con = con->pending.parent; |
@@ -298,12 +299,8 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { | |||
298 | } | 299 | } |
299 | 300 | ||
300 | e->target_node = node; | 301 | e->target_node = node; |
301 | e->drop_box.x = con->pending.content_x; | 302 | resize_box(&drop_box, e->target_edge, thickness); |
302 | e->drop_box.y = con->pending.content_y; | 303 | update_indicator(e, &drop_box); |
303 | e->drop_box.width = con->pending.content_width; | ||
304 | e->drop_box.height = con->pending.content_height; | ||
305 | resize_box(&e->drop_box, e->target_edge, thickness); | ||
306 | desktop_damage_box(&e->drop_box); | ||
307 | } | 304 | } |
308 | 305 | ||
309 | static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { | 306 | static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { |
@@ -438,7 +435,7 @@ static const struct sway_seatop_impl seatop_impl = { | |||
438 | .pointer_motion = handle_pointer_motion, | 435 | .pointer_motion = handle_pointer_motion, |
439 | .tablet_tool_tip = handle_tablet_tool_tip, | 436 | .tablet_tool_tip = handle_tablet_tool_tip, |
440 | .unref = handle_unref, | 437 | .unref = handle_unref, |
441 | .render = handle_render, | 438 | .end = handle_end, |
442 | }; | 439 | }; |
443 | 440 | ||
444 | void seatop_begin_move_tiling_threshold(struct sway_seat *seat, | 441 | void seatop_begin_move_tiling_threshold(struct sway_seat *seat, |
@@ -450,6 +447,20 @@ void seatop_begin_move_tiling_threshold(struct sway_seat *seat, | |||
450 | if (!e) { | 447 | if (!e) { |
451 | return; | 448 | return; |
452 | } | 449 | } |
450 | |||
451 | const float *indicator = config->border_colors.focused.indicator; | ||
452 | float color[4] = { | ||
453 | indicator[0] * .5, | ||
454 | indicator[1] * .5, | ||
455 | indicator[2] * .5, | ||
456 | indicator[3] * .5, | ||
457 | }; | ||
458 | e->indicator_rect = wlr_scene_rect_create(seat->scene_tree, 0, 0, color); | ||
459 | if (!e->indicator_rect) { | ||
460 | free(e); | ||
461 | return; | ||
462 | } | ||
463 | |||
453 | e->con = con; | 464 | e->con = con; |
454 | e->ref_lx = seat->cursor->cursor->x; | 465 | e->ref_lx = seat->cursor->cursor->x; |
455 | e->ref_ly = seat->cursor->cursor->y; | 466 | e->ref_ly = seat->cursor->cursor->y; |