aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dwyer <ryandwyer1@gmail.com>2018-09-04 20:00:04 +1000
committerRyan Dwyer <ryandwyer1@gmail.com>2018-09-04 20:00:04 +1000
commit7797490e9e285589f501e46202df36b6bf8afcfd (patch)
tree9e581c403ef8b99df78bddb7e54be856ada4514e
parent6dd3e0caf574ab9c328025489d3ea605fcdd7fc8 (diff)
downloadsway-7797490e9e285589f501e46202df36b6bf8afcfd.tar.xz
Deny repeating reload by holding key
Fixes #2568 The binding that gets stored in the keyboard's `repeat_binding` would get freed on reload, leaving a dangling pointer. Rather than attempt to unset the keyboard's `repeat_binding` along with the other bindings, I opted to just not set it for the reload command because there's no point in reloading repeatedly by holding the binding. This disables repeat bindings for the reload command. As we now need to detect whether it's a reload command in two places, I've added a binding flag to track whether it's a reload or not.
-rw-r--r--include/sway/config.h9
-rw-r--r--sway/commands/bind.c9
-rw-r--r--sway/input/keyboard.c5
3 files changed, 14 insertions, 9 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index 4ee8c3c2..6024f0f6 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -31,10 +31,11 @@ enum binding_input_type {
enum binding_flags {
BINDING_RELEASE=1,
- BINDING_LOCKED=2, // keyboard only
- BINDING_BORDER=4, // mouse only; trigger on container border
- BINDING_CONTENTS=8, // mouse only; trigger on container contents
- BINDING_TITLEBAR=16 // mouse only; trigger on container titlebar
+ BINDING_LOCKED=2, // keyboard only
+ BINDING_BORDER=4, // mouse only; trigger on container border
+ BINDING_CONTENTS=8, // mouse only; trigger on container contents
+ BINDING_TITLEBAR=16, // mouse only; trigger on container titlebar
+ BINDING_RELOAD=32, // the binding runs the reload command
};
/**
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index b134c92f..5b56ba30 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -214,6 +214,9 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
}
binding->command = join_args(argv + 1, argc - 1);
+ if (strcasestr(binding->command, "reload")) {
+ binding->flags |= BINDING_RELOAD;
+ }
list_t *split = split_string(argv[0], "+");
for (int i = 0; i < split->length; ++i) {
@@ -307,11 +310,9 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding)
binding->command);
struct sway_binding *binding_copy = binding;
- bool reload = false;
// if this is a reload command we need to make a duplicate of the
// binding since it will be gone after the reload has completed.
- if (strcasestr(binding->command, "reload")) {
- reload = true;
+ if (binding->flags & BINDING_RELOAD) {
binding_copy = sway_binding_dup(binding);
if (!binding_copy) {
wlr_log(WLR_ERROR, "Failed to duplicate binding during reload");
@@ -328,7 +329,7 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding)
binding->command, results->error);
}
- if (reload) { // free the binding if we made a copy
+ if (binding->flags & BINDING_RELOAD) { // free the binding if we made a copy
free_sway_binding(binding_copy);
}
free_cmd_results(results);
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 160ef10b..0d2a62b5 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -280,7 +280,10 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) {
if (binding_pressed) {
seat_execute_command(seat, binding_pressed);
handled = true;
- next_repeat_binding = binding_pressed;
+
+ if ((binding_pressed->flags & BINDING_RELOAD) == 0) {
+ next_repeat_binding = binding_pressed;
+ }
}
}