Merge branch 'master' into xwayland-dnd

master
Drew DeVault 7 years ago
commit 6710de9878

@ -91,6 +91,7 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
return backend; return backend;
} }
#ifdef WLR_HAS_X11_BACKEND
static struct wlr_backend *attempt_x11_backend(struct wl_display *display, static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
const char *x11_display) { const char *x11_display) {
struct wlr_backend *backend = wlr_x11_backend_create(display, x11_display); struct wlr_backend *backend = wlr_x11_backend_create(display, x11_display);
@ -105,6 +106,7 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
return backend; return backend;
} }
#endif
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
struct wlr_backend *backend = wlr_multi_backend_create(display); struct wlr_backend *backend = wlr_multi_backend_create(display);
@ -182,7 +184,3 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
return backend; return backend;
} }
uint32_t usec_to_msec(uint64_t usec) {
return (uint32_t)(usec / 1000);
}

@ -25,6 +25,10 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
(struct wlr_headless_output *)wlr_output; (struct wlr_headless_output *)wlr_output;
struct wlr_headless_backend *backend = output->backend; struct wlr_headless_backend *backend = output->backend;
if (refresh == 0) {
refresh = HEADLESS_DEFAULT_REFRESH;
}
if (output->egl_surface) { if (output->egl_surface) {
eglDestroySurface(backend->egl.display, output->egl_surface); eglDestroySurface(backend->egl.display, output->egl_surface);
} }
@ -114,7 +118,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
goto error; goto error;
} }
output_set_custom_mode(wlr_output, width, height, 60*1000); output_set_custom_mode(wlr_output, width, height, 0);
strncpy(wlr_output->make, "headless", sizeof(wlr_output->make)); strncpy(wlr_output->make, "headless", sizeof(wlr_output->make));
strncpy(wlr_output->model, "headless", sizeof(wlr_output->model)); strncpy(wlr_output->model, "headless", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "HEADLESS-%d", snprintf(wlr_output->name, sizeof(wlr_output->name), "HEADLESS-%d",

@ -191,3 +191,7 @@ struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *
struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev; struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev;
return dev->handle; return dev->handle;
} }
uint32_t usec_to_msec(uint64_t usec) {
return (uint32_t)(usec / 1000);
}

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <wlr/config.h> #include <wlr/config.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h> #include <wlr/interfaces/wlr_keyboard.h>
@ -27,6 +28,34 @@ static uint32_t xcb_button_to_wl(uint32_t button) {
} }
} }
static void x11_handle_pointer_position(struct wlr_x11_output *output,
int16_t x, int16_t y, xcb_timestamp_t time) {
struct wlr_x11_backend *x11 = output->x11;
struct wlr_output *wlr_output = &output->wlr_output;
struct wlr_box box = { .x = x, .y = y };
wlr_box_transform(&box, wlr_output->transform, wlr_output->width,
wlr_output->height, &box);
box.x /= wlr_output->scale;
box.y /= wlr_output->scale;
struct wlr_box layout_box;
x11_output_layout_get_box(x11, &layout_box);
double ox = wlr_output->lx / (double)layout_box.width;
double oy = wlr_output->ly / (double)layout_box.height;
struct wlr_event_pointer_motion_absolute wlr_event = {
.device = &x11->pointer_dev,
.time_msec = time,
.x = box.x / (double)layout_box.width + ox,
.y = box.y / (double)layout_box.height + oy,
};
wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &wlr_event);
x11->time = time;
}
bool x11_handle_input_event(struct wlr_x11_backend *x11, bool x11_handle_input_event(struct wlr_x11_backend *x11,
xcb_generic_event_t *event) { xcb_generic_event_t *event) {
switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) { switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) {
@ -91,30 +120,8 @@ bool x11_handle_input_event(struct wlr_x11_backend *x11,
if (output == NULL) { if (output == NULL) {
return false; return false;
} }
struct wlr_output *wlr_output = &output->wlr_output;
struct wlr_box box = { .x = ev->event_x, .y = ev->event_y };
wlr_box_transform(&box, wlr_output->transform, wlr_output->width,
wlr_output->height, &box);
box.x /= wlr_output->scale;
box.y /= wlr_output->scale;
struct wlr_box layout_box;
x11_output_layout_get_box(x11, &layout_box);
double ox = wlr_output->lx / (double)layout_box.width; x11_handle_pointer_position(output, ev->event_x, ev->event_y, ev->time);
double oy = wlr_output->ly / (double)layout_box.height;
struct wlr_event_pointer_motion_absolute wlr_event = {
.device = &x11->pointer_dev,
.time_msec = ev->time,
.x = box.x / (double)layout_box.width + ox,
.y = box.y / (double)layout_box.height + oy,
};
wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &wlr_event);
x11->time = ev->time;
return true; return true;
} }
default: default:
@ -135,6 +142,23 @@ bool x11_handle_input_event(struct wlr_x11_backend *x11,
const struct wlr_input_device_impl input_device_impl = { 0 }; const struct wlr_input_device_impl input_device_impl = { 0 };
void x11_update_pointer_position(struct wlr_x11_output *output,
xcb_timestamp_t time) {
struct wlr_x11_backend *x11 = output->x11;
xcb_query_pointer_cookie_t cookie =
xcb_query_pointer(x11->xcb_conn, output->win);
xcb_query_pointer_reply_t *reply =
xcb_query_pointer_reply(x11->xcb_conn, cookie, NULL);
if (!reply) {
return;
}
x11_handle_pointer_position(output, reply->win_x, reply->win_y, time);
free(reply);
}
bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) { bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) {
return wlr_dev->impl == &input_device_impl; return wlr_dev->impl == &input_device_impl;
} }

@ -23,14 +23,25 @@ static void parse_xcb_setup(struct wlr_output *output, xcb_connection_t *xcb_con
xcb_setup->protocol_minor_version); xcb_setup->protocol_minor_version);
} }
static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width, static void output_set_refresh(struct wlr_output *wlr_output, int32_t refresh) {
int32_t height, int32_t refresh) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;
struct wlr_x11_backend *x11 = output->x11;
if (refresh == 0) {
refresh = X11_DEFAULT_REFRESH;
}
wlr_output_update_custom_mode(&output->wlr_output, wlr_output->width, wlr_output_update_custom_mode(&output->wlr_output, wlr_output->width,
wlr_output->height, refresh); wlr_output->height, refresh);
output->frame_delay = 1000000 / refresh; output->frame_delay = 1000000 / refresh;
}
static bool output_set_custom_mode(struct wlr_output *wlr_output,
int32_t width, int32_t height, int32_t refresh) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;
struct wlr_x11_backend *x11 = output->x11;
output_set_refresh(&output->wlr_output, refresh);
const uint32_t values[] = { width, height }; const uint32_t values[] = { width, height };
xcb_configure_window(x11->xcb_conn, output->win, xcb_configure_window(x11->xcb_conn, output->win,
@ -97,8 +108,7 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
struct wlr_output *wlr_output = &output->wlr_output; struct wlr_output *wlr_output = &output->wlr_output;
wlr_output_init(wlr_output, &x11->backend, &output_impl, x11->wl_display); wlr_output_init(wlr_output, &x11->backend, &output_impl, x11->wl_display);
wlr_output->refresh = 60 * 1000000; output_set_refresh(&output->wlr_output, 0);
output->frame_delay = 16; // 60 Hz
snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%d", snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%d",
wl_list_length(&x11->outputs) + 1); wl_list_length(&x11->outputs) + 1);
@ -157,29 +167,11 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
void x11_output_handle_configure_notify(struct wlr_x11_output *output, void x11_output_handle_configure_notify(struct wlr_x11_output *output,
xcb_configure_notify_event_t *ev) { xcb_configure_notify_event_t *ev) {
struct wlr_x11_backend *x11 = output->x11;
wlr_output_update_custom_mode(&output->wlr_output, ev->width, wlr_output_update_custom_mode(&output->wlr_output, ev->width,
ev->height, output->wlr_output.refresh); ev->height, output->wlr_output.refresh);
// Move the pointer to its new location // Move the pointer to its new location
xcb_query_pointer_cookie_t cookie = x11_update_pointer_position(output, output->x11->time);
xcb_query_pointer(x11->xcb_conn, output->win);
xcb_query_pointer_reply_t *pointer =
xcb_query_pointer_reply(x11->xcb_conn, cookie, NULL);
if (!pointer) {
return;
}
struct wlr_event_pointer_motion_absolute abs = {
.device = &x11->pointer_dev,
.time_msec = x11->time,
.x = (double)pointer->root_x / output->wlr_output.width,
.y = (double)pointer->root_y / output->wlr_output.height,
};
wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs);
free(pointer);
} }
bool wlr_output_is_x11(struct wlr_output *wlr_output) { bool wlr_output_is_x11(struct wlr_output *wlr_output) {

@ -55,10 +55,8 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32
zwp_idle_inhibitor_v1_destroy(idle_inhibitor); zwp_idle_inhibitor_v1_destroy(idle_inhibitor);
idle_inhibitor = NULL; idle_inhibitor = NULL;
} else { } else {
idle_inhibitor = idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(
zwp_idle_inhibit_manager_v1_create_inhibitor( idle_inhibit_manager, surface);
idle_inhibit_manager,
surface);
} }
} }
@ -140,7 +138,6 @@ static void xdg_toplevel_handle_close(void *data,
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
static const struct xdg_toplevel_listener xdg_toplevel_listener = { static const struct xdg_toplevel_listener xdg_toplevel_listener = {
.configure = xdg_toplevel_handle_configure, .configure = xdg_toplevel_handle_configure,
.close = xdg_toplevel_handle_close, .close = xdg_toplevel_handle_close,

@ -0,0 +1,189 @@
#include <GLES2/gl2.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wayland-client.h>
#include <wayland-egl.h>
#include <wlr/render/egl.h>
#include "wlr-input-inhibitor-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
static int width = 500, height = 300;
static int keys = 0;
static struct wl_compositor *compositor = NULL;
static struct wl_seat *seat = NULL;
static struct xdg_wm_base *wm_base = NULL;
static struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager = NULL;
static struct zwlr_input_inhibitor_v1 *input_inhibitor = NULL;
struct wlr_egl egl;
struct wl_egl_window *egl_window;
struct wlr_egl_surface *egl_surface;
static void render_frame(void) {
eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context);
glViewport(0, 0, width, height);
if (keys) {
glClearColor(1.0, 1.0, 1.0, 1.0);
} else {
glClearColor(0.8, 0.4, 1.0, 1.0);
}
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(egl.display, egl_surface);
}
static void xdg_surface_handle_configure(void *data,
struct xdg_surface *xdg_surface, uint32_t serial) {
xdg_surface_ack_configure(xdg_surface, serial);
wl_egl_window_resize(egl_window, width, height, 0, 0);
render_frame();
}
static const struct xdg_surface_listener xdg_surface_listener = {
.configure = xdg_surface_handle_configure,
};
static void xdg_toplevel_handle_configure(void *data,
struct xdg_toplevel *xdg_toplevel, int32_t w, int32_t h,
struct wl_array *states) {
width = w;
height = h;
}
static void xdg_toplevel_handle_close(void *data,
struct xdg_toplevel *xdg_toplevel) {
exit(0);
}
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
.configure = xdg_toplevel_handle_configure,
.close = xdg_toplevel_handle_close,
};
static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
uint32_t format, int32_t fd, uint32_t size) {
}
static void wl_keyboard_enter(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
}
static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface) {
}
static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
uint32_t mods_locked, uint32_t group) {
}
static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
int32_t rate, int32_t delay) {
}
static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
++keys;
} else {
--keys;
}
render_frame();
}
static struct wl_keyboard_listener keyboard_listener = {
.keymap = wl_keyboard_keymap,
.enter = wl_keyboard_enter,
.leave = wl_keyboard_leave,
.key = wl_keyboard_key,
.modifiers = wl_keyboard_modifiers,
.repeat_info = wl_keyboard_repeat_info,
};
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) {
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
struct wl_keyboard *keyboard = wl_seat_get_keyboard(wl_seat);
wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
}
}
static void seat_handle_name(void *data, struct wl_seat *wl_seat,
const char *name) {
// Who cares
}
const struct wl_seat_listener seat_listener = {
.capabilities = seat_handle_capabilities,
.name = seat_handle_name,
};
static void handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) {
if (strcmp(interface, wl_compositor_interface.name) == 0) {
compositor = wl_registry_bind(registry, name,
&wl_compositor_interface, 1);
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
} else if (strcmp(interface, zwlr_input_inhibit_manager_v1_interface.name) == 0) {
input_inhibit_manager = wl_registry_bind(registry, name,
&zwlr_input_inhibit_manager_v1_interface, 1);
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
seat = wl_registry_bind(registry, name, &wl_seat_interface, version);
wl_seat_add_listener(seat, &seat_listener, seat);
}
}
static void handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name) {
// who cares
}
static const struct wl_registry_listener registry_listener = {
.global = handle_global,
.global_remove = handle_global_remove,
};
int main(int argc, char **argv) {
struct wl_display *display = wl_display_connect(NULL);
assert(display);
struct wl_registry *registry = wl_display_get_registry(display);
assert(registry);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_dispatch(display);
wl_display_roundtrip(display);
assert(compositor && seat && wm_base && input_inhibit_manager);
input_inhibitor = zwlr_input_inhibit_manager_v1_get_inhibitor(
input_inhibit_manager);
assert(input_inhibitor);
wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL,
WL_SHM_FORMAT_ARGB8888);
struct wl_surface *surface = wl_compositor_create_surface(compositor);
assert(surface);
struct xdg_surface *xdg_surface =
xdg_wm_base_get_xdg_surface(wm_base, surface);
assert(xdg_surface);
struct xdg_toplevel *xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
assert(xdg_toplevel);
xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, NULL);
xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, NULL);
wl_surface_commit(surface);
egl_window = wl_egl_window_create(surface, width, height);
egl_surface = wlr_egl_create_surface(&egl, egl_window);
wl_display_roundtrip(display);
render_frame();
while (wl_display_dispatch(display) != -1) {
// This space intentionally left blank
}
return 0;
}

@ -55,3 +55,9 @@ executable(
'layer-shell.c', 'layer-shell.c',
dependencies: [wayland_cursor, wayland_client, wlr_protos, wlroots] dependencies: [wayland_cursor, wayland_client, wlr_protos, wlroots]
) )
executable(
'input-inhibitor',
'input-inhibitor.c',
dependencies: [wayland_cursor, wayland_client, wlr_protos, wlroots]
)

@ -4,6 +4,8 @@
#include <wlr/backend/headless.h> #include <wlr/backend/headless.h>
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#define HEADLESS_DEFAULT_REFRESH (60 * 1000) // 60 Hz
struct wlr_headless_backend { struct wlr_headless_backend {
struct wlr_backend backend; struct wlr_backend backend;
struct wlr_egl egl; struct wlr_egl egl;

@ -29,6 +29,8 @@ struct wlr_libinput_input_device {
struct libinput_device *handle; struct libinput_device *handle;
}; };
uint32_t usec_to_msec(uint64_t usec);
void wlr_libinput_event(struct wlr_libinput_backend *state, void wlr_libinput_event(struct wlr_libinput_backend *state,
struct libinput_event *event); struct libinput_event *event);

@ -12,6 +12,8 @@
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f #define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
#define X11_DEFAULT_REFRESH (60 * 1000) // 60 Hz
struct wlr_x11_backend; struct wlr_x11_backend;
struct wlr_x11_output { struct wlr_x11_output {
@ -79,6 +81,8 @@ const struct wlr_input_device_impl input_device_impl;
bool x11_handle_input_event(struct wlr_x11_backend *x11, bool x11_handle_input_event(struct wlr_x11_backend *x11,
xcb_generic_event_t *event); xcb_generic_event_t *event);
void x11_update_pointer_position(struct wlr_x11_output *output,
xcb_timestamp_t time);
void x11_output_handle_configure_notify(struct wlr_x11_output *output, void x11_output_handle_configure_notify(struct wlr_x11_output *output,
xcb_configure_notify_event_t *event); xcb_configure_notify_event_t *event);

@ -6,6 +6,7 @@
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_gamma_control.h> #include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_layer_shell.h> #include <wlr/types/wlr_layer_shell.h>
#include <wlr/types/wlr_linux_dmabuf.h> #include <wlr/types/wlr_linux_dmabuf.h>
#include <wlr/types/wlr_list.h> #include <wlr/types/wlr_list.h>
@ -47,6 +48,7 @@ struct roots_desktop {
struct wlr_primary_selection_device_manager *primary_selection_device_manager; struct wlr_primary_selection_device_manager *primary_selection_device_manager;
struct wlr_idle *idle; struct wlr_idle *idle;
struct wlr_idle_inhibit_manager_v1 *idle_inhibit; struct wlr_idle_inhibit_manager_v1 *idle_inhibit;
struct wlr_input_inhibit_manager *input_inhibit;
struct wlr_linux_dmabuf *linux_dmabuf; struct wlr_linux_dmabuf *linux_dmabuf;
struct wlr_layer_shell *layer_shell; struct wlr_layer_shell *layer_shell;
@ -57,6 +59,8 @@ struct roots_desktop {
struct wl_listener wl_shell_surface; struct wl_listener wl_shell_surface;
struct wl_listener layer_shell_surface; struct wl_listener layer_shell_surface;
struct wl_listener decoration_new; struct wl_listener decoration_new;
struct wl_listener input_inhibit_activate;
struct wl_listener input_inhibit_deactivate;
#ifdef WLR_HAS_XWAYLAND #ifdef WLR_HAS_XWAYLAND
struct wlr_xwayland *xwayland; struct wlr_xwayland *xwayland;

@ -19,6 +19,9 @@ struct roots_seat {
// If the focused layer is set, views cannot receive keyboard focus // If the focused layer is set, views cannot receive keyboard focus
struct wlr_layer_surface *focused_layer; struct wlr_layer_surface *focused_layer;
// If non-null, only this client can receive input events
struct wl_client *exclusive_client;
struct wl_list views; // roots_seat_view::link struct wl_list views; // roots_seat_view::link
bool has_focus; bool has_focus;
@ -125,4 +128,10 @@ void roots_drag_icon_update_position(struct roots_drag_icon *icon);
void roots_drag_icon_damage_whole(struct roots_drag_icon *icon); void roots_drag_icon_damage_whole(struct roots_drag_icon *icon);
void roots_seat_set_exclusive_client(struct roots_seat *seat,
struct wl_client *client);
bool roots_seat_allow_input(struct roots_seat *seat,
struct wl_resource *resource);
#endif #endif

@ -46,6 +46,4 @@ struct wlr_egl *wlr_backend_get_egl(struct wlr_backend *backend);
*/ */
struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend); struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend);
uint32_t usec_to_msec(uint64_t usec);
#endif #endif

@ -4,6 +4,8 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
struct wlr_surface;
struct wlr_compositor { struct wlr_compositor {
struct wl_global *wl_global; struct wl_global *wl_global;
struct wl_list wl_resources; struct wl_list wl_resources;
@ -22,4 +24,8 @@ void wlr_compositor_destroy(struct wlr_compositor *wlr_compositor);
struct wlr_compositor *wlr_compositor_create(struct wl_display *display, struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
struct wlr_renderer *renderer); struct wlr_renderer *renderer);
bool wlr_surface_is_subsurface(struct wlr_surface *surface);
struct wlr_subsurface *wlr_subsurface_from_surface(struct wlr_surface *surface);
#endif #endif

@ -54,6 +54,8 @@ struct wlr_cursor {
struct wl_signal tablet_tool_tip; struct wl_signal tablet_tool_tip;
struct wl_signal tablet_tool_button; struct wl_signal tablet_tool_button;
} events; } events;
void *data;
}; };
struct wlr_cursor *wlr_cursor_create(); struct wlr_cursor *wlr_cursor_create();

@ -0,0 +1,25 @@
#ifndef WLR_TYPES_INPUT_INHIBITOR_H
#define WLR_TYPES_INPUT_INHIBITOR_H
#include <wayland-server.h>
struct wlr_input_inhibit_manager {
struct wl_global *wl_global;
struct wl_client *active_client;
struct wl_resource *active_inhibitor;
struct wl_listener display_destroy;
struct {
struct wl_signal activate; // struct wlr_input_inhibit_manager *
struct wl_signal deactivate; // struct wlr_input_inhibit_manager *
} events;
void *data;
};
struct wlr_input_inhibit_manager *wlr_input_inhibit_manager_create(
struct wl_display *display);
void wlr_input_inhibit_manager_destroy(
struct wlr_input_inhibit_manager *manager);
#endif

@ -112,8 +112,15 @@ struct wlr_surface;
void wlr_output_enable(struct wlr_output *output, bool enable); void wlr_output_enable(struct wlr_output *output, bool enable);
void wlr_output_create_global(struct wlr_output *output); void wlr_output_create_global(struct wlr_output *output);
void wlr_output_destroy_global(struct wlr_output *output); void wlr_output_destroy_global(struct wlr_output *output);
/**
* Sets the output mode.
*/
bool wlr_output_set_mode(struct wlr_output *output, bool wlr_output_set_mode(struct wlr_output *output,
struct wlr_output_mode *mode); struct wlr_output_mode *mode);
/**
* Sets a custom mode on the output. If modes are available, they are preferred.
* Setting `refresh` to zero lets the backend pick a preferred value.
*/
bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width,
int32_t height, int32_t refresh); int32_t height, int32_t refresh);
void wlr_output_set_transform(struct wlr_output *output, void wlr_output_set_transform(struct wlr_output *output,

@ -17,6 +17,8 @@ struct wlr_output_layout {
struct wl_signal change; struct wl_signal change;
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;
void *data;
}; };
struct wlr_output_layout_output_state; struct wlr_output_layout_output_state;
@ -32,6 +34,11 @@ struct wlr_output_layout_output {
} events; } events;
}; };
/**
* Creates a wlr_output_layout, which can be used to describing outputs in
* physical space relative to one another, and perform various useful operations
* on that state.
*/
struct wlr_output_layout *wlr_output_layout_create(); struct wlr_output_layout *wlr_output_layout_create();
void wlr_output_layout_destroy(struct wlr_output_layout *layout); void wlr_output_layout_destroy(struct wlr_output_layout *layout);

@ -537,6 +537,7 @@ bool wlr_seat_touch_has_grab(struct wlr_seat *seat);
*/ */
bool wlr_seat_validate_grab_serial(struct wlr_seat *seat, uint32_t serial); bool wlr_seat_validate_grab_serial(struct wlr_seat *seat, uint32_t serial);
struct wlr_seat_client *wlr_seat_client_from_resource(struct wl_resource *resource); struct wlr_seat_client *wlr_seat_client_from_resource(
struct wl_resource *resource);
#endif #endif

@ -122,20 +122,24 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t id); struct wlr_surface *parent, uint32_t id);
/** /**
* Get the top of the subsurface tree for this surface. * Get the root of the subsurface tree for this surface.
*/ */
struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface); struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface);
/** /**
* Find a subsurface within this surface at the surface-local coordinates. * Check if the surface accepts input events at the given surface-local
* Returns the surface and coordinates in the topmost surface coordinate system * coordinates. Does not check the surface's subsurfaces.
* or NULL if no subsurface is found at that location.
*/ */
struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y); double sx, double sy);
bool wlr_surface_point_accepts_input( /**
struct wlr_surface *surface, double sx, double sy); * Find a surface in this surface's tree that accepts input events at the given
* surface-local coordinates. Returns the surface and coordinates in the leaf
* surface coordinate system or NULL if no surface is found at that location.
*/
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y);
void wlr_surface_send_enter(struct wlr_surface *surface, void wlr_surface_send_enter(struct wlr_surface *surface,
struct wlr_output *output); struct wlr_output *output);

@ -142,13 +142,13 @@ void wlr_wl_shell_surface_configure(struct wlr_wl_shell_surface *surface,
enum wl_shell_surface_resize edges, int32_t width, int32_t height); enum wl_shell_surface_resize edges, int32_t width, int32_t height);
/** /**
* Find a popup within this surface at the surface-local coordinates. Returns * Find a surface within this wl-shell surface tree at the given surface-local
* the popup and coordinates in the topmost surface coordinate system or NULL if * coordinates. Returns the surface and coordinates in the leaf surface
* no popup is found at that location. * coordinate system or NULL if no surface is found at that location.
*/ */
struct wlr_wl_shell_surface *wlr_wl_shell_surface_popup_at( struct wlr_surface *wlr_wl_shell_surface_surface_at(
struct wlr_wl_shell_surface *surface, double sx, double sy, struct wlr_wl_shell_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy); double *sub_sx, double *sub_sy);
bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface); bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface);

@ -0,0 +1,32 @@
#ifndef WLR_TYPES_WLR_XDG_OUTPUT_H
#define WLR_TYPES_WLR_XDG_OUTPUT_H
#include <wayland-server.h>
#include <wlr/types/wlr_output_layout.h>
struct wlr_xdg_output {
struct wl_list link;
struct wl_list resources;
struct wlr_xdg_output_manager *manager;
struct wlr_output_layout_output *layout_output;
struct wl_listener destroy;
};
struct wlr_xdg_output_manager {
struct wl_global *global;
struct wlr_output_layout *layout;
struct wl_list outputs;
struct wl_listener layout_add;
struct wl_listener layout_change;
struct wl_listener layout_destroy;
};
struct wlr_xdg_output_manager *wlr_xdg_output_manager_create(
struct wl_display *display, struct wlr_output_layout *layout);
void wlr_xdg_output_manager_destroy(struct wlr_xdg_output_manager *manager);
#endif

@ -215,19 +215,19 @@ uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface,
void wlr_xdg_surface_send_close(struct wlr_xdg_surface *surface); void wlr_xdg_surface_send_close(struct wlr_xdg_surface *surface);
/** /**
* Compute the popup position in surface-local coordinates. * Compute the popup position in its parent's surface-local coordinate system.
*/ */
void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface, void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface,
double *popup_sx, double *popup_sy); double *popup_sx, double *popup_sy);
/** /**
* Find a popup within this surface at the surface-local coordinates. Returns * Find a surface within this xdg-surface tree at the given surface-local
* the popup and coordinates in the topmost surface coordinate system or NULL if * coordinates. Returns the surface and coordinates in the leaf surface
* no popup is found at that location. * coordinate system or NULL if no surface is found at that location.
*/ */
struct wlr_xdg_surface *wlr_xdg_surface_popup_at( struct wlr_surface *wlr_xdg_surface_surface_at(
struct wlr_xdg_surface *surface, double sx, double sy, struct wlr_xdg_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy); double *sub_x, double *sub_y);
bool wlr_surface_is_xdg_surface(struct wlr_surface *surface); bool wlr_surface_is_xdg_surface(struct wlr_surface *surface);

@ -233,19 +233,19 @@ uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
void wlr_xdg_surface_v6_send_close(struct wlr_xdg_surface_v6 *surface); void wlr_xdg_surface_v6_send_close(struct wlr_xdg_surface_v6 *surface);
/** /**
* Compute the popup position in surface-local coordinates. * Compute the popup position in its parent's surface-local coordinate system.
*/ */
void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface,
double *popup_sx, double *popup_sy); double *popup_sx, double *popup_sy);
/** /**
* Find a popup within this surface at the surface-local coordinates. Returns * Find a surface within this xdg-surface tree at the given surface-local
* the popup and coordinates in the topmost surface coordinate system or NULL if * coordinates. Returns the surface and coordinates in the leaf surface
* no popup is found at that location. * coordinate system or NULL if no surface is found at that location.
*/ */
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_surface *wlr_xdg_surface_v6_surface_at(
struct wlr_xdg_surface_v6 *surface, double sx, double sy, struct wlr_xdg_surface_v6 *surface, double sx, double sy,
double *popup_sx, double *popup_sy); double *sub_x, double *sub_y);
/** /**
* Get the geometry for this positioner based on the anchor rect, gravity, and * Get the geometry for this positioner based on the anchor rect, gravity, and

@ -25,12 +25,14 @@ protocols = [
[wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'],
[wl_protocol_dir, 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml'], [wl_protocol_dir, 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml'],
[wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
[wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'],
'gamma-control.xml', 'gamma-control.xml',
'gtk-primary-selection.xml', 'gtk-primary-selection.xml',
'idle.xml', 'idle.xml',
'screenshooter.xml', 'screenshooter.xml',
'server-decoration.xml', 'server-decoration.xml',
'wlr-layer-shell-unstable-v1.xml', 'wlr-layer-shell-unstable-v1.xml',
'wlr-input-inhibitor-unstable-v1.xml',
] ]
client_protocols = [ client_protocols = [
@ -40,6 +42,7 @@ client_protocols = [
'idle.xml', 'idle.xml',
'screenshooter.xml', 'screenshooter.xml',
'wlr-layer-shell-unstable-v1.xml', 'wlr-layer-shell-unstable-v1.xml',
'wlr-input-inhibitor-unstable-v1.xml',
] ]
wl_protos_src = [] wl_protos_src = []

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_input_inhibit_unstable_v1">
<copyright>
Copyright © 2018 Drew DeVault
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the copyright holders not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. The copyright holders make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
</copyright>
<interface name="zwlr_input_inhibit_manager_v1" version="1">
<description summary="inhibits input events to other clients">
Clients can use this interface to prevent input events from being sent to
any surfaces but its own, which is useful for example in lock screen
software. It is assumed that access to this interface will be locked down
to whitelisted clients by the compositor.
</description>
<request name="get_inhibitor">
<description summary="inhibit input to other clients">
Activates the input inhibitor. As long as the inhibitor is active, the
compositor will not send input events to other clients.
</description>
<arg name="id" type="new_id" interface="zwlr_input_inhibitor_v1"/>
</request>
<enum name="error">
<entry name="already_inhibited" value="0" summary="an input inhibitor is already in use on the compositor"/>
</enum>
</interface>
<interface name="zwlr_input_inhibitor_v1" version="1">
<description summary="inhibits input to other clients">
While this resource exists, input to clients other than the owner of the
inhibitor resource will not receive input events. The client that owns
this resource will receive all input events normally. The compositor will
also disable all of its own input processing (such as keyboard shortcuts)
while the inhibitor is active.
The compositor may continue to send input events to selected clients,
such as an on-screen keyboard (via the input-method protocol).
</description>
<request name="destroy" type="destructor">
<description summary="destroy the input inhibitor object">
Destroy the inhibitor and allow other clients to receive input.
</description>
</request>
</interface>
</protocol>

@ -474,7 +474,7 @@ int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl,
int format, uint64_t **modifiers) { int format, uint64_t **modifiers) {
if (!egl->egl_exts.dmabuf_import || if (!egl->egl_exts.dmabuf_import ||
!egl->egl_exts.dmabuf_import_modifiers) { !egl->egl_exts.dmabuf_import_modifiers) {
wlr_log(L_ERROR, "dmabuf extension not present"); wlr_log(L_DEBUG, "dmabuf extension not present");
return -1; return -1;
} }

@ -111,6 +111,9 @@ static void roots_passthrough_cursor(struct roots_cursor *cursor,
if (surface) { if (surface) {
client = wl_resource_get_client(surface->resource); client = wl_resource_get_client(surface->resource);
} }
if (surface && !roots_seat_allow_input(cursor->seat, surface->resource)) {
return;
}
if (cursor->cursor_client != client) { if (cursor->cursor_client != client) {
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
@ -327,7 +330,7 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
desktop, lx, ly, &sx, &sy, NULL); desktop, lx, ly, &sx, &sy, NULL);
uint32_t serial = 0; uint32_t serial = 0;
if (surface) { if (surface && roots_seat_allow_input(cursor->seat, surface->resource)) {
serial = wlr_seat_touch_notify_down(cursor->seat->seat, surface, serial = wlr_seat_touch_notify_down(cursor->seat->seat, surface,
event->time_msec, event->touch_id, sx, sy); event->time_msec, event->touch_id, sx, sy);
} }
@ -378,7 +381,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
struct wlr_surface *surface = desktop_surface_at( struct wlr_surface *surface = desktop_surface_at(
desktop, lx, ly, &sx, &sy, NULL); desktop, lx, ly, &sx, &sy, NULL);
if (surface) { if (surface && roots_seat_allow_input(cursor->seat, surface->resource)) {
wlr_seat_touch_point_focus(cursor->seat->seat, surface, wlr_seat_touch_point_focus(cursor->seat->seat, surface,
event->time_msec, event->touch_id, sx, sy); event->time_msec, event->touch_id, sx, sy);
wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec, wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec,

@ -10,6 +10,7 @@
#include <wlr/types/wlr_gamma_control.h> #include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h> #include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_layer_shell.h> #include <wlr/types/wlr_layer_shell.h>
#include <wlr/types/wlr_linux_dmabuf.h> #include <wlr/types/wlr_linux_dmabuf.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
@ -19,6 +20,7 @@
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_xdg_output.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "rootston/layers.h" #include "rootston/layers.h"
#include "rootston/seat.h" #include "rootston/seat.h"
@ -576,42 +578,30 @@ static bool view_at(struct roots_view *view, double lx, double ly,
view_sy = ry + (double)box.height/2; view_sy = ry + (double)box.height/2;
} }
if (view->type == ROOTS_XDG_SHELL_V6_VIEW) { double _sx, _sy;
double popup_sx, popup_sy; struct wlr_surface *_surface = NULL;
struct wlr_xdg_surface_v6 *popup = switch (view->type) {
wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6, case ROOTS_XDG_SHELL_V6_VIEW:
view_sx, view_sy, &popup_sx, &popup_sy); _surface = wlr_xdg_surface_v6_surface_at(view->xdg_surface_v6,
view_sx, view_sy, &_sx, &_sy);
if (popup) { break;
*sx = view_sx - popup_sx; case ROOTS_XDG_SHELL_VIEW:
*sy = view_sy - popup_sy; _surface = wlr_xdg_surface_surface_at(view->xdg_surface,
*surface = popup->surface; view_sx, view_sy, &_sx, &_sy);
return true; break;
} case ROOTS_WL_SHELL_VIEW:
} _surface = wlr_wl_shell_surface_surface_at(view->wl_shell_surface,
view_sx, view_sy, &_sx, &_sy);
if (view->type == ROOTS_WL_SHELL_VIEW) { break;
double popup_sx, popup_sy; case ROOTS_XWAYLAND_VIEW:
struct wlr_wl_shell_surface *popup = _surface = wlr_surface_surface_at(view->wlr_surface,
wlr_wl_shell_surface_popup_at(view->wl_shell_surface, view_sx, view_sy, &_sx, &_sy);
view_sx, view_sy, &popup_sx, &popup_sy); break;
}
if (popup) { if (_surface != NULL) {
*sx = view_sx - popup_sx; *sx = _sx;
*sy = view_sy - popup_sy; *sy = _sy;
*surface = popup->surface; *surface = _surface;
return true;
}
}
double sub_x, sub_y;
struct wlr_subsurface *subsurface =
wlr_surface_subsurface_at(view->wlr_surface,
view_sx, view_sy, &sub_x, &sub_y);
if (subsurface) {
*sx = view_sx - sub_x;
*sy = view_sy - sub_y;
*surface = subsurface->surface;
return true; return true;
} }
@ -622,13 +612,6 @@ static bool view_at(struct roots_view *view, double lx, double ly,
return true; return true;
} }
if (wlr_surface_point_accepts_input(view->wlr_surface, view_sx, view_sy)) {
*sx = view_sx;
*sy = view_sy;
*surface = view->wlr_surface;
return true;
}
return false; return false;
} }
@ -755,6 +738,25 @@ static void handle_layout_change(struct wl_listener *listener, void *data) {
} }
} }
static void input_inhibit_activate(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop = wl_container_of(
listener, desktop, input_inhibit_activate);
struct roots_seat *seat;
wl_list_for_each(seat, &desktop->server->input->seats, link) {
roots_seat_set_exclusive_client(seat,
desktop->input_inhibit->active_client);
}
}
static void input_inhibit_deactivate(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop = wl_container_of(
listener, desktop, input_inhibit_deactivate);
struct roots_seat *seat;
wl_list_for_each(seat, &desktop->server->input->seats, link) {
roots_seat_set_exclusive_client(seat, NULL);
}
}
struct roots_desktop *desktop_create(struct roots_server *server, struct roots_desktop *desktop_create(struct roots_server *server,
struct roots_config *config) { struct roots_config *config) {
wlr_log(L_DEBUG, "Initializing roots desktop"); wlr_log(L_DEBUG, "Initializing roots desktop");
@ -774,6 +776,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->config = config; desktop->config = config;
desktop->layout = wlr_output_layout_create(); desktop->layout = wlr_output_layout_create();
wlr_xdg_output_manager_create(server->wl_display, desktop->layout);
desktop->layout_change.notify = handle_layout_change; desktop->layout_change.notify = handle_layout_change;
wl_signal_add(&desktop->layout->events.change, &desktop->layout_change); wl_signal_add(&desktop->layout->events.change, &desktop->layout_change);
@ -855,6 +858,15 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->idle = wlr_idle_create(server->wl_display); desktop->idle = wlr_idle_create(server->wl_display);
desktop->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display); desktop->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display);
desktop->input_inhibit =
wlr_input_inhibit_manager_create(server->wl_display);
desktop->input_inhibit_activate.notify = input_inhibit_activate;
wl_signal_add(&desktop->input_inhibit->events.activate,
&desktop->input_inhibit_activate);
desktop->input_inhibit_deactivate.notify = input_inhibit_deactivate;
wl_signal_add(&desktop->input_inhibit->events.deactivate,
&desktop->input_inhibit_deactivate);
struct wlr_egl *egl = wlr_backend_get_egl(server->backend); struct wlr_egl *egl = wlr_backend_get_egl(server->backend);
desktop->linux_dmabuf = wlr_linux_dmabuf_create(server->wl_display, egl); desktop->linux_dmabuf = wlr_linux_dmabuf_create(server->wl_display, egl);
return desktop; return desktop;

@ -281,6 +281,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = layer_surface->output; struct wlr_output *wlr_output = layer_surface->output;
struct roots_output *output = wlr_output->data; struct roots_output *output = wlr_output->data;
wlr_output_damage_add_box(output->damage, &layer->geo); wlr_output_damage_add_box(output->damage, &layer->geo);
wlr_surface_send_enter(layer_surface->surface, wlr_output);
} }
static void handle_unmap(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) {

@ -1,6 +1,8 @@
#define _POSIX_C_SOURCE 199309L
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/config.h> #include <wlr/config.h>
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
@ -716,7 +718,17 @@ struct roots_seat_view *roots_seat_view_from_view(
return seat_view; return seat_view;
} }
bool roots_seat_allow_input(struct roots_seat *seat,
struct wl_resource *resource) {
return !seat->exclusive_client ||
wl_resource_get_client(resource) == seat->exclusive_client;
}
void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
if (view && !roots_seat_allow_input(seat, view->wlr_surface->resource)) {
return;
}
// Make sure the view will be rendered on top of others, even if it's // Make sure the view will be rendered on top of others, even if it's
// already focused in this seat // already focused in this seat
if (view != NULL) { if (view != NULL) {
@ -811,11 +823,14 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
*/ */
void roots_seat_set_focus_layer(struct roots_seat *seat, void roots_seat_set_focus_layer(struct roots_seat *seat,
struct wlr_layer_surface *layer) { struct wlr_layer_surface *layer) {
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
if (!layer) { if (!layer) {
seat->focused_layer = NULL; seat->focused_layer = NULL;
return; return;
} }
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
if (!roots_seat_allow_input(seat, layer->resource)) {
return;
}
if (seat->has_focus) { if (seat->has_focus) {
struct roots_view *prev_focus = roots_seat_get_focus(seat); struct roots_view *prev_focus = roots_seat_get_focus(seat);
wlr_seat_keyboard_clear_focus(seat->seat); wlr_seat_keyboard_clear_focus(seat->seat);
@ -835,6 +850,46 @@ void roots_seat_set_focus_layer(struct roots_seat *seat,
} }
} }
void roots_seat_set_exclusive_client(struct roots_seat *seat,
struct wl_client *client) {
if (!client) {
seat->exclusive_client = client;
// Triggers a refocus of the topmost surface layer if necessary
// TODO: Make layer surface focus per-output based on cursor position
struct roots_output *output;
wl_list_for_each(output, &seat->input->server->desktop->outputs, link) {
arrange_layers(output);
}
return;
}
if (seat->focused_layer) {
if (wl_resource_get_client(seat->focused_layer->resource) != client) {
roots_seat_set_focus_layer(seat, NULL);
}
}
if (seat->has_focus) {
struct roots_view *focus = roots_seat_get_focus(seat);
if (wl_resource_get_client(focus->wlr_surface->resource) != client) {
roots_seat_set_focus(seat, NULL);
}
}
if (seat->seat->pointer_state.focused_client) {
if (seat->seat->pointer_state.focused_client->client != client) {
wlr_seat_pointer_clear_focus(seat->seat);
}
}
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct wlr_touch_point *point;
wl_list_for_each(point, &seat->seat->touch_state.touch_points, link) {
if (point->client->client != client) {
wlr_seat_touch_point_clear_focus(seat->seat,
now.tv_nsec / 1000, point->touch_id);
}
}
seat->exclusive_client = client;
}
void roots_seat_cycle_focus(struct roots_seat *seat) { void roots_seat_cycle_focus(struct roots_seat *seat) {
if (wl_list_empty(&seat->views)) { if (wl_list_empty(&seat->views)) {
return; return;

@ -10,6 +10,7 @@ lib_wlr_types = static_library(
'wlr_idle.c', 'wlr_idle.c',
'wlr_idle_inhibit_v1.c', 'wlr_idle_inhibit_v1.c',
'wlr_input_device.c', 'wlr_input_device.c',
'wlr_input_inhibitor.c',
'wlr_keyboard.c', 'wlr_keyboard.c',
'wlr_layer_shell.c', 'wlr_layer_shell.c',
'wlr_linux_dmabuf.c', 'wlr_linux_dmabuf.c',
@ -32,6 +33,7 @@ lib_wlr_types = static_library(
'wlr_xcursor_manager.c', 'wlr_xcursor_manager.c',
'wlr_xdg_shell_v6.c', 'wlr_xdg_shell_v6.c',
'wlr_xdg_shell.c', 'wlr_xdg_shell.c',
'wlr_xdg_output.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [pixman, xkbcommon, wayland_server, wlr_protos], dependencies: [pixman, xkbcommon, wayland_server, wlr_protos],

@ -7,6 +7,18 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "util/signal.h" #include "util/signal.h"
static const char *subsurface_role = "wl_subsurface";
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
return strcmp(surface->role, subsurface_role) == 0;
}
struct wlr_subsurface *wlr_subsurface_from_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_subsurface(surface));
return (struct wlr_subsurface *)surface->role_data;
}
static const struct wl_compositor_interface wl_compositor_impl; static const struct wl_compositor_interface wl_compositor_impl;
static struct wlr_compositor *compositor_from_resource(struct wl_resource *resource) { static struct wlr_compositor *compositor_from_resource(struct wl_resource *resource) {
@ -126,7 +138,7 @@ static void subcompositor_get_subsurface(struct wl_client *client,
return; return;
} }
if (wlr_surface_get_main_surface(parent) == surface) { if (wlr_surface_get_root_surface(parent) == surface) {
wl_resource_post_error(resource, wl_resource_post_error(resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
"%s%d: wl_surface@%d is an ancestor of parent", "%s%d: wl_surface@%d is an ancestor of parent",
@ -134,7 +146,7 @@ static void subcompositor_get_subsurface(struct wl_client *client,
return; return;
} }
if (wlr_surface_set_role(surface, "wl_subsurface", resource, if (wlr_surface_set_role(surface, subsurface_role, resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) { WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) {
return; return;
} }
@ -144,6 +156,8 @@ static void subcompositor_get_subsurface(struct wl_client *client,
wl_resource_post_no_memory(resource); wl_resource_post_no_memory(resource);
return; return;
} }
surface->role_data = surface->subsurface;
} }

@ -0,0 +1,150 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server.h>
#include "wlr/types/wlr_input_inhibitor.h"
#include "wlr-input-inhibitor-unstable-v1-protocol.h"
static const struct zwlr_input_inhibit_manager_v1_interface inhibit_manager_implementation;
static struct zwlr_input_inhibitor_v1_interface input_inhibitor_implementation;
static struct wlr_input_inhibit_manager *input_inhibit_manager_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource,
&zwlr_input_inhibit_manager_v1_interface,
&inhibit_manager_implementation)
|| wl_resource_instance_of(resource,
&zwlr_input_inhibitor_v1_interface,
&input_inhibitor_implementation));
return wl_resource_get_user_data(resource);
}
static void input_inhibit_manager_deactivate(
struct wlr_input_inhibit_manager *manager) {
if (manager->active_client == NULL && manager->active_inhibitor == NULL) {
return;
}
manager->active_client = NULL;
manager->active_inhibitor = NULL;
wl_signal_emit(&manager->events.deactivate, manager);
}
static void input_inhibitor_destroy(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
input_inhibit_manager_deactivate(manager);
wl_resource_destroy(resource);
}
static void input_inhibitor_resource_destroy(struct wl_resource *resource) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
input_inhibit_manager_deactivate(manager);
}
static struct zwlr_input_inhibitor_v1_interface input_inhibitor_implementation = {
.destroy = input_inhibitor_destroy,
};
static void inhibit_manager_get_inhibitor(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
if (manager->active_client || manager->active_inhibitor) {
wl_resource_post_error(resource,
ZWLR_INPUT_INHIBIT_MANAGER_V1_ERROR_ALREADY_INHIBITED,
"this compositor already has input inhibited");
return;
}
struct wl_resource *wl_resource = wl_resource_create(client,
&zwlr_input_inhibitor_v1_interface,
wl_resource_get_version(resource), id);
if (!wl_resource) {
wl_client_post_no_memory(client);
}
wl_resource_set_implementation(wl_resource, &input_inhibitor_implementation,
manager, input_inhibitor_resource_destroy);
manager->active_client = client;
manager->active_inhibitor = wl_resource;
wl_signal_emit(&manager->events.activate, manager);
}
static const struct zwlr_input_inhibit_manager_v1_interface inhibit_manager_implementation = {
.get_inhibitor = inhibit_manager_get_inhibitor
};
static void input_manager_resource_destroy(struct wl_resource *resource) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
struct wl_client *client = wl_resource_get_client(resource);
if (manager->active_client == client) {
input_inhibit_manager_deactivate(manager);
}
}
static void inhibit_manager_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) {
struct wlr_input_inhibit_manager *manager = data;
assert(wl_client && manager);
struct wl_resource *wl_resource = wl_resource_create(wl_client,
&zwlr_input_inhibit_manager_v1_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource,
&inhibit_manager_implementation, manager,
input_manager_resource_destroy);
}
void wlr_input_inhibit_manager_destroy(
struct wlr_input_inhibit_manager *manager) {
if (!manager) {
return;
}
if (manager->active_client) {
input_inhibitor_destroy(manager->active_client,
manager->active_inhibitor);
}
wl_list_remove(&manager->display_destroy.link);
wl_global_destroy(manager->wl_global);
free(manager);
}
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_input_inhibit_manager *manager =
wl_container_of(listener, manager, display_destroy);
wlr_input_inhibit_manager_destroy(manager);
}
struct wlr_input_inhibit_manager *wlr_input_inhibit_manager_create(
struct wl_display *display) {
// TODO: Client destroy
struct wlr_input_inhibit_manager *manager =
calloc(1, sizeof(struct wlr_input_inhibit_manager));
if (!manager) {
return NULL;
}
manager->wl_global = wl_global_create(display,
&zwlr_input_inhibit_manager_v1_interface,
1, manager, inhibit_manager_bind);
if (manager->wl_global == NULL){
wl_list_remove(&manager->display_destroy.link);
free(manager);
return NULL;
}
wl_signal_init(&manager->events.activate);
wl_signal_init(&manager->events.deactivate);
manager->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &manager->display_destroy);
return manager;
}

@ -137,6 +137,7 @@ static void surface_set_input_region(struct wl_client *client,
pixman_region32_t *region = wlr_region_from_resource(region_resource); pixman_region32_t *region = wlr_region_from_resource(region_resource);
pixman_region32_copy(&surface->pending->input, region); pixman_region32_copy(&surface->pending->input, region);
} else { } else {
pixman_region32_fini(&surface->pending->input);
pixman_region32_init_rect(&surface->pending->input, pixman_region32_init_rect(&surface->pending->input,
INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX); INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
} }
@ -868,43 +869,41 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
} }
struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface) { struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface) {
struct wlr_subsurface *sub; while (surface != NULL) {
struct wlr_subsurface *sub = surface->subsurface;
while (surface && (sub = surface->subsurface)) { if (sub == NULL) {
return surface;
}
surface = sub->parent; surface = sub->parent;
} }
return NULL;
}
return surface; bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
double sx, double sy) {
return sx >= 0 && sx <= surface->current->width &&
sy >= 0 && sy <= surface->current->height &&
pixman_region32_contains_point(&surface->current->input, sx, sy, NULL);
} }
struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y) { double sx, double sy, double *sub_x, double *sub_y) {
struct wlr_subsurface *subsurface; struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
double _sub_x = subsurface->surface->current->subsurface_position.x; double _sub_x = subsurface->surface->current->subsurface_position.x;
double _sub_y = subsurface->surface->current->subsurface_position.y; double _sub_y = subsurface->surface->current->subsurface_position.y;
struct wlr_subsurface *sub = struct wlr_surface *sub = wlr_surface_surface_at(subsurface->surface,
wlr_surface_subsurface_at(subsurface->surface, _sub_x + sx, sx - _sub_x, sy - _sub_y, sub_x, sub_y);
_sub_y + sy, sub_x, sub_y); if (sub != NULL) {
if (sub) {
// TODO: This won't work for nested subsurfaces. Convert sub_x and
// sub_y to the parent coordinate system
return sub; return sub;
} }
}
int sub_width = subsurface->surface->current->buffer_width; if (wlr_surface_point_accepts_input(surface, sx, sy)) {
int sub_height = subsurface->surface->current->buffer_height; *sub_x = sx;
if ((sx > _sub_x && sx < _sub_x + sub_width) && *sub_y = sy;
(sy > _sub_y && sy < _sub_y + sub_height)) { return surface;
if (pixman_region32_contains_point(
&subsurface->surface->current->input,
sx - _sub_x, sy - _sub_y, NULL)) {
*sub_x = _sub_x;
*sub_y = _sub_y;
return subsurface;
}
}
} }
return NULL; return NULL;
@ -952,10 +951,3 @@ void wlr_surface_set_role_committed(struct wlr_surface *surface,
surface->role_committed = role_committed; surface->role_committed = role_committed;
surface->role_data = role_data; surface->role_data = role_data;
} }
bool wlr_surface_point_accepts_input(
struct wlr_surface *surface, double sx, double sy) {
return sx >= 0 && sx <= surface->current->width &&
sy >= 0 && sy <= surface->current->height &&
pixman_region32_contains_point(&surface->current->input, sx, sy, NULL);
}

@ -658,42 +658,23 @@ void wlr_wl_shell_surface_configure(struct wlr_wl_shell_surface *surface,
wl_shell_surface_send_configure(surface->resource, edges, width, height); wl_shell_surface_send_configure(surface->resource, edges, width, height);
} }
struct wlr_wl_shell_surface *wlr_wl_shell_surface_popup_at( struct wlr_surface *wlr_wl_shell_surface_surface_at(
struct wlr_wl_shell_surface *surface, double sx, double sy, struct wlr_wl_shell_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy) { double *sub_sx, double *sub_sy) {
struct wlr_wl_shell_surface *popup; struct wlr_wl_shell_surface *popup;
wl_list_for_each(popup, &surface->popups, popup_link) { wl_list_for_each(popup, &surface->popups, popup_link) {
if (!popup->popup_mapped) { if (!popup->popup_mapped) {
continue; continue;
} }
double _popup_sx = popup->transient_state->x;
double _popup_sy = popup->transient_state->y;
int popup_width =
popup->surface->current->buffer_width;
int popup_height =
popup->surface->current->buffer_height;
struct wlr_wl_shell_surface *_popup =
wlr_wl_shell_surface_popup_at(popup,
popup->transient_state->x,
popup->transient_state->y,
popup_sx, popup_sy);
if (_popup) {
*popup_sx = sx + _popup_sx;
*popup_sy = sy + _popup_sy;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) && double popup_sx = popup->transient_state->x;
(sy > _popup_sy && sy < _popup_sy + popup_height)) { double popup_sy = popup->transient_state->y;
if (pixman_region32_contains_point(&popup->surface->current->input, struct wlr_surface *sub = wlr_wl_shell_surface_surface_at(popup,
sx - _popup_sx, sy - _popup_sy, NULL)) { sx - popup_sx, sy - popup_sy, sub_sx, sub_sy);
*popup_sx = _popup_sx; if (sub != NULL) {
*popup_sy = _popup_sy; return sub;
return popup;
}
} }
} }
return NULL; return wlr_surface_surface_at(surface->surface, sx, sy, sub_sx, sub_sy);
} }

@ -0,0 +1,178 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_xdg_output.h>
#include <wlr/util/log.h>
#include "xdg-output-unstable-v1-protocol.h"
static void xdg_output_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static const struct zxdg_output_v1_interface xdg_output_implementation = {
.destroy = xdg_output_destroy,
};
static void xdg_output_manager_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation;
static void xdg_output_send_details(struct wl_resource *resource,
struct wlr_output_layout_output *layout_output) {
zxdg_output_v1_send_logical_position(resource,
layout_output->x, layout_output->y);
zxdg_output_v1_send_logical_size(resource,
(float)layout_output->output->width / layout_output->output->scale,
(float)layout_output->output->height / layout_output->output->scale);
zxdg_output_v1_send_done(resource);
}
static void xdg_output_manager_get_xdg_output(struct wl_client *client,
struct wl_resource *resource, uint32_t id, struct wl_resource *output) {
assert(wl_resource_instance_of(resource, &zxdg_output_manager_v1_interface,
&xdg_output_manager_implementation));
struct wlr_xdg_output_manager *manager =
wl_resource_get_user_data(resource);
struct wlr_output_layout *layout = manager->layout;
struct wlr_output *wlr_output = wlr_output_from_resource(output);
struct wlr_output_layout_output *layout_output =
wlr_output_layout_get(layout, wlr_output);
assert(layout_output);
struct wl_resource *output_resource = wl_resource_create(client,
&zxdg_output_v1_interface, wl_resource_get_version(resource), id);
if (!output_resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(output_resource,
&xdg_output_implementation, NULL, NULL);
xdg_output_send_details(output_resource, layout_output);
}
static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation = {
.destroy = xdg_output_manager_destroy,
.get_xdg_output = xdg_output_manager_get_xdg_output,
};
static void output_manager_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) {
struct wlr_xdg_output_manager *manager = data;
assert(wl_client && manager);
struct wl_resource *wl_resource = wl_resource_create(wl_client,
&zxdg_output_manager_v1_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource,
&xdg_output_manager_implementation, manager, NULL);
}
static void destroy_output(struct wlr_xdg_output *output) {
struct wl_resource *resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &output->resources) {
wl_list_remove(wl_resource_get_link(resource));
wl_list_init(wl_resource_get_link(resource));
}
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->link);
free(output);
}
static void handle_output_destroy(struct wl_listener *listener, void *data) {
struct wlr_xdg_output *output = wl_container_of(listener, output, destroy);
destroy_output(output);
}
static void add_output(struct wlr_xdg_output_manager *manager,
struct wlr_output_layout_output *layout_output) {
struct wlr_xdg_output *output = calloc(1, sizeof(struct wlr_xdg_output));
wl_list_init(&output->resources);
output->manager = manager;
output->layout_output = layout_output;
output->destroy.notify = handle_output_destroy;
wl_signal_add(&layout_output->events.destroy, &output->destroy);
wl_list_insert(&manager->outputs, &output->link);
}
static void xdg_output_manager_send_details(
struct wlr_xdg_output_manager *manager) {
struct wlr_xdg_output *output;
wl_list_for_each(output, &manager->outputs, link) {
struct wl_resource *resource;
wl_resource_for_each(resource, &output->resources) {
xdg_output_send_details(resource, output->layout_output);
}
}
}
static void handle_layout_add(struct wl_listener *listener, void *data) {
struct wlr_xdg_output_manager *manager =
wl_container_of(listener, manager, layout_add);
struct wlr_output_layout_output *layout_output = data;
add_output(manager, layout_output);
}
static void handle_layout_change(struct wl_listener *listener, void *data) {
struct wlr_xdg_output_manager *manager =
wl_container_of(listener, manager, layout_change);
xdg_output_manager_send_details(manager);
}
static void handle_layout_destroy(struct wl_listener *listener, void *data) {
struct wlr_xdg_output_manager *manager =
wl_container_of(listener, manager, layout_change);
wlr_xdg_output_manager_destroy(manager);
}
struct wlr_xdg_output_manager *wlr_xdg_output_manager_create(
struct wl_display *display, struct wlr_output_layout *layout) {
assert(display && layout);
struct wlr_xdg_output_manager *manager =
calloc(1, sizeof(struct wlr_xdg_output_manager));
if (manager == NULL) {
return NULL;
}
manager->layout = layout;
manager->global = wl_global_create(display,
&zxdg_output_manager_v1_interface,
1, manager, output_manager_bind);
if (!manager->global) {
free(manager);
return NULL;
}
wl_list_init(&manager->outputs);
struct wlr_output_layout_output *layout_output;
wl_list_for_each(layout_output, &layout->outputs, link) {
add_output(manager, layout_output);
}
manager->layout_add.notify = handle_layout_add;
wl_signal_add(&layout->events.add, &manager->layout_add);
manager->layout_change.notify = handle_layout_change;
wl_signal_add(&layout->events.change, &manager->layout_change);
manager->layout_destroy.notify = handle_layout_destroy;
wl_signal_add(&layout->events.destroy, &manager->layout_destroy);
return manager;
}
void wlr_xdg_output_manager_destroy(struct wlr_xdg_output_manager *manager) {
struct wlr_xdg_output *output, *tmp;
wl_list_for_each_safe(output, tmp, &manager->outputs, link) {
destroy_output(output);
}
wl_list_remove(&manager->layout_add.link);
wl_list_remove(&manager->layout_change.link);
wl_list_remove(&manager->layout_destroy.link);
free(manager);
}

@ -1638,45 +1638,24 @@ void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface,
surface->geometry.y; surface->geometry.y;
} }
struct wlr_xdg_surface *wlr_xdg_surface_popup_at( struct wlr_surface *wlr_xdg_surface_surface_at(
struct wlr_xdg_surface *surface, double sx, double sy, struct wlr_xdg_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy) { double *sub_x, double *sub_y) {
// XXX: I think this is so complicated because we're mixing geometry
// coordinates with surface coordinates. Input handling should only deal
// with surface coordinates.
struct wlr_xdg_popup *popup_state; struct wlr_xdg_popup *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) { wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface *popup = popup_state->base; struct wlr_xdg_surface *popup = popup_state->base;
double _popup_sx = double popup_sx, popup_sy;
surface->geometry.x + popup_state->geometry.x; wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy);
double _popup_sy =
surface->geometry.y + popup_state->geometry.y;
int popup_width = popup_state->geometry.width;
int popup_height = popup_state->geometry.height;
struct wlr_xdg_surface *_popup =
wlr_xdg_surface_popup_at(popup,
sx - _popup_sx + popup->geometry.x,
sy - _popup_sy + popup->geometry.y,
popup_sx, popup_sy);
if (_popup) {
*popup_sx = *popup_sx + _popup_sx - popup->geometry.x;
*popup_sy = *popup_sy + _popup_sy - popup->geometry.y;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) && struct wlr_surface *sub = wlr_xdg_surface_surface_at(popup,
(sy > _popup_sy && sy < _popup_sy + popup_height)) { sx - popup_sx + popup->geometry.x,
if (pixman_region32_contains_point(&popup->surface->current->input, sy - popup_sy + popup->geometry.y,
sx - _popup_sx + popup->geometry.x, sub_x, sub_y);
sy - _popup_sy + popup->geometry.y, NULL)) { if (sub != NULL) {
*popup_sx = _popup_sx - popup->geometry.x; return sub;
*popup_sy = _popup_sy - popup->geometry.y;
return popup;
}
} }
} }
return NULL; return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
} }

@ -1602,47 +1602,26 @@ void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface,
surface->geometry.y; surface->geometry.y;
} }
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_surface *wlr_xdg_surface_v6_surface_at(
struct wlr_xdg_surface_v6 *surface, double sx, double sy, struct wlr_xdg_surface_v6 *surface, double sx, double sy,
double *popup_sx, double *popup_sy) { double *sub_x, double *sub_y) {
// XXX: I think this is so complicated because we're mixing geometry
// coordinates with surface coordinates. Input handling should only deal
// with surface coordinates.
struct wlr_xdg_popup_v6 *popup_state; struct wlr_xdg_popup_v6 *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) { wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface_v6 *popup = popup_state->base; struct wlr_xdg_surface_v6 *popup = popup_state->base;
double _popup_sx = double popup_sx, popup_sy;
surface->geometry.x + popup_state->geometry.x; wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy);
double _popup_sy =
surface->geometry.y + popup_state->geometry.y;
int popup_width = popup_state->geometry.width;
int popup_height = popup_state->geometry.height;
struct wlr_xdg_surface_v6 *_popup =
wlr_xdg_surface_v6_popup_at(popup,
sx - _popup_sx + popup->geometry.x,
sy - _popup_sy + popup->geometry.y,
popup_sx, popup_sy);
if (_popup) {
*popup_sx = *popup_sx + _popup_sx - popup->geometry.x;
*popup_sy = *popup_sy + _popup_sy - popup->geometry.y;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) && struct wlr_surface *sub = wlr_xdg_surface_v6_surface_at(popup,
(sy > _popup_sy && sy < _popup_sy + popup_height)) { sx - popup_sx + popup->geometry.x,
if (pixman_region32_contains_point(&popup->surface->current->input, sy - popup_sy + popup->geometry.y,
sx - _popup_sx + popup->geometry.x, sub_x, sub_y);
sy - _popup_sy + popup->geometry.y, NULL)) { if (sub != NULL) {
*popup_sx = _popup_sx - popup->geometry.x; return sub;
*popup_sy = _popup_sy - popup->geometry.y;
return popup;
}
} }
} }
return NULL; return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
} }
void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup,

Loading…
Cancel
Save