summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-07-17 17:12:20 -0400
committerLibravatar Simon Ser <contact@emersion.fr>2019-07-23 20:45:46 +0300
commit6effca7b61e87c7d17885d007d94e556a0137651 (patch)
tree686cc1e219d8236f8c9864c9992b3cb6b44c9583
parentinput_cmd_xkb_switch_layout: support input types (diff)
downloadsway-6effca7b61e87c7d17885d007d94e556a0137651.tar.gz
sway-6effca7b61e87c7d17885d007d94e556a0137651.tar.zst
sway-6effca7b61e87c7d17885d007d94e556a0137651.zip
ipc: add an input event
This adds an ipc event related to input devices. Currently the following changes are supported: - added: when an input device becomes available - removed: when an input device is no longer available - xkb_keymap_changed: (keyboards only) the keymap changed - xkb_layout_changed: (keyboards only) the effective layout changed
-rw-r--r--include/ipc.h1
-rw-r--r--include/sway/input/keyboard.h1
-rw-r--r--include/sway/ipc-server.h2
-rw-r--r--sway/input/input-manager.c5
-rw-r--r--sway/input/keyboard.c28
-rw-r--r--sway/ipc-server.c17
-rw-r--r--sway/sway-ipc.7.scd53
7 files changed, 107 insertions, 0 deletions
diff --git a/include/ipc.h b/include/ipc.h
index 6063f69c..7ae21ab3 100644
--- a/include/ipc.h
+++ b/include/ipc.h
@@ -34,6 +34,7 @@ enum ipc_command_type {
34 34
35 // sway-specific event types 35 // sway-specific event types
36 IPC_EVENT_BAR_STATE_UPDATE = ((1<<31) | 20), 36 IPC_EVENT_BAR_STATE_UPDATE = ((1<<31) | 20),
37 IPC_EVENT_INPUT = ((1<<31) | 21),
37}; 38};
38 39
39#endif 40#endif
diff --git a/include/sway/input/keyboard.h b/include/sway/input/keyboard.h
index 90214af9..1ff63c94 100644
--- a/include/sway/input/keyboard.h
+++ b/include/sway/input/keyboard.h
@@ -52,6 +52,7 @@ struct sway_keyboard {
52 struct sway_seat_device *seat_device; 52 struct sway_seat_device *seat_device;
53 53
54 struct xkb_keymap *keymap; 54 struct xkb_keymap *keymap;
55 xkb_layout_index_t effective_layout;
55 56
56 struct wl_listener keyboard_key; 57 struct wl_listener keyboard_key;
57 struct wl_listener keyboard_modifiers; 58 struct wl_listener keyboard_modifiers;
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h
index 3c43f74d..bc4f781a 100644
--- a/include/sway/ipc-server.h
+++ b/include/sway/ipc-server.h
@@ -2,6 +2,7 @@
2#define _SWAY_IPC_SERVER_H 2#define _SWAY_IPC_SERVER_H
3#include <sys/socket.h> 3#include <sys/socket.h>
4#include "sway/config.h" 4#include "sway/config.h"
5#include "sway/input/input-manager.h"
5#include "sway/tree/container.h" 6#include "sway/tree/container.h"
6#include "ipc.h" 7#include "ipc.h"
7 8
@@ -19,5 +20,6 @@ void ipc_event_bar_state_update(struct bar_config *bar);
19void ipc_event_mode(const char *mode, bool pango); 20void ipc_event_mode(const char *mode, bool pango);
20void ipc_event_shutdown(const char *reason); 21void ipc_event_shutdown(const char *reason);
21void ipc_event_binding(struct sway_binding *binding); 22void ipc_event_binding(struct sway_binding *binding);
23void ipc_event_input(const char *change, struct sway_input_device *device);
22 24
23#endif 25#endif
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index 4fd980c4..dd84a0b3 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -12,6 +12,7 @@
12#include "sway/config.h" 12#include "sway/config.h"
13#include "sway/input/input-manager.h" 13#include "sway/input/input-manager.h"
14#include "sway/input/seat.h" 14#include "sway/input/seat.h"
15#include "sway/ipc-server.h"
15#include "sway/server.h" 16#include "sway/server.h"
16#include "stringop.h" 17#include "stringop.h"
17#include "list.h" 18#include "list.h"
@@ -584,6 +585,8 @@ static void handle_device_destroy(struct wl_listener *listener, void *data) {
584 seat_remove_device(seat, input_device); 585 seat_remove_device(seat, input_device);
585 } 586 }
586 587
588 ipc_event_input("removed", input_device);
589
587 wl_list_remove(&input_device->link); 590 wl_list_remove(&input_device->link);
588 wl_list_remove(&input_device->device_destroy.link); 591 wl_list_remove(&input_device->device_destroy.link);
589 free(input_device->identifier); 592 free(input_device->identifier);
@@ -656,6 +659,8 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
656 "device '%s' is not configured on any seats", 659 "device '%s' is not configured on any seats",
657 input_device->identifier); 660 input_device->identifier);
658 } 661 }
662
663 ipc_event_input("added", input_device);
659} 664}
660 665
661static void handle_inhibit_activate(struct wl_listener *listener, void *data) { 666static void handle_inhibit_activate(struct wl_listener *listener, void *data) {
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 1f7ed849..328458fa 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -473,6 +473,11 @@ static void handle_keyboard_modifiers(struct wl_listener *listener,
473 473
474 uint32_t modifiers = wlr_keyboard_get_modifiers(wlr_device->keyboard); 474 uint32_t modifiers = wlr_keyboard_get_modifiers(wlr_device->keyboard);
475 determine_bar_visibility(modifiers); 475 determine_bar_visibility(modifiers);
476
477 if (wlr_device->keyboard->modifiers.group != keyboard->effective_layout) {
478 keyboard->effective_layout = wlr_device->keyboard->modifiers.group;
479 ipc_event_input("xkb_layout", keyboard->seat_device->input_device);
480 }
476} 481}
477 482
478struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, 483struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
@@ -603,8 +608,23 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
603 } 608 }
604 } 609 }
605 610
611 bool keymap_changed = false;
612 bool effective_layout_changed = keyboard->effective_layout != 0;
613 if (keyboard->keymap) {
614 char *old_keymap_string = xkb_keymap_get_as_string(keyboard->keymap,
615 XKB_KEYMAP_FORMAT_TEXT_V1);
616 char *new_keymap_string = xkb_keymap_get_as_string(keymap,
617 XKB_KEYMAP_FORMAT_TEXT_V1);
618 keymap_changed = strcmp(old_keymap_string, new_keymap_string);
619 free(old_keymap_string);
620 free(new_keymap_string);
621 } else {
622 keymap_changed = true;
623 }
624
606 xkb_keymap_unref(keyboard->keymap); 625 xkb_keymap_unref(keyboard->keymap);
607 keyboard->keymap = keymap; 626 keyboard->keymap = keymap;
627 keyboard->effective_layout = 0;
608 wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap); 628 wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap);
609 629
610 xkb_mod_mask_t locked_mods = 0; 630 xkb_mod_mask_t locked_mods = 0;
@@ -654,6 +674,14 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
654 wl_signal_add(&wlr_device->keyboard->events.modifiers, 674 wl_signal_add(&wlr_device->keyboard->events.modifiers,
655 &keyboard->keyboard_modifiers); 675 &keyboard->keyboard_modifiers);
656 keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers; 676 keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
677
678 if (keymap_changed) {
679 ipc_event_input("xkb_keymap",
680 keyboard->seat_device->input_device);
681 } else if (effective_layout_changed) {
682 ipc_event_input("xkb_layout",
683 keyboard->seat_device->input_device);
684 }
657} 685}
658 686
659void sway_keyboard_destroy(struct sway_keyboard *keyboard) { 687void sway_keyboard_destroy(struct sway_keyboard *keyboard) {
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index ca1c1b12..773e90fd 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -487,6 +487,21 @@ static void ipc_event_tick(const char *payload) {
487 json_object_put(json); 487 json_object_put(json);
488} 488}
489 489
490void ipc_event_input(const char *change, struct sway_input_device *device) {
491 if (!ipc_has_event_listeners(IPC_EVENT_INPUT)) {
492 return;
493 }
494 sway_log(SWAY_DEBUG, "Sending input event");
495
496 json_object *json = json_object_new_object();
497 json_object_object_add(json, "change", json_object_new_string(change));
498 json_object_object_add(json, "input", ipc_json_describe_input(device));
499
500 const char *json_string = json_object_to_json_string(json);
501 ipc_send_event(json_string, IPC_EVENT_INPUT);
502 json_object_put(json);
503}
504
490int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { 505int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
491 struct ipc_client *client = data; 506 struct ipc_client *client = data;
492 507
@@ -716,6 +731,8 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt
716 } else if (strcmp(event_type, "tick") == 0) { 731 } else if (strcmp(event_type, "tick") == 0) {
717 client->subscribed_events |= event_mask(IPC_EVENT_TICK); 732 client->subscribed_events |= event_mask(IPC_EVENT_TICK);
718 is_tick = true; 733 is_tick = true;
734 } else if (strcmp(event_type, "input") == 0) {
735 client->subscribed_events |= event_mask(IPC_EVENT_INPUT);
719 } else { 736 } else {
720 const char msg[] = "{\"success\": false}"; 737 const char msg[] = "{\"success\": false}";
721 ipc_send_reply(client, payload_type, msg, strlen(msg)); 738 ipc_send_reply(client, payload_type, msg, strlen(msg));
diff --git a/sway/sway-ipc.7.scd b/sway/sway-ipc.7.scd
index 3657dcd6..4688e46d 100644
--- a/sway/sway-ipc.7.scd
+++ b/sway/sway-ipc.7.scd
@@ -1371,6 +1371,9 @@ available:
1371|- 0x80000014 1371|- 0x80000014
1372: bar_status_update 1372: bar_status_update
1373: Send when the visibility of a bar should change due to a modifier 1373: Send when the visibility of a bar should change due to a modifier
1374|- 0x80000015
1375: input
1376: Sent when something related to input devices changes
1374 1377
1375 1378
1376## 0x80000000. WORKSPACE 1379## 0x80000000. WORKSPACE
@@ -1702,6 +1705,56 @@ event is a single object with the following properties:
1702} 1705}
1703``` 1706```
1704 1707
1708## 0x80000015. INPUT
1709
1710Sent when something related to the input devices changes. The event is a single
1711object with the following properties:
1712
1713[- *PROPERTY*
1714:- *DATA TYPE*
1715:- *DESCRIPTION*
1716|- change
1717: string
1718:[ What has changed
1719|- input
1720: object
1721: An object representing the input that is identical the ones GET_INPUTS gives
1722
1723The following change types are currently available:
1724[- *TYPE*
1725:- *DESCRIPTION*
1726|- added
1727:[ The input device became available
1728|- removed
1729: The input device is no longer available
1730|- xkb_keymap
1731: (Keyboards only) The keymap for the keyboard has changed
1732|- xkb_layout
1733: (Keyboards only) The effective layout in the keymap has changed
1734
1735*Example Event:*
1736```
1737{
1738 "change": "xkb_layout",
1739 "input": {
1740 "identifier": "1:1:AT_Translated_Set_2_keyboard",
1741 "name": "AT Translated Set 2 keyboard",
1742 "vendor": 1,
1743 "product": 1,
1744 "type": "keyboard",
1745 "xkb_layout_names": [
1746 "English (US)",
1747 "English (Dvorak)"
1748 ],
1749 "xkb_active_layout_index": 1,
1750 "xkb_active_layout_name": "English (Dvorak)",
1751 "libinput": {
1752 "send_events": "enabled"
1753 }
1754 }
1755}
1756```
1757
1705# SEE ALSO 1758# SEE ALSO
1706 1759
1707*sway*(1) *sway*(5) *sway-bar*(5) *swaymsg*(1) *sway-input*(5) *sway-output*(5) 1760*sway*(1) *sway*(5) *sway-bar*(5) *swaymsg*(1) *sway-input*(5) *sway-output*(5)