From 1a084807ce6ce1d8e4b8c35e3195240507ebffe8 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 03:31:46 +0100 Subject: rootston: do not redraw if output has no damage --- rootston/xdg_shell_v6.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rootston/xdg_shell_v6.c') diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 0515263b..e915d1a6 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -217,6 +217,8 @@ static void handle_commit(struct wl_listener *listener, void *data) { roots_surface->pending_move_resize_configure_serial = 0; } } + + desktop_damage_surface(view->desktop, view->wlr_surface, view->x, view->y); } static void handle_destroy(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From 01bcc2ab01715df1f105ab972041134c878612e0 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 12:25:39 +0100 Subject: rootston: damage views when moved --- include/rootston/desktop.h | 4 ++-- include/rootston/output.h | 3 +-- rootston/desktop.c | 26 ++++++++++++++++---------- rootston/output.c | 8 +++++++- rootston/wl_shell.c | 9 ++++++--- rootston/xdg_shell_v6.c | 11 ++++++----- rootston/xwayland.c | 24 ++++++++++++++---------- 7 files changed, 52 insertions(+), 33 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 3d0e2a2b..c0790917 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -62,12 +62,12 @@ struct roots_output *desktop_output_from_wlr_output( struct roots_desktop *desktop, struct wlr_output *output); struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); -void desktop_damage_surface(struct roots_desktop *desktop, - struct wlr_surface *surface, double lx, double ly); void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_destroy(struct roots_view *view); void view_activate(struct roots_view *view, bool activate); +void view_damage(struct roots_view *view); +void view_update_position(struct roots_view *view, double x, double y); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_wl_shell_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/output.h b/include/rootston/output.h index d44479ed..e8c64c3e 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -23,7 +23,6 @@ struct roots_output { void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); -void output_damage_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly); +void output_damage_view(struct roots_output *output, struct roots_view *view); #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index 3b8e6602..94350359 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -61,8 +61,7 @@ void view_move(struct roots_view *view, double x, double y) { if (view->move) { view->move(view, x, y); } else { - view->x = x; - view->y = y; + view_update_position(view, x, y); } view_update_output(view, &before); } @@ -268,6 +267,7 @@ void view_destroy(struct roots_view *view) { void view_init(struct roots_view *view, struct roots_desktop *desktop) { view->desktop = desktop; wl_signal_init(&view->events.destroy); + view_damage(view); } void view_setup(struct roots_view *view) { @@ -282,6 +282,20 @@ void view_setup(struct roots_view *view) { view_update_output(view, NULL); } +void view_damage(struct roots_view *view) { + struct roots_output *output; + wl_list_for_each(output, &view->desktop->outputs, link) { + output_damage_view(output, view); + } +} + +void view_update_position(struct roots_view *view, double x, double y) { + view_damage(view); + view->x = x; + view->y = y; + view_damage(view); +} + static bool view_at(struct roots_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (view->type == ROOTS_WL_SHELL_VIEW && @@ -522,11 +536,3 @@ struct roots_output *desktop_output_from_wlr_output( } return NULL; } - -void desktop_damage_surface(struct roots_desktop *desktop, - struct wlr_surface *surface, double lx, double ly) { - struct roots_output *output; - wl_list_for_each(output, &desktop->outputs, link) { - output_damage_surface(output, surface, lx, ly); - } -} diff --git a/rootston/output.c b/rootston/output.c index a700ea07..5ccd9eb7 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -337,7 +337,7 @@ static int handle_repaint(void *data) { return 0; } -void output_damage_surface(struct roots_output *output, +static void output_damage_surface(struct roots_output *output, struct wlr_surface *surface, double lx, double ly) { if (!wlr_surface_has_buffer(surface)) { return; @@ -355,6 +355,12 @@ void output_damage_surface(struct roots_output *output, box.width, box.height); } +void output_damage_view(struct roots_output *output, struct roots_view *view) { + output_damage_surface(output, view->wlr_surface, view->x, view->y); + + // TODO: subsurfaces, popups, etc +} + static void set_mode(struct wlr_output *output, struct roots_output_config *oc) { int mhz = (int)(oc->mode.refresh_rate * 1000); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 65067920..e1dea82b 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -90,17 +90,20 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int width = wlr_surface->current->width; int height = wlr_surface->current->height; - if (view->pending_move_resize.update_x) { - view->x = view->pending_move_resize.x + + double x = view->pending_move_resize.x + view->pending_move_resize.width - width; + view_update_position(view, x, view->y); view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - view->y = view->pending_move_resize.y + + double y = view->pending_move_resize.y + view->pending_move_resize.height - height; + view_update_position(view, view->x, y); view->pending_move_resize.update_y = false; } + + view_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index e915d1a6..259b62a5 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -102,8 +102,7 @@ static void move_resize(struct roots_view *view, double x, double y, if (serial > 0) { roots_surface->pending_move_resize_configure_serial = serial; } else { - view->x = x; - view->y = y; + view_update_position(view, x, y); } } @@ -205,12 +204,14 @@ static void handle_commit(struct wl_listener *listener, void *data) { get_size(view, &size); if (view->pending_move_resize.update_x) { - view->x = view->pending_move_resize.x + + double x = view->pending_move_resize.x + view->pending_move_resize.width - size.width; + view_update_position(view, x, view->y); } if (view->pending_move_resize.update_y) { - view->y = view->pending_move_resize.y + + double y = view->pending_move_resize.y + view->pending_move_resize.height - size.height; + view_update_position(view, view->x, y); } if (pending_serial == surface->configure_serial) { @@ -218,7 +219,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { } } - desktop_damage_surface(view->desktop, view->wlr_surface, view->x, view->y); + view_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 3d84dc19..b3cf409c 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -18,8 +18,7 @@ static void activate(struct roots_view *view, bool active) { static void move(struct roots_view *view, double x, double y) { assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - view->x = x; - view->y = y; + view_update_position(view, x, y); wlr_xwayland_surface_configure(xwayland_surface, x, y, xwayland_surface->width, xwayland_surface->height); } @@ -133,8 +132,7 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { roots_surface->view->xwayland_surface; struct wlr_xwayland_surface_configure_event *event = data; - roots_surface->view->x = (double)event->x; - roots_surface->view->y = (double)event->y; + view_update_position(roots_surface->view, event->x, event->y); wlr_xwayland_surface_configure(xwayland_surface, event->x, event->y, event->width, event->height); @@ -210,15 +208,19 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int height = wlr_surface->current->height; if (view->pending_move_resize.update_x) { - view->x = view->pending_move_resize.x + + double x = view->pending_move_resize.x + view->pending_move_resize.width - width; + view_update_position(view, x, view->y); view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - view->y = view->pending_move_resize.y + + double y = view->pending_move_resize.y + view->pending_move_resize.height - height; + view_update_position(view, view->x, y); view->pending_move_resize.update_y = false; } + + view_damage(view); } static void handle_map_notify(struct wl_listener *listener, void *data) { @@ -229,8 +231,9 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = view->desktop; view->wlr_surface = xsurface->surface; - view->x = (double)xsurface->x; - view->y = (double)xsurface->y; + view->x = xsurface->x; + view->y = xsurface->y; + view_damage(view); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, @@ -242,10 +245,11 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { static void handle_unmap_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, unmap_notify); - roots_surface->view->wlr_surface = NULL; - wl_list_remove(&roots_surface->surface_commit.link); + view_damage(roots_surface->view); + roots_surface->view->wlr_surface = NULL; + wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->view->link); } -- cgit v1.2.3 From 96d6f34eddbd0159e347d41e5c20c74a0600e878 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 16:30:56 +0100 Subject: rootston: replace view_damage with view_apply_damage and view_damage_whole --- include/rootston/desktop.h | 3 ++- include/rootston/output.h | 5 ++++- rootston/desktop.c | 19 +++++++++++++------ rootston/output.c | 15 +++++++++++---- rootston/wl_shell.c | 2 +- rootston/xdg_shell_v6.c | 2 +- rootston/xwayland.c | 6 +++--- 7 files changed, 35 insertions(+), 17 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index c0790917..812bb42a 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -66,7 +66,8 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_destroy(struct roots_view *view); void view_activate(struct roots_view *view, bool activate); -void view_damage(struct roots_view *view); +void view_apply_damage(struct roots_view *view); +void view_damage_whole(struct roots_view *view); void view_update_position(struct roots_view *view, double x, double y); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/output.h b/include/rootston/output.h index e8c64c3e..cf34496b 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -23,6 +23,9 @@ struct roots_output { void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); -void output_damage_view(struct roots_output *output, struct roots_view *view); +void output_damage_whole_view(struct roots_output *output, + struct roots_view *view); +void output_damage_from_view(struct roots_output *output, + struct roots_view *view); #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index b8c876cb..faaefd05 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -255,7 +255,7 @@ bool view_center(struct roots_view *view) { } void view_destroy(struct roots_view *view) { - view_damage(view); + view_damage_whole(view); wl_signal_emit(&view->events.destroy, view); if (view->fullscreen_output) { @@ -268,7 +268,7 @@ void view_destroy(struct roots_view *view) { void view_init(struct roots_view *view, struct roots_desktop *desktop) { view->desktop = desktop; wl_signal_init(&view->events.destroy); - view_damage(view); + view_damage_whole(view); } void view_setup(struct roots_view *view) { @@ -283,18 +283,25 @@ void view_setup(struct roots_view *view) { view_update_output(view, NULL); } -void view_damage(struct roots_view *view) { +void view_apply_damage(struct roots_view *view) { struct roots_output *output; wl_list_for_each(output, &view->desktop->outputs, link) { - output_damage_view(output, view); + output_damage_from_view(output, view); + } +} + +void view_damage_whole(struct roots_view *view) { + struct roots_output *output; + wl_list_for_each(output, &view->desktop->outputs, link) { + output_damage_whole_view(output, view); } } void view_update_position(struct roots_view *view, double x, double y) { - view_damage(view); + view_damage_whole(view); view->x = x; view->y = y; - view_damage(view); + view_damage_whole(view); } static bool view_at(struct roots_view *view, double lx, double ly, diff --git a/rootston/output.c b/rootston/output.c index 16a185af..846bb4e6 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -379,7 +379,7 @@ static int handle_repaint(void *data) { return 0; } -static void output_damage_surface(struct roots_output *output, +static void output_damage_whole_surface(struct roots_output *output, struct wlr_surface *surface, double lx, double ly) { if (!wlr_surface_has_buffer(surface)) { return; @@ -392,17 +392,24 @@ static void output_damage_surface(struct roots_output *output, return; } - // TODO: use surface damage + pixman_region32_union_rect(&output->damage, &output->damage, box.x, box.y, box.width, box.height); } -void output_damage_view(struct roots_output *output, struct roots_view *view) { - output_damage_surface(output, view->wlr_surface, view->x, view->y); +void output_damage_whole_view(struct roots_output *output, + struct roots_view *view) { + output_damage_whole_surface(output, view->wlr_surface, view->x, view->y); // TODO: subsurfaces, popups, etc } +void output_damage_from_view(struct roots_output *output, + struct roots_view *view) { + // TODO: use surface damage + output_damage_whole_view(output, view); +} + static void set_mode(struct wlr_output *output, struct roots_output_config *oc) { int mhz = (int)(oc->mode.refresh_rate * 1000); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index e1dea82b..25ef9a3c 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -103,7 +103,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { view->pending_move_resize.update_y = false; } - view_damage(view); + view_apply_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 259b62a5..225886ad 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -219,7 +219,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { } } - view_damage(view); + view_apply_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index b3cf409c..856c3d70 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -220,7 +220,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { view->pending_move_resize.update_y = false; } - view_damage(view); + view_apply_damage(view); } static void handle_map_notify(struct wl_listener *listener, void *data) { @@ -233,7 +233,7 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->wlr_surface = xsurface->surface; view->x = xsurface->x; view->y = xsurface->y; - view_damage(view); + view_damage_whole(view); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, @@ -246,7 +246,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, unmap_notify); - view_damage(roots_surface->view); + view_damage_whole(roots_surface->view); roots_surface->view->wlr_surface = NULL; wl_list_remove(&roots_surface->surface_commit.link); -- cgit v1.2.3 From bc001e90e988c965776abbd078224c14ac296047 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 20 Jan 2018 01:04:35 +0100 Subject: rootston: fix artifacts when un-maximizing a view --- rootston/desktop.c | 4 ++++ rootston/wl_shell.c | 17 +++++++++-------- rootston/xdg_shell_v6.c | 17 +++++++++-------- rootston/xwayland.c | 18 +++++++++--------- 4 files changed, 31 insertions(+), 25 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index faaefd05..e36ae6a4 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -298,6 +298,10 @@ void view_damage_whole(struct roots_view *view) { } void view_update_position(struct roots_view *view, double x, double y) { + if (view->x == x && view->y == y) { + return; + } + view_damage_whole(view); view->x = x; view->y = y; diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 25ef9a3c..f7b09db0 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -88,22 +88,23 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_surface *wlr_surface = view->wlr_surface; + view_apply_damage(view); + int width = wlr_surface->current->width; int height = wlr_surface->current->height; + double x = view->x; + double y = view->y; if (view->pending_move_resize.update_x) { - double x = view->pending_move_resize.x + - view->pending_move_resize.width - width; - view_update_position(view, x, view->y); + x = view->pending_move_resize.x + view->pending_move_resize.width - + width; view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - double y = view->pending_move_resize.y + - view->pending_move_resize.height - height; - view_update_position(view, view->x, y); + y = view->pending_move_resize.y + view->pending_move_resize.height - + height; view->pending_move_resize.update_y = false; } - - view_apply_damage(view); + view_update_position(view, x, y); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 225886ad..295be6a2 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -197,29 +197,30 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + view_apply_damage(view); + uint32_t pending_serial = roots_surface->pending_move_resize_configure_serial; if (pending_serial > 0 && pending_serial >= surface->configure_serial) { struct wlr_box size; get_size(view, &size); + double x = view->x; + double y = view->y; if (view->pending_move_resize.update_x) { - double x = view->pending_move_resize.x + - view->pending_move_resize.width - size.width; - view_update_position(view, x, view->y); + x = view->pending_move_resize.x + view->pending_move_resize.width - + size.width; } if (view->pending_move_resize.update_y) { - double y = view->pending_move_resize.y + - view->pending_move_resize.height - size.height; - view_update_position(view, view->x, y); + y = view->pending_move_resize.y + view->pending_move_resize.height - + size.height; } + view_update_position(view, x, y); if (pending_serial == surface->configure_serial) { roots_surface->pending_move_resize_configure_serial = 0; } } - - view_apply_damage(view); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 856c3d70..81f91b4f 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -204,23 +204,23 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_surface *wlr_surface = view->wlr_surface; + view_apply_damage(view); + int width = wlr_surface->current->width; int height = wlr_surface->current->height; - + double x = view->x; + double y = view->y; if (view->pending_move_resize.update_x) { - double x = view->pending_move_resize.x + - view->pending_move_resize.width - width; - view_update_position(view, x, view->y); + x = view->pending_move_resize.x + view->pending_move_resize.width - + width; view->pending_move_resize.update_x = false; } if (view->pending_move_resize.update_y) { - double y = view->pending_move_resize.y + - view->pending_move_resize.height - height; - view_update_position(view, view->x, y); + y = view->pending_move_resize.y + view->pending_move_resize.height - + height; view->pending_move_resize.update_y = false; } - - view_apply_damage(view); + view_update_position(view, x, y); } static void handle_map_notify(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From a636d72fc77ebcaa986fd1b72e85664e2fe586a3 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 21 Jan 2018 14:50:37 +0100 Subject: rootston: track subsurface damage --- include/rootston/desktop.h | 2 +- include/rootston/view.h | 27 ++++++++++++++ rootston/desktop.c | 90 ++++++++++++++++++++++++++++++++++++++++++++-- rootston/output.c | 38 ++++++++++++++++---- rootston/wl_shell.c | 3 +- rootston/xdg_shell_v6.c | 3 +- rootston/xwayland.c | 17 +++++---- 7 files changed, 162 insertions(+), 18 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 812bb42a..388fb55d 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -64,7 +64,7 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); void view_init(struct roots_view *view, struct roots_desktop *desktop); -void view_destroy(struct roots_view *view); +void view_finish(struct roots_view *view); void view_activate(struct roots_view *view, bool activate); void view_apply_damage(struct roots_view *view); void view_damage_whole(struct roots_view *view); diff --git a/include/rootston/view.h b/include/rootston/view.h index 579b148a..6c5e0573 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -91,7 +91,11 @@ struct roots_view { struct roots_xwayland_surface *roots_xwayland_surface; #endif }; + struct wlr_surface *wlr_surface; + struct wl_list children; // roots_view_child::link + + struct wl_listener new_subsurface; struct { struct wl_signal destroy; @@ -112,6 +116,21 @@ struct roots_view { void (*close)(struct roots_view *view); }; +struct roots_view_child { + struct roots_view *view; + struct wlr_surface *wlr_surface; + struct wl_list link; + + struct wl_listener commit; + struct wl_listener new_subsurface; +}; + +struct roots_subsurface { + struct roots_view_child view_child; + struct wlr_subsurface *wlr_subsurface; + struct wl_listener destroy; +}; + void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_move(struct roots_view *view, double x, double y); @@ -126,4 +145,12 @@ bool view_center(struct roots_view *view); void view_setup(struct roots_view *view); void view_teardown(struct roots_view *view); +void view_child_init(struct roots_view_child *child, struct roots_view *view, + struct wlr_surface *wlr_surface); +void view_child_finish(struct roots_view_child *child); + +struct roots_subsurface *subsurface_create(struct roots_view *view, + struct wlr_subsurface *wlr_subsurface); +void subsurface_destroy(struct roots_subsurface *subsurface); + #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index e36ae6a4..191338a8 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -254,20 +254,106 @@ bool view_center(struct roots_view *view) { return true; } -void view_destroy(struct roots_view *view) { +void view_child_finish(struct roots_view_child *child) { + if (child == NULL) { + return; + } + view_damage_whole(child->view); + wl_list_remove(&child->link); + wl_list_remove(&child->commit.link); + wl_list_remove(&child->new_subsurface.link); +} + +static void view_child_handle_commit(struct wl_listener *listener, + void *data) { + struct roots_view_child *child = wl_container_of(listener, child, commit); + view_apply_damage(child->view); +} + +static void view_child_handle_new_subsurface(struct wl_listener *listener, + void *data) { + struct roots_view_child *child = + wl_container_of(listener, child, new_subsurface); + struct wlr_subsurface *wlr_subsurface = data; + subsurface_create(child->view, wlr_subsurface); +} + +void view_child_init(struct roots_view_child *child, struct roots_view *view, + struct wlr_surface *wlr_surface) { + child->view = view; + child->wlr_surface = wlr_surface; + child->commit.notify = view_child_handle_commit; + wl_signal_add(&wlr_surface->events.commit, &child->commit); + child->new_subsurface.notify = view_child_handle_new_subsurface; + wl_signal_add(&wlr_surface->events.new_subsurface, &child->new_subsurface); + wl_list_insert(&view->children, &child->link); +} + +static void subsurface_handle_destroy(struct wl_listener *listener, + void *data) { + struct roots_subsurface *subsurface = + wl_container_of(listener, subsurface, destroy); + subsurface_destroy(subsurface); +} + +struct roots_subsurface *subsurface_create(struct roots_view *view, + struct wlr_subsurface *wlr_subsurface) { + struct roots_subsurface *subsurface = + calloc(1, sizeof(struct roots_subsurface)); + if (subsurface == NULL) { + return NULL; + } + subsurface->wlr_subsurface = wlr_subsurface; + view_child_init(&subsurface->view_child, view, wlr_subsurface->surface); + subsurface->destroy.notify = subsurface_handle_destroy; + wl_signal_add(&wlr_subsurface->events.destroy, &subsurface->destroy); + return subsurface; +} + +void subsurface_destroy(struct roots_subsurface *subsurface) { + if (subsurface == NULL) { + return; + } + wl_list_remove(&subsurface->destroy.link); + view_child_finish(&subsurface->view_child); + free(subsurface); +} + +void view_finish(struct roots_view *view) { view_damage_whole(view); wl_signal_emit(&view->events.destroy, view); + wl_list_remove(&view->new_subsurface.link); + if (view->fullscreen_output) { view->fullscreen_output->fullscreen_view = NULL; } +} - free(view); +static void view_handle_new_subsurface(struct wl_listener *listener, + void *data) { + struct roots_view *view = wl_container_of(listener, view, new_subsurface); + struct wlr_subsurface *wlr_subsurface = data; + subsurface_create(view, wlr_subsurface); } void view_init(struct roots_view *view, struct roots_desktop *desktop) { + assert(view->wlr_surface); + view->desktop = desktop; wl_signal_init(&view->events.destroy); + wl_list_init(&view->children); + + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &view->wlr_surface->subsurface_list, + parent_link) { + subsurface_create(view, subsurface); + } + + view->new_subsurface.notify = view_handle_new_subsurface; + wl_signal_add(&view->wlr_surface->events.new_subsurface, + &view->new_subsurface); + view_damage_whole(view); } diff --git a/rootston/output.c b/rootston/output.c index f8da9c77..1c966e08 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -444,7 +444,7 @@ static void output_damage_whole(struct roots_output *output) { } static void output_damage_whole_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly) { + struct wlr_surface *surface, double lx, double ly, float rotation) { if (!wlr_surface_has_buffer(surface)) { return; } @@ -460,6 +460,18 @@ static void output_damage_whole_surface(struct roots_output *output, box.x, box.y, box.width, box.height); schedule_render(output); + + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + struct wlr_surface_state *state = subsurface->surface->current; + double sx = state->subsurface_position.x; + double sy = state->subsurface_position.y; + rotate_child_position(&sx, &sy, state->width, state->height, + surface->current->width, surface->current->height, rotation); + + output_damage_whole_surface(output, subsurface->surface, + lx + sx, ly + sy, rotation); + } } void output_damage_whole_view(struct roots_output *output, @@ -469,14 +481,15 @@ void output_damage_whole_view(struct roots_output *output, } if (view->wlr_surface != NULL) { - output_damage_whole_surface(output, view->wlr_surface, view->x, view->y); + output_damage_whole_surface(output, view->wlr_surface, + view->x, view->y, view->rotation); } - // TODO: subsurfaces, popups, etc + // TODO: popups, etc } static void output_damage_from_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly) { + struct wlr_surface *surface, double lx, double ly, float rotation) { if (!wlr_surface_has_buffer(surface)) { return; } @@ -497,6 +510,18 @@ static void output_damage_from_surface(struct roots_output *output, pixman_region32_fini(&damage); schedule_render(output); + + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + struct wlr_surface_state *state = subsurface->surface->current; + double sx = state->subsurface_position.x; + double sy = state->subsurface_position.y; + rotate_child_position(&sx, &sy, state->width, state->height, + surface->current->width, surface->current->height, rotation); + + output_damage_from_surface(output, subsurface->surface, + lx + sx, ly + sy, rotation); + } } void output_damage_from_view(struct roots_output *output, @@ -506,10 +531,11 @@ void output_damage_from_view(struct roots_output *output, } if (view->wlr_surface != NULL) { - output_damage_from_surface(output, view->wlr_surface, view->x, view->y); + output_damage_from_surface(output, view->wlr_surface, + view->x, view->y, view->rotation); } - // TODO: subsurfaces, popups, etc + // TODO: popups, etc } static void output_handle_mode(struct wl_listener *listener, void *data) { diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index f7b09db0..be658f40 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -118,7 +118,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_surface->set_state.link); wl_list_remove(&roots_surface->surface_commit.link); wl_list_remove(&roots_surface->view->link); - view_destroy(roots_surface->view); + view_finish(roots_surface->view); + free(roots_surface->view); free(roots_surface); } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 295be6a2..7337fb1e 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -231,7 +231,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&roots_xdg_surface->request_move.link); wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->view->link); - view_destroy(roots_xdg_surface->view); + view_finish(roots_xdg_surface->view); + free(roots_xdg_surface->view); free(roots_xdg_surface); } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 81f91b4f..6f9912e6 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -121,7 +121,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { if (xwayland_surface->mapped) { wl_list_remove(&roots_surface->view->link); } - view_destroy(roots_surface->view); + view_finish(roots_surface->view); + free(roots_surface->view); free(roots_surface); } @@ -233,24 +234,26 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->wlr_surface = xsurface->surface; view->x = xsurface->x; view->y = xsurface->y; + wl_list_insert(&desktop->views, &view->link); + view_damage_whole(view); roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&xsurface->surface->events.commit, &roots_surface->surface_commit); - - wl_list_insert(&desktop->views, &view->link); } static void handle_unmap_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, unmap_notify); + struct roots_view *view = roots_surface->view; - view_damage_whole(roots_surface->view); - - roots_surface->view->wlr_surface = NULL; wl_list_remove(&roots_surface->surface_commit.link); - wl_list_remove(&roots_surface->view->link); + + view_damage_whole(view); + + view->wlr_surface = NULL; + wl_list_remove(&view->link); } void handle_xwayland_surface(struct wl_listener *listener, void *data) { -- cgit v1.2.3 From 66ae4071a7985fbc6e5d41f50e34ce4474ab4fe4 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 21 Jan 2018 21:06:37 +0100 Subject: rootston: damage tracking for xdg popups --- include/rootston/view.h | 11 +- include/wlr/types/wlr_xdg_shell_v6.h | 5 +- rootston/output.c | 297 +++++++++++++++++------------------ rootston/xdg_shell_v6.c | 69 +++++++- types/wlr_xdg_shell_v6.c | 22 +-- 5 files changed, 235 insertions(+), 169 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/view.h b/include/rootston/view.h index d07f9ca2..8cfdf321 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -23,13 +23,15 @@ struct roots_wl_shell_surface { struct roots_xdg_surface_v6 { struct roots_view *view; - struct wl_listener commit; struct wl_listener destroy; + struct wl_listener new_popup; struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_maximize; struct wl_listener request_fullscreen; + struct wl_listener surface_commit; + uint32_t pending_move_resize_configure_serial; }; @@ -133,6 +135,13 @@ struct roots_subsurface { struct wl_listener destroy; }; +struct roots_xdg_popup_v6 { + struct roots_view_child view_child; + struct wlr_xdg_popup_v6 *wlr_popup; + struct wl_listener destroy; + struct wl_listener new_popup; +}; + void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_move(struct roots_view *view, double x, double y); diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 280bea27..c7b1a24b 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -34,6 +34,7 @@ struct wlr_xdg_client_v6 { struct wlr_xdg_popup_v6 { struct wlr_xdg_surface_v6 *base; + struct wl_list link; struct wl_resource *resource; bool committed; @@ -104,8 +105,7 @@ struct wlr_xdg_surface_v6 { struct wlr_xdg_popup_v6 *popup_state; }; - struct wl_list popups; - struct wl_list popup_link; + struct wl_list popups; // wlr_xdg_popup_v6::link bool configured; bool added; @@ -126,6 +126,7 @@ struct wlr_xdg_surface_v6 { struct { struct wl_signal destroy; struct wl_signal ping_timeout; + struct wl_signal new_popup; struct wl_signal request_maximize; struct wl_signal request_fullscreen; diff --git a/rootston/output.c b/rootston/output.c index 1c966e08..d2ea2ade 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -13,6 +13,9 @@ #include "rootston/output.h" #include "rootston/config.h" +typedef void (*surface_iterator_func_t)(struct wlr_surface *surface, + double lx, double ly, float rotation, void *data); + /** * Rotate a child's position relative to a parent. The parent size is (pw, ph), * the child position is (*sx, *sy) and its size is (sw, sh). @@ -31,6 +34,119 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh, } } +static void surface_for_each_surface(struct wlr_surface *surface, double lx, + double ly, float rotation, surface_iterator_func_t iterator, + void *user_data) { + iterator(surface, lx, ly, rotation, user_data); + + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + struct wlr_surface_state *state = subsurface->surface->current; + double sx = state->subsurface_position.x; + double sy = state->subsurface_position.y; + rotate_child_position(&sx, &sy, state->width, state->height, + surface->current->width, surface->current->height, rotation); + + surface_for_each_surface(subsurface->surface, lx + sx, ly + sy, + rotation, iterator, user_data); + } +} + +static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface, + double base_x, double base_y, float rotation, + surface_iterator_func_t iterator, void *user_data) { + double width = surface->surface->current->width; + double height = surface->surface->current->height; + + struct wlr_xdg_popup_v6 *popup_state; + wl_list_for_each(popup_state, &surface->popups, link) { + struct wlr_xdg_surface_v6 *popup = popup_state->base; + if (!popup->configured) { + continue; + } + + double popup_width = popup->surface->current->width; + double popup_height = popup->surface->current->height; + + double popup_sx, popup_sy; + wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy); + rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height, + width, height, rotation); + + surface_for_each_surface(popup->surface, base_x + popup_sx, + base_y + popup_sy, rotation, iterator, user_data); + xdg_surface_v6_for_each_surface(popup, base_x + popup_sx, + base_y + popup_sy, rotation, iterator, user_data); + } +} + +static void wl_shell_surface_for_each_surface( + struct wlr_wl_shell_surface *surface, double lx, double ly, + float rotation, bool is_child, surface_iterator_func_t iterator, + void *user_data) { + if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) { + surface_for_each_surface(surface->surface, lx, ly, rotation, iterator, + user_data); + + double width = surface->surface->current->width; + double height = surface->surface->current->height; + + struct wlr_wl_shell_surface *popup; + wl_list_for_each(popup, &surface->popups, popup_link) { + double popup_width = popup->surface->current->width; + double popup_height = popup->surface->current->height; + + double popup_x = popup->transient_state->x; + double popup_y = popup->transient_state->y; + rotate_child_position(&popup_x, &popup_y, popup_width, popup_height, + width, height, rotation); + + wl_shell_surface_for_each_surface(popup, lx + popup_x, ly + popup_y, + rotation, true, iterator, user_data); + } + } +} + +static void view_for_each_surface(struct roots_view *view, + surface_iterator_func_t iterator, void *user_data) { + switch (view->type) { + case ROOTS_XDG_SHELL_V6_VIEW: + surface_for_each_surface(view->wlr_surface, view->x, view->y, + view->rotation, iterator, user_data); + xdg_surface_v6_for_each_surface(view->xdg_surface_v6, view->x, view->y, + view->rotation, iterator, user_data); + break; + case ROOTS_WL_SHELL_VIEW: + wl_shell_surface_for_each_surface(view->wl_shell_surface, view->x, + view->y, view->rotation, false, iterator, user_data); + break; + case ROOTS_XWAYLAND_VIEW: + surface_for_each_surface(view->wlr_surface, view->x, view->y, + view->rotation, iterator, user_data); + break; + } +} + +static void xwayland_children_for_each_surface( + struct wlr_xwayland_surface *surface, + surface_iterator_func_t iterator, void *user_data) { + struct wlr_xwayland_surface *child; + wl_list_for_each(child, &surface->children, parent_link) { + if (child->surface != NULL && child->added) { + surface_for_each_surface(child->surface, child->x, child->y, 0, + iterator, user_data); + } + xwayland_children_for_each_surface(child, iterator, user_data); + } +} + + +struct render_data { + struct roots_output *output; + struct timespec *when; + pixman_region32_t *damage; +}; + /** * Checks whether a surface at (lx, ly) intersects an output. Sets `box` to the * surface box in the output, in output-local coordinates. @@ -52,9 +168,13 @@ static bool surface_intersect_output(struct wlr_surface *surface, return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box); } -static void render_surface(struct wlr_surface *surface, - struct roots_output *output, struct timespec *when, - pixman_region32_t *damage, double lx, double ly, float rotation) { +static void render_surface(struct wlr_surface *surface, double lx, double ly, + float rotation, void *_data) { + struct render_data *data = _data; + struct roots_output *output = data->output; + struct timespec *when = data->when; + pixman_region32_t *damage = data->damage; + if (!wlr_surface_has_buffer(surface)) { return; } @@ -63,7 +183,7 @@ static void render_surface(struct wlr_surface *surface, bool intersects = surface_intersect_output(surface, output->desktop->layout, output->wlr_output, lx, ly, &box); if (!intersects) { - goto render_subsurfaces; + return; } // TODO: output scale, output transform support @@ -135,107 +255,6 @@ static void render_surface(struct wlr_surface *surface, surface_damage_finish: pixman_region32_fini(&surface_damage); - -render_subsurfaces:; - struct wlr_subsurface *subsurface; - wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { - struct wlr_surface_state *state = subsurface->surface->current; - double sx = state->subsurface_position.x; - double sy = state->subsurface_position.y; - rotate_child_position(&sx, &sy, state->width, state->height, - surface->current->width, surface->current->height, rotation); - - render_surface(subsurface->surface, output, when, damage, - lx + sx, ly + sy, rotation); - } -} - -static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, - struct roots_output *output, struct timespec *when, - pixman_region32_t *damage, double base_x, double base_y, - float rotation) { - double width = surface->surface->current->width; - double height = surface->surface->current->height; - - struct wlr_xdg_surface_v6 *popup; - wl_list_for_each(popup, &surface->popups, popup_link) { - if (!popup->configured) { - continue; - } - - double popup_width = popup->surface->current->width; - double popup_height = popup->surface->current->height; - - double popup_sx, popup_sy; - wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy); - rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height, - width, height, rotation); - - render_surface(popup->surface, output, when, damage, - base_x + popup_sx, base_y + popup_sy, rotation); - render_xdg_v6_popups(popup, output, when, damage, - base_x + popup_sx, base_y + popup_sy, rotation); - } -} - -static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, - struct roots_output *output, struct timespec *when, - pixman_region32_t *damage, double lx, double ly, float rotation, - bool is_child) { - if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) { - render_surface(surface->surface, output, when, damage, lx, ly, - rotation); - - double width = surface->surface->current->width; - double height = surface->surface->current->height; - - struct wlr_wl_shell_surface *popup; - wl_list_for_each(popup, &surface->popups, popup_link) { - double popup_width = popup->surface->current->width; - double popup_height = popup->surface->current->height; - - double popup_x = popup->transient_state->x; - double popup_y = popup->transient_state->y; - rotate_child_position(&popup_x, &popup_y, popup_width, popup_height, - width, height, rotation); - - render_wl_shell_surface(popup, output, when, damage, - lx + popup_x, ly + popup_y, rotation, true); - } - } -} - -static void render_xwayland_children(struct wlr_xwayland_surface *surface, - struct roots_output *output, struct timespec *when, - pixman_region32_t *damage) { - struct wlr_xwayland_surface *child; - wl_list_for_each(child, &surface->children, parent_link) { - if (child->surface != NULL && child->added) { - render_surface(child->surface, output, when, damage, - child->x, child->y, 0); - } - render_xwayland_children(child, output, when, damage); - } -} - -static void render_view(struct roots_view *view, struct roots_output *output, - struct timespec *when, pixman_region32_t *damage) { - switch (view->type) { - case ROOTS_XDG_SHELL_V6_VIEW: - render_surface(view->wlr_surface, output, when, damage, - view->x, view->y, view->rotation); - render_xdg_v6_popups(view->xdg_surface_v6, output, when, damage, - view->x, view->y, view->rotation); - break; - case ROOTS_WL_SHELL_VIEW: - render_wl_shell_surface(view->wl_shell_surface, output, when, damage, - view->x, view->y, view->rotation, false); - break; - case ROOTS_XWAYLAND_VIEW: - render_surface(view->wlr_surface, output, when, damage, - view->x, view->y, view->rotation); - break; - } } static bool has_standalone_surface(struct roots_view *view) { @@ -325,7 +344,11 @@ static void render_output(struct roots_output *output) { goto damage_finish; } - wlr_log(L_DEBUG, "render"); + struct render_data data = { + .output = output, + .when = &now, + .damage = &damage, + }; wlr_renderer_begin(server->renderer, wlr_output); glEnable(GL_SCISSOR_TEST); @@ -353,14 +376,14 @@ static void render_output(struct roots_output *output) { goto renderer_end; } - render_view(view, output, &now, &damage); + view_for_each_surface(view, render_surface, &data); // During normal rendering the xwayland window tree isn't traversed // because all windows are rendered. Here we only want to render // the fullscreen window's children so we have to traverse the tree. if (view->type == ROOTS_XWAYLAND_VIEW) { - render_xwayland_children(view->xwayland_surface, output, &now, - &damage); + xwayland_children_for_each_surface(view->xwayland_surface, + render_surface, &data); } goto renderer_end; @@ -369,7 +392,7 @@ static void render_output(struct roots_output *output) { // Render all views struct roots_view *view; wl_list_for_each_reverse(view, &desktop->views, link) { - render_view(view, output, &now, &damage); + view_for_each_surface(view, render_surface, &data); } // Render drag icons @@ -386,14 +409,14 @@ static void render_output(struct roots_output *output) { if (drag_icon->is_pointer) { icon_x = cursor->x + drag_icon->sx; icon_y = cursor->y + drag_icon->sy; - render_surface(icon, output, &now, &damage, icon_x, icon_y, 0); + render_surface(icon, icon_x, icon_y, 0, &data); } else { struct wlr_touch_point *point = wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id); if (point) { icon_x = seat->touch_x + drag_icon->sx; icon_y = seat->touch_y + drag_icon->sy; - render_surface(icon, output, &now, &damage, icon_x, icon_y, 0); + render_surface(icon, icon_x, icon_y, 0, &data); } } } @@ -443,8 +466,10 @@ static void output_damage_whole(struct roots_output *output) { schedule_render(output); } -static void output_damage_whole_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly, float rotation) { +static void damage_whole_surface(struct wlr_surface *surface, + double lx, double ly, float rotation, void *data) { + struct roots_output *output = data; + if (!wlr_surface_has_buffer(surface)) { return; } @@ -460,18 +485,6 @@ static void output_damage_whole_surface(struct roots_output *output, box.x, box.y, box.width, box.height); schedule_render(output); - - struct wlr_subsurface *subsurface; - wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { - struct wlr_surface_state *state = subsurface->surface->current; - double sx = state->subsurface_position.x; - double sy = state->subsurface_position.y; - rotate_child_position(&sx, &sy, state->width, state->height, - surface->current->width, surface->current->height, rotation); - - output_damage_whole_surface(output, subsurface->surface, - lx + sx, ly + sy, rotation); - } } void output_damage_whole_view(struct roots_output *output, @@ -480,16 +493,13 @@ void output_damage_whole_view(struct roots_output *output, return; } - if (view->wlr_surface != NULL) { - output_damage_whole_surface(output, view->wlr_surface, - view->x, view->y, view->rotation); - } - - // TODO: popups, etc + view_for_each_surface(view, damage_whole_surface, output); } -static void output_damage_from_surface(struct roots_output *output, - struct wlr_surface *surface, double lx, double ly, float rotation) { +static void damage_from_surface(struct wlr_surface *surface, + double lx, double ly, float rotation, void *data) { + struct roots_output *output = data; + if (!wlr_surface_has_buffer(surface)) { return; } @@ -510,18 +520,6 @@ static void output_damage_from_surface(struct roots_output *output, pixman_region32_fini(&damage); schedule_render(output); - - struct wlr_subsurface *subsurface; - wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { - struct wlr_surface_state *state = subsurface->surface->current; - double sx = state->subsurface_position.x; - double sy = state->subsurface_position.y; - rotate_child_position(&sx, &sy, state->width, state->height, - surface->current->width, surface->current->height, rotation); - - output_damage_from_surface(output, subsurface->surface, - lx + sx, ly + sy, rotation); - } } void output_damage_from_view(struct roots_output *output, @@ -530,12 +528,7 @@ void output_damage_from_view(struct roots_output *output, return; } - if (view->wlr_surface != NULL) { - output_damage_from_surface(output, view->wlr_surface, - view->x, view->y, view->rotation); - } - - // TODO: popups, etc + view_for_each_surface(view, damage_from_surface, output); } static void output_handle_mode(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 7337fb1e..0a3ca72c 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -10,6 +10,52 @@ #include "rootston/server.h" #include "rootston/input.h" +static void popup_destroy(struct roots_view_child *child) { + assert(child->destroy == popup_destroy); + struct roots_xdg_popup_v6 *popup = (struct roots_xdg_popup_v6 *)child; + if (popup == NULL) { + return; + } + wl_list_remove(&popup->destroy.link); + wl_list_remove(&popup->new_popup.link); + view_child_finish(&popup->view_child); + free(popup); +} + +static void popup_handle_destroy(struct wl_listener *listener, void *data) { + struct roots_xdg_popup_v6 *popup = + wl_container_of(listener, popup, destroy); + popup_destroy((struct roots_view_child *)popup); +} + +static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, + struct wlr_xdg_popup_v6 *wlr_popup); + +static void popup_handle_new_popup(struct wl_listener *listener, void *data) { + struct roots_xdg_popup_v6 *popup = + wl_container_of(listener, popup, new_popup); + struct wlr_xdg_popup_v6 *wlr_popup = data; + popup_create(popup->view_child.view, wlr_popup); +} + +static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, + struct wlr_xdg_popup_v6 *wlr_popup) { + struct roots_xdg_popup_v6 *popup = + calloc(1, sizeof(struct roots_xdg_popup_v6)); + if (popup == NULL) { + return NULL; + } + popup->wlr_popup = wlr_popup; + popup->view_child.destroy = popup_destroy; + view_child_init(&popup->view_child, view, wlr_popup->base->surface); + popup->destroy.notify = popup_handle_destroy; + wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy); + popup->new_popup.notify = popup_handle_new_popup; + wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup); + return popup; +} + + static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; @@ -191,9 +237,9 @@ static void handle_request_fullscreen(struct wl_listener *listener, view_set_fullscreen(view, e->fullscreen, e->output); } -static void handle_commit(struct wl_listener *listener, void *data) { +static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_surface = - wl_container_of(listener, roots_surface, commit); + wl_container_of(listener, roots_surface, surface_commit); struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; @@ -223,13 +269,23 @@ static void handle_commit(struct wl_listener *listener, void *data) { } } +static void handle_new_popup(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, new_popup); + struct wlr_xdg_popup_v6 *wlr_popup = data; + popup_create(roots_xdg_surface->view, wlr_popup); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); - wl_list_remove(&roots_xdg_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->new_popup.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_maximize.link); + wl_list_remove(&roots_xdg_surface->request_fullscreen.link); wl_list_remove(&roots_xdg_surface->view->link); view_finish(roots_xdg_surface->view); free(roots_xdg_surface->view); @@ -257,8 +313,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { if (!roots_surface) { return; } - roots_surface->commit.notify = handle_commit; - wl_signal_add(&surface->surface->events.commit, &roots_surface->commit); + roots_surface->surface_commit.notify = handle_surface_commit; + wl_signal_add(&surface->surface->events.commit, + &roots_surface->surface_commit); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); roots_surface->request_move.notify = handle_request_move; @@ -272,6 +329,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->request_fullscreen.notify = handle_request_fullscreen; wl_signal_add(&surface->events.request_fullscreen, &roots_surface->request_fullscreen); + roots_surface->new_popup.notify = handle_new_popup; + wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (!view) { diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 1c46197e..daf5f867 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -203,7 +203,7 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { } } - wl_list_remove(&surface->popup_link); + wl_list_remove(&surface->popup_state->link); free(surface->popup_state); } @@ -502,12 +502,13 @@ static void xdg_surface_get_popup(struct wl_client *client, surface->popup_state->parent = parent; surface->popup_state->geometry = xdg_positioner_get_geometry(positioner, surface, parent); - wl_list_insert(&surface->popup_state->parent->popups, - &surface->popup_link); + wl_list_insert(&parent->popups, &surface->popup_state->link); wl_resource_set_implementation(surface->popup_state->resource, &zxdg_popup_v6_implementation, surface, xdg_popup_resource_destroy); + + wl_signal_emit(&parent->events.new_popup, surface->popup_state); } @@ -1184,6 +1185,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.request_show_window_menu); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); + wl_signal_init(&surface->events.new_popup); wl_signal_add(&surface->surface->events.destroy, &surface->surface_destroy_listener); @@ -1401,14 +1403,16 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( // XXX: I think this is so complicated because we're mixing geometry // coordinates with surface coordinates. Input handling should only deal // with surface coordinates. - struct wlr_xdg_surface_v6 *popup; - wl_list_for_each(popup, &surface->popups, popup_link) { + struct wlr_xdg_popup_v6 *popup_state; + wl_list_for_each(popup_state, &surface->popups, link) { + struct wlr_xdg_surface_v6 *popup = popup_state->base; + double _popup_sx = - surface->geometry->x + popup->popup_state->geometry.x; + surface->geometry->x + popup_state->geometry.x; double _popup_sy = - surface->geometry->y + popup->popup_state->geometry.y; - int popup_width = popup->popup_state->geometry.width; - int popup_height = popup->popup_state->geometry.height; + surface->geometry->y + popup_state->geometry.y; + int popup_width = popup_state->geometry.width; + int popup_height = popup_state->geometry.height; struct wlr_xdg_surface_v6 *_popup = wlr_xdg_surface_v6_popup_at(popup, -- cgit v1.2.3 From 63736be2143a1821fe0b378e56c7e70f1f3cafec Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 28 Jan 2018 10:11:31 +0100 Subject: rootston: fix damage tracking for SSD --- include/rootston/desktop.h | 1 + include/rootston/view.h | 7 ++----- rootston/desktop.c | 25 +++++++++++++------------ rootston/wl_shell.c | 4 ++++ rootston/xdg_shell_v6.c | 15 +++++++++++---- rootston/xwayland.c | 7 +++++++ 6 files changed, 38 insertions(+), 21 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 388fb55d..1232121a 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -69,6 +69,7 @@ void view_activate(struct roots_view *view, bool activate); void view_apply_damage(struct roots_view *view); void view_damage_whole(struct roots_view *view); void view_update_position(struct roots_view *view, double x, double y); +void view_update_size(struct roots_view *view, uint32_t width, uint32_t height); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_wl_shell_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/view.h b/include/rootston/view.h index c9d1deb2..9312c8c3 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -62,6 +62,7 @@ struct roots_view { struct wl_list link; // roots_desktop::views double x, y; + uint32_t width, height; float rotation; bool decorated; @@ -108,11 +109,7 @@ struct roots_view { struct wl_signal destroy; } events; - // 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 - // elsewhere - void (*get_size)(const struct roots_view *view, struct wlr_box *box); + // TODO: this should follow the typical type/impl pattern we use elsewhere void (*activate)(struct roots_view *view, bool active); void (*move)(struct roots_view *view, double x, double y); void (*resize)(struct roots_view *view, uint32_t width, uint32_t height); diff --git a/rootston/desktop.c b/rootston/desktop.c index 25930d2a..9abcfa33 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -24,18 +24,8 @@ void view_get_box(const struct roots_view *view, struct wlr_box *box) { box->x = view->x; box->y = view->y; - if (view->get_size) { - view->get_size(view, box); - } else { - if (view->wlr_surface == NULL) { - // View is unmapped - box->width = box->height = 0; - return; - } - - box->width = view->wlr_surface->current->width; - box->height = view->wlr_surface->current->height; - } + box->width = view->width; + box->height = view->height; } void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) { @@ -469,6 +459,17 @@ void view_update_position(struct roots_view *view, double x, double y) { view_damage_whole(view); } +void view_update_size(struct roots_view *view, uint32_t width, uint32_t height) { + if (view->width == width && view->height == height) { + return; + } + + view_damage_whole(view); + view->width = width; + view->height = height; + view_damage_whole(view); +} + static bool view_at(struct roots_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (view->type == ROOTS_WL_SHELL_VIEW && diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 1fc48452..267e2cf5 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -147,6 +147,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int width = wlr_surface->current->width; int height = wlr_surface->current->height; + view_update_size(view, width, height); + double x = view->x; double y = view->y; if (view->pending_move_resize.update_x) { @@ -231,6 +233,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { return; } view->type = ROOTS_WL_SHELL_VIEW; + view->width = surface->surface->current->width; + view->height = surface->surface->current->height; view->wl_shell_surface = surface; view->roots_wl_shell_surface = roots_surface; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 0a3ca72c..b354b77b 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -245,12 +245,13 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { view_apply_damage(view); + struct wlr_box size; + get_size(view, &size); + view_update_size(view, size.width, size.height); + uint32_t pending_serial = roots_surface->pending_move_resize_configure_serial; if (pending_serial > 0 && pending_serial >= surface->configure_serial) { - struct wlr_box size; - get_size(view, &size); - double x = view->x; double y = view->y; if (view->pending_move_resize.update_x) { @@ -338,10 +339,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { return; } view->type = ROOTS_XDG_SHELL_V6_VIEW; + view->xdg_surface_v6 = surface; view->roots_xdg_surface_v6 = roots_surface; view->wlr_surface = surface->surface; - view->get_size = get_size; view->activate = activate; view->resize = resize; view->move_resize = move_resize; @@ -349,6 +350,12 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->set_fullscreen = set_fullscreen; view->close = close; roots_surface->view = view; + + struct wlr_box box; + get_size(view, &box); + view->width = box.width; + view->height = box.height; + view_init(view, desktop); wl_list_insert(&desktop->views, &view->link); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index c0bc9ae7..a3e12d00 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -209,6 +209,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { int width = wlr_surface->current->width; int height = wlr_surface->current->height; + view_update_size(view, width, height); + double x = view->x; double y = view->y; if (view->pending_move_resize.update_x) { @@ -234,6 +236,8 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->wlr_surface = xsurface->surface; view->x = xsurface->x; view->y = xsurface->y; + view->width = xsurface->surface->current->width; + view->height = xsurface->surface->current->height; wl_list_insert(&desktop->views, &view->link); struct wlr_subsurface *subsurface; @@ -264,6 +268,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { } view->wlr_surface = NULL; + view->width = view->height = 0; wl_list_remove(&view->link); } @@ -314,6 +319,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->type = ROOTS_XWAYLAND_VIEW; view->x = (double)surface->x; view->y = (double)surface->y; + view->width = surface->surface->current->width; + view->height = surface->surface->current->height; view->xwayland_surface = surface; view->roots_xwayland_surface = roots_surface; -- cgit v1.2.3