Skip to content

Commit

Permalink
input: implement xdg_toplevel interactive resize hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan Pigott authored and RedSoxFan committed Jul 13, 2020
1 parent 10ec97c commit 39d677a
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/sway/tree/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ void container_floating_resize_and_center(struct sway_container *con);

void container_floating_set_default_size(struct sway_container *con);

void container_set_resizing(struct sway_container *con, bool resizing);

void container_set_floating(struct sway_container *container, bool enable);

void container_set_geometry_from_content(struct sway_container *con);
Expand Down
1 change: 1 addition & 0 deletions include/sway/tree/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct sway_view_impl {
void (*set_activated)(struct sway_view *view, bool activated);
void (*set_tiled)(struct sway_view *view, bool tiled);
void (*set_fullscreen)(struct sway_view *view, bool fullscreen);
void (*set_resizing)(struct sway_view *view, bool resizing);
bool (*wants_floating)(struct sway_view *view);
void (*for_each_surface)(struct sway_view *view,
wlr_surface_iterator_func_t iterator, void *user_data);
Expand Down
9 changes: 9 additions & 0 deletions sway/desktop/xdg_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions sway/input/seatop_resize_floating.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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 ?
Expand Down
50 changes: 50 additions & 0 deletions sway/input/seatop_resize_tiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,17 +15,58 @@ 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
double h_con_orig_width; // width of the horizontal ancestor at start
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);
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
22 changes: 22 additions & 0 deletions sway/tree/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 39d677a

Please sign in to comment.