Added input_init
This commit is contained in:
parent
593303e672
commit
b5589ef47f
7 changed files with 66 additions and 13 deletions
20
include/kiwmi/input/input.h
Normal file
20
include/kiwmi/input/input.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* Copyright (c), Niclas Meyer <niclas@countingsort.com>
|
||||
*
|
||||
* 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 <wayland-server.h>
|
||||
|
||||
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 */
|
|
@ -12,14 +12,14 @@
|
|||
#include <wlr/backend.h>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "kiwmi/desktop/output.h"
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
|
|
|
@ -11,40 +11,45 @@
|
|||
#include <wlr/types/wlr_input_device.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#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
|
||||
|
|
24
kiwmi/input/input.c
Normal file
24
kiwmi/input/input.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* Copyright (c), Niclas Meyer <niclas@countingsort.com>
|
||||
*
|
||||
* 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 <wayland-server.h>
|
||||
|
||||
#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);
|
||||
}
|
|
@ -6,6 +6,7 @@ kiwmi_sources = files(
|
|||
'desktop/desktop.c',
|
||||
'desktop/output.c',
|
||||
'input/cursor.c',
|
||||
'input/input.c',
|
||||
'input/keyboard.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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue