From e2843d87c868341869cf905f6c77531e78d997ad Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 17 Nov 2017 23:52:42 +0100 Subject: Ensure to move the view when configured --- include/wlr/types/wlr_xdg_shell_v6.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index e3982003..d0e7957b 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -107,7 +107,9 @@ struct wlr_xdg_surface_v6 { bool configured; bool added; + uint32_t configure_serial; struct wl_event_source *configure_idle; + uint32_t configure_next_serial; struct wl_list configure_list; char *title; @@ -171,37 +173,38 @@ void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell); void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface); /** - * Request that this toplevel surface be the given size. + * Request that this toplevel surface be the given size. Returns the associated + * configure serial. */ -void wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t width, uint32_t height); /** * Request that this toplevel surface show itself in an activated or deactivated - * state. + * state. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, bool activated); /** * Request that this toplevel surface consider itself maximized or not - * maximized. + * maximized. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, bool maximized); /** * Request that this toplevel surface consider itself fullscreen or not - * fullscreen. + * fullscreen. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, bool fullscreen); /** * Request that this toplevel surface consider itself to be resizing or not - * resizing. + * resizing. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing); /** @@ -223,4 +226,5 @@ void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *surface, double sx, double sy, double *popup_sx, double *popup_sy); + #endif -- cgit v1.2.3 From a3a8b7bfd8d1616cdf9f7ba911616ca0baeedc67 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 09:09:23 +0100 Subject: Fixed a bug with move-resize, removed xdg-shell ack_configure event Fixed move-resizing a view when only one coordinate changes. --- include/rootston/view.h | 1 + include/wlr/types/wlr_xdg_shell_v6.h | 1 - rootston/cursor.c | 8 +------- rootston/desktop.c | 5 +++++ rootston/xdg_shell_v6.c | 31 ++++++++++++++++++++++++------- types/wlr_xdg_shell_v6.c | 3 --- 6 files changed, 31 insertions(+), 18 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/view.h b/include/rootston/view.h index 66616207..058dc73e 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -32,6 +32,7 @@ struct roots_xdg_surface_v6 { struct { uint32_t configure_serial; double x, y; + bool update_x, update_y; uint32_t width, height; } move_resize; }; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index d0e7957b..6ac84cef 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -125,7 +125,6 @@ struct wlr_xdg_surface_v6 { struct { struct wl_signal commit; struct wl_signal destroy; - struct wl_signal ack_configure; struct wl_signal ping_timeout; struct wl_signal request_maximize; diff --git a/rootston/cursor.c b/rootston/cursor.c index 5949a364..d4c4510a 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -98,13 +98,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t height = 0; } - if (active_x != seat->focus->x || - active_y != seat->focus->y) { - view_move_resize(seat->focus, active_x, active_y, - width, height); - } else { - view_resize(seat->focus, width, height); - } + view_move_resize(seat->focus, active_x, active_y, width, height); } break; case ROOTS_CURSOR_ROTATE: diff --git a/rootston/desktop.c b/rootston/desktop.c index 1695d007..be63d7f5 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -103,6 +103,11 @@ 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) { + if (x == view->x == x && y == view->y) { + view_resize(view, width, height); + return; + } + if (view->move_resize) { view->move_resize(view, x, y, width, height); return; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index d91fc2d9..5a55b8c4 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -76,15 +76,24 @@ static void move_resize(struct roots_view *view, double x, double y, return; } + bool update_x = x != view->x; + bool update_y = y != view->y; + uint32_t constrained_width, constrained_height; apply_size_constraints(surface, width, height, &constrained_width, &constrained_height); - x = x + width - constrained_width; - y = y + height - constrained_height; + if (update_x) { + x = x + width - constrained_width; + } + if (update_y) { + y = y + height - constrained_height; + } roots_surface->move_resize.x = x; roots_surface->move_resize.y = y; + roots_surface->move_resize.update_x = update_x; + roots_surface->move_resize.update_y = update_y; roots_surface->move_resize.width = constrained_width; roots_surface->move_resize.height = constrained_height; @@ -158,12 +167,20 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (roots_surface->move_resize.configure_serial == + if (roots_surface->move_resize.configure_serial > 0 && + roots_surface->move_resize.configure_serial == surface->configure_serial) { - view->x = roots_surface->move_resize.x + - roots_surface->move_resize.width - surface->geometry->width; - view->y = roots_surface->move_resize.y + - roots_surface->move_resize.height - surface->geometry->height; + struct wlr_box size; + get_size(view, &size); + + if (roots_surface->move_resize.update_x) { + view->x = roots_surface->move_resize.x + + roots_surface->move_resize.width - size.width; + } + if (roots_surface->move_resize.update_y) { + view->y = roots_surface->move_resize.y + + roots_surface->move_resize.height - size.height; + } roots_surface->move_resize.configure_serial = 0; } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index dfe5ddc5..8bb48a24 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -814,8 +814,6 @@ static void xdg_surface_ack_configure(struct wl_client *client, surface->configured = true; surface->configure_serial = serial; - wl_signal_emit(&surface->events.ack_configure, surface); - free(configure); } @@ -1155,7 +1153,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.request_show_window_menu); wl_signal_init(&surface->events.commit); wl_signal_init(&surface->events.destroy); - wl_signal_init(&surface->events.ack_configure); wl_signal_init(&surface->events.ping_timeout); wl_signal_add(&surface->surface->events.destroy, -- cgit v1.2.3 From b04a9a248d4cf3d0e93e1b39ee9eedc9da359173 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 17:27:36 +0100 Subject: Initial fullscreen support --- include/rootston/view.h | 6 +++ include/wlr/types/wlr_output.h | 6 +++ include/wlr/types/wlr_xdg_shell_v6.h | 7 ++++ rootston/desktop.c | 69 +++++++++++++++++++++++++++++++---- rootston/output.c | 7 ++++ rootston/wl_shell.c | 20 ++++++++++ rootston/xdg_shell_v6.c | 29 +++++++++++++++ types/wlr_output.c | 67 ++++++++++++++++++++++++++++++++++ types/wlr_xdg_shell_v6.c | 71 ++++++++++++++++++++---------------- 9 files changed, 244 insertions(+), 38 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/view.h b/include/rootston/view.h index 69034d60..e1397b89 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -13,6 +13,7 @@ struct roots_wl_shell_surface { struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_set_maximized; + struct wl_listener request_set_fullscreen; struct wl_listener set_state; struct wl_listener surface_commit; @@ -26,6 +27,7 @@ struct roots_xdg_surface_v6 { struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_maximize; + struct wl_listener request_fullscreen; }; struct roots_xwayland_surface { @@ -54,6 +56,7 @@ struct roots_view { float rotation; bool maximized; + struct wlr_output *fullscreen_output; struct { double x, y; uint32_t width, height; @@ -93,6 +96,7 @@ struct roots_view { 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 (*set_fullscreen)(struct roots_view *view, bool fullscreen); void (*close)(struct roots_view *view); }; @@ -103,6 +107,8 @@ 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_set_fullscreen(struct roots_view *view, bool fullscreen, + struct wlr_output *output); void view_close(struct roots_view *view); bool view_center(struct roots_view *view); void view_setup(struct roots_view *view); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index cf000019..d382b593 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -64,6 +64,10 @@ struct wlr_output { struct wl_signal destroy; } events; + struct wlr_surface *fullscreen_surface; + struct wl_listener fullscreen_surface_commit; + struct wl_listener fullscreen_surface_destroy; + struct wl_list cursors; // wlr_output_cursor::link struct wlr_output_cursor *hardware_cursor; @@ -89,6 +93,8 @@ void wlr_output_swap_buffers(struct wlr_output *output); void wlr_output_set_gamma(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t wlr_output_get_gamma_size(struct wlr_output *output); +void wlr_output_set_fullscreen_surface(struct wlr_output *output, + struct wlr_surface *surface); struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output); bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index e3982003..7940deef 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -152,6 +152,13 @@ struct wlr_xdg_toplevel_v6_resize_event { uint32_t edges; }; +struct wlr_xdg_toplevel_v6_set_fullscreen_event { + struct wl_client *client; + struct wlr_xdg_surface_v6 *surface; + bool fullscreen; + struct wlr_output *output; +}; + struct wlr_xdg_toplevel_v6_show_window_menu_event { struct wl_client *client; struct wlr_xdg_surface_v6 *surface; diff --git a/rootston/desktop.c b/rootston/desktop.c index cf5a8cdc..be74b619 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -89,6 +89,19 @@ void view_move_resize(struct roots_view *view, double x, double y, view_resize(view, width, height); } +static struct wlr_output *view_get_output(struct roots_view *view) { + struct wlr_box view_box; + view_get_box(view, &view_box); + + 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); + return wlr_output_layout_output_at(view->desktop->layout, output_x, + output_y); +} + void view_maximize(struct roots_view *view, bool maximized) { if (view->maximized == maximized) { return; @@ -109,13 +122,7 @@ void view_maximize(struct roots_view *view, bool maximized) { 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_output *output = view_get_output(view); struct wlr_box *output_box = wlr_output_layout_get_box(view->desktop->layout, output); @@ -133,6 +140,54 @@ void view_maximize(struct roots_view *view, bool maximized) { } } +void view_set_fullscreen(struct roots_view *view, bool fullscreen, + struct wlr_output *output) { + bool was_fullscreen = view->fullscreen_output != NULL; + if (was_fullscreen == fullscreen) { + // TODO: support changing the output? + return; + } + + // TODO: check if client is focused? + + if (view->set_fullscreen) { + view->set_fullscreen(view, fullscreen); + } + + if (!was_fullscreen && fullscreen) { + if (output == NULL) { + output = view_get_output(view); + } + + struct wlr_box view_box; + view_get_box(view, &view_box); + + 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; + + 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; + + wlr_output_set_fullscreen_surface(output, view->wlr_surface); + view->fullscreen_output = output; + } + + if (was_fullscreen && !fullscreen) { + view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, + view->saved.height); + view->rotation = view->saved.rotation; + + wlr_output_set_fullscreen_surface(view->fullscreen_output, NULL); + view->fullscreen_output = NULL; + } +} + void view_close(struct roots_view *view) { if (view->close) { view->close(view); diff --git a/rootston/output.c b/rootston/output.c index 83ff37fd..35a5dac3 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -186,6 +186,13 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_output_make_current(wlr_output); wlr_renderer_begin(server->renderer, wlr_output); + if (wlr_output->fullscreen_surface != NULL) { + wlr_renderer_end(server->renderer); + wlr_output_swap_buffers(wlr_output); + output->last_frame = desktop->last_frame = now; + return; + } + struct roots_view *view; wl_list_for_each_reverse(view, &desktop->views, link) { render_view(view, desktop, wlr_output, &now); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 7359c878..f285d7f6 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -59,6 +59,17 @@ static void handle_request_set_maximized(struct wl_listener *listener, view_maximize(view, true); } +static void handle_request_set_fullscreen(struct wl_listener *listener, + void *data) { + struct roots_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, request_set_fullscreen); + struct roots_view *view = roots_surface->view; + struct wlr_wl_shell_surface_set_fullscreen_event *e = data; + + // TODO: support e->method, e->framerate + view_set_fullscreen(view, true, e->output); +} + 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); @@ -68,6 +79,10 @@ static void handle_set_state(struct wl_listener *listener, void *data) { surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) { view_maximize(view, false); } + if (view->fullscreen_output != NULL && + surface->state != WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN) { + view_set_fullscreen(view, false, NULL); + } } static void handle_surface_commit(struct wl_listener *listener, void *data) { @@ -81,6 +96,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { 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->request_set_fullscreen.link); wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->surface_commit.link); view_destroy(roots_surface->view); @@ -111,6 +127,10 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { 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->request_set_fullscreen.notify = + handle_request_set_fullscreen; + wl_signal_add(&surface->events.request_set_fullscreen, + &roots_surface->request_set_fullscreen); 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; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 656231c7..9017f7bd 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -100,6 +100,16 @@ static void maximize(struct roots_view *view, bool maximized) { wlr_xdg_toplevel_v6_set_maximized(surface, maximized); } +static void set_fullscreen(struct roots_view *view, bool fullscreen) { + 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_fullscreen(surface, fullscreen); +} + 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; @@ -150,6 +160,21 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { view_maximize(view, surface->toplevel_state->next.maximized); } +static void handle_request_fullscreen(struct wl_listener *listener, + void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, request_fullscreen); + struct roots_view *view = roots_xdg_surface->view; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + struct wlr_xdg_toplevel_v6_set_fullscreen_event *e = data; + + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + return; + } + + view_set_fullscreen(view, e->fullscreen, e->output); +} + 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); @@ -202,6 +227,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->request_maximize.notify = handle_request_maximize; wl_signal_add(&surface->events.request_maximize, &roots_surface->request_maximize); + roots_surface->request_fullscreen.notify = handle_request_fullscreen; + wl_signal_add(&surface->events.request_fullscreen, + &roots_surface->request_fullscreen); struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (!view) { @@ -217,6 +245,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->resize = resize; view->move_resize = move_resize; view->maximize = maximize; + view->set_fullscreen = set_fullscreen; view->close = close; roots_surface->view = view; view_init(view, desktop); diff --git a/types/wlr_output.c b/types/wlr_output.c index 411dd404..5a8baa3d 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -252,6 +252,24 @@ void wlr_output_make_current(struct wlr_output *output) { output->impl->make_current(output); } +static void output_fullscreen_surface_render(struct wlr_output *output, + struct wlr_surface *surface) { + int x = (output->width - surface->current->width) / 2; + int y = (output->height - surface->current->height) / 2; + + glViewport(0, 0, output->width, output->height); + glClearColor(0, 0, 0, 0); + + if (!wlr_surface_has_buffer(surface)) { + return; + } + + float matrix[16]; + wlr_texture_get_matrix(surface->texture, &matrix, &output->transform_matrix, + x, y); + wlr_render_with_matrix(surface->renderer, surface->texture, &matrix); +} + static void output_cursor_get_box(struct wlr_output_cursor *cursor, struct wlr_box *box) { box->x = cursor->x - cursor->hotspot_x; @@ -308,6 +326,10 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { void wlr_output_swap_buffers(struct wlr_output *output) { wl_signal_emit(&output->events.swap_buffers, &output); + if (output->fullscreen_surface != NULL) { + output_fullscreen_surface_render(output, output->fullscreen_surface); + } + struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { if (!cursor->enabled || output->hardware_cursor == cursor) { @@ -334,6 +356,51 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { return output->impl->get_gamma_size(output); } +static void output_fullscreen_surface_reset(struct wlr_output *output) { + if (output->fullscreen_surface != NULL) { + wl_list_remove(&output->fullscreen_surface_commit.link); + wl_list_remove(&output->fullscreen_surface_destroy.link); + output->fullscreen_surface = NULL; + output->needs_swap = true; + } +} + +static void output_fullscreen_surface_handle_commit( + struct wl_listener *listener, void *data) { + struct wlr_output *output = wl_container_of(listener, output, + fullscreen_surface_destroy); + output->needs_swap = true; +} + +static void output_fullscreen_surface_handle_destroy( + struct wl_listener *listener, void *data) { + struct wlr_output *output = wl_container_of(listener, output, + fullscreen_surface_destroy); + output_fullscreen_surface_reset(output); +} + +void wlr_output_set_fullscreen_surface(struct wlr_output *output, + struct wlr_surface *surface) { + // TODO: hardware fullscreen + output_fullscreen_surface_reset(output); + + output->fullscreen_surface = surface; + output->needs_swap = true; + + if (surface == NULL) { + return; + } + + output->fullscreen_surface_commit.notify = + output_fullscreen_surface_handle_commit; + wl_signal_add(&surface->events.commit, &output->fullscreen_surface_commit); + output->fullscreen_surface_destroy.notify = + output_fullscreen_surface_handle_destroy; + wl_signal_add(&surface->events.destroy, + &output->fullscreen_surface_destroy); +} + + static void output_cursor_reset(struct wlr_output_cursor *cursor) { if (cursor->output->hardware_cursor != cursor) { cursor->output->needs_swap = true; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 429baa70..896a5f33 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -597,21 +597,14 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, return; } - struct wlr_xdg_toplevel_v6_move_event *event = - calloc(1, sizeof(struct wlr_xdg_toplevel_v6_move_event)); - if (event == NULL) { - wl_client_post_no_memory(client); - return; - } - - event->client = client; - event->surface = surface; - event->seat = seat; - event->serial = serial; - - wl_signal_emit(&surface->events.request_move, event); + struct wlr_xdg_toplevel_v6_move_event event = { + .client = client, + .surface = surface, + .seat = seat, + .serial = serial, + }; - free(event); + wl_signal_emit(&surface->events.request_move, &event); } static void xdg_toplevel_protocol_resize(struct wl_client *client, @@ -628,22 +621,15 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, return; } - struct wlr_xdg_toplevel_v6_resize_event *event = - calloc(1, sizeof(struct wlr_xdg_toplevel_v6_resize_event)); - if (event == NULL) { - wl_client_post_no_memory(client); - return; - } - - event->client = client; - event->surface = surface; - event->seat = seat; - event->serial = serial; - event->edges = edges; - - wl_signal_emit(&surface->events.request_resize, event); + struct wlr_xdg_toplevel_v6_resize_event event = { + .client = client, + .surface = surface, + .seat = seat, + .serial = serial, + .edges = edges, + }; - free(event); + wl_signal_emit(&surface->events.request_resize, &event); } static void xdg_toplevel_protocol_set_max_size(struct wl_client *client, @@ -677,15 +663,38 @@ static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client, 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); + + struct wlr_output *output = NULL; + if (output_resource != NULL) { + output = wl_resource_get_user_data(output_resource); + } + surface->toplevel_state->next.fullscreen = true; - wl_signal_emit(&surface->events.request_fullscreen, surface); + + struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { + .client = client, + .surface = surface, + .fullscreen = true, + .output = output, + }; + + wl_signal_emit(&surface->events.request_fullscreen, &event); } 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); + + struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { + .client = client, + .surface = surface, + .fullscreen = false, + .output = NULL, + }; + + wl_signal_emit(&surface->events.request_fullscreen, &event); } static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, -- cgit v1.2.3 From 54f1135c057e76b1c05058592a6878a07a524b99 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 20:53:13 +0100 Subject: Fix fullscreen in xdg-shell --- include/wlr/types/wlr_surface.h | 8 ++++++-- rootston/output.c | 12 +----------- types/wlr_output.c | 39 +++++++++++++++++++-------------------- types/wlr_surface.c | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 33 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index cea53109..c8e3761a 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -1,9 +1,10 @@ #ifndef WLR_TYPES_WLR_SURFACE_H #define WLR_TYPES_WLR_SURFACE_H -#include -#include #include #include +#include +#include +#include #include struct wlr_frame_callback { @@ -142,4 +143,7 @@ void wlr_surface_send_enter(struct wlr_surface *surface, void wlr_surface_send_leave(struct wlr_surface *surface, struct wlr_output *output); +void wlr_surface_send_frame_done(struct wlr_surface *surface, + const struct timespec *when); + #endif diff --git a/rootston/output.c b/rootston/output.c index 82618b06..52db62f1 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -13,10 +13,6 @@ #include "rootston/desktop.h" #include "rootston/config.h" -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; -} - /** * Rotate a child's position relative to a parent. The parent size is (pw, ph), * the child position is (*sx, *sy) and its size is (sw, sh). @@ -75,12 +71,7 @@ static void render_surface(struct wlr_surface *surface, wlr_render_with_matrix(desktop->server->renderer, surface->texture, &matrix); - 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(when)); - wl_resource_destroy(cb->resource); - } + wlr_surface_send_frame_done(surface, when); } struct wlr_subsurface *subsurface; @@ -176,7 +167,6 @@ static void render_view(struct roots_view *view, struct roots_desktop *desktop, static bool has_standalone_surface(struct roots_view *view) { if (!wl_list_empty(&view->wlr_surface->subsurface_list)) { - wlr_log(L_DEBUG, "has subsurfaces"); return false; } diff --git a/types/wlr_output.c b/types/wlr_output.c index 3ef91179..8accf7a5 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -253,7 +253,7 @@ void wlr_output_make_current(struct wlr_output *output) { } static void output_fullscreen_surface_render(struct wlr_output *output, - struct wlr_surface *surface) { + struct wlr_surface *surface, const struct timespec *when) { int x = (output->width - surface->current->width) / 2; int y = (output->height - surface->current->height) / 2; @@ -268,6 +268,8 @@ static void output_fullscreen_surface_render(struct wlr_output *output, wlr_texture_get_matrix(surface->texture, &matrix, &output->transform_matrix, x, y); wlr_render_with_matrix(surface->renderer, surface->texture, &matrix); + + wlr_surface_send_frame_done(surface, when); } static void output_cursor_get_box(struct wlr_output_cursor *cursor, @@ -278,7 +280,8 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor, box->height = cursor->height; } -static void output_cursor_render(struct wlr_output_cursor *cursor) { +static void output_cursor_render(struct wlr_output_cursor *cursor, + const struct timespec *when) { struct wlr_texture *texture = cursor->texture; struct wlr_renderer *renderer = cursor->renderer; if (cursor->surface != NULL) { @@ -321,13 +324,21 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { wlr_texture_get_matrix(texture, &matrix, &cursor->output->transform_matrix, x, y); wlr_render_with_matrix(renderer, texture, &matrix); + + if (cursor->surface != NULL) { + wlr_surface_send_frame_done(cursor->surface, when); + } } void wlr_output_swap_buffers(struct wlr_output *output) { wl_signal_emit(&output->events.swap_buffers, &output); + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + if (output->fullscreen_surface != NULL) { - output_fullscreen_surface_render(output, output->fullscreen_surface); + output_fullscreen_surface_render(output, output->fullscreen_surface, + &now); } struct wlr_output_cursor *cursor; @@ -335,7 +346,7 @@ void wlr_output_swap_buffers(struct wlr_output *output) { if (!cursor->enabled || output->hardware_cursor == cursor) { continue; } - output_cursor_render(cursor); + output_cursor_render(cursor, &now); } output->impl->swap_buffers(output); @@ -472,30 +483,18 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor) { cursor->output->needs_swap = true; } else { // TODO: upload pixels - } -} -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + wlr_surface_send_frame_done(cursor->surface, &now); + } } 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, diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 8cc2aa33..ad0c6f68 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -929,3 +929,17 @@ void wlr_surface_send_leave(struct wlr_surface *surface, } } } + +static inline int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + +void wlr_surface_send_frame_done(struct wlr_surface *surface, + const struct timespec *when) { + 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(when)); + wl_resource_destroy(cb->resource); + } +} -- cgit v1.2.3 From 17d9e2ce3508d21ccdc9907b02d127b47a4a21bb Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 21 Nov 2017 09:50:00 +0100 Subject: Unify view events naming, remove client from event structs --- include/rootston/view.h | 4 +- include/wlr/types/wlr_wl_shell.h | 10 ++--- include/wlr/types/wlr_xdg_shell_v6.h | 7 +-- rootston/wl_shell.c | 30 ++++++------- types/wlr_wl_shell.c | 87 +++++++++++------------------------- types/wlr_xdg_shell_v6.c | 28 ++++-------- 6 files changed, 55 insertions(+), 111 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/view.h b/include/rootston/view.h index 44a98115..5901f0a5 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -12,8 +12,8 @@ struct roots_wl_shell_surface { struct wl_listener destroy; struct wl_listener request_move; struct wl_listener request_resize; - struct wl_listener request_set_maximized; - struct wl_listener request_set_fullscreen; + struct wl_listener request_maximize; + struct wl_listener request_fullscreen; 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 24936a34..ec087693 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -81,8 +81,8 @@ struct wlr_wl_shell_surface { struct wl_signal request_move; struct wl_signal request_resize; - struct wl_signal request_set_fullscreen; - struct wl_signal request_set_maximized; + struct wl_signal request_fullscreen; + struct wl_signal request_maximize; struct wl_signal set_state; struct wl_signal set_title; @@ -93,14 +93,12 @@ struct wlr_wl_shell_surface { }; struct wlr_wl_shell_surface_move_event { - struct wl_client *client; struct wlr_wl_shell_surface *surface; struct wlr_seat_client *seat; uint32_t serial; }; struct wlr_wl_shell_surface_resize_event { - struct wl_client *client; struct wlr_wl_shell_surface *surface; struct wlr_seat_client *seat; uint32_t serial; @@ -108,15 +106,13 @@ struct wlr_wl_shell_surface_resize_event { }; struct wlr_wl_shell_surface_set_fullscreen_event { - struct wl_client *client; struct wlr_wl_shell_surface *surface; enum wl_shell_surface_fullscreen_method method; uint32_t framerate; struct wlr_output *output; }; -struct wlr_wl_shell_surface_set_maximized_event { - struct wl_client *client; +struct wlr_wl_shell_surface_maximize_event { struct wlr_wl_shell_surface *surface; struct wlr_output *output; }; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 7940deef..7e89ec74 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -138,14 +138,12 @@ struct wlr_xdg_surface_v6 { }; struct wlr_xdg_toplevel_v6_move_event { - struct wl_client *client; struct wlr_xdg_surface_v6 *surface; struct wlr_seat_client *seat; uint32_t serial; }; struct wlr_xdg_toplevel_v6_resize_event { - struct wl_client *client; struct wlr_xdg_surface_v6 *surface; struct wlr_seat_client *seat; uint32_t serial; @@ -153,19 +151,16 @@ struct wlr_xdg_toplevel_v6_resize_event { }; struct wlr_xdg_toplevel_v6_set_fullscreen_event { - struct wl_client *client; struct wlr_xdg_surface_v6 *surface; bool fullscreen; struct wlr_output *output; }; struct wlr_xdg_toplevel_v6_show_window_menu_event { - struct wl_client *client; struct wlr_xdg_surface_v6 *surface; struct wlr_seat_client *seat; uint32_t serial; - uint32_t x; - uint32_t y; + uint32_t x, y; }; struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index e69f2dd9..ce568355 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -50,23 +50,21 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { roots_seat_begin_resize(seat, view, e->edges); } -static void handle_request_set_maximized(struct wl_listener *listener, +static void handle_request_maximize(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = - wl_container_of(listener, roots_surface, request_set_maximized); + wl_container_of(listener, roots_surface, request_maximize); struct roots_view *view = roots_surface->view; - //struct wlr_wl_shell_surface_set_maximized_event *e = data; + //struct wlr_wl_shell_surface_maximize_event *e = data; view_maximize(view, true); } -static void handle_request_set_fullscreen(struct wl_listener *listener, +static void handle_request_fullscreen(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = - wl_container_of(listener, roots_surface, request_set_fullscreen); + wl_container_of(listener, roots_surface, request_fullscreen); struct roots_view *view = roots_surface->view; struct wlr_wl_shell_surface_set_fullscreen_event *e = data; - - // TODO: support e->method, e->framerate view_set_fullscreen(view, true, e->output); } @@ -95,8 +93,8 @@ 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->request_set_fullscreen.link); + wl_list_remove(&roots_surface->request_maximize.link); + wl_list_remove(&roots_surface->request_fullscreen.link); wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->view->link); @@ -125,13 +123,13 @@ 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->request_set_fullscreen.notify = - handle_request_set_fullscreen; - wl_signal_add(&surface->events.request_set_fullscreen, - &roots_surface->request_set_fullscreen); + roots_surface->request_maximize.notify = handle_request_maximize; + wl_signal_add(&surface->events.request_maximize, + &roots_surface->request_maximize); + roots_surface->request_fullscreen.notify = + handle_request_fullscreen; + wl_signal_add(&surface->events.request_fullscreen, + &roots_surface->request_fullscreen); 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; diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index abe967d7..6174c872 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -108,25 +108,17 @@ static void shell_surface_protocol_pong(struct wl_client *client, static void shell_surface_protocol_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { - wlr_log(L_DEBUG, "got shell surface move"); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_seat_client *seat = wl_resource_get_user_data(seat_resource); - struct wlr_wl_shell_surface_move_event *event = - calloc(1, sizeof(struct wlr_wl_shell_surface_move_event)); - if (event == NULL) { - wl_client_post_no_memory(client); - return; - } - event->client = client; - event->surface = surface; - event->seat = seat; - event->serial = serial; + struct wlr_wl_shell_surface_move_event event = { + .surface = surface, + .seat = seat, + .serial = serial, + }; - wl_signal_emit(&surface->events.request_move, event); - - free(event); + wl_signal_emit(&surface->events.request_move, &event); } static struct wlr_wl_shell_popup_grab *shell_popup_grab_from_seat( @@ -174,26 +166,18 @@ 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) { - wlr_log(L_DEBUG, "got shell surface resize"); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_seat_client *seat = wl_resource_get_user_data(seat_resource); - struct wlr_wl_shell_surface_resize_event *event = - calloc(1, sizeof(struct wlr_wl_shell_surface_resize_event)); - if (event == NULL) { - wl_client_post_no_memory(client); - return; - } - event->client = client; - event->surface = surface; - event->seat = seat; - event->serial = serial; - event->edges = edges; + struct wlr_wl_shell_surface_resize_event event = { + .surface = surface, + .seat = seat, + .serial = serial, + .edges = edges, + }; - wl_signal_emit(&surface->events.request_resize, event); - - free(event); + wl_signal_emit(&surface->events.request_resize, &event); } static void shell_surface_set_state(struct wlr_wl_shell_surface *surface, @@ -279,7 +263,6 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client, struct wl_resource *resource, enum wl_shell_surface_fullscreen_method method, uint32_t framerate, struct wl_resource *output_resource) { - wlr_log(L_DEBUG, "got shell surface fullscreen"); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_output *output = NULL; if (output_resource != NULL) { @@ -289,24 +272,16 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client, 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)); - if (event == NULL) { - wl_client_post_no_memory(client); - return; - } - event->client = client; - event->surface = surface; - event->method = method; - event->framerate = framerate; - event->output = output; + struct wlr_wl_shell_surface_set_fullscreen_event event = { + .surface = surface, + .method = method, + .framerate = framerate, + .output = output, + }; - wl_signal_emit(&surface->events.request_set_fullscreen, event); - - free(event); + wl_signal_emit(&surface->events.request_fullscreen, &event); } - static void shell_surface_protocol_set_popup(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, struct wl_resource *parent_resource, int32_t x, @@ -368,7 +343,6 @@ static void shell_surface_protocol_set_popup(struct wl_client *client, static void shell_surface_protocol_set_maximized(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { - wlr_log(L_DEBUG, "got shell surface maximized"); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); struct wlr_output *output = NULL; if (output_resource != NULL) { @@ -378,19 +352,12 @@ static void shell_surface_protocol_set_maximized(struct wl_client *client, 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)); - if (event == NULL) { - wl_client_post_no_memory(client); - return; - } - event->client = client; - event->surface = surface; - event->output = output; - - wl_signal_emit(&surface->events.request_set_maximized, event); + struct wlr_wl_shell_surface_maximize_event event = { + .surface = surface, + .output = output, + }; - free(event); + wl_signal_emit(&surface->events.request_maximize, &event); } static void shell_surface_protocol_set_title(struct wl_client *client, @@ -545,8 +512,8 @@ static void shell_protocol_get_shell_surface(struct wl_client *client, wl_signal_init(&wl_surface->events.ping_timeout); wl_signal_init(&wl_surface->events.request_move); wl_signal_init(&wl_surface->events.request_resize); - wl_signal_init(&wl_surface->events.request_set_fullscreen); - wl_signal_init(&wl_surface->events.request_set_maximized); + wl_signal_init(&wl_surface->events.request_fullscreen); + wl_signal_init(&wl_surface->events.request_maximize); wl_signal_init(&wl_surface->events.set_state); wl_signal_init(&wl_surface->events.set_title); wl_signal_init(&wl_surface->events.set_class); diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 896a5f33..b69f713e 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -564,23 +564,15 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, return; } - struct wlr_xdg_toplevel_v6_show_window_menu_event *event = - calloc(1, sizeof(struct wlr_xdg_toplevel_v6_show_window_menu_event)); - if (event == NULL) { - wl_client_post_no_memory(client); - return; - } - - event->client = client; - event->surface = surface; - event->seat = seat; - event->serial = serial; - event->x = x; - event->y = y; - - wl_signal_emit(&surface->events.request_show_window_menu, event); + struct wlr_xdg_toplevel_v6_show_window_menu_event event = { + .surface = surface, + .seat = seat, + .serial = serial, + .x = x, + .y = y, + }; - free(event); + wl_signal_emit(&surface->events.request_show_window_menu, &event); } static void xdg_toplevel_protocol_move(struct wl_client *client, @@ -598,7 +590,6 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, } struct wlr_xdg_toplevel_v6_move_event event = { - .client = client, .surface = surface, .seat = seat, .serial = serial, @@ -622,7 +613,6 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, } struct wlr_xdg_toplevel_v6_resize_event event = { - .client = client, .surface = surface, .seat = seat, .serial = serial, @@ -672,7 +662,6 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, surface->toplevel_state->next.fullscreen = true; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { - .client = client, .surface = surface, .fullscreen = true, .output = output, @@ -688,7 +677,6 @@ static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, surface->toplevel_state->next.fullscreen = false; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { - .client = client, .surface = surface, .fullscreen = false, .output = NULL, -- cgit v1.2.3 From 41d7bad4703d872ffcfb2c20f300d4b3e1c84246 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 3 Dec 2017 12:37:23 -0500 Subject: wl-shell: add commit event --- include/wlr/types/wlr_wl_shell.h | 1 + types/wlr_wl_shell.c | 3 +++ 2 files changed, 4 insertions(+) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index ec087693..986f92e8 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -77,6 +77,7 @@ struct wlr_wl_shell_surface { struct { struct wl_signal destroy; + struct wl_signal commit; struct wl_signal ping_timeout; struct wl_signal request_move; diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index 6174c872..ee72856c 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -459,6 +459,8 @@ static void handle_wlr_surface_committed(struct wl_listener *listener, surface->popup_state->seat); shell_pointer_grab_maybe_end(&grab->pointer_grab); } + + wl_signal_emit(&surface->events.commit, surface); } static int shell_surface_ping_timeout(void *user_data) { @@ -509,6 +511,7 @@ static void shell_protocol_get_shell_surface(struct wl_client *client, wl_surface->resource); wl_signal_init(&wl_surface->events.destroy); + wl_signal_init(&wl_surface->events.commit); wl_signal_init(&wl_surface->events.ping_timeout); wl_signal_init(&wl_surface->events.request_move); wl_signal_init(&wl_surface->events.request_resize); -- cgit v1.2.3 From 344ca222db6b1811f983cabb80c3ba70e04fd31e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 3 Dec 2017 13:16:41 -0500 Subject: wrap server decoration modes --- include/wlr/types/wlr_server_decoration.h | 27 +++++++++++++++++++++++++-- rootston/desktop.c | 3 +-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_server_decoration.h b/include/wlr/types/wlr_server_decoration.h index b4cac5b7..474a9386 100644 --- a/include/wlr/types/wlr_server_decoration.h +++ b/include/wlr/types/wlr_server_decoration.h @@ -3,12 +3,35 @@ #include +/** + * Possible values to use in request_mode and the event mode. Same as + * org_kde_kwin_server_decoration_manager_mode. + */ +enum wlr_server_decoration_manager_mode { + /** + * Undecorated: The surface is not decorated at all, neither server nor + * client-side. An example is a popup surface which should not be + * decorated. + */ + WLR_SERVER_DECORATION_MANAGER_MODE_NONE = 0, + /** + * Client-side decoration: The decoration is part of the surface and the + * client. + */ + WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT = 1, + /** + * Server-side decoration: The server embeds the surface into a decoration + * frame. + */ + WLR_SERVER_DECORATION_MANAGER_MODE_SERVER = 2, +}; + struct wlr_server_decoration_manager { struct wl_global *wl_global; struct wl_list wl_resources; struct wl_list decorations; // wlr_server_decoration::link - uint32_t default_mode; // enum org_kde_kwin_server_decoration_manager_mode + uint32_t default_mode; // enum wlr_server_decoration_manager_mode struct { struct wl_signal new_decoration; @@ -22,7 +45,7 @@ struct wlr_server_decoration { struct wlr_surface *surface; struct wl_list link; - uint32_t mode; // enum org_kde_kwin_server_decoration_manager_mode + uint32_t mode; // enum wlr_server_decoration_manager_mode struct { struct wl_signal destroy; diff --git a/rootston/desktop.c b/rootston/desktop.c index bb3af258..244f7c94 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "rootston/server.h" #include "rootston/seat.h" #include "rootston/xcursor.h" @@ -468,7 +467,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, wlr_server_decoration_manager_create(server->wl_display); wlr_server_decoration_manager_set_default_mode( desktop->server_decoration_manager, - ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_CLIENT); + WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT); return desktop; } -- cgit v1.2.3 From 86df909256ede7ed5f415073bdf9f952ebcf473d Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 3 Dec 2017 17:30:57 -0500 Subject: xwayland: remove xwayland param from xsurface methods --- include/wlr/xwayland.h | 20 +++++++++----------- rootston/xwayland.c | 28 ++++++++++++---------------- xwayland/xwm.c | 32 +++++++++++++++----------------- 3 files changed, 36 insertions(+), 44 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 9b493d88..792d2b88 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -153,20 +153,18 @@ void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland, uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y); -void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, bool activated); +void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *surface, + bool activated); -void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, int16_t x, int16_t y, - uint16_t width, uint16_t height); +void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *surface, + int16_t x, int16_t y, uint16_t width, uint16_t height); -void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface); +void wlr_xwayland_surface_close(struct wlr_xwayland_surface *surface); -void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, bool maximized); +void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface, + bool maximized); -void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, bool fullscreen); +void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface, + bool fullscreen); #endif diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 2b17ee3f..5f677116 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -11,8 +11,7 @@ static void activate(struct roots_view *view, bool active) { assert(view->type == ROOTS_XWAYLAND_VIEW); - struct wlr_xwayland *xwayland = view->desktop->xwayland; - wlr_xwayland_surface_activate(xwayland, view->xwayland_surface, active); + wlr_xwayland_surface_activate(view->xwayland_surface, active); } static void move(struct roots_view *view, double x, double y) { @@ -20,8 +19,8 @@ static void move(struct roots_view *view, double x, double y) { struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; view->x = x; view->y = y; - wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - x, y, xwayland_surface->width, xwayland_surface->height); + wlr_xwayland_surface_configure(xwayland_surface, x, y, + xwayland_surface->width, xwayland_surface->height); } static void apply_size_constraints( @@ -56,9 +55,8 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) { apply_size_constraints(xwayland_surface, width, height, &constrained_width, &constrained_height); - wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - xwayland_surface->x, xwayland_surface->y, constrained_width, - constrained_height); + wlr_xwayland_surface_configure(xwayland_surface, xwayland_surface->x, + xwayland_surface->y, constrained_width, constrained_height); } static void move_resize(struct roots_view *view, double x, double y, @@ -87,27 +85,25 @@ static void move_resize(struct roots_view *view, double x, double y, view->pending_move_resize.width = constrained_width; view->pending_move_resize.height = constrained_height; - wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - x, y, constrained_width, constrained_height); + wlr_xwayland_surface_configure(xwayland_surface, x, y, constrained_width, + constrained_height); } static void close(struct roots_view *view) { assert(view->type == ROOTS_XWAYLAND_VIEW); - wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); + wlr_xwayland_surface_close(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); + wlr_xwayland_surface_set_maximized(view->xwayland_surface, maximized); } static void set_fullscreen(struct roots_view *view, bool fullscreen) { assert(view->type == ROOTS_XWAYLAND_VIEW); - wlr_xwayland_surface_set_fullscreen(view->desktop->xwayland, - view->xwayland_surface, fullscreen); + wlr_xwayland_surface_set_fullscreen(view->xwayland_surface, fullscreen); } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -139,8 +135,8 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { roots_surface->view->x = (double)event->x; roots_surface->view->y = (double)event->y; - wlr_xwayland_surface_configure(roots_surface->view->desktop->xwayland, - xwayland_surface, event->x, event->y, event->width, event->height); + wlr_xwayland_surface_configure(xwayland_surface, event->x, event->y, + event->width, event->height); } static struct roots_seat *guess_seat_for_view(struct roots_view *view) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index d36822b5..562f2052 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -590,7 +590,7 @@ static void xwm_handle_configure_request(struct wlr_xwm *xwm, if (xsurface->surface == NULL) { // Surface has not been mapped yet - wlr_xwayland_surface_configure(xwm->xwayland, xsurface, ev->x, ev->y, + wlr_xwayland_surface_configure(xsurface, ev->x, ev->y, ev->width, ev->height); } else { struct wlr_xwayland_surface_configure_event *wlr_event = @@ -981,25 +981,24 @@ static void handle_compositor_surface_create(struct wl_listener *listener, } } -void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *xsurface, bool activated) { - struct wlr_xwayland_surface *focused = wlr_xwayland->xwm->focus_surface; +void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *xsurface, + bool activated) { + struct wlr_xwayland_surface *focused = xsurface->xwm->focus_surface; if (activated) { - xwm_surface_activate(wlr_xwayland->xwm, xsurface); + xwm_surface_activate(xsurface->xwm, xsurface); } else if (focused == xsurface) { - xwm_surface_activate(wlr_xwayland->xwm, NULL); + xwm_surface_activate(xsurface->xwm, NULL); } } -void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *xsurface, int16_t x, int16_t y, - uint16_t width, uint16_t height) { +void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *xsurface, + int16_t x, int16_t y, uint16_t width, uint16_t height) { xsurface->x = x; xsurface->y = y; xsurface->width = width; xsurface->height = height; - struct wlr_xwm *xwm = wlr_xwayland->xwm; + struct wlr_xwm *xwm = xsurface->xwm; uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_BORDER_WIDTH; @@ -1008,9 +1007,8 @@ void wlr_xwayland_surface_configure(struct wlr_xwayland *wlr_xwayland, xcb_flush(xwm->xcb_conn); } -void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *xsurface) { - struct wlr_xwm *xwm = wlr_xwayland->xwm; +void wlr_xwayland_surface_close(struct wlr_xwayland_surface *xsurface) { + struct wlr_xwm *xwm = xsurface->xwm; bool supports_delete = false; for (size_t i = 0; i < xsurface->protocols_len; i++) { @@ -1343,16 +1341,16 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { return xwm; } -void wlr_xwayland_surface_set_maximized(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, bool maximized) { +void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface, + bool maximized) { surface->maximized_horz = maximized; surface->maximized_vert = maximized; xsurface_set_net_wm_state(surface); xcb_flush(surface->xwm->xcb_conn); } -void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland *wlr_xwayland, - struct wlr_xwayland_surface *surface, bool fullscreen) { +void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface, + bool fullscreen) { surface->fullscreen = fullscreen; xsurface_set_net_wm_state(surface); xcb_flush(surface->xwm->xcb_conn); -- cgit v1.2.3 From bf2b58eb6db5a59f08a3b0a3ab5e43e93711bf51 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 6 Dec 2017 16:36:46 +0100 Subject: Add wlr_output_set_scale Fixes #465 --- include/wlr/types/wlr_output.h | 1 + rootston/output.c | 6 +++--- types/wlr_output.c | 29 +++++++++++++++++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index d382b593..42c46233 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -85,6 +85,7 @@ bool wlr_output_set_mode(struct wlr_output *output, void wlr_output_transform(struct wlr_output *output, enum wl_output_transform transform); void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly); +void wlr_output_set_scale(struct wlr_output *output, uint32_t scale); void wlr_output_destroy(struct wlr_output *output); void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height); diff --git a/rootston/output.c b/rootston/output.c index bf684f2f..d0f4a378 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -314,10 +314,10 @@ 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_set_scale(wlr_output, 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); + wlr_output_layout_add(desktop->layout, wlr_output, output_config->x, + output_config->y); } else { wlr_output_layout_add_auto(desktop->layout, wlr_output); } diff --git a/types/wlr_output.c b/types/wlr_output.c index 21d94cfb..163f2d8c 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -52,6 +52,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { static void wlr_output_send_current_mode_to_resource( struct wl_resource *resource) { + assert(resource); struct wlr_output *output = wl_resource_get_user_data(resource); assert(output); const uint32_t version = wl_resource_get_version(resource); @@ -119,7 +120,6 @@ struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, struct wl_global *wl_global = wl_global_create(display, &wl_output_interface, 3, wlr_output, wl_output_bind); wlr_output->wl_global = wl_global; - wl_list_init(&wlr_output->wl_resources); return wl_global; } @@ -155,6 +155,7 @@ bool wlr_output_set_mode(struct wlr_output *output, bool result = output->impl->set_mode(output, mode); if (result) { wlr_output_update_matrix(output); + struct wl_resource *resource; wl_resource_for_each(resource, &output->wl_resources) { wlr_output_send_current_mode_to_resource(resource); @@ -168,14 +169,14 @@ void wlr_output_update_size(struct wlr_output *output, int32_t width, if (output->width == width && output->height == height) { return; } + output->width = width; output->height = height; wlr_output_update_matrix(output); - if (output->wl_global != NULL) { - struct wl_resource *resource; - wl_resource_for_each(resource, &output->wl_resources) { - wlr_output_send_current_mode_to_resource(resource); - } + + struct wl_resource *resource; + wl_resource_for_each(resource, &output->wl_resources) { + wlr_output_send_current_mode_to_resource(resource); } } @@ -194,6 +195,21 @@ void wlr_output_set_position(struct wlr_output *output, int32_t lx, output->lx = lx; output->ly = ly; + // TODO: only send geometry and done + struct wl_resource *resource; + wl_resource_for_each(resource, &output->wl_resources) { + wl_output_send_to_resource(resource); + } +} + +void wlr_output_set_scale(struct wlr_output *output, uint32_t scale) { + if (output->scale == scale) { + return; + } + + output->scale = scale; + + // TODO: only send mode and done struct wl_resource *resource; wl_resource_for_each(resource, &output->wl_resources) { wl_output_send_to_resource(resource); @@ -209,6 +225,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->scale = 1; wl_list_init(&output->cursors); + wl_list_init(&output->wl_resources); wl_signal_init(&output->events.frame); wl_signal_init(&output->events.swap_buffers); wl_signal_init(&output->events.resolution); -- cgit v1.2.3 From d74ac69f7b932a8833527a41351e3310ad391d7c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 7 Dec 2017 11:19:43 -0500 Subject: bring edges into wlr --- include/rootston/cursor.h | 7 ------- include/rootston/xcursor.h | 2 -- include/wlr/types/wlr_xcursor_manager.h | 7 +++++++ include/wlr/util/edges.h | 12 ++++++++++++ rootston/cursor.c | 17 +++++++++-------- rootston/meson.build | 1 - rootston/seat.c | 3 ++- rootston/xcursor.c | 28 ---------------------------- types/wlr_xcursor_manager.c | 23 +++++++++++++++++++++++ 9 files changed, 53 insertions(+), 47 deletions(-) create mode 100644 include/wlr/util/edges.h delete mode 100644 rootston/xcursor.c (limited to 'include/wlr') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index e2a371bf..2d9a9215 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -10,13 +10,6 @@ enum roots_cursor_mode { ROOTS_CURSOR_ROTATE = 3, }; -enum roots_cursor_resize_edge { - ROOTS_CURSOR_RESIZE_EDGE_TOP = 1, - ROOTS_CURSOR_RESIZE_EDGE_BOTTOM = 2, - ROOTS_CURSOR_RESIZE_EDGE_LEFT = 4, - ROOTS_CURSOR_RESIZE_EDGE_RIGHT = 8, -}; - struct roots_input_event { uint32_t serial; struct wlr_cursor *cursor; diff --git a/include/rootston/xcursor.h b/include/rootston/xcursor.h index bc00f79c..285db78d 100644 --- a/include/rootston/xcursor.h +++ b/include/rootston/xcursor.h @@ -9,6 +9,4 @@ #define ROOTS_XCURSOR_MOVE "grabbing" #define ROOTS_XCURSOR_ROTATE "grabbing" -const char *roots_xcursor_get_resize_name(uint32_t edges); - #endif diff --git a/include/wlr/types/wlr_xcursor_manager.h b/include/wlr/types/wlr_xcursor_manager.h index c78a6e8d..63eb5386 100644 --- a/include/wlr/types/wlr_xcursor_manager.h +++ b/include/wlr/types/wlr_xcursor_manager.h @@ -4,6 +4,7 @@ #include #include #include +#include /** * A scaled XCursor theme. @@ -50,4 +51,10 @@ struct wlr_xcursor *wlr_xcursor_manager_get_xcursor( void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, const char *name, struct wlr_cursor *cursor); +/** + * Get the name of the cursor image for the given edges. + */ +const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges); + + #endif diff --git a/include/wlr/util/edges.h b/include/wlr/util/edges.h new file mode 100644 index 00000000..53268323 --- /dev/null +++ b/include/wlr/util/edges.h @@ -0,0 +1,12 @@ +#ifndef WLR_UTIL_EDGES_H +#define WLR_UTIL_EDGES_H + +enum wlr_edges { + WLR_EDGE_NONE = 0, + WLR_EDGE_TOP = 1, + WLR_EDGE_BOTTOM = 2, + WLR_EDGE_LEFT = 4, + WLR_EDGE_RIGHT = 8, +}; + +#endif diff --git a/rootston/cursor.c b/rootston/cursor.c index f0e3d70d..d38e40a1 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -8,6 +8,7 @@ #endif #include #include +#include #include "rootston/xcursor.h" #include "rootston/cursor.h" @@ -75,22 +76,22 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, double y = view->y; int width = cursor->view_width; int height = cursor->view_height; - if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { + if (cursor->resize_edges & WLR_EDGE_TOP) { y = cursor->view_y + dy; height -= dy; if (height < 1) { y += height; } - } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { + } else if (cursor->resize_edges & WLR_EDGE_BOTTOM) { height += dy; } - if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + if (cursor->resize_edges & WLR_EDGE_LEFT) { x = cursor->view_x + dx; width -= dx; if (width < 1) { x += width; } - } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + } else if (cursor->resize_edges & WLR_EDGE_RIGHT) { width += dx; } @@ -147,14 +148,14 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, case BTN_RIGHT: edges = 0; if (sx < view->wlr_surface->current->width/2) { - edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT; + edges |= WLR_EDGE_LEFT; } else { - edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT; + edges |= WLR_EDGE_RIGHT; } if (sy < view->wlr_surface->current->height/2) { - edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP; + edges |= WLR_EDGE_TOP; } else { - edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM; + edges |= WLR_EDGE_BOTTOM; } roots_seat_begin_resize(seat, view, edges); break; diff --git a/rootston/meson.build b/rootston/meson.build index 9c543c4f..36b6241a 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -8,7 +8,6 @@ sources = [ 'main.c', 'output.c', 'seat.c', - 'xcursor.c', 'xdg_shell_v6.c', 'wl_shell.c', ] diff --git a/rootston/seat.c b/rootston/seat.c index 737bbd67..f6473581 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -661,8 +661,9 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); + const char *resize_name = wlr_xcursor_manager_get_resize_name(edges); wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, - roots_xcursor_get_resize_name(edges), seat->cursor->cursor); + resize_name, seat->cursor->cursor); } void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { diff --git a/rootston/xcursor.c b/rootston/xcursor.c deleted file mode 100644 index 74e732c9..00000000 --- a/rootston/xcursor.c +++ /dev/null @@ -1,28 +0,0 @@ -#define _POSIX_C_SOURCE 200809L -#include -#include -#include "rootston/xcursor.h" -#include "rootston/input.h" - -const char *roots_xcursor_get_resize_name(uint32_t edges) { - if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { - if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { - return "ne-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - return "nw-resize"; - } - return "n-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { - if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { - return "se-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - return "sw-resize"; - } - return "s-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { - return "e-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - return "w-resize"; - } - return "se-resize"; // fallback -} diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index f32a96bc..9350d721 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -82,3 +82,26 @@ void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, theme->scale); } } + +const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges) { + if (edges & WLR_EDGE_TOP) { + if (edges & WLR_EDGE_RIGHT) { + return "ne-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "nw-resize"; + } + return "n-resize"; + } else if (edges & WLR_EDGE_BOTTOM) { + if (edges & WLR_EDGE_RIGHT) { + return "se-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "sw-resize"; + } + return "s-resize"; + } else if (edges & WLR_EDGE_RIGHT) { + return "e-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "w-resize"; + } + return "se-resize"; // fallback +} -- cgit v1.2.3 From 4c60072be584a7ed5b97de325994217a9e96bbd4 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 8 Dec 2017 06:08:06 -0500 Subject: move get_resize_name to xcursor --- include/wlr/types/wlr_xcursor_manager.h | 7 ------- include/wlr/xcursor.h | 6 ++++++ rootston/seat.c | 2 +- types/wlr_xcursor_manager.c | 23 ----------------------- xcursor/wlr_xcursor.c | 23 +++++++++++++++++++++++ 5 files changed, 30 insertions(+), 31 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_xcursor_manager.h b/include/wlr/types/wlr_xcursor_manager.h index 63eb5386..c78a6e8d 100644 --- a/include/wlr/types/wlr_xcursor_manager.h +++ b/include/wlr/types/wlr_xcursor_manager.h @@ -4,7 +4,6 @@ #include #include #include -#include /** * A scaled XCursor theme. @@ -51,10 +50,4 @@ struct wlr_xcursor *wlr_xcursor_manager_get_xcursor( void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, const char *name, struct wlr_cursor *cursor); -/** - * Get the name of the cursor image for the given edges. - */ -const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges); - - #endif diff --git a/include/wlr/xcursor.h b/include/wlr/xcursor.h index b6362b06..42fcedb9 100644 --- a/include/wlr/xcursor.h +++ b/include/wlr/xcursor.h @@ -32,6 +32,7 @@ #define WLR_XCURSOR_H #include +#include struct wlr_xcursor_image { uint32_t width; /* actual width */ @@ -65,4 +66,9 @@ struct wlr_xcursor *wlr_xcursor_theme_get_cursor( int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time); +/** + * Get the name of the resize cursor image for the given edges. + */ +const char *wlr_xcursor_get_resize_name(enum wlr_edges edges); + #endif diff --git a/rootston/seat.c b/rootston/seat.c index f6473581..1fa09ad6 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -661,7 +661,7 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - const char *resize_name = wlr_xcursor_manager_get_resize_name(edges); + const char *resize_name = wlr_xcursor_get_resize_name(edges); wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, resize_name, seat->cursor->cursor); } diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index 9350d721..f32a96bc 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -82,26 +82,3 @@ void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, theme->scale); } } - -const char *wlr_xcursor_manager_get_resize_name(enum wlr_edges edges) { - if (edges & WLR_EDGE_TOP) { - if (edges & WLR_EDGE_RIGHT) { - return "ne-resize"; - } else if (edges & WLR_EDGE_LEFT) { - return "nw-resize"; - } - return "n-resize"; - } else if (edges & WLR_EDGE_BOTTOM) { - if (edges & WLR_EDGE_RIGHT) { - return "se-resize"; - } else if (edges & WLR_EDGE_LEFT) { - return "sw-resize"; - } - return "s-resize"; - } else if (edges & WLR_EDGE_RIGHT) { - return "e-resize"; - } else if (edges & WLR_EDGE_LEFT) { - return "w-resize"; - } - return "se-resize"; // fallback -} diff --git a/xcursor/wlr_xcursor.c b/xcursor/wlr_xcursor.c index fdebe1af..b1678223 100644 --- a/xcursor/wlr_xcursor.c +++ b/xcursor/wlr_xcursor.c @@ -326,3 +326,26 @@ static int wlr_xcursor_frame_and_duration(struct wlr_xcursor *cursor, int wlr_xcursor_frame(struct wlr_xcursor *_cursor, uint32_t time) { return wlr_xcursor_frame_and_duration(_cursor, time, NULL); } + +const char *wlr_xcursor_get_resize_name(enum wlr_edges edges) { + if (edges & WLR_EDGE_TOP) { + if (edges & WLR_EDGE_RIGHT) { + return "ne-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "nw-resize"; + } + return "n-resize"; + } else if (edges & WLR_EDGE_BOTTOM) { + if (edges & WLR_EDGE_RIGHT) { + return "se-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "sw-resize"; + } + return "s-resize"; + } else if (edges & WLR_EDGE_RIGHT) { + return "e-resize"; + } else if (edges & WLR_EDGE_LEFT) { + return "w-resize"; + } + return "se-resize"; // fallback +} -- cgit v1.2.3 From c5fa415a0373e0fbd974d4a8aee94014050b93f2 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 14:23:33 +0100 Subject: Send wl_surface.{enter,leave} to cursor surfaces --- include/rootston/xcursor.h | 2 +- include/wlr/types/wlr_output.h | 4 +++ types/wlr_output.c | 75 +++++++++++++++++++++++++++++------------- 3 files changed, 58 insertions(+), 23 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/xcursor.h b/include/rootston/xcursor.h index 285db78d..a7d2b960 100644 --- a/include/rootston/xcursor.h +++ b/include/rootston/xcursor.h @@ -3,7 +3,7 @@ #include -#define ROOTS_XCURSOR_SIZE 16 +#define ROOTS_XCURSOR_SIZE 24 #define ROOTS_XCURSOR_DEFAULT "left_ptr" #define ROOTS_XCURSOR_MOVE "grabbing" diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 42c46233..895536e1 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -16,6 +16,7 @@ struct wlr_output_cursor { struct wlr_output *output; double x, y; bool enabled; + bool visible; uint32_t width, height; int32_t hotspot_x, hotspot_y; struct wl_list link; @@ -98,6 +99,9 @@ void wlr_output_set_fullscreen_surface(struct wlr_output *output, struct wlr_surface *surface); struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output); +/** + * Sets the cursor image. The image must be already scaled for the output. + */ 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); diff --git a/types/wlr_output.c b/types/wlr_output.c index ed74004d..3141e9ef 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -316,6 +316,11 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor, box->y = cursor->y - cursor->hotspot_y; box->width = cursor->width; box->height = cursor->height; + + if (cursor->surface != NULL) { + box->x += cursor->surface->current->sx; + box->y += cursor->surface->current->sy; + } } static void output_cursor_render(struct wlr_output_cursor *cursor, @@ -331,36 +336,29 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, return; } - struct wlr_box output_box; - 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; + glViewport(0, 0, cursor->output->width, cursor->output->height); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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 translate[16]; + wlr_matrix_translate(&translate, cursor_box.x, cursor_box.y, 0); - int x = cursor->x - cursor->hotspot_x; - int y = cursor->y - cursor->hotspot_y; + // Assume cursors without a surface are already scaled for the output if (cursor->surface != NULL) { - x += cursor->surface->current->sx; - y += cursor->surface->current->sy; + cursor_box.width *= cursor->output->scale; + cursor_box.height *= cursor->output->scale; } + float scale[16]; + wlr_matrix_scale(&scale, cursor_box.width, cursor_box.height, 1); + float matrix[16]; - wlr_texture_get_matrix(texture, &matrix, &cursor->output->transform_matrix, - x, y); + wlr_matrix_mul(&translate, &scale, &matrix); + wlr_matrix_mul(&cursor->output->transform_matrix, &matrix, &matrix); + wlr_render_with_matrix(renderer, texture, &matrix); if (cursor->surface != NULL) { @@ -381,7 +379,8 @@ void wlr_output_swap_buffers(struct wlr_output *output) { struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { - if (!cursor->enabled || output->hardware_cursor == cursor) { + if (!cursor->enabled || !cursor->visible || + output->hardware_cursor == cursor) { continue; } output_cursor_render(cursor, &now); @@ -516,6 +515,34 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, stride, width, height, pixels); } +static void output_cursor_update_visible(struct wlr_output_cursor *cursor) { + struct wlr_box output_box; + 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); + + struct wlr_box intersection; + struct wlr_box *intersection_ptr = &intersection; + bool visible = + wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr); + + if (cursor->surface != NULL) { + if (cursor->visible && !visible) { + wlr_surface_send_leave(cursor->surface, cursor->output); + } + if (!cursor->visible && visible) { + wlr_surface_send_enter(cursor->surface, cursor->output); + } + } + + cursor->visible = visible; +} + static void output_cursor_commit(struct wlr_output_cursor *cursor) { // Some clients commit a cursor surface with a NULL buffer to hide it. cursor->enabled = wlr_surface_has_buffer(cursor->surface); @@ -584,6 +611,9 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, wl_signal_add(&surface->events.commit, &cursor->surface_commit); wl_signal_add(&surface->events.destroy, &cursor->surface_destroy); output_cursor_commit(cursor); + + cursor->visible = false; + output_cursor_update_visible(cursor); } else { cursor->enabled = false; cursor->width = 0; @@ -599,6 +629,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, y *= cursor->output->scale; cursor->x = x; cursor->y = y; + output_cursor_update_visible(cursor); if (cursor->output->hardware_cursor != cursor) { cursor->output->needs_swap = true; -- cgit v1.2.3