mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
ipc get_inputs
This commit is contained in:
parent
a949d7de5a
commit
f2985000f3
|
@ -2,10 +2,12 @@
|
||||||
#define _SWAY_IPC_JSON_H
|
#define _SWAY_IPC_JSON_H
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
#include "sway/container.h"
|
#include "sway/container.h"
|
||||||
|
#include "sway/input/input-manager.h"
|
||||||
|
|
||||||
json_object *ipc_json_get_version();
|
json_object *ipc_json_get_version();
|
||||||
|
|
||||||
json_object *ipc_json_describe_container(swayc_t *c);
|
json_object *ipc_json_describe_container(swayc_t *c);
|
||||||
json_object *ipc_json_describe_container_recursive(swayc_t *c);
|
json_object *ipc_json_describe_container_recursive(swayc_t *c);
|
||||||
|
json_object *ipc_json_describe_input(struct sway_input_device *device);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -141,3 +141,40 @@ json_object *ipc_json_describe_container_recursive(swayc_t *c) {
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *describe_device_type(struct sway_input_device *device) {
|
||||||
|
switch (device->wlr_device->type) {
|
||||||
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
|
return "pointer";
|
||||||
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||||
|
return "keyboard";
|
||||||
|
case WLR_INPUT_DEVICE_TOUCH:
|
||||||
|
return "touch";
|
||||||
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
||||||
|
return "tablet_tool";
|
||||||
|
case WLR_INPUT_DEVICE_TABLET_PAD:
|
||||||
|
return "tablet_pad";
|
||||||
|
}
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object *ipc_json_describe_input(struct sway_input_device *device) {
|
||||||
|
if (!(sway_assert(device, "Device must not be null"))) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object *object = json_object_new_object();
|
||||||
|
|
||||||
|
json_object_object_add(object, "identifier",
|
||||||
|
json_object_new_string(device->identifier));
|
||||||
|
json_object_object_add(object, "name",
|
||||||
|
json_object_new_string(device->wlr_device->name));
|
||||||
|
json_object_object_add(object, "vendor",
|
||||||
|
json_object_new_int(device->wlr_device->vendor));
|
||||||
|
json_object_object_add(object, "product",
|
||||||
|
json_object_new_int(device->wlr_device->product));
|
||||||
|
json_object_object_add(object, "type",
|
||||||
|
json_object_new_string(describe_device_type(device)));
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "sway/ipc-json.h"
|
#include "sway/ipc-json.h"
|
||||||
#include "sway/ipc-server.h"
|
#include "sway/ipc-server.h"
|
||||||
#include "sway/server.h"
|
#include "sway/server.h"
|
||||||
|
#include "sway/input/input-manager.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
@ -359,6 +360,19 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
||||||
goto exit_cleanup;
|
goto exit_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case IPC_GET_INPUTS:
|
||||||
|
{
|
||||||
|
json_object *inputs = json_object_new_array();
|
||||||
|
struct sway_input_device *device = NULL;
|
||||||
|
wl_list_for_each(device, &input_manager->devices, link) {
|
||||||
|
json_object_array_add(inputs, ipc_json_describe_input(device));
|
||||||
|
}
|
||||||
|
const char *json_string = json_object_to_json_string(inputs);
|
||||||
|
ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
|
||||||
|
json_object_put(inputs); // free
|
||||||
|
goto exit_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
case IPC_GET_TREE:
|
case IPC_GET_TREE:
|
||||||
{
|
{
|
||||||
json_object *tree =
|
json_object *tree =
|
||||||
|
|
|
@ -61,55 +61,49 @@ static void pretty_print_workspace(json_object *w) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pretty_print_input(json_object *i) {
|
static const char *pretty_type_name(const char *name) {
|
||||||
json_object *id, *name, *size, *caps;
|
// TODO these constants probably belong in the common lib
|
||||||
json_object_object_get_ex(i, "identifier", &id);
|
|
||||||
json_object_object_get_ex(i, "name", &name);
|
|
||||||
json_object_object_get_ex(i, "size", &size);
|
|
||||||
json_object_object_get_ex(i, "capabilities", &caps);
|
|
||||||
|
|
||||||
printf( "Input device %s\n Type: ", json_object_get_string(name));
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
const char *a;
|
const char *a;
|
||||||
const char *b;
|
const char *b;
|
||||||
} cap_names[] = {
|
} type_names[] = {
|
||||||
{ "keyboard", "Keyboard" },
|
{ "keyboard", "Keyboard" },
|
||||||
{ "pointer", "Mouse" },
|
{ "pointer", "Mouse" },
|
||||||
{ "touch", "Touch" },
|
|
||||||
{ "tablet_tool", "Tablet tool" },
|
|
||||||
{ "tablet_pad", "Tablet pad" },
|
{ "tablet_pad", "Tablet pad" },
|
||||||
{ "gesture", "Gesture" },
|
{ "tablet_tool", "Tablet tool" },
|
||||||
{ "switch", "Switch" },
|
{ "touch", "Touch" },
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t len = json_object_array_length(caps);
|
for (size_t i = 0; i < sizeof(type_names) / sizeof(type_names[0]); ++i) {
|
||||||
if (len == 0) {
|
if (strcmp(type_names[i].a, name) == 0) {
|
||||||
printf("Unknown");
|
return type_names[i].b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object *cap;
|
return name;
|
||||||
for (size_t i = 0; i < len; ++i) {
|
}
|
||||||
cap = json_object_array_get_idx(caps, i);
|
|
||||||
const char *cap_s = json_object_get_string(cap);
|
static void pretty_print_input(json_object *i) {
|
||||||
const char *_name = NULL;
|
json_object *id, *name, *type, *product, *vendor;
|
||||||
for (size_t j = 0; j < sizeof(cap_names) / sizeof(cap_names[0]); ++i) {
|
json_object_object_get_ex(i, "identifier", &id);
|
||||||
if (strcmp(cap_names[i].a, cap_s) == 0) {
|
json_object_object_get_ex(i, "name", &name);
|
||||||
_name = cap_names[i].b;
|
json_object_object_get_ex(i, "type", &type);
|
||||||
break;
|
json_object_object_get_ex(i, "product", &product);
|
||||||
}
|
json_object_object_get_ex(i, "vendor", &vendor);
|
||||||
}
|
|
||||||
printf("%s%s", _name ? _name : cap_s, len > 1 && i != len - 1 ? ", " : "");
|
const char *fmt =
|
||||||
}
|
"Input device: %s\n"
|
||||||
printf("\n Sway ID: %s\n", json_object_get_string(id));
|
" Type: %s\n"
|
||||||
if (size) {
|
" Identifier: %s\n"
|
||||||
json_object *width, *height;
|
" Product ID: %d\n"
|
||||||
json_object_object_get_ex(size, "width", &width);
|
" Vendor ID: %d\n\n";
|
||||||
json_object_object_get_ex(size, "height", &height);
|
|
||||||
printf(" Size: %lfmm x %lfmm\n",
|
|
||||||
json_object_get_double(width), json_object_get_double(height));
|
printf(fmt, json_object_get_string(name),
|
||||||
}
|
pretty_type_name(json_object_get_string(type)),
|
||||||
printf("\n");
|
json_object_get_string(id),
|
||||||
|
json_object_get_int(product),
|
||||||
|
json_object_get_int(vendor));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pretty_print_output(json_object *o) {
|
static void pretty_print_output(json_object *o) {
|
||||||
|
|
Loading…
Reference in a new issue