smooth resize
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
struct absinthe_toplevel *absinthe_toplevel_at(struct absinthe_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy);
|
struct absinthe_toplevel *absinthe_toplevel_at(struct absinthe_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy);
|
||||||
|
|
||||||
|
void absinthe_toplevel_update_borders_geometry(struct absinthe_toplevel *toplevel);
|
||||||
void absinthe_toplevel_set_position(struct absinthe_toplevel *toplevel, int32_t x, int32_t y);
|
void absinthe_toplevel_set_position(struct absinthe_toplevel *toplevel, int32_t x, int32_t y);
|
||||||
void absinthe_toplevel_set_size(struct absinthe_toplevel *toplevel, int32_t width, int32_t height);
|
void absinthe_toplevel_set_size(struct absinthe_toplevel *toplevel, int32_t width, int32_t height);
|
||||||
void absinthe_toplevel_update_border_geometry(struct absinthe_toplevel *toplevel);
|
|
||||||
void absinthe_toplevel_set_border_color(struct absinthe_toplevel *toplevel, const float color[4]);
|
void absinthe_toplevel_set_border_color(struct absinthe_toplevel *toplevel, const float color[4]);
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ struct absinthe_toplevel {
|
|||||||
struct wlr_scene_tree *scene_tree;
|
struct wlr_scene_tree *scene_tree;
|
||||||
struct wlr_scene_tree *scene_surface;
|
struct wlr_scene_tree *scene_surface;
|
||||||
struct wlr_scene_rect *border[4];
|
struct wlr_scene_rect *border[4];
|
||||||
|
bool performing_resize;
|
||||||
struct wlr_box geometry;
|
struct wlr_box geometry;
|
||||||
struct wlr_xdg_toplevel *xdg_toplevel;
|
struct wlr_xdg_toplevel *xdg_toplevel;
|
||||||
struct wl_listener map;
|
struct wl_listener map;
|
||||||
|
|||||||
+22
-25
@@ -24,31 +24,7 @@ struct absinthe_toplevel *absinthe_toplevel_at(struct absinthe_server *server, d
|
|||||||
return tree->node.data;
|
return tree->node.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void absinthe_toplevel_set_position(struct absinthe_toplevel *toplevel, int32_t x, int32_t y)
|
void absinthe_toplevel_update_borders_geometry(struct absinthe_toplevel *toplevel)
|
||||||
{
|
|
||||||
wlr_scene_node_set_position(&toplevel->scene_tree->node, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void absinthe_toplevel_set_size(struct absinthe_toplevel *toplevel, int32_t width, int32_t height)
|
|
||||||
{
|
|
||||||
if (width < 0 || height < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (width == toplevel->xdg_toplevel->current.width && height == toplevel->xdg_toplevel->current.height) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
toplevel->geometry.width = width;
|
|
||||||
toplevel->geometry.height = height;
|
|
||||||
|
|
||||||
int bw = ABSINTHE_BORDER_WIDTH;
|
|
||||||
|
|
||||||
wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, width, height);
|
|
||||||
wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
void absinthe_toplevel_update_border_geometry(struct absinthe_toplevel *toplevel)
|
|
||||||
{
|
{
|
||||||
int bw = ABSINTHE_BORDER_WIDTH;
|
int bw = ABSINTHE_BORDER_WIDTH;
|
||||||
|
|
||||||
@@ -56,6 +32,7 @@ void absinthe_toplevel_update_border_geometry(struct absinthe_toplevel *toplevel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wlr_scene_node_set_position(&toplevel->scene_tree->node, toplevel->geometry.x, toplevel->geometry.y);
|
||||||
wlr_scene_node_set_position(&toplevel->scene_surface->node, bw, bw);
|
wlr_scene_node_set_position(&toplevel->scene_surface->node, bw, bw);
|
||||||
|
|
||||||
wlr_scene_rect_set_size(toplevel->border[0], toplevel->geometry.width - 2 * bw, bw);
|
wlr_scene_rect_set_size(toplevel->border[0], toplevel->geometry.width - 2 * bw, bw);
|
||||||
@@ -69,6 +46,26 @@ void absinthe_toplevel_update_border_geometry(struct absinthe_toplevel *toplevel
|
|||||||
wlr_scene_node_set_position(&toplevel->border[3]->node, toplevel->geometry.width - bw, 0);
|
wlr_scene_node_set_position(&toplevel->border[3]->node, toplevel->geometry.width - bw, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void absinthe_toplevel_set_position(struct absinthe_toplevel *toplevel, int32_t x, int32_t y)
|
||||||
|
{
|
||||||
|
wlr_scene_node_set_position(&toplevel->scene_tree->node, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void absinthe_toplevel_set_size(struct absinthe_toplevel *toplevel, int32_t width, int32_t height)
|
||||||
|
{
|
||||||
|
int bw = ABSINTHE_BORDER_WIDTH;
|
||||||
|
|
||||||
|
if (width - 2 * bw < 0 || height - 2 * bw < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toplevel->geometry.width = width;
|
||||||
|
toplevel->geometry.height = height;
|
||||||
|
|
||||||
|
wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, width, height);
|
||||||
|
wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base);
|
||||||
|
}
|
||||||
|
|
||||||
void absinthe_toplevel_set_border_color(struct absinthe_toplevel *toplevel, const float color[4])
|
void absinthe_toplevel_set_border_color(struct absinthe_toplevel *toplevel, const float color[4])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
|||||||
+28
-13
@@ -18,40 +18,53 @@ static void process_cursor_move(struct absinthe_server *server) {
|
|||||||
uint32_t new_x, new_y;
|
uint32_t new_x, new_y;
|
||||||
new_x = server->cursor->x - server->grab_x + server->grabbed_geometry.x;
|
new_x = server->cursor->x - server->grab_x + server->grabbed_geometry.x;
|
||||||
new_y = server->cursor->y - server->grab_y + server->grabbed_geometry.y;
|
new_y = server->cursor->y - server->grab_y + server->grabbed_geometry.y;
|
||||||
wlr_scene_node_set_position(&toplevel->scene_tree->node, new_x, new_y);
|
toplevel->geometry.x = new_x;
|
||||||
|
toplevel->geometry.y = new_y;
|
||||||
|
absinthe_toplevel_set_position(toplevel, new_x, new_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_cursor_resize(struct absinthe_server *server) {
|
static void process_cursor_resize(struct absinthe_server *server) {
|
||||||
struct absinthe_toplevel *toplevel = server->grabbed_toplevel;
|
struct absinthe_toplevel *toplevel = server->grabbed_toplevel;
|
||||||
|
|
||||||
|
if (toplevel->performing_resize == true) return;
|
||||||
|
|
||||||
if (!toplevel) return;
|
if (!toplevel) return;
|
||||||
|
|
||||||
|
int bw = ABSINTHE_BORDER_WIDTH;
|
||||||
|
|
||||||
int32_t new_x, new_y, new_width, new_height;
|
int32_t new_x, new_y, new_width, new_height;
|
||||||
new_x = server->grabbed_geometry.x;
|
new_x = server->grabbed_geometry.x;
|
||||||
new_y = server->grabbed_geometry.y;
|
new_y = server->grabbed_geometry.y;
|
||||||
new_width = server->grabbed_geometry.width;
|
new_width = server->grabbed_geometry.width;
|
||||||
new_height = server->grabbed_geometry.height;
|
new_height = server->grabbed_geometry.height;
|
||||||
|
|
||||||
|
int32_t dx = server->cursor->x - server->grab_x;
|
||||||
|
int32_t dy = server->cursor->y - server->grab_y;
|
||||||
|
|
||||||
|
if (dx == 0 && dy == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (server->cursor_resize_corner) {
|
switch (server->cursor_resize_corner) {
|
||||||
case ABSINTHE_CURSOR_RESIZE_CORNER_TOP_LEFT:
|
case ABSINTHE_CURSOR_RESIZE_CORNER_TOP_LEFT:
|
||||||
new_x += server->cursor->x - server->grab_x;
|
new_x += dx;
|
||||||
new_y += server->cursor->y - server->grab_y;
|
new_y += dy;
|
||||||
new_width -= server->cursor->x - server->grab_x;
|
new_width -= dx;
|
||||||
new_height -= server->cursor->y - server->grab_y;
|
new_height -= dy;
|
||||||
break;
|
break;
|
||||||
case ABSINTHE_CURSOR_RESIZE_CORNER_TOP_RIGHT:
|
case ABSINTHE_CURSOR_RESIZE_CORNER_TOP_RIGHT:
|
||||||
new_y += server->cursor->y - server->grab_y;
|
new_y += dy;
|
||||||
new_width += server->cursor->x - server->grab_x;
|
new_width += dx;
|
||||||
new_height -= server->cursor->y - server->grab_y;
|
new_height -= dy;
|
||||||
break;
|
break;
|
||||||
case ABSINTHE_CURSOR_RESIZE_CORNER_BOTTOM_LEFT:
|
case ABSINTHE_CURSOR_RESIZE_CORNER_BOTTOM_LEFT:
|
||||||
new_x += server->cursor->x - server->grab_x;
|
new_x += dx;
|
||||||
new_width -= server->cursor->x - server->grab_x;
|
new_width -= dx;
|
||||||
new_height += server->cursor->y - server->grab_y;
|
new_height += dy;
|
||||||
break;
|
break;
|
||||||
case ABSINTHE_CURSOR_RESIZE_CORNER_BOTTOM_RIGHT:
|
case ABSINTHE_CURSOR_RESIZE_CORNER_BOTTOM_RIGHT:
|
||||||
new_width += server->cursor->x - server->grab_x;
|
new_width += dx;
|
||||||
new_height += server->cursor->y - server->grab_y;
|
new_height += dy;
|
||||||
break;
|
break;
|
||||||
default: // unreachable
|
default: // unreachable
|
||||||
break;
|
break;
|
||||||
@@ -62,6 +75,8 @@ static void process_cursor_resize(struct absinthe_server *server) {
|
|||||||
toplevel->geometry.y = new_y;
|
toplevel->geometry.y = new_y;
|
||||||
|
|
||||||
absinthe_toplevel_set_size(toplevel, new_width, new_height);
|
absinthe_toplevel_set_size(toplevel, new_width, new_height);
|
||||||
|
|
||||||
|
toplevel->performing_resize = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -13,14 +13,15 @@ void xdg_toplevel_commit(struct wl_listener *listener, void *data)
|
|||||||
if (toplevel->xdg_toplevel->base->initial_commit) {
|
if (toplevel->xdg_toplevel->base->initial_commit) {
|
||||||
int bw = ABSINTHE_BORDER_WIDTH;
|
int bw = ABSINTHE_BORDER_WIDTH;
|
||||||
|
|
||||||
wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, toplevel->geometry.width - 2 * bw, toplevel->geometry.height - 2 * bw);
|
absinthe_toplevel_set_size(toplevel, toplevel->geometry.width - 2 * bw, toplevel->geometry.height - 2 * bw);
|
||||||
|
|
||||||
if (toplevel->decoration) {
|
if (toplevel->decoration) {
|
||||||
xdg_decoration_request_mode(&toplevel->decoration_request_mode, toplevel->decoration);
|
xdg_decoration_request_mode(&toplevel->decoration_request_mode, toplevel->decoration);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
absinthe_toplevel_update_border_geometry(toplevel);
|
|
||||||
absinthe_toplevel_set_position(toplevel, toplevel->geometry.x, toplevel->geometry.y);
|
absinthe_toplevel_set_position(toplevel, toplevel->geometry.x, toplevel->geometry.y);
|
||||||
|
absinthe_toplevel_update_borders_geometry(toplevel);
|
||||||
|
toplevel->performing_resize = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +34,9 @@ void xdg_toplevel_map(struct wl_listener *listener, void *data)
|
|||||||
toplevel->border[i]->node.data = toplevel;
|
toplevel->border[i]->node.data = toplevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
absinthe_toplevel_update_border_geometry(toplevel);
|
int bw = ABSINTHE_BORDER_WIDTH;
|
||||||
|
|
||||||
|
absinthe_toplevel_set_size(toplevel, toplevel->geometry.width - 2 * bw, toplevel->geometry.height - 2 * bw);
|
||||||
|
|
||||||
absinthe_toplevel_set_border_color(toplevel, bordercolor);
|
absinthe_toplevel_set_border_color(toplevel, bordercolor);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user