From 36b4465eb988621847bc8e83490e7a3b26ea34be Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 11 Oct 2017 08:38:32 +0200 Subject: [PATCH 01/15] Do not release buffer before emitting commit event --- types/wlr_surface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 9e38d701..1432c120 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -391,8 +391,6 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface, release: pixman_region32_clear(&surface->current->surface_damage); pixman_region32_clear(&surface->current->buffer_damage); - - wlr_surface_state_release_buffer(surface->current); } static void wlr_surface_commit_pending(struct wlr_surface *surface) { @@ -428,6 +426,8 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { // TODO: add the invalid bitfield to this callback wl_signal_emit(&surface->events.commit, surface); + + wlr_surface_state_release_buffer(surface->current); } static bool wlr_subsurface_is_synchronized(struct wlr_subsurface *subsurface) { From 67f0c3ca427343fab26a8340296c3f95b062916f Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 11 Oct 2017 14:02:41 +0200 Subject: [PATCH 02/15] Rename release label --- types/wlr_surface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 1432c120..4c433184 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -359,7 +359,7 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface, if (wlr_renderer_buffer_is_drm(surface->renderer, surface->current->buffer)) { wlr_texture_upload_drm(surface->texture, surface->current->buffer); - goto release; + goto clear_damage; } else { wlr_log(L_INFO, "Unknown buffer handle attached"); return; @@ -372,7 +372,7 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface, } else { pixman_region32_t damage = surface->current->buffer_damage; if (!pixman_region32_not_empty(&damage)) { - goto release; + goto clear_damage; } int n; pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n); @@ -388,7 +388,7 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface, } } -release: +clear_damage: pixman_region32_clear(&surface->current->surface_damage); pixman_region32_clear(&surface->current->buffer_damage); } From 5c6a93389023f8f31e81d34cad618137b0483487 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 11 Oct 2017 20:29:21 +0200 Subject: [PATCH 03/15] Do not call wlr_surface_state_release_buffer anymore --- types/wlr_output.c | 8 +++----- types/wlr_surface.c | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 13a6adbd..0b3f3842 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -238,10 +238,6 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, output->cursor.hotspot_x = hotspot_x; output->cursor.hotspot_y = hotspot_y; - if (surface && output->cursor.surface == surface) { - return; - } - if (output->cursor.surface) { wl_list_remove(&output->cursor.surface_commit.link); wl_list_remove(&output->cursor.surface_destroy.link); @@ -252,7 +248,9 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, if (surface != NULL) { wl_signal_add(&surface->events.commit, &output->cursor.surface_commit); - wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy); + wl_signal_add(&surface->events.destroy, + &output->cursor.surface_destroy); + commit_cursor_surface(output, surface); } else { set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y); } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 4c433184..654b5f1c 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -427,7 +427,8 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { // TODO: add the invalid bitfield to this callback wl_signal_emit(&surface->events.commit, surface); - wlr_surface_state_release_buffer(surface->current); + // TODO: call this + //wlr_surface_state_release_buffer(surface->current); } static bool wlr_subsurface_is_synchronized(struct wlr_subsurface *subsurface) { From 92daa790bb4ac1b15eedd91e02ab65b340e8f2a5 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 12 Oct 2017 09:40:51 +0200 Subject: [PATCH 04/15] Allow to update the cursor hotspot without its pixels --- backend/drm/drm.c | 10 ++++++++-- backend/wayland/output.c | 9 ++++++++- include/wlr/interfaces/wlr_output.h | 10 +++++----- types/wlr_output.c | 11 ++++++++++- types/wlr_surface.c | 5 +++-- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 9e5346a1..ff4dc7f6 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -470,7 +470,7 @@ static void wlr_drm_connector_transform(struct wlr_output *output, static bool wlr_drm_connector_set_cursor(struct wlr_output *output, const uint8_t *buf, 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, bool update_pixels) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_renderer *renderer = &drm->renderer; @@ -478,7 +478,8 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_plane *plane = crtc->cursor; - if (!buf) { + if (!buf && update_pixels) { + // Hide the cursor return drm->iface->crtc_set_cursor(drm, crtc, NULL); } @@ -566,6 +567,11 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, break; } + if (!update_pixels) { + // Only update the cursor hotspot + return true; + } + struct gbm_bo *bo = plane->cursor_bo; uint32_t bo_width = gbm_bo_get_width(bo); uint32_t bo_height = gbm_bo_get_height(bo); diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 03b43b35..2616b347 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -54,11 +54,18 @@ static void wlr_wl_output_transform(struct wlr_output *_output, static bool wlr_wl_output_set_cursor(struct wlr_output *_output, const uint8_t *buf, 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, bool update_pixels) { struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; struct wlr_wl_backend *backend = output->backend; + if (!update_pixels) { + // Update hotspot without changing cursor image + wlr_wl_output_update_cursor(output, output->enter_serial, hotspot_x, + hotspot_y); + return true; + } if (!buf) { + // Hide cursor wl_pointer_set_cursor(output->backend->pointer, output->enter_serial, NULL, 0, 0); return true; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 7d2821e0..b7927569 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -8,16 +8,16 @@ struct wlr_output_impl { void (*enable)(struct wlr_output *output, bool enable); bool (*set_mode)(struct wlr_output *output, struct wlr_output_mode *mode); void (*transform)(struct wlr_output *output, - enum wl_output_transform transform); + enum wl_output_transform transform); bool (*set_cursor)(struct wlr_output *output, const uint8_t *buf, - int32_t stride, uint32_t width, uint32_t height, - int32_t hotspot_x, int32_t hotspot_y); + int32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y, bool update_pixels); bool (*move_cursor)(struct wlr_output *output, int x, int y); void (*destroy)(struct wlr_output *output); void (*make_current)(struct wlr_output *output); void (*swap_buffers)(struct wlr_output *output); void (*set_gamma)(struct wlr_output *output, - uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b); + uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint16_t (*get_gamma_size)(struct wlr_output *output); }; @@ -25,6 +25,6 @@ void wlr_output_init(struct wlr_output *output, const struct wlr_output_impl *im void wlr_output_free(struct wlr_output *output); void wlr_output_update_matrix(struct wlr_output *output); struct wl_global *wlr_output_create_global( - struct wlr_output *wlr_output, struct wl_display *display); + struct wlr_output *wlr_output, struct wl_display *display); #endif diff --git a/types/wlr_output.c b/types/wlr_output.c index 0b3f3842..568ea093 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -127,7 +127,7 @@ static bool set_cursor(struct wlr_output *output, const uint8_t *buf, int32_t hotspot_y) { if (output->impl->set_cursor && output->impl->set_cursor(output, buf, stride, width, height, - hotspot_x, hotspot_y)) { + hotspot_x, hotspot_y, true)) { output->cursor.is_sw = false; return true; } @@ -238,6 +238,15 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, output->cursor.hotspot_x = hotspot_x; output->cursor.hotspot_y = hotspot_y; + if (surface && surface == output->cursor.surface) { + if (output->impl->set_cursor && !output->cursor.is_sw) { + // Only update the hotspot + output->impl->set_cursor(output, NULL, 0, 0, 0, hotspot_x, + hotspot_y, false); + } + return; + } + if (output->cursor.surface) { wl_list_remove(&output->cursor.surface_commit.link); wl_list_remove(&output->cursor.surface_destroy.link); diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 654b5f1c..a5760d67 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -427,8 +427,9 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { // TODO: add the invalid bitfield to this callback wl_signal_emit(&surface->events.commit, surface); - // TODO: call this - //wlr_surface_state_release_buffer(surface->current); + // Release the buffer after calling commit, because some listeners + // might need it (e.g. for cursor surfaces) + wlr_surface_state_release_buffer(surface->current); } static bool wlr_subsurface_is_synchronized(struct wlr_subsurface *subsurface) { From 19860c03f7567bd85ffd735ce2ccc90c454dd5b1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 12 Oct 2017 13:25:29 +0200 Subject: [PATCH 05/15] Better handling of hidden cursors in wayland backend, add TODOs --- backend/wayland/output.c | 10 +++++++--- types/wlr_output.c | 4 +++- types/wlr_surface.c | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 2616b347..d308b907 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -66,8 +66,12 @@ static bool wlr_wl_output_set_cursor(struct wlr_output *_output, } if (!buf) { // Hide cursor - wl_pointer_set_cursor(output->backend->pointer, output->enter_serial, - NULL, 0, 0); + wl_surface_destroy(output->cursor_surface); + munmap(output->cursor_data, output->cursor_buf_size); + output->cursor_surface = NULL; + output->cursor_buf_size = 0; + wlr_wl_output_update_cursor(output, output->enter_serial, hotspot_x, + hotspot_y); return true; } @@ -160,7 +164,7 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) { void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output, uint32_t serial, int32_t hotspot_x, int32_t hotspot_y) { - if (output->cursor_surface && output->backend->pointer && serial) { + if (output->backend->pointer && serial) { wl_pointer_set_cursor(output->backend->pointer, serial, output->cursor_surface, hotspot_x, hotspot_y); } diff --git a/types/wlr_output.c b/types/wlr_output.c index 568ea093..b416f9de 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -259,7 +259,9 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, wl_signal_add(&surface->events.commit, &output->cursor.surface_commit); wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy); - commit_cursor_surface(output, surface); + // TODO: doing it breaks GTK apps + // TODO: not doing it breaks weston-subsurfaces + //commit_cursor_surface(output, surface); } else { set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y); } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index a5760d67..b3cdb809 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -429,7 +429,8 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { // Release the buffer after calling commit, because some listeners // might need it (e.g. for cursor surfaces) - wlr_surface_state_release_buffer(surface->current); + // TODO: breaks weston-subsurfaces + //wlr_surface_state_release_buffer(surface->current); } static bool wlr_subsurface_is_synchronized(struct wlr_subsurface *subsurface) { From 29abf93bb6a52101a53ece0b23e3b24c593a737e Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 12 Oct 2017 14:28:37 +0200 Subject: [PATCH 06/15] Check pointer focused surface instead of view at cursor --- include/rootston/input.h | 2 +- rootston/cursor.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/rootston/input.h b/include/rootston/input.h index fbabbdb6..516104a7 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -79,7 +79,7 @@ struct roots_input { struct wlr_xcursor_theme *theme; struct wlr_xcursor *xcursor; struct wlr_seat *wl_seat; - struct roots_view *client_cursor_view; + struct wl_client *cursor_client; enum roots_cursor_mode mode; struct roots_view *active_view, *last_active_view; diff --git a/rootston/cursor.c b/rootston/cursor.c index eeb657ad..4c3a9947 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -80,10 +80,16 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { case ROOTS_CURSOR_PASSTHROUGH: view = view_at(desktop, input->cursor->x, input->cursor->y, &surface, &sx, &sy); - if (view != input->client_cursor_view) { + bool set_compositor_cursor = !view && input->cursor_client; + if (view) { + struct wl_client *view_client = + wl_resource_get_client(view->wlr_surface->resource); + set_compositor_cursor = view_client != input->cursor_client; + } + if (set_compositor_cursor) { wlr_log(L_DEBUG, "Switching to compositor cursor"); cursor_set_xcursor_image(input, input->xcursor->images[0]); - input->client_cursor_view = NULL; + input->cursor_client = NULL; } if (view) { wlr_seat_pointer_notify_enter(input->wl_seat, surface, sx, sy); @@ -298,10 +304,8 @@ static void handle_request_set_cursor(struct wl_listener *listener, request_set_cursor); struct wlr_seat_pointer_request_set_cursor_event *event = data; - struct wlr_surface *focused_surface = NULL; - double sx, sy; - struct roots_view *focused_view = view_at(input->server->desktop, - input->cursor->x, input->cursor->y, &focused_surface, &sx, &sy); + struct wlr_surface *focused_surface = + event->seat_handle->wlr_seat->pointer_state.focused_surface; bool ok = focused_surface != NULL; if (focused_surface != NULL) { struct wl_client *focused_client = @@ -309,7 +313,7 @@ static void handle_request_set_cursor(struct wl_listener *listener, ok = event->client == focused_client; } if (!ok) { - wlr_log(L_DEBUG, "Denying request to set cursor outside view"); + wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client"); return; } @@ -321,7 +325,7 @@ static void handle_request_set_cursor(struct wl_listener *listener, event->hotspot_x, event->hotspot_y); } - input->client_cursor_view = focused_view; + input->cursor_client = event->client; } void cursor_initialize(struct roots_input *input) { From 8fd4ae5de86b62e482e338113e94f23ee183d28d Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 14 Oct 2017 12:21:36 +0200 Subject: [PATCH 07/15] Fix cursor role name, fix segfault when surface->resource is NULL --- rootston/cursor.c | 4 ++-- types/wlr_output.c | 2 +- types/wlr_seat.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index 4c3a9947..03189587 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -306,8 +306,8 @@ static void handle_request_set_cursor(struct wl_listener *listener, struct wlr_surface *focused_surface = event->seat_handle->wlr_seat->pointer_state.focused_surface; - bool ok = focused_surface != NULL; - if (focused_surface != NULL) { + bool ok = focused_surface != NULL && focused_surface->resource != NULL; + if (ok) { struct wl_client *focused_client = wl_resource_get_client(focused_surface->resource); ok = event->client == focused_client; diff --git a/types/wlr_output.c b/types/wlr_output.c index b416f9de..bd4799c4 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -231,7 +231,7 @@ static void handle_cursor_surface_destroy(struct wl_listener *listener, void wlr_output_set_cursor_surface(struct wlr_output *output, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { - if (surface && strcmp(surface->role, "cursor") != 0) { + if (surface && strcmp(surface->role, "wl_pointer-cursor") != 0) { return; } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ef81655c..aea4196b 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -28,7 +28,7 @@ static void wl_pointer_set_cursor(struct wl_client *client, if (surface_resource != NULL) { surface = wl_resource_get_user_data(surface_resource); - if (wlr_surface_set_role(surface, "cursor", resource, + if (wlr_surface_set_role(surface, "wl_pointer-cursor", resource, WL_POINTER_ERROR_ROLE) < 0) { return; } From dd5114a5143b1594340dcbd91279c325f1c5e776 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 14 Oct 2017 12:44:25 +0200 Subject: [PATCH 08/15] Fix client cursors when software cursors are used --- types/wlr_output.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index bd4799c4..f47896d5 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -179,6 +179,11 @@ static inline int64_t timespec_to_msec(const struct timespec *a) { static void commit_cursor_surface(struct wlr_output *output, struct wlr_surface *surface) { + if (!output->impl->set_cursor) { + output->cursor.is_sw = true; + return; + } + struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer); if (buffer == NULL) { return; @@ -342,10 +347,20 @@ void wlr_output_swap_buffers(struct wlr_output *output) { glViewport(0, 0, output->width, output->height); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - float matrix[16]; - wlr_texture_get_matrix(output->cursor.texture, &matrix, &output->transform_matrix, - output->cursor.x, output->cursor.y); - wlr_render_with_matrix(output->cursor.renderer, output->cursor.texture, &matrix); + + struct wlr_texture *texture = output->cursor.texture; + struct wlr_renderer *renderer = output->cursor.renderer; + if (output->cursor.surface) { + texture = output->cursor.surface->texture; + renderer = output->cursor.surface->renderer; + } + + if (texture && renderer) { + float matrix[16]; + wlr_texture_get_matrix(texture, &matrix, &output->transform_matrix, + output->cursor.x, output->cursor.y); + wlr_render_with_matrix(renderer, texture, &matrix); + } } wl_signal_emit(&output->events.swap_buffers, &output); From 6dc0517bb163b4ee38602d8955b9994e5928d739 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 14 Oct 2017 13:24:29 +0200 Subject: [PATCH 09/15] Fix software cursor when setting committed cursor surface --- types/wlr_output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index f47896d5..0026678e 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -179,8 +179,7 @@ static inline int64_t timespec_to_msec(const struct timespec *a) { static void commit_cursor_surface(struct wlr_output *output, struct wlr_surface *surface) { - if (!output->impl->set_cursor) { - output->cursor.is_sw = true; + if (output->cursor.is_sw) { return; } @@ -258,6 +257,7 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, output->cursor.surface = NULL; } + output->cursor.is_sw = output->impl->set_cursor == NULL; output->cursor.surface = surface; if (surface != NULL) { From 08720db01db302246c9e0a15c0cde7120af3e1d8 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 14 Oct 2017 13:33:34 +0200 Subject: [PATCH 10/15] Release buffer in wlr_surface_flush_damage --- types/wlr_output.c | 4 +--- types/wlr_surface.c | 13 +++++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 0026678e..5f3820bc 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -264,9 +264,7 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, wl_signal_add(&surface->events.commit, &output->cursor.surface_commit); wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy); - // TODO: doing it breaks GTK apps - // TODO: not doing it breaks weston-subsurfaces - //commit_cursor_surface(output, surface); + commit_cursor_surface(output, surface); } else { set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y); } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index b3cdb809..9e38d701 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -359,7 +359,7 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface, if (wlr_renderer_buffer_is_drm(surface->renderer, surface->current->buffer)) { wlr_texture_upload_drm(surface->texture, surface->current->buffer); - goto clear_damage; + goto release; } else { wlr_log(L_INFO, "Unknown buffer handle attached"); return; @@ -372,7 +372,7 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface, } else { pixman_region32_t damage = surface->current->buffer_damage; if (!pixman_region32_not_empty(&damage)) { - goto clear_damage; + goto release; } int n; pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n); @@ -388,9 +388,11 @@ static void wlr_surface_flush_damage(struct wlr_surface *surface, } } -clear_damage: +release: pixman_region32_clear(&surface->current->surface_damage); pixman_region32_clear(&surface->current->buffer_damage); + + wlr_surface_state_release_buffer(surface->current); } static void wlr_surface_commit_pending(struct wlr_surface *surface) { @@ -426,11 +428,6 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { // TODO: add the invalid bitfield to this callback wl_signal_emit(&surface->events.commit, surface); - - // Release the buffer after calling commit, because some listeners - // might need it (e.g. for cursor surfaces) - // TODO: breaks weston-subsurfaces - //wlr_surface_state_release_buffer(surface->current); } static bool wlr_subsurface_is_synchronized(struct wlr_subsurface *subsurface) { From 60e2bd3550648784ee36702cd7b477854266fbfc Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 15 Oct 2017 22:21:05 +0200 Subject: [PATCH 11/15] Add XML rules to .editorconfig --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 4b8b3e12..64f18915 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,7 @@ charset = utf-8 indent_style = tab indent_size = 4 trim_trailing_whitespace = true + +[*.xml] +indent_style = space +indent_size = 2 From 19784360f11796eb9cbd27ea6baa2ca0bc39a5f5 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 16 Oct 2017 14:35:16 -0400 Subject: [PATCH 12/15] bug: fix view centering --- include/rootston/view.h | 6 +--- include/wlr/types/wlr_output_layout.h | 6 ++++ include/wlr/types/wlr_xdg_shell_v6.h | 1 + rootston/desktop.c | 45 ++++++++++++++++----------- rootston/wl_shell.c | 10 ++---- rootston/xdg_shell_v6.c | 11 ++----- types/wlr_output_layout.c | 17 ++++++++++ types/wlr_xdg_shell_v6.c | 10 +++--- 8 files changed, 62 insertions(+), 44 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index af087182..a4fb6f01 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -17,8 +17,6 @@ struct roots_wl_shell_surface { struct wl_listener request_set_maximized; struct wl_listener surface_commit; - - bool initialized; }; struct roots_xdg_surface_v6 { @@ -32,8 +30,6 @@ struct roots_xdg_surface_v6 { struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_show_window_menu; - - bool initialized; }; struct roots_xwayland_surface { @@ -85,6 +81,6 @@ void view_activate(struct roots_view *view, bool active); void view_resize(struct roots_view *view, uint32_t width, uint32_t height); void view_close(struct roots_view *view); bool view_center(struct roots_view *view); -bool view_initialize(struct roots_view *view); +void view_initialize(struct roots_view *view); #endif diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index fe09106f..ea8dbcd2 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -84,4 +84,10 @@ struct wlr_box *wlr_output_layout_get_box( void wlr_output_layout_add_auto(struct wlr_output_layout *layout, struct wlr_output *output); +/** + * Get the output closest to the center of the layout extents. + */ +struct wlr_output *wlr_output_layout_get_center_output( + struct wlr_output_layout *layout); + #endif diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 48da6604..b0de41e2 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -106,6 +106,7 @@ struct wlr_xdg_surface_v6 { struct wl_list popup_link; bool configured; + bool added; struct wl_event_source *configure_idle; struct wl_list configure_list; diff --git a/rootston/desktop.c b/rootston/desktop.c index d5cac575..a7137255 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -67,35 +67,42 @@ void view_close(struct roots_view *view) { bool view_center(struct roots_view *view) { struct wlr_box size; view_get_size(view, &size); - if (size.width == 0 && size.height == 0) { - return false; - } struct roots_desktop *desktop = view->desktop; struct wlr_cursor *cursor = desktop->server->input->cursor; - struct wlr_output *output = wlr_output_layout_output_at(desktop->layout, - cursor->x, cursor->y); - const struct wlr_output_layout_output *output_layout = - wlr_output_layout_get(desktop->layout, output); + + struct wlr_output *output = + wlr_output_layout_output_at(desktop->layout, cursor->x, cursor->y); + if (!output) { + output = wlr_output_layout_get_center_output(desktop->layout); + } + + if (!output) { + // empty layout return false; } - view->x = (double)(output->width - size.width) / 2 - + output_layout->x; - view->y = (double)(output->height - size.height) / 2 - + output_layout->y; + const struct wlr_output_layout_output *l_output = + wlr_output_layout_get(desktop->layout, output); + + int width, height; + wlr_output_effective_resolution(output, &width, &height); + + view->x = (double)(width - size.width) / 2 + + l_output->x; + view->y = (double)(height - size.height) / 2 + + l_output->y; + return true; } -bool view_initialize(struct roots_view *view) { - bool centered = view_center(view); - if (centered) { - struct roots_input *input = view->desktop->server->input; - set_view_focus(input, view->desktop, view); - wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); - } - return centered; +void view_initialize(struct roots_view *view) { + view_center(view); + struct roots_input *input = view->desktop->server->input; + + set_view_focus(input, view->desktop, view); + wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); } struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 34f53c7a..33f54a32 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -50,14 +50,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { } static void handle_surface_commit(struct wl_listener *listener, void *data) { - struct roots_wl_shell_surface *roots_surface = - wl_container_of(listener, roots_surface, surface_commit); - struct roots_view *view = roots_surface->view; - - if (view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL && - !roots_surface->initialized) { - roots_surface->initialized = view_initialize(view); - } + // TODO do we need to do anything here? } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -137,4 +130,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); + view_initialize(view); } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 9b8d8882..1e21fa02 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -68,14 +68,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { } static void handle_commit(struct wl_listener *listener, void *data) { - struct roots_xdg_surface_v6 *roots_xdg_surface = - wl_container_of(listener, roots_xdg_surface, commit); - struct roots_view *view = roots_xdg_surface->view; - - if (view->xdg_surface_v6->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL && - !roots_xdg_surface->initialized) { - roots_xdg_surface->initialized = view_initialize(view); - } + // TODO is there anything we need to do here? } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -141,4 +134,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); + + view_initialize(view); } diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 1890074b..8c3f1d88 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -343,3 +343,20 @@ void wlr_output_layout_add_auto(struct wlr_output_layout *layout, l_output->state->auto_configured = true; wlr_output_layout_reconfigure(layout); } + +struct wlr_output *wlr_output_layout_get_center_output( + struct wlr_output_layout *layout) { + if (wl_list_empty(&layout->outputs)) { + return NULL; + } + + struct wlr_box *extents = wlr_output_layout_get_box(layout, NULL); + double center_x = extents->width / 2 + extents->x; + double center_y = extents->height / 2 + extents->y; + + double dest_x = 0, dest_y = 0; + wlr_output_layout_closest_point(layout, NULL, center_x, center_y, + &dest_x, &dest_y); + + return wlr_output_layout_output_at(layout, dest_x, dest_y); +} diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 3f5f22a0..31207c89 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -802,10 +802,7 @@ static void xdg_surface_ack_configure(struct wl_client *client, break; } - if (!surface->configured) { - surface->configured = true; - wl_signal_emit(&surface->client->shell->events.new_surface, surface); - } + surface->configured = true; wl_signal_emit(&surface->events.ack_configure, surface); @@ -1055,6 +1052,11 @@ static void handle_wlr_surface_committed(struct wl_listener *listener, break; } + if (surface->configured && !surface->added) { + surface->added = true; + wl_signal_emit(&surface->client->shell->events.new_surface, surface); + } + wl_signal_emit(&surface->events.commit, surface); } From 786f4bdd4d79f5aaa9fd4f7872553a5f3afe98f9 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 17 Oct 2017 00:04:33 +0200 Subject: [PATCH 13/15] Disable hardware cursors for now --- types/wlr_output.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 5f3820bc..d3b37d65 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -257,7 +257,15 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, output->cursor.surface = NULL; } - output->cursor.is_sw = output->impl->set_cursor == NULL; + // Disable hardware cursor + // TODO: support hardware cursors + output->cursor.is_sw = true; + if (output->impl->set_cursor) { + output->impl->set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y, + true); + } + + //output->cursor.is_sw = output->impl->set_cursor == NULL; output->cursor.surface = surface; if (surface != NULL) { From 2bd52c83ce156ab8262d28c4ebf29a1a1a3a553e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 17 Oct 2017 08:29:57 -0400 Subject: [PATCH 14/15] bug: detect invalid texture in xdg-shell --- types/wlr_xdg_shell_v6.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 31207c89..c8c09dc9 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "xdg-shell-unstable-v6-protocol.h" static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel"; @@ -993,7 +994,7 @@ static void wlr_xdg_surface_v6_toplevel_committed( struct wlr_xdg_surface_v6 *surface) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - if (!surface->surface->current->buffer && !surface->toplevel_state->added) { + if (!surface->surface->texture->valid && !surface->toplevel_state->added) { // on the first commit, send a configure request to tell the client it // is added wlr_xdg_surface_v6_schedule_configure(surface, true); @@ -1001,7 +1002,7 @@ static void wlr_xdg_surface_v6_toplevel_committed( return; } - if (!surface->surface->current->buffer) { + if (!surface->surface->texture->valid) { return; } @@ -1023,7 +1024,7 @@ static void handle_wlr_surface_committed(struct wl_listener *listener, struct wlr_xdg_surface_v6 *surface = wl_container_of(listener, surface, surface_commit_listener); - if (surface->surface->current->buffer && !surface->configured) { + if (surface->surface->texture->valid && !surface->configured) { wl_resource_post_error(surface->resource, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, "xdg_surface has never been configured"); @@ -1092,7 +1093,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, &zxdg_surface_v6_interface, wl_resource_get_version(client_resource), id); - if (surface->surface->current->buffer != NULL) { + if (surface->surface->texture->valid) { wl_resource_post_error(surface->resource, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, "xdg_surface must not have a buffer at creation"); From 82076bd772f8d015774d3efbf1e98230757d0980 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 17 Oct 2017 09:22:50 -0400 Subject: [PATCH 15/15] xdg-shell: force configure when pending different --- types/wlr_xdg_shell_v6.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 31207c89..39f8e139 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -840,6 +840,10 @@ static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = { static bool wlr_xdg_surface_v6_toplevel_state_compare( struct wlr_xdg_toplevel_v6 *state) { // is pending state different from current state? + if (!state->base->configured) { + return false; + } + if (state->pending.activated != state->current.activated) { return false; } @@ -1260,42 +1264,49 @@ void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) { void wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t width, uint32_t height) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + bool force = + (surface->toplevel_state->pending.width != width || + surface->toplevel_state->pending.height != height); surface->toplevel_state->pending.width = width; surface->toplevel_state->pending.height = height; - wlr_xdg_surface_v6_schedule_configure(surface, false); + wlr_xdg_surface_v6_schedule_configure(surface, force); } void wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, bool activated) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + bool force = surface->toplevel_state->pending.activated != activated; surface->toplevel_state->pending.activated = activated; - wlr_xdg_surface_v6_schedule_configure(surface, false); + wlr_xdg_surface_v6_schedule_configure(surface, force); } void wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, bool maximized) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + bool force = surface->toplevel_state->pending.maximized != maximized; surface->toplevel_state->pending.maximized = maximized; - wlr_xdg_surface_v6_schedule_configure(surface, false); + wlr_xdg_surface_v6_schedule_configure(surface, force); } void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, bool fullscreen) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + bool force = surface->toplevel_state->pending.fullscreen != fullscreen; surface->toplevel_state->pending.fullscreen = fullscreen; - wlr_xdg_surface_v6_schedule_configure(surface, false); + wlr_xdg_surface_v6_schedule_configure(surface, force); } void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel_state->pending.fullscreen = resizing; + bool force = surface->toplevel_state->pending.resizing != resizing; + surface->toplevel_state->pending.resizing = resizing; - wlr_xdg_surface_v6_schedule_configure(surface, false); + wlr_xdg_surface_v6_schedule_configure(surface, force); } void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) {