From b3eed39a8249a5e3a049ed3beab4d469bb363e3f Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Sun, 17 Mar 2019 20:17:41 +0100 Subject: [PATCH] Added input_init --- include/kiwmi/input/input.h | 20 ++++++++++++++++++++ include/kiwmi/server.h | 4 ++-- kiwmi/desktop/output.c | 1 + kiwmi/input.c | 19 ++++++++++++------- kiwmi/input/input.c | 24 ++++++++++++++++++++++++ kiwmi/meson.build | 1 + kiwmi/server.c | 10 ++++++---- 7 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 include/kiwmi/input/input.h create mode 100644 kiwmi/input/input.c diff --git a/include/kiwmi/input/input.h b/include/kiwmi/input/input.h new file mode 100644 index 0000000..bf1582d --- /dev/null +++ b/include/kiwmi/input/input.h @@ -0,0 +1,20 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef KIWMI_INPUT_INPUT_H +#define KIWMI_INPUT_INPUT_H + +#include + +struct kiwmi_input { + struct wl_list keyboards; // struct kiwmi_keyboard::link + struct wl_listener new_input; +}; + +bool input_init(struct kiwmi_input *input); + +#endif /* KIWMI_INPUT_INPUT_H */ diff --git a/include/kiwmi/server.h b/include/kiwmi/server.h index b4254ca..873d37a 100644 --- a/include/kiwmi/server.h +++ b/include/kiwmi/server.h @@ -12,14 +12,14 @@ #include #include "kiwmi/desktop/desktop.h" +#include "kiwmi/input/input.h" struct kiwmi_server { struct wl_display *wl_display; struct wlr_backend *backend; const char *socket; struct kiwmi_desktop desktop; - struct wl_list keyboards; // struct kiwmi_keyboard::link - struct wl_listener new_input; + struct kiwmi_input input; }; bool server_init(struct kiwmi_server *server); diff --git a/kiwmi/desktop/output.c b/kiwmi/desktop/output.c index 6262deb..e422da7 100644 --- a/kiwmi/desktop/output.c +++ b/kiwmi/desktop/output.c @@ -8,6 +8,7 @@ #include "kiwmi/desktop/output.h" #include +#include #include #include diff --git a/kiwmi/input.c b/kiwmi/input.c index 3caa597..cf0a3e9 100644 --- a/kiwmi/input.c +++ b/kiwmi/input.c @@ -11,40 +11,45 @@ #include #include -#include "kiwmi/input/keyboard.h" #include "kiwmi/server.h" +#include "kiwmi/input/input.h" +#include "kiwmi/input/keyboard.h" static void -new_pointer(struct kiwmi_server *server, struct wlr_input_device *device) +new_pointer(struct kiwmi_input *input, struct wlr_input_device *device) { + struct kiwmi_server *server = wl_container_of(input, server, input); + wlr_cursor_attach_input_device(server->desktop.cursor->cursor, device); } static void -new_keyboard(struct kiwmi_server *server, struct wlr_input_device *device) +new_keyboard(struct kiwmi_input *input, struct wlr_input_device *device) { + struct kiwmi_server *server = wl_container_of(input, server, input); + struct kiwmi_keyboard *keyboard = keyboard_create(server, device); if (!keyboard) { return; } - wl_list_insert(&server->keyboards, &keyboard->link); + wl_list_insert(&input->keyboards, &keyboard->link); } void new_input_notify(struct wl_listener *listener, void *data) { - struct kiwmi_server *server = wl_container_of(listener, server, new_input); + struct kiwmi_input *input = wl_container_of(listener, input, new_input); struct wlr_input_device *device = data; wlr_log(WLR_DEBUG, "New input %p: %s", device, device->name); switch (device->type) { case WLR_INPUT_DEVICE_POINTER: - new_pointer(server, device); + new_pointer(input, device); break; case WLR_INPUT_DEVICE_KEYBOARD: - new_keyboard(server, device); + new_keyboard(input, device); break; default: // NOT HANDLED diff --git a/kiwmi/input/input.c b/kiwmi/input/input.c new file mode 100644 index 0000000..ed940a7 --- /dev/null +++ b/kiwmi/input/input.c @@ -0,0 +1,24 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include "kiwmi/input/input.h" + +#include + +#include "kiwmi/input.h" +#include "kiwmi/server.h" + +bool +input_init(struct kiwmi_input *input) +{ + struct kiwmi_server *server = wl_container_of(input, server, input); + + wl_list_init(&input->keyboards); + + input->new_input.notify = new_input_notify; + wl_signal_add(&server->backend->events.new_input, &input->new_input); +} diff --git a/kiwmi/meson.build b/kiwmi/meson.build index 7f70811..e6d0902 100644 --- a/kiwmi/meson.build +++ b/kiwmi/meson.build @@ -6,6 +6,7 @@ kiwmi_sources = files( 'desktop/desktop.c', 'desktop/output.c', 'input/cursor.c', + 'input/input.c', 'input/keyboard.c', ) diff --git a/kiwmi/server.c b/kiwmi/server.c index 50c1b0d..528eb86 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -17,6 +17,7 @@ #include "kiwmi/desktop/desktop.h" #include "kiwmi/input.h" #include "kiwmi/input/cursor.h" +#include "kiwmi/input/input.h" bool server_init(struct kiwmi_server *server) @@ -40,10 +41,11 @@ server_init(struct kiwmi_server *server) return false; } - wl_list_init(&server->keyboards); - - server->new_input.notify = new_input_notify; - wl_signal_add(&server->backend->events.new_input, &server->new_input); + if (!input_init(&server->input)) { + wlr_log(WLR_ERROR, "Failed to initialize input"); + wl_display_destroy(server->wl_display); + return false; + } return true; }