summaryrefslogtreecommitdiff
path: root/sway/commands/input
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/input')
-rw-r--r--sway/commands/input/events.c10
-rw-r--r--sway/commands/input/map_from_region.c18
-rw-r--r--sway/commands/input/map_to_region.c2
-rw-r--r--sway/commands/input/rotation_angle.c29
-rw-r--r--sway/commands/input/scroll_button.c2
-rw-r--r--sway/commands/input/scroll_button_lock.c26
6 files changed, 80 insertions, 7 deletions
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c
index 9405181a..08d99bf0 100644
--- a/sway/commands/input/events.c
+++ b/sway/commands/input/events.c
@@ -1,14 +1,19 @@
#include <limits.h>
#include <string.h>
#include <strings.h>
-#include <wlr/backend/libinput.h>
+#include <wlr/config.h>
#include "sway/config.h"
#include "sway/commands.h"
#include "sway/input/input-manager.h"
#include "log.h"
+#if WLR_HAS_LIBINPUT_BACKEND
+#include <wlr/backend/libinput.h>
+#endif
+
static void toggle_supported_send_events_for_device(struct input_config *ic,
struct sway_input_device *input_device) {
+#if WLR_HAS_LIBINPUT_BACKEND
struct wlr_input_device *wlr_device = input_device->wlr_device;
if (!wlr_input_device_is_libinput(wlr_device)) {
return;
@@ -41,6 +46,7 @@ static void toggle_supported_send_events_for_device(struct input_config *ic,
}
ic->send_events = mode;
+#endif
}
static int mode_for_name(const char *name) {
@@ -56,6 +62,7 @@ static int mode_for_name(const char *name) {
static void toggle_select_send_events_for_device(struct input_config *ic,
struct sway_input_device *input_device, int argc, char **argv) {
+#if WLR_HAS_LIBINPUT_BACKEND
if (!wlr_input_device_is_libinput(input_device->wlr_device)) {
return;
}
@@ -72,6 +79,7 @@ static void toggle_select_send_events_for_device(struct input_config *ic,
}
}
ic->send_events = mode_for_name(argv[index % argc]);
+#endif
}
static void toggle_send_events(int argc, char **argv) {
diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c
index de00b714..4400e111 100644
--- a/sway/commands/input/map_from_region.c
+++ b/sway/commands/input/map_from_region.c
@@ -11,11 +11,21 @@ static bool parse_coords(const char *str, double *x, double *y, bool *mm) {
*mm = false;
char *end;
- *x = strtod(str, &end);
- if (end[0] != 'x') {
- return false;
+
+ // Check for "0x" prefix to avoid strtod treating the string as hex
+ if (str[0] == '0' && str[1] == 'x') {
+ if (strlen(str) < 3) {
+ return false;
+ }
+ *x = 0;
+ end = (char *)str + 2;
+ } else {
+ *x = strtod(str, &end);
+ if (end[0] != 'x') {
+ return false;
+ }
+ ++end;
}
- ++end;
*y = strtod(end, &end);
if (end[0] == 'm') {
diff --git a/sway/commands/input/map_to_region.c b/sway/commands/input/map_to_region.c
index 284b57d0..ad535db2 100644
--- a/sway/commands/input/map_to_region.c
+++ b/sway/commands/input/map_to_region.c
@@ -49,5 +49,5 @@ struct cmd_results *input_cmd_map_to_region(int argc, char **argv) {
error:
free(ic->mapped_to_region);
ic->mapped_to_region = NULL;
- return cmd_results_new(CMD_FAILURE, errstr);
+ return cmd_results_new(CMD_FAILURE, "%s", errstr);
}
diff --git a/sway/commands/input/rotation_angle.c b/sway/commands/input/rotation_angle.c
new file mode 100644
index 00000000..5e278fff
--- /dev/null
+++ b/sway/commands/input/rotation_angle.c
@@ -0,0 +1,29 @@
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include "sway/config.h"
+#include "sway/commands.h"
+#include "sway/input/input-manager.h"
+#include "util.h"
+
+struct cmd_results *input_cmd_rotation_angle(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "rotation_angle", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ struct input_config *ic = config->handler_context.input_config;
+ if (!ic) {
+ return cmd_results_new(CMD_FAILURE, "No input device defined.");
+ }
+
+ float rotation_angle = parse_float(argv[0]);
+ if (isnan(rotation_angle)) {
+ return cmd_results_new(CMD_INVALID,
+ "Invalid rotation_angle; expected float.");
+ } if (rotation_angle < 0 || rotation_angle > 360) {
+ return cmd_results_new(CMD_INVALID, "Input out of range [0, 360)");
+ }
+ ic->rotation_angle = rotation_angle;
+
+ return cmd_results_new(CMD_SUCCESS, NULL);
+}
diff --git a/sway/commands/input/scroll_button.c b/sway/commands/input/scroll_button.c
index 6b331419..81f69a6d 100644
--- a/sway/commands/input/scroll_button.c
+++ b/sway/commands/input/scroll_button.c
@@ -21,7 +21,7 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {
char *message = NULL;
uint32_t button = get_mouse_button(*argv, &message);
if (message) {
- error = cmd_results_new(CMD_INVALID, message);
+ error = cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN
diff --git a/sway/commands/input/scroll_button_lock.c b/sway/commands/input/scroll_button_lock.c
new file mode 100644
index 00000000..f96b6514
--- /dev/null
+++ b/sway/commands/input/scroll_button_lock.c
@@ -0,0 +1,26 @@
+#include <libinput.h>
+#include <string.h>
+#include <strings.h>
+#include "sway/config.h"
+#include "sway/commands.h"
+#include "sway/input/input-manager.h"
+#include "util.h"
+
+struct cmd_results *input_cmd_scroll_button_lock(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "scroll_button_lock", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ struct input_config *ic = config->handler_context.input_config;
+ if (!ic) {
+ return cmd_results_new(CMD_FAILURE, "No input device defined.");
+ }
+
+ if (parse_boolean(argv[0], true)) {
+ ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED;
+ } else {
+ ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED;
+ }
+
+ return cmd_results_new(CMD_SUCCESS, NULL);
+}