#include <libds/backend/libinput.h>
#include <libds/input_device.h>
#include <libds/keyboard.h>
+#include <libds/seat.h>
+#include <xkbcommon/xkbcommon.h>
+
+#include "headless_server.h"
typedef struct headless_input headless_input_t;
typedef struct headless_keyboard headless_keyboard_t;
struct headless_input
{
+ headless_server_t *server;
headless_keyboard_t *keyboard;
- struct wl_display *display;
struct ds_backend *backend;
+ struct ds_seat *seat;
struct wl_listener new_input;
+ struct wl_listener focus_change;
};
struct headless_keyboard
struct wl_listener key;
};
+static void handle_focus_change(struct wl_listener *listener, void *data);
static void handle_new_input(struct wl_listener *listener, void *data);
-static void add_keyboard(headless_input_t *input, struct ds_input_device *dev);
+static headless_keyboard_t *create_keyboard(headless_input_t *input,
+ struct ds_input_device *dev);
static void keyboard_destroy(headless_keyboard_t *keyboard);
static void keyboard_handle_destroy(struct wl_listener *listener, void *data);
static void keyboard_handle_key(struct wl_listener *listener, void *data);
headless_input_t *
-headless_input_create(struct wl_display *display)
+headless_input_create(headless_server_t *server)
{
headless_input_t *input;
if (!input)
return NULL;
- input->display = display;
+ input->server = server;
- input->backend = ds_libinput_backend_create(display);
+ input->backend = ds_libinput_backend_create(server->display);
if (!input->backend) {
ds_err("Could not create libinput backend");
- free(input);
- return NULL;
+ goto err_backend;
+ }
+
+ input->seat = ds_seat_create(server->display, "seat0");
+ if (!input->seat) {
+ ds_err("Could not create ds_seat");
+ goto err_seat;
}
input->new_input.notify = handle_new_input;
ds_backend_add_new_input_listener(input->backend, &input->new_input);
+ input->focus_change.notify = handle_focus_change;
+ wl_signal_add(&server->events.focus_change, &input->focus_change);
+
ds_backend_start(input->backend);
ds_inf("Created Headless input(%p)", input);
return input;
+
+err_seat:
+ ds_backend_destroy(input->backend);
+err_backend:
+ free(input);
+
+ return NULL;
}
void
if (input->keyboard)
keyboard_destroy(input->keyboard);
+ wl_list_remove(&input->focus_change.link);
wl_list_remove(&input->new_input.link);
+
ds_backend_destroy(input->backend);
free(input);
}
+static void
+handle_focus_change(struct wl_listener *listener, void *data)
+{
+ headless_input_t *input;
+ headless_view_t *view = data;
+
+ input = wl_container_of(listener, input, focus_change);
+
+ if (view) {
+ ds_seat_keyboard_notify_enter(input->seat, view->surface,
+ NULL, 0, NULL /* TODO */);
+ }
+ else {
+ ds_seat_keyboard_notify_clear_focus(input->seat);
+ }
+}
static void
handle_new_input(struct wl_listener *listener, void *data)
dev_type = ds_input_device_get_type(dev);
- ds_inf("Input(%p): New input device(%p) type(%d)",
- input, dev, ds_input_device_get_type(dev));
+ ds_inf("Input(%p): New input device(%p) type(%d)", input, dev, dev_type);
- switch (dev_type) {
- case DS_INPUT_DEVICE_KEYBOARD:
- add_keyboard(input, dev);
- break;
- default:
- ds_inf("Not supported device, type(%d)", dev_type);
- break;
+ if (dev_type != DS_INPUT_DEVICE_KEYBOARD) {
+ ds_inf("Not supported device: type(%d)", dev_type);
+ return;
}
-}
-
-static void
-add_keyboard(headless_input_t *input, struct ds_input_device *dev)
-{
- headless_keyboard_t *keyboard;
- struct ds_keyboard *ds_keyboard;
if (input->keyboard) {
ds_inf("Already created keyboard device(%p)", input->keyboard);
return;
}
+ input->keyboard = create_keyboard(input, dev);
+ if (!input->keyboard) {
+ ds_err("Could not create keyboard");
+ return;
+ }
+
+ ds_seat_set_keyboard(input->seat, dev);
+ ds_seat_set_capabilities(input->seat, WL_SEAT_CAPABILITY_KEYBOARD);
+}
+
+static headless_keyboard_t *
+create_keyboard(headless_input_t *input, struct ds_input_device *dev)
+{
+ headless_keyboard_t *keyboard;
+ struct ds_keyboard *ds_keyboard;
+ struct xkb_context *context;
+ struct xkb_keymap *keymap;
+
keyboard = calloc(1, sizeof *keyboard);
if (!keyboard) {
ds_err("Could not allocate memory");
- return;
+ return false;
}
keyboard->input = input;
keyboard->key.notify = keyboard_handle_key;
ds_keyboard_add_key_listener(ds_keyboard, &keyboard->key);
- input->keyboard = keyboard;
+ context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ keymap = xkb_keymap_new_from_names(context, NULL,
+ XKB_KEYMAP_COMPILE_NO_FLAGS);
+ ds_keyboard_set_keymap(ds_keyboard, keymap);
+ xkb_keymap_unref(keymap);
+ xkb_context_unref(context);
ds_inf("Input(%p): New keyboard(%p)", input, keyboard);
+
+ return keyboard;
}
static void
ds_inf("Keyboard(%p) key: keycode(%d), state(%d), time_msec(%d), "
"update_state(%d)", keyboard, event->keycode, event->state,
event->time_msec, event->update_state);
+
+ ds_seat_keyboard_notify_key(keyboard->input->seat, event->time_msec,
+ event->keycode, event->state);
}
#else
#include <pepper-evdev.h>