mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 14:45:58 +01:00
Basic maximization implementation for xdg-shell
This commit is contained in:
parent
74a45ee776
commit
03d3fdc158
4 changed files with 87 additions and 2 deletions
|
@ -48,8 +48,17 @@ enum roots_view_type {
|
|||
|
||||
struct roots_view {
|
||||
struct roots_desktop *desktop;
|
||||
|
||||
double x, y;
|
||||
float rotation;
|
||||
|
||||
bool maximized;
|
||||
struct {
|
||||
double x, y;
|
||||
uint32_t width, height;
|
||||
float rotation;
|
||||
} saved;
|
||||
|
||||
// TODO: Something for roots-enforced width/height
|
||||
enum roots_view_type type;
|
||||
union {
|
||||
|
@ -67,6 +76,7 @@ struct roots_view {
|
|||
#endif
|
||||
};
|
||||
struct wlr_surface *wlr_surface;
|
||||
|
||||
// TODO: This would probably be better as a field that's updated on a
|
||||
// configure event from the xdg_shell
|
||||
// If not then this should follow the typical type/impl pattern we use
|
||||
|
@ -77,6 +87,7 @@ struct roots_view {
|
|||
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
|
||||
void (*move_resize)(struct roots_view *view, double x, double y,
|
||||
uint32_t width, uint32_t height);
|
||||
void (*maximize)(struct roots_view *view, bool maximized);
|
||||
void (*close)(struct roots_view *view);
|
||||
};
|
||||
|
||||
|
@ -86,6 +97,7 @@ void view_move(struct roots_view *view, double x, double y);
|
|||
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
|
||||
void view_move_resize(struct roots_view *view, double x, double y,
|
||||
uint32_t width, uint32_t height);
|
||||
void view_maximize(struct roots_view *view, bool maximized);
|
||||
void view_close(struct roots_view *view);
|
||||
bool view_center(struct roots_view *view);
|
||||
void view_setup(struct roots_view *view);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue