mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 00:16:22 +01:00
Merge pull request #73 from KoffeinFlummi/gaps
Add support for gaps option
This commit is contained in:
commit
446d593b4c
6 changed files with 63 additions and 10 deletions
|
@ -41,6 +41,9 @@ struct sway_config {
|
||||||
bool active;
|
bool active;
|
||||||
bool failed;
|
bool failed;
|
||||||
bool reloading;
|
bool reloading;
|
||||||
|
|
||||||
|
int gaps_inner;
|
||||||
|
int gaps_outer;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool load_config(void);
|
bool load_config(void);
|
||||||
|
|
|
@ -48,6 +48,8 @@ struct sway_container {
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
|
int gaps;
|
||||||
|
|
||||||
list_t *children;
|
list_t *children;
|
||||||
list_t *floating;
|
list_t *floating;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -281,6 +282,44 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char *
|
||||||
return true;
|
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) {
|
static bool cmd_kill(struct sway_config *config, int argc, char **argv) {
|
||||||
swayc_t *view = get_focused_container(&root_container);
|
swayc_t *view = get_focused_container(&root_container);
|
||||||
wlc_view_close(view->handle);
|
wlc_view_close(view->handle);
|
||||||
|
@ -484,6 +523,7 @@ static struct cmd_handler handlers[] = {
|
||||||
{ "focus", cmd_focus },
|
{ "focus", cmd_focus },
|
||||||
{ "focus_follows_mouse", cmd_focus_follows_mouse },
|
{ "focus_follows_mouse", cmd_focus_follows_mouse },
|
||||||
{ "fullscreen", cmd_fullscreen },
|
{ "fullscreen", cmd_fullscreen },
|
||||||
|
{ "gaps", cmd_gaps },
|
||||||
{ "kill", cmd_kill },
|
{ "kill", cmd_kill },
|
||||||
{ "layout", cmd_layout },
|
{ "layout", cmd_layout },
|
||||||
{ "log_colors", cmd_log_colors },
|
{ "log_colors", cmd_log_colors },
|
||||||
|
|
|
@ -170,6 +170,8 @@ void config_defaults(struct sway_config *config) {
|
||||||
config->reloading = false;
|
config->reloading = false;
|
||||||
config->active = false;
|
config->active = false;
|
||||||
config->failed = false;
|
config->failed = false;
|
||||||
|
config->gaps_inner = 0;
|
||||||
|
config->gaps_outer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_config(FILE *file, bool is_active) {
|
bool read_config(FILE *file, bool is_active) {
|
||||||
|
|
|
@ -63,8 +63,10 @@ swayc_t *new_output(wlc_handle handle) {
|
||||||
sway_log(L_DEBUG, "Added output %lu:%s", handle, name);
|
sway_log(L_DEBUG, "Added output %lu:%s", handle, name);
|
||||||
|
|
||||||
swayc_t *output = new_swayc(C_OUTPUT);
|
swayc_t *output = new_swayc(C_OUTPUT);
|
||||||
output->width = size->w;
|
output->x = (config->gaps_outer + config->gaps_inner) / 2;
|
||||||
output->height = size->h;
|
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->handle = handle;
|
||||||
output->name = name ? strdup(name) : NULL;
|
output->name = name ? strdup(name) : NULL;
|
||||||
|
|
||||||
|
@ -105,6 +107,8 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
|
||||||
swayc_t *workspace = new_swayc(C_WORKSPACE);
|
swayc_t *workspace = new_swayc(C_WORKSPACE);
|
||||||
|
|
||||||
workspace->layout = L_HORIZ; // TODO: default layout
|
workspace->layout = L_HORIZ; // TODO: default layout
|
||||||
|
workspace->x = output->x;
|
||||||
|
workspace->y = output->y;
|
||||||
workspace->width = output->width;
|
workspace->width = output->width;
|
||||||
workspace->height = output->height;
|
workspace->height = output->height;
|
||||||
workspace->name = strdup(name);
|
workspace->name = strdup(name);
|
||||||
|
@ -167,6 +171,8 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
|
||||||
view->visible = true;
|
view->visible = true;
|
||||||
view->is_focused = true;
|
view->is_focused = true;
|
||||||
|
|
||||||
|
view->gaps = config->gaps_inner;
|
||||||
|
|
||||||
view->desired_width = -1;
|
view->desired_width = -1;
|
||||||
view->desired_height = -1;
|
view->desired_height = -1;
|
||||||
|
|
||||||
|
|
|
@ -135,12 +135,12 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
{
|
{
|
||||||
struct wlc_geometry geometry = {
|
struct wlc_geometry geometry = {
|
||||||
.origin = {
|
.origin = {
|
||||||
.x = container->x,
|
.x = container->x + container->gaps / 2,
|
||||||
.y = container->y
|
.y = container->y + container->gaps / 2
|
||||||
},
|
},
|
||||||
.size = {
|
.size = {
|
||||||
.w = width,
|
.w = width - container->gaps,
|
||||||
.h = height
|
.h = height - container->gaps
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) {
|
if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) {
|
||||||
|
@ -148,10 +148,10 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
while (parent->type != C_OUTPUT) {
|
while (parent->type != C_OUTPUT) {
|
||||||
parent = parent->parent;
|
parent = parent->parent;
|
||||||
}
|
}
|
||||||
geometry.origin.x = 0;
|
geometry.origin.x = container->gaps / 2;
|
||||||
geometry.origin.y = 0;
|
geometry.origin.y = container->gaps / 2;
|
||||||
geometry.size.w = parent->width;
|
geometry.size.w = parent->width - container->gaps;
|
||||||
geometry.size.h = parent->height;
|
geometry.size.h = parent->height - container->gaps;
|
||||||
wlc_view_set_geometry(container->handle, 0, &geometry);
|
wlc_view_set_geometry(container->handle, 0, &geometry);
|
||||||
wlc_view_bring_to_front(container->handle);
|
wlc_view_bring_to_front(container->handle);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue