From 4c688cba4e3528921656d63a09f7015cae13cd0c Mon Sep 17 00:00:00 2001 From: KoffeinFlummi Date: Tue, 18 Aug 2015 23:53:57 +0200 Subject: [PATCH] Add support for gaps option --- include/config.h | 3 +++ include/container.h | 2 ++ sway/commands.c | 40 ++++++++++++++++++++++++++++++++++++++++ sway/config.c | 2 ++ sway/container.c | 10 ++++++++-- sway/layout.c | 16 ++++++++-------- 6 files changed, 63 insertions(+), 10 deletions(-) diff --git a/include/config.h b/include/config.h index 9243bf351..c47eb6831 100644 --- a/include/config.h +++ b/include/config.h @@ -41,6 +41,9 @@ struct sway_config { bool active; bool failed; bool reloading; + + int gaps_inner; + int gaps_outer; }; bool load_config(void); diff --git a/include/container.h b/include/container.h index 186ee8b6b..6d64b4909 100644 --- a/include/container.h +++ b/include/container.h @@ -48,6 +48,8 @@ struct sway_container { char *name; + int gaps; + list_t *children; list_t *floating; diff --git a/sway/commands.c b/sway/commands.c index 51de7a50c..f716efa35 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -281,6 +282,44 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * return true; } +static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { + if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { + return false; + } + + if (argc == 1) { + char *end; + int amount = (int)strtol(argv[0], &end, 10); + if (errno == ERANGE || amount == 0) { + errno = 0; + return false; + } + if (config->gaps_inner == 0) { + config->gaps_inner = amount; + } + if (config->gaps_outer == 0) { + config->gaps_outer = amount; + } + } else if (argc == 2) { + char *end; + int amount = (int)strtol(argv[1], &end, 10); + if (errno == ERANGE || amount == 0) { + errno = 0; + return false; + } + if (strcmp(argv[0], "inner") == 0) { + config->gaps_inner = amount; + } else if (strcmp(argv[0], "outer") == 0) { + config->gaps_outer = amount; + } else { + return false; + } + } else { + return false; + } + return true; +} + static bool cmd_kill(struct sway_config *config, int argc, char **argv) { swayc_t *view = get_focused_container(&root_container); wlc_view_close(view->handle); @@ -484,6 +523,7 @@ static struct cmd_handler handlers[] = { { "focus", cmd_focus }, { "focus_follows_mouse", cmd_focus_follows_mouse }, { "fullscreen", cmd_fullscreen }, + { "gaps", cmd_gaps }, { "kill", cmd_kill }, { "layout", cmd_layout }, { "log_colors", cmd_log_colors }, diff --git a/sway/config.c b/sway/config.c index 6d39839da..b0b663151 100644 --- a/sway/config.c +++ b/sway/config.c @@ -170,6 +170,8 @@ void config_defaults(struct sway_config *config) { config->reloading = false; config->active = false; config->failed = false; + config->gaps_inner = 0; + config->gaps_outer = 0; } bool read_config(FILE *file, bool is_active) { diff --git a/sway/container.c b/sway/container.c index e679e8235..68511156a 100644 --- a/sway/container.c +++ b/sway/container.c @@ -43,8 +43,10 @@ swayc_t *new_output(wlc_handle handle) { sway_log(L_DEBUG, "Added output %lu:%s", handle, name); swayc_t *output = new_swayc(C_OUTPUT); - output->width = size->w; - output->height = size->h; + output->x = (config->gaps_outer + config->gaps_inner) / 2; + output->y = (config->gaps_outer + config->gaps_inner) / 2; + output->width = size->w - (config->gaps_outer + config->gaps_inner); + output->height = size->h - (config->gaps_outer + config->gaps_inner); output->handle = handle; output->name = name ? strdup(name) : NULL; @@ -81,6 +83,8 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { swayc_t *workspace = new_swayc(C_WORKSPACE); workspace->layout = L_HORIZ; // TODO: default layout + workspace->x = output->x; + workspace->y = output->y; workspace->width = output->width; workspace->height = output->height; workspace->name = strdup(name); @@ -143,6 +147,8 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { view->visible = true; view->is_focused = true; + view->gaps = config->gaps_inner; + view->desired_width = -1; view->desired_height = -1; diff --git a/sway/layout.c b/sway/layout.c index e2ea46a70..737477f7c 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -133,12 +133,12 @@ void arrange_windows(swayc_t *container, int width, int height) { { struct wlc_geometry geometry = { .origin = { - .x = container->x, - .y = container->y + .x = container->x + container->gaps / 2, + .y = container->y + container->gaps / 2 }, .size = { - .w = width, - .h = height + .w = width - container->gaps, + .h = height - container->gaps } }; if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { @@ -146,10 +146,10 @@ void arrange_windows(swayc_t *container, int width, int height) { while (parent->type != C_OUTPUT) { parent = parent->parent; } - geometry.origin.x = 0; - geometry.origin.y = 0; - geometry.size.w = parent->width; - geometry.size.h = parent->height; + geometry.origin.x = container->gaps / 2; + geometry.origin.y = container->gaps / 2; + geometry.size.w = parent->width - container->gaps; + geometry.size.h = parent->height - container->gaps; wlc_view_set_geometry(container->handle, &geometry); wlc_view_bring_to_front(container->handle); } else {