aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-07-11 18:51:07 +0100
committerGitHub <noreply@github.com>2018-07-11 18:51:07 +0100
commit588abbb128c17430b8af1a26b4a3f01bbd5852e5 (patch)
tree693908491b4b01cd5589dc4e8adc49726c87fef1 /sway/commands
parent73084c5fa6d9fd7693e4dd5b369e79667ba8dfbe (diff)
parentf2d1cf3ceb9ca7198aba89245fafad42f16edb8e (diff)
Merge pull request #2245 from RyanDwyer/floating-minmax-size
Implement floating_minimum_size and floating_maximum_size
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/floating_minmax_size.c53
1 files changed, 53 insertions, 0 deletions
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 @@
+#include <errno.h>
+#include <math.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <wlr/util/log.h>
+#include "sway/commands.h"
+#include "log.h"
+
+static const char* min_usage =
+ "Expected 'floating_minimum_size <width> x <height>'";
+
+static const char* max_usage =
+ "Expected 'floating_maximum_size <width> x <height>'";
+
+static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name,
+ const char *usage, int *config_width, int *config_height) {
+ struct cmd_results *error;
+ if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 3))) {
+ return error;
+ }
+
+ char *err;
+ int width = (int)strtol(argv[0], &err, 10);
+ if (*err) {
+ return cmd_results_new(CMD_INVALID, cmd_name, usage);
+ }
+
+ if (strcmp(argv[1], "x") != 0) {
+ return cmd_results_new(CMD_INVALID, cmd_name, usage);
+ }
+
+ int height = (int)strtol(argv[2], &err, 10);
+ if (*err) {
+ return cmd_results_new(CMD_INVALID, cmd_name, usage);
+ }
+
+ *config_width = width;
+ *config_height = height;
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) {
+ return handle_command(argc, argv, "floating_minimum_size", min_usage,
+ &config->floating_minimum_width, &config->floating_minimum_height);
+}
+
+struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) {
+ return handle_command(argc, argv, "floating_maximum_size", max_usage,
+ &config->floating_maximum_width, &config->floating_maximum_height);
+}