Added input_init
This commit is contained in:
parent
5b91ce1835
commit
b3eed39a82
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), Charlotte Meyer <dev@buffet.sh>
|
||||||
|
*
|
||||||
|
* 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 <wlr/backend.h>
|
||||||
|
|
||||||
#include "kiwmi/desktop/desktop.h"
|
#include "kiwmi/desktop/desktop.h"
|
||||||
|
#include "kiwmi/input/input.h"
|
||||||
|
|
||||||
struct kiwmi_server {
|
struct kiwmi_server {
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
struct wlr_backend *backend;
|
struct wlr_backend *backend;
|
||||||
const char *socket;
|
const char *socket;
|
||||||
struct kiwmi_desktop desktop;
|
struct kiwmi_desktop desktop;
|
||||||
struct wl_list keyboards; // struct kiwmi_keyboard::link
|
struct kiwmi_input input;
|
||||||
struct wl_listener new_input;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool server_init(struct kiwmi_server *server);
|
bool server_init(struct kiwmi_server *server);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "kiwmi/desktop/output.h"
|
#include "kiwmi/desktop/output.h"
|
||||||
|
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
|
|
|
@ -11,40 +11,45 @@
|
||||||
#include <wlr/types/wlr_input_device.h>
|
#include <wlr/types/wlr_input_device.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
#include "kiwmi/input/keyboard.h"
|
|
||||||
#include "kiwmi/server.h"
|
#include "kiwmi/server.h"
|
||||||
|
#include "kiwmi/input/input.h"
|
||||||
|
#include "kiwmi/input/keyboard.h"
|
||||||
|
|
||||||
static void
|
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);
|
wlr_cursor_attach_input_device(server->desktop.cursor->cursor, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
struct kiwmi_keyboard *keyboard = keyboard_create(server, device);
|
||||||
if (!keyboard) {
|
if (!keyboard) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_insert(&server->keyboards, &keyboard->link);
|
wl_list_insert(&input->keyboards, &keyboard->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
new_input_notify(struct wl_listener *listener, void *data)
|
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;
|
struct wlr_input_device *device = data;
|
||||||
|
|
||||||
wlr_log(WLR_DEBUG, "New input %p: %s", device, device->name);
|
wlr_log(WLR_DEBUG, "New input %p: %s", device, device->name);
|
||||||
|
|
||||||
switch (device->type) {
|
switch (device->type) {
|
||||||
case WLR_INPUT_DEVICE_POINTER:
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
new_pointer(server, device);
|
new_pointer(input, device);
|
||||||
break;
|
break;
|
||||||
case WLR_INPUT_DEVICE_KEYBOARD:
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||||
new_keyboard(server, device);
|
new_keyboard(input, device);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// NOT HANDLED
|
// NOT HANDLED
|
||||||
|
|
24
kiwmi/input/input.c
Normal file
24
kiwmi/input/input.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||||
|
*
|
||||||
|
* 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/desktop.c',
|
||||||
'desktop/output.c',
|
'desktop/output.c',
|
||||||
'input/cursor.c',
|
'input/cursor.c',
|
||||||
|
'input/input.c',
|
||||||
'input/keyboard.c',
|
'input/keyboard.c',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "kiwmi/desktop/desktop.h"
|
#include "kiwmi/desktop/desktop.h"
|
||||||
#include "kiwmi/input.h"
|
#include "kiwmi/input.h"
|
||||||
#include "kiwmi/input/cursor.h"
|
#include "kiwmi/input/cursor.h"
|
||||||
|
#include "kiwmi/input/input.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
server_init(struct kiwmi_server *server)
|
server_init(struct kiwmi_server *server)
|
||||||
|
@ -40,10 +41,11 @@ server_init(struct kiwmi_server *server)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_init(&server->keyboards);
|
if (!input_init(&server->input)) {
|
||||||
|
wlr_log(WLR_ERROR, "Failed to initialize input");
|
||||||
server->new_input.notify = new_input_notify;
|
wl_display_destroy(server->wl_display);
|
||||||
wl_signal_add(&server->backend->events.new_input, &server->new_input);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue