summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-18 14:27:38 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-18 14:27:38 -0500
commitf2985000f364693fbeb832df1c4fd468c608e40f (patch)
treef84600bdc02e4239fd93f203eb020a90fc7a5f48 /sway
parentMerge branch 'wlroots' into feature/input (diff)
downloadsway-f2985000f364693fbeb832df1c4fd468c608e40f.tar.gz
sway-f2985000f364693fbeb832df1c4fd468c608e40f.tar.zst
sway-f2985000f364693fbeb832df1c4fd468c608e40f.zip
ipc get_inputs
Diffstat (limited to 'sway')
-rw-r--r--sway/ipc-json.c37
-rw-r--r--sway/ipc-server.c14
2 files changed, 51 insertions, 0 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 09a32c1b..bab9a201 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -141,3 +141,40 @@ json_object *ipc_json_describe_container_recursive(swayc_t *c) {
141 141
142 return object; 142 return object;
143} 143}
144
145static const char *describe_device_type(struct sway_input_device *device) {
146 switch (device->wlr_device->type) {
147 case WLR_INPUT_DEVICE_POINTER:
148 return "pointer";
149 case WLR_INPUT_DEVICE_KEYBOARD:
150 return "keyboard";
151 case WLR_INPUT_DEVICE_TOUCH:
152 return "touch";
153 case WLR_INPUT_DEVICE_TABLET_TOOL:
154 return "tablet_tool";
155 case WLR_INPUT_DEVICE_TABLET_PAD:
156 return "tablet_pad";
157 }
158 return "unknown";
159}
160
161json_object *ipc_json_describe_input(struct sway_input_device *device) {
162 if (!(sway_assert(device, "Device must not be null"))) {
163 return NULL;
164 }
165
166 json_object *object = json_object_new_object();
167
168 json_object_object_add(object, "identifier",
169 json_object_new_string(device->identifier));
170 json_object_object_add(object, "name",
171 json_object_new_string(device->wlr_device->name));
172 json_object_object_add(object, "vendor",
173 json_object_new_int(device->wlr_device->vendor));
174 json_object_object_add(object, "product",
175 json_object_new_int(device->wlr_device->product));
176 json_object_object_add(object, "type",
177 json_object_new_string(describe_device_type(device)));
178
179 return object;
180}
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index b7cd2d76..046e40a8 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -20,6 +20,7 @@
20#include "sway/ipc-json.h" 20#include "sway/ipc-json.h"
21#include "sway/ipc-server.h" 21#include "sway/ipc-server.h"
22#include "sway/server.h" 22#include "sway/server.h"
23#include "sway/input/input-manager.h"
23#include "list.h" 24#include "list.h"
24#include "log.h" 25#include "log.h"
25 26
@@ -359,6 +360,19 @@ void ipc_client_handle_command(struct ipc_client *client) {
359 goto exit_cleanup; 360 goto exit_cleanup;
360 } 361 }
361 362
363 case IPC_GET_INPUTS:
364 {
365 json_object *inputs = json_object_new_array();
366 struct sway_input_device *device = NULL;
367 wl_list_for_each(device, &input_manager->devices, link) {
368 json_object_array_add(inputs, ipc_json_describe_input(device));
369 }
370 const char *json_string = json_object_to_json_string(inputs);
371 ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
372 json_object_put(inputs); // free
373 goto exit_cleanup;
374 }
375
362 case IPC_GET_TREE: 376 case IPC_GET_TREE:
363 { 377 {
364 json_object *tree = 378 json_object *tree =