2018-08-26 12:05:16 +10:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-05-27 01:02:21 +10:00
|
|
|
#include <strings.h>
|
2018-07-25 21:32:20 +10:00
|
|
|
#include "config.h"
|
2018-08-26 12:05:16 +10:00
|
|
|
#include "log.h"
|
2018-05-27 01:02:21 +10:00
|
|
|
#include "sway/commands.h"
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
#include "sway/output.h"
|
2018-06-06 22:57:34 +10:00
|
|
|
#include "sway/tree/arrange.h"
|
2018-08-26 12:05:16 +10:00
|
|
|
#include "sway/tree/root.h"
|
2018-05-27 01:02:21 +10:00
|
|
|
#include "sway/tree/view.h"
|
2018-08-26 12:05:16 +10:00
|
|
|
#include "sway/tree/workspace.h"
|
2018-05-27 01:02:21 +10:00
|
|
|
#include "stringop.h"
|
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
static const char expected_syntax[] =
|
2018-05-27 01:02:21 +10:00
|
|
|
"Expected 'swap container with id|con_id|mark <arg>'";
|
|
|
|
|
2018-08-26 12:05:16 +10:00
|
|
|
static void swap_places(struct sway_container *con1,
|
|
|
|
struct sway_container *con2) {
|
|
|
|
struct sway_container *temp = malloc(sizeof(struct sway_container));
|
|
|
|
temp->x = con1->x;
|
|
|
|
temp->y = con1->y;
|
|
|
|
temp->width = con1->width;
|
|
|
|
temp->height = con1->height;
|
2019-06-29 07:21:20 +10:00
|
|
|
temp->width_fraction = con1->width_fraction;
|
|
|
|
temp->height_fraction = con1->height_fraction;
|
2018-08-26 12:05:16 +10:00
|
|
|
temp->parent = con1->parent;
|
2018-10-15 20:40:40 +11:00
|
|
|
temp->workspace = con1->workspace;
|
2019-08-06 04:35:50 +10:00
|
|
|
bool temp_floating = container_is_floating(con1);
|
2018-08-26 12:05:16 +10:00
|
|
|
|
|
|
|
con1->x = con2->x;
|
|
|
|
con1->y = con2->y;
|
|
|
|
con1->width = con2->width;
|
|
|
|
con1->height = con2->height;
|
2019-06-29 07:21:20 +10:00
|
|
|
con1->width_fraction = con2->width_fraction;
|
|
|
|
con1->height_fraction = con2->height_fraction;
|
2018-08-26 12:05:16 +10:00
|
|
|
|
|
|
|
con2->x = temp->x;
|
|
|
|
con2->y = temp->y;
|
|
|
|
con2->width = temp->width;
|
|
|
|
con2->height = temp->height;
|
2019-06-29 07:21:20 +10:00
|
|
|
con2->width_fraction = temp->width_fraction;
|
|
|
|
con2->height_fraction = temp->height_fraction;
|
2018-08-26 12:05:16 +10:00
|
|
|
|
|
|
|
int temp_index = container_sibling_index(con1);
|
2018-10-15 20:40:40 +11:00
|
|
|
if (con2->parent) {
|
|
|
|
container_insert_child(con2->parent, con1,
|
|
|
|
container_sibling_index(con2));
|
2019-08-06 04:35:50 +10:00
|
|
|
} else if (container_is_floating(con2)) {
|
|
|
|
workspace_add_floating(con2->workspace, con1);
|
2018-10-15 20:40:40 +11:00
|
|
|
} else {
|
|
|
|
workspace_insert_tiling(con2->workspace, con1,
|
|
|
|
container_sibling_index(con2));
|
|
|
|
}
|
|
|
|
if (temp->parent) {
|
|
|
|
container_insert_child(temp->parent, con2, temp_index);
|
2019-08-06 04:35:50 +10:00
|
|
|
} else if (temp_floating) {
|
|
|
|
workspace_add_floating(temp->workspace, con2);
|
2018-10-15 20:40:40 +11:00
|
|
|
} else {
|
|
|
|
workspace_insert_tiling(temp->workspace, con2, temp_index);
|
|
|
|
}
|
2018-08-26 12:05:16 +10:00
|
|
|
|
|
|
|
free(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void swap_focus(struct sway_container *con1,
|
|
|
|
struct sway_container *con2, struct sway_seat *seat,
|
|
|
|
struct sway_container *focus) {
|
|
|
|
if (focus == con1 || focus == con2) {
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
struct sway_workspace *ws1 = con1->workspace;
|
|
|
|
struct sway_workspace *ws2 = con2->workspace;
|
|
|
|
enum sway_container_layout layout1 = container_parent_layout(con1);
|
|
|
|
enum sway_container_layout layout2 = container_parent_layout(con2);
|
|
|
|
if (focus == con1 && (layout2 == L_TABBED || layout2 == L_STACKED)) {
|
2018-08-26 12:05:16 +10:00
|
|
|
if (workspace_is_visible(ws2)) {
|
2018-10-19 00:08:45 +11:00
|
|
|
seat_set_focus(seat, &con2->node);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
2018-09-06 19:26:56 +10:00
|
|
|
seat_set_focus_container(seat, ws1 != ws2 ? con2 : con1);
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
} else if (focus == con2 && (layout1 == L_TABBED
|
|
|
|
|| layout1 == L_STACKED)) {
|
2018-08-26 12:05:16 +10:00
|
|
|
if (workspace_is_visible(ws1)) {
|
2018-10-19 00:08:45 +11:00
|
|
|
seat_set_focus(seat, &con1->node);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
2018-09-06 19:26:56 +10:00
|
|
|
seat_set_focus_container(seat, ws1 != ws2 ? con1 : con2);
|
2018-08-26 12:05:16 +10:00
|
|
|
} else if (ws1 != ws2) {
|
2018-09-06 19:26:56 +10:00
|
|
|
seat_set_focus_container(seat, focus == con1 ? con2 : con1);
|
2018-08-26 12:05:16 +10:00
|
|
|
} else {
|
2018-09-06 19:26:56 +10:00
|
|
|
seat_set_focus_container(seat, focus);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
} else {
|
2018-09-06 19:26:56 +10:00
|
|
|
seat_set_focus_container(seat, focus);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
2019-01-25 09:29:21 +11:00
|
|
|
|
|
|
|
if (root->fullscreen_global) {
|
|
|
|
seat_set_focus(seat,
|
|
|
|
seat_get_focus_inactive(seat, &root->fullscreen_global->node));
|
|
|
|
}
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
|
2019-07-09 06:29:04 +10:00
|
|
|
void container_swap(struct sway_container *con1, struct sway_container *con2) {
|
2018-08-26 12:05:16 +10:00
|
|
|
if (!sway_assert(con1 && con2, "Cannot swap with nothing")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!sway_assert(!container_has_ancestor(con1, con2)
|
|
|
|
&& !container_has_ancestor(con2, con1),
|
|
|
|
"Cannot swap ancestor and descendant")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Swapping containers %zu and %zu",
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
con1->node.id, con2->node.id);
|
2018-08-26 12:05:16 +10:00
|
|
|
|
2019-08-06 04:35:50 +10:00
|
|
|
bool scratch1 = con1->scratchpad;
|
|
|
|
bool hidden1 = container_is_scratchpad_hidden(con1);
|
|
|
|
bool scratch2 = con2->scratchpad;
|
|
|
|
bool hidden2 = container_is_scratchpad_hidden(con2);
|
|
|
|
if (scratch1) {
|
|
|
|
if (hidden1) {
|
|
|
|
root_scratchpad_show(con1);
|
|
|
|
}
|
|
|
|
root_scratchpad_remove_container(con1);
|
|
|
|
}
|
|
|
|
if (scratch2) {
|
|
|
|
if (hidden2) {
|
|
|
|
root_scratchpad_show(con2);
|
|
|
|
}
|
|
|
|
root_scratchpad_remove_container(con2);
|
|
|
|
}
|
|
|
|
|
2019-01-25 09:29:21 +11:00
|
|
|
enum sway_fullscreen_mode fs1 = con1->fullscreen_mode;
|
|
|
|
enum sway_fullscreen_mode fs2 = con2->fullscreen_mode;
|
2018-08-26 12:05:16 +10:00
|
|
|
if (fs1) {
|
2019-01-25 09:29:21 +11:00
|
|
|
container_fullscreen_disable(con1);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
if (fs2) {
|
2019-01-25 09:29:21 +11:00
|
|
|
container_fullscreen_disable(con2);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
|
2019-01-09 17:37:46 +11:00
|
|
|
struct sway_seat *seat = config->handler_context.seat;
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
struct sway_container *focus = seat_get_focused_container(seat);
|
|
|
|
struct sway_workspace *vis1 =
|
|
|
|
output_get_active_workspace(con1->workspace->output);
|
|
|
|
struct sway_workspace *vis2 =
|
|
|
|
output_get_active_workspace(con2->workspace->output);
|
2019-02-22 05:24:13 +11:00
|
|
|
if (!sway_assert(vis1 && vis2, "con1 or con2 are on an output without a"
|
|
|
|
"workspace. This should not happen")) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-26 12:05:16 +10:00
|
|
|
|
|
|
|
char *stored_prev_name = NULL;
|
2018-10-21 12:26:22 +11:00
|
|
|
if (seat->prev_workspace_name) {
|
|
|
|
stored_prev_name = strdup(seat->prev_workspace_name);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
swap_places(con1, con2);
|
|
|
|
|
|
|
|
if (!workspace_is_visible(vis1)) {
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
seat_set_focus(seat, seat_get_focus_inactive(seat, &vis1->node));
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
if (!workspace_is_visible(vis2)) {
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
seat_set_focus(seat, seat_get_focus_inactive(seat, &vis2->node));
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
swap_focus(con1, con2, seat, focus);
|
|
|
|
|
|
|
|
if (stored_prev_name) {
|
2018-10-21 12:26:22 +11:00
|
|
|
free(seat->prev_workspace_name);
|
|
|
|
seat->prev_workspace_name = stored_prev_name;
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
|
2019-08-06 04:35:50 +10:00
|
|
|
if (scratch1) {
|
|
|
|
root_scratchpad_add_container(con2, NULL);
|
|
|
|
if (!hidden1) {
|
|
|
|
root_scratchpad_show(con2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scratch2) {
|
|
|
|
root_scratchpad_add_container(con1, NULL);
|
|
|
|
if (!hidden2) {
|
|
|
|
root_scratchpad_show(con1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-26 12:05:16 +10:00
|
|
|
if (fs1) {
|
2019-01-25 09:29:21 +11:00
|
|
|
container_set_fullscreen(con2, fs1);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
if (fs2) {
|
2019-01-25 09:29:21 +11:00
|
|
|
container_set_fullscreen(con1, fs2);
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 05:31:43 +11:00
|
|
|
static bool test_con_id(struct sway_container *container, void *data) {
|
|
|
|
size_t *con_id = data;
|
|
|
|
return container->node.id == *con_id;
|
2018-05-27 01:02:21 +10:00
|
|
|
}
|
|
|
|
|
2018-11-18 10:33:06 +11:00
|
|
|
#if HAVE_XWAYLAND
|
2018-11-15 05:31:43 +11:00
|
|
|
static bool test_id(struct sway_container *container, void *data) {
|
|
|
|
xcb_window_t *wid = data;
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
return (container->view && container->view->type == SWAY_VIEW_XWAYLAND
|
|
|
|
&& container->view->wlr_xwayland_surface->window_id == *wid);
|
2018-05-27 01:02:21 +10:00
|
|
|
}
|
2018-11-15 05:31:43 +11:00
|
|
|
#endif
|
2018-05-27 01:02:21 +10:00
|
|
|
|
|
|
|
static bool test_mark(struct sway_container *container, void *mark) {
|
2018-10-31 22:27:38 +11:00
|
|
|
if (container->marks->length) {
|
|
|
|
return !list_seq_find(container->marks,
|
2018-05-27 01:02:21 +10:00
|
|
|
(int (*)(const void *, const void *))strcmp, mark);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_results *cmd_swap(int argc, char **argv) {
|
|
|
|
struct cmd_results *error = NULL;
|
|
|
|
if ((error = checkarg(argc, "swap", EXPECTED_AT_LEAST, 4))) {
|
|
|
|
return error;
|
|
|
|
}
|
2018-10-26 01:03:44 +11:00
|
|
|
if (!root->outputs->length) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID,
|
2018-10-26 01:03:44 +11:00
|
|
|
"Can't run this command while there's no outputs connected.");
|
|
|
|
}
|
2018-05-27 01:02:21 +10:00
|
|
|
|
|
|
|
if (strcasecmp(argv[0], "container") || strcasecmp(argv[1], "with")) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, expected_syntax);
|
2018-05-27 01:02:21 +10:00
|
|
|
}
|
|
|
|
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
struct sway_container *current = config->handler_context.container;
|
2018-11-08 23:57:04 +11:00
|
|
|
struct sway_container *other = NULL;
|
2018-05-27 01:02:21 +10:00
|
|
|
|
|
|
|
char *value = join_args(argv + 3, argc - 3);
|
|
|
|
if (strcasecmp(argv[2], "id") == 0) {
|
2018-11-18 10:33:06 +11:00
|
|
|
#if HAVE_XWAYLAND
|
2018-05-27 01:02:21 +10:00
|
|
|
xcb_window_t id = strtol(value, NULL, 0);
|
2018-11-15 05:31:43 +11:00
|
|
|
other = root_find_container(test_id, &id);
|
2018-07-25 07:37:41 +10:00
|
|
|
#endif
|
2018-05-27 01:02:21 +10:00
|
|
|
} else if (strcasecmp(argv[2], "con_id") == 0) {
|
|
|
|
size_t con_id = atoi(value);
|
2018-11-15 05:31:43 +11:00
|
|
|
other = root_find_container(test_con_id, &con_id);
|
2018-05-27 01:02:21 +10:00
|
|
|
} else if (strcasecmp(argv[2], "mark") == 0) {
|
2018-11-15 05:31:43 +11:00
|
|
|
other = root_find_container(test_mark, value);
|
2018-05-27 01:02:21 +10:00
|
|
|
} else {
|
|
|
|
free(value);
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, expected_syntax);
|
2018-05-27 01:02:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!other) {
|
2019-01-11 10:27:21 +11:00
|
|
|
error = cmd_results_new(CMD_FAILURE,
|
2018-05-27 01:02:21 +10:00
|
|
|
"Failed to find %s '%s'", argv[2], value);
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
} else if (!current) {
|
2019-01-11 10:27:21 +11:00
|
|
|
error = cmd_results_new(CMD_FAILURE,
|
2018-05-27 01:02:21 +10:00
|
|
|
"Can only swap with containers and views");
|
2018-05-28 12:45:42 +10:00
|
|
|
} else if (container_has_ancestor(current, other)
|
|
|
|
|| container_has_ancestor(other, current)) {
|
2019-01-11 10:27:21 +11:00
|
|
|
error = cmd_results_new(CMD_FAILURE,
|
2018-05-27 01:02:21 +10:00
|
|
|
"Cannot swap ancestor and descendant");
|
|
|
|
}
|
|
|
|
|
|
|
|
free(value);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
container_swap(current, other);
|
2018-06-06 22:57:34 +10:00
|
|
|
|
2019-01-25 09:29:21 +11:00
|
|
|
if (root->fullscreen_global) {
|
|
|
|
arrange_root();
|
|
|
|
} else {
|
2019-08-06 04:35:50 +10:00
|
|
|
struct sway_node *current_parent = node_get_parent(¤t->node);
|
|
|
|
struct sway_node *other_parent = node_get_parent(&other->node);
|
|
|
|
if (current_parent) {
|
|
|
|
arrange_node(current_parent);
|
|
|
|
}
|
|
|
|
if (other_parent && current_parent != other_parent) {
|
|
|
|
arrange_node(other_parent);
|
2019-01-25 09:29:21 +11:00
|
|
|
}
|
2018-06-06 22:57:34 +10:00
|
|
|
}
|
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-05-27 01:02:21 +10:00
|
|
|
}
|