mirror of
https://github.com/swaywm/sway.git
synced 2025-11-11 13:29:51 -05:00
basic split containers
This commit is contained in:
parent
122b96abed
commit
7706d83160
10 changed files with 245 additions and 51 deletions
|
|
@ -3,21 +3,30 @@
|
|||
#include "sway/input/input-manager.h"
|
||||
#include "sway/input/seat.h"
|
||||
#include "sway/tree/view.h"
|
||||
#include "sway/tree/container.h"
|
||||
#include "sway/commands.h"
|
||||
|
||||
struct cmd_results *cmd_kill(int argc, char **argv) {
|
||||
enum sway_container_type type = config->handler_context.current_container->type;
|
||||
if (type != C_VIEW && type != C_CONTAINER) {
|
||||
struct sway_container *con =
|
||||
config->handler_context.current_container;
|
||||
|
||||
switch (con->type) {
|
||||
case C_ROOT:
|
||||
case C_OUTPUT:
|
||||
case C_WORKSPACE:
|
||||
return cmd_results_new(CMD_INVALID, NULL,
|
||||
"Can only kill views and containers with this command");
|
||||
}
|
||||
|
||||
// TODO close arbitrary containers without a view
|
||||
struct sway_view *view =
|
||||
config->handler_context.current_container->sway_view;
|
||||
|
||||
if (view) {
|
||||
view_close(view);
|
||||
break;
|
||||
case C_CONTAINER:
|
||||
con = container_destroy(con);
|
||||
con = container_reap_empty(con);
|
||||
arrange_windows(con, -1, -1);
|
||||
break;
|
||||
case C_VIEW:
|
||||
view_close(con->sway_view);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
|
|
|
|||
107
sway/commands/split.c
Normal file
107
sway/commands/split.c
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "sway/tree/container.h"
|
||||
#include "sway/tree/layout.h"
|
||||
#include "sway/tree/view.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/input/seat.h"
|
||||
#include "log.h"
|
||||
|
||||
static struct cmd_results *_do_split(int argc, char **argv, int layout) {
|
||||
char *name = layout == L_VERT ? "splitv" :
|
||||
layout == L_HORIZ ? "splith" : "split";
|
||||
struct cmd_results *error = NULL;
|
||||
if (config->reading) {
|
||||
return cmd_results_new(CMD_FAILURE, name,
|
||||
"Can't be used in config file.");
|
||||
}
|
||||
if (!config->active) {
|
||||
return cmd_results_new(CMD_FAILURE, name,
|
||||
"Can only be used when sway is running.");
|
||||
}
|
||||
if ((error = checkarg(argc, name, EXPECTED_EQUAL_TO, 0))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
struct sway_container *focused = config->handler_context.current_container;
|
||||
|
||||
// TODO floating: dont split
|
||||
|
||||
/* Case that focus is on an workspace with 0/1 children.change its layout */
|
||||
if (focused->type == C_WORKSPACE && focused->children->length <= 1) {
|
||||
wlr_log(L_DEBUG, "changing workspace layout");
|
||||
container_set_layout(focused, layout);
|
||||
} else if (focused->type != C_WORKSPACE &&
|
||||
focused->parent->children->length == 1) {
|
||||
/* Case of no siblings. change parent layout */
|
||||
wlr_log(L_DEBUG, "changing container layout");
|
||||
container_set_layout(focused->parent, layout);
|
||||
} else {
|
||||
// regular case where new split container is build around focused
|
||||
// container or in case of workspace, container inherits its children
|
||||
wlr_log(L_DEBUG,
|
||||
"Adding new container around current focused container");
|
||||
wlr_log(L_INFO, "FOCUSED SIZE: %.f %.f",
|
||||
focused->width, focused->height);
|
||||
|
||||
struct sway_container *parent = container_split(focused, layout);
|
||||
arrange_windows(parent, -1, -1);
|
||||
}
|
||||
|
||||
// TODO borders: update borders
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
struct cmd_results *cmd_split(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if (config->reading) {
|
||||
return cmd_results_new(CMD_FAILURE, "split",
|
||||
"Can't be used in config file.");
|
||||
}
|
||||
if (!config->active) {
|
||||
return cmd_results_new(CMD_FAILURE, "split",
|
||||
"Can only be used when sway is running.");
|
||||
}
|
||||
if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
|
||||
_do_split(argc - 1, argv + 1, L_VERT);
|
||||
} else if (strcasecmp(argv[0], "h") == 0 ||
|
||||
strcasecmp(argv[0], "horizontal") == 0) {
|
||||
_do_split(argc - 1, argv + 1, L_HORIZ);
|
||||
} else if (strcasecmp(argv[0], "t") == 0 ||
|
||||
strcasecmp(argv[0], "toggle") == 0) {
|
||||
struct sway_container *focused =
|
||||
config->handler_context.current_container;
|
||||
if (focused->parent->layout == L_VERT) {
|
||||
_do_split(argc - 1, argv + 1, L_HORIZ);
|
||||
} else {
|
||||
_do_split(argc - 1, argv + 1, L_VERT);
|
||||
}
|
||||
} else {
|
||||
error = cmd_results_new(CMD_FAILURE, "split",
|
||||
"Invalid split command (expected either horizontal or vertical).");
|
||||
return error;
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
struct cmd_results *cmd_splitv(int argc, char **argv) {
|
||||
return _do_split(argc, argv, L_VERT);
|
||||
}
|
||||
|
||||
struct cmd_results *cmd_splith(int argc, char **argv) {
|
||||
return _do_split(argc, argv, L_HORIZ);
|
||||
}
|
||||
|
||||
struct cmd_results *cmd_splitt(int argc, char **argv) {
|
||||
struct sway_container *focused = config->handler_context.current_container;
|
||||
if (focused->parent->layout == L_VERT) {
|
||||
return _do_split(argc, argv, L_HORIZ);
|
||||
} else {
|
||||
return _do_split(argc, argv, L_VERT);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue