mirror of
https://github.com/NickHu/sway
synced 2024-12-27 21:58:11 +01:00
Merge pull request #3398 from RedSoxFan/toggle-input-events
input events: toggle and ipc get_inputs
This commit is contained in:
commit
4eb0767414
4 changed files with 107 additions and 5 deletions
|
@ -1,10 +1,69 @@
|
|||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <wlr/backend/libinput.h>
|
||||
#include "sway/config.h"
|
||||
#include "sway/commands.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "log.h"
|
||||
|
||||
static void toggle_send_events_for_device(struct input_config *ic,
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
if (!wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
struct libinput_device *libinput_dev
|
||||
= wlr_libinput_get_device_handle(wlr_device);
|
||||
|
||||
enum libinput_config_send_events_mode mode =
|
||||
libinput_device_config_send_events_get_mode(libinput_dev);
|
||||
uint32_t possible =
|
||||
libinput_device_config_send_events_get_modes(libinput_dev);
|
||||
|
||||
switch (mode) {
|
||||
case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
|
||||
mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
|
||||
if (possible & mode) {
|
||||
break;
|
||||
}
|
||||
// fall through
|
||||
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
|
||||
mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
|
||||
if (possible & mode) {
|
||||
break;
|
||||
}
|
||||
// fall through
|
||||
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
|
||||
default:
|
||||
mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
|
||||
break;
|
||||
}
|
||||
|
||||
ic->send_events = mode;
|
||||
}
|
||||
|
||||
static void toggle_send_events(struct input_config *ic) {
|
||||
struct sway_input_device *input_device = NULL;
|
||||
wl_list_for_each(input_device, &server.input->devices, link) {
|
||||
if (strcmp(input_device->identifier, ic->identifier) == 0) {
|
||||
toggle_send_events_for_device(ic, input_device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void toggle_wildcard_send_events() {
|
||||
struct sway_input_device *input_device = NULL;
|
||||
wl_list_for_each(input_device, &server.input->devices, link) {
|
||||
struct input_config *ic = new_input_config(input_device->identifier);
|
||||
if (!ic) {
|
||||
break;
|
||||
}
|
||||
toggle_send_events_for_device(ic, input_device);
|
||||
store_input_config(ic);
|
||||
}
|
||||
}
|
||||
|
||||
struct cmd_results *input_cmd_events(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) {
|
||||
|
@ -23,9 +82,24 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {
|
|||
} else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) {
|
||||
ic->send_events =
|
||||
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
|
||||
} else {
|
||||
} else if (config->reading) {
|
||||
return cmd_results_new(CMD_INVALID, "events",
|
||||
"Expected 'events <enabled|disabled|disabled_on_external_mouse>'");
|
||||
} else if (strcasecmp(argv[0], "toggle") == 0) {
|
||||
if (strcmp(ic->identifier, "*") == 0) {
|
||||
// Update the device input configs and then reset the wildcard
|
||||
// config send events mode so that is does not override the device
|
||||
// ones. The device ones will be applied when attempting to apply
|
||||
// the wildcard config
|
||||
toggle_wildcard_send_events();
|
||||
ic->send_events = INT_MIN;
|
||||
} else {
|
||||
toggle_send_events(ic);
|
||||
}
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "events",
|
||||
"Expected 'events <enabled|disabled|disabled_on_external_mouse|"
|
||||
"toggle>'");
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "sway/output.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/input/seat.h"
|
||||
#include <wlr/backend/libinput.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
@ -598,6 +599,26 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
|
|||
}
|
||||
}
|
||||
|
||||
if (wlr_input_device_is_libinput(device->wlr_device)) {
|
||||
struct libinput_device *libinput_dev;
|
||||
libinput_dev = wlr_libinput_get_device_handle(device->wlr_device);
|
||||
|
||||
const char *events = "unknown";
|
||||
switch (libinput_device_config_send_events_get_mode(libinput_dev)) {
|
||||
case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
|
||||
events = "enabled";
|
||||
break;
|
||||
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
|
||||
events = "disabled_on_external_mouse";
|
||||
break;
|
||||
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
|
||||
events = "disabled";
|
||||
break;
|
||||
}
|
||||
json_object_object_add(object, "libinput_send_events",
|
||||
json_object_new_string(events));
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,9 +82,12 @@ The following commands may only be used in the configuration file.
|
|||
*input* <identifier> dwt enabled|disabled
|
||||
Enables or disables disable-while-typing for the specified input device.
|
||||
|
||||
*input* <identifier> events enabled|disabled|disabled\_on\_external\_mouse
|
||||
Enables or disables send\_events for specified input device. (Disabling
|
||||
send\_events disables the input device)
|
||||
*input* <identifier> events enabled|disabled|disabled\_on\_external\_mouse|toggle
|
||||
Enables or disables send\_events for specified input device. Disabling
|
||||
send\_events disables the input device. The _toggle_ option cannot be used
|
||||
in the config. The order is enabled, disabled\_on\_external\_mouse,
|
||||
disabled, (loop back to enabled). Any mode which is not supported by the
|
||||
device will be skipped during the toggle.
|
||||
|
||||
*input* <identifier> left\_handed enabled|disabled
|
||||
Enables or disables left handed mode for specified input device.
|
||||
|
|
|
@ -113,7 +113,7 @@ static const char *pretty_type_name(const char *name) {
|
|||
}
|
||||
|
||||
static void pretty_print_input(json_object *i) {
|
||||
json_object *id, *name, *type, *product, *vendor, *kbdlayout;
|
||||
json_object *id, *name, *type, *product, *vendor, *kbdlayout, *events;
|
||||
json_object_object_get_ex(i, "identifier", &id);
|
||||
json_object_object_get_ex(i, "name", &name);
|
||||
json_object_object_get_ex(i, "type", &type);
|
||||
|
@ -139,6 +139,10 @@ static void pretty_print_input(json_object *i) {
|
|||
json_object_get_string(kbdlayout));
|
||||
}
|
||||
|
||||
if (json_object_object_get_ex(i, "libinput_send_events", &events)) {
|
||||
printf(" Libinput Send Events: %s\n", json_object_get_string(events));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue