2018-04-05 11:32:31 +10:00
|
|
|
#include <errno.h>
|
2018-07-14 10:00:22 +10:00
|
|
|
#include <limits.h>
|
2018-04-05 11:32:31 +10:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
2018-08-21 12:41:57 +10:00
|
|
|
#include <wlr/util/edges.h>
|
2018-04-05 11:32:31 +10:00
|
|
|
#include "sway/commands.h"
|
2018-04-28 11:26:14 +10:00
|
|
|
#include "sway/tree/arrange.h"
|
2018-07-11 21:30:43 +10:00
|
|
|
#include "sway/tree/view.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/tree/workspace.h"
|
2018-04-05 11:32:31 +10:00
|
|
|
#include "log.h"
|
|
|
|
|
2019-01-14 20:03:32 +11:00
|
|
|
#define AXIS_HORIZONTAL (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)
|
|
|
|
#define AXIS_VERTICAL (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)
|
|
|
|
|
2018-04-05 11:32:31 +10:00
|
|
|
static const int MIN_SANE_W = 100, MIN_SANE_H = 60;
|
|
|
|
|
|
|
|
enum resize_unit {
|
|
|
|
RESIZE_UNIT_PX,
|
|
|
|
RESIZE_UNIT_PPT,
|
|
|
|
RESIZE_UNIT_DEFAULT,
|
|
|
|
RESIZE_UNIT_INVALID,
|
|
|
|
};
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
struct resize_amount {
|
|
|
|
int amount;
|
|
|
|
enum resize_unit unit;
|
|
|
|
};
|
|
|
|
|
2018-04-05 11:32:31 +10:00
|
|
|
static enum resize_unit parse_resize_unit(const char *unit) {
|
|
|
|
if (strcasecmp(unit, "px") == 0) {
|
|
|
|
return RESIZE_UNIT_PX;
|
|
|
|
}
|
|
|
|
if (strcasecmp(unit, "ppt") == 0) {
|
|
|
|
return RESIZE_UNIT_PPT;
|
|
|
|
}
|
|
|
|
if (strcasecmp(unit, "default") == 0) {
|
|
|
|
return RESIZE_UNIT_DEFAULT;
|
|
|
|
}
|
|
|
|
return RESIZE_UNIT_INVALID;
|
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
// Parse arguments such as "10", "10px" or "10 px".
|
|
|
|
// Returns the number of arguments consumed.
|
|
|
|
static int parse_resize_amount(int argc, char **argv,
|
|
|
|
struct resize_amount *amount) {
|
|
|
|
char *err;
|
|
|
|
amount->amount = (int)strtol(argv[0], &err, 10);
|
|
|
|
if (*err) {
|
|
|
|
// e.g. 10px
|
|
|
|
amount->unit = parse_resize_unit(err);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (argc == 1) {
|
|
|
|
amount->unit = RESIZE_UNIT_DEFAULT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// Try the second argument
|
|
|
|
amount->unit = parse_resize_unit(argv[1]);
|
|
|
|
if (amount->unit == RESIZE_UNIT_INVALID) {
|
|
|
|
amount->unit = RESIZE_UNIT_DEFAULT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2018-07-14 10:00:22 +10:00
|
|
|
static void calculate_constraints(int *min_width, int *max_width,
|
|
|
|
int *min_height, int *max_height) {
|
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 *con = config->handler_context.container;
|
2018-07-14 10:00:22 +10:00
|
|
|
|
|
|
|
if (config->floating_minimum_width == -1) { // no minimum
|
|
|
|
*min_width = 0;
|
|
|
|
} else if (config->floating_minimum_width == 0) { // automatic
|
|
|
|
*min_width = 75;
|
|
|
|
} else {
|
|
|
|
*min_width = config->floating_minimum_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->floating_minimum_height == -1) { // no minimum
|
|
|
|
*min_height = 0;
|
|
|
|
} else if (config->floating_minimum_height == 0) { // automatic
|
|
|
|
*min_height = 50;
|
|
|
|
} else {
|
|
|
|
*min_height = config->floating_minimum_height;
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:02:08 +11:00
|
|
|
if (config->floating_maximum_width == -1 || !con->workspace) { // no max
|
2018-07-14 10:00:22 +10:00
|
|
|
*max_width = INT_MAX;
|
|
|
|
} else if (config->floating_maximum_width == 0) { // automatic
|
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
|
|
|
*max_width = con->workspace->width;
|
2018-07-14 10:00:22 +10:00
|
|
|
} else {
|
|
|
|
*max_width = config->floating_maximum_width;
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:02:08 +11:00
|
|
|
if (config->floating_maximum_height == -1 || !con->workspace) { // no max
|
2018-07-14 10:00:22 +10:00
|
|
|
*max_height = INT_MAX;
|
|
|
|
} else if (config->floating_maximum_height == 0) { // automatic
|
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
|
|
|
*max_height = con->workspace->height;
|
2018-07-14 10:00:22 +10:00
|
|
|
} else {
|
|
|
|
*max_height = config->floating_maximum_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:10:49 +11:00
|
|
|
static uint32_t parse_resize_axis(const char *axis) {
|
2018-04-05 11:32:31 +10:00
|
|
|
if (strcasecmp(axis, "width") == 0 || strcasecmp(axis, "horizontal") == 0) {
|
2019-01-14 20:03:32 +11:00
|
|
|
return AXIS_HORIZONTAL;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
if (strcasecmp(axis, "height") == 0 || strcasecmp(axis, "vertical") == 0) {
|
2019-01-14 20:03:32 +11:00
|
|
|
return AXIS_VERTICAL;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
2018-07-11 21:30:43 +10:00
|
|
|
if (strcasecmp(axis, "up") == 0) {
|
2019-01-14 20:03:32 +11:00
|
|
|
return WLR_EDGE_TOP;
|
2018-07-11 21:30:43 +10:00
|
|
|
}
|
|
|
|
if (strcasecmp(axis, "down") == 0) {
|
2019-01-14 20:03:32 +11:00
|
|
|
return WLR_EDGE_BOTTOM;
|
2018-07-11 21:30:43 +10:00
|
|
|
}
|
|
|
|
if (strcasecmp(axis, "left") == 0) {
|
2019-01-14 20:03:32 +11:00
|
|
|
return WLR_EDGE_LEFT;
|
2018-07-11 21:30:43 +10:00
|
|
|
}
|
|
|
|
if (strcasecmp(axis, "right") == 0) {
|
2019-01-14 20:03:32 +11:00
|
|
|
return WLR_EDGE_RIGHT;
|
2018-07-11 21:30:43 +10:00
|
|
|
}
|
2019-01-14 20:03:32 +11:00
|
|
|
return WLR_EDGE_NONE;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2019-01-14 21:10:49 +11:00
|
|
|
static bool is_horizontal(uint32_t axis) {
|
2019-01-14 20:03:32 +11:00
|
|
|
return axis & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT);
|
2018-08-09 19:36:44 +10:00
|
|
|
}
|
|
|
|
|
2019-01-14 22:22:53 +11:00
|
|
|
struct sway_container *container_find_resize_parent(struct sway_container *con,
|
|
|
|
uint32_t axis) {
|
|
|
|
enum sway_container_layout parallel_layout =
|
|
|
|
is_horizontal(axis) ? L_HORIZ : L_VERT;
|
|
|
|
bool allow_first = axis != WLR_EDGE_TOP && axis != WLR_EDGE_LEFT;
|
|
|
|
bool allow_last = axis != WLR_EDGE_RIGHT && axis != WLR_EDGE_BOTTOM;
|
|
|
|
|
|
|
|
while (con) {
|
|
|
|
list_t *siblings = container_get_siblings(con);
|
|
|
|
int index = container_sibling_index(con);
|
|
|
|
if (container_parent_layout(con) == parallel_layout &&
|
|
|
|
siblings->length > 1 && (allow_first || index > 0) &&
|
|
|
|
(allow_last || index < siblings->length - 1)) {
|
|
|
|
return con;
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
2019-01-14 22:22:53 +11:00
|
|
|
con = con->parent;
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
2019-01-14 22:22:53 +11:00
|
|
|
|
|
|
|
return NULL;
|
2018-08-26 12:05:16 +10:00
|
|
|
}
|
|
|
|
|
2019-01-14 22:22:53 +11:00
|
|
|
void container_resize_tiled(struct sway_container *con,
|
|
|
|
uint32_t axis, int amount) {
|
|
|
|
if (!con) {
|
2018-10-09 23:25:21 +11:00
|
|
|
return;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2019-01-14 22:22:53 +11:00
|
|
|
con = container_find_resize_parent(con, axis);
|
|
|
|
if (!con) {
|
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
|
|
|
// Can't resize in this direction
|
2018-10-09 23:25:21 +11:00
|
|
|
return;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2019-01-14 22:22:53 +11:00
|
|
|
// For HORIZONTAL or VERTICAL, we are growing in two directions so select
|
|
|
|
// both adjacent siblings. For RIGHT or DOWN, just select the next sibling.
|
|
|
|
// For LEFT or UP, convert it to a RIGHT or DOWN resize and reassign con to
|
|
|
|
// the previous sibling.
|
|
|
|
struct sway_container *prev = NULL;
|
|
|
|
struct sway_container *next = NULL;
|
|
|
|
list_t *siblings = container_get_siblings(con);
|
|
|
|
int index = container_sibling_index(con);
|
|
|
|
|
|
|
|
if (axis == AXIS_HORIZONTAL || axis == AXIS_VERTICAL) {
|
2019-01-15 09:17:41 +11:00
|
|
|
if (index == 0) {
|
|
|
|
next = siblings->items[1];
|
|
|
|
} else if (index == siblings->length - 1) {
|
|
|
|
// Convert edge to top/left
|
|
|
|
next = con;
|
|
|
|
con = siblings->items[index - 1];
|
|
|
|
amount = -amount;
|
|
|
|
} else {
|
|
|
|
prev = siblings->items[index - 1];
|
|
|
|
next = siblings->items[index + 1];
|
|
|
|
}
|
2019-01-14 22:22:53 +11:00
|
|
|
} else if (axis == WLR_EDGE_TOP || axis == WLR_EDGE_LEFT) {
|
|
|
|
if (!sway_assert(index > 0, "Didn't expect first child")) {
|
|
|
|
return;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
2019-01-14 22:22:53 +11:00
|
|
|
next = con;
|
|
|
|
con = siblings->items[index - 1];
|
|
|
|
amount = -amount;
|
|
|
|
} else {
|
|
|
|
if (!sway_assert(index < siblings->length - 1,
|
|
|
|
"Didn't expect last child")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
next = siblings->items[index + 1];
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2019-01-14 22:22:53 +11:00
|
|
|
// Apply new dimensions
|
|
|
|
int sibling_amount = prev ? amount / 2 : amount;
|
|
|
|
|
|
|
|
if (is_horizontal(axis)) {
|
|
|
|
if (con->width + amount < MIN_SANE_W) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (next->width - sibling_amount < MIN_SANE_W) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (prev && prev->width - sibling_amount < MIN_SANE_W) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
con->width += amount;
|
|
|
|
next->width -= sibling_amount;
|
|
|
|
if (prev) {
|
|
|
|
prev->width -= sibling_amount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (con->height + amount < MIN_SANE_H) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (next->height - sibling_amount < MIN_SANE_H) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (prev && prev->height - sibling_amount < MIN_SANE_H) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
con->height += amount;
|
|
|
|
next->height -= sibling_amount;
|
|
|
|
if (prev) {
|
|
|
|
prev->height -= sibling_amount;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 22:22:53 +11:00
|
|
|
if (con->parent) {
|
|
|
|
arrange_container(con->parent);
|
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 {
|
2019-01-14 22:22:53 +11:00
|
|
|
arrange_workspace(con->workspace);
|
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
|
|
|
}
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
/**
|
|
|
|
* Implement `resize <grow|shrink>` for a floating container.
|
|
|
|
*/
|
2019-01-14 21:10:49 +11:00
|
|
|
static struct cmd_results *resize_adjust_floating(uint32_t axis,
|
2018-07-13 18:06:11 +10:00
|
|
|
struct resize_amount *amount) {
|
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 *con = config->handler_context.container;
|
2018-07-11 21:30:43 +10:00
|
|
|
int grow_width = 0, grow_height = 0;
|
2019-01-14 20:03:32 +11:00
|
|
|
|
|
|
|
if (is_horizontal(axis)) {
|
2018-07-13 18:06:11 +10:00
|
|
|
grow_width = amount->amount;
|
2019-01-14 20:03:32 +11:00
|
|
|
} else {
|
2018-07-13 18:06:11 +10:00
|
|
|
grow_height = amount->amount;
|
2018-07-14 10:00:22 +10:00
|
|
|
}
|
2019-01-14 20:03:32 +11:00
|
|
|
|
2018-07-14 10:00:22 +10:00
|
|
|
// Make sure we're not adjusting beyond floating min/max size
|
|
|
|
int min_width, max_width, min_height, max_height;
|
|
|
|
calculate_constraints(&min_width, &max_width, &min_height, &max_height);
|
|
|
|
if (con->width + grow_width < min_width) {
|
|
|
|
grow_width = min_width - con->width;
|
|
|
|
} else if (con->width + grow_width > max_width) {
|
|
|
|
grow_width = max_width - con->width;
|
|
|
|
}
|
|
|
|
if (con->height + grow_height < min_height) {
|
|
|
|
grow_height = min_height - con->height;
|
|
|
|
} else if (con->height + grow_height > max_height) {
|
|
|
|
grow_height = max_height - con->height;
|
|
|
|
}
|
|
|
|
int grow_x = 0, grow_y = 0;
|
2019-01-14 20:03:32 +11:00
|
|
|
|
|
|
|
if (axis == AXIS_HORIZONTAL) {
|
2018-07-14 10:00:22 +10:00
|
|
|
grow_x = -grow_width / 2;
|
2019-01-14 20:03:32 +11:00
|
|
|
} else if (axis == AXIS_VERTICAL) {
|
2018-07-14 10:00:22 +10:00
|
|
|
grow_y = -grow_height / 2;
|
2019-01-14 20:03:32 +11:00
|
|
|
} else if (axis == WLR_EDGE_TOP) {
|
2018-07-14 10:00:22 +10:00
|
|
|
grow_y = -grow_height;
|
2019-01-14 20:03:32 +11:00
|
|
|
} else if (axis == WLR_EDGE_LEFT) {
|
2018-07-14 10:00:22 +10:00
|
|
|
grow_x = -grow_width;
|
2018-07-11 21:30:43 +10:00
|
|
|
}
|
2018-09-29 17:05:55 +10:00
|
|
|
if (grow_x == 0 && grow_y == 0) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Cannot resize any further");
|
2018-09-29 17:05:55 +10:00
|
|
|
}
|
2018-07-11 21:30:43 +10:00
|
|
|
con->x += grow_x;
|
|
|
|
con->y += grow_y;
|
|
|
|
con->width += grow_width;
|
|
|
|
con->height += grow_height;
|
|
|
|
|
Move view {x,y,width,height} into container struct
This renames/moves the following properties:
* sway_view.{x,y,width,height} ->
sway_container.content_{x,y,width,height}
* This is required to support placeholder containers as they don't
have a view.
* sway_container_state.view_{x,y,width,height} ->
sway_container_state.content_{x,y,width,height}
* To remain consistent with the above.
* sway_container_state.con_{x,y,width,height} ->
sway_container_state.{x,y,width,height}
* The con prefix was there to give it contrast from the view
properties, and is no longer useful.
The function container_set_geometry_from_floating_view has also been
renamed to container_set_geometry_from_content.
2018-11-17 19:32:03 +11:00
|
|
|
con->content_x += grow_x;
|
|
|
|
con->content_y += grow_y;
|
|
|
|
con->content_width += grow_width;
|
|
|
|
con->content_height += grow_height;
|
2018-07-11 21:30:43 +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
|
|
|
arrange_container(con);
|
2018-07-13 18:06:11 +10:00
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-07-11 21:30:43 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
/**
|
|
|
|
* Implement `resize <grow|shrink>` for a tiled container.
|
|
|
|
*/
|
2019-01-14 21:10:49 +11:00
|
|
|
static struct cmd_results *resize_adjust_tiled(uint32_t axis,
|
2018-07-13 18:06:11 +10:00
|
|
|
struct resize_amount *amount) {
|
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-07-11 21:30:43 +10:00
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
if (amount->unit == RESIZE_UNIT_DEFAULT) {
|
|
|
|
amount->unit = RESIZE_UNIT_PPT;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
2018-07-13 18:06:11 +10:00
|
|
|
if (amount->unit == RESIZE_UNIT_PPT) {
|
|
|
|
float pct = amount->amount / 100.0f;
|
2019-01-14 20:03:32 +11:00
|
|
|
|
|
|
|
if (is_horizontal(axis)) {
|
2018-07-13 18:06:11 +10:00
|
|
|
amount->amount = (float)current->width * pct;
|
2019-01-14 20:03:32 +11:00
|
|
|
} else {
|
2018-07-13 18:06:11 +10:00
|
|
|
amount->amount = (float)current->height * pct;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 23:25:21 +11:00
|
|
|
double old_width = current->width;
|
|
|
|
double old_height = current->height;
|
2019-01-14 22:22:53 +11:00
|
|
|
container_resize_tiled(current, axis, amount->amount);
|
2018-10-09 23:25:21 +11:00
|
|
|
if (current->width == old_width && current->height == old_height) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Cannot resize any further");
|
2018-09-29 17:05:55 +10:00
|
|
|
}
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
/**
|
|
|
|
* Implement `resize set` for a tiled container.
|
|
|
|
*/
|
|
|
|
static struct cmd_results *resize_set_tiled(struct sway_container *con,
|
|
|
|
struct resize_amount *width, struct resize_amount *height) {
|
2018-08-09 20:25:24 +10:00
|
|
|
if (width->amount) {
|
|
|
|
if (width->unit == RESIZE_UNIT_PPT ||
|
|
|
|
width->unit == RESIZE_UNIT_DEFAULT) {
|
|
|
|
// Convert to px
|
|
|
|
struct sway_container *parent = con->parent;
|
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
|
|
|
while (parent && parent->layout != L_HORIZ) {
|
2018-08-09 20:25:24 +10:00
|
|
|
parent = parent->parent;
|
|
|
|
}
|
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
|
|
|
if (parent) {
|
2018-08-09 20:25:24 +10:00
|
|
|
width->amount = parent->width * width->amount / 100;
|
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 {
|
|
|
|
width->amount = con->workspace->width * width->amount / 100;
|
2018-08-09 20:25:24 +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
|
|
|
width->unit = RESIZE_UNIT_PX;
|
2018-08-09 20:25:24 +10:00
|
|
|
}
|
|
|
|
if (width->unit == RESIZE_UNIT_PX) {
|
2019-01-14 22:22:53 +11:00
|
|
|
container_resize_tiled(con, AXIS_HORIZONTAL,
|
|
|
|
width->amount - con->width);
|
2018-08-09 20:25:24 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height->amount) {
|
|
|
|
if (height->unit == RESIZE_UNIT_PPT ||
|
|
|
|
height->unit == RESIZE_UNIT_DEFAULT) {
|
|
|
|
// Convert to px
|
|
|
|
struct sway_container *parent = con->parent;
|
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
|
|
|
while (parent && parent->layout != L_VERT) {
|
2018-08-09 20:25:24 +10:00
|
|
|
parent = parent->parent;
|
|
|
|
}
|
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
|
|
|
if (parent) {
|
2018-08-09 20:25:24 +10:00
|
|
|
height->amount = parent->height * height->amount / 100;
|
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 {
|
|
|
|
height->amount = con->workspace->height * height->amount / 100;
|
2018-08-09 20:25:24 +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
|
|
|
height->unit = RESIZE_UNIT_PX;
|
2018-08-09 20:25:24 +10:00
|
|
|
}
|
|
|
|
if (height->unit == RESIZE_UNIT_PX) {
|
2019-01-14 22:22:53 +11:00
|
|
|
container_resize_tiled(con, AXIS_VERTICAL,
|
|
|
|
height->amount - con->height);
|
2018-08-09 20:25:24 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-07-13 18:06:11 +10:00
|
|
|
}
|
2018-07-11 21:30:43 +10:00
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
/**
|
|
|
|
* Implement `resize set` for a floating container.
|
|
|
|
*/
|
|
|
|
static struct cmd_results *resize_set_floating(struct sway_container *con,
|
|
|
|
struct resize_amount *width, struct resize_amount *height) {
|
2018-11-17 22:23:06 +11:00
|
|
|
int min_width, max_width, min_height, max_height, grow_width = 0, grow_height = 0;
|
2018-07-14 10:00:22 +10:00
|
|
|
calculate_constraints(&min_width, &max_width, &min_height, &max_height);
|
2018-11-17 02:30:46 +11:00
|
|
|
|
|
|
|
if (width->amount) {
|
2018-11-25 20:03:04 +11:00
|
|
|
switch (width->unit) {
|
|
|
|
case RESIZE_UNIT_PPT:
|
2019-01-16 17:05:10 +11:00
|
|
|
if (con->scratchpad && !con->workspace) {
|
|
|
|
return cmd_results_new(CMD_FAILURE,
|
|
|
|
"Cannot resize a hidden scratchpad container by ppt");
|
|
|
|
}
|
2018-11-17 02:30:46 +11:00
|
|
|
// Convert to px
|
|
|
|
width->amount = con->workspace->width * width->amount / 100;
|
|
|
|
width->unit = RESIZE_UNIT_PX;
|
2018-11-25 20:03:04 +11:00
|
|
|
// Falls through
|
|
|
|
case RESIZE_UNIT_PX:
|
|
|
|
case RESIZE_UNIT_DEFAULT:
|
2018-11-17 02:30:46 +11:00
|
|
|
width->amount = fmax(min_width, fmin(width->amount, max_width));
|
|
|
|
grow_width = width->amount - con->width;
|
|
|
|
con->x -= grow_width / 2;
|
|
|
|
con->width = width->amount;
|
2018-11-25 23:16:45 +11:00
|
|
|
break;
|
2018-11-25 20:03:04 +11:00
|
|
|
case RESIZE_UNIT_INVALID:
|
2018-11-25 23:16:45 +11:00
|
|
|
sway_assert(false, "invalid width unit");
|
2018-11-25 20:03:04 +11:00
|
|
|
break;
|
2018-11-17 02:30:46 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height->amount) {
|
2018-11-25 20:03:04 +11:00
|
|
|
switch (height->unit) {
|
|
|
|
case RESIZE_UNIT_PPT:
|
2019-01-16 17:05:10 +11:00
|
|
|
if (con->scratchpad && !con->workspace) {
|
|
|
|
return cmd_results_new(CMD_FAILURE,
|
|
|
|
"Cannot resize a hidden scratchpad container by ppt");
|
|
|
|
}
|
2018-11-17 02:30:46 +11:00
|
|
|
// Convert to px
|
|
|
|
height->amount = con->workspace->height * height->amount / 100;
|
|
|
|
height->unit = RESIZE_UNIT_PX;
|
2018-11-25 20:03:04 +11:00
|
|
|
// Falls through
|
|
|
|
case RESIZE_UNIT_PX:
|
|
|
|
case RESIZE_UNIT_DEFAULT:
|
2018-11-17 02:30:46 +11:00
|
|
|
height->amount = fmax(min_height, fmin(height->amount, max_height));
|
|
|
|
grow_height = height->amount - con->height;
|
|
|
|
con->y -= grow_height / 2;
|
|
|
|
con->height = height->amount;
|
2018-11-25 23:16:45 +11:00
|
|
|
break;
|
2018-11-25 20:03:04 +11:00
|
|
|
case RESIZE_UNIT_INVALID:
|
2018-11-25 23:16:45 +11:00
|
|
|
sway_assert(false, "invalid height unit");
|
2018-11-25 20:03:04 +11:00
|
|
|
break;
|
2018-11-17 02:30:46 +11:00
|
|
|
}
|
|
|
|
}
|
2018-07-11 21:30:43 +10:00
|
|
|
|
Move view {x,y,width,height} into container struct
This renames/moves the following properties:
* sway_view.{x,y,width,height} ->
sway_container.content_{x,y,width,height}
* This is required to support placeholder containers as they don't
have a view.
* sway_container_state.view_{x,y,width,height} ->
sway_container_state.content_{x,y,width,height}
* To remain consistent with the above.
* sway_container_state.con_{x,y,width,height} ->
sway_container_state.{x,y,width,height}
* The con prefix was there to give it contrast from the view
properties, and is no longer useful.
The function container_set_geometry_from_floating_view has also been
renamed to container_set_geometry_from_content.
2018-11-17 19:32:03 +11:00
|
|
|
con->content_x -= grow_width / 2;
|
|
|
|
con->content_y -= grow_height / 2;
|
|
|
|
con->content_width += grow_width;
|
|
|
|
con->content_height += grow_height;
|
2018-07-11 21:30:43 +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
|
|
|
arrange_container(con);
|
2018-07-11 21:30:43 +10:00
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-07-11 21:30:43 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
/**
|
|
|
|
* resize set <args>
|
|
|
|
*
|
2018-11-09 06:17:49 +11:00
|
|
|
* args: [width] <width> [px|ppt]
|
|
|
|
* : height <height> [px|ppt]
|
|
|
|
* : [width] <width> [px|ppt] [height] <height> [px|ppt]
|
2018-07-13 18:06:11 +10:00
|
|
|
*/
|
|
|
|
static struct cmd_results *cmd_resize_set(int argc, char **argv) {
|
2018-05-03 23:04:09 +10:00
|
|
|
struct cmd_results *error;
|
2018-11-09 06:17:49 +11:00
|
|
|
if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 1))) {
|
2018-05-03 23:04:09 +10:00
|
|
|
return error;
|
|
|
|
}
|
2019-01-11 10:27:21 +11:00
|
|
|
const char usage[] = "Expected 'resize set [width] <width> [px|ppt]' or "
|
2018-11-09 06:17:49 +11:00
|
|
|
"'resize set height <height> [px|ppt]' or "
|
|
|
|
"'resize set [width] <width> [px|ppt] [height] <height> [px|ppt]'";
|
2018-05-03 23:04:09 +10:00
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
// Width
|
2018-11-09 06:17:49 +11:00
|
|
|
struct resize_amount width = {0};
|
|
|
|
if (argc >= 2 && !strcmp(argv[0], "width") && strcmp(argv[1], "height")) {
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
if (strcmp(argv[0], "height")) {
|
|
|
|
int num_consumed_args = parse_resize_amount(argc, argv, &width);
|
|
|
|
argc -= num_consumed_args;
|
|
|
|
argv += num_consumed_args;
|
|
|
|
if (width.unit == RESIZE_UNIT_INVALID) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
2018-11-09 06:17:49 +11:00
|
|
|
}
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
// Height
|
2018-11-09 06:17:49 +11:00
|
|
|
struct resize_amount height = {0};
|
|
|
|
if (argc) {
|
|
|
|
if (argc >= 2 && !strcmp(argv[0], "height")) {
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
int num_consumed_args = parse_resize_amount(argc, argv, &height);
|
2019-01-23 02:07:38 +11:00
|
|
|
if (argc > num_consumed_args) {
|
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
|
|
|
}
|
2018-11-09 06:17:49 +11:00
|
|
|
if (width.unit == RESIZE_UNIT_INVALID) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
2018-11-09 06:17:49 +11:00
|
|
|
}
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
// If 0, don't resize that dimension
|
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 *con = config->handler_context.container;
|
2018-07-13 18:06:11 +10:00
|
|
|
if (width.amount <= 0) {
|
|
|
|
width.amount = con->width;
|
|
|
|
}
|
|
|
|
if (height.amount <= 0) {
|
|
|
|
height.amount = con->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (container_is_floating(con)) {
|
|
|
|
return resize_set_floating(con, &width, &height);
|
|
|
|
}
|
|
|
|
return resize_set_tiled(con, &width, &height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* resize <grow|shrink> <args>
|
|
|
|
*
|
|
|
|
* args: <direction>
|
|
|
|
* args: <direction> <amount> <unit>
|
|
|
|
* args: <direction> <amount> <unit> or <amount> <other_unit>
|
|
|
|
*/
|
|
|
|
static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
|
|
|
|
int multiplier) {
|
2019-01-11 10:27:21 +11:00
|
|
|
const char usage[] = "Expected 'resize grow|shrink <direction> "
|
2018-07-13 18:06:11 +10:00
|
|
|
"[<amount> px|ppt [or <amount> px|ppt]]'";
|
2019-01-14 21:10:49 +11:00
|
|
|
uint32_t axis = parse_resize_axis(*argv);
|
2019-01-14 20:03:32 +11:00
|
|
|
if (axis == WLR_EDGE_NONE) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
--argc; ++argv;
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
// First amount
|
|
|
|
struct resize_amount first_amount;
|
2018-04-05 11:32:31 +10:00
|
|
|
if (argc) {
|
2018-07-13 18:06:11 +10:00
|
|
|
int num_consumed_args = parse_resize_amount(argc, argv, &first_amount);
|
|
|
|
argc -= num_consumed_args;
|
|
|
|
argv += num_consumed_args;
|
|
|
|
if (first_amount.unit == RESIZE_UNIT_INVALID) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
2018-07-13 18:06:11 +10:00
|
|
|
} else {
|
|
|
|
first_amount.amount = 10;
|
|
|
|
first_amount.unit = RESIZE_UNIT_DEFAULT;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
// "or"
|
2018-04-05 11:32:31 +10:00
|
|
|
if (argc) {
|
2018-07-13 18:06:11 +10:00
|
|
|
if (strcmp(*argv, "or") != 0) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
--argc; ++argv;
|
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
// Second amount
|
|
|
|
struct resize_amount second_amount;
|
2018-04-05 11:32:31 +10:00
|
|
|
if (argc) {
|
2018-07-13 18:06:11 +10:00
|
|
|
int num_consumed_args = parse_resize_amount(argc, argv, &second_amount);
|
2019-01-23 02:07:38 +11:00
|
|
|
if (argc > num_consumed_args) {
|
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
|
|
|
}
|
2018-07-13 18:06:11 +10:00
|
|
|
if (second_amount.unit == RESIZE_UNIT_INVALID) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
2018-07-13 18:06:11 +10:00
|
|
|
}
|
|
|
|
} else {
|
2019-01-23 02:07:38 +11:00
|
|
|
second_amount.amount = 0;
|
2018-07-13 18:06:11 +10:00
|
|
|
second_amount.unit = RESIZE_UNIT_INVALID;
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|
|
|
|
|
2018-07-13 18:06:11 +10:00
|
|
|
first_amount.amount *= multiplier;
|
|
|
|
second_amount.amount *= multiplier;
|
|
|
|
|
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 *con = config->handler_context.container;
|
2018-07-13 18:06:11 +10:00
|
|
|
if (container_is_floating(con)) {
|
|
|
|
// Floating containers can only resize in px. Choose an amount which
|
|
|
|
// uses px, with fallback to an amount that specified no unit.
|
|
|
|
if (first_amount.unit == RESIZE_UNIT_PX) {
|
|
|
|
return resize_adjust_floating(axis, &first_amount);
|
|
|
|
} else if (second_amount.unit == RESIZE_UNIT_PX) {
|
|
|
|
return resize_adjust_floating(axis, &second_amount);
|
|
|
|
} else if (first_amount.unit == RESIZE_UNIT_DEFAULT) {
|
|
|
|
return resize_adjust_floating(axis, &first_amount);
|
|
|
|
} else if (second_amount.unit == RESIZE_UNIT_DEFAULT) {
|
|
|
|
return resize_adjust_floating(axis, &second_amount);
|
|
|
|
} else {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID,
|
2018-07-13 18:06:11 +10:00
|
|
|
"Floating containers cannot use ppt measurements");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For tiling, prefer ppt -> default -> px
|
|
|
|
if (first_amount.unit == RESIZE_UNIT_PPT) {
|
|
|
|
return resize_adjust_tiled(axis, &first_amount);
|
|
|
|
} else if (second_amount.unit == RESIZE_UNIT_PPT) {
|
|
|
|
return resize_adjust_tiled(axis, &second_amount);
|
|
|
|
} else if (first_amount.unit == RESIZE_UNIT_DEFAULT) {
|
|
|
|
return resize_adjust_tiled(axis, &first_amount);
|
|
|
|
} else if (second_amount.unit == RESIZE_UNIT_DEFAULT) {
|
|
|
|
return resize_adjust_tiled(axis, &second_amount);
|
|
|
|
} else {
|
|
|
|
return resize_adjust_tiled(axis, &first_amount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_results *cmd_resize(int argc, char **argv) {
|
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.");
|
|
|
|
}
|
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-07-13 18:06:11 +10:00
|
|
|
if (!current) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Cannot resize nothing");
|
2018-07-13 18:06:11 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_results *error;
|
|
|
|
if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(argv[0], "set") == 0) {
|
|
|
|
return cmd_resize_set(argc - 1, &argv[1]);
|
|
|
|
}
|
|
|
|
if (strcasecmp(argv[0], "grow") == 0) {
|
|
|
|
return cmd_resize_adjust(argc - 1, &argv[1], 1);
|
|
|
|
}
|
|
|
|
if (strcasecmp(argv[0], "shrink") == 0) {
|
|
|
|
return cmd_resize_adjust(argc - 1, &argv[1], -1);
|
|
|
|
}
|
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
const char usage[] = "Expected 'resize <shrink|grow> "
|
2018-07-13 18:06:11 +10:00
|
|
|
"<width|height|up|down|left|right> [<amount>] [px|ppt]'";
|
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, usage);
|
2018-04-05 11:32:31 +10:00
|
|
|
}
|