aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/cursor.c15
-rw-r--r--sway/input/input-manager.c10
-rw-r--r--sway/input/keyboard.c29
3 files changed, 10 insertions, 44 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 15687993..75d055cd 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -1273,11 +1273,7 @@ uint32_t get_mouse_bindsym(const char *name, char **error) {
1273 // Get event code from name 1273 // Get event code from name
1274 int code = libevdev_event_code_from_name(EV_KEY, name); 1274 int code = libevdev_event_code_from_name(EV_KEY, name);
1275 if (code == -1) { 1275 if (code == -1) {
1276 size_t len = snprintf(NULL, 0, "Unknown event %s", name) + 1; 1276 *error = format_str("Unknown event %s", name);
1277 *error = malloc(len);
1278 if (*error) {
1279 snprintf(*error, len, "Unknown event %s", name);
1280 }
1281 return 0; 1277 return 0;
1282 } 1278 }
1283 return code; 1279 return code;
@@ -1299,13 +1295,8 @@ uint32_t get_mouse_bindcode(const char *name, char **error) {
1299 } 1295 }
1300 const char *event = libevdev_event_code_get_name(EV_KEY, code); 1296 const char *event = libevdev_event_code_get_name(EV_KEY, code);
1301 if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) { 1297 if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) {
1302 size_t len = snprintf(NULL, 0, "Event code %d (%s) is not a button", 1298 *error = format_str("Event code %d (%s) is not a button",
1303 code, event ? event : "(null)") + 1; 1299 code, event ? event : "(null)");
1304 *error = malloc(len);
1305 if (*error) {
1306 snprintf(*error, len, "Event code %d (%s) is not a button",
1307 code, event ? event : "(null)");
1308 }
1309 return 0; 1300 return 0;
1310 } 1301 }
1311 return code; 1302 return code;
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index ea2cc038..1115ba5e 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -80,15 +80,7 @@ char *input_device_get_identifier(struct wlr_input_device *device) {
80 } 80 }
81 } 81 }
82 82
83 const char *fmt = "%d:%d:%s"; 83 char *identifier = format_str("%d:%d:%s", vendor, product, name);
84 int len = snprintf(NULL, 0, fmt, vendor, product, name) + 1;
85 char *identifier = malloc(len);
86 if (!identifier) {
87 sway_log(SWAY_ERROR, "Unable to allocate unique input device name");
88 return NULL;
89 }
90
91 snprintf(identifier, len, fmt, vendor, product, name);
92 free(name); 84 free(name);
93 return identifier; 85 return identifier;
94} 86}
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 45a588ec..c3bf4fbb 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -717,23 +717,11 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
717 717
718static void handle_xkb_context_log(struct xkb_context *context, 718static void handle_xkb_context_log(struct xkb_context *context,
719 enum xkb_log_level level, const char *format, va_list args) { 719 enum xkb_log_level level, const char *format, va_list args) {
720 va_list args_copy; 720 char *error = vformat_str(format, args);
721 va_copy(args_copy, args);
722 size_t length = vsnprintf(NULL, 0, format, args_copy) + 1;
723 va_end(args_copy);
724
725 char *error = malloc(length);
726 if (!error) {
727 sway_log(SWAY_ERROR, "Failed to allocate libxkbcommon log message");
728 return;
729 }
730 721
731 va_copy(args_copy, args); 722 size_t len = strlen(error);
732 vsnprintf(error, length, format, args_copy); 723 if (error[len - 1] == '\n') {
733 va_end(args_copy); 724 error[len - 1] = '\0';
734
735 if (error[length - 2] == '\n') {
736 error[length - 2] = '\0';
737 } 725 }
738 726
739 sway_log_importance_t importance = SWAY_DEBUG; 727 sway_log_importance_t importance = SWAY_DEBUG;
@@ -768,13 +756,8 @@ struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic,
768 if (!keymap_file) { 756 if (!keymap_file) {
769 sway_log_errno(SWAY_ERROR, "cannot read xkb file %s", ic->xkb_file); 757 sway_log_errno(SWAY_ERROR, "cannot read xkb file %s", ic->xkb_file);
770 if (error) { 758 if (error) {
771 size_t len = snprintf(NULL, 0, "cannot read xkb file %s: %s", 759 *error = format_str("cannot read xkb file %s: %s",
772 ic->xkb_file, strerror(errno)) + 1; 760 ic->xkb_file, strerror(errno));
773 *error = malloc(len);
774 if (*error) {
775 snprintf(*error, len, "cannot read xkb_file %s: %s",
776 ic->xkb_file, strerror(errno));
777 }
778 } 761 }
779 goto cleanup; 762 goto cleanup;
780 } 763 }