mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-17 06:59:43 -05:00
move keyboard to seat
This commit is contained in:
parent
9bd0f47efd
commit
5354fe8729
13 changed files with 176 additions and 43 deletions
|
|
@ -12,6 +12,7 @@
|
|||
#include "rootston/keyboard.h"
|
||||
#include "rootston/pointer.h"
|
||||
#include "rootston/touch.h"
|
||||
#include "rootston/seat.h"
|
||||
|
||||
static const char *device_type(enum wlr_input_device_type type) {
|
||||
switch (type) {
|
||||
|
|
@ -29,15 +30,42 @@ static const char *device_type(enum wlr_input_device_type type) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct roots_seat *input_get_seat(struct roots_input *input, char *name) {
|
||||
struct roots_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
if (strcmp(seat->seat->name, name) == 0) {
|
||||
return seat;
|
||||
}
|
||||
}
|
||||
|
||||
seat = roots_seat_create(input, name);
|
||||
return seat;
|
||||
}
|
||||
|
||||
static void input_add_notify(struct wl_listener *listener, void *data) {
|
||||
struct wlr_input_device *device = data;
|
||||
struct roots_input *input = wl_container_of(listener, input, input_add);
|
||||
|
||||
char *seat_name = "seat0";
|
||||
struct device_config *dc = config_get_device(input->config, device);
|
||||
if (dc) {
|
||||
seat_name = dc->seat;
|
||||
}
|
||||
|
||||
struct roots_seat *seat = input_get_seat(input, seat_name);
|
||||
if (!seat) {
|
||||
wlr_log(L_ERROR, "could not create roots seat");
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s", device->name,
|
||||
device->vendor, device->product, device_type(device->type));
|
||||
switch (device->type) {
|
||||
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||
roots_keyboard_create(device, input);
|
||||
case WLR_INPUT_DEVICE_KEYBOARD: {
|
||||
struct roots_keyboard *keyboard = roots_keyboard_create(device, input);
|
||||
roots_seat_add_keyboard(seat, keyboard);
|
||||
break;
|
||||
}
|
||||
case WLR_INPUT_DEVICE_POINTER:
|
||||
pointer_add(device, input);
|
||||
break;
|
||||
|
|
@ -123,6 +151,7 @@ struct roots_input *input_create(struct roots_server *server,
|
|||
wl_list_init(&input->pointers);
|
||||
wl_list_init(&input->touch);
|
||||
wl_list_init(&input->tablet_tools);
|
||||
wl_list_init(&input->seats);
|
||||
|
||||
input->input_add.notify = input_add_notify;
|
||||
wl_signal_add(&server->backend->events.input_add, &input->input_add);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <wlr/util/log.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "rootston/input.h"
|
||||
#include "rootston/seat.h"
|
||||
#include "rootston/keyboard.h"
|
||||
|
||||
static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard,
|
||||
|
|
@ -85,8 +86,8 @@ static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
|
|||
}
|
||||
|
||||
if (keysym == XKB_KEY_Escape) {
|
||||
wlr_seat_pointer_end_grab(keyboard->input->wl_seat);
|
||||
wlr_seat_keyboard_end_grab(keyboard->input->wl_seat);
|
||||
wlr_seat_pointer_end_grab(keyboard->seat->seat);
|
||||
wlr_seat_keyboard_end_grab(keyboard->seat->seat);
|
||||
}
|
||||
|
||||
uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
|
||||
|
|
@ -141,20 +142,15 @@ void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
|
|||
}
|
||||
|
||||
if (!handled) {
|
||||
wlr_seat_set_keyboard(keyboard->input->wl_seat, keyboard->device);
|
||||
wlr_seat_keyboard_notify_key(keyboard->input->wl_seat, event->time_msec,
|
||||
wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device);
|
||||
wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec,
|
||||
event->keycode, event->state);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
||||
struct roots_keyboard *keyboard = wl_container_of(listener, keyboard, key);
|
||||
struct wlr_event_keyboard_key *event = data;
|
||||
roots_keyboard_handle_key(keyboard, event);
|
||||
}
|
||||
|
||||
void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) {
|
||||
struct wlr_seat *seat = r_keyboard->input->wl_seat;
|
||||
void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard,
|
||||
struct wlr_event_keyboard_modifiers *event) {
|
||||
struct wlr_seat *seat = r_keyboard->seat->seat;
|
||||
struct wlr_keyboard *keyboard = r_keyboard->device->keyboard;
|
||||
wlr_seat_set_keyboard(seat, r_keyboard->device);
|
||||
wlr_seat_keyboard_notify_modifiers(seat,
|
||||
|
|
@ -164,12 +160,6 @@ void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) {
|
|||
keyboard->modifiers.group);
|
||||
}
|
||||
|
||||
static void handle_keyboard_modifiers(struct wl_listener *listener, void *data) {
|
||||
struct roots_keyboard *r_keyboard =
|
||||
wl_container_of(listener, r_keyboard, modifiers);
|
||||
roots_keyboard_handle_modifiers(r_keyboard);
|
||||
}
|
||||
|
||||
static void keyboard_config_merge(struct keyboard_config *config,
|
||||
struct keyboard_config *fallback) {
|
||||
if (fallback == NULL) {
|
||||
|
|
@ -192,7 +182,8 @@ static void keyboard_config_merge(struct keyboard_config *config,
|
|||
}
|
||||
}
|
||||
|
||||
struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, struct roots_input *input) {
|
||||
struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
|
||||
struct roots_input *input) {
|
||||
struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1);
|
||||
if (keyboard == NULL) {
|
||||
return NULL;
|
||||
|
|
@ -201,12 +192,7 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, st
|
|||
keyboard->device = device;
|
||||
keyboard->input = input;
|
||||
|
||||
keyboard->key.notify = handle_keyboard_key;
|
||||
wl_signal_add(&device->keyboard->events.key, &keyboard->key);
|
||||
|
||||
keyboard->modifiers.notify = handle_keyboard_modifiers;
|
||||
wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers);
|
||||
|
||||
// XXX temporary
|
||||
wl_list_insert(&input->keyboards, &keyboard->link);
|
||||
|
||||
struct keyboard_config config;
|
||||
|
|
@ -244,8 +230,6 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, st
|
|||
|
||||
void roots_keyboard_destroy(struct wlr_input_device *device, struct roots_input *input) {
|
||||
struct roots_keyboard *keyboard = device->data;
|
||||
wl_list_remove(&keyboard->key.link);
|
||||
wl_list_remove(&keyboard->modifiers.link);
|
||||
wl_list_remove(&keyboard->link);
|
||||
free(keyboard);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ sources = [
|
|||
'main.c',
|
||||
'output.c',
|
||||
'pointer.c',
|
||||
'seat.c',
|
||||
'tablet_tool.c',
|
||||
'touch.c',
|
||||
'xcursor.c',
|
||||
|
|
|
|||
66
rootston/seat.c
Normal file
66
rootston/seat.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include <wayland-server.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "rootston/input.h"
|
||||
#include "rootston/seat.h"
|
||||
#include "rootston/keyboard.h"
|
||||
|
||||
static void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
||||
struct roots_keyboard *keyboard =
|
||||
wl_container_of(listener, keyboard, keyboard_key);
|
||||
struct wlr_event_keyboard_key *event = data;
|
||||
roots_keyboard_handle_key(keyboard, event);
|
||||
}
|
||||
|
||||
static void handle_keyboard_modifiers(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct roots_keyboard *keyboard =
|
||||
wl_container_of(listener, keyboard, keyboard_modifiers);
|
||||
struct wlr_event_keyboard_modifiers *event = data;
|
||||
roots_keyboard_handle_modifiers(keyboard, event);
|
||||
}
|
||||
|
||||
struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
|
||||
struct roots_seat *seat = calloc(1, sizeof(struct roots_seat));
|
||||
if (!seat) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seat->seat = wlr_seat_create(input->server->wl_display, name);
|
||||
wlr_seat_set_capabilities(seat->seat,
|
||||
WL_SEAT_CAPABILITY_KEYBOARD |
|
||||
WL_SEAT_CAPABILITY_POINTER |
|
||||
WL_SEAT_CAPABILITY_TOUCH);
|
||||
seat->input = input;
|
||||
wl_list_insert(&input->seats, &seat->link);
|
||||
wl_list_init(&seat->keyboards);
|
||||
|
||||
return seat;
|
||||
}
|
||||
|
||||
void roots_seat_destroy(struct roots_seat *seat) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void roots_seat_add_keyboard(struct roots_seat *seat,
|
||||
struct roots_keyboard *keyboard) {
|
||||
if (keyboard->seat) {
|
||||
roots_seat_remove_keyboard(keyboard->seat, keyboard);
|
||||
}
|
||||
keyboard->seat = seat;
|
||||
wl_list_insert(&seat->keyboards, &keyboard->seat_link);
|
||||
|
||||
keyboard->keyboard_key.notify = handle_keyboard_key;
|
||||
wl_signal_add(&keyboard->device->keyboard->events.key,
|
||||
&keyboard->keyboard_key);
|
||||
|
||||
keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
|
||||
wl_signal_add(&keyboard->device->keyboard->events.modifiers,
|
||||
&keyboard->keyboard_modifiers);
|
||||
}
|
||||
|
||||
void roots_seat_remove_keyboard(struct roots_seat *seat,
|
||||
struct roots_keyboard *keyboard) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue