diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/input-manager.c | 54 | ||||
-rw-r--r-- | sway/input/seat.c | 24 |
2 files changed, 78 insertions, 0 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 285a68b8..b5ab8cc1 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -7,12 +7,52 @@ | |||
7 | #include <libinput.h> | 7 | #include <libinput.h> |
8 | #include "sway/config.h" | 8 | #include "sway/config.h" |
9 | #include "sway/input-manager.h" | 9 | #include "sway/input-manager.h" |
10 | #include "sway/seat.h" | ||
10 | #include "sway/server.h" | 11 | #include "sway/server.h" |
11 | #include "list.h" | 12 | #include "list.h" |
12 | #include "log.h" | 13 | #include "log.h" |
13 | 14 | ||
15 | static const char *default_seat = "seat0"; | ||
16 | |||
14 | struct input_config *current_input_config = NULL; | 17 | struct input_config *current_input_config = NULL; |
15 | 18 | ||
19 | static struct sway_seat *input_manager_get_seat( | ||
20 | struct sway_input_manager *input, const char *seat_name) { | ||
21 | struct sway_seat *seat = NULL; | ||
22 | |||
23 | for (int i = 0; i < input->seats->length; ++i) { | ||
24 | seat = input->seats->items[i]; | ||
25 | if (strcmp(seat->seat->name, seat_name) == 0) { | ||
26 | return seat; | ||
27 | } | ||
28 | } | ||
29 | |||
30 | seat = sway_seat_create(input->server->wl_display, seat_name); | ||
31 | list_add(input->seats, seat); | ||
32 | |||
33 | return seat; | ||
34 | } | ||
35 | |||
36 | static void input_add_notify(struct wl_listener *listener, void *data) { | ||
37 | struct sway_input_manager *input = | ||
38 | wl_container_of(listener, input, input_add); | ||
39 | struct wlr_input_device *device = data; | ||
40 | |||
41 | // TODO device configuration | ||
42 | struct sway_seat *seat = input_manager_get_seat(input, default_seat); | ||
43 | sway_seat_add_device(seat, device); | ||
44 | } | ||
45 | |||
46 | static void input_remove_notify(struct wl_listener *listener, void *data) { | ||
47 | struct sway_input_manager *input = | ||
48 | wl_container_of(listener, input, input_remove); | ||
49 | struct wlr_input_device *device = data; | ||
50 | |||
51 | // TODO device configuration | ||
52 | struct sway_seat *seat = input_manager_get_seat(input, default_seat); | ||
53 | sway_seat_remove_device(seat, device); | ||
54 | } | ||
55 | |||
16 | struct sway_input_manager *sway_input_manager_create( | 56 | struct sway_input_manager *sway_input_manager_create( |
17 | struct sway_server *server) { | 57 | struct sway_server *server) { |
18 | struct sway_input_manager *input = | 58 | struct sway_input_manager *input = |
@@ -20,6 +60,20 @@ struct sway_input_manager *sway_input_manager_create( | |||
20 | if (!input) { | 60 | if (!input) { |
21 | return NULL; | 61 | return NULL; |
22 | } | 62 | } |
63 | // XXX probably don't need the full server | ||
64 | input->server = server; | ||
65 | |||
66 | input->seats = create_list(); | ||
67 | |||
68 | // create the default seat | ||
69 | input_manager_get_seat(input, default_seat); | ||
70 | |||
71 | input->input_add.notify = input_add_notify; | ||
72 | wl_signal_add(&server->backend->events.input_add, &input->input_add); | ||
73 | |||
74 | input->input_remove.notify = input_remove_notify; | ||
75 | wl_signal_add(&server->backend->events.input_remove, &input->input_remove); | ||
76 | |||
23 | return input; | 77 | return input; |
24 | } | 78 | } |
25 | 79 | ||
diff --git a/sway/input/seat.c b/sway/input/seat.c new file mode 100644 index 00000000..f41b6dba --- /dev/null +++ b/sway/input/seat.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include "sway/seat.h" | ||
3 | #include "sway/input-manager.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct sway_seat *sway_seat_create(struct wl_display *display, | ||
7 | const char *seat_name) { | ||
8 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); | ||
9 | if (!seat) { | ||
10 | return NULL; | ||
11 | } | ||
12 | seat->seat = wlr_seat_create(display, seat_name); | ||
13 | return seat; | ||
14 | } | ||
15 | |||
16 | void sway_seat_add_device(struct sway_seat *seat, | ||
17 | struct wlr_input_device *device) { | ||
18 | sway_log(L_DEBUG, "input add: %s", device->name); | ||
19 | } | ||
20 | |||
21 | void sway_seat_remove_device(struct sway_seat *seat, | ||
22 | struct wlr_input_device *device) { | ||
23 | sway_log(L_DEBUG, "input remove: %s", device->name); | ||
24 | } | ||