Fix rootston keyboard, add Xwayland

This commit is contained in:
Drew DeVault 2017-09-28 08:54:57 -04:00
parent 7cf4ee128e
commit 906a816abf
15 changed files with 91 additions and 42 deletions

View file

@ -100,6 +100,7 @@ static void do_cursor_button_press(struct roots_input *input,
input->input_events_idx = (i + 1)
% (sizeof(input->input_events) / sizeof(input->input_events[0]));
set_view_focus(input, desktop, view);
wlr_seat_keyboard_enter(input->wl_seat, view->wlr_surface);
break;
}
}

View file

@ -83,6 +83,12 @@ struct roots_desktop *desktop_create(struct roots_server *server,
&desktop->wl_shell_surface);
desktop->wl_shell_surface.notify = handle_wl_shell_surface;
desktop->xwayland = wlr_xwayland_create(server->wl_display,
desktop->compositor);
wl_signal_add(&desktop->xwayland->events.new_surface,
&desktop->xwayland_surface);
desktop->xwayland_surface.notify = handle_xwayland_surface;
desktop->gamma_control_manager = wlr_gamma_control_manager_create(
server->wl_display);

View file

@ -10,38 +10,19 @@
#include <xkbcommon/xkbcommon.h>
#include "rootston/input.h"
static void keyboard_led_update(struct roots_keyboard *keyboard) {
uint32_t leds = 0;
for (uint32_t i = 0; i < WLR_LED_LAST; ++i) {
if (xkb_state_led_index_is_active(
keyboard->xkb_state, keyboard->leds[i])) {
leds |= (1 << i);
}
}
wlr_keyboard_led_update(keyboard->device->keyboard, leds);
}
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
struct wlr_event_keyboard_key *event = data;
struct roots_keyboard *keyboard = wl_container_of(listener, keyboard, key);
struct roots_input *input = keyboard->input;
struct roots_server *server = input->server;
uint32_t keycode = event->keycode + 8;
enum wlr_key_state key_state = event->state;
uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms;
int nsyms = xkb_state_key_get_syms(keyboard->xkb_state, keycode, &syms);
xkb_state_update_key(keyboard->xkb_state, keycode,
event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP);
keyboard_led_update(keyboard);
int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state,
keycode, &syms);
for (int i = 0; i < nsyms; ++i) {
xkb_keysym_t sym = syms[i];
char name[64];
int l = xkb_keysym_get_name(sym, name, sizeof(name));
if (l != -1 && l != sizeof(name)) {
wlr_log(L_DEBUG, "Key event: %s %s", name,
key_state == WLR_KEY_PRESSED ? "pressed" : "released");
}
// TODO: pass key to clients
if (sym == XKB_KEY_Escape) {
// TEMPORARY, probably
wl_display_terminate(server->wl_display);
@ -77,16 +58,9 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
rules.options = getenv("XKB_DEFAULT_OPTIONS");
struct xkb_context *context;
assert(context = xkb_context_new(XKB_CONTEXT_NO_FLAGS));
assert(keyboard->keymap = xkb_map_new_from_names(context, &rules,
wlr_keyboard_set_keymap(device->keyboard,
xkb_map_new_from_names(context, &rules,
XKB_KEYMAP_COMPILE_NO_FLAGS));
xkb_context_unref(context);
assert(keyboard->xkb_state = xkb_state_new(keyboard->keymap));
const char *led_names[3] = {
XKB_LED_NAME_NUM,
XKB_LED_NAME_CAPS,
XKB_LED_NAME_SCROLL
};
for (uint32_t i = 0; i < 3; ++i) {
keyboard->leds[i] = xkb_map_led_get_index(keyboard->keymap, led_names[i]);
}
wlr_seat_attach_keyboard(input->wl_seat, device);
}

View file

@ -10,6 +10,7 @@ executable(
'output.c',
'pointer.c',
'xdg_shell_v6.c',
'xwayland.c',
'wl_shell.c',
], dependencies: wlroots
)

43
rootston/xwayland.c Normal file
View file

@ -0,0 +1,43 @@
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <wayland-server.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/xwayland.h>
#include <wlr/util/log.h>
#include "rootston/desktop.h"
#include "rootston/server.h"
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
wl_list_remove(&roots_surface->destroy.link);
view_destroy(roots_surface->view);
free(roots_surface);
}
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop =
wl_container_of(listener, desktop, xwayland_surface);
struct wlr_x11_window *surface = data;
// TODO: get and log title, class, etc
wlr_log(L_DEBUG, "new xwayland surface");
struct roots_x11_surface *roots_surface =
calloc(1, sizeof(struct roots_wl_shell_surface));
wl_list_init(&roots_surface->destroy.link);
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
view->type = ROOTS_XWAYLAND_VIEW;
view->x = view->y = 200;
view->x11_window = surface;
view->roots_x11_surface = roots_surface;
view->wlr_surface = surface->surface;
view->desktop = desktop;
roots_surface->view = view;
wl_list_insert(&desktop->views, &view->link);
}