diff options
author | emersion <contact@emersion.fr> | 2017-11-21 18:34:12 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-11-21 18:34:12 +0100 |
commit | dcb168914e714156605eb9be03e175de78092e50 (patch) | |
tree | 98415a19a4c3cf2c9a1f2508949eebc1d28d300b /rootston | |
parent | 9a6f799d8f72c1dcd24e22749d43eb2ed54681c6 (diff) | |
parent | 1228d0da19edbfc1730b6918760aef444fac8887 (diff) |
Merge branch 'master' into fullscreen
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 32 | ||||
-rw-r--r-- | rootston/desktop.c | 15 | ||||
-rw-r--r-- | rootston/wl_shell.c | 19 | ||||
-rw-r--r-- | rootston/xdg_shell_v6.c | 108 | ||||
-rw-r--r-- | rootston/xwayland.c | 68 |
5 files changed, 172 insertions, 70 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index b3c87b30..f0e3d70d 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -71,43 +71,37 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, if (view != NULL) { double dx = cursor->cursor->x - cursor->offs_x; double dy = cursor->cursor->y - cursor->offs_y; - double active_x = view->x; - double active_y = view->y; + double x = view->x; + double y = view->y; int width = cursor->view_width; int height = cursor->view_height; if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { - active_y = cursor->view_y + dy; + y = cursor->view_y + dy; height -= dy; - if (height < 0) { - active_y += height; + if (height < 1) { + y += height; } } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { height += dy; } if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - active_x = cursor->view_x + dx; + x = cursor->view_x + dx; width -= dx; - if (width < 0) { - active_x += width; + if (width < 1) { + x += width; } } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { width += dx; } - if (width < 0) { - width = 0; + if (width < 1) { + width = 1; } - if (height < 0) { - height = 0; + if (height < 1) { + height = 1; } - if (active_x != view->x || - active_y != view->y) { - view_move_resize(view, active_x, active_y, - width, height); - } else { - view_resize(view, width, height); - } + view_move_resize(view, x, y, width, height); } break; case ROOTS_CURSOR_ROTATE: diff --git a/rootston/desktop.c b/rootston/desktop.c index 1a21a7c2..eb18e716 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -85,12 +85,25 @@ 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) { + bool update_x = x != view->x; + bool update_y = y != view->y; + if (!update_x && !update_y) { + view_resize(view, width, height); + return; + } + if (view->move_resize) { view->move_resize(view, x, y, width, height); return; } - view_move(view, x, y); + view->pending_move_resize.update_x = update_x; + view->pending_move_resize.update_y = update_y; + view->pending_move_resize.x = x; + view->pending_move_resize.y = y; + view->pending_move_resize.width = width; + view->pending_move_resize.height = height; + view_resize(view, width, height); } diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index ce568355..5fd6352d 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -84,7 +84,24 @@ static void handle_set_state(struct wl_listener *listener, void *data) { } static void handle_surface_commit(struct wl_listener *listener, void *data) { - // TODO do we need to do anything here? + struct roots_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, surface_commit); + struct roots_view *view = roots_surface->view; + struct wlr_surface *wlr_surface = view->wlr_surface; + + int width = wlr_surface->current->width; + int height = wlr_surface->current->height; + + if (view->pending_move_resize.update_x) { + view->x = view->pending_move_resize.x + + view->pending_move_resize.width - width; + view->pending_move_resize.update_x = false; + } + if (view->pending_move_resize.update_y) { + view->y = view->pending_move_resize.y + + view->pending_move_resize.height - height; + view->pending_move_resize.update_y = false; + } } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index f301a2e1..a0503ad8 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -12,11 +12,11 @@ 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; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (surf->geometry->width > 0 && surf->geometry->height > 0) { - box->width = surf->geometry->width; - box->height = surf->geometry->height; + if (surface->geometry->width > 0 && surface->geometry->height > 0) { + box->width = surface->geometry->width; + box->height = surface->geometry->height; } else { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; @@ -25,20 +25,19 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { static void activate(struct roots_view *view, bool active) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - wlr_xdg_toplevel_v6_set_activated(surf, active); + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_v6_set_activated(surface, active); } } -static void apply_size_constraints(struct wlr_xdg_surface_v6 *surf, +static void apply_size_constraints(struct wlr_xdg_surface_v6 *surface, uint32_t width, uint32_t height, uint32_t *dest_width, uint32_t *dest_height) { *dest_width = width; *dest_height = height; - struct wlr_xdg_toplevel_v6_state *state = - &surf->toplevel_state->current; + struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel_state->current; if (width < state->min_width) { *dest_width = state->min_width; } else if (state->max_width > 0 && @@ -55,39 +54,57 @@ static void apply_size_constraints(struct wlr_xdg_surface_v6 *surf, static void resize(struct roots_view *view, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - if (surf->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { return; } - uint32_t contrained_width, contrained_height; - apply_size_constraints(surf, width, height, &contrained_width, - &contrained_height); + uint32_t constrained_width, constrained_height; + apply_size_constraints(surface, width, height, &constrained_width, + &constrained_height); - wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); + wlr_xdg_toplevel_v6_set_size(surface, constrained_width, + constrained_height); } static void move_resize(struct roots_view *view, double x, double y, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - if (surf->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + struct roots_xdg_surface_v6 *roots_surface = view->roots_xdg_surface_v6; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { return; } - uint32_t contrained_width, contrained_height; - apply_size_constraints(surf, width, height, &contrained_width, - &contrained_height); + bool update_x = x != view->x; + bool update_y = y != view->y; - x = x + width - contrained_width; - y = y + height - contrained_height; + uint32_t constrained_width, constrained_height; + apply_size_constraints(surface, width, height, &constrained_width, + &constrained_height); - // TODO: we should wait for an ack_configure event before updating the - // position - view->x = x; - view->y = y; + if (update_x) { + x = x + width - constrained_width; + } + if (update_y) { + y = y + height - constrained_height; + } - wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); + view->pending_move_resize.update_x = update_x; + view->pending_move_resize.update_y = update_y; + view->pending_move_resize.x = x; + view->pending_move_resize.y = y; + view->pending_move_resize.width = constrained_width; + view->pending_move_resize.height = constrained_height; + + uint32_t serial = wlr_xdg_toplevel_v6_set_size(surface, constrained_width, + constrained_height); + if (serial > 0) { + roots_surface->pending_move_resize_configure_serial = serial; + } else { + view->x = x; + view->y = y; + } } static void maximize(struct roots_view *view, bool maximized) { @@ -112,9 +129,9 @@ static void set_fullscreen(struct roots_view *view, bool 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; - if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - wlr_xdg_toplevel_v6_send_close(surf); + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_v6_send_close(surface); } } @@ -176,11 +193,30 @@ static void handle_request_fullscreen(struct wl_listener *listener, } 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 + struct roots_xdg_surface_v6 *roots_surface = + wl_container_of(listener, roots_surface, commit); + struct roots_view *view = roots_surface->view; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + + uint32_t pending_serial = + roots_surface->pending_move_resize_configure_serial; + if (pending_serial > 0 && pending_serial >= surface->configure_serial) { + struct wlr_box size; + get_size(view, &size); + + if (view->pending_move_resize.update_x) { + view->x = view->pending_move_resize.x + + view->pending_move_resize.width - size.width; + } + if (view->pending_move_resize.update_y) { + view->y = view->pending_move_resize.y + + view->pending_move_resize.height - size.height; + } + + if (pending_serial == surface->configure_serial) { + roots_surface->pending_move_resize_configure_serial = 0; + } + } } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index cdf2a2d9..2b17ee3f 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -52,13 +52,13 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - uint32_t contrained_width, contrained_height; - apply_size_constraints(xwayland_surface, width, height, &contrained_width, - &contrained_height); + uint32_t constrained_width, constrained_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, contrained_width, - contrained_height); + xwayland_surface->x, xwayland_surface->y, constrained_width, + constrained_height); } static void move_resize(struct roots_view *view, double x, double y, @@ -66,18 +66,29 @@ static void move_resize(struct roots_view *view, double x, double y, assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - uint32_t contrained_width, contrained_height; - apply_size_constraints(xwayland_surface, width, height, &contrained_width, - &contrained_height); + bool update_x = x != view->x; + bool update_y = y != view->y; - x = x + width - contrained_width; - y = y + height - contrained_height; + uint32_t constrained_width, constrained_height; + apply_size_constraints(xwayland_surface, width, height, &constrained_width, + &constrained_height); - view->x = x; - view->y = y; + if (update_x) { + x = x + width - constrained_width; + } + if (update_y) { + y = y + height - constrained_height; + } + + view->pending_move_resize.update_x = update_x; + view->pending_move_resize.update_y = update_y; + view->pending_move_resize.x = x; + view->pending_move_resize.y = 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, contrained_width, contrained_height); + x, y, constrained_width, constrained_height); } static void close(struct roots_view *view) { @@ -192,6 +203,27 @@ static void handle_request_fullscreen(struct wl_listener *listener, view_set_fullscreen(view, xwayland_surface->fullscreen, NULL); } +static void handle_surface_commit(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, surface_commit); + struct roots_view *view = roots_surface->view; + struct wlr_surface *wlr_surface = view->wlr_surface; + + int width = wlr_surface->current->width; + int height = wlr_surface->current->height; + + if (view->pending_move_resize.update_x) { + view->x = view->pending_move_resize.x + + view->pending_move_resize.width - width; + view->pending_move_resize.update_x = false; + } + if (view->pending_move_resize.update_y) { + view->y = view->pending_move_resize.y + + view->pending_move_resize.height - height; + view->pending_move_resize.update_y = false; + } +} + 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); @@ -203,6 +235,10 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->x = (double)xsurface->x; view->y = (double)xsurface->y; + roots_surface->surface_commit.notify = handle_surface_commit; + wl_signal_add(&xsurface->surface->events.commit, + &roots_surface->surface_commit); + wl_list_insert(&desktop->views, &view->link); } @@ -211,6 +247,8 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { wl_container_of(listener, roots_surface, unmap_notify); roots_surface->view->wlr_surface = NULL; + wl_list_remove(&roots_surface->surface_commit.link); + wl_list_remove(&roots_surface->view->link); } @@ -249,6 +287,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_signal_add(&surface->events.request_fullscreen, &roots_surface->request_fullscreen); + roots_surface->surface_commit.notify = handle_surface_commit; + wl_signal_add(&surface->surface->events.commit, + &roots_surface->surface_commit); + struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (view == NULL) { free(roots_surface); |