diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-04 14:46:27 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-08 08:48:20 +1000 |
commit | 36281609ea882d4c0a2a10fc9e604eb1ec2e8951 (patch) | |
tree | 9d24fd3116da5feb8922ac041633d795d96e9596 /sway | |
parent | Merge pull request #2432 from RyanDwyer/fix-move-crash (diff) | |
download | sway-36281609ea882d4c0a2a10fc9e604eb1ec2e8951.tar.gz sway-36281609ea882d4c0a2a10fc9e604eb1ec2e8951.tar.zst sway-36281609ea882d4c0a2a10fc9e604eb1ec2e8951.zip |
Implement move to workspace on a floating container
Also adjusts container_floating_translate to not change the current
properties directly.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/tree/container.c | 51 | ||||
-rw-r--r-- | sway/tree/layout.c | 2 |
2 files changed, 46 insertions, 7 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 6da5ac3c..f31c152f 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -1163,19 +1163,16 @@ void container_floating_translate(struct sway_container *con, | |||
1163 | double x_amount, double y_amount) { | 1163 | double x_amount, double y_amount) { |
1164 | con->x += x_amount; | 1164 | con->x += x_amount; |
1165 | con->y += y_amount; | 1165 | con->y += y_amount; |
1166 | con->current.swayc_x += x_amount; | ||
1167 | con->current.swayc_y += y_amount; | ||
1168 | if (con->type == C_VIEW) { | 1166 | if (con->type == C_VIEW) { |
1169 | con->sway_view->x += x_amount; | 1167 | con->sway_view->x += x_amount; |
1170 | con->sway_view->y += y_amount; | 1168 | con->sway_view->y += y_amount; |
1171 | con->current.view_x += x_amount; | ||
1172 | con->current.view_y += y_amount; | ||
1173 | } else { | 1169 | } else { |
1174 | for (int i = 0; i < con->children->length; ++i) { | 1170 | for (int i = 0; i < con->children->length; ++i) { |
1175 | struct sway_container *child = con->children->items[i]; | 1171 | struct sway_container *child = con->children->items[i]; |
1176 | container_floating_translate(child, x_amount, y_amount); | 1172 | container_floating_translate(child, x_amount, y_amount); |
1177 | } | 1173 | } |
1178 | } | 1174 | } |
1175 | container_set_dirty(con); | ||
1179 | } | 1176 | } |
1180 | 1177 | ||
1181 | /** | 1178 | /** |
@@ -1219,9 +1216,7 @@ void container_floating_move_to(struct sway_container *con, | |||
1219 | "Expected a floating container")) { | 1216 | "Expected a floating container")) { |
1220 | return; | 1217 | return; |
1221 | } | 1218 | } |
1222 | desktop_damage_whole_container(con); | ||
1223 | container_floating_translate(con, lx - con->x, ly - con->y); | 1219 | container_floating_translate(con, lx - con->x, ly - con->y); |
1224 | desktop_damage_whole_container(con); | ||
1225 | struct sway_container *old_workspace = container_parent(con, C_WORKSPACE); | 1220 | struct sway_container *old_workspace = container_parent(con, C_WORKSPACE); |
1226 | struct sway_container *new_output = container_floating_find_output(con); | 1221 | struct sway_container *new_output = container_floating_find_output(con); |
1227 | if (!sway_assert(new_output, "Unable to find any output")) { | 1222 | if (!sway_assert(new_output, "Unable to find any output")) { |
@@ -1239,6 +1234,50 @@ void container_floating_move_to(struct sway_container *con, | |||
1239 | } | 1234 | } |
1240 | } | 1235 | } |
1241 | 1236 | ||
1237 | void container_floating_move_to_center(struct sway_container *con) { | ||
1238 | if (!sway_assert(container_is_floating(con), | ||
1239 | "Expected a floating container")) { | ||
1240 | return; | ||
1241 | } | ||
1242 | struct sway_container *ws = container_parent(con, C_WORKSPACE); | ||
1243 | double new_lx = ws->x + (ws->width - con->width) / 2; | ||
1244 | double new_ly = ws->y + (ws->height - con->height) / 2; | ||
1245 | container_floating_translate(con, new_lx - con->x, new_ly - con->y); | ||
1246 | } | ||
1247 | |||
1248 | void container_floating_move_to_container(struct sway_container *container, | ||
1249 | struct sway_container *destination) { | ||
1250 | // Resolve destination into a workspace | ||
1251 | struct sway_container *new_ws = NULL; | ||
1252 | if (destination->type == C_OUTPUT) { | ||
1253 | new_ws = output_get_active_workspace(destination->sway_output); | ||
1254 | } else if (destination->type == C_WORKSPACE) { | ||
1255 | new_ws = destination; | ||
1256 | } else { | ||
1257 | new_ws = container_parent(destination, C_WORKSPACE); | ||
1258 | } | ||
1259 | if (!new_ws) { | ||
1260 | // This can happen if the user has run "move container to mark foo", | ||
1261 | // where mark foo is on a hidden scratchpad container. | ||
1262 | return; | ||
1263 | } | ||
1264 | struct sway_container *old_ws = container_parent(container, C_WORKSPACE); | ||
1265 | if (old_ws != new_ws) { | ||
1266 | container_remove_child(container); | ||
1267 | container_add_child(new_ws->sway_workspace->floating, container); | ||
1268 | arrange_windows(old_ws); | ||
1269 | arrange_windows(new_ws); | ||
1270 | workspace_detect_urgent(old_ws); | ||
1271 | workspace_detect_urgent(new_ws); | ||
1272 | } | ||
1273 | // If the container's center doesn't overlap the new workspace, center it | ||
1274 | // within the workspace. | ||
1275 | struct sway_container *output = container_floating_find_output(container); | ||
1276 | if (new_ws->parent != output) { | ||
1277 | container_floating_move_to_center(container); | ||
1278 | } | ||
1279 | } | ||
1280 | |||
1242 | void container_set_dirty(struct sway_container *container) { | 1281 | void container_set_dirty(struct sway_container *container) { |
1243 | if (container->dirty) { | 1282 | if (container->dirty) { |
1244 | return; | 1283 | return; |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 20815654..bdcd1a9b 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -151,7 +151,7 @@ void container_move_to(struct sway_container *container, | |||
151 | return; | 151 | return; |
152 | } | 152 | } |
153 | if (container_is_floating(container)) { | 153 | if (container_is_floating(container)) { |
154 | // TODO | 154 | container_floating_move_to_container(container, destination); |
155 | return; | 155 | return; |
156 | } | 156 | } |
157 | struct sway_container *old_parent = container_remove_child(container); | 157 | struct sway_container *old_parent = container_remove_child(container); |