Initial pass on roots_input

This commit is contained in:
Drew DeVault 2017-09-23 10:13:05 -04:00
parent b6d7c3ed8e
commit 0699aa62d8
6 changed files with 135 additions and 17 deletions

View File

@ -35,6 +35,12 @@ static bool wlr_wl_backend_start(struct wlr_backend *_backend) {
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend;
wlr_log(L_INFO, "Initializating wayland backend");
wlr_wl_registry_poll(backend);
if (!(backend->compositor) || (!(backend->shell))) {
wlr_log_errno(L_ERROR, "Could not obtain retrieve required globals");
return false;
}
backend->started = true;
for (size_t i = 0; i < backend->requested_outputs; ++i) {
wlr_wl_output_create(&backend->backend);
@ -139,12 +145,6 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
return false;
}
wlr_wl_registry_poll(backend);
if (!(backend->compositor) || (!(backend->shell))) {
wlr_log_errno(L_ERROR, "Could not obtain retrieve required globals");
return false;
}
wlr_egl_init(&backend->egl, EGL_PLATFORM_WAYLAND_EXT, backend->remote_display);
wlr_egl_bind_display(&backend->egl, backend->local_display);

View File

@ -6,6 +6,7 @@
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/xcursor.h>
#include "rootston/config.h"
#include "rootston/view.h"
struct roots_keyboard {
@ -52,10 +53,10 @@ struct roots_tablet_tool {
};
enum roots_cursor_mode {
ROOTS_CURSOR_PASSTHROUGH,
ROOTS_CURSOR_MOVE,
ROOTS_CURSOR_RESIZE,
ROOTS_CURSOR_ROTATE,
ROOTS_CURSOR_PASSTHROUGH = 0,
ROOTS_CURSOR_MOVE = 1,
ROOTS_CURSOR_RESIZE = 2,
ROOTS_CURSOR_ROTATE = 3,
};
struct roots_input_event {
@ -65,16 +66,15 @@ struct roots_input_event {
};
struct roots_input {
struct roots_config *config;
// TODO: multiseat, multicursor
struct wlr_cursor *cursor;
struct wlr_xcursor *xcursor;
struct wlr_seat *wl_seat;
enum roots_cursor_mode mode;
struct roots_view *focused_view;
struct roots_view *moving_view;
struct roots_view *resizing_view;
struct roots_view *rotating_view;
struct roots_view *active_view;
int offs_x, offs_y;
// Ring buffer of input events that could trigger move/resize/rotate
@ -85,7 +85,13 @@ struct roots_input {
struct wl_list pointers;
struct wl_list touch;
struct wl_list tablet_tools;
struct wl_list tablet_pads;
struct wl_listener input_add;
struct wl_listener input_remove;
};
struct roots_input *input_create(struct roots_server *server,
struct roots_config *config);
void input_destroy(struct roots_input *input);
#endif

View File

@ -1,11 +1,12 @@
#define _POSIX_C_SOURCE 199309L
#include <time.h>
#include <stdlib.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_wl_shell.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_gamma_control.h>
#include <wlr/util/log.h>
#include "rootston/desktop.h"
#include "rootston/server.h"
@ -43,6 +44,9 @@ struct roots_desktop *desktop_create(struct roots_server *server,
server->wl_display, server->renderer);
desktop->wl_shell = wlr_wl_shell_create(server->wl_display);
wlr_cursor_attach_output_layout(server->input->cursor, desktop->layout);
wlr_cursor_map_to_region(server->input->cursor, config->cursor.mapped_box);
desktop->xdg_shell_v6 = wlr_xdg_shell_v6_create(server->wl_display);
wl_signal_add(&desktop->xdg_shell_v6->events.new_surface,
&desktop->xdg_shell_v6_surface);

106
rootston/input.c Normal file
View File

@ -0,0 +1,106 @@
#include <assert.h>
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/util/log.h>
#include <wlr/xcursor.h>
#include "rootston/server.h"
#include "rootston/config.h"
#include "rootston/input.h"
static const char *device_type(enum wlr_input_device_type type) {
switch (type) {
case WLR_INPUT_DEVICE_KEYBOARD:
return "keyboard";
case WLR_INPUT_DEVICE_POINTER:
return "pointer";
case WLR_INPUT_DEVICE_TOUCH:
return "touch";
case WLR_INPUT_DEVICE_TABLET_TOOL:
return "tablet tool";
case WLR_INPUT_DEVICE_TABLET_PAD:
return "tablet pad";
}
return NULL;
}
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);
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:
//keyboard_add(device, state);
break;
case WLR_INPUT_DEVICE_POINTER:
//pointer_add(device, state);
break;
case WLR_INPUT_DEVICE_TOUCH:
//touch_add(device, state);
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
//tablet_tool_add(device, state);
break;
default:
break;
}
}
static void input_remove_notify(struct wl_listener *listener, void *data) {
struct wlr_input_device *device = data;
struct roots_input *input = wl_container_of(listener, input, input_remove);
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
//keyboard_remove(device, state);
break;
case WLR_INPUT_DEVICE_POINTER:
//pointer_remove(device, state);
break;
case WLR_INPUT_DEVICE_TOUCH:
//touch_remove(device, state);
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
//tablet_tool_remove(device, state);
break;
default:
break;
}
}
struct roots_input *input_create(struct roots_server *server,
struct roots_config *config) {
wlr_log(L_DEBUG, "Initializing roots input");
struct roots_input *input = calloc(1, sizeof(struct roots_input));
assert(input);
input->config = config;
input->cursor = wlr_cursor_create();
struct wlr_xcursor_theme *theme;
assert(theme = wlr_xcursor_theme_load("default", 16));
assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr"));
wlr_cursor_set_xcursor(input->cursor, input->xcursor);
assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0"));
wl_list_init(&input->keyboards);
wl_list_init(&input->pointers);
wl_list_init(&input->touch);
wl_list_init(&input->tablet_tools);
wl_list_init(&input->input_add.link);
input->input_add.notify = input_add_notify;
wl_list_init(&input->input_remove.link);
input->input_remove.notify = input_remove_notify;
wl_signal_add(&server->backend->events.input_add,
&input->input_add);
wl_signal_add(&server->backend->events.input_remove,
&input->input_remove);
return input;
}
void input_destroy(struct roots_input *input) {
// TODO
}

View File

@ -20,6 +20,7 @@ int main(int argc, char **argv) {
assert(server.renderer = wlr_gles2_renderer_create(server.backend));
wl_display_init_shm(server.wl_display);
server.input = input_create(&server, server.config);
server.desktop = desktop_create(&server, server.config);
server.data_device_manager = wlr_data_device_manager_create(
server.wl_display);

View File

@ -3,6 +3,7 @@ executable(
'config.c',
'desktop.c',
'ini.c',
'input.c',
'main.c',
'output.c',
], dependencies: wlroots