From a7446792a1a0fd9fe3391f041d7bbfe9e2b11255 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 22 Oct 2017 23:19:21 -0400 Subject: [PATCH 01/25] Consider scale factor when rendering views --- include/rootston/config.h | 1 + include/rootston/view.h | 1 + include/wlr/types/wlr_surface.h | 6 +++++- rootston/config.c | 4 ++++ rootston/output.c | 3 +++ types/wlr_output.c | 4 ++-- types/wlr_surface.c | 19 ++++++++++++++++--- 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/rootston/config.h b/include/rootston/config.h index 75c04619..e0466117 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -8,6 +8,7 @@ struct output_config { char *name; enum wl_output_transform transform; int x, y; + int scale; struct wl_list link; struct { int width, height; diff --git a/include/rootston/view.h b/include/rootston/view.h index 993ff654..4a5e8d08 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -48,6 +48,7 @@ enum roots_view_type { struct roots_view { struct roots_desktop *desktop; + struct roots_output *output; double x, y; float rotation; // TODO: Something for roots-enforced width/height diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index ea4184aa..e1a07566 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -1,10 +1,10 @@ #ifndef WLR_TYPES_WLR_SURFACE_H #define WLR_TYPES_WLR_SURFACE_H - #include #include #include #include +#include struct wlr_frame_callback { struct wl_resource *resource; @@ -135,4 +135,8 @@ struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface); */ struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, double sx, double sy, double *sub_x, double *sub_y); + +void wlr_surface_send_enter(struct wlr_surface *surface, + struct wlr_output *output); + #endif diff --git a/rootston/config.c b/rootston/config.c index 18138ab0..983117ba 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -220,6 +220,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, oc = calloc(1, sizeof(struct output_config)); oc->name = strdup(output_name); oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; + oc->scale = 1; wl_list_insert(&config->outputs, &oc->link); } @@ -227,6 +228,9 @@ static int config_ini_handler(void *user, const char *section, const char *name, oc->x = strtol(value, NULL, 10); } else if (strcmp(name, "y") == 0) { oc->y = strtol(value, NULL, 10); + } else if (strcmp(name, "scale") == 0) { + oc->scale = strtol(value, NULL, 10); + assert(oc->scale >= 1); } else if (strcmp(name, "rotate") == 0) { if (strcmp(value, "90") == 0) { oc->transform = WL_OUTPUT_TRANSFORM_90; diff --git a/rootston/output.c b/rootston/output.c index baa7b6cc..faf39e74 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -27,6 +27,8 @@ static void render_surface(struct wlr_surface *surface, if (wlr_output_layout_intersects(desktop->layout, wlr_output, lx, ly, lx + width, ly + height)) { + // TODO: accomodate for mismatched scale, which can happen, for + // example, when a view is rendered over two outputs float matrix[16]; float translate_origin[16]; @@ -217,6 +219,7 @@ void output_add_notify(struct wl_listener *listener, void *data) { if (output_config->mode.width) { set_mode(wlr_output, output_config); } + wlr_output->scale = output_config->scale; wlr_output_transform(wlr_output, output_config->transform); wlr_output_layout_add(desktop->layout, wlr_output, output_config->x, output_config->y); diff --git a/types/wlr_output.c b/types/wlr_output.c index 44d24ae3..2f5e3086 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -29,8 +29,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { if (version >= WL_OUTPUT_MODE_SINCE_VERSION) { struct wlr_output_mode *mode; wl_list_for_each(mode, &output->modes, link) { - // TODO: mode->flags should just be preferred - uint32_t flags = mode->flags; + uint32_t flags = mode->flags & ~WL_OUTPUT_MODE_PREFERRED; if (output->current_mode == mode) { flags |= WL_OUTPUT_MODE_CURRENT; } @@ -45,6 +44,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { } } if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) { + wlr_log(L_DEBUG, "Sending scale"); wl_output_send_scale(resource, output->scale); } if (version >= WL_OUTPUT_DONE_SINCE_VERSION) { diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 2a8c4d04..28f3d05b 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -649,14 +649,14 @@ void wlr_surface_get_matrix(struct wlr_surface *surface, float (*matrix)[16], const float (*projection)[16], const float (*transform)[16]) { - int width = surface->texture->width / surface->current->scale; - int height = surface->texture->height / surface->current->scale; + int width = surface->texture->width; + int height = surface->texture->height; float scale[16]; wlr_matrix_identity(matrix); if (transform) { wlr_matrix_mul(matrix, transform, matrix); } - wlr_matrix_scale(&scale, width, height, 1); + wlr_matrix_scale(&scale, width, height, surface->current->scale); wlr_matrix_mul(matrix, &scale, matrix); wlr_matrix_mul(projection, matrix, matrix); } @@ -894,3 +894,16 @@ struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, return NULL; } + +void wlr_surface_send_enter(struct wlr_surface *surface, + struct wlr_output *output) { + struct wl_client *client = wl_resource_get_client(surface->resource); + struct wl_resource *resource; + wl_resource_for_each(resource, &output->wl_resources) { + if (client == wl_resource_get_client(resource)) { + wlr_log(L_DEBUG, "sending output enter"); + wl_surface_send_enter(surface->resource, resource); + break; + } + } +} From 9861add146af54836ca85dd5769ab3b966346432 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 24 Oct 2017 08:37:30 -0400 Subject: [PATCH 02/25] Send surface enter output events to clients --- rootston/desktop.c | 32 +++- types/wlr_output.c | 442 ++++++++++++++++++++------------------------- 2 files changed, 226 insertions(+), 248 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index f93d1df8..37022ca4 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -45,14 +45,35 @@ void view_get_size(struct roots_view *view, struct wlr_box *box) { box->height = view->wlr_surface->current->height; } +static void view_update_output(struct roots_view *view) { + struct roots_desktop *desktop = view->desktop; + struct roots_output *output = NULL, *_output; + struct wlr_box box; + view_get_size(view, &box); + wl_list_for_each(_output, &desktop->outputs, link) { + if (!wlr_output_layout_intersects(desktop->layout, _output->wlr_output, + view->x, view->y, view->x + box.width, view->x + box.height)) { + continue; + } + if (output == NULL + || output->wlr_output->scale < _output->wlr_output->scale) { + output = _output; + } + } + if (output && output != view->output) { + view->output = output; + wlr_surface_send_enter(view->wlr_surface, output->wlr_output); + } +} + void view_set_position(struct roots_view *view, double x, double y) { if (view->set_position) { view->set_position(view, x, y); - return; + } else { + view->x = x; + view->y = y; } - - view->x = x; - view->y = y; + view_update_output(view); } void view_activate(struct roots_view *view, bool activate) { @@ -65,6 +86,7 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { if (view->resize) { view->resize(view, width, height); } + view_update_output(view); } void view_close(struct roots_view *view) { @@ -111,6 +133,8 @@ void view_setup(struct roots_view *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); + view_update_output(view); } void view_teardown(struct roots_view *view) { diff --git a/types/wlr_output.c b/types/wlr_output.c index 2f5e3086..dd7e8d6a 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -136,9 +135,7 @@ static void wlr_output_update_matrix(struct wlr_output *output) { } void wlr_output_enable(struct wlr_output *output, bool enable) { - if (output->impl->enable) { - output->impl->enable(output, enable); - } + output->impl->enable(output, enable); } bool wlr_output_set_mode(struct wlr_output *output, @@ -191,19 +188,192 @@ void wlr_output_set_position(struct wlr_output *output, int32_t lx, } } +static 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) { + if (output->impl->set_cursor + && output->impl->set_cursor(output, buf, stride, width, height, + hotspot_x, hotspot_y, true)) { + output->cursor.is_sw = false; + return true; + } + + wlr_log(L_INFO, "Falling back to software cursor"); + + output->cursor.is_sw = true; + output->cursor.width = width; + output->cursor.height = height; + + if (!output->cursor.renderer) { + output->cursor.renderer = wlr_gles2_renderer_create(output->backend); + if (!output->cursor.renderer) { + return false; + } + } + + if (!output->cursor.texture) { + output->cursor.texture = + wlr_render_texture_create(output->cursor.renderer); + if (!output->cursor.texture) { + return false; + } + } + + return wlr_texture_upload_pixels(output->cursor.texture, + WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); +} + +bool wlr_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) { + if (output->cursor.surface) { + wl_list_remove(&output->cursor.surface_commit.link); + wl_list_remove(&output->cursor.surface_destroy.link); + output->cursor.surface = NULL; + } + + output->cursor.hotspot_x = hotspot_x; + output->cursor.hotspot_y = hotspot_y; + + return set_cursor(output, buf, stride, width, height, hotspot_x, hotspot_y); +} + +static inline int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + +static void commit_cursor_surface(struct wlr_output *output, + struct wlr_surface *surface) { + if (output->cursor.is_sw) { + return; + } + + struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer); + if (buffer == NULL) { + return; + } + + uint32_t format = wl_shm_buffer_get_format(buffer); + if (format != WL_SHM_FORMAT_ARGB8888) { + return; + } + + void *buffer_data = wl_shm_buffer_get_data(buffer); + int32_t width = wl_shm_buffer_get_width(buffer); + int32_t height = wl_shm_buffer_get_height(buffer); + int32_t stride = wl_shm_buffer_get_stride(buffer); + wl_shm_buffer_begin_access(buffer); + wlr_output_set_cursor(output, buffer_data, stride/4, width, height, + output->cursor.hotspot_x - surface->current->sx, + output->cursor.hotspot_y - surface->current->sy); + wl_shm_buffer_end_access(buffer); +} + +static void handle_cursor_surface_commit(struct wl_listener *listener, + void *data) { + struct wlr_output *output = wl_container_of(listener, output, + cursor.surface_commit); + struct wlr_surface *surface = data; + + commit_cursor_surface(output, surface); + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + struct wlr_frame_callback *cb, *cnext; + wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list, + link) { + wl_callback_send_done(cb->resource, timespec_to_msec(&now)); + wl_resource_destroy(cb->resource); + } +} + +static void handle_cursor_surface_destroy(struct wl_listener *listener, + void *data) { + struct wlr_output *output = wl_container_of(listener, output, + cursor.surface_destroy); + + wl_list_remove(&output->cursor.surface_commit.link); + wl_list_remove(&output->cursor.surface_destroy.link); + output->cursor.surface = NULL; +} + +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, "wl_pointer-cursor") != 0) { + return; + } + + 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); + output->cursor.surface = 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) { + 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); + } else { + set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y); + } +} + +bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { + output->cursor.x = x; + output->cursor.y = y; + + if (output->cursor.is_sw) { + return true; + } + + if (!output->impl->move_cursor) { + return false; + } + + return output->impl->move_cursor(output, x, y); +} + void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, const struct wlr_output_impl *impl) { - assert(impl->make_current && impl->swap_buffers && impl->transform); output->backend = backend; output->impl = impl; wl_list_init(&output->modes); output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->scale = 1; - wl_list_init(&output->cursors); wl_signal_init(&output->events.frame); wl_signal_init(&output->events.swap_buffers); wl_signal_init(&output->events.resolution); wl_signal_init(&output->events.destroy); + + wl_list_init(&output->cursor.surface_commit.link); + output->cursor.surface_commit.notify = handle_cursor_surface_commit; + wl_list_init(&output->cursor.surface_destroy.link); + output->cursor.surface_destroy.notify = handle_cursor_surface_destroy; } void wlr_output_destroy(struct wlr_output *output) { @@ -213,6 +383,9 @@ void wlr_output_destroy(struct wlr_output *output) { wl_signal_emit(&output->events.destroy, output); + wlr_texture_destroy(output->cursor.texture); + wlr_renderer_destroy(output->cursor.renderer); + struct wlr_output_mode *mode, *tmp_mode; wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) { free(mode); @@ -227,7 +400,6 @@ void wlr_output_destroy(struct wlr_output *output) { void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height) { - // TODO: Scale factor if (output->transform % 2 == 1) { *width = output->height; *height = output->width; @@ -241,62 +413,27 @@ void wlr_output_make_current(struct wlr_output *output) { output->impl->make_current(output); } -static void output_cursor_get_box(struct wlr_output_cursor *cursor, - struct wlr_box *box) { - box->x = cursor->x - cursor->hotspot_x; - box->y = cursor->y - cursor->hotspot_y; - box->width = cursor->width; - box->height = cursor->height; -} - -static void output_cursor_render(struct wlr_output_cursor *cursor) { - struct wlr_texture *texture = cursor->texture; - struct wlr_renderer *renderer = cursor->renderer; - if (cursor->surface != NULL) { - // Some clients commit a cursor surface with a NULL buffer to hide it. - if (!wlr_surface_has_buffer(cursor->surface)) { - return; - } - texture = cursor->surface->texture; - renderer = cursor->surface->renderer; - } - - if (texture == NULL || renderer == NULL) { - return; - } - - struct wlr_box output_box; - output_box.x = output_box.y = 0; - output_box.width = cursor->output->width; - output_box.height = cursor->output->height; - - struct wlr_box cursor_box; - output_cursor_get_box(cursor, &cursor_box); - - struct wlr_box intersection; - struct wlr_box *intersection_ptr = &intersection; - if (!wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr)) { - return; - } - - glViewport(0, 0, cursor->output->width, cursor->output->height); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - float matrix[16]; - wlr_texture_get_matrix(texture, &matrix, - &cursor->output->transform_matrix, cursor->x - cursor->hotspot_x, - cursor->y - cursor->hotspot_y); - wlr_render_with_matrix(renderer, texture, &matrix); -} - void wlr_output_swap_buffers(struct wlr_output *output) { - struct wlr_output_cursor *cursor; - wl_list_for_each(cursor, &output->cursors, link) { - if (output->hardware_cursor == cursor) { - continue; + if (output->cursor.is_sw) { + glViewport(0, 0, output->width, output->height); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + 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; + } + + // We check texture->valid because some clients set a cursor surface + // with a NULL buffer to hide it + if (renderer && texture && texture->valid) { + 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); } - output_cursor_render(cursor); } wl_signal_emit(&output->events.swap_buffers, &output); @@ -317,186 +454,3 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { } return output->impl->get_gamma_size(output); } - -static void output_cursor_reset(struct wlr_output_cursor *cursor) { - if (cursor->surface != NULL) { - wl_list_remove(&cursor->surface_commit.link); - wl_list_remove(&cursor->surface_destroy.link); - cursor->surface = NULL; - } -} - -bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, - const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, - int32_t hotspot_x, int32_t hotspot_y) { - output_cursor_reset(cursor); - - cursor->width = width; - cursor->height = height; - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = hotspot_y; - - if (cursor->output->hardware_cursor == NULL && - cursor->output->impl->set_cursor) { - int ok = cursor->output->impl->set_cursor(cursor->output, pixels, - stride, width, height, hotspot_x, hotspot_y, true); - if (ok) { - cursor->output->hardware_cursor = cursor; - return true; - } - } - - wlr_log(L_INFO, "Falling back to software cursor"); - - if (cursor->renderer == NULL) { - cursor->renderer = wlr_gles2_renderer_create(cursor->output->backend); - if (cursor->renderer == NULL) { - return false; - } - } - - if (cursor->texture == NULL) { - cursor->texture = wlr_render_texture_create(cursor->renderer); - if (cursor->texture == NULL) { - return false; - } - } - - return wlr_texture_upload_pixels(cursor->texture, WL_SHM_FORMAT_ARGB8888, - stride, width, height, pixels); -} - -static void output_cursor_commit(struct wlr_output_cursor *cursor) { - cursor->width = cursor->surface->current->width; - cursor->height = cursor->surface->current->height; - - // TODO: if hardware cursor, upload pixels -} - -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; -} - -static void output_cursor_handle_commit(struct wl_listener *listener, - void *data) { - struct wlr_output_cursor *cursor = wl_container_of(listener, cursor, - surface_commit); - struct wlr_surface *surface = data; - - output_cursor_commit(cursor); - - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - - struct wlr_frame_callback *cb, *cnext; - wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list, - link) { - wl_callback_send_done(cb->resource, timespec_to_msec(&now)); - wl_resource_destroy(cb->resource); - } -} - -static void output_cursor_handle_destroy(struct wl_listener *listener, - void *data) { - struct wlr_output_cursor *cursor = wl_container_of(listener, cursor, - surface_destroy); - output_cursor_reset(cursor); -} - -void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, - struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { - if (surface && strcmp(surface->role, "wl_pointer-cursor") != 0) { - return; - } - - if (surface) { - cursor->width = surface->current->width; - cursor->height = surface->current->height; - } - cursor->hotspot_x = hotspot_x; - cursor->hotspot_y = hotspot_y; - - if (surface && surface == cursor->surface) { - if (cursor->output->hardware_cursor == 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, - hotspot_x, hotspot_y, false); - } - return; - } - - output_cursor_reset(cursor); - - // Disable hardware cursor for surfaces - // TODO: support hardware cursors - if (cursor->output->hardware_cursor == cursor && - cursor->output->impl->set_cursor) { - cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, 0, 0, - true); - cursor->output->hardware_cursor = NULL; - } - - cursor->surface = surface; - - if (surface != NULL) { - wl_signal_add(&surface->events.commit, &cursor->surface_commit); - wl_signal_add(&surface->events.destroy, &cursor->surface_destroy); - output_cursor_commit(cursor); - } else { - // TODO: if hardware cursor, disable cursor - } -} - -bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) { - cursor->x = x; - cursor->y = y; - - if (cursor->output->hardware_cursor != cursor) { - return true; - } - - if (!cursor->output->impl->move_cursor) { - return false; - } - return cursor->output->impl->move_cursor(cursor->output, x, y); -} - -struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) { - struct wlr_output_cursor *cursor = - calloc(1, sizeof(struct wlr_output_cursor)); - if (cursor == NULL) { - return NULL; - } - cursor->output = output; - wl_list_init(&cursor->surface_commit.link); - cursor->surface_commit.notify = output_cursor_handle_commit; - wl_list_init(&cursor->surface_destroy.link); - cursor->surface_destroy.notify = output_cursor_handle_destroy; - wl_list_insert(&output->cursors, &cursor->link); - return cursor; -} - -void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { - if (cursor == NULL) { - return; - } - output_cursor_reset(cursor); - if (cursor->output->hardware_cursor == cursor) { - // If this cursor was the hardware cursor, disable it - if (cursor->output->impl->set_cursor) { - cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, 0, - 0, true); - } - cursor->output->hardware_cursor = NULL; - } - if (cursor->texture != NULL) { - wlr_texture_destroy(cursor->texture); - } - if (cursor->renderer != NULL) { - wlr_renderer_destroy(cursor->renderer); - } - wl_list_remove(&cursor->link); - free(cursor); -} From a6930cd8ea2424f12aafc8d0b67426d0e5161c44 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 25 Oct 2017 22:37:02 -0400 Subject: [PATCH 03/25] Handle output enter/leave correctly --- include/rootston/view.h | 5 ++- include/wlr/types/wlr_surface.h | 3 ++ rootston/desktop.c | 59 ++++++++++++++++++--------------- rootston/xdg_shell_v6.c | 2 +- types/wlr_output.c | 1 - types/wlr_surface.c | 13 +++++++- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 4a5e8d08..79d61ba6 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -48,7 +48,6 @@ enum roots_view_type { struct roots_view { struct roots_desktop *desktop; - struct roots_output *output; double x, y; float rotation; // TODO: Something for roots-enforced width/height @@ -72,14 +71,14 @@ struct roots_view { // configure event from the xdg_shell // If not then this should follow the typical type/impl pattern we use // elsewhere - void (*get_size)(struct roots_view *view, struct wlr_box *box); + void (*get_size)(const struct roots_view *view, struct wlr_box *box); void (*activate)(struct roots_view *view, bool active); void (*resize)(struct roots_view *view, uint32_t width, uint32_t height); void (*set_position)(struct roots_view *view, double x, double y); void (*close)(struct roots_view *view); }; -void view_get_size(struct roots_view *view, struct wlr_box *box); +void view_get_size(const struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_resize(struct roots_view *view, uint32_t width, uint32_t height); void view_set_position(struct roots_view *view, double x, double y); diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index e1a07566..cea53109 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -139,4 +139,7 @@ struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, void wlr_surface_send_enter(struct wlr_surface *surface, struct wlr_output *output); +void wlr_surface_send_leave(struct wlr_surface *surface, + struct wlr_output *output); + #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index 37022ca4..0cc2180d 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -35,45 +35,52 @@ void view_destroy(struct roots_view *view) { free(view); } -void view_get_size(struct roots_view *view, struct wlr_box *box) { +void view_get_size(const struct roots_view *view, struct wlr_box *box) { if (view->get_size) { view->get_size(view, box); - return; + } else { + box->width = view->wlr_surface->current->width; + box->height = view->wlr_surface->current->height; } - box->x = box->y = 0; - box->width = view->wlr_surface->current->width; - box->height = view->wlr_surface->current->height; + box->x = view->x; + box->y = view->y; } -static void view_update_output(struct roots_view *view) { +static void view_update_output(const struct roots_view *view, + const struct wlr_box *before) { struct roots_desktop *desktop = view->desktop; - struct roots_output *output = NULL, *_output; + struct roots_output *output; struct wlr_box box; view_get_size(view, &box); - wl_list_for_each(_output, &desktop->outputs, link) { - if (!wlr_output_layout_intersects(desktop->layout, _output->wlr_output, - view->x, view->y, view->x + box.width, view->x + box.height)) { - continue; + wl_list_for_each(output, &desktop->outputs, link) { + bool intersected = before->x != -1 && wlr_output_layout_intersects( + desktop->layout, output->wlr_output, + before->x, before->y, before->x + before->width, + before->y + before->height); + bool intersects = wlr_output_layout_intersects( + desktop->layout, output->wlr_output, + view->x, view->y, view->x + box.width, view->y + box.height); + if (intersected && !intersects) { + wlr_log(L_DEBUG, "Leaving output %s", output->wlr_output->name); + wlr_surface_send_leave(view->wlr_surface, output->wlr_output); } - if (output == NULL - || output->wlr_output->scale < _output->wlr_output->scale) { - output = _output; + if (!intersected && intersects) { + wlr_log(L_DEBUG, "Entering output %s", output->wlr_output->name); + wlr_surface_send_enter(view->wlr_surface, output->wlr_output); } } - if (output && output != view->output) { - view->output = output; - wlr_surface_send_enter(view->wlr_surface, output->wlr_output); - } } void view_set_position(struct roots_view *view, double x, double y) { + struct wlr_box before; + view_get_size(view, &before); if (view->set_position) { view->set_position(view, x, y); } else { view->x = x; view->y = y; } - view_update_output(view); + view_update_output(view, &before); } void view_activate(struct roots_view *view, bool activate) { @@ -83,10 +90,12 @@ void view_activate(struct roots_view *view, bool activate) { } void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { + struct wlr_box before; + view_get_size(view, &before); if (view->resize) { view->resize(view, width, height); } - view_update_output(view); + view_update_output(view, &before); } void view_close(struct roots_view *view) { @@ -96,8 +105,8 @@ void view_close(struct roots_view *view) { } bool view_center(struct roots_view *view) { - struct wlr_box size; - view_get_size(view, &size); + struct wlr_box box; + view_get_size(view, &box); struct roots_desktop *desktop = view->desktop; struct wlr_cursor *cursor = desktop->server->input->cursor; @@ -122,16 +131,14 @@ bool view_center(struct roots_view *view) { double view_x = (double)(width - size.width) / 2 + l_output->x; double view_y = (double)(height - size.height) / 2 + l_output->y; - view_set_position(view, view_x, view_y); return true; } -void view_setup(struct roots_view *view) { - view_center(view); - +void view_initialize(struct roots_view *view) { struct roots_input *input = view->desktop->server->input; + view_center(view); set_view_focus(input, view->desktop, view); wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); view_update_output(view); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 704ccb1e..2d83019f 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -10,7 +10,7 @@ #include "rootston/server.h" #include "rootston/input.h" -static void get_size(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); struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; // TODO: surf->geometry can be NULL diff --git a/types/wlr_output.c b/types/wlr_output.c index dd7e8d6a..d6efd9bf 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -43,7 +43,6 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { } } if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) { - wlr_log(L_DEBUG, "Sending scale"); wl_output_send_scale(resource, output->scale); } if (version >= WL_OUTPUT_DONE_SINCE_VERSION) { diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 28f3d05b..a21be8de 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -901,9 +901,20 @@ void wlr_surface_send_enter(struct wlr_surface *surface, struct wl_resource *resource; wl_resource_for_each(resource, &output->wl_resources) { if (client == wl_resource_get_client(resource)) { - wlr_log(L_DEBUG, "sending output enter"); wl_surface_send_enter(surface->resource, resource); break; } } } + +void wlr_surface_send_leave(struct wlr_surface *surface, + struct wlr_output *output) { + struct wl_client *client = wl_resource_get_client(surface->resource); + struct wl_resource *resource; + wl_resource_for_each(resource, &output->wl_resources) { + if (client == wl_resource_get_client(resource)) { + wl_surface_send_leave(surface->resource, resource); + break; + } + } +} From bafb97087121dbeab83ffc7d2e571d4c53d1f000 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 25 Oct 2017 22:46:20 -0400 Subject: [PATCH 04/25] View view_at (and pointer events) for hidpi --- rootston/desktop.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index 0cc2180d..f7f12eff 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -61,11 +61,9 @@ static void view_update_output(const struct roots_view *view, desktop->layout, output->wlr_output, view->x, view->y, view->x + box.width, view->y + box.height); if (intersected && !intersects) { - wlr_log(L_DEBUG, "Leaving output %s", output->wlr_output->name); wlr_surface_send_leave(view->wlr_surface, output->wlr_output); } if (!intersected && intersects) { - wlr_log(L_DEBUG, "Entering output %s", output->wlr_output->name); wlr_surface_send_enter(view->wlr_surface, output->wlr_output); } } @@ -167,14 +165,15 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, continue; } - double view_sx = lx - view->x; - double view_sy = ly - view->y; + int scale = view->wlr_surface->current->scale; + double view_sx = (lx - view->x) / (double)scale; + double view_sy = (ly - view->y) / (double)scale; struct wlr_box box = { .x = 0, .y = 0, - .width = view->wlr_surface->current->buffer_width, - .height = view->wlr_surface->current->buffer_height, + .width = view->wlr_surface->current->buffer_width * scale, + .height = view->wlr_surface->current->buffer_height * scale, }; if (view->rotation != 0.0) { // Coordinates relative to the center of the view From c8f97a3a2c43948147e4225e09437884a848fa9d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 25 Oct 2017 23:03:30 -0400 Subject: [PATCH 05/25] Use surface matrix for software cursors A similar change should probably be applied to hardware cursors, though more complicated. Also, this doesn't actually fix the issue where the cursor is too small when over a scale=2 surface. Apparently they don't set their cursor scales to 2. Seems like a client bug? idk --- types/wlr_output.c | 13 +++++++++++-- types/wlr_surface.c | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index d6efd9bf..4bc9d6aa 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -429,8 +429,17 @@ void wlr_output_swap_buffers(struct wlr_output *output) { // with a NULL buffer to hide it if (renderer && texture && texture->valid) { float matrix[16]; - wlr_texture_get_matrix(texture, &matrix, &output->transform_matrix, - output->cursor.x, output->cursor.y); + if (output->cursor.surface) { + float translation[16]; + wlr_matrix_translate(&translation, + output->cursor.x, output->cursor.y, 0); + wlr_surface_get_matrix(output->cursor.surface, + &matrix, &output->transform_matrix, &translation); + } else { + wlr_texture_get_matrix(texture, + &matrix, &output->transform_matrix, + output->cursor.x, output->cursor.y); + } wlr_render_with_matrix(renderer, texture, &matrix); } } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index a21be8de..a6f91d47 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -656,7 +656,7 @@ void wlr_surface_get_matrix(struct wlr_surface *surface, if (transform) { wlr_matrix_mul(matrix, transform, matrix); } - wlr_matrix_scale(&scale, width, height, surface->current->scale); + wlr_matrix_scale(&scale, width, height, 1); wlr_matrix_mul(matrix, &scale, matrix); wlr_matrix_mul(projection, matrix, matrix); } From 8c0929cfb3e97a71a00210fc299fb7c65703e053 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 25 Oct 2017 23:27:12 -0400 Subject: [PATCH 06/25] Fix backwards bit banging --- types/wlr_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 4bc9d6aa..7a56eab6 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -28,7 +28,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { if (version >= WL_OUTPUT_MODE_SINCE_VERSION) { struct wlr_output_mode *mode; wl_list_for_each(mode, &output->modes, link) { - uint32_t flags = mode->flags & ~WL_OUTPUT_MODE_PREFERRED; + uint32_t flags = mode->flags & WL_OUTPUT_MODE_PREFERRED; if (output->current_mode == mode) { flags |= WL_OUTPUT_MODE_CURRENT; } From 7f76f463181872f39356e5a4d6e2e34fd9a0a1bb Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 25 Oct 2017 23:48:54 -0400 Subject: [PATCH 07/25] Adjust rendering to compensate for disparate scale Something about my math is off, but I'm not certain what. Would appreciate a second opinion. --- rootston/output.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/rootston/output.c b/rootston/output.c index faf39e74..37af1e2d 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -20,29 +20,35 @@ static void render_surface(struct wlr_surface *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double lx, double ly, float rotation) { if (surface->texture->valid) { - int width = surface->current->buffer_width; - int height = surface->current->buffer_height; + float scale_factor = (float)wlr_output->scale / surface->current->scale; + int width = surface->current->buffer_width * scale_factor; + int height = surface->current->buffer_height * scale_factor; double ox = lx, oy = ly; wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); if (wlr_output_layout_intersects(desktop->layout, wlr_output, lx, ly, lx + width, ly + height)) { - // TODO: accomodate for mismatched scale, which can happen, for - // example, when a view is rendered over two outputs float matrix[16]; float translate_origin[16]; wlr_matrix_translate(&translate_origin, (int)ox + width / 2, (int)oy + height / 2, 0); + float rotate[16]; wlr_matrix_rotate(&rotate, rotation); + float translate_center[16]; wlr_matrix_translate(&translate_center, -width / 2, -height / 2, 0); + + float scale[16]; + wlr_matrix_scale(&scale, width, height, 1); + float transform[16]; wlr_matrix_mul(&translate_origin, &rotate, &transform); wlr_matrix_mul(&transform, &translate_center, &transform); - wlr_surface_get_matrix(surface, &matrix, - &wlr_output->transform_matrix, &transform); + wlr_matrix_mul(&transform, &scale, &transform); + wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix); + wlr_render_with_matrix(desktop->server->renderer, surface->texture, &matrix); From ed74f473d60bb577aca9c7309664ae07d3ccf09b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 1 Nov 2017 08:57:30 -0400 Subject: [PATCH 08/25] Fix various rebase-related bugs --- rootston/desktop.c | 10 +- types/wlr_output.c | 454 ++++++++++++++++++++++++--------------------- 2 files changed, 252 insertions(+), 212 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index f7f12eff..a724a40c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -127,19 +127,21 @@ bool view_center(struct roots_view *view) { int width, height; wlr_output_effective_resolution(output, &width, &height); - double view_x = (double)(width - size.width) / 2 + l_output->x; - double view_y = (double)(height - size.height) / 2 + l_output->y; + double view_x = (double)(width - box.width) / 2 + l_output->x; + double view_y = (double)(height - box.height) / 2 + l_output->y; view_set_position(view, view_x, view_y); return true; } -void view_initialize(struct roots_view *view) { +void view_setup(struct roots_view *view) { struct roots_input *input = view->desktop->server->input; view_center(view); set_view_focus(input, view->desktop, view); wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); - view_update_output(view); + struct wlr_box before; + view_get_size(view, &before); + view_update_output(view, &before); } void view_teardown(struct roots_view *view) { diff --git a/types/wlr_output.c b/types/wlr_output.c index 7a56eab6..44d24ae3 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -28,7 +29,8 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { if (version >= WL_OUTPUT_MODE_SINCE_VERSION) { struct wlr_output_mode *mode; wl_list_for_each(mode, &output->modes, link) { - uint32_t flags = mode->flags & WL_OUTPUT_MODE_PREFERRED; + // TODO: mode->flags should just be preferred + uint32_t flags = mode->flags; if (output->current_mode == mode) { flags |= WL_OUTPUT_MODE_CURRENT; } @@ -134,7 +136,9 @@ static void wlr_output_update_matrix(struct wlr_output *output) { } void wlr_output_enable(struct wlr_output *output, bool enable) { - output->impl->enable(output, enable); + if (output->impl->enable) { + output->impl->enable(output, enable); + } } bool wlr_output_set_mode(struct wlr_output *output, @@ -187,192 +191,19 @@ void wlr_output_set_position(struct wlr_output *output, int32_t lx, } } -static 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) { - if (output->impl->set_cursor - && output->impl->set_cursor(output, buf, stride, width, height, - hotspot_x, hotspot_y, true)) { - output->cursor.is_sw = false; - return true; - } - - wlr_log(L_INFO, "Falling back to software cursor"); - - output->cursor.is_sw = true; - output->cursor.width = width; - output->cursor.height = height; - - if (!output->cursor.renderer) { - output->cursor.renderer = wlr_gles2_renderer_create(output->backend); - if (!output->cursor.renderer) { - return false; - } - } - - if (!output->cursor.texture) { - output->cursor.texture = - wlr_render_texture_create(output->cursor.renderer); - if (!output->cursor.texture) { - return false; - } - } - - return wlr_texture_upload_pixels(output->cursor.texture, - WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); -} - -bool wlr_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) { - if (output->cursor.surface) { - wl_list_remove(&output->cursor.surface_commit.link); - wl_list_remove(&output->cursor.surface_destroy.link); - output->cursor.surface = NULL; - } - - output->cursor.hotspot_x = hotspot_x; - output->cursor.hotspot_y = hotspot_y; - - return set_cursor(output, buf, stride, width, height, hotspot_x, hotspot_y); -} - -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; -} - -static void commit_cursor_surface(struct wlr_output *output, - struct wlr_surface *surface) { - if (output->cursor.is_sw) { - return; - } - - struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer); - if (buffer == NULL) { - return; - } - - uint32_t format = wl_shm_buffer_get_format(buffer); - if (format != WL_SHM_FORMAT_ARGB8888) { - return; - } - - void *buffer_data = wl_shm_buffer_get_data(buffer); - int32_t width = wl_shm_buffer_get_width(buffer); - int32_t height = wl_shm_buffer_get_height(buffer); - int32_t stride = wl_shm_buffer_get_stride(buffer); - wl_shm_buffer_begin_access(buffer); - wlr_output_set_cursor(output, buffer_data, stride/4, width, height, - output->cursor.hotspot_x - surface->current->sx, - output->cursor.hotspot_y - surface->current->sy); - wl_shm_buffer_end_access(buffer); -} - -static void handle_cursor_surface_commit(struct wl_listener *listener, - void *data) { - struct wlr_output *output = wl_container_of(listener, output, - cursor.surface_commit); - struct wlr_surface *surface = data; - - commit_cursor_surface(output, surface); - - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - - struct wlr_frame_callback *cb, *cnext; - wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list, - link) { - wl_callback_send_done(cb->resource, timespec_to_msec(&now)); - wl_resource_destroy(cb->resource); - } -} - -static void handle_cursor_surface_destroy(struct wl_listener *listener, - void *data) { - struct wlr_output *output = wl_container_of(listener, output, - cursor.surface_destroy); - - wl_list_remove(&output->cursor.surface_commit.link); - wl_list_remove(&output->cursor.surface_destroy.link); - output->cursor.surface = NULL; -} - -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, "wl_pointer-cursor") != 0) { - return; - } - - 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); - output->cursor.surface = 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) { - 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); - } else { - set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y); - } -} - -bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { - output->cursor.x = x; - output->cursor.y = y; - - if (output->cursor.is_sw) { - return true; - } - - if (!output->impl->move_cursor) { - return false; - } - - return output->impl->move_cursor(output, x, y); -} - void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, const struct wlr_output_impl *impl) { + assert(impl->make_current && impl->swap_buffers && impl->transform); output->backend = backend; output->impl = impl; wl_list_init(&output->modes); output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->scale = 1; + wl_list_init(&output->cursors); wl_signal_init(&output->events.frame); wl_signal_init(&output->events.swap_buffers); wl_signal_init(&output->events.resolution); wl_signal_init(&output->events.destroy); - - wl_list_init(&output->cursor.surface_commit.link); - output->cursor.surface_commit.notify = handle_cursor_surface_commit; - wl_list_init(&output->cursor.surface_destroy.link); - output->cursor.surface_destroy.notify = handle_cursor_surface_destroy; } void wlr_output_destroy(struct wlr_output *output) { @@ -382,9 +213,6 @@ void wlr_output_destroy(struct wlr_output *output) { wl_signal_emit(&output->events.destroy, output); - wlr_texture_destroy(output->cursor.texture); - wlr_renderer_destroy(output->cursor.renderer); - struct wlr_output_mode *mode, *tmp_mode; wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) { free(mode); @@ -399,6 +227,7 @@ void wlr_output_destroy(struct wlr_output *output) { void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height) { + // TODO: Scale factor if (output->transform % 2 == 1) { *width = output->height; *height = output->width; @@ -412,36 +241,62 @@ void wlr_output_make_current(struct wlr_output *output) { output->impl->make_current(output); } +static void output_cursor_get_box(struct wlr_output_cursor *cursor, + struct wlr_box *box) { + box->x = cursor->x - cursor->hotspot_x; + box->y = cursor->y - cursor->hotspot_y; + box->width = cursor->width; + box->height = cursor->height; +} + +static void output_cursor_render(struct wlr_output_cursor *cursor) { + struct wlr_texture *texture = cursor->texture; + struct wlr_renderer *renderer = cursor->renderer; + if (cursor->surface != NULL) { + // Some clients commit a cursor surface with a NULL buffer to hide it. + if (!wlr_surface_has_buffer(cursor->surface)) { + return; + } + texture = cursor->surface->texture; + renderer = cursor->surface->renderer; + } + + if (texture == NULL || renderer == NULL) { + return; + } + + struct wlr_box output_box; + output_box.x = output_box.y = 0; + output_box.width = cursor->output->width; + output_box.height = cursor->output->height; + + struct wlr_box cursor_box; + output_cursor_get_box(cursor, &cursor_box); + + struct wlr_box intersection; + struct wlr_box *intersection_ptr = &intersection; + if (!wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr)) { + return; + } + + glViewport(0, 0, cursor->output->width, cursor->output->height); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + float matrix[16]; + wlr_texture_get_matrix(texture, &matrix, + &cursor->output->transform_matrix, cursor->x - cursor->hotspot_x, + cursor->y - cursor->hotspot_y); + wlr_render_with_matrix(renderer, texture, &matrix); +} + void wlr_output_swap_buffers(struct wlr_output *output) { - if (output->cursor.is_sw) { - glViewport(0, 0, output->width, output->height); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - 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; - } - - // We check texture->valid because some clients set a cursor surface - // with a NULL buffer to hide it - if (renderer && texture && texture->valid) { - float matrix[16]; - if (output->cursor.surface) { - float translation[16]; - wlr_matrix_translate(&translation, - output->cursor.x, output->cursor.y, 0); - wlr_surface_get_matrix(output->cursor.surface, - &matrix, &output->transform_matrix, &translation); - } else { - wlr_texture_get_matrix(texture, - &matrix, &output->transform_matrix, - output->cursor.x, output->cursor.y); - } - wlr_render_with_matrix(renderer, texture, &matrix); + struct wlr_output_cursor *cursor; + wl_list_for_each(cursor, &output->cursors, link) { + if (output->hardware_cursor == cursor) { + continue; } + output_cursor_render(cursor); } wl_signal_emit(&output->events.swap_buffers, &output); @@ -462,3 +317,186 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { } return output->impl->get_gamma_size(output); } + +static void output_cursor_reset(struct wlr_output_cursor *cursor) { + if (cursor->surface != NULL) { + wl_list_remove(&cursor->surface_commit.link); + wl_list_remove(&cursor->surface_destroy.link); + cursor->surface = NULL; + } +} + +bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, + const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y) { + output_cursor_reset(cursor); + + cursor->width = width; + cursor->height = height; + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = hotspot_y; + + if (cursor->output->hardware_cursor == NULL && + cursor->output->impl->set_cursor) { + int ok = cursor->output->impl->set_cursor(cursor->output, pixels, + stride, width, height, hotspot_x, hotspot_y, true); + if (ok) { + cursor->output->hardware_cursor = cursor; + return true; + } + } + + wlr_log(L_INFO, "Falling back to software cursor"); + + if (cursor->renderer == NULL) { + cursor->renderer = wlr_gles2_renderer_create(cursor->output->backend); + if (cursor->renderer == NULL) { + return false; + } + } + + if (cursor->texture == NULL) { + cursor->texture = wlr_render_texture_create(cursor->renderer); + if (cursor->texture == NULL) { + return false; + } + } + + return wlr_texture_upload_pixels(cursor->texture, WL_SHM_FORMAT_ARGB8888, + stride, width, height, pixels); +} + +static void output_cursor_commit(struct wlr_output_cursor *cursor) { + cursor->width = cursor->surface->current->width; + cursor->height = cursor->surface->current->height; + + // TODO: if hardware cursor, upload pixels +} + +static inline int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + +static void output_cursor_handle_commit(struct wl_listener *listener, + void *data) { + struct wlr_output_cursor *cursor = wl_container_of(listener, cursor, + surface_commit); + struct wlr_surface *surface = data; + + output_cursor_commit(cursor); + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + struct wlr_frame_callback *cb, *cnext; + wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list, + link) { + wl_callback_send_done(cb->resource, timespec_to_msec(&now)); + wl_resource_destroy(cb->resource); + } +} + +static void output_cursor_handle_destroy(struct wl_listener *listener, + void *data) { + struct wlr_output_cursor *cursor = wl_container_of(listener, cursor, + surface_destroy); + output_cursor_reset(cursor); +} + +void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, + struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { + if (surface && strcmp(surface->role, "wl_pointer-cursor") != 0) { + return; + } + + if (surface) { + cursor->width = surface->current->width; + cursor->height = surface->current->height; + } + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = hotspot_y; + + if (surface && surface == cursor->surface) { + if (cursor->output->hardware_cursor == 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, + hotspot_x, hotspot_y, false); + } + return; + } + + output_cursor_reset(cursor); + + // Disable hardware cursor for surfaces + // TODO: support hardware cursors + if (cursor->output->hardware_cursor == cursor && + cursor->output->impl->set_cursor) { + cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, 0, 0, + true); + cursor->output->hardware_cursor = NULL; + } + + cursor->surface = surface; + + if (surface != NULL) { + wl_signal_add(&surface->events.commit, &cursor->surface_commit); + wl_signal_add(&surface->events.destroy, &cursor->surface_destroy); + output_cursor_commit(cursor); + } else { + // TODO: if hardware cursor, disable cursor + } +} + +bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) { + cursor->x = x; + cursor->y = y; + + if (cursor->output->hardware_cursor != cursor) { + return true; + } + + if (!cursor->output->impl->move_cursor) { + return false; + } + return cursor->output->impl->move_cursor(cursor->output, x, y); +} + +struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) { + struct wlr_output_cursor *cursor = + calloc(1, sizeof(struct wlr_output_cursor)); + if (cursor == NULL) { + return NULL; + } + cursor->output = output; + wl_list_init(&cursor->surface_commit.link); + cursor->surface_commit.notify = output_cursor_handle_commit; + wl_list_init(&cursor->surface_destroy.link); + cursor->surface_destroy.notify = output_cursor_handle_destroy; + wl_list_insert(&output->cursors, &cursor->link); + return cursor; +} + +void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { + if (cursor == NULL) { + return; + } + output_cursor_reset(cursor); + if (cursor->output->hardware_cursor == cursor) { + // If this cursor was the hardware cursor, disable it + if (cursor->output->impl->set_cursor) { + cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, 0, + 0, true); + } + cursor->output->hardware_cursor = NULL; + } + if (cursor->texture != NULL) { + wlr_texture_destroy(cursor->texture); + } + if (cursor->renderer != NULL) { + wlr_renderer_destroy(cursor->renderer); + } + wl_list_remove(&cursor->link); + free(cursor); +} From ca8cf7d48dc8de94494e23292c1687c1dad766f2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 2 Nov 2017 23:17:39 -0400 Subject: [PATCH 09/25] Rethink HiDPI output layouts, fixes everything Except for subsurfaces not rendering at the right scale. But that part is (somewhat) easy. --- rootston/desktop.c | 9 ++++----- rootston/output.c | 2 ++ types/wlr_output.c | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index a724a40c..f87be11e 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -167,15 +167,14 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, continue; } - int scale = view->wlr_surface->current->scale; - double view_sx = (lx - view->x) / (double)scale; - double view_sy = (ly - view->y) / (double)scale; + double view_sx = lx - view->x; + double view_sy = ly - view->y; struct wlr_box box = { .x = 0, .y = 0, - .width = view->wlr_surface->current->buffer_width * scale, - .height = view->wlr_surface->current->buffer_height * scale, + .width = view->wlr_surface->current->buffer_width, + .height = view->wlr_surface->current->buffer_height, }; if (view->rotation != 0.0) { // Coordinates relative to the center of the view diff --git a/rootston/output.c b/rootston/output.c index 37af1e2d..c21c6781 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -25,6 +25,8 @@ static void render_surface(struct wlr_surface *surface, int height = surface->current->buffer_height * scale_factor; double ox = lx, oy = ly; wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); + ox *= wlr_output->scale; + oy *= wlr_output->scale; if (wlr_output_layout_intersects(desktop->layout, wlr_output, lx, ly, lx + width, ly + height)) { diff --git a/types/wlr_output.c b/types/wlr_output.c index 44d24ae3..82e805b4 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -227,7 +227,6 @@ void wlr_output_destroy(struct wlr_output *output) { void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height) { - // TODO: Scale factor if (output->transform % 2 == 1) { *width = output->height; *height = output->width; @@ -235,6 +234,8 @@ void wlr_output_effective_resolution(struct wlr_output *output, *width = output->width; *height = output->height; } + *width /= output->scale; + *height /= output->scale; } void wlr_output_make_current(struct wlr_output *output) { @@ -450,6 +451,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, } bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) { + x *= cursor->output->scale; + y *= cursor->output->scale; cursor->x = x; cursor->y = y; From 975b9dc365d5a7bec531522320a1506323575525 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 2 Nov 2017 23:33:06 -0400 Subject: [PATCH 10/25] Fix view centering on HiDPI outputs --- rootston/desktop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rootston/desktop.c b/rootston/desktop.c index f87be11e..fe95426f 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -126,6 +126,8 @@ bool view_center(struct roots_view *view) { int width, height; wlr_output_effective_resolution(output, &width, &height); + width /= output->scale; + height /= output->scale; double view_x = (double)(width - box.width) / 2 + l_output->x; double view_y = (double)(height - box.height) / 2 + l_output->y; From 6d8e1abfc0a266e8ff1a8c9ba1a004faeaac79d5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 4 Nov 2017 01:35:12 -0400 Subject: [PATCH 11/25] Improve input sensitivity We now use doubles until the last minute, which makes it so we can move the pointer more precisely. This also includes a fix for tablet tools, which move absolutely and sometimes do not update the X or Y axis. --- backend/libinput/tablet_tool.c | 2 ++ include/wlr/types/wlr_output.h | 5 +++-- rootston/cursor.c | 9 +++++++++ types/wlr_cursor.c | 4 ++-- types/wlr_output.c | 6 ++++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 3caaf3f7..3d5fafc3 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -70,6 +70,8 @@ void handle_tablet_tool_axis(struct libinput_event *event, wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_WHEEL; wlr_event.wheel_delta = libinput_event_tablet_tool_get_wheel_delta(tevent); } + wlr_log(L_DEBUG, "Tablet tool axis event %d @ %f,%f", + wlr_event.updated_axes, wlr_event.x_mm, wlr_event.y_mm); wl_signal_emit(&wlr_dev->tablet_tool->events.axis, &wlr_event); } diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index e6323f9c..df123639 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -14,7 +14,7 @@ struct wlr_output_mode { struct wlr_output_cursor { struct wlr_output *output; - int32_t x, y; + double x, y; bool enabled; uint32_t width, height; int32_t hotspot_x, hotspot_y; @@ -95,7 +95,8 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, int32_t hotspot_x, int32_t hotspot_y); void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y); -bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y); +bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, + double x, double y); void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 31001a9f..aa8e5122 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -378,11 +378,20 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { static void handle_tool_axis(struct wl_listener *listener, void *data) { struct roots_input *input = wl_container_of(listener, input, cursor_tool_axis); struct wlr_event_tablet_tool_axis *event = data; + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { wlr_cursor_warp_absolute(input->cursor, event->device, event->x_mm / event->width_mm, event->y_mm / event->height_mm); cursor_update_position(input, event->time_msec); + } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { + wlr_cursor_warp_absolute(input->cursor, event->device, + event->x_mm / event->width_mm, -1); + cursor_update_position(input, event->time_msec); + } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + wlr_cursor_warp_absolute(input->cursor, event->device, + -1, event->y_mm / event->height_mm); + cursor_update_position(input, event->time_msec); } } diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 83d36d14..dfaccb53 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -261,8 +261,8 @@ void wlr_cursor_warp_absolute(struct wlr_cursor *cur, mapping = wlr_output_layout_get_box(cur->state->layout, NULL); } - double x = mapping->width * x_mm + mapping->x; - double y = mapping->height * y_mm + mapping->y; + double x = x_mm > 0 ? mapping->width * x_mm + mapping->x : cur->x; + double y = y_mm > 0 ? mapping->height * y_mm + mapping->y : cur->y; wlr_cursor_warp_unchecked(cur, x, y); } diff --git a/types/wlr_output.c b/types/wlr_output.c index ff8b07be..3ad69ce3 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -472,9 +472,11 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, } } -bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) { +bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, + double x, double y) { x *= cursor->output->scale; y *= cursor->output->scale; + wlr_log(L_DEBUG, "Moving cursor to %f,%f", x, y); cursor->x = x; cursor->y = y; @@ -486,7 +488,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) { if (!cursor->output->impl->move_cursor) { return false; } - return cursor->output->impl->move_cursor(cursor->output, x, y); + return cursor->output->impl->move_cursor(cursor->output, (int)x, (int)y); } struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) { From 2f6cfe4057fbef41977159e24fea0d19fbeeb052 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 4 Nov 2017 11:47:34 -0400 Subject: [PATCH 12/25] Fix software cursors on scaled outputs There was an issue where it would only work within the boundaries of the unscaled resolution. --- backend/wayland/output.c | 2 +- types/wlr_output.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 90f8b39a..c4301617 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -249,7 +249,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { wlr_output_init(&output->wlr_output, &backend->backend, &output_impl); struct wlr_output *wlr_output = &output->wlr_output; - wlr_output_update_size(wlr_output, 640, 480); + wlr_output_update_size(wlr_output, 1280, 720); strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make)); strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model)); snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%d", diff --git a/types/wlr_output.c b/types/wlr_output.c index 3ad69ce3..df02afec 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -270,6 +270,8 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { output_box.x = output_box.y = 0; wlr_output_effective_resolution(cursor->output, &output_box.width, &output_box.height); + output_box.width *= cursor->output->scale; + output_box.height *= cursor->output->scale; struct wlr_box cursor_box; output_cursor_get_box(cursor, &cursor_box); @@ -476,7 +478,6 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, double x, double y) { x *= cursor->output->scale; y *= cursor->output->scale; - wlr_log(L_DEBUG, "Moving cursor to %f,%f", x, y); cursor->x = x; cursor->y = y; From 03d3fdc15879c6fbdd24d5fe1d60f9a77402220d Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 5 Nov 2017 16:29:43 +0100 Subject: [PATCH 13/25] Basic maximization implementation for xdg-shell --- include/rootston/view.h | 12 +++++++++++ rootston/cursor.c | 9 ++++++++- rootston/desktop.c | 44 +++++++++++++++++++++++++++++++++++++++++ rootston/xdg_shell_v6.c | 24 +++++++++++++++++++++- 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 0913b42e..67643b94 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -48,8 +48,17 @@ enum roots_view_type { struct roots_view { struct roots_desktop *desktop; + double x, y; float rotation; + + bool maximized; + struct { + double x, y; + uint32_t width, height; + float rotation; + } saved; + // TODO: Something for roots-enforced width/height enum roots_view_type type; union { @@ -67,6 +76,7 @@ struct roots_view { #endif }; struct wlr_surface *wlr_surface; + // TODO: This would probably be better as a field that's updated on a // configure event from the xdg_shell // If not then this should follow the typical type/impl pattern we use @@ -77,6 +87,7 @@ struct roots_view { void (*resize)(struct roots_view *view, uint32_t width, uint32_t height); void (*move_resize)(struct roots_view *view, double x, double y, uint32_t width, uint32_t height); + void (*maximize)(struct roots_view *view, bool maximized); void (*close)(struct roots_view *view); }; @@ -86,6 +97,7 @@ void view_move(struct roots_view *view, double x, double y); void view_resize(struct roots_view *view, uint32_t width, uint32_t height); void view_move_resize(struct roots_view *view, double x, double y, uint32_t width, uint32_t height); +void view_maximize(struct roots_view *view, bool maximized); void view_close(struct roots_view *view); bool view_center(struct roots_view *view); void view_setup(struct roots_view *view); diff --git a/rootston/cursor.c b/rootston/cursor.c index b153e8c8..d97d518e 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -39,6 +39,8 @@ static void cursor_set_xcursor_image(struct roots_input *input, void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view) { + view_maximize(view, false); + input->mode = ROOTS_CURSOR_MOVE; input->offs_x = cursor->x; input->offs_y = cursor->y; @@ -54,6 +56,8 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view, uint32_t edges) { + view_maximize(view, false); + input->mode = ROOTS_CURSOR_RESIZE; input->offs_x = cursor->x; input->offs_y = cursor->y; @@ -74,6 +78,8 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view) { + view_maximize(view, false); + input->mode = ROOTS_CURSOR_ROTATE; input->offs_x = cursor->x; input->offs_y = cursor->y; @@ -102,7 +108,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { set_compositor_cursor = view_client != input->cursor_client; } if (set_compositor_cursor) { - struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme); + struct wlr_xcursor *xcursor = + get_default_xcursor(input->xcursor_theme); cursor_set_xcursor_image(input, xcursor->images[0]); input->cursor_client = NULL; } diff --git a/rootston/desktop.c b/rootston/desktop.c index 29f78ac7..f5d5925b 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -78,6 +78,50 @@ void view_move_resize(struct roots_view *view, double x, double y, view_resize(view, width, height); } +void view_maximize(struct roots_view *view, bool maximized) { + if (view->maximized == maximized) { + return; + } + + if (view->maximize) { + view->maximize(view, maximized); + } + + if (!view->maximized && maximized) { + struct wlr_box view_box; + view_get_size(view, &view_box); + + view->maximized = true; + view->saved.x = view->x; + view->saved.y = view->y; + view->saved.rotation = view->rotation; + view->saved.width = view_box.width; + view->saved.height = view_box.height; + + double output_x, output_y; + wlr_output_layout_closest_point(view->desktop->layout, NULL, + view->x + (double)view_box.width/2, + view->y + (double)view_box.height/2, + &output_x, &output_y); + struct wlr_output *output = wlr_output_layout_output_at( + view->desktop->layout, output_x, output_y); + struct wlr_box *output_box = + wlr_output_layout_get_box(view->desktop->layout, output); + + view_move_resize(view, output_box->x, output_box->y, output_box->width, + output_box->height); + view->rotation = 0; + } + + if (view->maximized && !maximized) { + view->maximized = false; + + view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, + view->saved.height); + view->rotation = view->saved.rotation; + } +} + void view_close(struct roots_view *view) { if (view->close) { view->close(view); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ca33c582..45691d16 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -84,6 +84,16 @@ static void move_resize(struct roots_view *view, double x, double y, wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); } +static void maximize(struct roots_view *view, bool maximized) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + return; + } + + wlr_xdg_toplevel_v6_set_maximized(surface, maximized); +} + static void close(struct roots_view *view) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; @@ -119,7 +129,18 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { } static void handle_commit(struct wl_listener *listener, void *data) { - // TODO is there anything we need to do here? + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, commit); + struct roots_view *view = roots_xdg_surface->view; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + return; + } + + if (view->maximized != surface->toplevel_state->current.maximized) { + view_maximize(view, surface->toplevel_state->current.maximized); + } } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -178,6 +199,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->activate = activate; view->resize = resize; view->move_resize = move_resize; + view->maximize = maximize; view->close = close; view->desktop = desktop; roots_surface->view = view; From 4df8be1a8f32ea59f88a179104885c0452a89d6e Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 8 Nov 2017 22:25:06 +0100 Subject: [PATCH 14/25] Better UX when moving/resizing/rotating maximized views --- rootston/cursor.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index d97d518e..80836ccd 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -39,13 +39,18 @@ static void cursor_set_xcursor_image(struct roots_input *input, void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view) { - view_maximize(view, false); - input->mode = ROOTS_CURSOR_MOVE; input->offs_x = cursor->x; input->offs_y = cursor->y; - input->view_x = view->x; - input->view_y = view->y; + if (view->maximized) { + input->view_x = view->saved.x; + input->view_y = view->saved.y; + } else { + input->view_x = view->x; + input->view_y = view->y; + } + + view_maximize(view, false); wlr_seat_pointer_clear_focus(input->wl_seat); struct wlr_xcursor *xcursor = get_move_xcursor(input->xcursor_theme); @@ -56,18 +61,25 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view, uint32_t edges) { - view_maximize(view, false); - input->mode = ROOTS_CURSOR_RESIZE; input->offs_x = cursor->x; input->offs_y = cursor->y; - input->view_x = view->x; - input->view_y = view->y; - struct wlr_box size; - view_get_size(view, &size); - input->view_width = size.width; - input->view_height = size.height; + if (view->maximized) { + input->view_x = view->saved.x; + input->view_y = view->saved.y; + input->view_width = view->saved.width; + input->view_height = view->saved.height; + } else { + input->view_x = view->x; + input->view_y = view->y; + struct wlr_box size; + view_get_size(view, &size); + input->view_width = size.width; + input->view_height = size.height; + } input->resize_edges = edges; + + view_maximize(view, false); wlr_seat_pointer_clear_focus(input->wl_seat); struct wlr_xcursor *xcursor = get_resize_xcursor(input->xcursor_theme, edges); @@ -78,12 +90,12 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view) { - view_maximize(view, false); - input->mode = ROOTS_CURSOR_ROTATE; input->offs_x = cursor->x; input->offs_y = cursor->y; input->view_rotation = view->rotation; + + view_maximize(view, false); wlr_seat_pointer_clear_focus(input->wl_seat); struct wlr_xcursor *xcursor = get_rotate_xcursor(input->xcursor_theme); From 2118c691b13c20d7100abfa02f9e274667501aef Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 8 Nov 2017 23:03:07 +0100 Subject: [PATCH 15/25] Add maximize support for xwayland in rootston --- include/rootston/view.h | 1 + rootston/xwayland.c | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 67643b94..f6ac0d23 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -36,6 +36,7 @@ struct roots_xwayland_surface { struct wl_listener request_configure; struct wl_listener request_move; struct wl_listener request_resize; + struct wl_listener request_maximize; struct wl_listener map_notify; struct wl_listener unmap_notify; }; diff --git a/rootston/xwayland.c b/rootston/xwayland.c index e3fc1c84..431586ba 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -85,6 +85,13 @@ static void close(struct roots_view *view) { wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); } +static void maximize(struct roots_view *view, bool maximized) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + + wlr_xwayland_surface_set_maximized(view->desktop->xwayland, + view->xwayland_surface, maximized); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); @@ -161,6 +168,17 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { view_begin_resize(input, cursor, view, e->edges); } +static void handle_request_maximize(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, request_resize); + struct roots_view *view = roots_surface->view; + struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + + bool maximized = xwayland_surface->maximized_vert && + xwayland_surface->maximized_horz; + view_maximize(view, maximized); +} + static void handle_map_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, map_notify); @@ -202,24 +220,24 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { if (roots_surface == NULL) { return; } + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); - roots_surface->request_configure.notify = handle_request_configure; wl_signal_add(&surface->events.request_configure, &roots_surface->request_configure); - roots_surface->map_notify.notify = handle_map_notify; wl_signal_add(&surface->events.map_notify, &roots_surface->map_notify); - roots_surface->unmap_notify.notify = handle_unmap_notify; wl_signal_add(&surface->events.unmap_notify, &roots_surface->unmap_notify); - roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); - roots_surface->request_resize.notify = handle_request_resize; - wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize); + wl_signal_add(&surface->events.request_resize, + &roots_surface->request_resize); + roots_surface->request_maximize.notify = handle_request_maximize; + wl_signal_add(&surface->events.request_maximize, + &roots_surface->request_maximize); struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (view == NULL) { @@ -237,6 +255,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->resize = resize; view->move = move; view->move_resize = move_resize; + view->maximize = maximize; view->close = close; roots_surface->view = view; wlr_list_add(desktop->views, view); From 758514fe5d67d226290694208a34f90d1a857d8e Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 9 Nov 2017 11:21:55 +0100 Subject: [PATCH 16/25] Fix xwayland _NET_WM_STATE handling --- rootston/xwayland.c | 2 +- xwayland/xwm.c | 54 ++++++++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 431586ba..1da61ec3 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -170,7 +170,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { static void handle_request_maximize(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = - wl_container_of(listener, roots_surface, request_resize); + wl_container_of(listener, roots_surface, request_maximize); struct roots_view *view = roots_surface->view; struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index f011587e..e5806d5b 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -823,41 +823,49 @@ static void xwm_handle_net_wm_state_message(struct wlr_xwm *xwm, if (!xsurface) { return; } + if (client_message->format != 32) { + return; + } - int maximized = xsurface_is_maximized(xsurface); + bool fullscreen = xsurface->fullscreen; + bool maximized = xsurface_is_maximized(xsurface); uint32_t action = client_message->data.data32[0]; - uint32_t property = client_message->data.data32[1]; + for (size_t i = 0; i < 2; ++i) { + uint32_t property = client_message->data.data32[1 + i]; - if (property == xwm->atoms[_NET_WM_STATE_FULLSCREEN] && - update_state(action, &xsurface->fullscreen)) { - xsurface_set_net_wm_state(xsurface); + if (property == xwm->atoms[_NET_WM_STATE_FULLSCREEN] && + update_state(action, &xsurface->fullscreen)) { + xsurface_set_net_wm_state(xsurface); + } else if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT] && + update_state(action, &xsurface->maximized_vert)) { + wlr_log(L_DEBUG, "cc sava"); + xsurface_set_net_wm_state(xsurface); + } else if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ] && + update_state(action, &xsurface->maximized_horz)) { + wlr_log(L_DEBUG, "mwa sava"); + xsurface_set_net_wm_state(xsurface); + } + } + // client_message->data.data32[3] is the source indication + // all other values are set to 0 + if (fullscreen != xsurface->fullscreen) { if (xsurface->fullscreen) { xsurface->saved_width = xsurface->width; xsurface->saved_height = xsurface->height; } wl_signal_emit(&xsurface->events.request_fullscreen, xsurface); - } else { - if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT] && - update_state(action, &xsurface->maximized_vert)) { - xsurface_set_net_wm_state(xsurface); + } + + if (maximized != xsurface_is_maximized(xsurface)) { + if (xsurface_is_maximized(xsurface)) { + xsurface->saved_width = xsurface->width; + xsurface->saved_height = xsurface->height; } - if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ] && - update_state(action, &xsurface->maximized_horz)) { - xsurface_set_net_wm_state(xsurface); - } - - if (maximized != xsurface_is_maximized(xsurface)) { - if (xsurface_is_maximized(xsurface)) { - xsurface->saved_width = xsurface->width; - xsurface->saved_height = xsurface->height; - } - - wl_signal_emit(&xsurface->events.request_maximize, xsurface); - } + wl_signal_emit(&xsurface->events.request_maximize, xsurface); } } @@ -1310,8 +1318,8 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm->atoms[_NET_ACTIVE_WINDOW], xwm->atoms[_NET_WM_MOVERESIZE], xwm->atoms[_NET_WM_STATE_FULLSCREEN], - xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ], xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT], + xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ], }; xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE, From 75fd9b8426953d98c57fc0f598bf3a3ace602c0c Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 9 Nov 2017 08:40:15 -0500 Subject: [PATCH 17/25] Remove extraneous keyboard send_enter --- rootston/desktop.c | 1 - 1 file changed, 1 deletion(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index df8a79f2..2448ffac 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -150,7 +150,6 @@ void view_setup(struct roots_view *view) { struct roots_input *input = view->desktop->server->input; view_center(view); set_view_focus(input, view->desktop, view); - wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); struct wlr_box before; view_get_size(view, &before); view_update_output(view, &before); From 26dadacb7199d28af672cca3f91713e173a41258 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 9 Nov 2017 20:06:05 +0100 Subject: [PATCH 18/25] Add wl_shell support for maximized views --- include/rootston/view.h | 3 ++- include/wlr/types/wlr_wl_shell.h | 2 ++ rootston/wl_shell.c | 28 ++++++++++++++++++++++++++++ types/wlr_wl_shell.c | 11 ++++------- xwayland/xwm.c | 2 -- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index f6ac0d23..1b0fb831 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -11,9 +11,10 @@ struct roots_wl_shell_surface { // TODO: Maybe destroy listener should go in roots_view struct wl_listener destroy; - struct wl_listener ping_timeout; struct wl_listener request_move; struct wl_listener request_resize; + struct wl_listener request_set_maximized; + struct wl_listener set_state; struct wl_listener surface_commit; }; diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 4e814817..1f0630f2 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -42,6 +42,8 @@ struct wlr_wl_shell_popup_grab { enum wlr_wl_shell_surface_state { WLR_WL_SHELL_SURFACE_STATE_NONE, WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL, + WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED, + WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN, WLR_WL_SHELL_SURFACE_STATE_TRANSIENT, WLR_WL_SHELL_SURFACE_STATE_POPUP, }; diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index e38eb697..3ac8fe61 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -49,6 +49,26 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { view_begin_resize(input, event->cursor, view, e->edges); } +static void handle_request_set_maximized(struct wl_listener *listener, + void *data) { + struct roots_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, request_set_maximized); + struct roots_view *view = roots_surface->view; + //struct wlr_wl_shell_surface_set_maximized_event *e = data; + view_maximize(view, true); +} + +static void handle_set_state(struct wl_listener *listener, void *data) { + struct roots_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, set_state); + struct roots_view *view = roots_surface->view; + struct wlr_wl_shell_surface *surface = view->wl_shell_surface; + if (view->maximized && + surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) { + view_maximize(view, false); + } +} + static void handle_surface_commit(struct wl_listener *listener, void *data) { // TODO do we need to do anything here? } @@ -60,6 +80,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_move.link); wl_list_remove(&roots_surface->request_resize.link); + wl_list_remove(&roots_surface->request_set_maximized.link); + wl_list_remove(&roots_surface->set_state.link); + wl_list_remove(&roots_surface->surface_commit.link); view_destroy(roots_surface->view); free(roots_surface); } @@ -93,6 +116,11 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { roots_surface->request_resize.notify = handle_request_resize; wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize); + roots_surface->request_set_maximized.notify = handle_request_set_maximized; + wl_signal_add(&surface->events.request_set_maximized, + &roots_surface->request_set_maximized); + roots_surface->set_state.notify = handle_set_state; + wl_signal_add(&surface->events.set_state, &roots_surface->set_state); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit); diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index fe61075e..f0287ba9 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -171,7 +171,6 @@ static void shell_surface_destroy_popup_state( } } - static void shell_surface_protocol_resize(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, enum wl_shell_surface_resize edges) { @@ -287,9 +286,8 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client, output = wl_resource_get_user_data(output_resource); } - if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL) { - return; - } + shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN, + NULL, NULL); struct wlr_wl_shell_surface_set_fullscreen_event *event = calloc(1, sizeof(struct wlr_wl_shell_surface_set_fullscreen_event)); @@ -377,9 +375,8 @@ static void shell_surface_protocol_set_maximized(struct wl_client *client, output = wl_resource_get_user_data(output_resource); } - if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL) { - return; - } + shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED, + NULL, NULL); struct wlr_wl_shell_surface_set_maximized_event *event = calloc(1, sizeof(struct wlr_wl_shell_surface_set_maximized_event)); diff --git a/xwayland/xwm.c b/xwayland/xwm.c index e5806d5b..dff9fac2 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -839,11 +839,9 @@ static void xwm_handle_net_wm_state_message(struct wlr_xwm *xwm, xsurface_set_net_wm_state(xsurface); } else if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT] && update_state(action, &xsurface->maximized_vert)) { - wlr_log(L_DEBUG, "cc sava"); xsurface_set_net_wm_state(xsurface); } else if (property == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ] && update_state(action, &xsurface->maximized_horz)) { - wlr_log(L_DEBUG, "mwa sava"); xsurface_set_net_wm_state(xsurface); } } From 0204f811b44a0a999666bc7601c9b38f7c5c1adb Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 9 Nov 2017 20:08:43 +0100 Subject: [PATCH 19/25] Remove xwayland view listeners on destroy --- rootston/xwayland.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 1da61ec3..b608b143 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -97,6 +97,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_container_of(listener, roots_surface, destroy); view_teardown(roots_surface->view); wl_list_remove(&roots_surface->destroy.link); + wl_list_remove(&roots_surface->request_configure.link); + wl_list_remove(&roots_surface->request_move.link); + wl_list_remove(&roots_surface->request_resize.link); + wl_list_remove(&roots_surface->request_maximize.link); wl_list_remove(&roots_surface->map_notify.link); wl_list_remove(&roots_surface->unmap_notify.link); view_destroy(roots_surface->view); From bf1b12a72500fb8cb41cbc60d29e602c25c97fc2 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 9 Nov 2017 21:41:11 +0100 Subject: [PATCH 20/25] Fix maximize delay in xdg-shell --- include/rootston/view.h | 1 + include/wlr/types/wlr_xdg_shell_v6.h | 2 ++ rootston/xdg_shell_v6.c | 19 ++++++++++++++----- types/wlr_xdg_shell_v6.c | 6 ++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 1b0fb831..956ba1d3 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -27,6 +27,7 @@ struct roots_xdg_surface_v6 { struct wl_listener destroy; struct wl_listener request_move; struct wl_listener request_resize; + struct wl_listener request_maximize; }; struct roots_xwayland_surface { diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index b0de41e2..bc78428b 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -126,6 +126,8 @@ struct wlr_xdg_surface_v6 { struct wl_signal ack_configure; struct wl_signal ping_timeout; + struct wl_signal request_maximize; + struct wl_signal request_fullscreen; struct wl_signal request_minimize; struct wl_signal request_move; struct wl_signal request_resize; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 45691d16..a86899be 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -128,9 +128,9 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { view_begin_resize(input, event->cursor, view, e->edges); } -static void handle_commit(struct wl_listener *listener, void *data) { +static void handle_request_maximize(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = - wl_container_of(listener, roots_xdg_surface, commit); + wl_container_of(listener, roots_xdg_surface, request_maximize); struct roots_view *view = roots_xdg_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; @@ -138,9 +138,15 @@ static void handle_commit(struct wl_listener *listener, void *data) { return; } - if (view->maximized != surface->toplevel_state->current.maximized) { - view_maximize(view, surface->toplevel_state->current.maximized); - } + view_maximize(view, surface->toplevel_state->next.maximized); +} + +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; + //struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + // TODO } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -185,6 +191,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->request_resize.notify = handle_request_resize; wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize); + roots_surface->request_maximize.notify = handle_request_maximize; + wl_signal_add(&surface->events.request_maximize, + &roots_surface->request_maximize); struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (!view) { diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index fc45bc17..c260fd5e 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -667,24 +667,28 @@ static void xdg_toplevel_protocol_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); surface->toplevel_state->next.maximized = true; + wl_signal_emit(&surface->events.request_maximize, surface); } static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); surface->toplevel_state->next.maximized = false; + wl_signal_emit(&surface->events.request_maximize, surface); } static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); surface->toplevel_state->next.fullscreen = true; + wl_signal_emit(&surface->events.request_fullscreen, surface); } static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); surface->toplevel_state->next.fullscreen = false; + wl_signal_emit(&surface->events.request_fullscreen, surface); } static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, @@ -1146,6 +1150,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_list_init(&surface->configure_list); wl_list_init(&surface->popups); + wl_signal_init(&surface->events.request_maximize); + wl_signal_init(&surface->events.request_fullscreen); wl_signal_init(&surface->events.request_minimize); wl_signal_init(&surface->events.request_move); wl_signal_init(&surface->events.request_resize); From 80bf3cfff05d3ddabf75b2e53ed040aff0bbae62 Mon Sep 17 00:00:00 2001 From: Timidger Date: Thu, 9 Nov 2017 18:38:13 -0800 Subject: [PATCH 21/25] Fixes #399 Adds wlr_data_device_manager destructor Fixed issues --- include/wlr/types/wlr_data_device.h | 5 +++++ types/wlr_data_device.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 691e2df8..f45c15a2 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -74,6 +74,11 @@ struct wlr_drag { struct wlr_data_device_manager *wlr_data_device_manager_create( struct wl_display *display); +/** + * Destroys a wlr_data_device_manager and removes its wl_data_device_manager global. + */ +void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager); + /** * Creates a new wl_data_offer if there is a wl_data_source currently set as * the seat selection and sends it to the seat client, followed by the diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index ea28ef50..df18317b 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -815,3 +815,11 @@ struct wlr_data_device_manager *wlr_data_device_manager_create( return manager; } + +void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) { + if (!manager) { + return; + } + wl_global_destroy(manager->global); + free(manager); +} From aafb00a15fd84b6d40f2efa52333eea5633b14e5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 10 Nov 2017 08:21:23 -0500 Subject: [PATCH 22/25] Fix centering views on scaled outputs --- rootston/desktop.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index 2448ffac..78bd271a 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -136,8 +136,6 @@ bool view_center(struct roots_view *view) { int width, height; wlr_output_effective_resolution(output, &width, &height); - width /= output->scale; - height /= output->scale; double view_x = (double)(width - box.width) / 2 + l_output->x; double view_y = (double)(height - box.height) / 2 + l_output->y; From 5be11a5c95457c6d4f6cd9720162f962286c2258 Mon Sep 17 00:00:00 2001 From: Eric Molitor Date: Fri, 10 Nov 2017 15:12:00 +0000 Subject: [PATCH 23/25] Remove VLA from session.h VLAs are optional C11 features and not supported by C++. --- backend/session/session.c | 2 +- include/wlr/backend/session.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/session/session.c b/backend/session/session.c index b14ca4d0..760830c3 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -257,7 +257,7 @@ static size_t explicit_find_gpus(struct wlr_session *session, * If it's not found, it returns the first valid GPU it finds. */ size_t wlr_session_find_gpus(struct wlr_session *session, - size_t ret_len, int ret[static ret_len]) { + size_t ret_len, int *ret) { const char *explicit = getenv("WLR_DRM_DEVICES"); if (explicit) { return explicit_find_gpus(session, ret_len, ret, explicit); diff --git a/include/wlr/backend/session.h b/include/wlr/backend/session.h index 94002bc5..5c822ea9 100644 --- a/include/wlr/backend/session.h +++ b/include/wlr/backend/session.h @@ -79,6 +79,6 @@ void wlr_session_signal_add(struct wlr_session *session, int fd, bool wlr_session_change_vt(struct wlr_session *session, unsigned vt); size_t wlr_session_find_gpus(struct wlr_session *session, - size_t ret_len, int ret[static ret_len]); + size_t ret_len, int *ret); #endif From f092a379556ed3bbca2043445305eee28ab8c850 Mon Sep 17 00:00:00 2001 From: Stefano Ragni Date: Sat, 11 Nov 2017 00:45:52 +0100 Subject: [PATCH 24/25] Fix typos --- backend/session/logind.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/session/logind.c b/backend/session/logind.c index 42b48e94..daff75b6 100644 --- a/backend/session/logind.c +++ b/backend/session/logind.c @@ -123,7 +123,7 @@ static bool logind_change_vt(struct wlr_session *base, unsigned vt) { return ret >= 0; } -static bool find_sesion_path(struct logind_session *session) { +static bool find_session_path(struct logind_session *session) { int ret; sd_bus_message *msg = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; @@ -303,7 +303,7 @@ static bool add_signal_matches(struct logind_session *session) { "member='%s'," "path='%s'"; - snprintf(str, sizeof(str), fmt, "Manager", "SesssionRemoved", "/org/freedesktop/login1"); + snprintf(str, sizeof(str), fmt, "Manager", "SessionRemoved", "/org/freedesktop/login1"); ret = sd_bus_add_match(session->bus, NULL, str, session_removed, session); if (ret < 0) { wlr_log(L_ERROR, "Failed to add D-Bus match: %s", strerror(-ret)); @@ -368,7 +368,7 @@ static struct wlr_session *logind_session_create(struct wl_display *disp) { goto error; } - if (!find_sesion_path(session)) { + if (!find_session_path(session)) { sd_bus_unref(session->bus); goto error; } From eb89f1dcd2dd820bc86ae0350774aff4d81408e8 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 11 Nov 2017 15:39:15 +0100 Subject: [PATCH 25/25] Fix resize issues with some xdg-shell apps. Also renames view_get_size to view_get_box to be more consistent with wlroots API and make it more obvious that x,y are set (while in roots_view.get_size this isn't the case). Fixes #407 --- include/rootston/view.h | 2 +- rootston/cursor.c | 8 ++++---- rootston/desktop.c | 18 +++++++++--------- rootston/xdg_shell_v6.c | 10 ++++++++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index f0d102cd..99b4ed78 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -94,7 +94,7 @@ struct roots_view { void (*close)(struct roots_view *view); }; -void view_get_size(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_move(struct roots_view *view, double x, double y); void view_resize(struct roots_view *view, uint32_t width, uint32_t height); diff --git a/rootston/cursor.c b/rootston/cursor.c index cbd03af1..81841b6c 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -72,10 +72,10 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, } else { input->view_x = view->x; input->view_y = view->y; - struct wlr_box size; - view_get_size(view, &size); - input->view_width = size.width; - input->view_height = size.height; + struct wlr_box box; + view_get_box(view, &box); + input->view_width = box.width; + input->view_height = box.height; } input->resize_edges = edges; diff --git a/rootston/desktop.c b/rootston/desktop.c index 469a503b..0f5f5fdd 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -35,15 +35,15 @@ void view_destroy(struct roots_view *view) { free(view); } -void view_get_size(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->y = view->y; if (view->get_size) { view->get_size(view, box); } else { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; } - box->x = view->x; - box->y = view->y; } static void view_update_output(const struct roots_view *view, @@ -51,7 +51,7 @@ static void view_update_output(const struct roots_view *view, struct roots_desktop *desktop = view->desktop; struct roots_output *output; struct wlr_box box; - view_get_size(view, &box); + view_get_box(view, &box); wl_list_for_each(output, &desktop->outputs, link) { bool intersected = before->x != -1 && wlr_output_layout_intersects( desktop->layout, output->wlr_output, @@ -71,7 +71,7 @@ static void view_update_output(const struct roots_view *view, void view_move(struct roots_view *view, double x, double y) { struct wlr_box before; - view_get_size(view, &before); + view_get_box(view, &before); if (view->move) { view->move(view, x, y); } else { @@ -88,7 +88,7 @@ void view_activate(struct roots_view *view, bool activate) { void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { struct wlr_box before; - view_get_size(view, &before); + view_get_box(view, &before); if (view->resize) { view->resize(view, width, height); } @@ -117,7 +117,7 @@ void view_maximize(struct roots_view *view, bool maximized) { if (!view->maximized && maximized) { struct wlr_box view_box; - view_get_size(view, &view_box); + view_get_box(view, &view_box); view->maximized = true; view->saved.x = view->x; @@ -158,7 +158,7 @@ void view_close(struct roots_view *view) { bool view_center(struct roots_view *view) { struct wlr_box box; - view_get_size(view, &box); + view_get_box(view, &box); struct roots_desktop *desktop = view->desktop; struct wlr_cursor *cursor = desktop->server->input->cursor; @@ -193,7 +193,7 @@ void view_setup(struct roots_view *view) { view_center(view); set_view_focus(input, view->desktop, view); struct wlr_box before; - view_get_size(view, &before); + view_get_box(view, &before); view_update_output(view, &before); } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 2a0660a6..5e76e5d4 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -13,8 +13,14 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - // TODO: surf->geometry can be NULL - memcpy(box, surf->geometry, sizeof(struct wlr_box)); + + if (surf->geometry->width > 0 && surf->geometry->height > 0) { + box->width = surf->geometry->width; + box->height = surf->geometry->height; + } else { + box->width = view->wlr_surface->current->width; + box->height = view->wlr_surface->current->height; + } } static void activate(struct roots_view *view, bool active) {