mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-29 16:05:59 +01:00
xdg-shell: add map/unmap support
This commit is contained in:
parent
42cc575266
commit
e607d0f7ee
4 changed files with 356 additions and 257 deletions
|
@ -44,6 +44,8 @@ struct roots_xdg_surface {
|
||||||
|
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
struct wl_listener new_popup;
|
struct wl_listener new_popup;
|
||||||
|
struct wl_listener map;
|
||||||
|
struct wl_listener unmap;
|
||||||
struct wl_listener request_move;
|
struct wl_listener request_move;
|
||||||
struct wl_listener request_resize;
|
struct wl_listener request_resize;
|
||||||
struct wl_listener request_maximize;
|
struct wl_listener request_maximize;
|
||||||
|
|
|
@ -62,19 +62,10 @@ enum wlr_xdg_surface_role {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_xdg_toplevel_state {
|
struct wlr_xdg_toplevel_state {
|
||||||
bool maximized;
|
bool maximized, fullscreen, resizing, activated;
|
||||||
bool fullscreen;
|
uint32_t width, height;
|
||||||
bool resizing;
|
uint32_t max_width, max_height;
|
||||||
bool activated;
|
uint32_t min_width, min_height;
|
||||||
|
|
||||||
uint32_t width;
|
|
||||||
uint32_t height;
|
|
||||||
|
|
||||||
uint32_t max_width;
|
|
||||||
uint32_t max_height;
|
|
||||||
|
|
||||||
uint32_t min_width;
|
|
||||||
uint32_t min_height;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_xdg_toplevel {
|
struct wlr_xdg_toplevel {
|
||||||
|
@ -90,7 +81,8 @@ struct wlr_xdg_toplevel {
|
||||||
struct wlr_xdg_surface_configure {
|
struct wlr_xdg_surface_configure {
|
||||||
struct wl_list link; // wlr_xdg_surface::configure_list
|
struct wl_list link; // wlr_xdg_surface::configure_list
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
struct wlr_xdg_toplevel_state state;
|
|
||||||
|
struct wlr_xdg_toplevel_state *toplevel_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_xdg_surface {
|
struct wlr_xdg_surface {
|
||||||
|
@ -101,14 +93,13 @@ struct wlr_xdg_surface {
|
||||||
enum wlr_xdg_surface_role role;
|
enum wlr_xdg_surface_role role;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct wlr_xdg_toplevel *toplevel_state;
|
struct wlr_xdg_toplevel *toplevel;
|
||||||
struct wlr_xdg_popup *popup_state;
|
struct wlr_xdg_popup *popup;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_list popups; // wlr_xdg_popup::link
|
struct wl_list popups; // wlr_xdg_popup::link
|
||||||
|
|
||||||
bool configured;
|
bool added, configured, mapped;
|
||||||
bool added;
|
|
||||||
uint32_t configure_serial;
|
uint32_t configure_serial;
|
||||||
struct wl_event_source *configure_idle;
|
struct wl_event_source *configure_idle;
|
||||||
uint32_t configure_next_serial;
|
uint32_t configure_next_serial;
|
||||||
|
@ -118,8 +109,8 @@ struct wlr_xdg_surface {
|
||||||
char *app_id;
|
char *app_id;
|
||||||
|
|
||||||
bool has_next_geometry;
|
bool has_next_geometry;
|
||||||
struct wlr_box *next_geometry;
|
struct wlr_box next_geometry;
|
||||||
struct wlr_box *geometry;
|
struct wlr_box geometry;
|
||||||
|
|
||||||
struct wl_listener surface_destroy_listener;
|
struct wl_listener surface_destroy_listener;
|
||||||
|
|
||||||
|
@ -127,6 +118,8 @@ struct wlr_xdg_surface {
|
||||||
struct wl_signal destroy;
|
struct wl_signal destroy;
|
||||||
struct wl_signal ping_timeout;
|
struct wl_signal ping_timeout;
|
||||||
struct wl_signal new_popup;
|
struct wl_signal new_popup;
|
||||||
|
struct wl_signal map;
|
||||||
|
struct wl_signal unmap;
|
||||||
|
|
||||||
struct wl_signal request_maximize;
|
struct wl_signal request_maximize;
|
||||||
struct wl_signal request_fullscreen;
|
struct wl_signal request_fullscreen;
|
||||||
|
|
|
@ -60,12 +60,14 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) {
|
||||||
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||||
|
|
||||||
if (surface->geometry->width > 0 && surface->geometry->height > 0) {
|
if (surface->geometry.width > 0 && surface->geometry.height > 0) {
|
||||||
box->width = surface->geometry->width;
|
box->width = surface->geometry.width;
|
||||||
box->height = surface->geometry->height;
|
box->height = surface->geometry.height;
|
||||||
} else {
|
} else if (view->wlr_surface != NULL) {
|
||||||
box->width = view->wlr_surface->current->width;
|
box->width = view->wlr_surface->current->width;
|
||||||
box->height = view->wlr_surface->current->height;
|
box->height = view->wlr_surface->current->height;
|
||||||
|
} else {
|
||||||
|
box->width = box->height = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ static void apply_size_constraints(struct wlr_xdg_surface *surface,
|
||||||
*dest_width = width;
|
*dest_width = width;
|
||||||
*dest_height = height;
|
*dest_height = height;
|
||||||
|
|
||||||
struct wlr_xdg_toplevel_state *state = &surface->toplevel_state->current;
|
struct wlr_xdg_toplevel_state *state = &surface->toplevel->current;
|
||||||
if (width < state->min_width) {
|
if (width < state->min_width) {
|
||||||
*dest_width = state->min_width;
|
*dest_width = state->min_width;
|
||||||
} else if (state->max_width > 0 &&
|
} else if (state->max_width > 0 &&
|
||||||
|
@ -181,10 +183,13 @@ static void close(struct roots_view *view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy(struct roots_view *view) {
|
static void destroy(struct roots_view *view) {
|
||||||
|
assert(view->type == ROOTS_XDG_SHELL_VIEW);
|
||||||
struct roots_xdg_surface *roots_xdg_surface = view->roots_xdg_surface;
|
struct roots_xdg_surface *roots_xdg_surface = view->roots_xdg_surface;
|
||||||
wl_list_remove(&roots_xdg_surface->surface_commit.link);
|
wl_list_remove(&roots_xdg_surface->surface_commit.link);
|
||||||
wl_list_remove(&roots_xdg_surface->destroy.link);
|
wl_list_remove(&roots_xdg_surface->destroy.link);
|
||||||
wl_list_remove(&roots_xdg_surface->new_popup.link);
|
wl_list_remove(&roots_xdg_surface->new_popup.link);
|
||||||
|
wl_list_remove(&roots_xdg_surface->map.link);
|
||||||
|
wl_list_remove(&roots_xdg_surface->unmap.link);
|
||||||
wl_list_remove(&roots_xdg_surface->request_move.link);
|
wl_list_remove(&roots_xdg_surface->request_move.link);
|
||||||
wl_list_remove(&roots_xdg_surface->request_resize.link);
|
wl_list_remove(&roots_xdg_surface->request_resize.link);
|
||||||
wl_list_remove(&roots_xdg_surface->request_maximize.link);
|
wl_list_remove(&roots_xdg_surface->request_maximize.link);
|
||||||
|
@ -231,7 +236,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
view_maximize(view, surface->toplevel_state->next.maximized);
|
view_maximize(view, surface->toplevel->next.maximized);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_request_fullscreen(struct wl_listener *listener,
|
static void handle_request_fullscreen(struct wl_listener *listener,
|
||||||
|
@ -255,6 +260,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
|
||||||
struct roots_view *view = roots_surface->view;
|
struct roots_view *view = roots_surface->view;
|
||||||
struct wlr_xdg_surface *surface = view->xdg_surface;
|
struct wlr_xdg_surface *surface = view->xdg_surface;
|
||||||
|
|
||||||
|
if (!surface->mapped) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
view_apply_damage(view);
|
view_apply_damage(view);
|
||||||
|
|
||||||
struct wlr_box size;
|
struct wlr_box size;
|
||||||
|
@ -289,6 +298,26 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
|
||||||
popup_create(roots_xdg_surface->view, wlr_popup);
|
popup_create(roots_xdg_surface->view, wlr_popup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handle_map(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_xdg_surface *roots_xdg_surface =
|
||||||
|
wl_container_of(listener, roots_xdg_surface, map);
|
||||||
|
struct roots_view *view = roots_xdg_surface->view;
|
||||||
|
|
||||||
|
struct wlr_box box;
|
||||||
|
get_size(view, &box);
|
||||||
|
view->width = box.width;
|
||||||
|
view->height = box.height;
|
||||||
|
|
||||||
|
view_map(view, view->xdg_surface->surface);
|
||||||
|
view_setup(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_unmap(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_xdg_surface *roots_xdg_surface =
|
||||||
|
wl_container_of(listener, roots_xdg_surface, unmap);
|
||||||
|
view_unmap(roots_xdg_surface->view);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct roots_xdg_surface *roots_xdg_surface =
|
struct roots_xdg_surface *roots_xdg_surface =
|
||||||
wl_container_of(listener, roots_xdg_surface, destroy);
|
wl_container_of(listener, roots_xdg_surface, destroy);
|
||||||
|
@ -321,6 +350,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
|
||||||
&roots_surface->surface_commit);
|
&roots_surface->surface_commit);
|
||||||
roots_surface->destroy.notify = handle_destroy;
|
roots_surface->destroy.notify = handle_destroy;
|
||||||
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
|
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
|
||||||
|
roots_surface->map.notify = handle_map;
|
||||||
|
wl_signal_add(&surface->events.map, &roots_surface->map);
|
||||||
|
roots_surface->unmap.notify = handle_unmap;
|
||||||
|
wl_signal_add(&surface->events.unmap, &roots_surface->unmap);
|
||||||
roots_surface->request_move.notify = handle_request_move;
|
roots_surface->request_move.notify = handle_request_move;
|
||||||
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
|
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
|
||||||
roots_surface->request_resize.notify = handle_request_resize;
|
roots_surface->request_resize.notify = handle_request_resize;
|
||||||
|
@ -353,11 +386,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
|
||||||
view->destroy = destroy;
|
view->destroy = destroy;
|
||||||
roots_surface->view = view;
|
roots_surface->view = view;
|
||||||
|
|
||||||
struct wlr_box box;
|
if (surface->toplevel->next.maximized) {
|
||||||
get_size(view, &box);
|
view_maximize(view, true);
|
||||||
view->width = box.width;
|
}
|
||||||
view->height = box.height;
|
if (surface->toplevel->next.fullscreen) {
|
||||||
|
view_set_fullscreen(view, true, NULL);
|
||||||
view_map(view, surface->surface);
|
}
|
||||||
view_setup(view);
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue