aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/bar.c2
-rw-r--r--sway/commands/bar/status_edge_padding.c21
-rw-r--r--sway/commands/bar/status_padding.c21
-rw-r--r--sway/commands/bind.c126
-rw-r--r--sway/commands/input/events.c76
5 files changed, 194 insertions, 52 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index 507ee10a..3e7c1b0f 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -23,6 +23,8 @@ static struct cmd_handler bar_handlers[] = {
{ "position", bar_cmd_position },
{ "separator_symbol", bar_cmd_separator_symbol },
{ "status_command", bar_cmd_status_command },
+ { "status_edge_padding", bar_cmd_status_edge_padding },
+ { "status_padding", bar_cmd_status_padding },
{ "strip_workspace_name", bar_cmd_strip_workspace_name },
{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
{ "tray_bindsym", bar_cmd_tray_bindsym },
diff --git a/sway/commands/bar/status_edge_padding.c b/sway/commands/bar/status_edge_padding.c
new file mode 100644
index 00000000..f3b10631
--- /dev/null
+++ b/sway/commands/bar/status_edge_padding.c
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_status_edge_padding(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "status_edge_padding", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ char *end;
+ int padding = strtol(argv[0], &end, 10);
+ if (strlen(end) || padding < 0) {
+ return cmd_results_new(CMD_INVALID, "status_edge_padding",
+ "Padding must be a positive integer");
+ }
+ config->current_bar->status_edge_padding = padding;
+ wlr_log(WLR_DEBUG, "Status edge padding on bar %s: %d",
+ config->current_bar->id, config->current_bar->status_edge_padding);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/status_padding.c b/sway/commands/bar/status_padding.c
new file mode 100644
index 00000000..13b8eb6b
--- /dev/null
+++ b/sway/commands/bar/status_padding.c
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_status_padding(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "status_padding", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ char *end;
+ int padding = strtol(argv[0], &end, 10);
+ if (strlen(end) || padding < 0) {
+ return cmd_results_new(CMD_INVALID, "status_padding",
+ "Padding must be a positive integer");
+ }
+ config->current_bar->status_padding = padding;
+ wlr_log(WLR_DEBUG, "Status padding on bar %s: %d",
+ config->current_bar->id, config->current_bar->status_padding);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index 4fceaf8c..be47d412 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -85,69 +85,91 @@ static int key_qsort_cmp(const void *keyp_a, const void *keyp_b) {
*/
static struct cmd_results *identify_key(const char* name, bool first_key,
uint32_t* key_val, enum binding_input_type* type) {
- if (*type == BINDING_KEYCODE) {
- // check for keycode
- xkb_keycode_t keycode = strtol(name, NULL, 10);
- if (!xkb_keycode_is_legal_ext(keycode)) {
- return cmd_results_new(CMD_INVALID, "bindcode",
- "Invalid keycode '%s'", name);
+ if (*type == BINDING_MOUSECODE) {
+ // check for mouse bindcodes
+ char *message = NULL;
+ uint32_t button = get_mouse_bindcode(name, &message);
+ if (!button) {
+ if (message) {
+ struct cmd_results *error =
+ cmd_results_new(CMD_INVALID, "bindcode", message);
+ free(message);
+ return error;
+ } else {
+ return cmd_results_new(CMD_INVALID, "bindcode",
+ "Unknown button code %s", name);
+ }
}
- *key_val = keycode;
- } else {
- // check for keysym
- xkb_keysym_t keysym = xkb_keysym_from_name(name,
- XKB_KEYSYM_CASE_INSENSITIVE);
-
- // Check for mouse binding
- uint32_t button = 0;
- if (strncasecmp(name, "button", strlen("button")) == 0) {
- // Map to x11 mouse buttons
- button = name[strlen("button")] - '0';
- if (button < 1 || button > 9 || strlen(name) > strlen("button0")) {
+ *key_val = button;
+ } else if (*type == BINDING_MOUSESYM) {
+ // check for mouse bindsyms (x11 buttons or event names)
+ char *message = NULL;
+ uint32_t button = get_mouse_bindsym(name, &message);
+ if (!button) {
+ if (message) {
+ struct cmd_results *error =
+ cmd_results_new(CMD_INVALID, "bindsym", message);
+ free(message);
+ return error;
+ } else if (!button) {
return cmd_results_new(CMD_INVALID, "bindsym",
- "Only buttons 1-9 are supported. For other mouse "
- "buttons, use the name of the event code.");
+ "Unknown button %s", name);
}
- uint32_t buttons[] = {BTN_LEFT, BTN_MIDDLE, BTN_RIGHT,
- SWAY_SCROLL_UP, SWAY_SCROLL_DOWN, SWAY_SCROLL_LEFT,
- SWAY_SCROLL_RIGHT, BTN_SIDE, BTN_EXTRA};
- button = buttons[button - 1];
- } else if (strncmp(name, "BTN_", strlen("BTN_")) == 0) {
- // Get event code
- int code = libevdev_event_code_from_name(EV_KEY, name);
- if (code == -1) {
- return cmd_results_new(CMD_INVALID, "bindsym",
- "Invalid event code name %s", name);
+ }
+ *key_val = button;
+ } else if (*type == BINDING_KEYCODE) {
+ // check for keycode. If it is the first key, allow mouse bindcodes
+ if (first_key) {
+ char *message = NULL;
+ uint32_t button = get_mouse_bindcode(name, &message);
+ free(message);
+ if (button) {
+ *type = BINDING_MOUSECODE;
+ *key_val = button;
+ return NULL;
}
- button = code;
}
- if (*type == BINDING_KEYSYM) {
- if (button) {
- if (first_key) {
- *type = BINDING_MOUSE;
- *key_val = button;
- } else {
- return cmd_results_new(CMD_INVALID, "bindsym",
- "Mixed button '%s' into key sequence", name);
- }
- } else if (keysym) {
- *key_val = keysym;
+ xkb_keycode_t keycode = strtol(name, NULL, 10);
+ if (!xkb_keycode_is_legal_ext(keycode)) {
+ if (first_key) {
+ return cmd_results_new(CMD_INVALID, "bindcode",
+ "Invalid keycode or button code '%s'", name);
} else {
- return cmd_results_new(CMD_INVALID, "bindsym",
- "Unknown key '%s'", name);
+ return cmd_results_new(CMD_INVALID, "bindcode",
+ "Invalid keycode '%s'", name);
}
- } else {
- if (button) {
+ }
+ *key_val = keycode;
+ } else {
+ // check for keysym. If it is the first key, allow mouse bindsyms
+ if (first_key) {
+ char *message = NULL;
+ uint32_t button = get_mouse_bindsym(name, &message);
+ if (message) {
+ struct cmd_results *error =
+ cmd_results_new(CMD_INVALID, "bindsym", message);
+ free(message);
+ return error;
+ } else if (button) {
+ *type = BINDING_MOUSESYM;
*key_val = button;
- } else if (keysym) {
+ return NULL;
+ }
+ }
+
+ xkb_keysym_t keysym = xkb_keysym_from_name(name,
+ XKB_KEYSYM_CASE_INSENSITIVE);
+ if (!keysym) {
+ if (first_key) {
return cmd_results_new(CMD_INVALID, "bindsym",
- "Mixed keysym '%s' into button sequence", name);
+ "Unknown key or button '%s'", name);
} else {
return cmd_results_new(CMD_INVALID, "bindsym",
- "Unknown button '%s'", name);
+ "Unknown key '%s'", name);
}
}
+ *key_val = keysym;
}
return NULL;
}
@@ -201,7 +223,8 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
}
if (binding->flags & (BINDING_BORDER | BINDING_CONTENTS | BINDING_TITLEBAR)
|| exclude_titlebar) {
- binding->type = BINDING_MOUSE;
+ binding->type = binding->type == BINDING_KEYCODE ?
+ BINDING_MOUSECODE : BINDING_MOUSESYM;
}
if (argc < 2) {
@@ -249,7 +272,8 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
// that this is one
if (exclude_titlebar) {
binding->flags &= ~BINDING_TITLEBAR;
- } else if (binding->type == BINDING_MOUSE) {
+ } else if (binding->type == BINDING_MOUSECODE
+ || binding->type == BINDING_MOUSESYM) {
binding->flags |= BINDING_TITLEBAR;
}
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c
index e7ed69c6..69f46269 100644
--- a/sway/commands/input/events.c
+++ b/sway/commands/input/events.c
@@ -1,10 +1,69 @@
+#include <limits.h>
#include <string.h>
#include <strings.h>
+#include <wlr/backend/libinput.h>
#include "sway/config.h"
#include "sway/commands.h"
#include "sway/input/input-manager.h"
#include "log.h"
+static void toggle_send_events_for_device(struct input_config *ic,
+ struct sway_input_device *input_device) {
+ struct wlr_input_device *wlr_device = input_device->wlr_device;
+ if (!wlr_input_device_is_libinput(wlr_device)) {
+ return;
+ }
+ struct libinput_device *libinput_dev
+ = wlr_libinput_get_device_handle(wlr_device);
+
+ enum libinput_config_send_events_mode mode =
+ libinput_device_config_send_events_get_mode(libinput_dev);
+ uint32_t possible =
+ libinput_device_config_send_events_get_modes(libinput_dev);
+
+ switch (mode) {
+ case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
+ mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
+ if (possible & mode) {
+ break;
+ }
+ // fall through
+ case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
+ mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
+ if (possible & mode) {
+ break;
+ }
+ // fall through
+ case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
+ default:
+ mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
+ break;
+ }
+
+ ic->send_events = mode;
+}
+
+static void toggle_send_events(struct input_config *ic) {
+ struct sway_input_device *input_device = NULL;
+ wl_list_for_each(input_device, &server.input->devices, link) {
+ if (strcmp(input_device->identifier, ic->identifier) == 0) {
+ toggle_send_events_for_device(ic, input_device);
+ }
+ }
+}
+
+static void toggle_wildcard_send_events() {
+ struct sway_input_device *input_device = NULL;
+ wl_list_for_each(input_device, &server.input->devices, link) {
+ struct input_config *ic = new_input_config(input_device->identifier);
+ if (!ic) {
+ break;
+ }
+ toggle_send_events_for_device(ic, input_device);
+ store_input_config(ic);
+ }
+}
+
struct cmd_results *input_cmd_events(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) {
@@ -23,9 +82,24 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {
} else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) {
ic->send_events =
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
- } else {
+ } else if (config->reading) {
return cmd_results_new(CMD_INVALID, "events",
"Expected 'events <enabled|disabled|disabled_on_external_mouse>'");
+ } else if (strcasecmp(argv[0], "toggle") == 0) {
+ if (strcmp(ic->identifier, "*") == 0) {
+ // Update the device input configs and then reset the wildcard
+ // config send events mode so that is does not override the device
+ // ones. The device ones will be applied when attempting to apply
+ // the wildcard config
+ toggle_wildcard_send_events();
+ ic->send_events = INT_MIN;
+ } else {
+ toggle_send_events(ic);
+ }
+ } else {
+ return cmd_results_new(CMD_INVALID, "events",
+ "Expected 'events <enabled|disabled|disabled_on_external_mouse|"
+ "toggle>'");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);