Merge pull request #571 from emersion/output-damage

Output damage tracking
master
Drew DeVault 7 years ago committed by GitHub
commit 34489dca16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,7 +37,6 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
return; return;
} }
wl_signal_emit(&backend->events.destroy, backend);
if (backend->impl && backend->impl->destroy) { if (backend->impl && backend->impl->destroy) {
backend->impl->destroy(backend); backend->impl->destroy(backend);
} else { } else {

@ -34,6 +34,8 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
wlr_output_destroy(&conn->output); wlr_output_destroy(&conn->output);
} }
wl_signal_emit(&backend->events.destroy, backend);
wl_list_remove(&drm->display_destroy.link); wl_list_remove(&drm->display_destroy.link);
wl_list_remove(&drm->session_signal.link); wl_list_remove(&drm->session_signal.link);
wl_list_remove(&drm->drm_invalidated.link); wl_list_remove(&drm->drm_invalidated.link);
@ -89,6 +91,8 @@ static void session_signal(struct wl_listener *listener, void *data) {
struct wlr_drm_plane *plane = conn->crtc->cursor; struct wlr_drm_plane *plane = conn->crtc->cursor;
drm->iface->crtc_set_cursor(drm, conn->crtc, drm->iface->crtc_set_cursor(drm, conn->crtc,
(plane && plane->cursor_enabled) ? plane->cursor_bo : NULL); (plane && plane->cursor_enabled) ? plane->cursor_bo : NULL);
drm->iface->crtc_move_cursor(drm, conn->crtc, conn->cursor_x,
conn->cursor_y);
} }
} else { } else {
wlr_log(L_INFO, "DRM fd paused"); wlr_log(L_INFO, "DRM fd paused");

@ -184,18 +184,22 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) {
free(drm->planes); free(drm->planes);
} }
static void wlr_drm_connector_make_current(struct wlr_output *output) { static bool wlr_drm_connector_make_current(struct wlr_output *output,
int *buffer_age) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
wlr_drm_surface_make_current(&conn->crtc->primary->surf); return wlr_drm_surface_make_current(&conn->crtc->primary->surf, buffer_age);
} }
static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { static bool wlr_drm_connector_swap_buffers(struct wlr_output *output) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
if (!drm->session->active) {
return false;
}
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
if (!crtc) { if (!crtc) {
return; return false;
} }
struct wlr_drm_plane *plane = crtc->primary; struct wlr_drm_plane *plane = crtc->primary;
@ -203,16 +207,20 @@ static void wlr_drm_connector_swap_buffers(struct wlr_output *output) {
if (drm->parent) { if (drm->parent) {
bo = wlr_drm_surface_mgpu_copy(&plane->mgpu_surf, bo); bo = wlr_drm_surface_mgpu_copy(&plane->mgpu_surf, bo);
} }
uint32_t fb_id = get_fb_for_bo(bo); uint32_t fb_id = get_fb_for_bo(bo);
if (drm->iface->crtc_pageflip(drm, conn, crtc, fb_id, NULL)) { if (conn->pageflip_pending) {
conn->pageflip_pending = true; wlr_log(L_ERROR, "Skipping pageflip");
wlr_output_update_enabled(output, true); return false;
} else { }
wl_event_source_timer_update(conn->retry_pageflip,
1000.0f / conn->output.current_mode->refresh); if (!drm->iface->crtc_pageflip(drm, conn, crtc, fb_id, NULL)) {
return false;
} }
conn->pageflip_pending = true;
wlr_output_update_enabled(output, true);
return true;
} }
static void wlr_drm_connector_set_gamma(struct wlr_output *output, static void wlr_drm_connector_set_gamma(struct wlr_output *output,
@ -250,7 +258,7 @@ void wlr_drm_connector_start_renderer(struct wlr_drm_connector *conn) {
wlr_output_update_enabled(&conn->output, true); wlr_output_update_enabled(&conn->output, true);
} else { } else {
wl_event_source_timer_update(conn->retry_pageflip, wl_event_source_timer_update(conn->retry_pageflip,
1000.0f / conn->output.current_mode->refresh); 1000000.0f / conn->output.current_mode->refresh);
} }
} }
@ -531,6 +539,9 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
if (!buf && update_pixels) { if (!buf && update_pixels) {
// Hide the cursor // Hide the cursor
plane->cursor_enabled = false; plane->cursor_enabled = false;
if (!drm->session->active) {
return true;
}
return drm->iface->crtc_set_cursor(drm, crtc, NULL); return drm->iface->crtc_set_cursor(drm, crtc, NULL);
} }
plane->cursor_enabled = true; plane->cursor_enabled = true;
@ -577,17 +588,15 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
} }
struct wlr_box hotspot = { struct wlr_box hotspot = {
.width = plane->surf.width,
.height = plane->surf.height,
.x = hotspot_x, .x = hotspot_x,
.y = hotspot_y, .y = hotspot_y,
}; };
enum wl_output_transform transform = enum wl_output_transform transform =
wlr_output_transform_invert(output->transform); wlr_output_transform_invert(output->transform);
struct wlr_box transformed_hotspot; wlr_box_transform(&hotspot, transform,
wlr_box_transform(&hotspot, transform, &transformed_hotspot); plane->surf.width, plane->surf.height, &hotspot);
plane->cursor_hotspot_x = transformed_hotspot.x; plane->cursor_hotspot_x = hotspot.x;
plane->cursor_hotspot_y = transformed_hotspot.y; plane->cursor_hotspot_y = hotspot.y;
if (!update_pixels) { if (!update_pixels) {
// Only update the cursor hotspot // Only update the cursor hotspot
@ -606,7 +615,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
return false; return false;
} }
wlr_drm_surface_make_current(&plane->surf); wlr_drm_surface_make_current(&plane->surf, NULL);
wlr_texture_upload_pixels(plane->wlr_tex, WL_SHM_FORMAT_ARGB8888, wlr_texture_upload_pixels(plane->wlr_tex, WL_SHM_FORMAT_ARGB8888,
stride, width, height, buf); stride, width, height, buf);
@ -630,35 +639,52 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
gbm_bo_unmap(bo, bo_data); gbm_bo_unmap(bo, bo_data);
return drm->iface->crtc_set_cursor(drm, crtc, bo); if (!drm->session->active) {
return true;
}
bool ok = drm->iface->crtc_set_cursor(drm, crtc, bo);
if (ok) {
wlr_output_update_needs_swap(output);
}
return ok;
} }
static bool wlr_drm_connector_move_cursor(struct wlr_output *output, static bool wlr_drm_connector_move_cursor(struct wlr_output *output,
int x, int y) { int x, int y) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
if (!conn || !conn->crtc) { if (!conn->crtc) {
return false; return false;
} }
struct wlr_drm_plane *plane = conn->crtc->cursor; struct wlr_drm_plane *plane = conn->crtc->cursor;
struct wlr_box box; struct wlr_box box = { .x = x, .y = y };
box.x = x;
box.y = y; int width, height;
wlr_output_effective_resolution(output, &box.width, &box.height); wlr_output_transformed_resolution(output, &width, &height);
enum wl_output_transform transform = enum wl_output_transform transform =
wlr_output_transform_invert(output->transform); wlr_output_transform_invert(output->transform);
struct wlr_box transformed_box; wlr_box_transform(&box, transform, width, height, &box);
wlr_box_transform(&box, transform, &transformed_box);
if (plane != NULL) { if (plane != NULL) {
transformed_box.x -= plane->cursor_hotspot_x; box.x -= plane->cursor_hotspot_x;
transformed_box.y -= plane->cursor_hotspot_y; box.y -= plane->cursor_hotspot_y;
}
conn->cursor_x = box.x;
conn->cursor_y = box.y;
if (!drm->session->active) {
return true;
} }
return drm->iface->crtc_move_cursor(drm, conn->crtc, transformed_box.x, bool ok = drm->iface->crtc_move_cursor(drm, conn->crtc, box.x, box.y);
transformed_box.y); if (ok) {
wlr_output_update_needs_swap(output);
}
return ok;
} }
static void wlr_drm_connector_destroy(struct wlr_output *output) { static void wlr_drm_connector_destroy(struct wlr_output *output) {
@ -874,7 +900,7 @@ static void page_flip_handler(int fd, unsigned seq,
} }
if (drm->session->active) { if (drm->session->active) {
wl_signal_emit(&conn->output.events.frame, &conn->output); wlr_output_send_frame(&conn->output);
} }
} }

@ -128,9 +128,9 @@ void wlr_drm_surface_finish(struct wlr_drm_surface *surf) {
memset(surf, 0, sizeof(*surf)); memset(surf, 0, sizeof(*surf));
} }
void wlr_drm_surface_make_current(struct wlr_drm_surface *surf) { bool wlr_drm_surface_make_current(struct wlr_drm_surface *surf,
eglMakeCurrent(surf->renderer->egl.display, surf->egl, surf->egl, int *buffer_damage) {
surf->renderer->egl.context); return wlr_egl_make_current(&surf->renderer->egl, surf->egl, buffer_damage);
} }
struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf) { struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf) {
@ -138,7 +138,9 @@ struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf) {
gbm_surface_release_buffer(surf->gbm, surf->front); gbm_surface_release_buffer(surf->gbm, surf->front);
} }
eglSwapBuffers(surf->renderer->egl.display, surf->egl); if (!eglSwapBuffers(surf->renderer->egl.display, surf->egl)) {
wlr_log(L_ERROR, "eglSwapBuffers failed");
}
surf->front = surf->back; surf->front = surf->back;
surf->back = gbm_surface_lock_front_buffer(surf->gbm); surf->back = gbm_surface_lock_front_buffer(surf->gbm);
@ -150,7 +152,7 @@ struct gbm_bo *wlr_drm_surface_get_front(struct wlr_drm_surface *surf) {
return surf->front; return surf->front;
} }
wlr_drm_surface_make_current(surf); wlr_drm_surface_make_current(surf, NULL);
glViewport(0, 0, surf->width, surf->height); glViewport(0, 0, surf->width, surf->height);
glClearColor(0.0, 0.0, 0.0, 1.0); glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -222,8 +224,9 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, str
return tex->tex; return tex->tex;
} }
struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, struct gbm_bo *src) { struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest,
wlr_drm_surface_make_current(dest); struct gbm_bo *src) {
wlr_drm_surface_make_current(dest, NULL);
struct wlr_texture *tex = get_tex_for_bo(dest->renderer, src); struct wlr_texture *tex = get_tex_for_bo(dest->renderer, src);

@ -51,6 +51,8 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
wlr_input_device_destroy(&input_device->wlr_input_device); wlr_input_device_destroy(&input_device->wlr_input_device);
} }
wl_signal_emit(&wlr_backend->events.destroy, backend);
wlr_egl_finish(&backend->egl); wlr_egl_finish(&backend->egl);
free(backend); free(backend);
} }

@ -48,25 +48,20 @@ static void output_transform(struct wlr_output *wlr_output,
output->wlr_output.transform = transform; output->wlr_output.transform = transform;
} }
static void output_make_current(struct wlr_output *wlr_output) { static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
struct wlr_headless_output *output = struct wlr_headless_output *output =
(struct wlr_headless_output *)wlr_output; (struct wlr_headless_output *)wlr_output;
if (!eglMakeCurrent(output->backend->egl.display, return wlr_egl_make_current(&output->backend->egl, output->egl_surface,
output->egl_surface, output->egl_surface, buffer_age);
output->backend->egl.context)) {
wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error());
}
} }
static void output_swap_buffers(struct wlr_output *wlr_output) { static bool output_swap_buffers(struct wlr_output *wlr_output) {
// No-op return true; // No-op
} }
static void output_destroy(struct wlr_output *wlr_output) { static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_headless_output *output = struct wlr_headless_output *output =
(struct wlr_headless_output *)wlr_output; (struct wlr_headless_output *)wlr_output;
wl_signal_emit(&output->backend->backend.events.output_remove,
&output->wlr_output);
wl_list_remove(&output->link); wl_list_remove(&output->link);
@ -88,7 +83,7 @@ bool wlr_output_is_headless(struct wlr_output *wlr_output) {
static int signal_frame(void *data) { static int signal_frame(void *data) {
struct wlr_headless_output *output = data; struct wlr_headless_output *output = data;
wl_signal_emit(&output->wlr_output.events.frame, &output->wlr_output); wlr_output_send_frame(&output->wlr_output);
wl_event_source_timer_update(output->frame_timer, output->frame_delay); wl_event_source_timer_update(output->frame_timer, output->frame_delay);
return 0; return 0;
} }

@ -95,12 +95,12 @@ static bool wlr_libinput_backend_start(struct wlr_backend *_backend) {
return true; return true;
} }
static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) { static void wlr_libinput_backend_destroy(struct wlr_backend *wlr_backend) {
if (!_backend) { if (!wlr_backend) {
return; return;
} }
struct wlr_libinput_backend *backend = struct wlr_libinput_backend *backend =
(struct wlr_libinput_backend *)_backend; (struct wlr_libinput_backend *)wlr_backend;
for (size_t i = 0; i < backend->wlr_device_lists.length; i++) { for (size_t i = 0; i < backend->wlr_device_lists.length; i++) {
struct wl_list *wlr_devices = backend->wlr_device_lists.items[i]; struct wl_list *wlr_devices = backend->wlr_device_lists.items[i];
@ -112,6 +112,8 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) {
free(wlr_devices); free(wlr_devices);
} }
wl_signal_emit(&wlr_backend->events.destroy, wlr_backend);
wl_list_remove(&backend->display_destroy.link); wl_list_remove(&backend->display_destroy.link);
wl_list_remove(&backend->session_signal.link); wl_list_remove(&backend->session_signal.link);

@ -45,5 +45,16 @@ lib_wlr_backend = static_library(
'wlr_backend', 'wlr_backend',
backend_files, backend_files,
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [wayland_server, egl, gbm, libinput, systemd, elogind, wlr_render, wlr_protos, drm], dependencies: [
wayland_server,
egl,
gbm,
libinput,
systemd,
elogind,
wlr_render,
wlr_protos,
drm,
pixman,
],
) )

@ -42,11 +42,16 @@ static void subbackend_state_destroy(struct subbackend_state *sub) {
static void multi_backend_destroy(struct wlr_backend *wlr_backend) { static void multi_backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend; struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend;
wl_list_remove(&backend->display_destroy.link); wl_list_remove(&backend->display_destroy.link);
struct subbackend_state *sub, *next; struct subbackend_state *sub, *next;
wl_list_for_each_safe(sub, next, &backend->backends, link) { wl_list_for_each_safe(sub, next, &backend->backends, link) {
wlr_backend_destroy(sub->backend); wlr_backend_destroy(sub->backend);
} }
// Destroy this backend only after removing all sub-backends
wl_signal_emit(&wlr_backend->events.destroy, backend);
free(backend); free(backend);
} }

@ -64,9 +64,9 @@ static bool wlr_wl_backend_start(struct wlr_backend *_backend) {
return true; return true;
} }
static void wlr_wl_backend_destroy(struct wlr_backend *_backend) { static void wlr_wl_backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend; struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend;
if (!_backend) { if (backend == NULL) {
return; return;
} }
@ -80,6 +80,8 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) {
wlr_input_device_destroy(input_device); wlr_input_device_destroy(input_device);
} }
wl_signal_emit(&wlr_backend->events.destroy, wlr_backend);
wl_list_remove(&backend->local_display_destroy.link); wl_list_remove(&backend->local_display_destroy.link);
free(backend->seat_name); free(backend->seat_name);

@ -17,11 +17,14 @@ int os_create_anonymous_file(off_t size);
static struct wl_callback_listener frame_listener; static struct wl_callback_listener frame_listener;
static void surface_frame_callback(void *data, struct wl_callback *cb, uint32_t time) { static void surface_frame_callback(void *data, struct wl_callback *cb,
struct wlr_output *wlr_output = data; uint32_t time) {
assert(wlr_output); struct wlr_wl_backend_output *output = data;
wl_signal_emit(&wlr_output->events.frame, wlr_output); assert(output);
wl_callback_destroy(cb); wl_callback_destroy(cb);
output->frame_callback = NULL;
wlr_output_send_frame(&output->wlr_output);
} }
static struct wl_callback_listener frame_listener = { static struct wl_callback_listener frame_listener = {
@ -36,22 +39,32 @@ static bool wlr_wl_output_set_custom_mode(struct wlr_output *_output,
return true; return true;
} }
static void wlr_wl_output_make_current(struct wlr_output *_output) { static bool wlr_wl_output_make_current(struct wlr_output *wlr_output,
struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; int *buffer_age) {
if (!eglMakeCurrent(output->backend->egl.display, struct wlr_wl_backend_output *output =
output->egl_surface, output->egl_surface, (struct wlr_wl_backend_output *)wlr_output;
output->backend->egl.context)) { return wlr_egl_make_current(&output->backend->egl, output->egl_surface,
wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); buffer_age);
}
} }
static void wlr_wl_output_swap_buffers(struct wlr_output *_output) { static bool wlr_wl_output_swap_buffers(struct wlr_output *wlr_output) {
struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; struct wlr_wl_backend_output *output =
(struct wlr_wl_backend_output *)wlr_output;
if (output->frame_callback != NULL) {
wlr_log(L_ERROR, "Skipping buffer swap");
return false;
}
output->frame_callback = wl_surface_frame(output->surface); output->frame_callback = wl_surface_frame(output->surface);
wl_callback_add_listener(output->frame_callback, &frame_listener, output); wl_callback_add_listener(output->frame_callback, &frame_listener, output);
if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) { if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) {
wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error());
return false;
} }
return true;
} }
static void wlr_wl_output_transform(struct wlr_output *_output, static void wlr_wl_output_transform(struct wlr_output *_output,
@ -148,11 +161,12 @@ static bool wlr_wl_output_set_cursor(struct wlr_output *_output,
return true; return true;
} }
static void wlr_wl_output_destroy(struct wlr_output *_output) { static void wlr_wl_output_destroy(struct wlr_output *wlr_output) {
struct wlr_wl_backend_output *output = struct wlr_wl_backend_output *output =
(struct wlr_wl_backend_output *)_output; (struct wlr_wl_backend_output *)wlr_output;
wl_signal_emit(&output->backend->backend.events.output_remove, if (output == NULL) {
&output->wlr_output); return;
}
wl_list_remove(&output->link); wl_list_remove(&output->link);

@ -54,14 +54,16 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
struct wlr_output *wlr_output = &wlr_wl_pointer->current_output->wlr_output; struct wlr_output *wlr_output = &wlr_wl_pointer->current_output->wlr_output;
struct wlr_box box; int width, height;
wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window, wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window,
&box.width, &box.height); &width, &height);
box.x = wl_fixed_to_int(surface_x);
box.y = wl_fixed_to_int(surface_y);
struct wlr_box box = {
.x = wl_fixed_to_int(surface_x),
.y = wl_fixed_to_int(surface_y),
};
struct wlr_box transformed; struct wlr_box transformed;
wlr_box_transform(&box, wlr_output->transform, &transformed); wlr_box_transform(&box, wlr_output->transform, width, height, &transformed);
transformed.x /= wlr_output->scale; transformed.x /= wlr_output->scale;
transformed.y /= wlr_output->scale; transformed.y /= wlr_output->scale;

@ -45,7 +45,7 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
switch (event->response_type) { switch (event->response_type) {
case XCB_EXPOSE: { case XCB_EXPOSE: {
wl_signal_emit(&output->wlr_output.events.frame, output); wlr_output_send_frame(&output->wlr_output);
break; break;
} }
case XCB_KEY_PRESS: case XCB_KEY_PRESS:
@ -175,7 +175,7 @@ static int x11_event(int fd, uint32_t mask, void *data) {
static int signal_frame(void *data) { static int signal_frame(void *data) {
struct wlr_x11_backend *x11 = data; struct wlr_x11_backend *x11 = data;
wl_signal_emit(&x11->output.wlr_output.events.frame, &x11->output); wlr_output_send_frame(&x11->output.wlr_output);
wl_event_source_timer_update(x11->frame_timer, 16); wl_event_source_timer_update(x11->frame_timer, 16);
return 0; return 0;
} }
@ -259,6 +259,8 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) {
xkb_state_unref(x11->keyboard_dev.keyboard->xkb_state); xkb_state_unref(x11->keyboard_dev.keyboard->xkb_state);
} }
wl_signal_emit(&backend->events.destroy, backend);
wl_list_remove(&x11->display_destroy.link); wl_list_remove(&x11->display_destroy.link);
wl_event_source_remove(x11->frame_timer); wl_event_source_remove(x11->frame_timer);
@ -392,22 +394,23 @@ static void output_destroy(struct wlr_output *wlr_output) {
// output has been allocated on the stack, do not free it // output has been allocated on the stack, do not free it
} }
static void output_make_current(struct wlr_output *wlr_output) { static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
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; struct wlr_x11_backend *x11 = output->x11;
if (!eglMakeCurrent(x11->egl.display, output->surf, output->surf, x11->egl.context)) { return wlr_egl_make_current(&x11->egl, output->surf, buffer_age);
wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error());
}
} }
static void output_swap_buffers(struct wlr_output *wlr_output) { static bool output_swap_buffers(struct wlr_output *wlr_output) {
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; struct wlr_x11_backend *x11 = output->x11;
if (!eglSwapBuffers(x11->egl.display, output->surf)) { if (!eglSwapBuffers(x11->egl.display, output->surf)) {
wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error());
return false;
} }
return true;
} }
static struct wlr_output_impl output_impl = { static struct wlr_output_impl output_impl = {

@ -56,13 +56,13 @@ static void handle_output_frame(struct output_state *output,
struct sample_state *sample = state->data; struct sample_state *sample = state->data;
struct wlr_output *wlr_output = output->output; struct wlr_output *wlr_output = output->output;
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output, NULL);
glClearColor(sample->clear_color[0], sample->clear_color[1], glClearColor(sample->clear_color[0], sample->clear_color[1],
sample->clear_color[2], sample->clear_color[3]); sample->clear_color[2], sample->clear_color[3]);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
wlr_output_swap_buffers(wlr_output); wlr_output_swap_buffers(wlr_output, NULL, NULL);
} }
static void handle_output_add(struct output_state *ostate) { static void handle_output_add(struct output_state *ostate) {

@ -100,8 +100,9 @@ static void handle_output_frame(struct output_state *output,
struct sample_state *sample = state->data; struct sample_state *sample = state->data;
struct wlr_output *wlr_output = output->output; struct wlr_output *wlr_output = output->output;
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output, NULL);
wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_begin(sample->renderer, wlr_output);
wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1});
animate_cat(sample, output->output); animate_cat(sample, output->output);
@ -125,7 +126,7 @@ static void handle_output_frame(struct output_state *output,
} }
wlr_renderer_end(sample->renderer); wlr_renderer_end(sample->renderer);
wlr_output_swap_buffers(wlr_output); wlr_output_swap_buffers(wlr_output, NULL, NULL);
} }
static void handle_output_add(struct output_state *ostate) { static void handle_output_add(struct output_state *ostate) {

@ -85,13 +85,13 @@ static void handle_output_frame(struct output_state *output,
struct sample_state *sample = state->data; struct sample_state *sample = state->data;
struct wlr_output *wlr_output = output->output; struct wlr_output *wlr_output = output->output;
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output, NULL);
glClearColor(sample->clear_color[0], sample->clear_color[1], glClearColor(sample->clear_color[0], sample->clear_color[1],
sample->clear_color[2], sample->clear_color[3]); sample->clear_color[2], sample->clear_color[3]);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
wlr_output_swap_buffers(wlr_output); wlr_output_swap_buffers(wlr_output, NULL, NULL);
} }
static void handle_output_add(struct output_state *ostate) { static void handle_output_add(struct output_state *ostate) {

@ -42,8 +42,9 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
int32_t width, height; int32_t width, height;
wlr_output_effective_resolution(wlr_output, &width, &height); wlr_output_effective_resolution(wlr_output, &width, &height);
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output, NULL);
wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_begin(sample->renderer, wlr_output);
wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1});
float matrix[16]; float matrix[16];
for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { for (int y = -128 + (int)odata->y_offs; y < height; y += 128) {
@ -56,7 +57,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
} }
wlr_renderer_end(sample->renderer); wlr_renderer_end(sample->renderer);
wlr_output_swap_buffers(wlr_output); wlr_output_swap_buffers(wlr_output, NULL, NULL);
long ms = (ts->tv_sec - output->last_frame.tv_sec) * 1000 + long ms = (ts->tv_sec - output->last_frame.tv_sec) * 1000 +
(ts->tv_nsec - output->last_frame.tv_nsec) / 1000000; (ts->tv_nsec - output->last_frame.tv_nsec) / 1000000;

@ -35,12 +35,12 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) {
sample->dec = inc; sample->dec = inc;
} }
wlr_output_make_current(output->output); wlr_output_make_current(output->output, NULL);
glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0); glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
wlr_output_swap_buffers(output->output); wlr_output_swap_buffers(output->output, NULL, NULL);
} }
int main() { int main() {

@ -42,8 +42,9 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
int32_t width, height; int32_t width, height;
wlr_output_effective_resolution(wlr_output, &width, &height); wlr_output_effective_resolution(wlr_output, &width, &height);
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output, NULL);
wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_begin(sample->renderer, wlr_output);
wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1});
float matrix[16], view[16]; float matrix[16], view[16];
float distance = 0.8f * (1 - sample->distance); float distance = 0.8f * (1 - sample->distance);
@ -76,7 +77,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
} }
wlr_renderer_end(sample->renderer); wlr_renderer_end(sample->renderer);
wlr_output_swap_buffers(wlr_output); wlr_output_swap_buffers(wlr_output, NULL, NULL);
} }
static void handle_tool_axis(struct tablet_tool_state *tstate, static void handle_tool_axis(struct tablet_tool_state *tstate,

@ -41,8 +41,9 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
int32_t width, height; int32_t width, height;
wlr_output_effective_resolution(wlr_output, &width, &height); wlr_output_effective_resolution(wlr_output, &width, &height);
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output, NULL);
wlr_renderer_begin(sample->renderer, wlr_output); wlr_renderer_begin(sample->renderer, wlr_output);
wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1});
float matrix[16]; float matrix[16];
struct touch_point *p; struct touch_point *p;
@ -56,7 +57,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
} }
wlr_renderer_end(sample->renderer); wlr_renderer_end(sample->renderer);
wlr_output_swap_buffers(wlr_output); wlr_output_swap_buffers(wlr_output, NULL, NULL);
} }
static void handle_touch_down(struct touch_state *tstate, int32_t touch_id, static void handle_touch_down(struct touch_state *tstate, int32_t touch_id,

@ -123,8 +123,8 @@ struct wlr_drm_connector {
union wlr_drm_connector_props props; union wlr_drm_connector_props props;
uint32_t width; uint32_t width, height;
uint32_t height; int32_t cursor_x, cursor_y;
drmModeCrtc *old_crtc; drmModeCrtc *old_crtc;

@ -45,7 +45,7 @@ bool wlr_drm_plane_surfaces_init(struct wlr_drm_plane *plane, struct wlr_drm_bac
int32_t width, uint32_t height, uint32_t format); int32_t width, uint32_t height, uint32_t format);
void wlr_drm_surface_finish(struct wlr_drm_surface *surf); void wlr_drm_surface_finish(struct wlr_drm_surface *surf);
void wlr_drm_surface_make_current(struct wlr_drm_surface *surf); bool wlr_drm_surface_make_current(struct wlr_drm_surface *surf, int *buffer_age);
struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf); struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf);
struct gbm_bo *wlr_drm_surface_get_front(struct wlr_drm_surface *surf); struct gbm_bo *wlr_drm_surface_get_front(struct wlr_drm_surface *surf);
void wlr_drm_surface_post(struct wlr_drm_surface *surf); void wlr_drm_surface_post(struct wlr_drm_surface *surf);

@ -16,15 +16,7 @@
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include "rootston/view.h" #include "rootston/view.h"
#include "rootston/config.h" #include "rootston/config.h"
#include "rootston/output.h"
struct roots_output {
struct roots_desktop *desktop;
struct wlr_output *wlr_output;
struct wl_listener frame;
struct timespec last_frame;
struct wl_list link; // roots_desktop:outputs
struct roots_view *fullscreen_view;
};
struct roots_desktop { struct roots_desktop {
struct wl_list views; // roots_view::link struct wl_list views; // roots_view::link
@ -64,7 +56,7 @@ struct roots_desktop {
struct roots_server; struct roots_server;
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);
void desktop_destroy(struct roots_desktop *desktop); void desktop_destroy(struct roots_desktop *desktop);
struct roots_output *desktop_output_from_wlr_output( struct roots_output *desktop_output_from_wlr_output(
struct roots_desktop *desktop, struct wlr_output *output); struct roots_desktop *desktop, struct wlr_output *output);
@ -72,11 +64,12 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
double ly, struct wlr_surface **surface, double *sx, double *sy); double ly, struct wlr_surface **surface, double *sx, double *sy);
void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_init(struct roots_view *view, struct roots_desktop *desktop);
void view_destroy(struct roots_view *view); void view_finish(struct roots_view *view);
void view_activate(struct roots_view *view, bool activate); void view_activate(struct roots_view *view, bool activate);
void view_apply_damage(struct roots_view *view);
void output_add_notify(struct wl_listener *listener, void *data); void view_damage_whole(struct roots_view *view);
void output_remove_notify(struct wl_listener *listener, void *data); void view_update_position(struct roots_view *view, double x, double y);
void view_update_size(struct roots_view *view, uint32_t width, uint32_t height);
void handle_xdg_shell_v6_surface(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_wl_shell_surface(struct wl_listener *listener, void *data);

@ -0,0 +1,50 @@
#ifndef _ROOTSTON_OUTPUT_H
#define _ROOTSTON_OUTPUT_H
#include <time.h>
#include <pixman.h>
#include <wayland-server.h>
/**
* Damage tracking requires to keep track of previous frames' damage. To allow
* damage tracking to work with triple buffering, a history of two frames is
* required.
*/
#define ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN 2
struct roots_desktop;
struct roots_output {
struct roots_desktop *desktop;
struct wlr_output *wlr_output;
struct wl_list link; // roots_desktop:outputs
struct roots_view *fullscreen_view;
struct timespec last_frame;
pixman_region32_t damage; // in ouput-local coordinates
// circular queue for previous damage
pixman_region32_t previous_damage[ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN];
size_t previous_damage_idx;
struct wl_listener frame;
struct wl_listener mode;
struct wl_listener needs_swap;
};
void output_add_notify(struct wl_listener *listener, void *data);
void output_remove_notify(struct wl_listener *listener, void *data);
struct roots_view;
struct roots_drag_icon;
void output_damage_whole(struct roots_output *output);
void output_damage_whole_view(struct roots_output *output,
struct roots_view *view);
void output_damage_from_view(struct roots_output *output,
struct roots_view *view);
void output_damage_whole_drag_icon(struct roots_output *output,
struct roots_drag_icon *icon);
#endif

@ -17,12 +17,15 @@ struct roots_seat {
struct wl_list views; // roots_seat_view::link struct wl_list views; // roots_seat_view::link
bool has_focus; bool has_focus;
struct wl_list drag_icons; // roots_drag_icon::link
struct wl_list keyboards; struct wl_list keyboards;
struct wl_list pointers; struct wl_list pointers;
struct wl_list touch; struct wl_list touch;
struct wl_list tablet_tools; struct wl_list tablet_tools;
struct wl_listener seat_destroy; struct wl_listener new_drag_icon;
struct wl_listener destroy;
}; };
struct roots_seat_view { struct roots_seat_view {
@ -38,6 +41,18 @@ struct roots_seat_view {
struct wl_listener view_destroy; struct wl_listener view_destroy;
}; };
struct roots_drag_icon {
struct roots_seat *seat;
struct wlr_drag_icon *wlr_drag_icon;
struct wl_list link;
double x, y;
struct wl_listener surface_commit;
struct wl_listener map;
struct wl_listener destroy;
};
struct roots_pointer { struct roots_pointer {
struct roots_seat *seat; struct roots_seat *seat;
struct wlr_input_device *device; struct wlr_input_device *device;
@ -92,6 +107,10 @@ void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view);
void roots_seat_end_compositor_grab(struct roots_seat *seat); void roots_seat_end_compositor_grab(struct roots_seat *seat);
struct roots_seat_view *roots_seat_view_from_view( struct roots_seat *seat, struct roots_seat_view *roots_seat_view_from_view( struct roots_seat *seat,
struct roots_view *view); struct roots_view *view);
void roots_drag_icon_update_position(struct roots_drag_icon *icon);
void roots_drag_icon_damage_whole(struct roots_drag_icon *icon);
#endif #endif

@ -11,6 +11,7 @@ struct roots_wl_shell_surface {
struct roots_view *view; struct roots_view *view;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener new_popup;
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wl_listener request_maximize; struct wl_listener request_maximize;
@ -23,13 +24,15 @@ struct roots_wl_shell_surface {
struct roots_xdg_surface_v6 { struct roots_xdg_surface_v6 {
struct roots_view *view; struct roots_view *view;
struct wl_listener commit;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener new_popup;
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wl_listener request_maximize; struct wl_listener request_maximize;
struct wl_listener request_fullscreen; struct wl_listener request_fullscreen;
struct wl_listener surface_commit;
uint32_t pending_move_resize_configure_serial; uint32_t pending_move_resize_configure_serial;
}; };
@ -61,6 +64,7 @@ struct roots_view {
struct wl_list link; // roots_desktop::views struct wl_list link; // roots_desktop::views
double x, y; double x, y;
uint32_t width, height;
float rotation; float rotation;
bool decorated; bool decorated;
@ -97,17 +101,17 @@ struct roots_view {
struct roots_xwayland_surface *roots_xwayland_surface; struct roots_xwayland_surface *roots_xwayland_surface;
#endif #endif
}; };
struct wlr_surface *wlr_surface; struct wlr_surface *wlr_surface;
struct wl_list children; // roots_view_child::link
struct wl_listener new_subsurface;
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;
// TODO: This would probably be better as a field that's updated on a // TODO: this should follow the typical type/impl pattern we use elsewhere
// configure event from the xdg_shell
// If not then this should follow the typical type/impl pattern we use
// elsewhere
void (*get_size)(const struct roots_view *view, struct wlr_box *box);
void (*activate)(struct roots_view *view, bool active); void (*activate)(struct roots_view *view, bool active);
void (*move)(struct roots_view *view, double x, double y); void (*move)(struct roots_view *view, double x, double y);
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height); void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
@ -118,6 +122,38 @@ struct roots_view {
void (*close)(struct roots_view *view); void (*close)(struct roots_view *view);
}; };
struct roots_view_child {
struct roots_view *view;
struct wlr_surface *wlr_surface;
struct wl_list link;
struct wl_listener commit;
struct wl_listener new_subsurface;
void (*destroy)(struct roots_view_child *child);
};
struct roots_subsurface {
struct roots_view_child view_child;
struct wlr_subsurface *wlr_subsurface;
struct wl_listener destroy;
};
struct roots_wl_shell_popup {
struct roots_view_child view_child;
struct wlr_wl_shell_surface *wlr_wl_shell_surface;
struct wl_listener destroy;
struct wl_listener set_state;
struct wl_listener new_popup;
};
struct roots_xdg_popup_v6 {
struct roots_view_child view_child;
struct wlr_xdg_popup_v6 *wlr_popup;
struct wl_listener destroy;
struct wl_listener new_popup;
};
void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_get_box(const struct roots_view *view, struct wlr_box *box);
void view_activate(struct roots_view *view, bool active); void view_activate(struct roots_view *view, bool active);
void view_move(struct roots_view *view, double x, double y); void view_move(struct roots_view *view, double x, double y);
@ -127,6 +163,7 @@ void view_move_resize(struct roots_view *view, double x, double y,
void view_maximize(struct roots_view *view, bool maximized); void view_maximize(struct roots_view *view, bool maximized);
void view_set_fullscreen(struct roots_view *view, bool fullscreen, void view_set_fullscreen(struct roots_view *view, bool fullscreen,
struct wlr_output *output); struct wlr_output *output);
void view_rotate(struct roots_view *view, float rotation);
void view_close(struct roots_view *view); void view_close(struct roots_view *view);
bool view_center(struct roots_view *view); bool view_center(struct roots_view *view);
void view_setup(struct roots_view *view); void view_setup(struct roots_view *view);
@ -145,4 +182,11 @@ enum roots_deco_part {
enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy); enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy);
void view_child_init(struct roots_view_child *child, struct roots_view *view,
struct wlr_surface *wlr_surface);
void view_child_finish(struct roots_view_child *child);
struct roots_subsurface *subsurface_create(struct roots_view *view,
struct wlr_subsurface *wlr_subsurface);
#endif #endif

@ -18,8 +18,8 @@ struct wlr_output_impl {
int32_t hotspot_x, int32_t hotspot_y, bool update_pixels); int32_t hotspot_x, int32_t hotspot_y, bool update_pixels);
bool (*move_cursor)(struct wlr_output *output, int x, int y); bool (*move_cursor)(struct wlr_output *output, int x, int y);
void (*destroy)(struct wlr_output *output); void (*destroy)(struct wlr_output *output);
void (*make_current)(struct wlr_output *output); bool (*make_current)(struct wlr_output *output, int *buffer_age);
void (*swap_buffers)(struct wlr_output *output); bool (*swap_buffers)(struct wlr_output *output);
void (*set_gamma)(struct wlr_output *output, void (*set_gamma)(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
uint32_t (*get_gamma_size)(struct wlr_output *output); uint32_t (*get_gamma_size)(struct wlr_output *output);
@ -32,5 +32,7 @@ void wlr_output_update_mode(struct wlr_output *output,
void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width, void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width,
int32_t height, int32_t refresh); int32_t height, int32_t refresh);
void wlr_output_update_enabled(struct wlr_output *output, bool enabled); void wlr_output_update_enabled(struct wlr_output *output, bool enabled);
void wlr_output_update_needs_swap(struct wlr_output *output);
void wlr_output_send_frame(struct wlr_output *output);
#endif #endif

@ -5,6 +5,7 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <wayland-server-protocol.h> #include <wayland-server-protocol.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
struct wlr_texture; struct wlr_texture;
@ -12,6 +13,13 @@ struct wlr_renderer;
void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output);
void wlr_renderer_end(struct wlr_renderer *r); void wlr_renderer_end(struct wlr_renderer *r);
void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]);
/**
* Defines a scissor box. Only pixels that lie within the scissor box can be
* modified by drawing functions. Providing a NULL `box` disables the scissor
* box.
*/
void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box);
/** /**
* Requests a texture handle from this renderer. * Requests a texture handle from this renderer.
*/ */

@ -11,8 +11,12 @@ struct wlr_egl {
EGLConfig config; EGLConfig config;
EGLContext context; EGLContext context;
const char *egl_exts; const char *egl_exts_str;
const char *gl_exts; const char *gl_exts_str;
struct {
bool buffer_age;
} egl_exts;
struct wl_display *wl_display; struct wl_display *wl_display;
}; };
@ -65,4 +69,7 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image);
*/ */
const char *egl_error(void); const char *egl_error(void);
bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface,
int *buffer_age);
#endif #endif

@ -6,6 +6,7 @@
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <stdbool.h> #include <stdbool.h>
#include <wlr/render.h> #include <wlr/render.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
struct wlr_renderer_impl; struct wlr_renderer_impl;
@ -17,6 +18,8 @@ struct wlr_renderer {
struct wlr_renderer_impl { struct wlr_renderer_impl {
void (*begin)(struct wlr_renderer *renderer, struct wlr_output *output); void (*begin)(struct wlr_renderer *renderer, struct wlr_output *output);
void (*end)(struct wlr_renderer *renderer); void (*end)(struct wlr_renderer *renderer);
void (*clear)(struct wlr_renderer *renderer, const float (*color)[4]);
void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box);
struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer);
bool (*render_with_matrix)(struct wlr_renderer *renderer, bool (*render_with_matrix)(struct wlr_renderer *renderer,
struct wlr_texture *texture, const float (*matrix)[16]); struct wlr_texture *texture, const float (*matrix)[16]);

@ -2,6 +2,7 @@
#define WLR_TYPES_WLR_BOX_H #define WLR_TYPES_WLR_BOX_H
#include <stdbool.h> #include <stdbool.h>
#include <wayland-server.h>
struct wlr_box { struct wlr_box {
int x, y; int x, y;
@ -18,8 +19,17 @@ bool wlr_box_contains_point(const struct wlr_box *box, double x, double y);
bool wlr_box_empty(const struct wlr_box *box); bool wlr_box_empty(const struct wlr_box *box);
enum wl_output_transform; /**
* Transforms a box inside a `width` x `height` box.
*/
void wlr_box_transform(const struct wlr_box *box, void wlr_box_transform(const struct wlr_box *box,
enum wl_output_transform transform, struct wlr_box *dest); enum wl_output_transform transform, int width, int height,
struct wlr_box *dest);
/**
* Creates the smallest box that contains a rotated box.
*/
void wlr_box_rotated_bounds(const struct wlr_box *box, float rotation,
struct wlr_box *dest);
#endif #endif

@ -13,7 +13,7 @@ struct wlr_compositor {
struct wl_listener display_destroy; struct wl_listener display_destroy;
struct { struct {
struct wl_signal create_surface; struct wl_signal new_surface;
} events; } events;
}; };

@ -71,10 +71,10 @@ struct wlr_drag_icon {
bool is_pointer; bool is_pointer;
int32_t touch_id; int32_t touch_id;
int32_t sx; int32_t sx, sy;
int32_t sy;
struct { struct {
struct wl_signal map; // emitted when mapped or unmapped
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;

@ -2,6 +2,8 @@
#define WLR_TYPES_WLR_OUTPUT_H #define WLR_TYPES_WLR_OUTPUT_H
#include <stdbool.h> #include <stdbool.h>
#include <time.h>
#include <pixman.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <wayland-server.h> #include <wayland-server.h>
@ -22,7 +24,6 @@ struct wlr_output_cursor {
struct wl_list link; struct wl_list link;
// only when using a software cursor without a surface // only when using a software cursor without a surface
struct wlr_renderer *renderer;
struct wlr_texture *texture; struct wlr_texture *texture;
// only when using a cursor surface // only when using a cursor surface
@ -51,22 +52,26 @@ struct wlr_output {
char serial[16]; char serial[16];
int32_t phys_width, phys_height; // mm int32_t phys_width, phys_height; // mm
// Note: some backends may have zero modes
struct wl_list modes;
struct wlr_output_mode *current_mode;
int32_t width, height;
int32_t refresh; // mHz, may be zero
bool enabled; bool enabled;
float scale; float scale;
enum wl_output_subpixel subpixel; enum wl_output_subpixel subpixel;
enum wl_output_transform transform; enum wl_output_transform transform;
bool needs_swap;
bool needs_swap;
// damage for cursors and fullscreen surface, in output-local coordinates
pixman_region32_t damage;
bool frame_pending;
float transform_matrix[16]; float transform_matrix[16];
// Note: some backends may have zero modes
struct wl_list modes;
struct wlr_output_mode *current_mode;
int32_t width, height;
int32_t refresh; // mHz
struct { struct {
struct wl_signal frame; struct wl_signal frame;
struct wl_signal needs_swap;
struct wl_signal swap_buffers; struct wl_signal swap_buffers;
struct wl_signal enable; struct wl_signal enable;
struct wl_signal mode; struct wl_signal mode;
@ -75,9 +80,12 @@ struct wlr_output {
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;
struct wl_event_source *idle_frame;
struct wlr_surface *fullscreen_surface; struct wlr_surface *fullscreen_surface;
struct wl_listener fullscreen_surface_commit; struct wl_listener fullscreen_surface_commit;
struct wl_listener fullscreen_surface_destroy; struct wl_listener fullscreen_surface_destroy;
int fullscreen_width, fullscreen_height;
struct wl_list cursors; // wlr_output_cursor::link struct wl_list cursors; // wlr_output_cursor::link
struct wlr_output_cursor *hardware_cursor; struct wlr_output_cursor *hardware_cursor;
@ -104,16 +112,44 @@ void wlr_output_set_transform(struct wlr_output *output,
void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly); void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly);
void wlr_output_set_scale(struct wlr_output *output, float scale); void wlr_output_set_scale(struct wlr_output *output, float scale);
void wlr_output_destroy(struct wlr_output *output); void wlr_output_destroy(struct wlr_output *output);
/**
* Computes the transformed output resolution.
*/
void wlr_output_transformed_resolution(struct wlr_output *output,
int *width, int *height);
/**
* Computes the transformed and scaled output resolution.
*/
void wlr_output_effective_resolution(struct wlr_output *output, void wlr_output_effective_resolution(struct wlr_output *output,
int *width, int *height); int *width, int *height);
void wlr_output_make_current(struct wlr_output *output); /**
void wlr_output_swap_buffers(struct wlr_output *output); * Makes the output rendering context current.
*
* `buffer_age` is set to the drawing buffer age in number of frames or -1 if
* unknown. This is useful for damage tracking.
*/
bool wlr_output_make_current(struct wlr_output *output, int *buffer_age);
/**
* Swaps the output buffers. If the time of the frame isn't known, set `when` to
* NULL. If the compositor doesn't support damage tracking, set `damage` to
* NULL.
*
* Swapping buffers schedules a `frame` event.
*/
bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when,
pixman_region32_t *damage);
/**
* Manually schedules a `frame` event. If a `frame` event is already pending,
* it is a no-op.
*/
void wlr_output_schedule_frame(struct wlr_output *output);
void wlr_output_set_gamma(struct wlr_output *output, void wlr_output_set_gamma(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
uint32_t wlr_output_get_gamma_size(struct wlr_output *output); uint32_t wlr_output_get_gamma_size(struct wlr_output *output);
void wlr_output_set_fullscreen_surface(struct wlr_output *output, void wlr_output_set_fullscreen_surface(struct wlr_output *output,
struct wlr_surface *surface); struct wlr_surface *surface);
struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output); struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output);
/** /**
* Sets the cursor image. The image must be already scaled for the output. * Sets the cursor image. The image must be already scaled for the output.

@ -209,6 +209,8 @@ struct wlr_seat {
struct wl_signal selection; struct wl_signal selection;
struct wl_signal primary_selection; struct wl_signal primary_selection;
struct wl_signal new_drag_icon;
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;

@ -56,6 +56,10 @@ struct wlr_subsurface {
struct wl_list parent_pending_link; struct wl_list parent_pending_link;
struct wl_listener parent_destroy_listener; struct wl_listener parent_destroy_listener;
struct {
struct wl_signal destroy;
} events;
}; };
struct wlr_surface { struct wlr_surface {
@ -70,6 +74,7 @@ struct wlr_surface {
struct { struct {
struct wl_signal commit; struct wl_signal commit;
struct wl_signal new_subsurface;
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;

@ -79,6 +79,7 @@ struct wlr_wl_shell_surface {
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
struct wl_signal ping_timeout; struct wl_signal ping_timeout;
struct wl_signal new_popup;
struct wl_signal request_move; struct wl_signal request_move;
struct wl_signal request_resize; struct wl_signal request_resize;

@ -34,6 +34,7 @@ struct wlr_xdg_client_v6 {
struct wlr_xdg_popup_v6 { struct wlr_xdg_popup_v6 {
struct wlr_xdg_surface_v6 *base; struct wlr_xdg_surface_v6 *base;
struct wl_list link;
struct wl_resource *resource; struct wl_resource *resource;
bool committed; bool committed;
@ -104,8 +105,7 @@ struct wlr_xdg_surface_v6 {
struct wlr_xdg_popup_v6 *popup_state; struct wlr_xdg_popup_v6 *popup_state;
}; };
struct wl_list popups; struct wl_list popups; // wlr_xdg_popup_v6::link
struct wl_list popup_link;
bool configured; bool configured;
bool added; bool added;
@ -126,6 +126,7 @@ struct wlr_xdg_surface_v6 {
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
struct wl_signal ping_timeout; struct wl_signal ping_timeout;
struct wl_signal new_popup;
struct wl_signal request_maximize; struct wl_signal request_maximize;
struct wl_signal request_fullscreen; struct wl_signal request_fullscreen;

@ -0,0 +1,29 @@
#ifndef WLR_UTIL_REGION_H
#define WLR_UTIL_REGION_H
#include <pixman.h>
#include <wayland-server.h>
/**
* Scales a region, ie. multiplies all its coordinates by `scale`.
*
* The resulting coordinates are rounded up or down so that the new region is
* at least as big as the original one.
*/
void wlr_region_scale(pixman_region32_t *dst, pixman_region32_t *src,
float scale);
/**
* Applies a transform to a region inside a box of size `width` x `height`.
*/
void wlr_region_transform(pixman_region32_t *dst, pixman_region32_t *src,
enum wl_output_transform transform, int width, int height);
/**
* Expands the region of `distance`. If `distance` is negative, it shrinks the
* region.
*/
void wlr_region_expand(pixman_region32_t *dst, pixman_region32_t *src,
int distance);
#endif

@ -127,18 +127,23 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
} }
eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl->context); eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl->context);
egl->egl_exts = eglQueryString(egl->display, EGL_EXTENSIONS); egl->egl_exts_str = eglQueryString(egl->display, EGL_EXTENSIONS);
if (strstr(egl->egl_exts, "EGL_WL_bind_wayland_display") == NULL || egl->gl_exts_str = (const char*) glGetString(GL_EXTENSIONS);
strstr(egl->egl_exts, "EGL_KHR_image_base") == NULL) {
wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor);
wlr_log(L_INFO, "Supported EGL extensions: %s", egl->egl_exts_str);
wlr_log(L_INFO, "Using %s", glGetString(GL_VERSION));
wlr_log(L_INFO, "Supported OpenGL ES extensions: %s", egl->gl_exts_str);
if (strstr(egl->egl_exts_str, "EGL_WL_bind_wayland_display") == NULL ||
strstr(egl->egl_exts_str, "EGL_KHR_image_base") == NULL) {
wlr_log(L_ERROR, "Required egl extensions not supported"); wlr_log(L_ERROR, "Required egl extensions not supported");
goto error; goto error;
} }
egl->gl_exts = (const char*) glGetString(GL_EXTENSIONS); egl->egl_exts.buffer_age =
wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor); strstr(egl->egl_exts_str, "EGL_EXT_buffer_age") != NULL;
wlr_log(L_INFO, "Supported EGL extensions: %s", egl->egl_exts);
wlr_log(L_INFO, "Using %s", glGetString(GL_VERSION));
wlr_log(L_INFO, "Supported OpenGL ES extensions: %s", egl->gl_exts);
return true; return true;
error: error:
@ -208,3 +213,32 @@ EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window) {
} }
return surf; return surf;
} }
int wlr_egl_get_buffer_age(struct wlr_egl *egl, EGLSurface surface) {
if (!egl->egl_exts.buffer_age) {
return -1;
}
EGLint buffer_age;
EGLBoolean ok = eglQuerySurface(egl->display, surface,
EGL_BUFFER_AGE_EXT, &buffer_age);
if (!ok) {
wlr_log(L_ERROR, "Failed to get EGL surface buffer age: %s", egl_error());
return -1;
}
return buffer_age;
}
bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface,
int *buffer_age) {
if (!eglMakeCurrent(egl->display, surface, surface, egl->context)) {
wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error());
return false;
}
if (buffer_age != NULL) {
*buffer_age = wlr_egl_get_buffer_age(egl, surface);
}
return true;
}

@ -105,14 +105,9 @@ static void init_globals() {
init_default_shaders(); init_default_shaders();
} }
static void wlr_gles2_begin(struct wlr_renderer *_renderer, static void wlr_gles2_begin(struct wlr_renderer *wlr_renderer,
struct wlr_output *output) { struct wlr_output *output) {
// TODO: let users customize the clear color? GL_CALL(glViewport(0, 0, output->width, output->height));
GL_CALL(glClearColor(0.25f, 0.25f, 0.25f, 1));
GL_CALL(glClear(GL_COLOR_BUFFER_BIT));
int32_t width = output->width;
int32_t height = output->height;
GL_CALL(glViewport(0, 0, width, height));
// enable transparency // enable transparency
GL_CALL(glEnable(GL_BLEND)); GL_CALL(glEnable(GL_BLEND));
@ -122,14 +117,30 @@ static void wlr_gles2_begin(struct wlr_renderer *_renderer,
// for users to sling matricies themselves // for users to sling matricies themselves
} }
static void wlr_gles2_end(struct wlr_renderer *renderer) { static void wlr_gles2_end(struct wlr_renderer *wlr_renderer) {
// no-op // no-op
} }
static void wlr_gles2_clear(struct wlr_renderer *wlr_renderer,
const float (*color)[4]) {
glClearColor((*color)[0], (*color)[1], (*color)[2], (*color)[3]);
glClear(GL_COLOR_BUFFER_BIT);
}
static void wlr_gles2_scissor(struct wlr_renderer *wlr_renderer,
struct wlr_box *box) {
if (box != NULL) {
glScissor(box->x, box->y, box->width, box->height);
glEnable(GL_SCISSOR_TEST);
} else {
glDisable(GL_SCISSOR_TEST);
}
}
static struct wlr_texture *wlr_gles2_texture_create( static struct wlr_texture *wlr_gles2_texture_create(
struct wlr_renderer *_renderer) { struct wlr_renderer *wlr_renderer) {
struct wlr_gles2_renderer *renderer = struct wlr_gles2_renderer *renderer =
(struct wlr_gles2_renderer *)_renderer; (struct wlr_gles2_renderer *)wlr_renderer;
return gles2_texture_create(renderer->egl); return gles2_texture_create(renderer->egl);
} }
@ -159,7 +170,7 @@ static void draw_quad() {
GL_CALL(glDisableVertexAttribArray(1)); GL_CALL(glDisableVertexAttribArray(1));
} }
static bool wlr_gles2_render_texture(struct wlr_renderer *_renderer, static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer,
struct wlr_texture *texture, const float (*matrix)[16]) { struct wlr_texture *texture, const float (*matrix)[16]) {
if (!texture || !texture->valid) { if (!texture || !texture->valid) {
wlr_log(L_ERROR, "attempt to render invalid texture"); wlr_log(L_ERROR, "attempt to render invalid texture");
@ -174,7 +185,7 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *_renderer,
return true; return true;
} }
static void wlr_gles2_render_quad(struct wlr_renderer *renderer, static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer,
const float (*color)[4], const float (*matrix)[16]) { const float (*color)[4], const float (*matrix)[16]) {
GL_CALL(glUseProgram(shaders.quad)); GL_CALL(glUseProgram(shaders.quad));
GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix)); GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix));
@ -182,7 +193,7 @@ static void wlr_gles2_render_quad(struct wlr_renderer *renderer,
draw_quad(); draw_quad();
} }
static void wlr_gles2_render_ellipse(struct wlr_renderer *renderer, static void wlr_gles2_render_ellipse(struct wlr_renderer *wlr_renderer,
const float (*color)[4], const float (*matrix)[16]) { const float (*color)[4], const float (*matrix)[16]) {
GL_CALL(glUseProgram(shaders.ellipse)); GL_CALL(glUseProgram(shaders.ellipse));
GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, *matrix)); GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, *matrix));
@ -202,10 +213,10 @@ static const enum wl_shm_format *wlr_gles2_formats(
return formats; return formats;
} }
static bool wlr_gles2_buffer_is_drm(struct wlr_renderer *_renderer, static bool wlr_gles2_buffer_is_drm(struct wlr_renderer *wlr_renderer,
struct wl_resource *buffer) { struct wl_resource *buffer) {
struct wlr_gles2_renderer *renderer = struct wlr_gles2_renderer *renderer =
(struct wlr_gles2_renderer *)_renderer; (struct wlr_gles2_renderer *)wlr_renderer;
EGLint format; EGLint format;
return wlr_egl_query_buffer(renderer->egl, buffer, return wlr_egl_query_buffer(renderer->egl, buffer,
EGL_TEXTURE_FORMAT, &format); EGL_TEXTURE_FORMAT, &format);
@ -243,6 +254,8 @@ static bool wlr_gles2_format_supported(struct wlr_renderer *r,
static struct wlr_renderer_impl wlr_renderer_impl = { static struct wlr_renderer_impl wlr_renderer_impl = {
.begin = wlr_gles2_begin, .begin = wlr_gles2_begin,
.end = wlr_gles2_end, .end = wlr_gles2_end,
.clear = wlr_gles2_clear,
.scissor = wlr_gles2_scissor,
.texture_create = wlr_gles2_texture_create, .texture_create = wlr_gles2_texture_create,
.render_with_matrix = wlr_gles2_render_texture, .render_with_matrix = wlr_gles2_render_texture,
.render_quad = wlr_gles2_render_quad, .render_quad = wlr_gles2_render_quad,

@ -169,22 +169,26 @@ void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box,
int width = box->width; int width = box->width;
int height = box->height; int height = box->height;
float translate_center[16]; wlr_matrix_translate(mat, x, y, 0);
wlr_matrix_translate(&translate_center,
(int)x + width / 2, (int)y + height / 2, 0);
float rotate[16]; if (rotation != 0) {
wlr_matrix_rotate(&rotate, rotation); float translate_center[16];
wlr_matrix_translate(&translate_center, width/2, height/2, 0);
float translate_origin[16]; float rotate[16];
wlr_matrix_translate(&translate_origin, -width / 2, wlr_matrix_rotate(&rotate, rotation);
-height / 2, 0);
float translate_origin[16];
wlr_matrix_translate(&translate_origin, -width/2, -height/2, 0);
wlr_matrix_mul(mat, &translate_center, mat);
wlr_matrix_mul(mat, &rotate, mat);
wlr_matrix_mul(mat, &translate_origin, mat);
}
float scale[16]; float scale[16];
wlr_matrix_scale(&scale, width, height, 1); wlr_matrix_scale(&scale, width, height, 1);
wlr_matrix_mul(&translate_center, &rotate, mat);
wlr_matrix_mul(mat, &translate_origin, mat);
wlr_matrix_mul(mat, &scale, mat); wlr_matrix_mul(mat, &scale, mat);
if (transform != WL_OUTPUT_TRANSFORM_NORMAL) { if (transform != WL_OUTPUT_TRANSFORM_NORMAL) {
@ -192,17 +196,14 @@ void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box,
wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0);
float surface_transform[16]; float surface_transform[16];
wlr_matrix_transform(surface_transform, wlr_matrix_transform(surface_transform, transform);
wlr_output_transform_invert(transform));
float surface_translate_origin[16]; float surface_translate_origin[16];
wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0);
wlr_matrix_mul(mat, &surface_translate_center, wlr_matrix_mul(mat, &surface_translate_center, mat);
mat);
wlr_matrix_mul(mat, &surface_transform, mat); wlr_matrix_mul(mat, &surface_transform, mat);
wlr_matrix_mul(mat, &surface_translate_origin, wlr_matrix_mul(mat, &surface_translate_origin, mat);
mat);
} }
wlr_matrix_mul(projection, mat, mat); wlr_matrix_mul(projection, mat, mat);

@ -22,7 +22,7 @@ lib_wlr_render = static_library(
glapi[0], glapi[0],
glapi[1], glapi[1],
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [glesv2, egl], dependencies: [glesv2, egl, pixman],
) )
wlr_render = declare_dependency( wlr_render = declare_dependency(

@ -23,6 +23,14 @@ void wlr_renderer_end(struct wlr_renderer *r) {
r->impl->end(r); r->impl->end(r);
} }
void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]) {
r->impl->clear(r, color);
}
void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box) {
r->impl->scissor(r, box);
}
struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) {
return r->impl->texture_create(r); return r->impl->texture_create(r);
} }

@ -138,6 +138,11 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
} else { } else {
wlr_seat_pointer_clear_focus(seat->seat); wlr_seat_pointer_clear_focus(seat->seat);
} }
struct roots_drag_icon *drag_icon;
wl_list_for_each(drag_icon, &seat->drag_icons, link) {
roots_drag_icon_update_position(drag_icon);
}
break; break;
case ROOTS_CURSOR_MOVE: case ROOTS_CURSOR_MOVE:
view = roots_seat_get_focus(seat); view = roots_seat_get_focus(seat);
@ -198,7 +203,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy); float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy);
int steps = 12; int steps = 12;
angle = round(angle/M_PI*steps) / (steps/M_PI); angle = round(angle/M_PI*steps) / (steps/M_PI);
view->rotation = cursor->view_rotation + angle; view_rotate(view, cursor->view_rotation + angle);
} }
break; break;
} }

@ -24,12 +24,8 @@
void view_get_box(const struct roots_view *view, struct wlr_box *box) { void view_get_box(const struct roots_view *view, struct wlr_box *box) {
box->x = view->x; box->x = view->x;
box->y = view->y; box->y = view->y;
if (view->get_size) { box->width = view->width;
view->get_size(view, box); box->height = view->height;
} else {
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
}
} }
void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) { void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) {
@ -111,8 +107,7 @@ void view_move(struct roots_view *view, double x, double y) {
if (view->move) { if (view->move) {
view->move(view, x, y); view->move(view, x, y);
} else { } else {
view->x = x; view_update_position(view, x, y);
view->y = y;
} }
view_update_output(view, &before); view_update_output(view, &before);
} }
@ -195,7 +190,7 @@ void view_maximize(struct roots_view *view, bool maximized) {
view_move_resize(view, output_box->x, output_box->y, output_box->width, view_move_resize(view, output_box->x, output_box->y, output_box->width,
output_box->height); output_box->height);
view->rotation = 0; view_rotate(view, 0);
} }
if (view->maximized && !maximized) { if (view->maximized && !maximized) {
@ -203,7 +198,7 @@ void view_maximize(struct roots_view *view, bool maximized) {
view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, view_move_resize(view, view->saved.x, view->saved.y, view->saved.width,
view->saved.height); view->saved.height);
view->rotation = view->saved.rotation; view_rotate(view, view->saved.rotation);
} }
} }
@ -244,22 +239,34 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen,
wlr_output_layout_get_box(view->desktop->layout, output); wlr_output_layout_get_box(view->desktop->layout, output);
view_move_resize(view, output_box->x, output_box->y, output_box->width, view_move_resize(view, output_box->x, output_box->y, output_box->width,
output_box->height); output_box->height);
view->rotation = 0; view_rotate(view, 0);
roots_output->fullscreen_view = view; roots_output->fullscreen_view = view;
view->fullscreen_output = roots_output; view->fullscreen_output = roots_output;
output_damage_whole(roots_output);
} }
if (was_fullscreen && !fullscreen) { if (was_fullscreen && !fullscreen) {
view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, view_move_resize(view, view->saved.x, view->saved.y, view->saved.width,
view->saved.height); view->saved.height);
view->rotation = view->saved.rotation; view_rotate(view, view->saved.rotation);
output_damage_whole(view->fullscreen_output);
view->fullscreen_output->fullscreen_view = NULL; view->fullscreen_output->fullscreen_view = NULL;
view->fullscreen_output = NULL; view->fullscreen_output = NULL;
} }
} }
void view_rotate(struct roots_view *view, float rotation) {
if (view->rotation == rotation) {
return;
}
view_damage_whole(view);
view->rotation = rotation;
view_damage_whole(view);
}
void view_close(struct roots_view *view) { void view_close(struct roots_view *view) {
if (view->close) { if (view->close) {
view->close(view); view->close(view);
@ -305,19 +312,116 @@ bool view_center(struct roots_view *view) {
return true; return true;
} }
void view_destroy(struct roots_view *view) { void view_child_finish(struct roots_view_child *child) {
if (child == NULL) {
return;
}
view_damage_whole(child->view);
wl_list_remove(&child->link);
wl_list_remove(&child->commit.link);
wl_list_remove(&child->new_subsurface.link);
}
static void view_child_handle_commit(struct wl_listener *listener,
void *data) {
struct roots_view_child *child = wl_container_of(listener, child, commit);
view_apply_damage(child->view);
}
static void view_child_handle_new_subsurface(struct wl_listener *listener,
void *data) {
struct roots_view_child *child =
wl_container_of(listener, child, new_subsurface);
struct wlr_subsurface *wlr_subsurface = data;
subsurface_create(child->view, wlr_subsurface);
}
void view_child_init(struct roots_view_child *child, struct roots_view *view,
struct wlr_surface *wlr_surface) {
assert(child->destroy);
child->view = view;
child->wlr_surface = wlr_surface;
child->commit.notify = view_child_handle_commit;
wl_signal_add(&wlr_surface->events.commit, &child->commit);
child->new_subsurface.notify = view_child_handle_new_subsurface;
wl_signal_add(&wlr_surface->events.new_subsurface, &child->new_subsurface);
wl_list_insert(&view->children, &child->link);
}
static void subsurface_destroy(struct roots_view_child *child) {
assert(child->destroy == subsurface_destroy);
struct roots_subsurface *subsurface = (struct roots_subsurface *)child;
if (subsurface == NULL) {
return;
}
wl_list_remove(&subsurface->destroy.link);
view_child_finish(&subsurface->view_child);
free(subsurface);
}
static void subsurface_handle_destroy(struct wl_listener *listener,
void *data) {
struct roots_subsurface *subsurface =
wl_container_of(listener, subsurface, destroy);
subsurface_destroy((struct roots_view_child *)subsurface);
}
struct roots_subsurface *subsurface_create(struct roots_view *view,
struct wlr_subsurface *wlr_subsurface) {
struct roots_subsurface *subsurface =
calloc(1, sizeof(struct roots_subsurface));
if (subsurface == NULL) {
return NULL;
}
subsurface->wlr_subsurface = wlr_subsurface;
subsurface->view_child.destroy = subsurface_destroy;
view_child_init(&subsurface->view_child, view, wlr_subsurface->surface);
subsurface->destroy.notify = subsurface_handle_destroy;
wl_signal_add(&wlr_subsurface->events.destroy, &subsurface->destroy);
return subsurface;
}
void view_finish(struct roots_view *view) {
view_damage_whole(view);
wl_signal_emit(&view->events.destroy, view); wl_signal_emit(&view->events.destroy, view);
wl_list_remove(&view->new_subsurface.link);
struct roots_view_child *child, *tmp;
wl_list_for_each_safe(child, tmp, &view->children, link) {
child->destroy(child);
}
if (view->fullscreen_output) { if (view->fullscreen_output) {
view->fullscreen_output->fullscreen_view = NULL; view->fullscreen_output->fullscreen_view = NULL;
} }
}
free(view); static void view_handle_new_subsurface(struct wl_listener *listener,
void *data) {
struct roots_view *view = wl_container_of(listener, view, new_subsurface);
struct wlr_subsurface *wlr_subsurface = data;
subsurface_create(view, wlr_subsurface);
} }
void view_init(struct roots_view *view, struct roots_desktop *desktop) { void view_init(struct roots_view *view, struct roots_desktop *desktop) {
assert(view->wlr_surface);
view->desktop = desktop; view->desktop = desktop;
wl_signal_init(&view->events.destroy); wl_signal_init(&view->events.destroy);
wl_list_init(&view->children);
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list,
parent_link) {
subsurface_create(view, subsurface);
}
view->new_subsurface.notify = view_handle_new_subsurface;
wl_signal_add(&view->wlr_surface->events.new_subsurface,
&view->new_subsurface);
view_damage_whole(view);
} }
void view_setup(struct roots_view *view) { void view_setup(struct roots_view *view) {
@ -332,6 +436,42 @@ void view_setup(struct roots_view *view) {
view_update_output(view, NULL); view_update_output(view, NULL);
} }
void view_apply_damage(struct roots_view *view) {
struct roots_output *output;
wl_list_for_each(output, &view->desktop->outputs, link) {
output_damage_from_view(output, view);
}
}
void view_damage_whole(struct roots_view *view) {
struct roots_output *output;
wl_list_for_each(output, &view->desktop->outputs, link) {
output_damage_whole_view(output, view);
}
}
void view_update_position(struct roots_view *view, double x, double y) {
if (view->x == x && view->y == y) {
return;
}
view_damage_whole(view);
view->x = x;
view->y = y;
view_damage_whole(view);
}
void view_update_size(struct roots_view *view, uint32_t width, uint32_t height) {
if (view->width == width && view->height == height) {
return;
}
view_damage_whole(view);
view->width = width;
view->height = height;
view_damage_whole(view);
}
static bool view_at(struct roots_view *view, double lx, double ly, static bool view_at(struct roots_view *view, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) { struct wlr_surface **surface, double *sx, double *sy) {
if (view->type == ROOTS_WL_SHELL_VIEW && if (view->type == ROOTS_WL_SHELL_VIEW &&
@ -569,11 +709,11 @@ void desktop_destroy(struct roots_desktop *desktop) {
} }
struct roots_output *desktop_output_from_wlr_output( struct roots_output *desktop_output_from_wlr_output(
struct roots_desktop *desktop, struct wlr_output *output) { struct roots_desktop *desktop, struct wlr_output *wlr_output) {
struct roots_output *roots_output; struct roots_output *output;
wl_list_for_each(roots_output, &desktop->outputs, link) { wl_list_for_each(output, &desktop->outputs, link) {
if (roots_output->wlr_output == output) { if (output->wlr_output == wlr_output) {
return roots_output; return output;
} }
} }
return NULL; return NULL;

@ -15,5 +15,5 @@ if get_option('enable_xwayland')
sources += ['xwayland.c'] sources += ['xwayland.c']
endif endif
executable( executable(
'rootston', sources, dependencies: [wlroots, wlr_protos] 'rootston', sources, dependencies: [wlroots, wlr_protos, pixman]
) )

@ -2,17 +2,21 @@
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <GLES2/gl2.h> #include <assert.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/util/region.h>
#include "rootston/server.h" #include "rootston/server.h"
#include "rootston/desktop.h" #include "rootston/output.h"
#include "rootston/config.h" #include "rootston/config.h"
typedef void (*surface_iterator_func_t)(struct wlr_surface *surface,
double lx, double ly, float rotation, void *data);
/** /**
* Rotate a child's position relative to a parent. The parent size is (pw, ph), * Rotate a child's position relative to a parent. The parent size is (pw, ph),
* the child position is (*sx, *sy) and its size is (sw, sh). * the child position is (*sx, *sy) and its size is (sw, sh).
@ -31,66 +35,33 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh,
} }
} }
static void render_surface(struct wlr_surface *surface, static void surface_for_each_surface(struct wlr_surface *surface, double lx,
struct roots_desktop *desktop, struct wlr_output *wlr_output, double ly, float rotation, surface_iterator_func_t iterator,
struct timespec *when, double lx, double ly, float rotation) { void *user_data) {
if (!wlr_surface_has_buffer(surface)) { iterator(surface, lx, ly, rotation, user_data);
return;
}
int width = surface->current->width;
int height = surface->current->height;
int render_width = width * wlr_output->scale;
int render_height = height * wlr_output->scale;
double ox = lx, oy = ly;
wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
ox *= wlr_output->scale;
oy *= wlr_output->scale;
struct wlr_box render_box = {
.x = lx, .y = ly,
.width = render_width, .height = render_height,
};
if (wlr_output_layout_intersects(desktop->layout, wlr_output, &render_box)) {
struct wlr_box project_box = {
.x = ox,
.y = oy,
.width = render_width,
.height = render_height,
};
float matrix[16];
wlr_matrix_project_box(&matrix, &project_box, surface->current->transform,
rotation, &wlr_output->transform_matrix);
wlr_render_with_matrix(desktop->server->renderer, surface->texture,
&matrix);
wlr_surface_send_frame_done(surface, when);
}
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) {
struct wlr_surface_state *state = subsurface->surface->current; struct wlr_surface_state *state = subsurface->surface->current;
double sx = state->subsurface_position.x; double sx = state->subsurface_position.x;
double sy = state->subsurface_position.y; double sy = state->subsurface_position.y;
double sw = state->buffer_width / state->scale; rotate_child_position(&sx, &sy, state->width, state->height,
double sh = state->buffer_height / state->scale; surface->current->width, surface->current->height, rotation);
rotate_child_position(&sx, &sy, sw, sh, width, height, rotation);
render_surface(subsurface->surface, desktop, wlr_output, when, surface_for_each_surface(subsurface->surface, lx + sx, ly + sy,
lx + sx, rotation, iterator, user_data);
ly + sy,
rotation);
} }
} }
static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output, double base_x, double base_y, float rotation,
struct timespec *when, double base_x, double base_y, float rotation) { surface_iterator_func_t iterator, void *user_data) {
double width = surface->surface->current->width; double width = surface->surface->current->width;
double height = surface->surface->current->height; double height = surface->surface->current->height;
struct wlr_xdg_surface_v6 *popup; struct wlr_xdg_popup_v6 *popup_state;
wl_list_for_each(popup, &surface->popups, popup_link) { wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface_v6 *popup = popup_state->base;
if (!popup->configured) { if (!popup->configured) {
continue; continue;
} }
@ -103,20 +74,20 @@ static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface,
rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height, rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height,
width, height, rotation); width, height, rotation);
render_surface(popup->surface, desktop, wlr_output, when, surface_for_each_surface(popup->surface, base_x + popup_sx,
base_x + popup_sx, base_y + popup_sy, rotation); base_y + popup_sy, rotation, iterator, user_data);
render_xdg_v6_popups(popup, desktop, wlr_output, when, xdg_surface_v6_for_each_surface(popup, base_x + popup_sx,
base_x + popup_sx, base_y + popup_sy, rotation); base_y + popup_sy, rotation, iterator, user_data);
} }
} }
static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, static void wl_shell_surface_for_each_surface(
struct roots_desktop *desktop, struct wlr_output *wlr_output, struct wlr_wl_shell_surface *surface, double lx, double ly,
struct timespec *when, double lx, double ly, float rotation, float rotation, bool is_child, surface_iterator_func_t iterator,
bool is_child) { void *user_data) {
if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) { if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) {
render_surface(surface->surface, desktop, wlr_output, when, surface_for_each_surface(surface->surface, lx, ly, rotation, iterator,
lx, ly, rotation); user_data);
double width = surface->surface->current->width; double width = surface->surface->current->width;
double height = surface->surface->current->height; double height = surface->surface->current->height;
@ -131,32 +102,160 @@ static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface,
rotate_child_position(&popup_x, &popup_y, popup_width, popup_height, rotate_child_position(&popup_x, &popup_y, popup_width, popup_height,
width, height, rotation); width, height, rotation);
render_wl_shell_surface(popup, desktop, wlr_output, when, wl_shell_surface_for_each_surface(popup, lx + popup_x, ly + popup_y,
lx + popup_x, ly + popup_y, rotation, true); rotation, true, iterator, user_data);
} }
} }
} }
static void view_for_each_surface(struct roots_view *view,
surface_iterator_func_t iterator, void *user_data) {
switch (view->type) {
case ROOTS_XDG_SHELL_V6_VIEW:
surface_for_each_surface(view->wlr_surface, view->x, view->y,
view->rotation, iterator, user_data);
xdg_surface_v6_for_each_surface(view->xdg_surface_v6, view->x, view->y,
view->rotation, iterator, user_data);
break;
case ROOTS_WL_SHELL_VIEW:
wl_shell_surface_for_each_surface(view->wl_shell_surface, view->x,
view->y, view->rotation, false, iterator, user_data);
break;
#ifdef WLR_HAS_XWAYLAND
case ROOTS_XWAYLAND_VIEW:
if (view->wlr_surface != NULL) {
surface_for_each_surface(view->wlr_surface, view->x, view->y,
view->rotation, iterator, user_data);
}
break;
#endif
}
}
#ifdef WLR_HAS_XWAYLAND #ifdef WLR_HAS_XWAYLAND
static void render_xwayland_children(struct wlr_xwayland_surface *surface, static void xwayland_children_for_each_surface(
struct roots_desktop *desktop, struct wlr_output *wlr_output, struct wlr_xwayland_surface *surface,
struct timespec *when) { surface_iterator_func_t iterator, void *user_data) {
struct wlr_xwayland_surface *child; struct wlr_xwayland_surface *child;
wl_list_for_each(child, &surface->children, parent_link) { wl_list_for_each(child, &surface->children, parent_link) {
if (child->surface != NULL && child->added) { if (child->surface != NULL && child->added) {
render_surface(child->surface, desktop, wlr_output, when, surface_for_each_surface(child->surface, child->x, child->y, 0,
child->x, child->y, 0); iterator, user_data);
} }
render_xwayland_children(child, desktop, wlr_output, when); xwayland_children_for_each_surface(child, iterator, user_data);
} }
} }
#endif #endif
static void render_decorations(struct roots_view *view,
struct roots_desktop *desktop, struct wlr_output *output) { struct render_data {
if (!view->decorated) { struct roots_output *output;
struct timespec *when;
pixman_region32_t *damage;
};
/**
* Checks whether a surface at (lx, ly) intersects an output. Sets `box` to the
* surface box in the output, in output-local coordinates.
*/
static bool surface_intersect_output(struct wlr_surface *surface,
struct wlr_output_layout *output_layout, struct wlr_output *wlr_output,
double lx, double ly, float rotation, struct wlr_box *box) {
double ox = lx, oy = ly;
wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy);
box->x = ox * wlr_output->scale;
box->y = oy * wlr_output->scale;
box->width = surface->current->width * wlr_output->scale;
box->height = surface->current->height * wlr_output->scale;
struct wlr_box layout_box = {
.x = lx, .y = ly,
.width = surface->current->width, .height = surface->current->height,
};
wlr_box_rotated_bounds(&layout_box, -rotation, &layout_box);
return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box);
}
static void scissor_output(struct roots_output *output, pixman_box32_t *rect) {
struct wlr_output *wlr_output = output->wlr_output;
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
assert(renderer);
struct wlr_box box = {
.x = rect->x1,
.y = rect->y1,
.width = rect->x2 - rect->x1,
.height = rect->y2 - rect->y1,
};
int ow, oh;
wlr_output_transformed_resolution(output->wlr_output, &ow, &oh);
// Scissor is in renderer coordinates, ie. upside down
enum wl_output_transform transform = wlr_output_transform_compose(
wlr_output_transform_invert(wlr_output->transform),
WL_OUTPUT_TRANSFORM_FLIPPED_180);
wlr_box_transform(&box, transform, ow, oh, &box);
wlr_renderer_scissor(renderer, &box);
}
static void render_surface(struct wlr_surface *surface, double lx, double ly,
float rotation, void *_data) {
struct render_data *data = _data;
struct roots_output *output = data->output;
struct timespec *when = data->when;
struct wlr_renderer *renderer =
wlr_backend_get_renderer(output->wlr_output->backend);
assert(renderer);
if (!wlr_surface_has_buffer(surface)) {
return;
}
struct wlr_box box;
bool intersects = surface_intersect_output(surface, output->desktop->layout,
output->wlr_output, lx, ly, rotation, &box);
if (!intersects) {
return; return;
} }
struct wlr_box rotated;
wlr_box_rotated_bounds(&box, -rotation, &rotated);
pixman_region32_t damage;
pixman_region32_init(&damage);
pixman_region32_union_rect(&damage, &damage, rotated.x, rotated.y,
rotated.width, rotated.height);
pixman_region32_intersect(&damage, &damage, data->damage);
bool damaged = pixman_region32_not_empty(&damage);
if (!damaged) {
goto damage_finish;
}
float matrix[16];
enum wl_output_transform transform =
wlr_output_transform_invert(surface->current->transform);
wlr_matrix_project_box(&matrix, &box, transform, rotation,
&output->wlr_output->transform_matrix);
int nrects;
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]);
wlr_render_with_matrix(renderer, surface->texture, &matrix);
}
wlr_surface_send_frame_done(surface, when);
damage_finish:
pixman_region32_fini(&damage);
}
static void get_decoration_box(struct roots_view *view,
struct roots_output *output, struct wlr_box *box) {
struct wlr_output *wlr_output = output->wlr_output;
struct wlr_box deco_box; struct wlr_box deco_box;
view_get_deco_box(view, &deco_box); view_get_deco_box(view, &deco_box);
double sx = deco_box.x - view->x; double sx = deco_box.x - view->x;
@ -164,49 +263,70 @@ static void render_decorations(struct roots_view *view,
rotate_child_position(&sx, &sy, deco_box.width, deco_box.height, rotate_child_position(&sx, &sy, deco_box.width, deco_box.height,
view->wlr_surface->current->width, view->wlr_surface->current->width,
view->wlr_surface->current->height, view->rotation); view->wlr_surface->current->height, view->rotation);
double ox = sx + view->x; double x = sx + view->x;
double oy = sy + view->y; double y = sy + view->y;
wlr_output_layout_output_coords(desktop->layout, output, &ox, &oy);
ox *= output->scale;
oy *= output->scale;
struct wlr_box project_box = {
.x = ox,
.y = oy,
.width = deco_box.width,
.height = deco_box.height,
};
float matrix[16]; wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y);
wlr_matrix_project_box(&matrix, &project_box, WL_OUTPUT_TRANSFORM_NORMAL,
view->rotation, &output->transform_matrix); box->x = x * wlr_output->scale;
float color[4] = { 0.2, 0.2, 0.2, 1 }; box->y = y * wlr_output->scale;
wlr_render_colored_quad(desktop->server->renderer, &color, &matrix); box->width = deco_box.width * wlr_output->scale;
box->height = deco_box.height * wlr_output->scale;
} }
static void render_view(struct roots_view *view, struct roots_desktop *desktop, static void render_decorations(struct roots_view *view,
struct wlr_output *wlr_output, struct timespec *when) { struct render_data *data) {
render_decorations(view, desktop, wlr_output); if (!view->decorated || view->wlr_surface == NULL) {
return;
}
switch (view->type) { struct roots_output *output = data->output;
case ROOTS_XDG_SHELL_V6_VIEW: struct wlr_renderer *renderer =
render_surface(view->wlr_surface, desktop, wlr_output, when, wlr_backend_get_renderer(output->wlr_output->backend);
view->x, view->y, view->rotation); assert(renderer);
render_xdg_v6_popups(view->xdg_surface_v6, desktop, wlr_output,
when, view->x, view->y, view->rotation); struct wlr_box box;
break; get_decoration_box(view, output, &box);
case ROOTS_WL_SHELL_VIEW:
render_wl_shell_surface(view->wl_shell_surface, desktop, wlr_output, struct wlr_box rotated;
when, view->x, view->y, view->rotation, false); wlr_box_rotated_bounds(&box, -view->rotation, &rotated);
break;
#ifdef WLR_HAS_XWAYLAND pixman_region32_t damage;
case ROOTS_XWAYLAND_VIEW: pixman_region32_init(&damage);
render_surface(view->wlr_surface, desktop, wlr_output, when, pixman_region32_union_rect(&damage, &damage, rotated.x, rotated.y,
view->x, view->y, view->rotation); rotated.width, rotated.height);
break; pixman_region32_intersect(&damage, &damage, data->damage);
#endif bool damaged = pixman_region32_not_empty(&damage);
if (!damaged) {
goto damage_finish;
}
float matrix[16];
wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
view->rotation, &output->wlr_output->transform_matrix);
float color[] = { 0.2, 0.2, 0.2, 1 };
int nrects;
pixman_box32_t *rects =
pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]);
wlr_render_colored_quad(renderer, &color, &matrix);
}
damage_finish:
pixman_region32_fini(&damage);
}
static void render_view(struct roots_view *view, struct render_data *data) {
// Do not render views fullscreened on other outputs
if (view->fullscreen_output != NULL &&
view->fullscreen_output != data->output) {
return;
} }
render_decorations(view, data);
view_for_each_surface(view, render_surface, data);
} }
static bool has_standalone_surface(struct roots_view *view) { static bool has_standalone_surface(struct roots_view *view) {
@ -227,11 +347,12 @@ static bool has_standalone_surface(struct roots_view *view) {
return true; return true;
} }
static void output_frame_notify(struct wl_listener *listener, void *data) { static void render_output(struct roots_output *output) {
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = output->wlr_output;
struct roots_output *output = wl_container_of(listener, output, frame);
struct roots_desktop *desktop = output->desktop; struct roots_desktop *desktop = output->desktop;
struct roots_server *server = desktop->server; struct roots_server *server = desktop->server;
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
assert(renderer);
if (!wlr_output->enabled) { if (!wlr_output->enabled) {
return; return;
@ -240,9 +361,9 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
struct timespec now; struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
wlr_output_make_current(wlr_output); float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f};
wlr_renderer_begin(server->renderer, wlr_output);
// Check if we can delegate the fullscreen surface to the output
if (output->fullscreen_view != NULL) { if (output->fullscreen_view != NULL) {
struct roots_view *view = output->fullscreen_view; struct roots_view *view = output->fullscreen_view;
@ -261,65 +382,292 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_set_fullscreen_surface(wlr_output, view->wlr_surface); wlr_output_set_fullscreen_surface(wlr_output, view->wlr_surface);
} else { } else {
wlr_output_set_fullscreen_surface(wlr_output, NULL); wlr_output_set_fullscreen_surface(wlr_output, NULL);
}
// Fullscreen views are rendered on a black background
clear_color[0] = clear_color[1] = clear_color[2] = 0;
} else {
wlr_output_set_fullscreen_surface(wlr_output, NULL);
}
int buffer_age = -1;
if (!wlr_output_make_current(wlr_output, &buffer_age)) {
return;
}
int width, height;
wlr_output_transformed_resolution(output->wlr_output, &width, &height);
glClearColor(0, 0, 0, 0); // Check if we can use damage tracking
glClear(GL_COLOR_BUFFER_BIT); pixman_region32_t damage;
pixman_region32_init(&damage);
if (buffer_age <= 0 || buffer_age - 1 > ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN) {
// Buffer new or too old, damage the whole output
pixman_region32_union_rect(&damage, &damage, 0, 0, width, height);
} else {
pixman_region32_copy(&damage, &output->damage);
render_view(view, desktop, wlr_output, &now); // Accumulate damage from old buffers
size_t idx = output->previous_damage_idx;
for (int i = 0; i < buffer_age - 1; ++i) {
int j = (idx + i) % ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN;
pixman_region32_union(&damage, &damage, &output->previous_damage[j]);
}
}
pixman_region32_intersect_rect(&damage, &damage, 0, 0, width, height);
// During normal rendering the xwayland window tree isn't traversed if (!pixman_region32_not_empty(&damage) && !wlr_output->needs_swap) {
// because all windows are rendered. Here we only want to render // Output doesn't need swap and isn't damaged, skip rendering completely
// the fullscreen window's children so we have to traverse the tree. goto damage_finish;
}
struct render_data data = {
.output = output,
.when = &now,
.damage = &damage,
};
wlr_renderer_begin(renderer, wlr_output);
if (!pixman_region32_not_empty(&damage)) {
// Output isn't damaged but needs buffer swap
goto renderer_end;
}
int nrects;
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]);
wlr_renderer_clear(renderer, &clear_color);
}
// If a view is fullscreen on this output, render it
if (output->fullscreen_view != NULL) {
struct roots_view *view = output->fullscreen_view;
if (wlr_output->fullscreen_surface == view->wlr_surface) {
// The output will render the fullscreen view
goto renderer_end;
}
view_for_each_surface(view, render_surface, &data);
// During normal rendering the xwayland window tree isn't traversed
// because all windows are rendered. Here we only want to render
// the fullscreen window's children so we have to traverse the tree.
#ifdef WLR_HAS_XWAYLAND #ifdef WLR_HAS_XWAYLAND
if (view->type == ROOTS_XWAYLAND_VIEW) { if (view->type == ROOTS_XWAYLAND_VIEW) {
render_xwayland_children(view->xwayland_surface, desktop, xwayland_children_for_each_surface(view->xwayland_surface,
wlr_output, &now); render_surface, &data);
}
#endif
} }
wlr_renderer_end(server->renderer); #endif
wlr_output_swap_buffers(wlr_output);
output->last_frame = desktop->last_frame = now; goto renderer_end;
return;
} else {
wlr_output_set_fullscreen_surface(wlr_output, NULL);
} }
// Render all views
struct roots_view *view; struct roots_view *view;
wl_list_for_each_reverse(view, &desktop->views, link) { wl_list_for_each_reverse(view, &desktop->views, link) {
render_view(view, desktop, wlr_output, &now); render_view(view, &data);
} }
struct wlr_drag_icon *drag_icon = NULL; // Render drag icons
struct roots_drag_icon *drag_icon = NULL;
struct roots_seat *seat = NULL; struct roots_seat *seat = NULL;
wl_list_for_each(seat, &server->input->seats, link) { wl_list_for_each(seat, &server->input->seats, link) {
wl_list_for_each(drag_icon, &seat->seat->drag_icons, link) { wl_list_for_each(drag_icon, &seat->drag_icons, link) {
if (!drag_icon->mapped) { if (!drag_icon->wlr_drag_icon->mapped) {
continue; continue;
} }
struct wlr_surface *icon = drag_icon->surface; render_surface(drag_icon->wlr_drag_icon->surface,
struct wlr_cursor *cursor = seat->cursor->cursor; drag_icon->x, drag_icon->y, 0, &data);
double icon_x = 0, icon_y = 0; }
if (drag_icon->is_pointer) { }
icon_x = cursor->x + drag_icon->sx;
icon_y = cursor->y + drag_icon->sy; renderer_end:
render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); wlr_renderer_scissor(renderer, NULL);
} else { wlr_renderer_end(renderer);
struct wlr_touch_point *point = if (!wlr_output_swap_buffers(wlr_output, &now, &damage)) {
wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id); goto damage_finish;
if (point) { }
icon_x = seat->touch_x + drag_icon->sx; // same as decrementing, but works on unsigned integers
icon_y = seat->touch_y + drag_icon->sy; output->previous_damage_idx += ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN - 1;
render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); output->previous_damage_idx %= ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN;
} pixman_region32_copy(&output->previous_damage[output->previous_damage_idx],
&output->damage);
pixman_region32_clear(&output->damage);
output->last_frame = desktop->last_frame = now;
damage_finish:
pixman_region32_fini(&damage);
}
static void output_handle_frame(struct wl_listener *listener, void *data) {
struct roots_output *output = wl_container_of(listener, output, frame);
render_output(output);
}
void output_damage_whole(struct roots_output *output) {
int width, height;
wlr_output_transformed_resolution(output->wlr_output, &width, &height);
pixman_region32_union_rect(&output->damage, &output->damage, 0, 0,
width, height);
wlr_output_schedule_frame(output->wlr_output);
}
static bool view_accept_damage(struct roots_output *output,
struct roots_view *view) {
if (output->fullscreen_view == NULL) {
return true;
}
if (output->fullscreen_view == view) {
return true;
}
#ifdef WLR_HAS_XWAYLAND
if (output->fullscreen_view->type == ROOTS_XWAYLAND_VIEW &&
view->type == ROOTS_XWAYLAND_VIEW) {
// Special case: accept damage from children
struct wlr_xwayland_surface *xsurface = view->xwayland_surface;
while (xsurface != NULL) {
if (output->fullscreen_view->xwayland_surface == xsurface) {
return true;
} }
xsurface = xsurface->parent;
} }
} }
#endif
return false;
}
static void damage_whole_surface(struct wlr_surface *surface,
double lx, double ly, float rotation, void *data) {
struct roots_output *output = data;
if (!wlr_surface_has_buffer(surface)) {
return;
}
wlr_renderer_end(server->renderer); int ow, oh;
wlr_output_swap_buffers(wlr_output); wlr_output_transformed_resolution(output->wlr_output, &ow, &oh);
output->last_frame = desktop->last_frame = now; struct wlr_box box;
bool intersects = surface_intersect_output(surface, output->desktop->layout,
output->wlr_output, lx, ly, rotation, &box);
if (!intersects) {
return;
}
wlr_box_rotated_bounds(&box, -rotation, &box);
pixman_region32_union_rect(&output->damage, &output->damage,
box.x, box.y, box.width, box.height);
wlr_output_schedule_frame(output->wlr_output);
}
static void damage_whole_decoration(struct roots_view *view,
struct roots_output *output) {
if (!view->decorated || view->wlr_surface == NULL) {
return;
}
struct wlr_box box;
get_decoration_box(view, output, &box);
wlr_box_rotated_bounds(&box, -view->rotation, &box);
pixman_region32_union_rect(&output->damage, &output->damage,
box.x, box.y, box.width, box.height);
}
void output_damage_whole_view(struct roots_output *output,
struct roots_view *view) {
if (!view_accept_damage(output, view)) {
return;
}
damage_whole_decoration(view, output);
view_for_each_surface(view, damage_whole_surface, output);
}
void output_damage_whole_drag_icon(struct roots_output *output,
struct roots_drag_icon *icon) {
surface_for_each_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, 0,
damage_whole_surface, output);
}
static void damage_from_surface(struct wlr_surface *surface,
double lx, double ly, float rotation, void *data) {
struct roots_output *output = data;
struct wlr_output *wlr_output = output->wlr_output;
if (!wlr_surface_has_buffer(surface)) {
return;
}
int ow, oh;
wlr_output_transformed_resolution(wlr_output, &ow, &oh);
struct wlr_box box;
surface_intersect_output(surface, output->desktop->layout,
wlr_output, lx, ly, rotation, &box);
if (rotation == 0) {
pixman_region32_t damage;
pixman_region32_init(&damage);
pixman_region32_copy(&damage, &surface->current->surface_damage);
wlr_region_scale(&damage, &damage, wlr_output->scale);
if (ceil(wlr_output->scale) > surface->current->scale) {
// When scaling up a surface, it'll become blurry so we need to
// expand the damage region
wlr_region_expand(&damage, &damage,
ceil(wlr_output->scale) - surface->current->scale);
}
pixman_region32_translate(&damage, box.x, box.y);
pixman_region32_union(&output->damage, &output->damage, &damage);
pixman_region32_fini(&damage);
} else {
pixman_box32_t *extents =
pixman_region32_extents(&surface->current->surface_damage);
struct wlr_box damage_box = {
.x = box.x + extents->x1 * wlr_output->scale,
.y = box.y + extents->y1 * wlr_output->scale,
.width = (extents->x2 - extents->x1) * wlr_output->scale,
.height = (extents->y2 - extents->y1) * wlr_output->scale,
};
wlr_box_rotated_bounds(&damage_box, -rotation, &damage_box);
pixman_region32_union_rect(&output->damage, &output->damage,
damage_box.x, damage_box.y, damage_box.width, damage_box.height);
}
pixman_region32_intersect_rect(&output->damage, &output->damage, 0, 0,
ow, oh);
wlr_output_schedule_frame(wlr_output);
}
void output_damage_from_view(struct roots_output *output,
struct roots_view *view) {
if (!view_accept_damage(output, view)) {
return;
}
view_for_each_surface(view, damage_from_surface, output);
}
static void output_handle_mode(struct wl_listener *listener, void *data) {
struct roots_output *output = wl_container_of(listener, output, mode);
output_damage_whole(output);
}
static void output_handle_needs_swap(struct wl_listener *listener, void *data) {
struct roots_output *output =
wl_container_of(listener, output, needs_swap);
pixman_region32_union(&output->damage, &output->damage,
&output->wlr_output->damage);
wlr_output_schedule_frame(output->wlr_output);
} }
static void set_mode(struct wlr_output *output, static void set_mode(struct wlr_output *output,
@ -372,9 +720,18 @@ void output_add_notify(struct wl_listener *listener, void *data) {
clock_gettime(CLOCK_MONOTONIC, &output->last_frame); clock_gettime(CLOCK_MONOTONIC, &output->last_frame);
output->desktop = desktop; output->desktop = desktop;
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
output->frame.notify = output_frame_notify;
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&desktop->outputs, &output->link); wl_list_insert(&desktop->outputs, &output->link);
pixman_region32_init(&output->damage);
for (size_t i = 0; i < ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN; ++i) {
pixman_region32_init(&output->previous_damage[i]);
}
output->frame.notify = output_handle_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
output->mode.notify = output_handle_mode;
wl_signal_add(&wlr_output->events.mode, &output->mode);
output->needs_swap.notify = output_handle_needs_swap;
wl_signal_add(&wlr_output->events.needs_swap, &output->needs_swap);
struct roots_output_config *output_config = struct roots_output_config *output_config =
roots_config_get_output(config, wlr_output); roots_config_get_output(config, wlr_output);
@ -399,6 +756,8 @@ void output_add_notify(struct wl_listener *listener, void *data) {
roots_seat_configure_cursor(seat); roots_seat_configure_cursor(seat);
roots_seat_configure_xcursor(seat); roots_seat_configure_xcursor(seat);
} }
output_damage_whole(output);
} }
void output_remove_notify(struct wl_listener *listener, void *data) { void output_remove_notify(struct wl_listener *listener, void *data) {
@ -423,7 +782,13 @@ void output_remove_notify(struct wl_listener *listener, void *data) {
//example_config_configure_cursor(sample->config, sample->cursor, //example_config_configure_cursor(sample->config, sample->cursor,
// sample->compositor); // sample->compositor);
pixman_region32_fini(&output->damage);
for (size_t i = 0; i < ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN; ++i) {
pixman_region32_fini(&output->previous_damage[i]);
}
wl_list_remove(&output->link); wl_list_remove(&output->link);
wl_list_remove(&output->frame.link); wl_list_remove(&output->frame.link);
wl_list_remove(&output->mode.link);
wl_list_remove(&output->needs_swap.link);
free(output); free(output);
} }

@ -241,19 +241,97 @@ static void roots_seat_init_cursor(struct roots_seat *seat) {
seat->cursor->tool_tip.notify = handle_tool_tip; seat->cursor->tool_tip.notify = handle_tool_tip;
wl_signal_add(&seat->seat->events.request_set_cursor, wl_signal_add(&seat->seat->events.request_set_cursor,
&seat->cursor->request_set_cursor); &seat->cursor->request_set_cursor);
seat->cursor->request_set_cursor.notify = handle_request_set_cursor; seat->cursor->request_set_cursor.notify = handle_request_set_cursor;
} }
static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, surface_commit);
roots_drag_icon_damage_whole(icon);
}
static void roots_drag_icon_handle_map(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, map);
roots_drag_icon_damage_whole(icon);
}
static void roots_drag_icon_handle_destroy(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, destroy);
roots_drag_icon_damage_whole(icon);
wl_list_remove(&icon->link);
wl_list_remove(&icon->surface_commit.link);
wl_list_remove(&icon->map.link);
wl_list_remove(&icon->destroy.link);
free(icon);
}
static void roots_seat_handle_new_drag_icon(struct wl_listener *listener,
void *data) {
struct roots_seat *seat = wl_container_of(listener, seat, new_drag_icon);
struct wlr_drag_icon *wlr_drag_icon = data;
struct roots_drag_icon *icon = calloc(1, sizeof(struct roots_drag_icon));
if (icon == NULL) {
return;
}
icon->seat = seat;
icon->wlr_drag_icon = wlr_drag_icon;
icon->surface_commit.notify = roots_drag_icon_handle_surface_commit;
wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
icon->map.notify = roots_drag_icon_handle_map;
wl_signal_add(&wlr_drag_icon->events.map, &icon->map);
icon->destroy.notify = roots_drag_icon_handle_destroy;
wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
wl_list_insert(&seat->drag_icons, &icon->link);
}
void roots_drag_icon_update_position(struct roots_drag_icon *icon) {
roots_drag_icon_damage_whole(icon);
struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
struct roots_seat *seat = icon->seat;
struct wlr_cursor *cursor = seat->cursor->cursor;
if (wlr_icon->is_pointer) {
icon->x = cursor->x + wlr_icon->sx;
icon->y = cursor->y + wlr_icon->sy;
} else {
struct wlr_touch_point *point =
wlr_seat_touch_get_point(seat->seat, wlr_icon->touch_id);
if (point == NULL) {
return;
}
icon->x = seat->touch_x + wlr_icon->sx;
icon->y = seat->touch_y + wlr_icon->sy;
}
roots_drag_icon_damage_whole(icon);
}
void roots_drag_icon_damage_whole(struct roots_drag_icon *icon) {
struct roots_output *output;
wl_list_for_each(output, &icon->seat->input->server->desktop->outputs,
link) {
output_damage_whole_drag_icon(output, icon);
}
}
static void seat_view_destroy(struct roots_seat_view *seat_view); static void seat_view_destroy(struct roots_seat_view *seat_view);
static void roots_seat_handle_seat_destroy(struct wl_listener *listener, static void roots_seat_handle_destroy(struct wl_listener *listener,
void *data) { void *data) {
struct roots_seat *seat = struct roots_seat *seat = wl_container_of(listener, seat, destroy);
wl_container_of(listener, seat, seat_destroy);
// TODO: probably more to be freed here // TODO: probably more to be freed here
wl_list_remove(&seat->seat_destroy.link); wl_list_remove(&seat->destroy.link);
struct roots_seat_view *view, *nview; struct roots_seat_view *view, *nview;
wl_list_for_each_safe(view, nview, &seat->views, link) { wl_list_for_each_safe(view, nview, &seat->views, link) {
@ -262,7 +340,7 @@ static void roots_seat_handle_seat_destroy(struct wl_listener *listener,
} }
void roots_seat_destroy(struct roots_seat *seat) { void roots_seat_destroy(struct roots_seat *seat) {
roots_seat_handle_seat_destroy(&seat->seat_destroy, seat->seat); roots_seat_handle_destroy(&seat->destroy, seat->seat);
wlr_seat_destroy(seat->seat); wlr_seat_destroy(seat->seat);
} }
@ -277,6 +355,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
wl_list_init(&seat->touch); wl_list_init(&seat->touch);
wl_list_init(&seat->tablet_tools); wl_list_init(&seat->tablet_tools);
wl_list_init(&seat->views); wl_list_init(&seat->views);
wl_list_init(&seat->drag_icons);
seat->input = input; seat->input = input;
@ -295,8 +374,10 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
wl_list_insert(&input->seats, &seat->link); wl_list_insert(&input->seats, &seat->link);
seat->seat_destroy.notify = roots_seat_handle_seat_destroy; seat->new_drag_icon.notify = roots_seat_handle_new_drag_icon;
wl_signal_add(&seat->seat->events.destroy, &seat->seat_destroy); wl_signal_add(&seat->seat->events.new_drag_icon, &seat->new_drag_icon);
seat->destroy.notify = roots_seat_handle_destroy;
wl_signal_add(&seat->seat->events.destroy, &seat->destroy);
return seat; return seat;
} }
@ -683,6 +764,8 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
wl_list_remove(&seat_view->link); wl_list_remove(&seat_view->link);
wl_list_insert(&seat->views, &seat_view->link); wl_list_insert(&seat->views, &seat_view->link);
view_damage_whole(view);
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
if (keyboard != NULL) { if (keyboard != NULL) {
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface,

@ -10,6 +10,61 @@
#include "rootston/server.h" #include "rootston/server.h"
#include "rootston/input.h" #include "rootston/input.h"
static void popup_destroy(struct roots_view_child *child) {
assert(child->destroy == popup_destroy);
struct roots_wl_shell_popup *popup = (struct roots_wl_shell_popup *)child;
if (popup == NULL) {
return;
}
wl_list_remove(&popup->destroy.link);
wl_list_remove(&popup->set_state.link);
wl_list_remove(&popup->new_popup.link);
view_child_finish(&popup->view_child);
free(popup);
}
static void popup_handle_destroy(struct wl_listener *listener, void *data) {
struct roots_wl_shell_popup *popup =
wl_container_of(listener, popup, destroy);
popup_destroy((struct roots_view_child *)popup);
}
static void popup_handle_set_state(struct wl_listener *listener, void *data) {
struct roots_wl_shell_popup *popup =
wl_container_of(listener, popup, set_state);
popup_destroy((struct roots_view_child *)popup);
}
static struct roots_wl_shell_popup *popup_create(struct roots_view *view,
struct wlr_wl_shell_surface *wlr_wl_shell_surface);
static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
struct roots_wl_shell_popup *popup =
wl_container_of(listener, popup, new_popup);
struct wlr_wl_shell_surface *wlr_wl_shell_surface = data;
popup_create(popup->view_child.view, wlr_wl_shell_surface);
}
static struct roots_wl_shell_popup *popup_create(struct roots_view *view,
struct wlr_wl_shell_surface *wlr_wl_shell_surface) {
struct roots_wl_shell_popup *popup =
calloc(1, sizeof(struct roots_wl_shell_popup));
if (popup == NULL) {
return NULL;
}
popup->wlr_wl_shell_surface = wlr_wl_shell_surface;
popup->view_child.destroy = popup_destroy;
view_child_init(&popup->view_child, view, wlr_wl_shell_surface->surface);
popup->destroy.notify = popup_handle_destroy;
wl_signal_add(&wlr_wl_shell_surface->events.destroy, &popup->destroy);
popup->set_state.notify = popup_handle_set_state;
wl_signal_add(&wlr_wl_shell_surface->events.set_state, &popup->set_state);
popup->new_popup.notify = popup_handle_new_popup;
wl_signal_add(&wlr_wl_shell_surface->events.new_popup, &popup->new_popup);
return popup;
}
static void resize(struct roots_view *view, uint32_t width, uint32_t height) { static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
assert(view->type == ROOTS_WL_SHELL_VIEW); assert(view->type == ROOTS_WL_SHELL_VIEW);
struct wlr_wl_shell_surface *surf = view->wl_shell_surface; struct wlr_wl_shell_surface *surf = view->wl_shell_surface;
@ -88,19 +143,32 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view; struct roots_view *view = roots_surface->view;
struct wlr_surface *wlr_surface = view->wlr_surface; struct wlr_surface *wlr_surface = view->wlr_surface;
view_apply_damage(view);
int width = wlr_surface->current->width; int width = wlr_surface->current->width;
int height = wlr_surface->current->height; int height = wlr_surface->current->height;
view_update_size(view, width, height);
double x = view->x;
double y = view->y;
if (view->pending_move_resize.update_x) { if (view->pending_move_resize.update_x) {
view->x = view->pending_move_resize.x + x = view->pending_move_resize.x + view->pending_move_resize.width -
view->pending_move_resize.width - width; width;
view->pending_move_resize.update_x = false; view->pending_move_resize.update_x = false;
} }
if (view->pending_move_resize.update_y) { if (view->pending_move_resize.update_y) {
view->y = view->pending_move_resize.y + y = view->pending_move_resize.y + view->pending_move_resize.height -
view->pending_move_resize.height - height; height;
view->pending_move_resize.update_y = false; view->pending_move_resize.update_y = false;
} }
view_update_position(view, x, y);
}
static void handle_new_popup(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, new_popup);
struct wlr_wl_shell_surface *wlr_wl_shell_surface = data;
popup_create(roots_surface->view, wlr_wl_shell_surface);
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -114,16 +182,22 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->set_state.link);
wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->surface_commit.link);
wl_list_remove(&roots_surface->view->link); wl_list_remove(&roots_surface->view->link);
view_destroy(roots_surface->view); view_finish(roots_surface->view);
free(roots_surface->view);
free(roots_surface); free(roots_surface);
} }
void handle_wl_shell_surface(struct wl_listener *listener, void *data) { void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop = struct roots_desktop *desktop =
wl_container_of(listener, desktop, wl_shell_surface); wl_container_of(listener, desktop, wl_shell_surface);
struct wlr_wl_shell_surface *surface = data; struct wlr_wl_shell_surface *surface = data;
wlr_log(L_DEBUG, "new shell surface: title=%s, class=%s",
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) {
wlr_log(L_DEBUG, "new wl shell popup");
return;
}
wlr_log(L_DEBUG, "new wl shell surface: title=%s, class=%s",
surface->title, surface->class); surface->title, surface->class);
wlr_wl_shell_surface_ping(surface); wlr_wl_shell_surface_ping(surface);
@ -134,6 +208,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
} }
roots_surface->destroy.notify = handle_destroy; roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy); wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
roots_surface->new_popup.notify = handle_new_popup;
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
roots_surface->request_move.notify = handle_request_move; roots_surface->request_move.notify = handle_request_move;
wl_signal_add(&surface->events.request_move, &roots_surface->request_move); wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
roots_surface->request_resize.notify = handle_request_resize; roots_surface->request_resize.notify = handle_request_resize;
@ -157,6 +233,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
return; return;
} }
view->type = ROOTS_WL_SHELL_VIEW; view->type = ROOTS_WL_SHELL_VIEW;
view->width = surface->surface->current->width;
view->height = surface->surface->current->height;
view->wl_shell_surface = surface; view->wl_shell_surface = surface;
view->roots_wl_shell_surface = roots_surface; view->roots_wl_shell_surface = roots_surface;

@ -10,6 +10,52 @@
#include "rootston/server.h" #include "rootston/server.h"
#include "rootston/input.h" #include "rootston/input.h"
static void popup_destroy(struct roots_view_child *child) {
assert(child->destroy == popup_destroy);
struct roots_xdg_popup_v6 *popup = (struct roots_xdg_popup_v6 *)child;
if (popup == NULL) {
return;
}
wl_list_remove(&popup->destroy.link);
wl_list_remove(&popup->new_popup.link);
view_child_finish(&popup->view_child);
free(popup);
}
static void popup_handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xdg_popup_v6 *popup =
wl_container_of(listener, popup, destroy);
popup_destroy((struct roots_view_child *)popup);
}
static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view,
struct wlr_xdg_popup_v6 *wlr_popup);
static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
struct roots_xdg_popup_v6 *popup =
wl_container_of(listener, popup, new_popup);
struct wlr_xdg_popup_v6 *wlr_popup = data;
popup_create(popup->view_child.view, wlr_popup);
}
static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view,
struct wlr_xdg_popup_v6 *wlr_popup) {
struct roots_xdg_popup_v6 *popup =
calloc(1, sizeof(struct roots_xdg_popup_v6));
if (popup == NULL) {
return NULL;
}
popup->wlr_popup = wlr_popup;
popup->view_child.destroy = popup_destroy;
view_child_init(&popup->view_child, view, wlr_popup->base->surface);
popup->destroy.notify = popup_handle_destroy;
wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
popup->new_popup.notify = popup_handle_new_popup;
wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
return popup;
}
static void get_size(const struct roots_view *view, struct wlr_box *box) { static void get_size(const struct roots_view *view, struct wlr_box *box) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
@ -102,8 +148,7 @@ static void move_resize(struct roots_view *view, double x, double y,
if (serial > 0) { if (serial > 0) {
roots_surface->pending_move_resize_configure_serial = serial; roots_surface->pending_move_resize_configure_serial = serial;
} else if (roots_surface->pending_move_resize_configure_serial == 0) { } else if (roots_surface->pending_move_resize_configure_serial == 0) {
view->x = x; view_update_position(view, x, y);
view->y = y;
} }
} }
@ -192,26 +237,32 @@ static void handle_request_fullscreen(struct wl_listener *listener,
view_set_fullscreen(view, e->fullscreen, e->output); view_set_fullscreen(view, e->fullscreen, e->output);
} }
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_surface = struct roots_xdg_surface_v6 *roots_surface =
wl_container_of(listener, roots_surface, commit); wl_container_of(listener, roots_surface, surface_commit);
struct roots_view *view = roots_surface->view; struct roots_view *view = roots_surface->view;
struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
view_apply_damage(view);
struct wlr_box size;
get_size(view, &size);
view_update_size(view, size.width, size.height);
uint32_t pending_serial = uint32_t pending_serial =
roots_surface->pending_move_resize_configure_serial; roots_surface->pending_move_resize_configure_serial;
if (pending_serial > 0 && pending_serial >= surface->configure_serial) { if (pending_serial > 0 && pending_serial >= surface->configure_serial) {
struct wlr_box size; double x = view->x;
get_size(view, &size); double y = view->y;
if (view->pending_move_resize.update_x) { if (view->pending_move_resize.update_x) {
view->x = view->pending_move_resize.x + x = view->pending_move_resize.x + view->pending_move_resize.width -
view->pending_move_resize.width - size.width; size.width;
} }
if (view->pending_move_resize.update_y) { if (view->pending_move_resize.update_y) {
view->y = view->pending_move_resize.y + y = view->pending_move_resize.y + view->pending_move_resize.height -
view->pending_move_resize.height - size.height; size.height;
} }
view_update_position(view, x, y);
if (pending_serial == surface->configure_serial) { if (pending_serial == surface->configure_serial) {
roots_surface->pending_move_resize_configure_serial = 0; roots_surface->pending_move_resize_configure_serial = 0;
@ -219,15 +270,26 @@ static void handle_commit(struct wl_listener *listener, void *data) {
} }
} }
static void handle_new_popup(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, new_popup);
struct wlr_xdg_popup_v6 *wlr_popup = data;
popup_create(roots_xdg_surface->view, wlr_popup);
}
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface = struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, destroy); wl_container_of(listener, roots_xdg_surface, destroy);
wl_list_remove(&roots_xdg_surface->commit.link); wl_list_remove(&roots_xdg_surface->surface_commit.link);
wl_list_remove(&roots_xdg_surface->destroy.link); wl_list_remove(&roots_xdg_surface->destroy.link);
wl_list_remove(&roots_xdg_surface->new_popup.link);
wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_move.link);
wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_resize.link);
wl_list_remove(&roots_xdg_surface->request_maximize.link);
wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
wl_list_remove(&roots_xdg_surface->view->link); wl_list_remove(&roots_xdg_surface->view->link);
view_destroy(roots_xdg_surface->view); view_finish(roots_xdg_surface->view);
free(roots_xdg_surface->view);
free(roots_xdg_surface); free(roots_xdg_surface);
} }
@ -252,8 +314,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
if (!roots_surface) { if (!roots_surface) {
return; return;
} }
roots_surface->commit.notify = handle_commit; roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit, &roots_surface->commit); wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
roots_surface->destroy.notify = handle_destroy; roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy); wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
roots_surface->request_move.notify = handle_request_move; roots_surface->request_move.notify = handle_request_move;
@ -267,6 +330,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->request_fullscreen.notify = handle_request_fullscreen; roots_surface->request_fullscreen.notify = handle_request_fullscreen;
wl_signal_add(&surface->events.request_fullscreen, wl_signal_add(&surface->events.request_fullscreen,
&roots_surface->request_fullscreen); &roots_surface->request_fullscreen);
roots_surface->new_popup.notify = handle_new_popup;
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
struct roots_view *view = calloc(1, sizeof(struct roots_view)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) { if (!view) {
@ -274,10 +339,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
return; return;
} }
view->type = ROOTS_XDG_SHELL_V6_VIEW; view->type = ROOTS_XDG_SHELL_V6_VIEW;
view->xdg_surface_v6 = surface; view->xdg_surface_v6 = surface;
view->roots_xdg_surface_v6 = roots_surface; view->roots_xdg_surface_v6 = roots_surface;
view->wlr_surface = surface->surface; view->wlr_surface = surface->surface;
view->get_size = get_size;
view->activate = activate; view->activate = activate;
view->resize = resize; view->resize = resize;
view->move_resize = move_resize; view->move_resize = move_resize;
@ -285,6 +350,12 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->set_fullscreen = set_fullscreen; view->set_fullscreen = set_fullscreen;
view->close = close; view->close = close;
roots_surface->view = view; roots_surface->view = view;
struct wlr_box box;
get_size(view, &box);
view->width = box.width;
view->height = box.height;
view_init(view, desktop); view_init(view, desktop);
wl_list_insert(&desktop->views, &view->link); wl_list_insert(&desktop->views, &view->link);

@ -18,8 +18,7 @@ static void activate(struct roots_view *view, bool active) {
static void move(struct roots_view *view, double x, double y) { static void move(struct roots_view *view, double x, double y) {
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
view->x = x; view_update_position(view, x, y);
view->y = y;
wlr_xwayland_surface_configure(xwayland_surface, x, y, wlr_xwayland_surface_configure(xwayland_surface, x, y,
xwayland_surface->width, xwayland_surface->height); xwayland_surface->width, xwayland_surface->height);
} }
@ -122,7 +121,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
if (xwayland_surface->mapped) { if (xwayland_surface->mapped) {
wl_list_remove(&roots_surface->view->link); wl_list_remove(&roots_surface->view->link);
} }
view_destroy(roots_surface->view); view_finish(roots_surface->view);
free(roots_surface->view);
free(roots_surface); free(roots_surface);
} }
@ -133,8 +133,7 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
roots_surface->view->xwayland_surface; roots_surface->view->xwayland_surface;
struct wlr_xwayland_surface_configure_event *event = data; struct wlr_xwayland_surface_configure_event *event = data;
roots_surface->view->x = (double)event->x; view_update_position(roots_surface->view, event->x, event->y);
roots_surface->view->y = (double)event->y;
wlr_xwayland_surface_configure(xwayland_surface, event->x, event->y, wlr_xwayland_surface_configure(xwayland_surface, event->x, event->y,
event->width, event->height); event->width, event->height);
@ -206,19 +205,25 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view; struct roots_view *view = roots_surface->view;
struct wlr_surface *wlr_surface = view->wlr_surface; struct wlr_surface *wlr_surface = view->wlr_surface;
view_apply_damage(view);
int width = wlr_surface->current->width; int width = wlr_surface->current->width;
int height = wlr_surface->current->height; int height = wlr_surface->current->height;
view_update_size(view, width, height);
double x = view->x;
double y = view->y;
if (view->pending_move_resize.update_x) { if (view->pending_move_resize.update_x) {
view->x = view->pending_move_resize.x + x = view->pending_move_resize.x + view->pending_move_resize.width -
view->pending_move_resize.width - width; width;
view->pending_move_resize.update_x = false; view->pending_move_resize.update_x = false;
} }
if (view->pending_move_resize.update_y) { if (view->pending_move_resize.update_y) {
view->y = view->pending_move_resize.y + y = view->pending_move_resize.y + view->pending_move_resize.height -
view->pending_move_resize.height - height; height;
view->pending_move_resize.update_y = false; view->pending_move_resize.update_y = false;
} }
view_update_position(view, x, y);
} }
static void handle_map_notify(struct wl_listener *listener, void *data) { static void handle_map_notify(struct wl_listener *listener, void *data) {
@ -229,24 +234,48 @@ static void handle_map_notify(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop = view->desktop; struct roots_desktop *desktop = view->desktop;
view->wlr_surface = xsurface->surface; view->wlr_surface = xsurface->surface;
view->x = (double)xsurface->x; view->x = xsurface->x;
view->y = (double)xsurface->y; view->y = xsurface->y;
view->width = xsurface->surface->current->width;
view->height = xsurface->surface->current->height;
wl_list_insert(&desktop->views, &view->link);
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list,
parent_link) {
subsurface_create(view, subsurface);
}
view_damage_whole(view);
roots_surface->surface_commit.notify = handle_surface_commit; roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&xsurface->surface->events.commit, wl_signal_add(&xsurface->surface->events.commit,
&roots_surface->surface_commit); &roots_surface->surface_commit);
wl_list_insert(&desktop->views, &view->link);
} }
static void handle_unmap_notify(struct wl_listener *listener, void *data) { static void handle_unmap_notify(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface = struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, unmap_notify); wl_container_of(listener, roots_surface, unmap_notify);
roots_surface->view->wlr_surface = NULL; struct roots_view *view = roots_surface->view;
wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->surface_commit.link);
wl_list_remove(&roots_surface->view->link); view_damage_whole(view);
struct roots_view_child *child, *tmp;
wl_list_for_each_safe(child, tmp, &view->children, link) {
child->destroy(child);
}
if (view->fullscreen_output != NULL) {
output_damage_whole(view->fullscreen_output);
view->fullscreen_output->fullscreen_view = NULL;
view->fullscreen_output = NULL;
}
view->wlr_surface = NULL;
view->width = view->height = 0;
wl_list_remove(&view->link);
} }
void handle_xwayland_surface(struct wl_listener *listener, void *data) { void handle_xwayland_surface(struct wl_listener *listener, void *data) {
@ -296,6 +325,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->type = ROOTS_XWAYLAND_VIEW; view->type = ROOTS_XWAYLAND_VIEW;
view->x = (double)surface->x; view->x = (double)surface->x;
view->y = (double)surface->y; view->y = (double)surface->y;
view->width = surface->surface->current->width;
view->height = surface->surface->current->height;
view->xwayland_surface = surface; view->xwayland_surface = surface;
view->roots_xwayland_surface = roots_surface; view->roots_xwayland_surface = roots_surface;

@ -67,47 +67,79 @@ bool wlr_box_contains_point(const struct wlr_box *box, double x, double y) {
} }
void wlr_box_transform(const struct wlr_box *box, void wlr_box_transform(const struct wlr_box *box,
enum wl_output_transform transform, struct wlr_box *dest) { enum wl_output_transform transform, int width, int height,
struct wlr_box *dest) {
struct wlr_box src = *box;
if (transform % 2 == 0) { if (transform % 2 == 0) {
dest->width = box->width; dest->width = src.width;
dest->height = box->height; dest->height = src.height;
} else { } else {
dest->width = box->height; dest->width = src.height;
dest->height = box->width; dest->height = src.width;
} }
switch (transform) { switch (transform) {
case WL_OUTPUT_TRANSFORM_NORMAL: case WL_OUTPUT_TRANSFORM_NORMAL:
dest->x = box->x; dest->x = src.x;
dest->y = box->y; dest->y = src.y;
break; break;
case WL_OUTPUT_TRANSFORM_90: case WL_OUTPUT_TRANSFORM_90:
dest->x = box->y; dest->x = src.y;
dest->y = box->width - box->x; dest->y = width - src.x - src.width;
break; break;
case WL_OUTPUT_TRANSFORM_180: case WL_OUTPUT_TRANSFORM_180:
dest->x = box->width - box->x; dest->x = width - src.x - src.width;
dest->y = box->height - box->y; dest->y = height - src.y - src.height;
break; break;
case WL_OUTPUT_TRANSFORM_270: case WL_OUTPUT_TRANSFORM_270:
dest->x = box->height - box->y; dest->x = height - src.y - src.height;
dest->y = box->x; dest->y = src.x;
break; break;
case WL_OUTPUT_TRANSFORM_FLIPPED: case WL_OUTPUT_TRANSFORM_FLIPPED:
dest->x = box->width - box->x; dest->x = width - src.x - src.width;
dest->y = box->y; dest->y = src.y;
break; break;
case WL_OUTPUT_TRANSFORM_FLIPPED_90: case WL_OUTPUT_TRANSFORM_FLIPPED_90:
dest->x = box->height - box->y; dest->x = height - src.y - src.height;
dest->y = box->width - box->x; dest->y = width - src.x - src.width;
break; break;
case WL_OUTPUT_TRANSFORM_FLIPPED_180: case WL_OUTPUT_TRANSFORM_FLIPPED_180:
dest->x = box->x; dest->x = src.x;
dest->y = box->height - box->y; dest->y = height - src.y - src.height;
break; break;
case WL_OUTPUT_TRANSFORM_FLIPPED_270: case WL_OUTPUT_TRANSFORM_FLIPPED_270:
dest->x = box->y; dest->x = src.y;
dest->y = box->x; dest->y = src.x;
break; break;
} }
} }
void wlr_box_rotated_bounds(const struct wlr_box *box, float rotation,
struct wlr_box *dest) {
if (rotation == 0) {
*dest = *box;
return;
}
double ox = box->x + (double)box->width/2;
double oy = box->y + (double)box->height/2;
double c = fabs(cos(rotation));
double s = fabs(sin(rotation));
double x1 = ox + (box->x - ox) * c + (box->y - oy) * s;
double x2 = ox +
(box->x + box->width - ox) * c +
(box->y + box->height - oy) * s;
double y1 = oy + (box->x - ox) * s + (box->y - oy) * c;
double y2 = oy +
(box->x + box->width - ox) * s +
(box->y + box->height - oy) * c;
dest->x = floor(fmin(x1, x2));
dest->width = ceil(fmax(x1, x2) - fmin(x1, x2));
dest->y = floor(fmin(y1, y2));
dest->height = ceil(fmax(y1, y2) - fmin(y1, y2));
}

@ -35,7 +35,7 @@ static void wl_compositor_create_surface(struct wl_client *client,
wl_list_insert(&compositor->surfaces, wl_list_insert(&compositor->surfaces,
wl_resource_get_link(surface_resource)); wl_resource_get_link(surface_resource));
wl_signal_emit(&compositor->events.create_surface, surface); wl_signal_emit(&compositor->events.new_surface, surface);
} }
static void wl_compositor_create_region(struct wl_client *client, static void wl_compositor_create_region(struct wl_client *client,
@ -185,7 +185,7 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
wl_list_init(&compositor->wl_resources); wl_list_init(&compositor->wl_resources);
wl_list_init(&compositor->surfaces); wl_list_init(&compositor->surfaces);
wl_signal_init(&compositor->events.create_surface); wl_signal_init(&compositor->events.new_surface);
compositor->display_destroy.notify = handle_display_destroy; compositor->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &compositor->display_destroy); wl_display_add_destroy_listener(display, &compositor->display_destroy);

@ -457,6 +457,7 @@ static void wlr_drag_end(struct wlr_drag *drag) {
if (drag->icon) { if (drag->icon) {
drag->icon->mapped = false; drag->icon->mapped = false;
wl_list_remove(&drag->icon_destroy.link); wl_list_remove(&drag->icon_destroy.link);
wl_signal_emit(&drag->icon->events.map, drag->icon);
} }
free(drag); free(drag);
@ -676,8 +677,8 @@ static struct wlr_drag_icon *wlr_drag_icon_create(
icon->is_pointer = is_pointer; icon->is_pointer = is_pointer;
icon->touch_id = touch_id; icon->touch_id = touch_id;
icon->mapped = true; icon->mapped = true;
wl_list_insert(&client->seat->drag_icons, &icon->link);
wl_signal_init(&icon->events.map);
wl_signal_init(&icon->events.destroy); wl_signal_init(&icon->events.destroy);
wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy); wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
@ -689,6 +690,9 @@ static struct wlr_drag_icon *wlr_drag_icon_create(
wl_signal_add(&client->events.destroy, &icon->seat_client_destroy); wl_signal_add(&client->events.destroy, &icon->seat_client_destroy);
icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy; icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy;
wl_list_insert(&client->seat->drag_icons, &icon->link);
wl_signal_emit(&client->seat->events.new_drag_icon, icon);
return icon; return icon;
} }

@ -10,10 +10,9 @@
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_output.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <GLES2/gl2.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
#include <wlr/render/gles2.h>
#include <wlr/render.h> #include <wlr/render.h>
#include <wlr/util/region.h>
static void wl_output_send_to_resource(struct wl_resource *resource) { static void wl_output_send_to_resource(struct wl_resource *resource) {
assert(resource); assert(resource);
@ -183,11 +182,6 @@ void wlr_output_update_mode(struct wlr_output *output,
void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width, void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width,
int32_t height, int32_t refresh) { int32_t height, int32_t refresh) {
if (output->width == width && output->height == height &&
output->refresh == refresh) {
return;
}
output->width = width; output->width = width;
output->height = height; output->height = height;
wlr_output_update_matrix(output); wlr_output_update_matrix(output);
@ -266,15 +260,19 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
wl_list_init(&output->cursors); wl_list_init(&output->cursors);
wl_list_init(&output->wl_resources); wl_list_init(&output->wl_resources);
wl_signal_init(&output->events.frame); wl_signal_init(&output->events.frame);
wl_signal_init(&output->events.needs_swap);
wl_signal_init(&output->events.swap_buffers); wl_signal_init(&output->events.swap_buffers);
wl_signal_init(&output->events.enable); wl_signal_init(&output->events.enable);
wl_signal_init(&output->events.mode); wl_signal_init(&output->events.mode);
wl_signal_init(&output->events.scale); wl_signal_init(&output->events.scale);
wl_signal_init(&output->events.transform); wl_signal_init(&output->events.transform);
wl_signal_init(&output->events.destroy); wl_signal_init(&output->events.destroy);
pixman_region32_init(&output->damage);
output->display_destroy.notify = handle_display_destroy; output->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &output->display_destroy); wl_display_add_destroy_listener(display, &output->display_destroy);
output->frame_pending = true;
} }
void wlr_output_destroy(struct wlr_output *output) { void wlr_output_destroy(struct wlr_output *output) {
@ -286,6 +284,7 @@ void wlr_output_destroy(struct wlr_output *output) {
wlr_output_destroy_global(output); wlr_output_destroy_global(output);
wlr_output_set_fullscreen_surface(output, NULL); wlr_output_set_fullscreen_surface(output, NULL);
wl_signal_emit(&output->backend->events.output_remove, output);
wl_signal_emit(&output->events.destroy, output); wl_signal_emit(&output->events.destroy, output);
struct wlr_output_mode *mode, *tmp_mode; struct wlr_output_mode *mode, *tmp_mode;
@ -299,6 +298,8 @@ void wlr_output_destroy(struct wlr_output *output) {
wlr_output_cursor_destroy(cursor); wlr_output_cursor_destroy(cursor);
} }
pixman_region32_fini(&output->damage);
if (output->impl && output->impl->destroy) { if (output->impl && output->impl->destroy) {
output->impl->destroy(output); output->impl->destroy(output);
} else { } else {
@ -306,55 +307,93 @@ void wlr_output_destroy(struct wlr_output *output) {
} }
} }
void wlr_output_effective_resolution(struct wlr_output *output, void wlr_output_transformed_resolution(struct wlr_output *output,
int *width, int *height) { int *width, int *height) {
if (output->transform % 2 == 1) { if (output->transform % 2 == 0) {
*width = output->height;
*height = output->width;
} else {
*width = output->width; *width = output->width;
*height = output->height; *height = output->height;
} else {
*width = output->height;
*height = output->width;
} }
}
void wlr_output_effective_resolution(struct wlr_output *output,
int *width, int *height) {
wlr_output_transformed_resolution(output, width, height);
*width /= output->scale; *width /= output->scale;
*height /= output->scale; *height /= output->scale;
} }
void wlr_output_make_current(struct wlr_output *output) { bool wlr_output_make_current(struct wlr_output *output, int *buffer_age) {
output->impl->make_current(output); return output->impl->make_current(output, buffer_age);
} }
static void output_fullscreen_surface_render(struct wlr_output *output, static void output_scissor(struct wlr_output *output, pixman_box32_t *rect) {
struct wlr_surface *surface, const struct timespec *when) { struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend);
assert(renderer);
struct wlr_box box = {
.x = rect->x1,
.y = rect->y1,
.width = rect->x2 - rect->x1,
.height = rect->y2 - rect->y1,
};
int ow, oh;
wlr_output_transformed_resolution(output, &ow, &oh);
// Scissor is in renderer coordinates, ie. upside down
enum wl_output_transform transform = wlr_output_transform_compose(
wlr_output_transform_invert(output->transform),
WL_OUTPUT_TRANSFORM_FLIPPED_180);
wlr_box_transform(&box, transform, ow, oh, &box);
wlr_renderer_scissor(renderer, &box);
}
static void output_fullscreen_surface_get_box(struct wlr_output *output,
struct wlr_surface *surface, struct wlr_box *box) {
int width, height; int width, height;
wlr_output_effective_resolution(output, &width, &height); wlr_output_effective_resolution(output, &width, &height);
int x = (width - surface->current->width) / 2; int x = (width - surface->current->width) / 2;
int y = (height - surface->current->height) / 2; int y = (height - surface->current->height) / 2;
int render_x = x * output->scale; box->x = x * output->scale;
int render_y = y * output->scale; box->y = y * output->scale;
int render_width = surface->current->width * output->scale; box->width = surface->current->width * output->scale;
int render_height = surface->current->height * output->scale; box->height = surface->current->height * output->scale;
}
glViewport(0, 0, output->width, output->height); static void output_fullscreen_surface_render(struct wlr_output *output,
glClearColor(0, 0, 0, 0); struct wlr_surface *surface, const struct timespec *when,
glClear(GL_COLOR_BUFFER_BIT); pixman_region32_t *damage) {
struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend);
assert(renderer);
if (!wlr_surface_has_buffer(surface)) { if (!wlr_surface_has_buffer(surface)) {
wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0});
return; return;
} }
float translate[16]; struct wlr_box box;
wlr_matrix_translate(&translate, render_x, render_y, 0); output_fullscreen_surface_get_box(output, surface, &box);
float scale[16];
wlr_matrix_scale(&scale, render_width, render_height, 1);
float matrix[16]; float matrix[16];
wlr_matrix_mul(&translate, &scale, &matrix); enum wl_output_transform transform =
wlr_matrix_mul(&output->transform_matrix, &matrix, &matrix); wlr_output_transform_invert(surface->current->transform);
wlr_matrix_project_box(&matrix, &box, transform, 0,
&output->transform_matrix);
wlr_render_with_matrix(surface->renderer, surface->texture, &matrix); int nrects;
pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects);
for (int i = 0; i < nrects; ++i) {
output_scissor(output, &rects[i]);
wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0});
wlr_render_with_matrix(surface->renderer, surface->texture, &matrix);
}
wlr_renderer_scissor(renderer, NULL);
wlr_surface_send_frame_done(surface, when); wlr_surface_send_frame_done(surface, when);
} }
@ -376,64 +415,133 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor,
} }
static void output_cursor_render(struct wlr_output_cursor *cursor, static void output_cursor_render(struct wlr_output_cursor *cursor,
const struct timespec *when) { const struct timespec *when, pixman_region32_t *damage) {
struct wlr_renderer *renderer =
wlr_backend_get_renderer(cursor->output->backend);
assert(renderer);
struct wlr_texture *texture = cursor->texture; struct wlr_texture *texture = cursor->texture;
struct wlr_renderer *renderer = cursor->renderer;
if (cursor->surface != NULL) { if (cursor->surface != NULL) {
texture = cursor->surface->texture; texture = cursor->surface->texture;
renderer = cursor->surface->renderer;
} }
if (texture == NULL) {
if (texture == NULL || renderer == NULL) {
return; return;
} }
glViewport(0, 0, cursor->output->width, cursor->output->height); struct wlr_box box;
glEnable(GL_BLEND); output_cursor_get_box(cursor, &box);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
struct wlr_box cursor_box;
output_cursor_get_box(cursor, &cursor_box);
float translate[16];
wlr_matrix_translate(&translate, cursor_box.x, cursor_box.y, 0);
float scale[16]; pixman_region32_t surface_damage;
wlr_matrix_scale(&scale, cursor_box.width, cursor_box.height, 1); pixman_region32_init(&surface_damage);
pixman_region32_union_rect(&surface_damage, &surface_damage, box.x, box.y,
box.width, box.height);
pixman_region32_intersect(&surface_damage, &surface_damage, damage);
if (!pixman_region32_not_empty(&surface_damage)) {
goto surface_damage_finish;
}
float matrix[16]; float matrix[16];
wlr_matrix_mul(&translate, &scale, &matrix); wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
wlr_matrix_mul(&cursor->output->transform_matrix, &matrix, &matrix); &cursor->output->transform_matrix);
wlr_render_with_matrix(renderer, texture, &matrix); int nrects;
pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects);
for (int i = 0; i < nrects; ++i) {
output_scissor(cursor->output, &rects[i]);
wlr_render_with_matrix(renderer, texture, &matrix);
}
wlr_renderer_scissor(renderer, NULL);
if (cursor->surface != NULL) { if (cursor->surface != NULL) {
wlr_surface_send_frame_done(cursor->surface, when); wlr_surface_send_frame_done(cursor->surface, when);
} }
surface_damage_finish:
pixman_region32_fini(&surface_damage);
} }
void wlr_output_swap_buffers(struct wlr_output *output) { bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when,
wl_signal_emit(&output->events.swap_buffers, &output); pixman_region32_t *damage) {
if (output->frame_pending) {
wlr_log(L_ERROR, "Tried to swap buffers when a frame is pending");
return false;
}
if (output->idle_frame != NULL) {
wl_event_source_remove(output->idle_frame);
output->idle_frame = NULL;
}
struct timespec now; wl_signal_emit(&output->events.swap_buffers, damage);
clock_gettime(CLOCK_MONOTONIC, &now);
if (output->fullscreen_surface != NULL) { int width, height;
output_fullscreen_surface_render(output, output->fullscreen_surface, wlr_output_transformed_resolution(output, &width, &height);
&now);
pixman_region32_t render_damage;
pixman_region32_init(&render_damage);
pixman_region32_union_rect(&render_damage, &render_damage, 0, 0,
width, height);
if (damage != NULL) {
// Damage tracking supported
pixman_region32_intersect(&render_damage, &render_damage, damage);
}
if (when == NULL) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
when = &now;
} }
struct wlr_output_cursor *cursor; if (pixman_region32_not_empty(&render_damage)) {
wl_list_for_each(cursor, &output->cursors, link) { if (output->fullscreen_surface != NULL) {
if (!cursor->enabled || !cursor->visible || output_fullscreen_surface_render(output, output->fullscreen_surface,
output->hardware_cursor == cursor) { when, &render_damage);
continue; }
struct wlr_output_cursor *cursor;
wl_list_for_each(cursor, &output->cursors, link) {
if (!cursor->enabled || !cursor->visible ||
output->hardware_cursor == cursor) {
continue;
}
output_cursor_render(cursor, when, &render_damage);
} }
output_cursor_render(cursor, &now);
} }
output->impl->swap_buffers(output); // TODO: provide `damage` (not `render_damage`) to backend
if (!output->impl->swap_buffers(output)) {
return false;
}
output->frame_pending = true;
output->needs_swap = false; output->needs_swap = false;
pixman_region32_clear(&output->damage);
pixman_region32_fini(&render_damage);
return true;
}
void wlr_output_send_frame(struct wlr_output *output) {
output->frame_pending = false;
wl_signal_emit(&output->events.frame, output);
}
static void schedule_frame_handle_idle_timer(void *data) {
struct wlr_output *output = data;
output->idle_frame = NULL;
if (!output->frame_pending) {
wlr_output_send_frame(output);
}
}
void wlr_output_schedule_frame(struct wlr_output *output) {
if (output->frame_pending || output->idle_frame != NULL) {
return;
}
// TODO: ask the backend to send a frame event when appropriate instead
struct wl_event_loop *ev = wl_display_get_event_loop(output->display);
output->idle_frame =
wl_event_loop_add_idle(ev, schedule_frame_handle_idle_timer, output);
} }
void wlr_output_set_gamma(struct wlr_output *output, void wlr_output_set_gamma(struct wlr_output *output,
@ -450,12 +558,26 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) {
return output->impl->get_gamma_size(output); return output->impl->get_gamma_size(output);
} }
void wlr_output_update_needs_swap(struct wlr_output *output) {
output->needs_swap = true;
wl_signal_emit(&output->events.needs_swap, output);
}
static void output_damage_whole(struct wlr_output *output) {
int width, height;
wlr_output_transformed_resolution(output, &width, &height);
pixman_region32_union_rect(&output->damage, &output->damage, 0, 0,
width, height);
wlr_output_update_needs_swap(output);
}
static void output_fullscreen_surface_reset(struct wlr_output *output) { static void output_fullscreen_surface_reset(struct wlr_output *output) {
if (output->fullscreen_surface != NULL) { if (output->fullscreen_surface != NULL) {
wl_list_remove(&output->fullscreen_surface_commit.link); wl_list_remove(&output->fullscreen_surface_commit.link);
wl_list_remove(&output->fullscreen_surface_destroy.link); wl_list_remove(&output->fullscreen_surface_destroy.link);
output->fullscreen_surface = NULL; output->fullscreen_surface = NULL;
output->needs_swap = true; output_damage_whole(output);
} }
} }
@ -463,7 +585,28 @@ static void output_fullscreen_surface_handle_commit(
struct wl_listener *listener, void *data) { struct wl_listener *listener, void *data) {
struct wlr_output *output = wl_container_of(listener, output, struct wlr_output *output = wl_container_of(listener, output,
fullscreen_surface_commit); fullscreen_surface_commit);
output->needs_swap = true; struct wlr_surface *surface = output->fullscreen_surface;
if (output->fullscreen_width != surface->current->width ||
output->fullscreen_height != surface->current->height) {
output->fullscreen_width = surface->current->width;
output->fullscreen_height = surface->current->height;
output_damage_whole(output);
return;
}
struct wlr_box box;
output_fullscreen_surface_get_box(output, surface, &box);
pixman_region32_t damage;
pixman_region32_init(&damage);
pixman_region32_copy(&damage, &surface->current->surface_damage);
wlr_region_scale(&damage, &damage, output->scale);
pixman_region32_translate(&damage, box.x, box.y);
pixman_region32_union(&output->damage, &output->damage, &damage);
pixman_region32_fini(&damage);
wlr_output_update_needs_swap(output);
} }
static void output_fullscreen_surface_handle_destroy( static void output_fullscreen_surface_handle_destroy(
@ -484,7 +627,7 @@ void wlr_output_set_fullscreen_surface(struct wlr_output *output,
output_fullscreen_surface_reset(output); output_fullscreen_surface_reset(output);
output->fullscreen_surface = surface; output->fullscreen_surface = surface;
output->needs_swap = true; output_damage_whole(output);
if (surface == NULL) { if (surface == NULL) {
return; return;
@ -500,9 +643,17 @@ void wlr_output_set_fullscreen_surface(struct wlr_output *output,
} }
static void output_cursor_damage_whole(struct wlr_output_cursor *cursor) {
struct wlr_box box;
output_cursor_get_box(cursor, &box);
pixman_region32_union_rect(&cursor->output->damage, &cursor->output->damage,
box.x, box.y, box.width, box.height);
wlr_output_update_needs_swap(cursor->output);
}
static void output_cursor_reset(struct wlr_output_cursor *cursor) { static void output_cursor_reset(struct wlr_output_cursor *cursor) {
if (cursor->output->hardware_cursor != cursor) { if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true; output_cursor_damage_whole(cursor);
} }
if (cursor->surface != NULL) { if (cursor->surface != NULL) {
wl_list_remove(&cursor->surface_commit.link); wl_list_remove(&cursor->surface_commit.link);
@ -514,6 +665,10 @@ static void output_cursor_reset(struct wlr_output_cursor *cursor) {
bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height,
int32_t hotspot_x, int32_t hotspot_y) { int32_t hotspot_x, int32_t hotspot_y) {
struct wlr_renderer *renderer =
wlr_backend_get_renderer(cursor->output->backend);
assert(renderer);
output_cursor_reset(cursor); output_cursor_reset(cursor);
cursor->width = width; cursor->width = width;
@ -536,22 +691,15 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
} }
wlr_log(L_DEBUG, "Falling back to software cursor"); wlr_log(L_DEBUG, "Falling back to software cursor");
cursor->output->needs_swap = true; output_cursor_damage_whole(cursor);
cursor->enabled = pixels != NULL; cursor->enabled = pixels != NULL;
if (!cursor->enabled) { if (!cursor->enabled) {
return true; return true;
} }
if (cursor->renderer == NULL) {
cursor->renderer = wlr_gles2_renderer_create(cursor->output->backend);
if (cursor->renderer == NULL) {
return false;
}
}
if (cursor->texture == NULL) { if (cursor->texture == NULL) {
cursor->texture = wlr_render_texture_create(cursor->renderer); cursor->texture = wlr_render_texture_create(renderer);
if (cursor->texture == NULL) { if (cursor->texture == NULL) {
return false; return false;
} }
@ -564,10 +712,8 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
static void output_cursor_update_visible(struct wlr_output_cursor *cursor) { static void output_cursor_update_visible(struct wlr_output_cursor *cursor) {
struct wlr_box output_box; struct wlr_box output_box;
output_box.x = output_box.y = 0; output_box.x = output_box.y = 0;
wlr_output_effective_resolution(cursor->output, &output_box.width, wlr_output_transformed_resolution(cursor->output, &output_box.width,
&output_box.height); &output_box.height);
output_box.width *= cursor->output->scale;
output_box.height *= cursor->output->scale;
struct wlr_box cursor_box; struct wlr_box cursor_box;
output_cursor_get_box(cursor, &cursor_box); output_cursor_get_box(cursor, &cursor_box);
@ -589,13 +735,17 @@ static void output_cursor_update_visible(struct wlr_output_cursor *cursor) {
} }
static void output_cursor_commit(struct wlr_output_cursor *cursor) { static void output_cursor_commit(struct wlr_output_cursor *cursor) {
if (cursor->output->hardware_cursor != cursor) {
output_cursor_damage_whole(cursor);
}
// Some clients commit a cursor surface with a NULL buffer to hide it. // Some clients commit a cursor surface with a NULL buffer to hide it.
cursor->enabled = wlr_surface_has_buffer(cursor->surface); cursor->enabled = wlr_surface_has_buffer(cursor->surface);
cursor->width = cursor->surface->current->width * cursor->output->scale; cursor->width = cursor->surface->current->width * cursor->output->scale;
cursor->height = cursor->surface->current->height * cursor->output->scale; cursor->height = cursor->surface->current->height * cursor->output->scale;
if (cursor->output->hardware_cursor != cursor) { if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true; output_cursor_damage_whole(cursor);
} else { } else {
// TODO: upload pixels // TODO: upload pixels
@ -625,14 +775,23 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
return; return;
} }
cursor->hotspot_x = hotspot_x * cursor->output->scale; hotspot_x *= cursor->output->scale;
cursor->hotspot_y = hotspot_y * cursor->output->scale; hotspot_y *= cursor->output->scale;
if (surface && surface == cursor->surface) { if (surface && surface == cursor->surface) {
// Only update the hotspot: surface hasn't changed
if (cursor->output->hardware_cursor != cursor) {
output_cursor_damage_whole(cursor);
}
cursor->hotspot_x = hotspot_x;
cursor->hotspot_y = hotspot_y;
if (cursor->output->hardware_cursor != cursor) {
output_cursor_damage_whole(cursor);
}
if (cursor->output->hardware_cursor == cursor && if (cursor->output->hardware_cursor == cursor &&
cursor->output->impl->set_cursor) { cursor->output->impl->set_cursor) {
// If the surface hasn't changed and it's an hardware cursor, only
// update the hotspot
cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0,
hotspot_x, hotspot_y, false); hotspot_x, hotspot_y, false);
} }
@ -651,6 +810,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
} }
cursor->surface = surface; cursor->surface = surface;
cursor->hotspot_x = hotspot_x;
cursor->hotspot_y = hotspot_y;
if (surface != NULL) { if (surface != NULL) {
wl_signal_add(&surface->events.commit, &cursor->surface_commit); wl_signal_add(&surface->events.commit, &cursor->surface_commit);
@ -670,6 +831,14 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
double x, double y) { double x, double y) {
if (cursor->x == x && cursor->y == y) {
return true;
}
if (cursor->output->hardware_cursor != cursor) {
output_cursor_damage_whole(cursor);
}
x *= cursor->output->scale; x *= cursor->output->scale;
y *= cursor->output->scale; y *= cursor->output->scale;
cursor->x = x; cursor->x = x;
@ -677,7 +846,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
output_cursor_update_visible(cursor); output_cursor_update_visible(cursor);
if (cursor->output->hardware_cursor != cursor) { if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true; output_cursor_damage_whole(cursor);
return true; return true;
} }
@ -720,9 +889,6 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) {
if (cursor->texture != NULL) { if (cursor->texture != NULL) {
wlr_texture_destroy(cursor->texture); wlr_texture_destroy(cursor->texture);
} }
if (cursor->renderer != NULL) {
wlr_renderer_destroy(cursor->renderer);
}
wl_list_remove(&cursor->link); wl_list_remove(&cursor->link);
free(cursor); free(cursor);
} }

@ -41,8 +41,8 @@ static void output_handle_frame(struct wl_listener *listener, void *_data) {
int32_t width = wl_shm_buffer_get_width(shm_buffer); int32_t width = wl_shm_buffer_get_width(shm_buffer);
int32_t height = wl_shm_buffer_get_height(shm_buffer); int32_t height = wl_shm_buffer_get_height(shm_buffer);
int32_t stride = wl_shm_buffer_get_stride(shm_buffer); int32_t stride = wl_shm_buffer_get_stride(shm_buffer);
void *data = wl_shm_buffer_get_data(shm_buffer);
wl_shm_buffer_begin_access(shm_buffer); wl_shm_buffer_begin_access(shm_buffer);
void *data = wl_shm_buffer_get_data(shm_buffer);
bool ok = wlr_renderer_read_pixels(renderer, format, stride, width, height, bool ok = wlr_renderer_read_pixels(renderer, format, stride, width, height,
0, 0, 0, 0, data); 0, 0, 0, 0, data);
wl_shm_buffer_end_access(shm_buffer); wl_shm_buffer_end_access(shm_buffer);
@ -127,6 +127,10 @@ static void screenshooter_shoot(struct wl_client *client,
state->screenshot = screenshot; state->screenshot = screenshot;
state->frame_listener.notify = output_handle_frame; state->frame_listener.notify = output_handle_frame;
wl_signal_add(&output->events.swap_buffers, &state->frame_listener); wl_signal_add(&output->events.swap_buffers, &state->frame_listener);
// Schedule a buffer swap
output->needs_swap = true;
wlr_output_schedule_frame(output);
} }
static struct orbital_screenshooter_interface screenshooter_impl = { static struct orbital_screenshooter_interface screenshooter_impl = {

@ -454,7 +454,10 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wl_list_init(&wlr_seat->clients); wl_list_init(&wlr_seat->clients);
wl_list_init(&wlr_seat->drag_icons); wl_list_init(&wlr_seat->drag_icons);
wl_signal_init(&wlr_seat->events.new_drag_icon);
wl_signal_init(&wlr_seat->events.request_set_cursor); wl_signal_init(&wlr_seat->events.request_set_cursor);
wl_signal_init(&wlr_seat->events.selection); wl_signal_init(&wlr_seat->events.selection);
wl_signal_init(&wlr_seat->events.primary_selection); wl_signal_init(&wlr_seat->events.primary_selection);

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/util/region.h>
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/render/egl.h> #include <wlr/render/egl.h>
@ -133,11 +134,14 @@ static void surface_set_input_region(struct wl_client *client,
} }
} }
static void wlr_surface_update_size(struct wlr_surface *surface, struct wlr_surface_state *state) { static bool wlr_surface_update_size(struct wlr_surface *surface,
struct wlr_surface_state *state) {
if (!state->buffer) { if (!state->buffer) {
pixman_region32_union_rect(&state->surface_damage,
&state->surface_damage, 0, 0, state->width, state->height);
state->height = 0; state->height = 0;
state->width = 0; state->width = 0;
return; return true;
} }
int scale = state->scale; int scale = state->scale;
@ -146,16 +150,16 @@ static void wlr_surface_update_size(struct wlr_surface *surface, struct wlr_surf
wlr_texture_get_buffer_size(surface->texture, state->buffer, wlr_texture_get_buffer_size(surface->texture, state->buffer,
&state->buffer_width, &state->buffer_height); &state->buffer_width, &state->buffer_height);
int _width = state->buffer_width / scale; int width = state->buffer_width / scale;
int _height = state->buffer_height / scale; int height = state->buffer_height / scale;
if (transform == WL_OUTPUT_TRANSFORM_90 || if (transform == WL_OUTPUT_TRANSFORM_90 ||
transform == WL_OUTPUT_TRANSFORM_270 || transform == WL_OUTPUT_TRANSFORM_270 ||
transform == WL_OUTPUT_TRANSFORM_FLIPPED_90 || transform == WL_OUTPUT_TRANSFORM_FLIPPED_90 ||
transform == WL_OUTPUT_TRANSFORM_FLIPPED_270) { transform == WL_OUTPUT_TRANSFORM_FLIPPED_270) {
int tmp = _width; int tmp = width;
_width = _height; width = height;
_height = tmp; height = tmp;
} }
struct wlr_frame_callback *cb, *tmp; struct wlr_frame_callback *cb, *tmp;
@ -164,99 +168,34 @@ static void wlr_surface_update_size(struct wlr_surface *surface, struct wlr_surf
} }
wl_list_init(&state->frame_callback_list); wl_list_init(&state->frame_callback_list);
state->width = _width; bool update_damage = false;
state->height = _height; if (width != state->width || height != state->height) {
} // Damage the whole surface on resize
// This isn't in the spec, but Weston does it and QT expects it
static void wlr_surface_to_buffer_region(int scale, pixman_region32_union_rect(&state->surface_damage,
enum wl_output_transform transform, pixman_region32_t *surface_region, &state->surface_damage, 0, 0, state->width, state->height);
pixman_region32_t *buffer_region, pixman_region32_union_rect(&state->surface_damage,
int width, int height) { &state->surface_damage, 0, 0, width, height);
pixman_box32_t *src_rects, *dest_rects; update_damage = true;
int nrects, i;
src_rects = pixman_region32_rectangles(surface_region, &nrects);
dest_rects = malloc(nrects * sizeof(*dest_rects));
if (!dest_rects) {
return;
}
for (i = 0; i < nrects; i++) {
switch (transform) {
default:
case WL_OUTPUT_TRANSFORM_NORMAL:
dest_rects[i].x1 = src_rects[i].x1;
dest_rects[i].y1 = src_rects[i].y1;
dest_rects[i].x2 = src_rects[i].x2;
dest_rects[i].y2 = src_rects[i].y2;
break;
case WL_OUTPUT_TRANSFORM_90:
dest_rects[i].x1 = height - src_rects[i].y2;
dest_rects[i].y1 = src_rects[i].x1;
dest_rects[i].x2 = height - src_rects[i].y1;
dest_rects[i].y2 = src_rects[i].x2;
break;
case WL_OUTPUT_TRANSFORM_180:
dest_rects[i].x1 = width - src_rects[i].x2;
dest_rects[i].y1 = height - src_rects[i].y2;
dest_rects[i].x2 = width - src_rects[i].x1;
dest_rects[i].y2 = height - src_rects[i].y1;
break;
case WL_OUTPUT_TRANSFORM_270:
dest_rects[i].x1 = src_rects[i].y1;
dest_rects[i].y1 = width - src_rects[i].x2;
dest_rects[i].x2 = src_rects[i].y2;
dest_rects[i].y2 = width - src_rects[i].x1;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED:
dest_rects[i].x1 = width - src_rects[i].x2;
dest_rects[i].y1 = src_rects[i].y1;
dest_rects[i].x2 = width - src_rects[i].x1;
dest_rects[i].y2 = src_rects[i].y2;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
dest_rects[i].x1 = height - src_rects[i].y2;
dest_rects[i].y1 = width - src_rects[i].x2;
dest_rects[i].x2 = height - src_rects[i].y1;
dest_rects[i].y2 = width - src_rects[i].x1;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
dest_rects[i].x1 = src_rects[i].x1;
dest_rects[i].y1 = height - src_rects[i].y2;
dest_rects[i].x2 = src_rects[i].x2;
dest_rects[i].y2 = height - src_rects[i].y1;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
dest_rects[i].x1 = src_rects[i].y1;
dest_rects[i].y1 = src_rects[i].x1;
dest_rects[i].x2 = src_rects[i].y2;
dest_rects[i].y2 = src_rects[i].x2;
break;
}
} }
if (scale != 1) { state->width = width;
for (i = 0; i < nrects; i++) { state->height = height;
dest_rects[i].x1 *= scale;
dest_rects[i].x2 *= scale;
dest_rects[i].y1 *= scale;
dest_rects[i].y2 *= scale;
}
}
pixman_region32_fini(buffer_region); return update_damage;
pixman_region32_init_rects(buffer_region, dest_rects, nrects);
free(dest_rects);
} }
/** /**
* Append pending state to current state and clear pending state. * Append pending state to current state and clear pending state.
*/ */
static void wlr_surface_move_state(struct wlr_surface *surface, struct wlr_surface_state *next, static void wlr_surface_move_state(struct wlr_surface *surface,
struct wlr_surface_state *state) { struct wlr_surface_state *next, struct wlr_surface_state *state) {
bool update_damage = false; bool update_damage = false;
bool update_size = false; bool update_size = false;
int oldw = state->width;
int oldh = state->height;
if ((next->invalid & WLR_SURFACE_INVALID_SCALE)) { if ((next->invalid & WLR_SURFACE_INVALID_SCALE)) {
state->scale = next->scale; state->scale = next->scale;
update_size = true; update_size = true;
@ -274,40 +213,50 @@ static void wlr_surface_move_state(struct wlr_surface *surface, struct wlr_surfa
update_size = true; update_size = true;
} }
if (update_size) { if (update_size) {
wlr_surface_update_size(surface, state); update_damage = wlr_surface_update_size(surface, state);
} }
if ((next->invalid & WLR_SURFACE_INVALID_SURFACE_DAMAGE)) { if ((next->invalid & WLR_SURFACE_INVALID_SURFACE_DAMAGE)) {
pixman_region32_union(&state->surface_damage, pixman_region32_intersect_rect(&next->surface_damage,
&state->surface_damage, &next->surface_damage, 0, 0, state->width, state->height);
pixman_region32_union(&state->surface_damage, &state->surface_damage,
&next->surface_damage); &next->surface_damage);
pixman_region32_intersect_rect(&state->surface_damage,
&state->surface_damage, 0, 0, state->width,
state->height);
pixman_region32_clear(&next->surface_damage); pixman_region32_clear(&next->surface_damage);
update_damage = true; update_damage = true;
} }
if ((next->invalid & WLR_SURFACE_INVALID_BUFFER_DAMAGE)) { if ((next->invalid & WLR_SURFACE_INVALID_BUFFER_DAMAGE)) {
pixman_region32_union(&state->buffer_damage, pixman_region32_intersect_rect(&next->buffer_damage,
&state->buffer_damage, &next->buffer_damage, 0, 0, state->buffer_width,
state->buffer_height);
pixman_region32_union(&state->buffer_damage, &state->buffer_damage,
&next->buffer_damage); &next->buffer_damage);
pixman_region32_clear(&next->buffer_damage); pixman_region32_clear(&next->buffer_damage);
update_damage = true; update_damage = true;
} }
if (update_damage) { if (update_damage) {
pixman_region32_t buffer_damage; pixman_region32_t buffer_damage, surface_damage;
pixman_region32_init(&buffer_damage); pixman_region32_init(&buffer_damage);
wlr_surface_to_buffer_region(state->scale, state->transform, pixman_region32_init(&surface_damage);
&state->surface_damage, &buffer_damage, state->width,
state->height); // Surface to buffer damage
pixman_region32_union(&state->buffer_damage, pixman_region32_copy(&buffer_damage, &state->surface_damage);
&state->buffer_damage, &buffer_damage); wlr_region_transform(&buffer_damage, &buffer_damage,
pixman_region32_fini(&buffer_damage); wlr_output_transform_invert(state->transform),
state->width, state->height);
pixman_region32_intersect_rect(&state->buffer_damage, wlr_region_scale(&buffer_damage, &buffer_damage, state->scale);
&state->buffer_damage, 0, 0,
// Buffer to surface damage
pixman_region32_copy(&surface_damage, &state->buffer_damage);
wlr_region_transform(&surface_damage, &surface_damage, state->transform,
state->buffer_width, state->buffer_height); state->buffer_width, state->buffer_height);
wlr_region_scale(&surface_damage, &surface_damage, 1.0f/state->scale);
pixman_region32_union(&state->buffer_damage, &state->buffer_damage,
&buffer_damage);
pixman_region32_union(&state->surface_damage, &state->surface_damage,
&surface_damage);
pixman_region32_fini(&buffer_damage);
pixman_region32_fini(&surface_damage);
} }
if ((next->invalid & WLR_SURFACE_INVALID_OPAQUE_REGION)) { if ((next->invalid & WLR_SURFACE_INVALID_OPAQUE_REGION)) {
// TODO: process buffer // TODO: process buffer
@ -318,13 +267,25 @@ static void wlr_surface_move_state(struct wlr_surface *surface, struct wlr_surfa
pixman_region32_copy(&state->input, &next->input); pixman_region32_copy(&state->input, &next->input);
} }
if ((next->invalid & WLR_SURFACE_INVALID_SUBSURFACE_POSITION)) { if ((next->invalid & WLR_SURFACE_INVALID_SUBSURFACE_POSITION)) {
// Subsurface has moved
int dx = state->subsurface_position.x - next->subsurface_position.x;
int dy = state->subsurface_position.y - next->subsurface_position.y;
state->subsurface_position.x = next->subsurface_position.x; state->subsurface_position.x = next->subsurface_position.x;
state->subsurface_position.y = next->subsurface_position.y; state->subsurface_position.y = next->subsurface_position.y;
next->subsurface_position.x = 0; next->subsurface_position.x = 0;
next->subsurface_position.y = 0; next->subsurface_position.y = 0;
if (dx != 0 || dy != 0) {
pixman_region32_union_rect(&state->surface_damage,
&state->surface_damage, dx, dy, oldw, oldh);
pixman_region32_union_rect(&state->surface_damage,
&state->surface_damage, 0, 0, state->width, state->height);
}
} }
if ((next->invalid & WLR_SURFACE_INVALID_FRAME_CALLBACK_LIST)) { if ((next->invalid & WLR_SURFACE_INVALID_FRAME_CALLBACK_LIST)) {
wl_list_insert_list(&state->frame_callback_list, &next->frame_callback_list); wl_list_insert_list(&state->frame_callback_list,
&next->frame_callback_list);
wl_list_init(&next->frame_callback_list); wl_list_init(&next->frame_callback_list);
} }
@ -351,7 +312,7 @@ static void wlr_surface_damage_subsurfaces(struct wlr_subsurface *subsurface) {
} }
} }
static void wlr_surface_flush_damage(struct wlr_surface *surface, static void wlr_surface_apply_damage(struct wlr_surface *surface,
bool reupload_buffer) { bool reupload_buffer) {
if (!surface->current->buffer) { if (!surface->current->buffer) {
return; return;
@ -372,10 +333,12 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface,
if (reupload_buffer) { if (reupload_buffer) {
wlr_texture_upload_shm(surface->texture, format, buffer); wlr_texture_upload_shm(surface->texture, format, buffer);
} else { } else {
pixman_region32_t damage = surface->current->buffer_damage; pixman_region32_t damage;
if (!pixman_region32_not_empty(&damage)) { pixman_region32_init(&damage);
goto release; pixman_region32_copy(&damage, &surface->current->buffer_damage);
} pixman_region32_intersect_rect(&damage, &damage, 0, 0,
surface->current->buffer_width, surface->current->buffer_height);
int n; int n;
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n); pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n);
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
@ -388,12 +351,11 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface,
break; break;
} }
} }
pixman_region32_fini(&damage);
} }
release: release:
pixman_region32_clear(&surface->current->surface_damage);
pixman_region32_clear(&surface->current->buffer_damage);
wlr_surface_state_release_buffer(surface->current); wlr_surface_state_release_buffer(surface->current);
} }
@ -413,12 +375,12 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) {
bool reupload_buffer = oldw != surface->current->buffer_width || bool reupload_buffer = oldw != surface->current->buffer_width ||
oldh != surface->current->buffer_height; oldh != surface->current->buffer_height;
wlr_surface_flush_damage(surface, reupload_buffer); wlr_surface_apply_damage(surface, reupload_buffer);
// commit subsurface order // commit subsurface order
struct wlr_subsurface *subsurface; struct wlr_subsurface *subsurface;
wl_list_for_each_reverse(subsurface, &surface->subsurface_pending_list, wl_list_for_each_reverse(subsurface, &surface->subsurface_pending_list,
parent_pending_link) { parent_pending_link) {
wl_list_remove(&subsurface->parent_link); wl_list_remove(&subsurface->parent_link);
wl_list_insert(&surface->subsurface_list, &subsurface->parent_link); wl_list_insert(&surface->subsurface_list, &subsurface->parent_link);
@ -434,6 +396,9 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) {
// TODO: add the invalid bitfield to this callback // TODO: add the invalid bitfield to this callback
wl_signal_emit(&surface->events.commit, surface); wl_signal_emit(&surface->events.commit, surface);
pixman_region32_clear(&surface->current->surface_damage);
pixman_region32_clear(&surface->current->buffer_damage);
} }
static bool wlr_subsurface_is_synchronized(struct wlr_subsurface *subsurface) { static bool wlr_subsurface_is_synchronized(struct wlr_subsurface *subsurface) {
@ -459,7 +424,6 @@ static void wlr_subsurface_parent_commit(struct wlr_subsurface *subsurface,
bool synchronized) { bool synchronized) {
struct wlr_surface *surface = subsurface->surface; struct wlr_surface *surface = subsurface->surface;
if (synchronized || subsurface->synchronized) { if (synchronized || subsurface->synchronized) {
if (subsurface->has_cache) { if (subsurface->has_cache) {
wlr_surface_move_state(surface, subsurface->cached, surface->pending); wlr_surface_move_state(surface, subsurface->cached, surface->pending);
wlr_surface_commit_pending(surface); wlr_surface_commit_pending(surface);
@ -595,6 +559,8 @@ static void wlr_surface_state_destroy(struct wlr_surface_state *state) {
} }
void wlr_subsurface_destroy(struct wlr_subsurface *subsurface) { void wlr_subsurface_destroy(struct wlr_subsurface *subsurface) {
wl_signal_emit(&subsurface->events.destroy, subsurface);
wlr_surface_state_destroy(subsurface->cached); wlr_surface_state_destroy(subsurface->cached);
if (subsurface->parent) { if (subsurface->parent) {
@ -642,6 +608,7 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res,
wl_signal_init(&surface->events.commit); wl_signal_init(&surface->events.commit);
wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.new_subsurface);
wl_list_init(&surface->subsurface_list); wl_list_init(&surface->subsurface_list);
wl_list_init(&surface->subsurface_pending_list); wl_list_init(&surface->subsurface_pending_list);
wl_resource_set_implementation(res, &surface_interface, wl_resource_set_implementation(res, &surface_interface,
@ -732,10 +699,6 @@ static void subsurface_place_above(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *sibling_resource) { struct wl_resource *resource, struct wl_resource *sibling_resource) {
struct wlr_subsurface *subsurface = wl_resource_get_user_data(resource); struct wlr_subsurface *subsurface = wl_resource_get_user_data(resource);
if (!subsurface) {
return;
}
struct wlr_surface *sibling_surface = struct wlr_surface *sibling_surface =
wl_resource_get_user_data(sibling_resource); wl_resource_get_user_data(sibling_resource);
struct wlr_subsurface *sibling = struct wlr_subsurface *sibling =
@ -841,6 +804,7 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
} }
subsurface->synchronized = true; subsurface->synchronized = true;
subsurface->surface = surface; subsurface->surface = surface;
wl_signal_init(&subsurface->events.destroy);
// link parent // link parent
subsurface->parent = parent; subsurface->parent = parent;
@ -866,6 +830,8 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
subsurface_resource_destroy); subsurface_resource_destroy);
surface->subsurface = subsurface; surface->subsurface = subsurface;
wl_signal_emit(&parent->events.new_subsurface, subsurface);
} }

@ -221,6 +221,7 @@ static void shell_surface_popup_set_parent(struct wlr_wl_shell_surface *surface,
if (parent) { if (parent) {
wl_list_remove(&surface->popup_link); wl_list_remove(&surface->popup_link);
wl_list_insert(&parent->popups, &surface->popup_link); wl_list_insert(&parent->popups, &surface->popup_link);
wl_signal_emit(&parent->events.new_popup, surface);
} }
} }
@ -519,6 +520,7 @@ static void shell_protocol_get_shell_surface(struct wl_client *client,
wl_signal_init(&wl_surface->events.destroy); wl_signal_init(&wl_surface->events.destroy);
wl_signal_init(&wl_surface->events.ping_timeout); wl_signal_init(&wl_surface->events.ping_timeout);
wl_signal_init(&wl_surface->events.new_popup);
wl_signal_init(&wl_surface->events.request_move); wl_signal_init(&wl_surface->events.request_move);
wl_signal_init(&wl_surface->events.request_resize); wl_signal_init(&wl_surface->events.request_resize);
wl_signal_init(&wl_surface->events.request_fullscreen); wl_signal_init(&wl_surface->events.request_fullscreen);

@ -206,7 +206,7 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) {
} }
} }
wl_list_remove(&surface->popup_link); wl_list_remove(&surface->popup_state->link);
free(surface->popup_state); free(surface->popup_state);
} }
@ -505,12 +505,13 @@ static void xdg_surface_get_popup(struct wl_client *client,
surface->popup_state->parent = parent; surface->popup_state->parent = parent;
surface->popup_state->geometry = surface->popup_state->geometry =
xdg_positioner_get_geometry(positioner, surface, parent); xdg_positioner_get_geometry(positioner, surface, parent);
wl_list_insert(&surface->popup_state->parent->popups, wl_list_insert(&parent->popups, &surface->popup_state->link);
&surface->popup_link);
wl_resource_set_implementation(surface->popup_state->resource, wl_resource_set_implementation(surface->popup_state->resource,
&zxdg_popup_v6_implementation, surface, &zxdg_popup_v6_implementation, surface,
xdg_popup_resource_destroy); xdg_popup_resource_destroy);
wl_signal_emit(&parent->events.new_popup, surface->popup_state);
} }
@ -1187,6 +1188,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
wl_signal_init(&surface->events.request_show_window_menu); wl_signal_init(&surface->events.request_show_window_menu);
wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.ping_timeout);
wl_signal_init(&surface->events.new_popup);
wl_signal_add(&surface->surface->events.destroy, wl_signal_add(&surface->surface->events.destroy,
&surface->surface_destroy_listener); &surface->surface_destroy_listener);
@ -1404,14 +1406,16 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
// XXX: I think this is so complicated because we're mixing geometry // XXX: I think this is so complicated because we're mixing geometry
// coordinates with surface coordinates. Input handling should only deal // coordinates with surface coordinates. Input handling should only deal
// with surface coordinates. // with surface coordinates.
struct wlr_xdg_surface_v6 *popup; struct wlr_xdg_popup_v6 *popup_state;
wl_list_for_each(popup, &surface->popups, popup_link) { wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface_v6 *popup = popup_state->base;
double _popup_sx = double _popup_sx =
surface->geometry->x + popup->popup_state->geometry.x; surface->geometry->x + popup_state->geometry.x;
double _popup_sy = double _popup_sy =
surface->geometry->y + popup->popup_state->geometry.y; surface->geometry->y + popup_state->geometry.y;
int popup_width = popup->popup_state->geometry.width; int popup_width = popup_state->geometry.width;
int popup_height = popup->popup_state->geometry.height; int popup_height = popup_state->geometry.height;
struct wlr_xdg_surface_v6 *_popup = struct wlr_xdg_surface_v6 *_popup =
wlr_xdg_surface_v6_popup_at(popup, wlr_xdg_surface_v6_popup_at(popup,

@ -3,6 +3,8 @@ lib_wlr_util = static_library(
files( files(
'log.c', 'log.c',
'os-compatibility.c', 'os-compatibility.c',
'region.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [wayland_server, pixman],
) )

@ -0,0 +1,130 @@
#include <stdlib.h>
#include <math.h>
#include <wlr/util/region.h>
void wlr_region_scale(pixman_region32_t *dst, pixman_region32_t *src,
float scale) {
if (scale == 1) {
pixman_region32_copy(dst, src);
return;
}
int nrects;
pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects);
pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t));
if (dst_rects == NULL) {
return;
}
for (int i = 0; i < nrects; ++i) {
dst_rects[i].x1 = floor(src_rects[i].x1 * scale);
dst_rects[i].x2 = ceil(src_rects[i].x2 * scale);
dst_rects[i].y1 = floor(src_rects[i].y1 * scale);
dst_rects[i].y2 = ceil(src_rects[i].y2 * scale);
}
pixman_region32_fini(dst);
pixman_region32_init_rects(dst, dst_rects, nrects);
free(dst_rects);
}
void wlr_region_transform(pixman_region32_t *dst, pixman_region32_t *src,
enum wl_output_transform transform, int width, int height) {
if (transform == WL_OUTPUT_TRANSFORM_NORMAL) {
pixman_region32_copy(dst, src);
return;
}
int nrects;
pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects);
pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t));
if (dst_rects == NULL) {
return;
}
for (int i = 0; i < nrects; ++i) {
switch (transform) {
case WL_OUTPUT_TRANSFORM_NORMAL:
dst_rects[i].x1 = src_rects[i].x1;
dst_rects[i].y1 = src_rects[i].y1;
dst_rects[i].x2 = src_rects[i].x2;
dst_rects[i].y2 = src_rects[i].y2;
break;
case WL_OUTPUT_TRANSFORM_90:
dst_rects[i].x1 = src_rects[i].y1;
dst_rects[i].y1 = width - src_rects[i].x2;
dst_rects[i].x2 = src_rects[i].y2;
dst_rects[i].y2 = width - src_rects[i].x1;
break;
case WL_OUTPUT_TRANSFORM_180:
dst_rects[i].x1 = width - src_rects[i].x2;
dst_rects[i].y1 = height - src_rects[i].y2;
dst_rects[i].x2 = width - src_rects[i].x1;
dst_rects[i].y2 = height - src_rects[i].y1;
break;
case WL_OUTPUT_TRANSFORM_270:
dst_rects[i].x1 = height - src_rects[i].y2;
dst_rects[i].y1 = src_rects[i].x1;
dst_rects[i].x2 = height - src_rects[i].y1;
dst_rects[i].y2 = src_rects[i].x2;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED:
dst_rects[i].x1 = width - src_rects[i].x2;
dst_rects[i].y1 = src_rects[i].y1;
dst_rects[i].x2 = width - src_rects[i].x1;
dst_rects[i].y2 = src_rects[i].y2;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
dst_rects[i].x1 = height - src_rects[i].y2;
dst_rects[i].y1 = width - src_rects[i].x2;
dst_rects[i].x2 = height - src_rects[i].y1;
dst_rects[i].y2 = width - src_rects[i].x1;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
dst_rects[i].x1 = src_rects[i].x1;
dst_rects[i].y1 = height - src_rects[i].y2;
dst_rects[i].x2 = src_rects[i].x2;
dst_rects[i].y2 = height - src_rects[i].y1;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
dst_rects[i].x1 = src_rects[i].y1;
dst_rects[i].y1 = src_rects[i].x1;
dst_rects[i].x2 = src_rects[i].y2;
dst_rects[i].y2 = src_rects[i].x2;
break;
}
}
pixman_region32_fini(dst);
pixman_region32_init_rects(dst, dst_rects, nrects);
free(dst_rects);
}
void wlr_region_expand(pixman_region32_t *dst, pixman_region32_t *src,
int distance) {
if (distance == 0) {
pixman_region32_copy(dst, src);
return;
}
int nrects;
pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects);
pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t));
if (dst_rects == NULL) {
return;
}
for (int i = 0; i < nrects; ++i) {
dst_rects[i].x1 = src_rects[i].x1 - distance;
dst_rects[i].x2 = src_rects[i].x2 + distance;
dst_rects[i].y1 = src_rects[i].y1 - distance;
dst_rects[i].y2 = src_rects[i].y2 + distance;
}
pixman_region32_fini(dst);
pixman_region32_init_rects(dst, dst_rects, nrects);
free(dst_rects);
}

@ -24,7 +24,6 @@
*/ */
#define _XOPEN_SOURCE 500 #define _XOPEN_SOURCE 500
#include <wlr/render.h>
#include <wlr/xcursor.h> #include <wlr/xcursor.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <stdio.h> #include <stdio.h>

@ -315,7 +315,7 @@ static void read_surface_parent(struct wlr_xwm *xwm,
wl_list_init(&xsurface->parent_link); wl_list_init(&xsurface->parent_link);
} }
wlr_log(L_DEBUG, "XCB_ATOM_WM_TRANSIENT_FOR: %p", xid); wlr_log(L_DEBUG, "XCB_ATOM_WM_TRANSIENT_FOR: %p", xsurface->parent);
wl_signal_emit(&xsurface->events.set_parent, xsurface); wl_signal_emit(&xsurface->events.set_parent, xsurface);
} }
@ -1407,7 +1407,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
xwm_selection_init(xwm); xwm_selection_init(xwm);
xwm->compositor_surface_create.notify = handle_compositor_surface_create; xwm->compositor_surface_create.notify = handle_compositor_surface_create;
wl_signal_add(&wlr_xwayland->compositor->events.create_surface, wl_signal_add(&wlr_xwayland->compositor->events.new_surface,
&xwm->compositor_surface_create); &xwm->compositor_surface_create);
xwm_create_wm_window(xwm); xwm_create_wm_window(xwm);

Loading…
Cancel
Save