diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-07 09:58:32 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-07 09:58:32 -0500 |
commit | f6f63f60d6c7f9602dd1c07b45eb45a97e5b6f5a (patch) | |
tree | d1a2e6ae45c827956f4bd181aad3cdea82d32804 | |
parent | rename input to input-manager (diff) | |
download | sway-f6f63f60d6c7f9602dd1c07b45eb45a97e5b6f5a.tar.gz sway-f6f63f60d6c7f9602dd1c07b45eb45a97e5b6f5a.tar.zst sway-f6f63f60d6c7f9602dd1c07b45eb45a97e5b6f5a.zip |
basic input manager and seat
-rw-r--r-- | include/sway/input-manager.h | 9 | ||||
-rw-r--r-- | include/sway/seat.h | 20 | ||||
-rw-r--r-- | sway/input/input-manager.c | 54 | ||||
-rw-r--r-- | sway/input/seat.c | 24 | ||||
-rw-r--r-- | sway/meson.build | 1 |
5 files changed, 105 insertions, 3 deletions
diff --git a/include/sway/input-manager.h b/include/sway/input-manager.h index a3662f7b..4c01a043 100644 --- a/include/sway/input-manager.h +++ b/include/sway/input-manager.h | |||
@@ -1,12 +1,15 @@ | |||
1 | #ifndef _SWAY_INPUT_H | 1 | #ifndef _SWAY_INPUT_MANAGER_H |
2 | #define _SWAY_INPUT_H | 2 | #define _SWAY_INPUT_MANAGER_H |
3 | #include <libinput.h> | 3 | #include <libinput.h> |
4 | #include "sway/server.h" | 4 | #include "sway/server.h" |
5 | #include "config.h" | 5 | #include "config.h" |
6 | #include "list.h" | 6 | #include "list.h" |
7 | 7 | ||
8 | struct sway_input_manager { | 8 | struct sway_input_manager { |
9 | list_t *input_devices; | 9 | struct wl_listener input_add; |
10 | struct wl_listener input_remove; | ||
11 | struct sway_server *server; | ||
12 | list_t *seats; | ||
10 | }; | 13 | }; |
11 | 14 | ||
12 | struct input_config *new_input_config(const char* identifier); | 15 | struct input_config *new_input_config(const char* identifier); |
diff --git a/include/sway/seat.h b/include/sway/seat.h new file mode 100644 index 00000000..a2b8fe51 --- /dev/null +++ b/include/sway/seat.h | |||
@@ -0,0 +1,20 @@ | |||
1 | #ifndef _SWAY_SEAT_H | ||
2 | #define _SWAY_SEAT_H | ||
3 | |||
4 | #include <wlr/types/wlr_seat.h> | ||
5 | #include "sway/input-manager.h" | ||
6 | |||
7 | struct sway_seat { | ||
8 | struct wlr_seat *seat; | ||
9 | }; | ||
10 | |||
11 | struct sway_seat *sway_seat_create(struct wl_display *display, | ||
12 | const char *seat_name); | ||
13 | |||
14 | void sway_seat_add_device(struct sway_seat *seat, | ||
15 | struct wlr_input_device *device); | ||
16 | |||
17 | void sway_seat_remove_device(struct sway_seat *seat, | ||
18 | struct wlr_input_device *device); | ||
19 | |||
20 | #endif | ||
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 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index b5cdbbf2..cea565d6 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -3,6 +3,7 @@ sway_sources = files( | |||
3 | 'server.c', | 3 | 'server.c', |
4 | 'commands.c', | 4 | 'commands.c', |
5 | 'input/input-manager.c', | 5 | 'input/input-manager.c', |
6 | 'input/seat.c', | ||
6 | 'commands/exit.c', | 7 | 'commands/exit.c', |
7 | 'commands/exec.c', | 8 | 'commands/exec.c', |
8 | 'commands/exec_always.c', | 9 | 'commands/exec_always.c', |