]> git.sur5r.net Git - i3/i3/commitdiff
Add "modifiers" to events sent by i3bar 3465/head
authorSoumya <soumyasr@google.com>
Thu, 25 Oct 2018 16:05:17 +0000 (09:05 -0700)
committerSoumya <soumyasr@google.com>
Thu, 25 Oct 2018 23:02:06 +0000 (16:02 -0700)
docs/i3bar-protocol
i3bar/include/child.h
i3bar/src/child.c
i3bar/src/xcb.c

index 62706f74359488688bafa5a83e702aa0af5040f3..826cae53f018bcc21abfa34a1457de07552bf9bd 100644 (file)
@@ -243,6 +243,9 @@ relative_x, relative_y::
     of the block
 width, height::
     Width and height (in px) of the block
     of the block
 width, height::
     Width and height (in px) of the block
+modifiers::
+    An array of the modifiers active when the click occurred. The order in which
+    modifiers are listed is not guaranteed.
 
 *Example*:
 ------------------------------------------
 
 *Example*:
 ------------------------------------------
@@ -250,6 +253,7 @@ width, height::
  "name": "ethernet",
  "instance": "eth0",
  "button": 1,
  "name": "ethernet",
  "instance": "eth0",
  "button": 1,
+ "modifiers": ["Shift", "Mod1"],
  "x": 1320,
  "y": 1400,
  "relative_x": 12,
  "x": 1320,
  "y": 1400,
  "relative_x": 12,
index 51dd5a19f639e1c63de755e729f2dfe328560f9d..3afed81947efbe4fc2c703b105b768a84b3a4a80 100644 (file)
@@ -85,4 +85,4 @@ bool child_want_click_events(void);
  * Generates a click event, if enabled.
  *
  */
  * Generates a click event, if enabled.
  *
  */
-void send_block_clicked(int button, const char *name, const char *instance, int x, int y, int x_rel, int y_rel, int width, int height);
+void send_block_clicked(int button, const char *name, const char *instance, int x, int y, int x_rel, int y_rel, int width, int height, int mods);
index bb5ceaff0ee2cc1592e1edf157becdcdd4e7fdc9..7c527dc3707f1de7846614112164cfe244842f68 100644 (file)
@@ -8,6 +8,7 @@
  *
  */
 #include "common.h"
  *
  */
 #include "common.h"
+#include "yajl_utils.h"
 
 #include <stdlib.h>
 #include <unistd.h>
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -27,6 +28,8 @@
 #include <yajl/yajl_gen.h>
 #include <paths.h>
 
 #include <yajl/yajl_gen.h>
 #include <paths.h>
 
+#include <xcb/xcb_keysyms.h>
+
 /* Global variables for child_*() */
 i3bar_child child;
 
 /* Global variables for child_*() */
 i3bar_child child;
 
@@ -588,15 +591,11 @@ static void child_click_events_initialize(void) {
     }
 }
 
     }
 }
 
-static void child_click_events_key(const char *key) {
-    yajl_gen_string(gen, (const unsigned char *)key, strlen(key));
-}
-
 /*
  * Generates a click event, if enabled.
  *
  */
 /*
  * Generates a click event, if enabled.
  *
  */
-void send_block_clicked(int button, const char *name, const char *instance, int x, int y, int x_rel, int y_rel, int width, int height) {
+void send_block_clicked(int button, const char *name, const char *instance, int x, int y, int x_rel, int y_rel, int width, int height, int mods) {
     if (!child.click_events) {
         return;
     }
     if (!child.click_events) {
         return;
     }
@@ -606,34 +605,52 @@ void send_block_clicked(int button, const char *name, const char *instance, int
     yajl_gen_map_open(gen);
 
     if (name) {
     yajl_gen_map_open(gen);
 
     if (name) {
-        child_click_events_key("name");
-        yajl_gen_string(gen, (const unsigned char *)name, strlen(name));
+        ystr("name");
+        ystr(name);
     }
 
     if (instance) {
     }
 
     if (instance) {
-        child_click_events_key("instance");
-        yajl_gen_string(gen, (const unsigned char *)instance, strlen(instance));
+        ystr("instance");
+        ystr(instance);
     }
 
     }
 
-    child_click_events_key("button");
+    ystr("button");
     yajl_gen_integer(gen, button);
 
     yajl_gen_integer(gen, button);
 
-    child_click_events_key("x");
+    ystr("modifiers");
+    yajl_gen_array_open(gen);
+    if (mods & XCB_MOD_MASK_SHIFT)
+        ystr("Shift");
+    if (mods & XCB_MOD_MASK_CONTROL)
+        ystr("Control");
+    if (mods & XCB_MOD_MASK_1)
+        ystr("Mod1");
+    if (mods & XCB_MOD_MASK_2)
+        ystr("Mod2");
+    if (mods & XCB_MOD_MASK_3)
+        ystr("Mod3");
+    if (mods & XCB_MOD_MASK_4)
+        ystr("Mod4");
+    if (mods & XCB_MOD_MASK_5)
+        ystr("Mod5");
+    yajl_gen_array_close(gen);
+
+    ystr("x");
     yajl_gen_integer(gen, x);
 
     yajl_gen_integer(gen, x);
 
-    child_click_events_key("y");
+    ystr("y");
     yajl_gen_integer(gen, y);
 
     yajl_gen_integer(gen, y);
 
-    child_click_events_key("relative_x");
+    ystr("relative_x");
     yajl_gen_integer(gen, x_rel);
 
     yajl_gen_integer(gen, x_rel);
 
-    child_click_events_key("relative_y");
+    ystr("relative_y");
     yajl_gen_integer(gen, y_rel);
 
     yajl_gen_integer(gen, y_rel);
 
-    child_click_events_key("width");
+    ystr("width");
     yajl_gen_integer(gen, width);
 
     yajl_gen_integer(gen, width);
 
-    child_click_events_key("height");
+    ystr("height");
     yajl_gen_integer(gen, height);
 
     yajl_gen_map_close(gen);
     yajl_gen_integer(gen, height);
 
     yajl_gen_map_close(gen);
index c0486181b02933db87200396c318e0ee322924e2..31ae08f05c01d9c87d8fb0488a9c83aa1a25cffe 100644 (file)
@@ -524,7 +524,8 @@ static void handle_button(xcb_button_press_event_t *event) {
                 const int relative_x = statusline_x - last_block_x;
                 if (relative_x >= 0 && (uint32_t)relative_x <= render->width) {
                     send_block_clicked(event->detail, block->name, block->instance,
                 const int relative_x = statusline_x - last_block_x;
                 if (relative_x >= 0 && (uint32_t)relative_x <= render->width) {
                     send_block_clicked(event->detail, block->name, block->instance,
-                                       event->root_x, event->root_y, relative_x, event->event_y, render->width, bar_height);
+                                       event->root_x, event->root_y, relative_x, event->event_y, render->width, bar_height,
+                                       event->state);
                     return;
                 }
 
                     return;
                 }