aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-04-05 22:53:21 -0400
committerGitHub <noreply@github.com>2018-04-05 22:53:21 -0400
commitf63d9417cd4d25121fa1fd309acad14a7562a55c (patch)
treec46a070652793db69ec5d6c5258d0e6cf86c1231
parent268c68b41707a664e5059699c720f000f20e2276 (diff)
parent641807d920854fdecc1307bd809c198db1a7dff1 (diff)
downloadsway-f63d9417cd4d25121fa1fd309acad14a7562a55c.zip
sway-f63d9417cd4d25121fa1fd309acad14a7562a55c.tar.gz
sway-f63d9417cd4d25121fa1fd309acad14a7562a55c.tar.bz2
Merge pull request #1743 from emersion/subsurface-damage-tracking
Damage tracking for view children
-rw-r--r--include/sway/desktop.h7
-rw-r--r--include/sway/output.h6
-rw-r--r--include/sway/tree/container.h8
-rw-r--r--include/sway/tree/view.h50
-rw-r--r--sway/desktop/desktop.c20
-rw-r--r--sway/desktop/output.c25
-rw-r--r--sway/desktop/wl_shell.c1
-rw-r--r--sway/desktop/xdg_shell_v6.c73
-rw-r--r--sway/desktop/xwayland.c132
-rw-r--r--sway/input/cursor.c14
-rw-r--r--sway/meson.build1
-rw-r--r--sway/tree/container.c11
-rw-r--r--sway/tree/view.c112
13 files changed, 409 insertions, 51 deletions
diff --git a/include/sway/desktop.h b/include/sway/desktop.h
new file mode 100644
index 0000000..96bdc94
--- /dev/null
+++ b/include/sway/desktop.h
@@ -0,0 +1,7 @@
+#include <wlr/types/wlr_surface.h>
+
+void desktop_damage_whole_surface(struct wlr_surface *surface, double lx,
+ double ly);
+
+void desktop_damage_from_surface(struct wlr_surface *surface, double lx,
+ double ly);
diff --git a/include/sway/output.h b/include/sway/output.h
index 98d0f83..4bffa2b 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -34,9 +34,15 @@ struct sway_output {
void output_damage_whole(struct sway_output *output);
+void output_damage_whole_surface(struct sway_output *output,
+ double ox, double oy, struct wlr_surface *surface);
+
void output_damage_whole_view(struct sway_output *output,
struct sway_view *view);
+void output_damage_whole_container(struct sway_output *output,
+ struct sway_container *con);
+
struct sway_container *output_by_name(const char *name);
#endif
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 3a3a942..7acb607 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -97,8 +97,7 @@ struct sway_container *container_create(enum sway_container_type type);
const char *container_type_to_str(enum sway_container_type type);
-struct sway_container *output_create(
- struct sway_output *sway_output);
+struct sway_container *output_create(struct sway_output *sway_output);
/**
* Create a new container container. A container container can be a a child of
@@ -116,7 +115,8 @@ struct sway_container *output_create(struct sway_output *sway_output);
* Create a new workspace container. Workspaces are children of an output
* container and are ordered alphabetically by name.
*/
-struct sway_container *workspace_create(struct sway_container *output, const char *name);
+struct sway_container *workspace_create(struct sway_container *output,
+ const char *name);
/*
* Create a new view container. A view can be a child of a workspace container
@@ -182,4 +182,6 @@ bool container_has_child(struct sway_container *con,
void container_create_notify(struct sway_container *container);
+void container_damage_whole(struct sway_container *container);
+
#endif
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index d4dace4..03d27ce 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -45,6 +45,12 @@ struct sway_view {
struct wlr_xwayland_surface *wlr_xwayland_surface;
struct wlr_wl_shell_surface *wlr_wl_shell_surface;
};
+
+ struct {
+ struct wl_signal unmap;
+ } events;
+
+ struct wl_listener surface_new_subsurface;
};
struct sway_xdg_shell_v6_view {
@@ -54,6 +60,7 @@ struct sway_xdg_shell_v6_view {
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
+ struct wl_listener new_popup;
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy;
@@ -80,6 +87,12 @@ struct sway_xwayland_unmanaged {
struct wlr_xwayland_surface *wlr_xwayland_surface;
struct wl_list link;
+ int lx, ly;
+
+ struct wl_listener request_configure;
+ struct wl_listener commit;
+ struct wl_listener map;
+ struct wl_listener unmap;
struct wl_listener destroy;
};
@@ -95,6 +108,37 @@ struct sway_wl_shell_view {
int pending_width, pending_height;
};
+struct sway_view_child;
+
+struct sway_view_child_impl {
+ void (*destroy)(struct sway_view_child *child);
+};
+
+/**
+ * A view child is a surface in the view tree, such as a subsurface or a popup.
+ */
+struct sway_view_child {
+ const struct sway_view_child_impl *impl;
+
+ struct sway_view *view;
+ struct wlr_surface *surface;
+
+ struct wl_listener surface_commit;
+ struct wl_listener surface_new_subsurface;
+ struct wl_listener surface_destroy;
+ struct wl_listener view_unmap;
+};
+
+struct sway_xdg_popup_v6 {
+ struct sway_view_child child;
+
+ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
+
+ struct wl_listener new_popup;
+ struct wl_listener unmap;
+ struct wl_listener destroy;
+};
+
const char *view_get_title(struct sway_view *view);
const char *view_get_app_id(struct sway_view *view);
@@ -129,4 +173,10 @@ void view_update_position(struct sway_view *view, double ox, double oy);
void view_update_size(struct sway_view *view, int width, int height);
+void view_child_init(struct sway_view_child *child,
+ const struct sway_view_child_impl *impl, struct sway_view *view,
+ struct wlr_surface *surface);
+
+void view_child_destroy(struct sway_view_child *child);
+
#endif
diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c
new file mode 100644
index 0000000..3a13191
--- /dev/null
+++ b/sway/desktop/desktop.c
@@ -0,0 +1,20 @@
+#include "sway/tree/container.h"
+#include "sway/desktop.h"
+#include "sway/output.h"
+
+void desktop_damage_whole_surface(struct wlr_surface *surface, double lx,
+ double ly) {
+ for (int i = 0; i < root_container.children->length; ++i) {
+ struct sway_container *cont = root_container.children->items[i];
+ if (cont->type == C_OUTPUT) {
+ output_damage_whole_surface(cont->sway_output,
+ lx - cont->x, ly - cont->y, surface);
+ }
+ }
+}
+
+void desktop_damage_from_surface(struct wlr_surface *surface, double lx,
+ double ly) {
+ // TODO
+ desktop_damage_whole_surface(surface, lx, ly);
+}
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 0e8a948..aa18f1b 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -267,17 +267,14 @@ static void render_output(struct sway_output *output, struct timespec *when,
// render unmanaged views on top
struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged;
- struct sway_xwayland_unmanaged *sway_surface;
- wl_list_for_each(sway_surface, unmanaged, link) {
+ struct sway_xwayland_unmanaged *unmanaged_surface;
+ wl_list_for_each(unmanaged_surface, unmanaged, link) {
struct wlr_xwayland_surface *xsurface =
- sway_surface->wlr_xwayland_surface;
- if (xsurface->surface == NULL) {
- continue;
- }
+ unmanaged_surface->wlr_xwayland_surface;
const struct wlr_box view_box = {
- .x = xsurface->x,
- .y = xsurface->y,
+ .x = unmanaged_surface->lx,
+ .y = unmanaged_surface->ly,
.width = xsurface->width,
.height = xsurface->height,
};
@@ -335,12 +332,24 @@ void output_damage_whole(struct sway_output *output) {
wlr_output_damage_add_whole(output->damage);
}
+void output_damage_whole_surface(struct sway_output *output,
+ double ox, double oy, struct wlr_surface *surface) {
+ // TODO
+ output_damage_whole(output);
+}
+
void output_damage_whole_view(struct sway_output *output,
struct sway_view *view) {
// TODO
output_damage_whole(output);
}
+void output_damage_whole_container(struct sway_output *output,
+ struct sway_container *con) {
+ // TODO
+ output_damage_whole(output);
+}
+
static void damage_handle_destroy(struct wl_listener *listener, void *data) {
struct sway_output *output =
wl_container_of(listener, output, damage_destroy);
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c
index 5955fa9..fff31da 100644
--- a/sway/desktop/wl_shell.c
+++ b/sway/desktop/wl_shell.c
@@ -68,6 +68,7 @@ static const struct sway_view_impl view_impl = {
.get_prop = get_prop,
.configure = configure,
.close = _close,
+ .destroy = destroy,
};
static void handle_commit(struct wl_listener *listener, void *data) {
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 7b9d5fb..c66cc39 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -11,6 +11,66 @@
#include "sway/input/input-manager.h"
#include "log.h"
+static const struct sway_view_child_impl popup_impl;
+
+static void popup_destroy(struct sway_view_child *child) {
+ if (!sway_assert(child->impl == &popup_impl,
+ "Expected an xdg_shell_v6 popup")) {
+ return;
+ }
+ struct sway_xdg_popup_v6 *popup = (struct sway_xdg_popup_v6 *)child;
+ wl_list_remove(&popup->new_popup.link);
+ wl_list_remove(&popup->unmap.link);
+ wl_list_remove(&popup->destroy.link);
+ free(popup);
+}
+
+static const struct sway_view_child_impl popup_impl = {
+ .destroy = popup_destroy,
+};
+
+static struct sway_xdg_popup_v6 *popup_create(
+ struct wlr_xdg_popup_v6 *wlr_popup, struct sway_view *view);
+
+static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
+ struct sway_xdg_popup_v6 *popup =
+ wl_container_of(listener, popup, new_popup);
+ struct wlr_xdg_popup_v6 *wlr_popup = data;
+ popup_create(wlr_popup, popup->child.view);
+}
+
+static void popup_handle_unmap(struct wl_listener *listener, void *data) {
+ struct sway_xdg_popup_v6 *popup = wl_container_of(listener, popup, unmap);
+ view_child_destroy(&popup->child);
+}
+
+static void popup_handle_destroy(struct wl_listener *listener, void *data) {
+ struct sway_xdg_popup_v6 *popup = wl_container_of(listener, popup, destroy);
+ view_child_destroy(&popup->child);
+}
+
+static struct sway_xdg_popup_v6 *popup_create(
+ struct wlr_xdg_popup_v6 *wlr_popup, struct sway_view *view) {
+ struct wlr_xdg_surface_v6 *xdg_surface = wlr_popup->base;
+
+ struct sway_xdg_popup_v6 *popup =
+ calloc(1, sizeof(struct sway_xdg_popup_v6));
+ if (popup == NULL) {
+ return NULL;
+ }
+ view_child_init(&popup->child, &popup_impl, view, xdg_surface->surface);
+
+ wl_signal_add(&xdg_surface->events.new_popup, &popup->new_popup);
+ popup->new_popup.notify = popup_handle_new_popup;
+ wl_signal_add(&xdg_surface->events.unmap, &popup->unmap);
+ popup->unmap.notify = popup_handle_unmap;
+ wl_signal_add(&xdg_surface->events.destroy, &popup->destroy);
+ popup->destroy.notify = popup_handle_destroy;
+
+ return popup;
+}
+
+
static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view(
struct sway_view *view) {
if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL_V6,
@@ -76,6 +136,7 @@ static void destroy(struct sway_view *view) {
}
wl_list_remove(&xdg_shell_v6_view->commit.link);
wl_list_remove(&xdg_shell_v6_view->destroy.link);
+ wl_list_remove(&xdg_shell_v6_view->new_popup.link);
wl_list_remove(&xdg_shell_v6_view->map.link);
wl_list_remove(&xdg_shell_v6_view->unmap.link);
free(xdg_shell_v6_view);
@@ -86,6 +147,7 @@ static const struct sway_view_impl view_impl = {
.configure = configure,
.set_activated = set_activated,
.close = _close,
+ .destroy = destroy,
};
static void handle_commit(struct wl_listener *listener, void *data) {
@@ -100,6 +162,13 @@ static void handle_commit(struct wl_listener *listener, void *data) {
view_damage_from(view);
}
+static void handle_new_popup(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
+ wl_container_of(listener, xdg_shell_v6_view, new_popup);
+ struct wlr_xdg_popup_v6 *wlr_popup = data;
+ popup_create(wlr_popup, &xdg_shell_v6_view->view);
+}
+
static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, unmap);
@@ -151,6 +220,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&xdg_surface->surface->events.commit,
&xdg_shell_v6_view->commit);
+ xdg_shell_v6_view->new_popup.notify = handle_new_popup;
+ wl_signal_add(&xdg_surface->events.new_popup,
+ &xdg_shell_v6_view->new_popup);
+
xdg_shell_v6_view->map.notify = handle_map;
wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map);
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 384f423..e3da1da 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -2,42 +2,110 @@
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server.h>
-#include <wlr/xwayland.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
+#include <wlr/xwayland.h>
+#include "log.h"
+#include "sway/desktop.h"
+#include "sway/input/input-manager.h"
+#include "sway/input/seat.h"
+#include "sway/output.h"
+#include "sway/server.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
-#include "sway/server.h"
#include "sway/tree/view.h"
-#include "sway/output.h"
-#include "sway/input/seat.h"
-#include "sway/input/input-manager.h"
-#include "log.h"
-static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) {
- struct sway_xwayland_unmanaged *sway_surface =
- wl_container_of(listener, sway_surface, destroy);
- wl_list_remove(&sway_surface->destroy.link);
- wl_list_remove(&sway_surface->link);
- free(sway_surface);
+static void unmanaged_handle_request_configure(struct wl_listener *listener,
+ void *data) {
+ struct sway_xwayland_unmanaged *surface =
+ wl_container_of(listener, surface, request_configure);
+ struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
+ struct wlr_xwayland_surface_configure_event *ev = data;
+ wlr_xwayland_surface_configure(xsurface, ev->x, ev->y,
+ ev->width, ev->height);
}
-static void create_unmanaged(struct wlr_xwayland_surface *xsurface) {
- struct sway_xwayland_unmanaged *sway_surface =
- calloc(1, sizeof(struct sway_xwayland_unmanaged));
- if (!sway_assert(sway_surface, "Failed to allocate surface")) {
- return;
+static void unmanaged_handle_commit(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_unmanaged *surface =
+ wl_container_of(listener, surface, commit);
+ struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
+
+ if (xsurface->x != surface->lx || xsurface->y != surface->ly) {
+ // Surface has moved
+ desktop_damage_whole_surface(xsurface->surface,
+ surface->lx, surface->ly);
+ surface->lx = xsurface->x;
+ surface->ly = xsurface->y;
+ desktop_damage_whole_surface(xsurface->surface,
+ surface->lx, surface->ly);
+ } else {
+ desktop_damage_from_surface(xsurface->surface,
+ xsurface->x, xsurface->y);
}
+}
- sway_surface->wlr_xwayland_surface = xsurface;
-
- wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy);
- sway_surface->destroy.notify = unmanaged_handle_destroy;
+static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_unmanaged *surface =
+ wl_container_of(listener, surface, map);
+ struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
wl_list_insert(&root_container.sway_root->xwayland_unmanaged,
- &sway_surface->link);
+ &surface->link);
+
+ wl_signal_add(&xsurface->surface->events.commit, &surface->commit);
+ surface->commit.notify = unmanaged_handle_commit;
+
+ surface->lx = xsurface->x;
+ surface->ly = xsurface->y;
+ desktop_damage_whole_surface(xsurface->surface, surface->lx, surface->ly);
+}
+
+static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_unmanaged *surface =
+ wl_container_of(listener, surface, unmap);
+ struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
+ desktop_damage_whole_surface(xsurface->surface, xsurface->x, xsurface->y);
+ wl_list_remove(&surface->link);
+ wl_list_remove(&surface->commit.link);
+}
- // TODO: damage tracking
+static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_unmanaged *surface =
+ wl_container_of(listener, surface, destroy);
+ struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
+ if (xsurface->mapped) {
+ unmanaged_handle_unmap(&surface->unmap, xsurface);
+ }
+ wl_list_remove(&surface->map.link);
+ wl_list_remove(&surface->unmap.link);
+ wl_list_remove(&surface->destroy.link);
+ free(surface);
+}
+
+static struct sway_xwayland_unmanaged *create_unmanaged(
+ struct wlr_xwayland_surface *xsurface) {
+ struct sway_xwayland_unmanaged *surface =
+ calloc(1, sizeof(struct sway_xwayland_unmanaged));
+ if (surface == NULL) {
+ wlr_log(L_ERROR, "Allocation failed");
+ return NULL;
+ }
+
+ surface->wlr_xwayland_surface = xsurface;
+
+ wl_signal_add(&xsurface->events.request_configure,
+ &surface->request_configure);
+ surface->request_configure.notify = unmanaged_handle_request_configure;
+ wl_signal_add(&xsurface->events.map, &surface->map);
+ surface->map.notify = unmanaged_handle_map;
+ wl_signal_add(&xsurface->events.unmap, &surface->unmap);
+ surface->unmap.notify = unmanaged_handle_unmap;
+ wl_signal_add(&xsurface->events.destroy, &surface->destroy);
+ surface->destroy.notify = unmanaged_handle_destroy;
+
+ unmanaged_handle_map(&surface->map, xsurface);
+
+ return surface;
}
@@ -127,6 +195,7 @@ static const struct sway_view_impl view_impl = {
.configure = configure,
.set_activated = set_activated,
.close = _close,
+ .destroy = destroy,
};
static void handle_commit(struct wl_listener *listener, void *data) {
@@ -140,12 +209,6 @@ static void handle_commit(struct wl_listener *listener, void *data) {
view_damage_from(view);
}
-static void handle_destroy(struct wl_listener *listener, void *data) {
- struct sway_xwayland_view *xwayland_view =
- wl_container_of(listener, xwayland_view, destroy);
- view_destroy(&xwayland_view->view);
-}
-
static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, unmap);
@@ -169,6 +232,17 @@ static void handle_map(struct wl_listener *listener, void *data) {
view_map(view, xsurface->surface);
}
+static void handle_destroy(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_view *xwayland_view =
+ wl_container_of(listener, xwayland_view, destroy);
+ struct sway_view *view = &xwayland_view->view;
+ struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
+ if (xsurface->mapped) {
+ handle_unmap(&xwayland_view->unmap, xsurface);
+ }
+ view_destroy(&xwayland_view->view);
+}
+
static void handle_request_configure(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, request_configure);
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 195ddce..b83bc9f 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -48,17 +48,13 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
struct wlr_surface **surface, double *sx, double *sy) {
// check for unmanaged views first
struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged;
- struct sway_xwayland_unmanaged *sway_surface;
- wl_list_for_each_reverse(sway_surface, unmanaged, link) {
+ struct sway_xwayland_unmanaged *unmanaged_surface;
+ wl_list_for_each_reverse(unmanaged_surface, unmanaged, link) {
struct wlr_xwayland_surface *xsurface =
- sway_surface->wlr_xwayland_surface;
- if (xsurface->surface == NULL) {
- continue;
- }
-
+ unmanaged_surface->wlr_xwayland_surface;
struct wlr_box box = {
- .x = xsurface->x,
- .y = xsurface->y,
+ .x = unmanaged_surface->lx,
+ .y = unmanaged_surface->ly,
.width = xsurface->width,
.height = xsurface->height,
};
diff --git a/sway/meson.build b/sway/meson.build
index ec7b4c4..29aaa7b 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -8,6 +8,7 @@ sway_sources = files(
'ipc-server.c',
'security.c',
+ 'desktop/desktop.c',
'desktop/output.c',
'desktop/layer_shell.c',
'desktop/wl_shell.c',
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 3e8c1c7..41321dc 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -514,9 +514,16 @@ static bool find_child_func(struct sway_container *con, void *data) {
bool container_has_child(struct sway_container *con,
struct sway_container *child) {
- if (con == NULL || con->type == C_VIEW ||
- con->children->length == 0) {
+ if (con == NULL || con->type == C_VIEW || con->children->length == 0) {
return false;
}
return container_find(con, find_child_func, child);
}
+
+void container_damage_whole(struct sway_container *con) {
+ struct sway_container *output = con;
+ if (output->type != C_OUTPUT) {
+ output = container_parent(output, C_OUTPUT);
+ }
+ output_damage_whole_container(output->sway_output, con);
+}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 3927c19..d3e3186 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -11,6 +11,7 @@ void view_init(struct sway_view *view, enum sway_view_type type,
const struct sway_view_impl *impl) {
view->type = type;
view->impl = impl;
+ wl_signal_init(&view->events.unmap);
}
void view_destroy(struct sway_view *view) {
@@ -123,6 +124,20 @@ static void view_update_outputs(struct sway_view *view,
}
}
+static void view_subsurface_create(struct sway_view *view,
+ struct wlr_subsurface *subsurface);
+
+static void view_init_subsurfaces(struct sway_view *view,
+ struct wlr_surface *surface);
+
+static void view_handle_surface_new_subsurface(struct wl_listener *listener,
+ void *data) {
+ struct sway_view *view =
+ wl_container_of(listener, view, surface_new_subsurface);
+ struct wlr_subsurface *subsurface = data;
+ view_subsurface_create(view, subsurface);
+}
+
void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
if (!sway_assert(view->surface == NULL, "cannot map mapped view")) {
return;
@@ -136,6 +151,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
view->surface = wlr_surface;
view->swayc = cont;
+ view_init_subsurfaces(view, wlr_surface);
+ wl_signal_add(&wlr_surface->events.new_subsurface,
+ &view->surface_new_subsurface);
+ view->surface_new_subsurface.notify = view_handle_surface_new_subsurface;
+
arrange_windows(cont->parent, -1, -1);
input_manager_set_focus(input_manager, cont);
@@ -148,10 +168,14 @@ void view_unmap(struct sway_view *view) {
return;
}
+ wl_signal_emit(&view->events.unmap, view);
+
view_damage_whole(view);
struct sway_container *parent = container_destroy(view->swayc);
+ wl_list_remove(&view->surface_new_subsurface.link);
+
view->swayc = NULL;
view->surface = NULL;
@@ -185,3 +209,91 @@ void view_update_size(struct sway_view *view, int width, int height) {
view_update_outputs(view, &box);
view_damage_whole(view);
}
+
+
+static void view_subsurface_create(struct sway_view *view,
+ struct wlr_subsurface *subsurface) {
+ struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child));
+ if (child == NULL) {
+ wlr_log(L_ERROR, "Allocation failed");
+ return;
+ }
+ view_child_init(child, NULL, view, subsurface->surface);
+}
+
+static void view_child_handle_surface_commit(struct wl_listener *listener,
+ void *data) {
+ struct sway_view_child *child =
+ wl_container_of(listener, child, surface_commit);
+ // TODO: only accumulate damage from the child
+ view_damage_from(child->view);
+}
+
+static void view_child_handle_surface_new_subsurface(
+ struct wl_listener *listener, void *data) {
+ struct sway_view_child *child =
+ wl_container_of(listener, child, surface_new_subsurface);
+ struct wlr_subsurface *subsurface = data;
+ view_subsurface_create(child->view, subsurface);
+}
+
+static void view_child_handle_surface_destroy(struct wl_listener *listener,
+ void *data) {
+ struct sway_view_child *child =
+ wl_container_of(listener, child, surface_destroy);
+ view_child_destroy(child);
+}
+
+static void view_child_handle_view_unmap(struct wl_listener *listener,
+ void *data) {
+ struct sway_view_child *child =
+ wl_container_of(listener, child, view_unmap);
+ view_child_destroy(child);
+}
+
+static void view_init_subsurfaces(struct sway_view *view,
+ struct wlr_surface *surface) {
+ struct wlr_subsurface *subsurface;
+ wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
+ view_subsurface_create(view, subsurface);
+ }
+}
+
+void view_child_init(struct sway_view_child *child,
+ const struct sway_view_child_impl *impl, struct sway_view *view,
+ struct wlr_surface *surface) {
+ child->impl = impl;
+ child->view = view;
+ child->surface = surface;
+
+ wl_signal_add(&surface->events.commit, &child->surface_commit);
+ child->surface_commit.notify = view_child_handle_surface_commit;
+ wl_signal_add(&surface->events.new_subsurface,
+ &child->surface_new_subsurface);
+ child->surface_new_subsurface.notify =
+ view_child_handle_surface_new_subsurface;
+ wl_signal_add(&surface->events.destroy, &child->surface_destroy);
+ child->surface_destroy.notify = view_child_handle_surface_destroy;
+ wl_signal_add(&view->events.unmap, &child->view_unmap);
+ child->view_unmap.notify = view_child_handle_view_unmap;
+
+ view_init_subsurfaces(child->view, surface);
+
+ // TODO: only damage the whole child
+ view_damage_whole(child->view);
+}
+
+void view_child_destroy(struct sway_view_child *child) {
+ // TODO: only damage the whole child
+ view_damage_whole(child->view);
+
+ wl_list_remove(&child->surface_commit.link);
+ wl_list_remove(&child->surface_destroy.link);
+ wl_list_remove(&child->view_unmap.link);
+
+ if (child->impl && child->impl->destroy) {
+ child->impl->destroy(child);
+ } else {
+ free(child);
+ }
+}