aboutsummaryrefslogtreecommitdiff
path: root/rootston/xdg_shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'rootston/xdg_shell.c')
-rw-r--r--rootston/xdg_shell.c153
1 files changed, 72 insertions, 81 deletions
diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c
index c6c00f40..5686b3d7 100644
--- a/rootston/xdg_shell.c
+++ b/rootston/xdg_shell.c
@@ -10,6 +10,7 @@
#include "rootston/desktop.h"
#include "rootston/input.h"
#include "rootston/server.h"
+#include "rootston/view.h"
static const struct roots_view_child_interface popup_impl;
@@ -132,31 +133,31 @@ static struct roots_xdg_popup *popup_create(struct roots_view *view,
}
-static void get_size(const struct roots_view *view, struct wlr_box *box) {
- assert(view->type == ROOTS_XDG_SHELL_VIEW);
- struct wlr_xdg_surface *surface = view->xdg_surface;
+static void get_size(struct roots_view *view, struct wlr_box *box) {
+ struct wlr_xdg_surface *xdg_surface =
+ roots_xdg_surface_from_view(view)->xdg_surface;
struct wlr_box geo_box;
- wlr_xdg_surface_get_geometry(surface, &geo_box);
+ wlr_xdg_surface_get_geometry(xdg_surface, &geo_box);
box->width = geo_box.width;
box->height = geo_box.height;
}
static void activate(struct roots_view *view, bool active) {
- assert(view->type == ROOTS_XDG_SHELL_VIEW);
- struct wlr_xdg_surface *surface = view->xdg_surface;
- if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
- wlr_xdg_toplevel_set_activated(surface, active);
+ struct wlr_xdg_surface *xdg_surface =
+ roots_xdg_surface_from_view(view)->xdg_surface;
+ if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
+ wlr_xdg_toplevel_set_activated(xdg_surface, active);
}
}
-static void apply_size_constraints(struct wlr_xdg_surface *surface,
+static void apply_size_constraints(struct wlr_xdg_surface *xdg_surface,
uint32_t width, uint32_t height, uint32_t *dest_width,
uint32_t *dest_height) {
*dest_width = width;
*dest_height = height;
- struct wlr_xdg_toplevel_state *state = &surface->toplevel->current;
+ struct wlr_xdg_toplevel_state *state = &xdg_surface->toplevel->current;
if (width < state->min_width) {
*dest_width = state->min_width;
} else if (state->max_width > 0 &&
@@ -172,26 +173,26 @@ static void apply_size_constraints(struct wlr_xdg_surface *surface,
}
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
- assert(view->type == ROOTS_XDG_SHELL_VIEW);
- struct wlr_xdg_surface *surface = view->xdg_surface;
- if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
+ struct wlr_xdg_surface *xdg_surface =
+ roots_xdg_surface_from_view(view)->xdg_surface;
+ if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
return;
}
uint32_t constrained_width, constrained_height;
- apply_size_constraints(surface, width, height, &constrained_width,
+ apply_size_constraints(xdg_surface, width, height, &constrained_width,
&constrained_height);
- wlr_xdg_toplevel_set_size(surface, constrained_width,
+ wlr_xdg_toplevel_set_size(xdg_surface, constrained_width,
constrained_height);
}
static void move_resize(struct roots_view *view, double x, double y,
uint32_t width, uint32_t height) {
- assert(view->type == ROOTS_XDG_SHELL_VIEW);
- struct roots_xdg_surface *roots_surface = view->roots_xdg_surface;
- struct wlr_xdg_surface *surface = view->xdg_surface;
- if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
+ struct roots_xdg_surface *xdg_surface =
+ roots_xdg_surface_from_view(view);
+ struct wlr_xdg_surface *wlr_xdg_surface = xdg_surface->xdg_surface;
+ if (wlr_xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
return;
}
@@ -199,7 +200,7 @@ static void move_resize(struct roots_view *view, double x, double y,
bool update_y = y != view->box.y;
uint32_t constrained_width, constrained_height;
- apply_size_constraints(surface, width, height, &constrained_width,
+ apply_size_constraints(wlr_xdg_surface, width, height, &constrained_width,
&constrained_height);
if (update_x) {
@@ -216,48 +217,48 @@ static void move_resize(struct roots_view *view, double x, double y,
view->pending_move_resize.width = constrained_width;
view->pending_move_resize.height = constrained_height;
- uint32_t serial = wlr_xdg_toplevel_set_size(surface, constrained_width,
- constrained_height);
+ uint32_t serial = wlr_xdg_toplevel_set_size(wlr_xdg_surface,
+ constrained_width, constrained_height);
if (serial > 0) {
- roots_surface->pending_move_resize_configure_serial = serial;
- } else if (roots_surface->pending_move_resize_configure_serial == 0) {
+ xdg_surface->pending_move_resize_configure_serial = serial;
+ } else if (xdg_surface->pending_move_resize_configure_serial == 0) {
view_update_position(view, x, y);
}
}
static void maximize(struct roots_view *view, bool maximized) {
- assert(view->type == ROOTS_XDG_SHELL_VIEW);
- struct wlr_xdg_surface *surface = view->xdg_surface;
- if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
+ struct wlr_xdg_surface *xdg_surface =
+ roots_xdg_surface_from_view(view)->xdg_surface;
+ if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
return;
}
- wlr_xdg_toplevel_set_maximized(surface, maximized);
+ wlr_xdg_toplevel_set_maximized(xdg_surface, maximized);
}
static void set_fullscreen(struct roots_view *view, bool fullscreen) {
- assert(view->type == ROOTS_XDG_SHELL_VIEW);
- struct wlr_xdg_surface *surface = view->xdg_surface;
- if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
+ struct wlr_xdg_surface *xdg_surface =
+ roots_xdg_surface_from_view(view)->xdg_surface;
+ if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
return;
}
- wlr_xdg_toplevel_set_fullscreen(surface, fullscreen);
+ wlr_xdg_toplevel_set_fullscreen(xdg_surface, fullscreen);
}
static void close(struct roots_view *view) {
- assert(view->type == ROOTS_XDG_SHELL_VIEW);
- struct wlr_xdg_surface *surface = view->xdg_surface;
+ struct wlr_xdg_surface *xdg_surface =
+ roots_xdg_surface_from_view(view)->xdg_surface;
struct wlr_xdg_popup *popup = NULL;
- wl_list_for_each(popup, &surface->popups, link) {
+ wl_list_for_each(popup, &xdg_surface->popups, link) {
wlr_xdg_popup_destroy(popup->base);
}
- wlr_xdg_toplevel_send_close(surface);
+ wlr_xdg_toplevel_send_close(xdg_surface);
}
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 =
+ roots_xdg_surface_from_view(view);
wl_list_remove(&roots_xdg_surface->surface_commit.link);
wl_list_remove(&roots_xdg_surface->destroy.link);
wl_list_remove(&roots_xdg_surface->new_popup.link);
@@ -269,7 +270,7 @@ static void destroy(struct roots_view *view) {
wl_list_remove(&roots_xdg_surface->request_fullscreen.link);
wl_list_remove(&roots_xdg_surface->set_title.link);
wl_list_remove(&roots_xdg_surface->set_app_id.link);
- roots_xdg_surface->view->xdg_surface->data = NULL;
+ roots_xdg_surface->xdg_surface->data = NULL;
free(roots_xdg_surface);
}
@@ -286,7 +287,7 @@ static const struct roots_view_interface view_impl = {
static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_move);
- struct roots_view *view = roots_xdg_surface->view;
+ struct roots_view *view = &roots_xdg_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_xdg_toplevel_move_event *e = data;
struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat);
@@ -300,7 +301,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
static void handle_request_resize(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_resize);
- struct roots_view *view = roots_xdg_surface->view;
+ struct roots_view *view = &roots_xdg_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_xdg_toplevel_resize_event *e = data;
// TODO verify event serial
@@ -315,8 +316,8 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
static void handle_request_maximize(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_maximize);
- struct roots_view *view = roots_xdg_surface->view;
- struct wlr_xdg_surface *surface = view->xdg_surface;
+ struct roots_view *view = &roots_xdg_surface->view;
+ struct wlr_xdg_surface *surface = roots_xdg_surface->xdg_surface;
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
return;
@@ -329,8 +330,8 @@ static void handle_request_fullscreen(struct wl_listener *listener,
void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, request_fullscreen);
- struct roots_view *view = roots_xdg_surface->view;
- struct wlr_xdg_surface *surface = view->xdg_surface;
+ struct roots_view *view = &roots_xdg_surface->view;
+ struct wlr_xdg_surface *surface = roots_xdg_surface->xdg_surface;
struct wlr_xdg_toplevel_set_fullscreen_event *e = data;
if (surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
@@ -344,23 +345,23 @@ static void handle_set_title(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, set_title);
- view_set_title(roots_xdg_surface->view,
- roots_xdg_surface->view->xdg_surface->toplevel->title);
+ view_set_title(&roots_xdg_surface->view,
+ roots_xdg_surface->xdg_surface->toplevel->title);
}
static void handle_set_app_id(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, set_app_id);
- view_set_app_id(roots_xdg_surface->view,
- roots_xdg_surface->view->xdg_surface->toplevel->app_id);
+ view_set_app_id(&roots_xdg_surface->view,
+ roots_xdg_surface->xdg_surface->toplevel->app_id);
}
static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_surface =
wl_container_of(listener, roots_surface, surface_commit);
- struct roots_view *view = roots_surface->view;
- struct wlr_xdg_surface *surface = view->xdg_surface;
+ struct roots_view *view = &roots_surface->view;
+ struct wlr_xdg_surface *surface = roots_surface->xdg_surface;
if (!surface->mapped) {
return;
@@ -397,38 +398,38 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, new_popup);
struct wlr_xdg_popup *wlr_popup = 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 roots_view *view = &roots_xdg_surface->view;
struct wlr_box box;
get_size(view, &box);
view->box.width = box.width;
view->box.height = box.height;
- view_map(view, view->xdg_surface->surface);
+ view_map(view, roots_xdg_surface->xdg_surface->surface);
view_setup(view);
wlr_foreign_toplevel_handle_v1_set_title(view->toplevel_handle,
- view->xdg_surface->toplevel->title ?: "none");
+ roots_xdg_surface->xdg_surface->toplevel->title ?: "none");
wlr_foreign_toplevel_handle_v1_set_app_id(view->toplevel_handle,
- view->xdg_surface->toplevel->app_id ?: "none");
+ roots_xdg_surface->xdg_surface->toplevel->app_id ?: "none");
}
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);
+ view_unmap(&roots_xdg_surface->view);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, destroy);
- view_destroy(roots_xdg_surface->view);
+ view_destroy(&roots_xdg_surface->view);
}
void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
@@ -452,6 +453,11 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
if (!roots_surface) {
return;
}
+
+ view_init(&roots_surface->view, &view_impl, ROOTS_XDG_SHELL_VIEW, desktop);
+ roots_surface->xdg_surface = surface;
+ surface->data = roots_surface;
+
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
@@ -480,36 +486,16 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
&roots_surface->set_app_id);
roots_surface->new_popup.notify = handle_new_popup;
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
- surface->data = roots_surface;
-
- struct roots_view *view = view_create(desktop, &view_impl);
- if (!view) {
- free(roots_surface);
- return;
- }
- view->type = ROOTS_XDG_SHELL_VIEW;
-
- view->xdg_surface = surface;
- view->roots_xdg_surface = roots_surface;
- roots_surface->view = view;
-
- if (surface->toplevel->client_pending.maximized) {
- view_maximize(view, true);
- }
- if (surface->toplevel->client_pending.fullscreen) {
- view_set_fullscreen(view, true, NULL);
- }
}
-
static void decoration_handle_destroy(struct wl_listener *listener,
void *data) {
struct roots_xdg_toplevel_decoration *decoration =
wl_container_of(listener, decoration, destroy);
decoration->surface->xdg_toplevel_decoration = NULL;
- view_update_decorated(decoration->surface->view, false);
+ view_update_decorated(&decoration->surface->view, false);
wl_list_remove(&decoration->destroy.link);
wl_list_remove(&decoration->request_mode.link);
wl_list_remove(&decoration->surface_commit.link);
@@ -536,7 +522,7 @@ static void decoration_handle_surface_commit(struct wl_listener *listener,
bool decorated = decoration->wlr_decoration->current_mode ==
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
- view_update_decorated(decoration->surface->view, decorated);
+ view_update_decorated(&decoration->surface->view, decorated);
}
void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data) {
@@ -546,7 +532,7 @@ void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data) {
struct roots_xdg_surface *xdg_surface = wlr_decoration->surface->data;
assert(xdg_surface != NULL);
- struct wlr_xdg_surface *wlr_xdg_surface = xdg_surface->view->xdg_surface;
+ struct wlr_xdg_surface *wlr_xdg_surface = xdg_surface->xdg_surface;
struct roots_xdg_toplevel_decoration *decoration =
calloc(1, sizeof(struct roots_xdg_toplevel_decoration));
@@ -568,3 +554,8 @@ void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data) {
decoration_handle_request_mode(&decoration->request_mode, wlr_decoration);
}
+
+struct roots_xdg_surface *roots_xdg_surface_from_view(struct roots_view *view) {
+ assert(view->impl == &view_impl);
+ return (struct roots_xdg_surface *)view;
+}