mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 06:35:58 +01:00
Fix rootston keyboard, add Xwayland
This commit is contained in:
parent
7cf4ee128e
commit
906a816abf
15 changed files with 91 additions and 42 deletions
|
@ -323,7 +323,7 @@ static void handle_output_frame(struct output_state *output,
|
|||
struct wlr_x11_window *x11_window;
|
||||
wl_list_for_each(x11_window, &sample->xwayland->displayable_windows, link) {
|
||||
output_frame_handle_surface(sample, wlr_output, ts,
|
||||
x11_window->surface, 200, 200);
|
||||
x11_window->surface->resource, 200, 200);
|
||||
}
|
||||
|
||||
wlr_renderer_end(sample->renderer);
|
||||
|
|
|
@ -34,11 +34,13 @@ struct roots_desktop {
|
|||
struct wlr_compositor *compositor;
|
||||
struct wlr_wl_shell *wl_shell;
|
||||
struct wlr_xdg_shell_v6 *xdg_shell_v6;
|
||||
struct wlr_xwayland *xwayland;
|
||||
struct wlr_gamma_control_manager *gamma_control_manager;
|
||||
|
||||
struct wl_listener output_add;
|
||||
struct wl_listener output_remove;
|
||||
struct wl_listener xdg_shell_v6_surface;
|
||||
struct wl_listener xwayland_surface;
|
||||
struct wl_listener wl_shell_surface;
|
||||
};
|
||||
|
||||
|
@ -57,5 +59,6 @@ void output_remove_notify(struct wl_listener *listener, void *data);
|
|||
|
||||
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
|
||||
void handle_wl_shell_surface(struct wl_listener *listener, void *data);
|
||||
void handle_xwayland_surface(struct wl_listener *listener, void *data);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,11 +15,6 @@ struct roots_keyboard {
|
|||
struct wlr_input_device *device;
|
||||
struct wl_listener key;
|
||||
struct wl_list link;
|
||||
struct xkb_keymap *keymap;
|
||||
struct xkb_state *xkb_state;
|
||||
xkb_led_index_t leds[WLR_LED_LAST];
|
||||
int keymap_fd;
|
||||
size_t keymap_size;
|
||||
};
|
||||
|
||||
struct roots_pointer {
|
||||
|
|
|
@ -23,7 +23,6 @@ struct roots_server {
|
|||
/* WLR tools */
|
||||
struct wlr_backend *backend;
|
||||
struct wlr_renderer *renderer;
|
||||
struct wlr_xwayland *xwayland;
|
||||
|
||||
/* Global resources */
|
||||
struct wlr_data_device_manager *data_device_manager;
|
||||
|
|
|
@ -27,6 +27,12 @@ struct roots_xdg_surface_v6 {
|
|||
struct wl_listener request_show_window_menu;
|
||||
};
|
||||
|
||||
struct roots_x11_surface {
|
||||
struct roots_view *view;
|
||||
// TODO: Maybe destroy listener should go in roots_view
|
||||
struct wl_listener destroy;
|
||||
};
|
||||
|
||||
enum roots_view_type {
|
||||
ROOTS_WL_SHELL_VIEW,
|
||||
ROOTS_XDG_SHELL_V6_VIEW,
|
||||
|
@ -42,10 +48,12 @@ struct roots_view {
|
|||
union {
|
||||
struct wlr_wl_shell_surface *wl_shell_surface;
|
||||
struct wlr_xdg_surface_v6 *xdg_surface_v6;
|
||||
struct wlr_x11_window *x11_window;
|
||||
};
|
||||
union {
|
||||
struct roots_wl_shell_surface *roots_wl_shell_surface;
|
||||
struct roots_xdg_surface_v6 *roots_xdg_surface_v6;
|
||||
struct roots_x11_surface *roots_x11_surface;
|
||||
};
|
||||
struct wlr_surface *wlr_surface;
|
||||
struct wl_list link;
|
||||
|
|
|
@ -21,6 +21,12 @@ struct wlr_xwayland {
|
|||
struct wl_listener destroy_listener;
|
||||
struct wlr_xwm *xwm;
|
||||
struct wl_list displayable_windows;
|
||||
|
||||
struct {
|
||||
struct wl_signal new_surface;
|
||||
} events;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wlr_x11_window {
|
||||
|
@ -28,11 +34,17 @@ struct wlr_x11_window {
|
|||
uint32_t surface_id;
|
||||
struct wl_list link;
|
||||
|
||||
struct wl_resource *surface;
|
||||
struct wlr_surface *surface;
|
||||
struct wl_listener surface_destroy_listener;
|
||||
int16_t x, y;
|
||||
uint16_t width, height;
|
||||
bool override_redirect;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
43
rootston/xwayland.c
Normal 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);
|
||||
}
|
|
@ -54,6 +54,7 @@ void wlr_keyboard_led_update(struct wlr_keyboard *kb, uint32_t leds) {
|
|||
|
||||
void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
|
||||
struct xkb_keymap *keymap) {
|
||||
wlr_log(L_DEBUG, "Keymap set");
|
||||
kb->keymap = keymap;
|
||||
assert(kb->xkb_state = xkb_state_new(kb->keymap));
|
||||
const char *led_names[3] = {
|
||||
|
|
|
@ -377,6 +377,7 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
|
|||
}
|
||||
|
||||
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
|
||||
wlr_log(L_DEBUG, "Updating keyboard");
|
||||
struct wlr_seat_keyboard *seat_kb = wl_container_of(
|
||||
listener, seat_kb, key);
|
||||
struct wlr_seat *seat = seat_kb->seat;
|
||||
|
|
|
@ -194,6 +194,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
|
|||
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
|
||||
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
|
||||
wl_list_init(&wlr_xwayland->displayable_windows);
|
||||
wl_signal_init(&wlr_xwayland->events.new_surface);
|
||||
|
||||
wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd);
|
||||
if (wlr_xwayland->display < 0) {
|
||||
|
|
|
@ -16,6 +16,7 @@ static struct wlr_x11_window *lookup_window(struct wl_list *list, xcb_window_t w
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct wlr_x11_window *lookup_window_any(struct wlr_xwm *xwm, xcb_window_t window_id) {
|
||||
struct wlr_x11_window *window;
|
||||
if ((window = lookup_window(&xwm->xwayland->displayable_windows, window_id)) ||
|
||||
|
@ -43,10 +44,12 @@ static struct wlr_x11_window *wlr_x11_window_create(struct wlr_xwm *xwm,
|
|||
window->height = height;
|
||||
window->override_redirect = override_redirect;
|
||||
wl_list_insert(&xwm->new_windows, &window->link);
|
||||
wl_signal_init(&window->events.destroy);
|
||||
return window;
|
||||
}
|
||||
|
||||
static void wlr_x11_window_destroy(struct wlr_x11_window *window) {
|
||||
wl_signal_emit(&window->events.destroy, window);
|
||||
wl_list_remove(&window->link);
|
||||
free(window);
|
||||
}
|
||||
|
@ -69,10 +72,11 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line,
|
|||
static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window,
|
||||
struct wlr_surface *surface) {
|
||||
// get xcb geometry for depth = alpha channel
|
||||
window->surface = surface->resource;
|
||||
window->surface = surface;
|
||||
|
||||
wl_list_remove(&window->link);
|
||||
wl_list_insert(&xwm->xwayland->displayable_windows, &window->link);
|
||||
wl_signal_emit(&xwm->xwayland->events.new_surface, window);
|
||||
}
|
||||
|
||||
/* xcb event handlers */
|
||||
|
|
Loading…
Reference in a new issue