aboutsummaryrefslogtreecommitdiff
path: root/sway/desktop/xdg_shell_v6.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop/xdg_shell_v6.c')
-rw-r--r--sway/desktop/xdg_shell_v6.c67
1 files changed, 24 insertions, 43 deletions
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index cffe83fb..49305b39 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -30,23 +30,18 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
}
}
-static void set_size(struct sway_view *view, int width, int height) {
+static void configure(struct sway_view *view, double ox, double oy, int width,
+ int height) {
if (!assert_xdg(view)) {
return;
}
+
+ view_update_position(view, ox, oy);
view->sway_xdg_surface_v6->pending_width = width;
view->sway_xdg_surface_v6->pending_height = height;
wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height);
}
-static void set_position(struct sway_view *view, double ox, double oy) {
- if (!assert_xdg(view)) {
- return;
- }
- view->swayc->x = ox;
- view->swayc->y = oy;
-}
-
static void set_activated(struct sway_view *view, bool activated) {
if (!assert_xdg(view)) {
return;
@@ -57,7 +52,7 @@ static void set_activated(struct sway_view *view, bool activated) {
}
}
-static void close(struct sway_view *view) {
+static void _close(struct sway_view *view) {
if (!assert_xdg(view)) {
return;
}
@@ -67,6 +62,13 @@ static void close(struct sway_view *view) {
}
}
+static const struct sway_view_impl view_impl = {
+ .get_prop = get_prop,
+ .configure = configure,
+ .set_activated = set_activated,
+ .close = _close,
+};
+
static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_surface_v6 *sway_surface =
wl_container_of(listener, sway_surface, commit);
@@ -74,37 +76,22 @@ static void handle_commit(struct wl_listener *listener, void *data) {
// NOTE: We intentionally discard the view's desired width here
// TODO: Store this for restoration when moving to floating plane
// TODO: Let floating views do whatever
- view->width = sway_surface->pending_width;
- view->height = sway_surface->pending_height;
+ view_update_size(view, sway_surface->pending_width,
+ sway_surface->pending_height);
view_damage_from(view);
}
static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xdg_surface_v6 *sway_surface =
wl_container_of(listener, sway_surface, unmap);
- view_damage_whole(sway_surface->view);
- container_view_destroy(sway_surface->view->swayc);
- sway_surface->view->swayc = NULL;
- sway_surface->view->surface = NULL;
+ view_unmap(sway_surface->view);
}
static void handle_map(struct wl_listener *listener, void *data) {
struct sway_xdg_surface_v6 *sway_surface =
wl_container_of(listener, sway_surface, map);
struct sway_view *view = sway_surface->view;
-
- sway_surface->view->surface = view->wlr_xdg_surface_v6->surface;
-
- container_view_destroy(view->swayc);
-
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct sway_container *focus = seat_get_focus_inactive(seat, &root_container);
- struct sway_container *cont = container_view_create(focus, view);
- view->swayc = cont;
- arrange_windows(cont->parent, -1, -1);
- input_manager_set_focus(input_manager, cont);
-
- view_damage_whole(sway_surface->view);
+ view_map(view, view->wlr_xdg_surface_v6->surface);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -112,8 +99,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_container_of(listener, sway_xdg_surface, destroy);
wl_list_remove(&sway_xdg_surface->commit.link);
wl_list_remove(&sway_xdg_surface->destroy.link);
- container_view_destroy(sway_xdg_surface->view->swayc);
- free(sway_xdg_surface->view);
+ wl_list_remove(&sway_xdg_surface->map.link);
+ wl_list_remove(&sway_xdg_surface->unmap.link);
+ view_destroy(sway_xdg_surface->view);
free(sway_xdg_surface);
}
@@ -138,23 +126,16 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
return;
}
- struct sway_view *sway_view = calloc(1, sizeof(struct sway_view));
- if (!sway_assert(sway_view, "Failed to allocate view!")) {
+ struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW, &view_impl);
+ if (!sway_assert(view, "Failed to allocate view")) {
return;
}
- sway_view->type = SWAY_XDG_SHELL_V6_VIEW;
- sway_view->iface.get_prop = get_prop;
- sway_view->iface.set_size = set_size;
- sway_view->iface.set_position = set_position;
- sway_view->iface.set_activated = set_activated;
- sway_view->iface.close = close;
- sway_view->wlr_xdg_surface_v6 = xdg_surface;
- sway_view->sway_xdg_surface_v6 = sway_surface;
- sway_surface->view = sway_view;
+ view->wlr_xdg_surface_v6 = xdg_surface;
+ view->sway_xdg_surface_v6 = sway_surface;
+ sway_surface->view = view;
// TODO:
// - Look up pid and open on appropriate workspace
- // - Set new view to maximized so it behaves nicely
// - Criteria
sway_surface->commit.notify = handle_commit;