aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-11 22:16:48 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-11 22:16:48 +1000
commitf2d1cf3ceb9ca7198aba89245fafad42f16edb8e (patch)
tree693908491b4b01cd5589dc4e8adc49726c87fef1 /sway
parentMerge pull request #2243 from RyanDwyer/use-fullscreen-saved-buffer (diff)
downloadsway-f2d1cf3ceb9ca7198aba89245fafad42f16edb8e.tar.gz
sway-f2d1cf3ceb9ca7198aba89245fafad42f16edb8e.tar.zst
sway-f2d1cf3ceb9ca7198aba89245fafad42f16edb8e.zip
Implement floating_minimum_size and floating_maximum_size
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c4
-rw-r--r--sway/commands/floating_minmax_size.c53
-rw-r--r--sway/meson.build1
-rw-r--r--sway/tree/view.c43
4 files changed, 94 insertions, 7 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 6c5bea37..addd64a6 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -100,6 +100,8 @@ static struct cmd_handler handlers[] = {
100 { "default_border", cmd_default_border }, 100 { "default_border", cmd_default_border },
101 { "exec", cmd_exec }, 101 { "exec", cmd_exec },
102 { "exec_always", cmd_exec_always }, 102 { "exec_always", cmd_exec_always },
103 { "floating_maximum_size", cmd_floating_maximum_size },
104 { "floating_minimum_size", cmd_floating_minimum_size },
103 { "focus_follows_mouse", cmd_focus_follows_mouse }, 105 { "focus_follows_mouse", cmd_focus_follows_mouse },
104 { "focus_wrapping", cmd_focus_wrapping }, 106 { "focus_wrapping", cmd_focus_wrapping },
105 { "font", cmd_font }, 107 { "font", cmd_font },
@@ -344,7 +346,7 @@ struct cmd_results *config_command(char *exec) {
344 346
345 // Start block 347 // Start block
346 if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) { 348 if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) {
347 char *block = join_args(argv, argc - 1); 349 char *block = join_args(argv, argc - 1);
348 results = cmd_results_new(CMD_BLOCK, block, NULL); 350 results = cmd_results_new(CMD_BLOCK, block, NULL);
349 free(block); 351 free(block);
350 goto cleanup; 352 goto cleanup;
diff --git a/sway/commands/floating_minmax_size.c b/sway/commands/floating_minmax_size.c
new file mode 100644
index 00000000..0af78908
--- /dev/null
+++ b/sway/commands/floating_minmax_size.c
@@ -0,0 +1,53 @@
1#include <errno.h>
2#include <math.h>
3#include <stdbool.h>
4#include <stdlib.h>
5#include <string.h>
6#include <strings.h>
7#include <wlr/util/log.h>
8#include "sway/commands.h"
9#include "log.h"
10
11static const char* min_usage =
12 "Expected 'floating_minimum_size <width> x <height>'";
13
14static const char* max_usage =
15 "Expected 'floating_maximum_size <width> x <height>'";
16
17static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name,
18 const char *usage, int *config_width, int *config_height) {
19 struct cmd_results *error;
20 if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 3))) {
21 return error;
22 }
23
24 char *err;
25 int width = (int)strtol(argv[0], &err, 10);
26 if (*err) {
27 return cmd_results_new(CMD_INVALID, cmd_name, usage);
28 }
29
30 if (strcmp(argv[1], "x") != 0) {
31 return cmd_results_new(CMD_INVALID, cmd_name, usage);
32 }
33
34 int height = (int)strtol(argv[2], &err, 10);
35 if (*err) {
36 return cmd_results_new(CMD_INVALID, cmd_name, usage);
37 }
38
39 *config_width = width;
40 *config_height = height;
41
42 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
43}
44
45struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) {
46 return handle_command(argc, argv, "floating_minimum_size", min_usage,
47 &config->floating_minimum_width, &config->floating_minimum_height);
48}
49
50struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) {
51 return handle_command(argc, argv, "floating_maximum_size", max_usage,
52 &config->floating_maximum_width, &config->floating_maximum_height);
53}
diff --git a/sway/meson.build b/sway/meson.build
index e492aeee..72192917 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -40,6 +40,7 @@ sway_sources = files(
40 'commands/exec.c', 40 'commands/exec.c',
41 'commands/exec_always.c', 41 'commands/exec_always.c',
42 'commands/floating.c', 42 'commands/floating.c',
43 'commands/floating_minmax_size.c',
43 'commands/focus.c', 44 'commands/focus.c',
44 'commands/focus_follows_mouse.c', 45 'commands/focus_follows_mouse.c',
45 'commands/focus_wrapping.c', 46 'commands/focus_wrapping.c',
diff --git a/sway/tree/view.c b/sway/tree/view.c
index c96b6a97..f99def6c 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -150,12 +150,43 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
150 150
151void view_init_floating(struct sway_view *view) { 151void view_init_floating(struct sway_view *view) {
152 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 152 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
153 int max_width = ws->width * 0.6666; 153 int min_width, min_height;
154 int max_height = ws->height * 0.6666; 154 int max_width, max_height;
155 view->width = 155
156 view->natural_width > max_width ? max_width : view->natural_width; 156 if (config->floating_minimum_width == -1) { // no minimum
157 view->height = 157 min_width = 0;
158 view->natural_height > max_height ? max_height : view->natural_height; 158 } else if (config->floating_minimum_width == 0) { // automatic
159 min_width = 75;
160 } else {
161 min_width = config->floating_minimum_width;
162 }
163
164 if (config->floating_minimum_height == -1) { // no minimum
165 min_height = 0;
166 } else if (config->floating_minimum_height == 0) { // automatic
167 min_height = 50;
168 } else {
169 min_height = config->floating_minimum_height;
170 }
171
172 if (config->floating_maximum_width == -1) { // no maximum
173 max_width = INT_MAX;
174 } else if (config->floating_maximum_width == 0) { // automatic
175 max_width = ws->width * 0.6666;
176 } else {
177 max_width = config->floating_maximum_width;
178 }
179
180 if (config->floating_maximum_height == -1) { // no maximum
181 max_height = INT_MAX;
182 } else if (config->floating_maximum_height == 0) { // automatic
183 max_height = ws->height * 0.6666;
184 } else {
185 max_height = config->floating_maximum_height;
186 }
187
188 view->width = fmax(min_width, fmin(view->natural_width, max_width));
189 view->height = fmax(min_height, fmin(view->natural_height, max_height));
159 view->x = ws->x + (ws->width - view->width) / 2; 190 view->x = ws->x + (ws->width - view->width) / 2;
160 view->y = ws->y + (ws->height - view->height) / 2; 191 view->y = ws->y + (ws->height - view->height) / 2;
161 192