aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-01-22 01:16:23 +0100
committerGitHub <noreply@github.com>2018-01-22 01:16:23 +0100
commit0c58673c6a108ba241419a0f1d5fecd47f22370e (patch)
treec3e19af6dd70f04fc5c617e932b4afcc7a1b41d9 /sway/commands
parenta6bc46eea9d7dec6a2b93f85bac2e3737e0c6725 (diff)
parentbeb3805cf0300bc2640290233aa763d757c12466 (diff)
Merge pull request #1574 from acrisci/config-refactor
Command criteria
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/input.c31
-rw-r--r--sway/commands/input/accel_profile.c2
-rw-r--r--sway/commands/input/click_method.c4
-rw-r--r--sway/commands/input/drag_lock.c2
-rw-r--r--sway/commands/input/dwt.c2
-rw-r--r--sway/commands/input/events.c6
-rw-r--r--sway/commands/input/left_handed.c2
-rw-r--r--sway/commands/input/middle_emulation.c2
-rw-r--r--sway/commands/input/natural_scroll.c2
-rw-r--r--sway/commands/input/pointer_accel.c2
-rw-r--r--sway/commands/input/scroll_method.c2
-rw-r--r--sway/commands/input/tap.c3
-rw-r--r--sway/commands/input/xkb_layout.c3
-rw-r--r--sway/commands/input/xkb_model.c3
-rw-r--r--sway/commands/input/xkb_options.c3
-rw-r--r--sway/commands/input/xkb_rules.c3
-rw-r--r--sway/commands/input/xkb_variant.c3
-rw-r--r--sway/commands/kill.c28
-rw-r--r--sway/commands/seat.c25
-rw-r--r--sway/commands/seat/attach.c2
-rw-r--r--sway/commands/seat/fallback.c3
21 files changed, 110 insertions, 23 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c
index 5ea39f62..fa9cf05a 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -11,8 +11,12 @@ struct cmd_results *cmd_input(int argc, char **argv) {
}
if (config->reading && strcmp("{", argv[1]) == 0) {
- current_input_config = new_input_config(argv[0]);
- wlr_log(L_DEBUG, "entering input block: %s", current_input_config->identifier);
+ free_input_config(config->handler_context.input_config);
+ config->handler_context.input_config = new_input_config(argv[0]);
+ if (!config->handler_context.input_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
+ }
+ wlr_log(L_DEBUG, "entering input block: %s", argv[0]);
return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL);
}
@@ -20,15 +24,19 @@ struct cmd_results *cmd_input(int argc, char **argv) {
return error;
}
+ bool has_context = (config->handler_context.input_config != NULL);
+ if (!has_context) {
+ // caller did not give a context so create one just for this command
+ config->handler_context.input_config = new_input_config(argv[0]);
+ if (!config->handler_context.input_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
+ }
+ }
+
int argc_new = argc-2;
char **argv_new = argv+2;
struct cmd_results *res;
- struct input_config *old_input_config = current_input_config;
- current_input_config = new_input_config(argv[0]);
- if (!current_input_config) {
- return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
- }
if (strcasecmp("accel_profile", argv[1]) == 0) {
res = input_cmd_accel_profile(argc_new, argv_new);
} else if (strcasecmp("click_method", argv[1]) == 0) {
@@ -64,7 +72,12 @@ struct cmd_results *cmd_input(int argc, char **argv) {
} else {
res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]);
}
- free_input_config(current_input_config);
- current_input_config = old_input_config;
+
+ if (!has_context) {
+ // clean up the context we created earlier
+ free_input_config(config->handler_context.input_config);
+ config->handler_context.input_config = NULL;
+ }
+
return res;
}
diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c
index f72b7d48..37d6e133 100644
--- a/sway/commands/input/accel_profile.c
+++ b/sway/commands/input/accel_profile.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) {
if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "accel_profile",
"No input device defined.");
diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c
index 22eb15f7..8f1f0aa7 100644
--- a/sway/commands/input/click_method.c
+++ b/sway/commands/input/click_method.c
@@ -6,12 +6,12 @@
#include "log.h"
struct cmd_results *input_cmd_click_method(int argc, char **argv) {
- wlr_log(L_DEBUG, "click_method for device: %d %s",
- current_input_config==NULL, current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "click_method",
"No input device defined.");
diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c
index 1783978a..8273a7d4 100644
--- a/sway/commands/input/drag_lock.c
+++ b/sway/commands/input/drag_lock.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE,
"drag_lock", "No input device defined.");
diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c
index 8108a110..995a2f47 100644
--- a/sway/commands/input/dwt.c
+++ b/sway/commands/input/dwt.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) {
if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined.");
}
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c
index a1bfbacd..2217f5ce 100644
--- a/sway/commands/input/events.c
+++ b/sway/commands/input/events.c
@@ -6,16 +6,18 @@
#include "log.h"
struct cmd_results *input_cmd_events(int argc, char **argv) {
- wlr_log(L_DEBUG, "events for device: %s",
- current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "events",
"No input device defined.");
}
+ wlr_log(L_DEBUG, "events for device: %s",
+ current_input_config->identifier);
struct input_config *new_config =
new_input_config(current_input_config->identifier);
diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c
index 35740df3..94b8e03e 100644
--- a/sway/commands/input/left_handed.c
+++ b/sway/commands/input/left_handed.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) {
if ((error = checkarg(argc, "left_handed", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "left_handed",
"No input device defined.");
diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c
index 7bc08ae6..a551fd51 100644
--- a/sway/commands/input/middle_emulation.c
+++ b/sway/commands/input/middle_emulation.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "middle_emulation",
"No input device defined.");
diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c
index a7dcdc2c..c4e19b78 100644
--- a/sway/commands/input/natural_scroll.c
+++ b/sway/commands/input/natural_scroll.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "natural_scoll",
"No input device defined.");
diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c
index d2261a63..171063aa 100644
--- a/sway/commands/input/pointer_accel.c
+++ b/sway/commands/input/pointer_accel.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) {
if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE,
"pointer_accel", "No input device defined.");
diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c
index 035262cf..0a1c57ac 100644
--- a/sway/commands/input/scroll_method.c
+++ b/sway/commands/input/scroll_method.c
@@ -9,6 +9,8 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) {
if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "scroll_method",
"No input device defined.");
diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c
index ecab9a5b..e7f03058 100644
--- a/sway/commands/input/tap.c
+++ b/sway/commands/input/tap.c
@@ -6,11 +6,12 @@
#include "log.h"
struct cmd_results *input_cmd_tap(int argc, char **argv) {
- wlr_log(L_DEBUG, "tap for device: %s", current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "tap", "No input device defined.");
}
diff --git a/sway/commands/input/xkb_layout.c b/sway/commands/input/xkb_layout.c
index 25db1a33..867e65d3 100644
--- a/sway/commands/input/xkb_layout.c
+++ b/sway/commands/input/xkb_layout.c
@@ -5,11 +5,12 @@
#include "log.h"
struct cmd_results *input_cmd_xkb_layout(int argc, char **argv) {
- wlr_log(L_DEBUG, "xkb layout for device: %s", current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "xkb_layout", EXPECTED_EQUAL_TO, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "xkb_layout", "No input device defined.");
}
diff --git a/sway/commands/input/xkb_model.c b/sway/commands/input/xkb_model.c
index 819b796b..e8c8e04e 100644
--- a/sway/commands/input/xkb_model.c
+++ b/sway/commands/input/xkb_model.c
@@ -5,11 +5,12 @@
#include "log.h"
struct cmd_results *input_cmd_xkb_model(int argc, char **argv) {
- wlr_log(L_DEBUG, "xkb model for device: %s", current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "xkb_model", EXPECTED_EQUAL_TO, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "xkb_model", "No input device defined.");
}
diff --git a/sway/commands/input/xkb_options.c b/sway/commands/input/xkb_options.c
index ff5f83ec..e9ddd6e3 100644
--- a/sway/commands/input/xkb_options.c
+++ b/sway/commands/input/xkb_options.c
@@ -5,11 +5,12 @@
#include "log.h"
struct cmd_results *input_cmd_xkb_options(int argc, char **argv) {
- wlr_log(L_DEBUG, "xkb options for device: %s", current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "xkb_options", EXPECTED_EQUAL_TO, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "xkb_options", "No input device defined.");
}
diff --git a/sway/commands/input/xkb_rules.c b/sway/commands/input/xkb_rules.c
index aafe0003..926d0ac1 100644
--- a/sway/commands/input/xkb_rules.c
+++ b/sway/commands/input/xkb_rules.c
@@ -5,11 +5,12 @@
#include "log.h"
struct cmd_results *input_cmd_xkb_rules(int argc, char **argv) {
- wlr_log(L_DEBUG, "xkb rules for device: %s", current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "xkb_rules", EXPECTED_EQUAL_TO, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "xkb_rules", "No input device defined.");
}
diff --git a/sway/commands/input/xkb_variant.c b/sway/commands/input/xkb_variant.c
index 89a61fdc..0e3ffd41 100644
--- a/sway/commands/input/xkb_variant.c
+++ b/sway/commands/input/xkb_variant.c
@@ -5,11 +5,12 @@
#include "log.h"
struct cmd_results *input_cmd_xkb_variant(int argc, char **argv) {
- wlr_log(L_DEBUG, "xkb variant for device: %s", current_input_config->identifier);
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "xkb_variant", EXPECTED_EQUAL_TO, 1))) {
return error;
}
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
if (!current_input_config) {
return cmd_results_new(CMD_FAILURE, "xkb_variant", "No input device defined.");
}
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
new file mode 100644
index 00000000..3804f0b0
--- /dev/null
+++ b/sway/commands/kill.c
@@ -0,0 +1,28 @@
+#include <wlr/util/log.h>
+#include "log.h"
+#include "sway/input/input-manager.h"
+#include "sway/input/seat.h"
+#include "sway/view.h"
+#include "sway/commands.h"
+
+struct cmd_results *cmd_kill(int argc, char **argv) {
+ if (config->reading) {
+ return cmd_results_new(CMD_FAILURE, "kill",
+ "Command 'kill' cannot be used in the config file");
+ }
+ if (!sway_assert(config->handler_context.current_container,
+ "cmd_kill called without container context")) {
+ return cmd_results_new(CMD_INVALID, NULL,
+ "cmd_kill called without container context "
+ "(this is a bug in sway)");
+ }
+ // TODO close arbitrary containers without a view
+ struct sway_view *view =
+ config->handler_context.current_container->sway_view;
+
+ if (view) {
+ view_close(view);
+ }
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index 6284002b..45079616 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -11,8 +11,12 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
}
if (config->reading && strcmp("{", argv[1]) == 0) {
- current_seat_config = new_seat_config(argv[0]);
- wlr_log(L_DEBUG, "entering seat block: %s", current_seat_config->name);
+ free_seat_config(config->handler_context.seat_config);
+ config->handler_context.seat_config = new_seat_config(argv[0]);
+ if (!config->handler_context.seat_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
+ }
+ wlr_log(L_DEBUG, "entering seat block: %s", argv[0]);
return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL);
}
@@ -20,11 +24,18 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
return error;
}
+ bool has_context = (config->handler_context.seat_config != NULL);
+ if (!has_context) {
+ config->handler_context.seat_config = new_seat_config(argv[0]);
+ if (!config->handler_context.seat_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
+ }
+ }
+
int argc_new = argc-2;
char **argv_new = argv+2;
struct cmd_results *res;
- current_seat_config = new_seat_config(argv[0]);
if (strcasecmp("attach", argv[1]) == 0) {
res = seat_cmd_attach(argc_new, argv_new);
} else if (strcasecmp("fallback", argv[1]) == 0) {
@@ -32,6 +43,12 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
} else {
res = cmd_results_new(CMD_INVALID, "seat <name>", "Unknown command %s", argv[1]);
}
- current_seat_config = NULL;
+
+ if (!has_context) {
+ // clean up the context we created earlier
+ free_seat_config(config->handler_context.seat_config);
+ config->handler_context.seat_config = NULL;
+ }
+
return res;
}
diff --git a/sway/commands/seat/attach.c b/sway/commands/seat/attach.c
index 80ec63ce..3e771c00 100644
--- a/sway/commands/seat/attach.c
+++ b/sway/commands/seat/attach.c
@@ -12,6 +12,8 @@ struct cmd_results *seat_cmd_attach(int argc, char **argv) {
if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct seat_config *current_seat_config =
+ config->handler_context.seat_config;
if (!current_seat_config) {
return cmd_results_new(CMD_FAILURE, "attach", "No seat defined");
}
diff --git a/sway/commands/seat/fallback.c b/sway/commands/seat/fallback.c
index 7c129aae..56feaab5 100644
--- a/sway/commands/seat/fallback.c
+++ b/sway/commands/seat/fallback.c
@@ -9,6 +9,8 @@ struct cmd_results *seat_cmd_fallback(int argc, char **argv) {
if ((error = checkarg(argc, "fallback", EXPECTED_AT_LEAST, 1))) {
return error;
}
+ struct seat_config *current_seat_config =
+ config->handler_context.seat_config;
if (!current_seat_config) {
return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined");
}
@@ -20,6 +22,7 @@ struct cmd_results *seat_cmd_fallback(int argc, char **argv) {
} else if (strcasecmp(argv[0], "false") == 0) {
new_config->fallback = 0;
} else {
+ free_seat_config(new_config);
return cmd_results_new(CMD_INVALID, "fallback",
"Expected 'fallback <true|false>'");
}