summaryrefslogtreecommitdiffstats
path: root/sway/commands/bind.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/bind.c')
-rw-r--r--sway/commands/bind.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index 01a35cf2..5990166a 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -1,4 +1,5 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <libevdev/libevdev.h>
2#ifdef __linux__ 3#ifdef __linux__
3#include <linux/input-event-codes.h> 4#include <linux/input-event-codes.h>
4#elif __FreeBSD__ 5#elif __FreeBSD__
@@ -10,6 +11,7 @@
10#include <strings.h> 11#include <strings.h>
11#include "sway/commands.h" 12#include "sway/commands.h"
12#include "sway/config.h" 13#include "sway/config.h"
14#include "sway/input/cursor.h"
13#include "sway/ipc-server.h" 15#include "sway/ipc-server.h"
14#include "list.h" 16#include "list.h"
15#include "log.h" 17#include "log.h"
@@ -102,9 +104,26 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
102 104
103 // Check for mouse binding 105 // Check for mouse binding
104 uint32_t button = 0; 106 uint32_t button = 0;
105 if (strncasecmp(name, "button", strlen("button")) == 0 && 107 if (strncasecmp(name, "button", strlen("button")) == 0) {
106 strlen(name) == strlen("button0")) { 108 // Map to x11 mouse buttons
107 button = name[strlen("button")] - '1' + BTN_LEFT; 109 button = name[strlen("button")] - '0';
110 if (button < 1 || button > 9 || strlen(name) > strlen("button0")) {
111 return cmd_results_new(CMD_INVALID, "bindsym",
112 "Only buttons 1-9 are supported. For other mouse "
113 "buttons, use the name of the event code.");
114 }
115 uint32_t buttons[] = {BTN_LEFT, BTN_MIDDLE, BTN_RIGHT,
116 SWAY_SCROLL_UP, SWAY_SCROLL_DOWN, SWAY_SCROLL_LEFT,
117 SWAY_SCROLL_RIGHT, BTN_SIDE, BTN_EXTRA};
118 button = buttons[button - 1];
119 } else if (strncmp(name, "BTN_", strlen("BTN_")) == 0) {
120 // Get event code
121 int code = libevdev_event_code_from_name(EV_KEY, name);
122 if (code == -1) {
123 return cmd_results_new(CMD_INVALID, "bindsym",
124 "Invalid event code name %s", name);
125 }
126 button = code;
108 } 127 }
109 128
110 if (*type == BINDING_KEYSYM) { 129 if (*type == BINDING_KEYSYM) {