Move seat into extra file

This commit is contained in:
buffet 2020-01-18 15:14:19 +00:00
parent b909262f5a
commit c0b0418af8
9 changed files with 126 additions and 47 deletions

View file

@ -39,7 +39,6 @@ struct kiwmi_cursor {
struct wl_listener cursor_button; struct wl_listener cursor_button;
struct wl_listener cursor_axis; struct wl_listener cursor_axis;
struct wl_listener cursor_frame; struct wl_listener cursor_frame;
struct wl_listener seat_request_set_cursor;
struct { struct {
struct wl_signal button_down; struct wl_signal button_down;

View file

@ -14,7 +14,7 @@ struct kiwmi_input {
struct wl_list keyboards; // struct kiwmi_keyboard::link struct wl_list keyboards; // struct kiwmi_keyboard::link
struct wl_listener new_input; struct wl_listener new_input;
struct kiwmi_cursor *cursor; struct kiwmi_cursor *cursor;
struct wlr_seat *seat; struct kiwmi_seat *seat;
struct { struct {
struct wl_signal keyboard_new; struct wl_signal keyboard_new;

25
include/input/seat.h Normal file
View file

@ -0,0 +1,25 @@
/* 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_SEAT_H
#define KIWMI_INPUT_SEAT_H
#include <wayland-server.h>
#include "input/input.h"
struct kiwmi_seat {
struct kiwmi_input *input;
struct wlr_seat *seat;
struct wl_listener request_set_cursor;
};
struct kiwmi_seat *seat_create(struct kiwmi_input *input);
void seat_destroy(struct kiwmi_seat *seat);
#endif /* KIWMI_INPUT_SEAT_H */

View file

@ -12,6 +12,7 @@
#include "desktop/output.h" #include "desktop/output.h"
#include "input/cursor.h" #include "input/cursor.h"
#include "input/seat.h"
#include "server.h" #include "server.h"
void void
@ -89,7 +90,7 @@ view_focus(struct kiwmi_view *view)
struct kiwmi_desktop *desktop = view->desktop; struct kiwmi_desktop *desktop = view->desktop;
struct kiwmi_server *server = wl_container_of(desktop, server, desktop); struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
struct wlr_seat *seat = server->input.seat; struct wlr_seat *seat = server->input.seat->seat;
if (view == desktop->focused_view) { if (view == desktop->focused_view) {
return; return;
@ -174,7 +175,7 @@ view_begin_interactive(
struct kiwmi_server *server = wl_container_of(desktop, server, desktop); struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
struct kiwmi_cursor *cursor = server->input.cursor; struct kiwmi_cursor *cursor = server->input.cursor;
struct wlr_surface *focused_surface = struct wlr_surface *focused_surface =
server->input.seat->pointer_state.focused_surface; server->input.seat->seat->pointer_state.focused_surface;
struct wlr_surface *wlr_surface = view->wlr_surface; struct wlr_surface *wlr_surface = view->wlr_surface;
if (wlr_surface != focused_surface) { if (wlr_surface != focused_surface) {

View file

@ -19,8 +19,8 @@
#include "desktop/desktop.h" #include "desktop/desktop.h"
#include "desktop/view.h" #include "desktop/view.h"
#include "input/seat.h"
#include "server.h" #include "server.h"
#include "wlr/util/edges.h"
static void static void
process_cursor_motion(struct kiwmi_server *server, uint32_t time) process_cursor_motion(struct kiwmi_server *server, uint32_t time)
@ -28,7 +28,7 @@ process_cursor_motion(struct kiwmi_server *server, uint32_t time)
struct kiwmi_desktop *desktop = &server->desktop; struct kiwmi_desktop *desktop = &server->desktop;
struct kiwmi_input *input = &server->input; struct kiwmi_input *input = &server->input;
struct kiwmi_cursor *cursor = input->cursor; struct kiwmi_cursor *cursor = input->cursor;
struct wlr_seat *seat = input->seat; struct wlr_seat *seat = input->seat->seat;
switch (cursor->cursor_mode) { switch (cursor->cursor_mode) {
case KIWMI_CURSOR_MOVE: { case KIWMI_CURSOR_MOVE: {
@ -174,7 +174,7 @@ cursor_button_notify(struct wl_listener *listener, void *data)
if (!new_event.handled) { if (!new_event.handled) {
wlr_seat_pointer_notify_button( wlr_seat_pointer_notify_button(
input->seat, event->time_msec, event->button, event->state); input->seat->seat, event->time_msec, event->button, event->state);
} }
cursor->cursor_mode = KIWMI_CURSOR_PASSTHROUGH; cursor->cursor_mode = KIWMI_CURSOR_PASSTHROUGH;
@ -190,7 +190,7 @@ cursor_axis_notify(struct wl_listener *listener, void *data)
struct wlr_event_pointer_axis *event = data; struct wlr_event_pointer_axis *event = data;
wlr_seat_pointer_notify_axis( wlr_seat_pointer_notify_axis(
input->seat, input->seat->seat,
event->time_msec, event->time_msec,
event->orientation, event->orientation,
event->delta, event->delta,
@ -206,32 +206,7 @@ cursor_frame_notify(struct wl_listener *listener, void *UNUSED(data))
struct kiwmi_server *server = cursor->server; struct kiwmi_server *server = cursor->server;
struct kiwmi_input *input = &server->input; struct kiwmi_input *input = &server->input;
wlr_seat_pointer_notify_frame(input->seat); wlr_seat_pointer_notify_frame(input->seat->seat);
}
static void
seat_request_set_cursor_notify(struct wl_listener *listener, void *data)
{
struct kiwmi_cursor *cursor =
wl_container_of(listener, cursor, seat_request_set_cursor);
struct wlr_seat_pointer_request_set_cursor_event *event = data;
struct wlr_surface *focused_surface =
event->seat_client->seat->pointer_state.focused_surface;
struct wl_client *focused_client = NULL;
if (focused_surface && focused_surface->resource) {
focused_client = wl_resource_get_client(focused_surface->resource);
}
if (event->seat_client->client != focused_client) {
wlr_log(
WLR_DEBUG, "Ignoring request to set cursor on unfocused client");
return;
}
wlr_cursor_set_surface(
cursor->cursor, event->surface, event->hotspot_x, event->hotspot_y);
} }
struct kiwmi_cursor * struct kiwmi_cursor *
@ -278,11 +253,6 @@ cursor_create(
cursor->cursor_frame.notify = cursor_frame_notify; cursor->cursor_frame.notify = cursor_frame_notify;
wl_signal_add(&cursor->cursor->events.frame, &cursor->cursor_frame); wl_signal_add(&cursor->cursor->events.frame, &cursor->cursor_frame);
cursor->seat_request_set_cursor.notify = seat_request_set_cursor_notify;
wl_signal_add(
&server->input.seat->events.request_set_cursor,
&cursor->seat_request_set_cursor);
wl_signal_init(&cursor->events.button_down); wl_signal_init(&cursor->events.button_down);
wl_signal_init(&cursor->events.button_up); wl_signal_init(&cursor->events.button_up);
wl_signal_init(&cursor->events.motion); wl_signal_init(&cursor->events.motion);
@ -301,7 +271,6 @@ cursor_destroy(struct kiwmi_cursor *cursor)
wl_list_remove(&cursor->cursor_button.link); wl_list_remove(&cursor->cursor_button.link);
wl_list_remove(&cursor->cursor_axis.link); wl_list_remove(&cursor->cursor_axis.link);
wl_list_remove(&cursor->cursor_frame.link); wl_list_remove(&cursor->cursor_frame.link);
wl_list_remove(&cursor->seat_request_set_cursor.link);
free(cursor); free(cursor);
} }

View file

@ -19,6 +19,7 @@
#include "desktop/desktop.h" #include "desktop/desktop.h"
#include "input/cursor.h" #include "input/cursor.h"
#include "input/keyboard.h" #include "input/keyboard.h"
#include "input/seat.h"
#include "server.h" #include "server.h"
static void static void
@ -65,7 +66,7 @@ new_input_notify(struct wl_listener *listener, void *data)
caps |= WL_SEAT_CAPABILITY_KEYBOARD; caps |= WL_SEAT_CAPABILITY_KEYBOARD;
} }
wlr_seat_set_capabilities(input->seat, caps); wlr_seat_set_capabilities(input->seat->seat, caps);
} }
bool bool
@ -73,7 +74,10 @@ input_init(struct kiwmi_input *input)
{ {
struct kiwmi_server *server = wl_container_of(input, server, input); struct kiwmi_server *server = wl_container_of(input, server, input);
input->seat = wlr_seat_create(server->wl_display, "seat-0"); input->seat = seat_create(input);
if (!input->seat) {
return false;
}
input->cursor = cursor_create(server, server->desktop.output_layout); input->cursor = cursor_create(server, server->desktop.output_layout);
if (!input->cursor) { if (!input->cursor) {
@ -100,5 +104,7 @@ input_fini(struct kiwmi_input *input)
free(keyboard); free(keyboard);
} }
seat_destroy(input->seat);
cursor_destroy(input->cursor); cursor_destroy(input->cursor);
} }

View file

@ -18,6 +18,7 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include "input/seat.h"
#include "server.h" #include "server.h"
static bool static bool
@ -46,9 +47,10 @@ keyboard_modifiers_notify(struct wl_listener *listener, void *UNUSED(data))
{ {
struct kiwmi_keyboard *keyboard = struct kiwmi_keyboard *keyboard =
wl_container_of(listener, keyboard, modifiers); wl_container_of(listener, keyboard, modifiers);
wlr_seat_set_keyboard(keyboard->server->input.seat, keyboard->device); wlr_seat_set_keyboard(keyboard->server->input.seat->seat, keyboard->device);
wlr_seat_keyboard_notify_modifiers( wlr_seat_keyboard_notify_modifiers(
keyboard->server->input.seat, &keyboard->device->keyboard->modifiers); keyboard->server->input.seat->seat,
&keyboard->device->keyboard->modifiers);
} }
static void static void
@ -87,9 +89,12 @@ keyboard_key_notify(struct wl_listener *listener, void *data)
} }
if (!handled) { if (!handled) {
wlr_seat_set_keyboard(server->input.seat, keyboard->device); wlr_seat_set_keyboard(server->input.seat->seat, keyboard->device);
wlr_seat_keyboard_notify_key( wlr_seat_keyboard_notify_key(
server->input.seat, event->time_msec, event->keycode, event->state); server->input.seat->seat,
event->time_msec,
event->keycode,
event->state);
} }
} }
@ -141,7 +146,7 @@ keyboard_create(struct kiwmi_server *server, struct wlr_input_device *device)
xkb_context_unref(context); xkb_context_unref(context);
wlr_keyboard_set_repeat_info(device->keyboard, 25, 600); wlr_keyboard_set_repeat_info(device->keyboard, 25, 600);
wlr_seat_set_keyboard(server->input.seat, device); wlr_seat_set_keyboard(server->input.seat->seat, device);
wl_signal_init(&keyboard->events.key_down); wl_signal_init(&keyboard->events.key_down);
wl_signal_init(&keyboard->events.key_up); wl_signal_init(&keyboard->events.key_up);

73
kiwmi/input/seat.c Normal file
View file

@ -0,0 +1,73 @@
/* 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 "input/seat.h"
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>
#include "input/cursor.h"
#include "server.h"
static void
request_set_cursor_notify(struct wl_listener *listener, void *data)
{
struct kiwmi_seat *seat =
wl_container_of(listener, seat, request_set_cursor);
struct kiwmi_cursor *cursor = seat->input->cursor;
struct wlr_seat_pointer_request_set_cursor_event *event = data;
struct wlr_surface *focused_surface =
event->seat_client->seat->pointer_state.focused_surface;
struct wl_client *focused_client = NULL;
if (focused_surface && focused_surface->resource) {
focused_client = wl_resource_get_client(focused_surface->resource);
}
if (event->seat_client->client != focused_client) {
wlr_log(
WLR_DEBUG, "Ignoring request to set cursor on unfocused client");
return;
}
wlr_cursor_set_surface(
cursor->cursor, event->surface, event->hotspot_x, event->hotspot_y);
}
struct kiwmi_seat *
seat_create(struct kiwmi_input *input)
{
struct kiwmi_server *server = wl_container_of(input, server, input);
struct kiwmi_seat *seat = malloc(sizeof(*seat));
if (!seat) {
wlr_log(WLR_ERROR, "Failed to allocate kiwmi_seat");
return NULL;
}
seat->input = input;
seat->seat = wlr_seat_create(server->wl_display, "seat-0");
seat->request_set_cursor.notify = request_set_cursor_notify;
wl_signal_add(
&seat->seat->events.request_set_cursor, &seat->request_set_cursor);
return seat;
}
void
seat_destroy(struct kiwmi_seat *seat)
{
wl_list_remove(&seat->request_set_cursor.link);
free(seat);
}

View file

@ -9,6 +9,7 @@ kiwmi_sources = files(
'input/cursor.c', 'input/cursor.c',
'input/input.c', 'input/input.c',
'input/keyboard.c', 'input/keyboard.c',
'input/seat.c',
'luak/ipc.c', 'luak/ipc.c',
'luak/kiwmi_cursor.c', 'luak/kiwmi_cursor.c',
'luak/kiwmi_keyboard.c', 'luak/kiwmi_keyboard.c',