From 74189114065c79d85ad0b8f75e34490a802cc2f4 Mon Sep 17 00:00:00 2001
From: Harry Jeffery <harry@exec64.co.uk>
Date: Fri, 23 Aug 2019 23:41:22 +0100
Subject: x11_window: Maintain keyboard modifiers state

---
 src/x11_window.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/x11_window.c b/src/x11_window.c
index 315f600..69fb244 100644
--- a/src/x11_window.c
+++ b/src/x11_window.c
@@ -38,6 +38,7 @@ struct imv_window {
 
   int pipe_fds[2];
   char *keymap;
+  int last_mod_state;
 };
 
 static void set_nonblocking(int fd)
@@ -297,6 +298,21 @@ void imv_window_pump_events(struct imv_window *window, imv_event_handler handler
         handler(data, &e);
       }
     } else if (xev.type == KeyPress || xev.type == KeyRelease) {
+      if (window->last_mod_state != (int)xev.xkey.state) {
+        window->last_mod_state = (int)xev.xkey.state;
+        /* modifiers have changed, push an event for that first */
+        struct imv_event e = {
+          .type = IMV_EVENT_KEYBOARD_MODS,
+          .data = {
+            .keyboard_mods = {
+              .depressed = (int)xev.xkey.state,
+            }
+          }
+        };
+        if (handler) {
+          handler(data, &e);
+        }
+      }
       struct imv_event e = {
         .type = IMV_EVENT_KEYBOARD,
         .data = {
-- 
cgit v1.2.3