diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-18 18:07:51 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-18 18:07:51 -0400 |
commit | 446d593b4ca5cf4ea5bbf9eaafe8a6f3521b4189 (patch) | |
tree | 97279d1259c4e049a74af4efa3e4b2334a6cae74 | |
parent | Fix indented comments being weird (diff) | |
parent | Merge remote-tracking branch 'upstream/master' into gaps (diff) | |
download | sway-446d593b4ca5cf4ea5bbf9eaafe8a6f3521b4189.tar.gz sway-446d593b4ca5cf4ea5bbf9eaafe8a6f3521b4189.tar.zst sway-446d593b4ca5cf4ea5bbf9eaafe8a6f3521b4189.zip |
Merge pull request #73 from KoffeinFlummi/gaps
Add support for gaps option
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | include/container.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 40 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/container.c | 10 | ||||
-rw-r--r-- | sway/layout.c | 16 |
6 files changed, 63 insertions, 10 deletions
diff --git a/include/config.h b/include/config.h index 9243bf35..c47eb683 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -41,6 +41,9 @@ struct sway_config { | |||
41 | bool active; | 41 | bool active; |
42 | bool failed; | 42 | bool failed; |
43 | bool reloading; | 43 | bool reloading; |
44 | |||
45 | int gaps_inner; | ||
46 | int gaps_outer; | ||
44 | }; | 47 | }; |
45 | 48 | ||
46 | bool load_config(void); | 49 | bool load_config(void); |
diff --git a/include/container.h b/include/container.h index 186ee8b6..6d64b490 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -48,6 +48,8 @@ struct sway_container { | |||
48 | 48 | ||
49 | char *name; | 49 | char *name; |
50 | 50 | ||
51 | int gaps; | ||
52 | |||
51 | list_t *children; | 53 | list_t *children; |
52 | list_t *floating; | 54 | list_t *floating; |
53 | 55 | ||
diff --git a/sway/commands.c b/sway/commands.c index 6c3efb3b..54839322 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <errno.h> | ||
6 | #include <string.h> | 7 | #include <string.h> |
7 | #include <unistd.h> | 8 | #include <unistd.h> |
8 | #include <ctype.h> | 9 | #include <ctype.h> |
@@ -281,6 +282,44 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * | |||
281 | return true; | 282 | return true; |
282 | } | 283 | } |
283 | 284 | ||
285 | static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { | ||
286 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { | ||
287 | return false; | ||
288 | } | ||
289 | |||
290 | if (argc == 1) { | ||
291 | char *end; | ||
292 | int amount = (int)strtol(argv[0], &end, 10); | ||
293 | if (errno == ERANGE || amount == 0) { | ||
294 | errno = 0; | ||
295 | return false; | ||
296 | } | ||
297 | if (config->gaps_inner == 0) { | ||
298 | config->gaps_inner = amount; | ||
299 | } | ||
300 | if (config->gaps_outer == 0) { | ||
301 | config->gaps_outer = amount; | ||
302 | } | ||
303 | } else if (argc == 2) { | ||
304 | char *end; | ||
305 | int amount = (int)strtol(argv[1], &end, 10); | ||
306 | if (errno == ERANGE || amount == 0) { | ||
307 | errno = 0; | ||
308 | return false; | ||
309 | } | ||
310 | if (strcmp(argv[0], "inner") == 0) { | ||
311 | config->gaps_inner = amount; | ||
312 | } else if (strcmp(argv[0], "outer") == 0) { | ||
313 | config->gaps_outer = amount; | ||
314 | } else { | ||
315 | return false; | ||
316 | } | ||
317 | } else { | ||
318 | return false; | ||
319 | } | ||
320 | return true; | ||
321 | } | ||
322 | |||
284 | static bool cmd_kill(struct sway_config *config, int argc, char **argv) { | 323 | static bool cmd_kill(struct sway_config *config, int argc, char **argv) { |
285 | swayc_t *view = get_focused_container(&root_container); | 324 | swayc_t *view = get_focused_container(&root_container); |
286 | wlc_view_close(view->handle); | 325 | wlc_view_close(view->handle); |
@@ -484,6 +523,7 @@ static struct cmd_handler handlers[] = { | |||
484 | { "focus", cmd_focus }, | 523 | { "focus", cmd_focus }, |
485 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | 524 | { "focus_follows_mouse", cmd_focus_follows_mouse }, |
486 | { "fullscreen", cmd_fullscreen }, | 525 | { "fullscreen", cmd_fullscreen }, |
526 | { "gaps", cmd_gaps }, | ||
487 | { "kill", cmd_kill }, | 527 | { "kill", cmd_kill }, |
488 | { "layout", cmd_layout }, | 528 | { "layout", cmd_layout }, |
489 | { "log_colors", cmd_log_colors }, | 529 | { "log_colors", cmd_log_colors }, |
diff --git a/sway/config.c b/sway/config.c index d4871bab..637e2dbc 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -170,6 +170,8 @@ void config_defaults(struct sway_config *config) { | |||
170 | config->reloading = false; | 170 | config->reloading = false; |
171 | config->active = false; | 171 | config->active = false; |
172 | config->failed = false; | 172 | config->failed = false; |
173 | config->gaps_inner = 0; | ||
174 | config->gaps_outer = 0; | ||
173 | } | 175 | } |
174 | 176 | ||
175 | bool read_config(FILE *file, bool is_active) { | 177 | bool read_config(FILE *file, bool is_active) { |
diff --git a/sway/container.c b/sway/container.c index 62c5bda0..06111674 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -63,8 +63,10 @@ swayc_t *new_output(wlc_handle handle) { | |||
63 | sway_log(L_DEBUG, "Added output %lu:%s", handle, name); | 63 | sway_log(L_DEBUG, "Added output %lu:%s", handle, name); |
64 | 64 | ||
65 | swayc_t *output = new_swayc(C_OUTPUT); | 65 | swayc_t *output = new_swayc(C_OUTPUT); |
66 | output->width = size->w; | 66 | output->x = (config->gaps_outer + config->gaps_inner) / 2; |
67 | output->height = size->h; | 67 | output->y = (config->gaps_outer + config->gaps_inner) / 2; |
68 | output->width = size->w - (config->gaps_outer + config->gaps_inner); | ||
69 | output->height = size->h - (config->gaps_outer + config->gaps_inner); | ||
68 | output->handle = handle; | 70 | output->handle = handle; |
69 | output->name = name ? strdup(name) : NULL; | 71 | output->name = name ? strdup(name) : NULL; |
70 | 72 | ||
@@ -105,6 +107,8 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
105 | swayc_t *workspace = new_swayc(C_WORKSPACE); | 107 | swayc_t *workspace = new_swayc(C_WORKSPACE); |
106 | 108 | ||
107 | workspace->layout = L_HORIZ; // TODO: default layout | 109 | workspace->layout = L_HORIZ; // TODO: default layout |
110 | workspace->x = output->x; | ||
111 | workspace->y = output->y; | ||
108 | workspace->width = output->width; | 112 | workspace->width = output->width; |
109 | workspace->height = output->height; | 113 | workspace->height = output->height; |
110 | workspace->name = strdup(name); | 114 | workspace->name = strdup(name); |
@@ -167,6 +171,8 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
167 | view->visible = true; | 171 | view->visible = true; |
168 | view->is_focused = true; | 172 | view->is_focused = true; |
169 | 173 | ||
174 | view->gaps = config->gaps_inner; | ||
175 | |||
170 | view->desired_width = -1; | 176 | view->desired_width = -1; |
171 | view->desired_height = -1; | 177 | view->desired_height = -1; |
172 | 178 | ||
diff --git a/sway/layout.c b/sway/layout.c index a6a241f4..02c92026 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -135,12 +135,12 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
135 | { | 135 | { |
136 | struct wlc_geometry geometry = { | 136 | struct wlc_geometry geometry = { |
137 | .origin = { | 137 | .origin = { |
138 | .x = container->x, | 138 | .x = container->x + container->gaps / 2, |
139 | .y = container->y | 139 | .y = container->y + container->gaps / 2 |
140 | }, | 140 | }, |
141 | .size = { | 141 | .size = { |
142 | .w = width, | 142 | .w = width - container->gaps, |
143 | .h = height | 143 | .h = height - container->gaps |
144 | } | 144 | } |
145 | }; | 145 | }; |
146 | if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { | 146 | if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { |
@@ -148,10 +148,10 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
148 | while (parent->type != C_OUTPUT) { | 148 | while (parent->type != C_OUTPUT) { |
149 | parent = parent->parent; | 149 | parent = parent->parent; |
150 | } | 150 | } |
151 | geometry.origin.x = 0; | 151 | geometry.origin.x = container->gaps / 2; |
152 | geometry.origin.y = 0; | 152 | geometry.origin.y = container->gaps / 2; |
153 | geometry.size.w = parent->width; | 153 | geometry.size.w = parent->width - container->gaps; |
154 | geometry.size.h = parent->height; | 154 | geometry.size.h = parent->height - container->gaps; |
155 | wlc_view_set_geometry(container->handle, 0, &geometry); | 155 | wlc_view_set_geometry(container->handle, 0, &geometry); |
156 | wlc_view_bring_to_front(container->handle); | 156 | wlc_view_bring_to_front(container->handle); |
157 | } else { | 157 | } else { |