diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-10 08:26:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-10 08:26:20 -0500 |
commit | e6babc07a050262dc487ec665b042346b06e4916 (patch) | |
tree | 34c0eb69a7e5820c684aba6d2405c899c04e18f1 /rootston | |
parent | 425713b83730a7b707ac5b0a325b8e37464a982c (diff) | |
parent | bf1b12a72500fb8cb41cbc60d29e602c25c97fc2 (diff) |
Merge pull request #390 from emersion/rootston-maximize
Maximize views in rootston
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 37 | ||||
-rw-r--r-- | rootston/desktop.c | 44 | ||||
-rw-r--r-- | rootston/wl_shell.c | 28 | ||||
-rw-r--r-- | rootston/xdg_shell_v6.c | 33 | ||||
-rw-r--r-- | rootston/xwayland.c | 35 |
5 files changed, 161 insertions, 16 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index 3a6d087e..cbd03af1 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -42,8 +42,15 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, input->mode = ROOTS_CURSOR_MOVE; input->offs_x = cursor->x; input->offs_y = cursor->y; - input->view_x = view->x; - input->view_y = view->y; + if (view->maximized) { + input->view_x = view->saved.x; + input->view_y = view->saved.y; + } else { + input->view_x = view->x; + input->view_y = view->y; + } + + view_maximize(view, false); wlr_seat_pointer_clear_focus(input->wl_seat); struct wlr_xcursor *xcursor = get_move_xcursor(input->xcursor_theme); @@ -57,13 +64,22 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, input->mode = ROOTS_CURSOR_RESIZE; input->offs_x = cursor->x; input->offs_y = cursor->y; - input->view_x = view->x; - input->view_y = view->y; - struct wlr_box size; - view_get_size(view, &size); - input->view_width = size.width; - input->view_height = size.height; + if (view->maximized) { + input->view_x = view->saved.x; + input->view_y = view->saved.y; + input->view_width = view->saved.width; + input->view_height = view->saved.height; + } else { + input->view_x = view->x; + input->view_y = view->y; + struct wlr_box size; + view_get_size(view, &size); + input->view_width = size.width; + input->view_height = size.height; + } input->resize_edges = edges; + + view_maximize(view, false); wlr_seat_pointer_clear_focus(input->wl_seat); struct wlr_xcursor *xcursor = get_resize_xcursor(input->xcursor_theme, edges); @@ -78,6 +94,8 @@ void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, input->offs_x = cursor->x; input->offs_y = cursor->y; input->view_rotation = view->rotation; + + view_maximize(view, false); wlr_seat_pointer_clear_focus(input->wl_seat); struct wlr_xcursor *xcursor = get_rotate_xcursor(input->xcursor_theme); @@ -102,7 +120,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { set_compositor_cursor = view_client != input->cursor_client; } if (set_compositor_cursor) { - struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme); + struct wlr_xcursor *xcursor = + get_default_xcursor(input->xcursor_theme); cursor_set_xcursor_image(input, xcursor->images[0]); input->cursor_client = NULL; } diff --git a/rootston/desktop.c b/rootston/desktop.c index 78bd271a..469a503b 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -106,6 +106,50 @@ void view_move_resize(struct roots_view *view, double x, double y, view_resize(view, width, height); } +void view_maximize(struct roots_view *view, bool maximized) { + if (view->maximized == maximized) { + return; + } + + if (view->maximize) { + view->maximize(view, maximized); + } + + if (!view->maximized && maximized) { + struct wlr_box view_box; + view_get_size(view, &view_box); + + view->maximized = true; + view->saved.x = view->x; + view->saved.y = view->y; + view->saved.rotation = view->rotation; + view->saved.width = view_box.width; + view->saved.height = view_box.height; + + double output_x, output_y; + wlr_output_layout_closest_point(view->desktop->layout, NULL, + view->x + (double)view_box.width/2, + view->y + (double)view_box.height/2, + &output_x, &output_y); + struct wlr_output *output = wlr_output_layout_output_at( + view->desktop->layout, output_x, output_y); + struct wlr_box *output_box = + wlr_output_layout_get_box(view->desktop->layout, output); + + view_move_resize(view, output_box->x, output_box->y, output_box->width, + output_box->height); + view->rotation = 0; + } + + if (view->maximized && !maximized) { + view->maximized = false; + + view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, + view->saved.height); + view->rotation = view->saved.rotation; + } +} + void view_close(struct roots_view *view) { if (view->close) { view->close(view); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index e38eb697..3ac8fe61 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -49,6 +49,26 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { view_begin_resize(input, event->cursor, view, e->edges); } +static void handle_request_set_maximized(struct wl_listener *listener, + void *data) { + struct roots_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, request_set_maximized); + struct roots_view *view = roots_surface->view; + //struct wlr_wl_shell_surface_set_maximized_event *e = data; + view_maximize(view, true); +} + +static void handle_set_state(struct wl_listener *listener, void *data) { + struct roots_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, set_state); + struct roots_view *view = roots_surface->view; + struct wlr_wl_shell_surface *surface = view->wl_shell_surface; + if (view->maximized && + surface->state != WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED) { + view_maximize(view, false); + } +} + static void handle_surface_commit(struct wl_listener *listener, void *data) { // TODO do we need to do anything here? } @@ -60,6 +80,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_move.link); wl_list_remove(&roots_surface->request_resize.link); + wl_list_remove(&roots_surface->request_set_maximized.link); + wl_list_remove(&roots_surface->set_state.link); + wl_list_remove(&roots_surface->surface_commit.link); view_destroy(roots_surface->view); free(roots_surface); } @@ -93,6 +116,11 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { roots_surface->request_resize.notify = handle_request_resize; wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize); + roots_surface->request_set_maximized.notify = handle_request_set_maximized; + wl_signal_add(&surface->events.request_set_maximized, + &roots_surface->request_set_maximized); + roots_surface->set_state.notify = handle_set_state; + wl_signal_add(&surface->events.set_state, &roots_surface->set_state); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ad0ee962..2a0660a6 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -84,6 +84,16 @@ static void move_resize(struct roots_view *view, double x, double y, wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); } +static void maximize(struct roots_view *view, bool maximized) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + return; + } + + wlr_xdg_toplevel_v6_set_maximized(surface, maximized); +} + static void close(struct roots_view *view) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; @@ -118,8 +128,25 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { view_begin_resize(input, event->cursor, view, e->edges); } +static void handle_request_maximize(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, request_maximize); + struct roots_view *view = roots_xdg_surface->view; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + return; + } + + view_maximize(view, surface->toplevel_state->next.maximized); +} + static void handle_commit(struct wl_listener *listener, void *data) { - // TODO is there anything we need to do here? + //struct roots_xdg_surface_v6 *roots_xdg_surface = + // wl_container_of(listener, roots_xdg_surface, commit); + //struct roots_view *view = roots_xdg_surface->view; + //struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + // TODO } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -164,6 +191,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->request_resize.notify = handle_request_resize; wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize); + roots_surface->request_maximize.notify = handle_request_maximize; + wl_signal_add(&surface->events.request_maximize, + &roots_surface->request_maximize); struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (!view) { @@ -178,6 +208,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->activate = activate; view->resize = resize; view->move_resize = move_resize; + view->maximize = maximize; view->close = close; view->desktop = desktop; roots_surface->view = view; diff --git a/rootston/xwayland.c b/rootston/xwayland.c index e3fc1c84..b608b143 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -85,11 +85,22 @@ static void close(struct roots_view *view) { wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); } +static void maximize(struct roots_view *view, bool maximized) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + + wlr_xwayland_surface_set_maximized(view->desktop->xwayland, + view->xwayland_surface, maximized); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); view_teardown(roots_surface->view); wl_list_remove(&roots_surface->destroy.link); + wl_list_remove(&roots_surface->request_configure.link); + wl_list_remove(&roots_surface->request_move.link); + wl_list_remove(&roots_surface->request_resize.link); + wl_list_remove(&roots_surface->request_maximize.link); wl_list_remove(&roots_surface->map_notify.link); wl_list_remove(&roots_surface->unmap_notify.link); view_destroy(roots_surface->view); @@ -161,6 +172,17 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { view_begin_resize(input, cursor, view, e->edges); } +static void handle_request_maximize(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, request_maximize); + struct roots_view *view = roots_surface->view; + struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + + bool maximized = xwayland_surface->maximized_vert && + xwayland_surface->maximized_horz; + view_maximize(view, maximized); +} + static void handle_map_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, map_notify); @@ -202,24 +224,24 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { if (roots_surface == NULL) { return; } + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); - roots_surface->request_configure.notify = handle_request_configure; wl_signal_add(&surface->events.request_configure, &roots_surface->request_configure); - roots_surface->map_notify.notify = handle_map_notify; wl_signal_add(&surface->events.map_notify, &roots_surface->map_notify); - roots_surface->unmap_notify.notify = handle_unmap_notify; wl_signal_add(&surface->events.unmap_notify, &roots_surface->unmap_notify); - roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); - roots_surface->request_resize.notify = handle_request_resize; - wl_signal_add(&surface->events.request_resize, &roots_surface->request_resize); + wl_signal_add(&surface->events.request_resize, + &roots_surface->request_resize); + roots_surface->request_maximize.notify = handle_request_maximize; + wl_signal_add(&surface->events.request_maximize, + &roots_surface->request_maximize); struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (view == NULL) { @@ -237,6 +259,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->resize = resize; view->move = move; view->move_resize = move_resize; + view->maximize = maximize; view->close = close; roots_surface->view = view; wlr_list_add(desktop->views, view); |