aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Josip Janzic <josip@jjanzic.com>2017-05-04 22:42:50 +0200
committerLibravatar Josip Janzic <josip@jjanzic.com>2017-05-04 23:00:03 +0200
commit400998d6d2bf311f3402faf092154ee8ceac2bf9 (patch)
tree9d157c846bb7081c657e683284ae7510a9db9ccb
parentMerge pull request #1206 from zandrmartin/document-font-command (diff)
downloadsway-400998d6d2bf311f3402faf092154ee8ceac2bf9.tar.gz
sway-400998d6d2bf311f3402faf092154ee8ceac2bf9.tar.zst
sway-400998d6d2bf311f3402faf092154ee8ceac2bf9.zip
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 8282277b..af5a01e5 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -1,7 +1,9 @@
1#include <xkbcommon/xkbcommon.h> 1#include <xkbcommon/xkbcommon.h>
2#include <xkbcommon/xkbcommon-names.h> 2#include <xkbcommon/xkbcommon-names.h>
3#include <strings.h>
3#include "sway/commands.h" 4#include "sway/commands.h"
4#include "sway/config.h" 5#include "sway/config.h"
6#include "sway/input_state.h"
5#include "list.h" 7#include "list.h"
6#include "log.h" 8#include "log.h"
7#include "stringop.h" 9#include "stringop.h"
@@ -52,6 +54,12 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) {
52 // Check for xkb key 54 // Check for xkb key
53 xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], 55 xkb_keysym_t sym = xkb_keysym_from_name(split->items[i],
54 XKB_KEYSYM_CASE_INSENSITIVE); 56 XKB_KEYSYM_CASE_INSENSITIVE);
57
58 // Check for mouse binding
59 if (strncasecmp(split->items[i], "button", strlen("button")) == 0 &&
60 strlen(split->items[i]) == strlen("button0")) {
61 sym = ((char *)split->items[i])[strlen("button")] - '1' + M_LEFT_CLICK;
62 }
55 if (!sym) { 63 if (!sym) {
56 free_sway_binding(binding); 64 free_sway_binding(binding);
57 free_flat_list(split); 65 free_flat_list(split);
diff --git a/sway/handlers.c b/sway/handlers.c
index da765d6d..e1b90a07 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
917 // Update view pointer is on 917 // Update view pointer is on
918 pointer_state.view = container_under_pointer(); 918 pointer_state.view = container_under_pointer();
919 919
920 struct sway_mode *mode = config->current_mode;
921 // handle bindings
922 for (int i = 0; i < mode->bindings->length; ++i) {
923 struct sway_binding *binding = mode->bindings->items[i];
924 if ((modifiers->mods ^ binding->modifiers) == 0) {
925 switch (state) {
926 case WLC_BUTTON_STATE_PRESSED: {
927 if (!binding->release && handle_bindsym(binding, button, 0)) {
928 return EVENT_HANDLED;
929 }
930 }
931 case WLC_BUTTON_STATE_RELEASED:
932 if (binding->release && handle_bindsym(binding, button, 0)) {
933 return EVENT_HANDLED;
934 }
935 break;
936 }
937 }
938 }
939
920 // Update pointer_state 940 // Update pointer_state
921 switch (button) { 941 switch (button) {
922 case M_LEFT_CLICK: 942 case M_LEFT_CLICK: