mirror of
https://github.com/swaywm/sway.git
synced 2024-12-27 15:36:29 +01:00
input: implement xdg_toplevel interactive resize hints
This commit is contained in:
parent
10ec97c073
commit
39d677af15
6 changed files with 90 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 ?
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue