aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/compositor.c2
-rw-r--r--include/rootston/desktop.h3
-rw-r--r--include/rootston/input.h5
-rw-r--r--include/rootston/server.h1
-rw-r--r--include/rootston/view.h8
-rw-r--r--include/wlr/xwayland.h16
-rw-r--r--render/gles2/texture.c4
-rw-r--r--rootston/cursor.c3
-rw-r--r--rootston/desktop.c8
-rw-r--r--rootston/keyboard.c40
-rw-r--r--rootston/meson.build1
-rw-r--r--rootston/xwayland.c48
-rw-r--r--types/wlr_keyboard.c1
-rw-r--r--types/wlr_seat.c1
-rw-r--r--types/wlr_surface.c1
-rw-r--r--xwayland/xwayland.c1
-rw-r--r--xwayland/xwm.c25
-rw-r--r--xwayland/xwm.h3
18 files changed, 126 insertions, 45 deletions
diff --git a/examples/compositor.c b/examples/compositor.c
index ae21697a..7d6efdb6 100644
--- a/examples/compositor.c
+++ b/examples/compositor.c
@@ -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);
diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h
index ef361d87..5e138c11 100644
--- a/include/rootston/desktop.h
+++ b/include/rootston/desktop.h
@@ -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
diff --git a/include/rootston/input.h b/include/rootston/input.h
index ec1cd32d..b3ce84d7 100644
--- a/include/rootston/input.h
+++ b/include/rootston/input.h
@@ -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 {
diff --git a/include/rootston/server.h b/include/rootston/server.h
index d9fa8f9e..15e3a4ee 100644
--- a/include/rootston/server.h
+++ b/include/rootston/server.h
@@ -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;
diff --git a/include/rootston/view.h b/include/rootston/view.h
index 1010566a..8d4d69c5 100644
--- a/include/rootston/view.h
+++ b/include/rootston/view.h
@@ -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;
diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h
index 41b8042f..3c893c72 100644
--- a/include/wlr/xwayland.h
+++ b/include/wlr/xwayland.h
@@ -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,15 +34,23 @@ 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);
struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
struct wlr_compositor *compositor);
+void wlr_x11_window_activate(struct wlr_xwayland *wlr_xwayland,
+ struct wlr_x11_window *window);
#endif
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index f6a9d7eb..98d1a112 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -227,13 +227,13 @@ static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct
return;
}
if (!wlr_egl_query_buffer(tex->egl, resource, EGL_WIDTH,
- (EGLint*)&width)) {
+ (EGLint*)width)) {
wlr_log(L_ERROR, "could not get size of the buffer "
"(no buffer found)");
return;
};
wlr_egl_query_buffer(tex->egl, resource, EGL_HEIGHT,
- (EGLint*)&height);
+ (EGLint*)height);
return;
}
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 0e9bf748..89f5874e 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -100,6 +100,9 @@ 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);
+ if (view) {
+ wlr_seat_keyboard_enter(input->wl_seat, view->wlr_surface);
+ }
break;
}
}
diff --git a/rootston/desktop.c b/rootston/desktop.c
index f9af3b8e..697c83df 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -23,6 +23,8 @@ void view_get_input_bounds(struct roots_view *view, struct wlr_box *box) {
return;
}
box->x = box->y = 0;
+ box->width = view->wlr_surface->current.width;
+ box->height = view->wlr_surface->current.height;
}
void view_activate(struct roots_view *view, bool activate) {
@@ -83,6 +85,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);
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index 54ae3f8f..57e0d14e 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -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);
}
diff --git a/rootston/meson.build b/rootston/meson.build
index 6e9e0041..59f73e96 100644
--- a/rootston/meson.build
+++ b/rootston/meson.build
@@ -10,6 +10,7 @@ executable(
'output.c',
'pointer.c',
'xdg_shell_v6.c',
+ 'xwayland.c',
'wl_shell.c',
], dependencies: wlroots
)
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
new file mode 100644
index 00000000..f9ad2a22
--- /dev/null
+++ b/rootston/xwayland.c
@@ -0,0 +1,48 @@
+#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);
+}
+
+static void x11_activate(struct roots_view *view, bool active) {
+ wlr_x11_window_activate(view->desktop->xwayland, view->x11_window);
+}
+
+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;
+ view->activate = x11_activate;
+ roots_surface->view = view;
+ wl_list_insert(&desktop->views, &view->link);
+}
diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c
index 057f4ce3..dd90b38f 100644
--- a/types/wlr_keyboard.c
+++ b/types/wlr_keyboard.c
@@ -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] = {
diff --git a/types/wlr_seat.c b/types/wlr_seat.c
index aaff6005..e473064a 100644
--- a/types/wlr_seat.c
+++ b/types/wlr_seat.c
@@ -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;
diff --git a/types/wlr_surface.c b/types/wlr_surface.c
index a9a54abe..09002d2d 100644
--- a/types/wlr_surface.c
+++ b/types/wlr_surface.c
@@ -117,6 +117,7 @@ static void wlr_surface_update_size(struct wlr_surface *surface) {
surface->current.width = _width;
surface->current.height = _height;
+ wlr_log(L_DEBUG, "%dx%d", _width, _height);
}
static void wlr_surface_to_buffer_region(struct wlr_surface *surface,
diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c
index bed2e00e..6a521393 100644
--- a/xwayland/xwayland.c
+++ b/xwayland/xwayland.c
@@ -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) {
diff --git a/xwayland/xwm.c b/xwayland/xwm.c
index be8fe123..bda9f882 100644
--- a/xwayland/xwm.c
+++ b/xwayland/xwm.c
@@ -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 */
@@ -304,6 +308,25 @@ static void xcb_init_wm(struct wlr_xwm *xwm) {
xcb_flush(xwm->xcb_conn);
}
+void wlr_x11_window_activate(struct wlr_xwayland *wlr_xwayland,
+ struct wlr_x11_window *window) {
+ struct wlr_xwm *xwm = wlr_xwayland->xwm;
+ xcb_client_message_event_t m = {0};
+ m.response_type = XCB_CLIENT_MESSAGE;
+ m.format = 32;
+ m.window = window->window_id;
+ m.type = xwm->atoms[WM_PROTOCOLS];
+ m.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS];
+ m.data.data32[1] = XCB_TIME_CURRENT_TIME;
+ xcb_send_event_checked(xwm->xcb_conn, 0, window->window_id,
+ XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&m);
+ xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT,
+ window->window_id, XCB_CURRENT_TIME);
+ xcb_configure_window_checked(xwm->xcb_conn, window->window_id,
+ XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){XCB_STACK_MODE_ABOVE});
+ xcb_flush(xwm->xcb_conn);
+}
+
void xwm_destroy(struct wlr_xwm *xwm) {
if (!xwm) {
return;
diff --git a/xwayland/xwm.h b/xwayland/xwm.h
index 235145b9..7fc6f3bf 100644
--- a/xwayland/xwm.h
+++ b/xwayland/xwm.h
@@ -52,7 +52,8 @@ enum atom_name {
NET_SUPPORTED,
NET_WM_S0,
NET_WM_STATE,
- ATOM_LAST
+ WM_TAKE_FOCUS,
+ ATOM_LAST,
};
static const char * const atom_map[ATOM_LAST] = {