aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/input-manager.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-16 14:00:23 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-16 14:03:58 -0500
commit9e4fc7253e5e82f443ae8e1a27ced12fb13f8a67 (patch)
tree840b75e5ebb75a0dac97d85da6bb4d350d9a612f /sway/input/input-manager.c
parentdevice add/remove logging (diff)
downloadsway-9e4fc7253e5e82f443ae8e1a27ced12fb13f8a67.tar.gz
sway-9e4fc7253e5e82f443ae8e1a27ced12fb13f8a67.tar.zst
sway-9e4fc7253e5e82f443ae8e1a27ced12fb13f8a67.zip
get device id correctly
Diffstat (limited to 'sway/input/input-manager.c')
-rw-r--r--sway/input/input-manager.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index 34766ee6..6a49b13b 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -5,6 +5,7 @@
5#include <stdio.h> 5#include <stdio.h>
6#include <string.h> 6#include <string.h>
7#include <libinput.h> 7#include <libinput.h>
8#include <math.h>
8#include "sway/config.h" 9#include "sway/config.h"
9#include "sway/input/input-manager.h" 10#include "sway/input/input-manager.h"
10#include "sway/input/seat.h" 11#include "sway/input/seat.h"
@@ -33,6 +34,13 @@ static struct sway_seat *input_manager_get_seat(
33 return sway_seat_create(input, seat_name); 34 return sway_seat_create(input, seat_name);
34} 35}
35 36
37static inline int strlen_num(int num) {
38 if (num == 0) {
39 return 2;
40 }
41 return (int)((ceil(log10(abs(num)))+2));
42}
43
36static char *get_device_identifier(struct wlr_input_device *device) { 44static char *get_device_identifier(struct wlr_input_device *device) {
37 int vendor = device->vendor; 45 int vendor = device->vendor;
38 int product = device->product; 46 int product = device->product;
@@ -46,9 +54,12 @@ static char *get_device_identifier(struct wlr_input_device *device) {
46 } 54 }
47 } 55 }
48 56
49 sway_log(L_DEBUG, "rewritten name %s", name); 57 int len =
58 (strlen(name) +
59 strlen_num(device->vendor) +
60 strlen_num(device->product) +
61 3) * sizeof(char);
50 62
51 int len = strlen(name) + sizeof(char) * 6;
52 char *identifier = malloc(len); 63 char *identifier = malloc(len);
53 if (!identifier) { 64 if (!identifier) {
54 sway_log(L_ERROR, "Unable to allocate unique input device name"); 65 sway_log(L_ERROR, "Unable to allocate unique input device name");