aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorRonan Pigott <rpigott@berkeley.edu>2020-07-06 23:57:48 -0700
committerBrian Ashworth <bosrsf04@gmail.com>2020-07-13 00:21:52 -0400
commit39d677af15bd4c8cdea6b62fda80ac9a9e998045 (patch)
tree0612524effa083389ecce17d0f0dafad8f25d6ec /sway
parent10ec97c073ea7c06f7c129a4baa4576783248148 (diff)
input: implement xdg_toplevel interactive resize hints
Diffstat (limited to 'sway')
-rw-r--r--sway/desktop/xdg_shell.c9
-rw-r--r--sway/input/seatop_resize_floating.c6
-rw-r--r--sway/input/seatop_resize_tiling.c50
-rw-r--r--sway/tree/container.c22
4 files changed, 87 insertions, 0 deletions
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index df751ef6..3437cc07 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -185,6 +185,14 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) {
wlr_xdg_toplevel_set_fullscreen(surface, fullscreen);
}
+static void set_resizing(struct sway_view *view, bool resizing) {
+ if (xdg_shell_view_from_view(view) == NULL) {
+ return;
+ }
+ struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
+ wlr_xdg_toplevel_set_resizing(surface, resizing);
+}
+
static bool wants_floating(struct sway_view *view) {
struct wlr_xdg_toplevel *toplevel = view->wlr_xdg_surface->toplevel;
struct wlr_xdg_toplevel_state *state = &toplevel->current;
@@ -260,6 +268,7 @@ static const struct sway_view_impl view_impl = {
.set_activated = set_activated,
.set_tiled = set_tiled,
.set_fullscreen = set_fullscreen,
+ .set_resizing = set_resizing,
.wants_floating = wants_floating,
.for_each_surface = for_each_surface,
.for_each_popup = for_each_popup,
diff --git a/sway/input/seatop_resize_floating.c b/sway/input/seatop_resize_floating.c
index ec10cfc8..10af06fe 100644
--- a/sway/input/seatop_resize_floating.c
+++ b/sway/input/seatop_resize_floating.c
@@ -21,7 +21,12 @@ struct seatop_resize_floating_event {
static void handle_button(struct sway_seat *seat, uint32_t time_msec,
struct wlr_input_device *device, uint32_t button,
enum wlr_button_state state) {
+ struct seatop_resize_floating_event *e = seat->seatop_data;
+ struct sway_container *con = e->con;
+
if (seat->cursor->pressed_button_count == 0) {
+ container_set_resizing(con, false);
+ arrange_container(con); // Send configure w/o resizing hint
seatop_begin_default(seat);
}
}
@@ -170,6 +175,7 @@ void seatop_begin_resize_floating(struct sway_seat *seat,
seat->seatop_impl = &seatop_impl;
seat->seatop_data = e;
+ container_set_resizing(con, true);
container_raise_floating(con);
const char *image = edge == WLR_EDGE_NONE ?
diff --git a/sway/input/seatop_resize_tiling.c b/sway/input/seatop_resize_tiling.c
index f6f106ef..0dfafbd0 100644
--- a/sway/input/seatop_resize_tiling.c
+++ b/sway/input/seatop_resize_tiling.c
@@ -4,6 +4,9 @@
#include "sway/commands.h"
#include "sway/input/cursor.h"
#include "sway/input/seat.h"
+#include "sway/tree/arrange.h"
+#include "sway/tree/container.h"
+#include "sway/tree/view.h"
struct seatop_resize_tiling_event {
struct sway_container *con; // leaf container
@@ -12,6 +15,10 @@ struct seatop_resize_tiling_event {
struct sway_container *h_con;
struct sway_container *v_con;
+ // sibling con(s) that will be resized to accommodate
+ struct sway_container *h_sib;
+ struct sway_container *v_sib;
+
enum wlr_edges edge;
enum wlr_edges edge_x, edge_y;
double ref_lx, ref_ly; // cursor's x/y at start of op
@@ -19,10 +26,47 @@ struct seatop_resize_tiling_event {
double v_con_orig_height; // height of the vertical ancestor at start
};
+static struct sway_container *container_get_resize_sibling(
+ struct sway_container *con, uint32_t edge) {
+ if (!con) {
+ return NULL;
+ }
+
+ list_t *siblings = container_get_siblings(con);
+ int index = container_sibling_index(con);
+ int offset = edge & (WLR_EDGE_TOP | WLR_EDGE_LEFT) ? -1 : 1;
+
+ if (siblings->length == 1) {
+ return NULL;
+ } else {
+ return siblings->items[index + offset];
+ }
+}
+
static void handle_button(struct sway_seat *seat, uint32_t time_msec,
struct wlr_input_device *device, uint32_t button,
enum wlr_button_state state) {
+ struct seatop_resize_tiling_event *e = seat->seatop_data;
+
if (seat->cursor->pressed_button_count == 0) {
+ if (e->h_con) {
+ container_set_resizing(e->h_con, false);
+ container_set_resizing(e->h_sib, false);
+ if (e->h_con->parent) {
+ arrange_container(e->h_con->parent);
+ } else {
+ arrange_workspace(e->h_con->workspace);
+ }
+ }
+ if (e->v_con) {
+ container_set_resizing(e->v_con, false);
+ container_set_resizing(e->v_sib, false);
+ if (e->v_con->parent) {
+ arrange_container(e->v_con->parent);
+ } else {
+ arrange_workspace(e->v_con->workspace);
+ }
+ }
seatop_begin_default(seat);
}
}
@@ -89,16 +133,22 @@ void seatop_begin_resize_tiling(struct sway_seat *seat,
if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) {
e->edge_x = edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT);
e->h_con = container_find_resize_parent(e->con, e->edge_x);
+ e->h_sib = container_get_resize_sibling(e->h_con, e->edge_x);
if (e->h_con) {
+ container_set_resizing(e->h_con, true);
+ container_set_resizing(e->h_sib, true);
e->h_con_orig_width = e->h_con->width;
}
}
if (edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)) {
e->edge_y = edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM);
e->v_con = container_find_resize_parent(e->con, e->edge_y);
+ e->v_sib = container_get_resize_sibling(e->v_con, e->edge_y);
if (e->v_con) {
+ container_set_resizing(e->v_con, true);
+ container_set_resizing(e->v_sib, true);
e->v_con_orig_height = e->v_con->height;
}
}
diff --git a/sway/tree/container.c b/sway/tree/container.c
index fa1598ef..65696f15 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -746,6 +746,28 @@ void container_floating_set_default_size(struct sway_container *con) {
free(box);
}
+
+/**
+ * Indicate to clients in this container that they are participating in (or
+ * have just finished) an interactive resize
+ */
+void container_set_resizing(struct sway_container *con, bool resizing) {
+ if (!con) {
+ return;
+ }
+
+ if (con->view) {
+ if (con->view->impl->set_resizing) {
+ con->view->impl->set_resizing(con->view, resizing);
+ }
+ } else {
+ for (int i = 0; i < con->children->length; ++i ) {
+ struct sway_container *child = con->children->items[i];
+ container_set_resizing(child, resizing);
+ }
+ }
+}
+
void container_set_floating(struct sway_container *container, bool enable) {
if (container_is_floating(container) == enable) {
return;