aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-08-23 23:34:02 +0100
committerHarry Jeffery <harry@exec64.co.uk>2019-08-23 23:34:02 +0100
commit9e1d6e24a028ec96fb11ba943769764665fb024c (patch)
tree50eaaf19bbff64e6309ebe8c2b1ab1c4b58f3df9
parent9850d9c6a2be489a912ff3c98c83eef77198fccc (diff)
downloadimv-9e1d6e24a028ec96fb11ba943769764665fb024c.tar.gz
wl_window: Maintain keyboard modifiers state
-rw-r--r--src/imv.c6
-rw-r--r--src/keyboard.c6
-rw-r--r--src/keyboard.h4
-rw-r--r--src/window.h6
-rw-r--r--src/wl_window.c16
5 files changed, 34 insertions, 4 deletions
diff --git a/src/imv.c b/src/imv.c
index 6376ee5..269a70a 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -460,6 +460,12 @@ static void event_handler(void *data, const struct imv_event *e)
case IMV_EVENT_KEYBOARD:
key_handler(imv, e->data.keyboard.scancode, e->data.keyboard. pressed);
break;
+ case IMV_EVENT_KEYBOARD_MODS:
+ imv_keyboard_update_mods(imv->keyboard,
+ e->data.keyboard_mods.depressed,
+ e->data.keyboard_mods.latched,
+ e->data.keyboard_mods.locked);
+ break;
case IMV_EVENT_MOUSE_MOTION:
if (imv_window_get_mouse_button(imv->window, 1)) {
imv_viewport_move(imv->view, e->data.mouse_motion.dx,
diff --git a/src/keyboard.c b/src/keyboard.c
index af79006..55e4e49 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -55,6 +55,12 @@ void imv_keyboard_update_key(struct imv_keyboard *keyboard, int scancode, bool p
xkb_state_update_key(keyboard->state, scancode + scancode_offset, pressed ? XKB_KEY_DOWN : XKB_KEY_UP);
}
+void imv_keyboard_update_mods(struct imv_keyboard *keyboard,
+ int depressed, int latched, int locked)
+{
+ xkb_state_update_mask(keyboard->state, depressed, latched, locked, 0, 0, 0);
+}
+
static const char *describe_prefix(struct imv_keyboard *keyboard)
{
const bool ctrl = (xkb_state_mod_name_is_active(keyboard->state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0);
diff --git a/src/keyboard.h b/src/keyboard.h
index 7bbb202..05036c4 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -15,6 +15,10 @@ void imv_keyboard_free(struct imv_keyboard *keyboard);
/* Notify the keyboard of the state of a key */
void imv_keyboard_update_key(struct imv_keyboard *keyboard, int scancode, bool pressed);
+/* Notify the keyboard of the state of the modifiers */
+void imv_keyboard_update_mods(struct imv_keyboard *keyboard,
+ int depressed, int latched, int locked);
+
/* Write the null-terminated name of the key corresponding to scancode into buf */
size_t imv_keyboard_keyname(struct imv_keyboard *keyboard, int scancode, char *buf, size_t buflen);
diff --git a/src/window.h b/src/window.h
index 978278c..eff00ab 100644
--- a/src/window.h
+++ b/src/window.h
@@ -9,6 +9,7 @@ enum imv_event_type {
IMV_EVENT_CLOSE,
IMV_EVENT_RESIZE,
IMV_EVENT_KEYBOARD,
+ IMV_EVENT_KEYBOARD_MODS,
IMV_EVENT_MOUSE_MOTION,
IMV_EVENT_MOUSE_BUTTON,
IMV_EVENT_MOUSE_SCROLL,
@@ -29,6 +30,11 @@ struct imv_event {
bool pressed;
} keyboard;
struct {
+ int depressed;
+ int latched;
+ int locked;
+ } keyboard_mods;
+ struct {
double x, y, dx, dy;
} mouse_motion;
struct {
diff --git a/src/wl_window.c b/src/wl_window.c
index ace66f0..e9a8a0f 100644
--- a/src/wl_window.c
+++ b/src/wl_window.c
@@ -152,13 +152,21 @@ static void keyboard_modifiers(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
uint32_t mods_locked, uint32_t group)
{
- (void)data;
(void)keyboard;
(void)serial;
- (void)mods_depressed;
- (void)mods_latched;
- (void)mods_locked;
(void)group;
+ struct imv_window *window = data;
+ struct imv_event e = {
+ .type = IMV_EVENT_KEYBOARD_MODS,
+ .data = {
+ .keyboard_mods = {
+ .depressed = mods_depressed,
+ .latched = mods_latched,
+ .locked = mods_locked,
+ }
+ }
+ };
+ imv_window_push_event(window, &e);
}
static void keyboard_repeat(void *data, struct wl_keyboard *keyboard,