aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosip Janzic <josip@jjanzic.com>2017-05-04 22:42:50 +0200
committerJosip Janzic <josip@jjanzic.com>2017-05-04 23:00:03 +0200
commit400998d6d2bf311f3402faf092154ee8ceac2bf9 (patch)
tree9d157c846bb7081c657e683284ae7510a9db9ccb
parent02d1ae7e27e1183abbf3d16acd87fcd5ec370e26 (diff)
downloadsway-400998d6d2bf311f3402faf092154ee8ceac2bf9.zip
sway-400998d6d2bf311f3402faf092154ee8ceac2bf9.tar.gz
sway-400998d6d2bf311f3402faf092154ee8ceac2bf9.tar.bz2
Add mouse button bindings
Adds support for bindings like: bindsym button3 floating toggle bindsym $mod+button3 floating toggle
-rw-r--r--sway/commands/bind.c8
-rw-r--r--sway/handlers.c20
2 files changed, 28 insertions, 0 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index 8282277..af5a01e 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -1,7 +1,9 @@
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-names.h>
+#include <strings.h>
#include "sway/commands.h"
#include "sway/config.h"
+#include "sway/input_state.h"
#include "list.h"
#include "log.h"
#include "stringop.h"
@@ -52,6 +54,12 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) {
// Check for xkb key
xkb_keysym_t sym = xkb_keysym_from_name(split->items[i],
XKB_KEYSYM_CASE_INSENSITIVE);
+
+ // Check for mouse binding
+ if (strncasecmp(split->items[i], "button", strlen("button")) == 0 &&
+ strlen(split->items[i]) == strlen("button0")) {
+ sym = ((char *)split->items[i])[strlen("button")] - '1' + M_LEFT_CLICK;
+ }
if (!sym) {
free_sway_binding(binding);
free_flat_list(split);
diff --git a/sway/handlers.c b/sway/handlers.c
index da765d6..e1b90a0 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -917,6 +917,26 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
// Update view pointer is on
pointer_state.view = container_under_pointer();
+ struct sway_mode *mode = config->current_mode;
+ // handle bindings
+ for (int i = 0; i < mode->bindings->length; ++i) {
+ struct sway_binding *binding = mode->bindings->items[i];
+ if ((modifiers->mods ^ binding->modifiers) == 0) {
+ switch (state) {
+ case WLC_BUTTON_STATE_PRESSED: {
+ if (!binding->release && handle_bindsym(binding, button, 0)) {
+ return EVENT_HANDLED;
+ }
+ }
+ case WLC_BUTTON_STATE_RELEASED:
+ if (binding->release && handle_bindsym(binding, button, 0)) {
+ return EVENT_HANDLED;
+ }
+ break;
+ }
+ }
+ }
+
// Update pointer_state
switch (button) {
case M_LEFT_CLICK: