aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2017-11-05 16:29:43 +0100
committeremersion <contact@emersion.fr>2017-11-05 16:29:43 +0100
commit03d3fdc15879c6fbdd24d5fe1d60f9a77402220d (patch)
treef442d9c2cf8e73393d5fa8474b584aae2bae3afe /rootston
parent74a45ee776ec05b5dbe7bae5be456ba08a850d7b (diff)
Basic maximization implementation for xdg-shell
Diffstat (limited to 'rootston')
-rw-r--r--rootston/cursor.c9
-rw-r--r--rootston/desktop.c44
-rw-r--r--rootston/xdg_shell_v6.c24
3 files changed, 75 insertions, 2 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c
index b153e8c8..d97d518e 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -39,6 +39,8 @@ static void cursor_set_xcursor_image(struct roots_input *input,
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
struct roots_view *view) {
+ view_maximize(view, false);
+
input->mode = ROOTS_CURSOR_MOVE;
input->offs_x = cursor->x;
input->offs_y = cursor->y;
@@ -54,6 +56,8 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
struct roots_view *view, uint32_t edges) {
+ view_maximize(view, false);
+
input->mode = ROOTS_CURSOR_RESIZE;
input->offs_x = cursor->x;
input->offs_y = cursor->y;
@@ -74,6 +78,8 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor,
struct roots_view *view) {
+ view_maximize(view, false);
+
input->mode = ROOTS_CURSOR_ROTATE;
input->offs_x = cursor->x;
input->offs_y = cursor->y;
@@ -102,7 +108,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
set_compositor_cursor = view_client != input->cursor_client;
}
if (set_compositor_cursor) {
- struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
+ struct wlr_xcursor *xcursor =
+ get_default_xcursor(input->xcursor_theme);
cursor_set_xcursor_image(input, xcursor->images[0]);
input->cursor_client = NULL;
}
diff --git a/rootston/desktop.c b/rootston/desktop.c
index 29f78ac7..f5d5925b 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -78,6 +78,50 @@ void view_move_resize(struct roots_view *view, double x, double y,
view_resize(view, width, height);
}
+void view_maximize(struct roots_view *view, bool maximized) {
+ if (view->maximized == maximized) {
+ return;
+ }
+
+ if (view->maximize) {
+ view->maximize(view, maximized);
+ }
+
+ if (!view->maximized && maximized) {
+ struct wlr_box view_box;
+ view_get_size(view, &view_box);
+
+ view->maximized = true;
+ view->saved.x = view->x;
+ view->saved.y = view->y;
+ view->saved.rotation = view->rotation;
+ view->saved.width = view_box.width;
+ view->saved.height = view_box.height;
+
+ double output_x, output_y;
+ wlr_output_layout_closest_point(view->desktop->layout, NULL,
+ view->x + (double)view_box.width/2,
+ view->y + (double)view_box.height/2,
+ &output_x, &output_y);
+ struct wlr_output *output = wlr_output_layout_output_at(
+ view->desktop->layout, output_x, output_y);
+ struct wlr_box *output_box =
+ wlr_output_layout_get_box(view->desktop->layout, output);
+
+ view_move_resize(view, output_box->x, output_box->y, output_box->width,
+ output_box->height);
+ view->rotation = 0;
+ }
+
+ if (view->maximized && !maximized) {
+ view->maximized = false;
+
+ view_move_resize(view, view->saved.x, view->saved.y, view->saved.width,
+ view->saved.height);
+ view->rotation = view->saved.rotation;
+ }
+}
+
void view_close(struct roots_view *view) {
if (view->close) {
view->close(view);
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index ca33c582..45691d16 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -84,6 +84,16 @@ static void move_resize(struct roots_view *view, double x, double y,
wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height);
}
+static void maximize(struct roots_view *view, bool maximized) {
+ assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
+ struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
+ if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
+ return;
+ }
+
+ wlr_xdg_toplevel_v6_set_maximized(surface, maximized);
+}
+
static void close(struct roots_view *view) {
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
@@ -119,7 +129,18 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
}
static void handle_commit(struct wl_listener *listener, void *data) {
- // TODO is there anything we need to do here?
+ struct roots_xdg_surface_v6 *roots_xdg_surface =
+ wl_container_of(listener, roots_xdg_surface, commit);
+ struct roots_view *view = roots_xdg_surface->view;
+ struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6;
+
+ if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
+ return;
+ }
+
+ if (view->maximized != surface->toplevel_state->current.maximized) {
+ view_maximize(view, surface->toplevel_state->current.maximized);
+ }
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -178,6 +199,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->activate = activate;
view->resize = resize;
view->move_resize = move_resize;
+ view->maximize = maximize;
view->close = close;
view->desktop = desktop;
roots_surface->view = view;