diff options
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/output.c | 87 | ||||
-rw-r--r-- | sway/desktop/wl_shell.c | 61 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 67 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 136 |
4 files changed, 167 insertions, 184 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 5e8a081c..10ed1f6d 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -39,6 +39,32 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh, } } +/** + * Checks whether a surface at (lx, ly) intersects an output. If `box` is not + * NULL, it populates it with the surface box in the output, in output-local + * coordinates. + */ +static bool surface_intersect_output(struct wlr_surface *surface, + struct wlr_output_layout *output_layout, struct wlr_output *wlr_output, + double lx, double ly, float rotation, struct wlr_box *box) { + double ox = lx, oy = ly; + wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy); + + if (box != NULL) { + box->x = ox * wlr_output->scale; + box->y = oy * wlr_output->scale; + box->width = surface->current->width * wlr_output->scale; + box->height = surface->current->height * wlr_output->scale; + } + + struct wlr_box layout_box = { + .x = lx, .y = ly, + .width = surface->current->width, .height = surface->current->height, + }; + wlr_box_rotated_bounds(&layout_box, rotation, &layout_box); + return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box); +} + static void render_surface(struct wlr_surface *surface, struct wlr_output *wlr_output, struct timespec *when, double lx, double ly, float rotation) { @@ -48,29 +74,21 @@ static void render_surface(struct wlr_surface *surface, if (!wlr_surface_has_buffer(surface)) { return; } + struct wlr_output_layout *layout = root_container.sway_root->output_layout; - int width = surface->current->width; - int height = surface->current->height; - int render_width = width * wlr_output->scale; - int render_height = height * wlr_output->scale; - int owidth, oheight; - wlr_output_effective_resolution(wlr_output, &owidth, &oheight); - - // FIXME: view coords are inconsistently assumed to be in output or layout coords - struct wlr_box layout_box = { - .x = lx + wlr_output->lx, .y = ly + wlr_output->ly, - .width = render_width, .height = render_height, - }; - if (wlr_output_layout_intersects(layout, wlr_output, &layout_box)) { - struct wlr_box render_box = { - .x = lx, .y = ly, - .width = render_width, .height = render_height - }; + + struct wlr_box box; + bool intersects = surface_intersect_output(surface, layout, wlr_output, + lx, ly, rotation, &box); + if (intersects) { float matrix[9]; - wlr_matrix_project_box(matrix, &render_box, surface->current->transform, - 0, wlr_output->transform_matrix); - wlr_render_texture_with_matrix(renderer, surface->texture, matrix, - 1.0f); // TODO: configurable alpha + enum wl_output_transform transform = + wlr_output_transform_invert(surface->current->transform); + wlr_matrix_project_box(matrix, &box, transform, rotation, + wlr_output->transform_matrix); + + // TODO: configurable alpha + wlr_render_texture_with_matrix(renderer, surface->texture, matrix, 1.0f); wlr_surface_send_frame_done(surface, when); } @@ -80,9 +98,8 @@ static void render_surface(struct wlr_surface *surface, struct wlr_surface_state *state = subsurface->surface->current; double sx = state->subsurface_position.x; double sy = state->subsurface_position.y; - double sw = state->buffer_width / state->scale; - double sh = state->buffer_height / state->scale; - rotate_child_position(&sx, &sy, sw, sh, width, height, rotation); + rotate_child_position(&sx, &sy, state->width, state->height, + surface->current->width, surface->current->height, rotation); render_surface(subsurface->surface, wlr_output, when, lx + sx, ly + sy, rotation); @@ -243,15 +260,15 @@ static void render_output(struct sway_output *output, struct timespec *when, container_descendants(workspace, C_VIEW, render_view, &rdata); // render unmanaged views on top - struct sway_view *view; - wl_list_for_each(view, &root_container.sway_root->unmanaged_views, - unmanaged_view_link) { - if (view->type != SWAY_XWAYLAND_VIEW) { + 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 wlr_xwayland_surface *xsurface = + sway_surface->wlr_xwayland_surface; + if (xsurface->surface == NULL) { continue; } - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - const struct wlr_box view_box = { .x = xsurface->x, .y = xsurface->y, @@ -263,7 +280,7 @@ static void render_output(struct sway_output *output, struct timespec *when, continue; } - render_surface(view->surface, wlr_output, &output->last_frame, + render_surface(xsurface->surface, wlr_output, &output->last_frame, view_box.x - output_box->x, view_box.y - output_box->y, 0); } @@ -341,6 +358,12 @@ static void handle_transform(struct wl_listener *listener, void *data) { arrange_windows(output->swayc, -1, -1); } +static void handle_scale(struct wl_listener *listener, void *data) { + struct sway_output *output = wl_container_of(listener, output, scale); + arrange_layers(output); + arrange_windows(output->swayc, -1, -1); +} + void handle_new_output(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, new_output); struct wlr_output *wlr_output = data; @@ -381,6 +404,8 @@ void handle_new_output(struct wl_listener *listener, void *data) { output->mode.notify = handle_mode; wl_signal_add(&wlr_output->events.transform, &output->transform); output->transform.notify = handle_transform; + wl_signal_add(&wlr_output->events.scale, &output->scale); + output->scale.notify = handle_scale; wl_signal_add(&output->damage->events.frame, &output->damage_frame); output->damage_frame.notify = damage_handle_frame; diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index c44fcf27..6528a397 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -30,28 +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_wl_shell(view)) { return; } + view_update_position(view, ox, oy); view->sway_wl_shell_surface->pending_width = width; view->sway_wl_shell_surface->pending_height = height; wlr_wl_shell_surface_configure(view->wlr_wl_shell_surface, 0, width, height); } -static void set_position(struct sway_view *view, double ox, double oy) { - if (!assert_wl_shell(view)) { - return; - } - view->swayc->x = ox; - view->swayc->y = oy; -} - -static void set_activated(struct sway_view *view, bool activated) { - // no way to activate wl_shell -} - -static void close(struct sway_view *view) { +static void _close(struct sway_view *view) { if (!assert_wl_shell(view)) { return; } @@ -59,14 +49,20 @@ static void close(struct sway_view *view) { wl_client_destroy(view->wlr_wl_shell_surface->client); } +static const struct sway_view_impl view_impl = { + .get_prop = get_prop, + .configure = configure, + .close = _close, +}; + static void handle_commit(struct wl_listener *listener, void *data) { struct sway_wl_shell_surface *sway_surface = wl_container_of(listener, sway_surface, commit); struct sway_view *view = sway_surface->view; // NOTE: We intentionally discard the view's desired width here // 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); } @@ -75,15 +71,13 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_container_of(listener, sway_surface, destroy); wl_list_remove(&sway_surface->commit.link); wl_list_remove(&sway_surface->destroy.link); - struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); - free(sway_surface->view); + view_destroy(sway_surface->view); free(sway_surface); - arrange_windows(parent, -1, -1); } void handle_wl_shell_surface(struct wl_listener *listener, void *data) { - struct sway_server *server = wl_container_of( - listener, server, wl_shell_surface); + struct sway_server *server = wl_container_of(listener, server, + wl_shell_surface); struct wlr_wl_shell_surface *shell_surface = data; if (shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) { @@ -103,20 +97,13 @@ void handle_wl_shell_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_WL_SHELL_VIEW, &view_impl); + if (!sway_assert(view, "Failed to allocate view")) { return; } - sway_view->type = SWAY_WL_SHELL_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_wl_shell_surface = shell_surface; - sway_view->sway_wl_shell_surface = sway_surface; - sway_view->surface = shell_surface->surface; - sway_surface->view = sway_view; + view->wlr_wl_shell_surface = shell_surface; + view->sway_wl_shell_surface = sway_surface; + sway_surface->view = view; // TODO: // - Wire up listeners @@ -132,11 +119,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { sway_surface->destroy.notify = handle_destroy; wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy); - 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, sway_view); - sway_view->swayc = cont; - - arrange_windows(cont->parent, -1, -1); - input_manager_set_focus(input_manager, cont); + view_map(view, shell_surface->surface); } 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; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 17f827d9..bfef68cf 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -14,6 +14,33 @@ #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 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; + } + + sway_surface->wlr_xwayland_surface = xsurface; + + wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy); + sway_surface->destroy.notify = unmanaged_handle_destroy; + + wl_list_insert(&root_container.sway_root->xwayland_unmanaged, + &sway_surface->link); + + // TODO: damage tracking +} + + static bool assert_xwayland(struct sway_view *view) { return sway_assert(view->type == SWAY_XWAYLAND_VIEW, "Expected xwayland view!"); @@ -33,22 +60,13 @@ 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_xwayland(view)) { return; } - view->sway_xwayland_surface->pending_width = width; - view->sway_xwayland_surface->pending_height = height; - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - wlr_xwayland_surface_configure(xsurface, xsurface->x, xsurface->y, - width, height); -} -static void set_position(struct sway_view *view, double ox, double oy) { - if (!assert_xwayland(view)) { - return; - } struct sway_container *output = container_parent(view->swayc, C_OUTPUT); if (!sway_assert(output, "view must be within tree to set position")) { return; @@ -64,13 +82,12 @@ static void set_position(struct sway_view *view, double ox, double oy) { return; } - view->swayc->x = ox; - view->swayc->y = oy; + view_update_position(view, ox, oy); - wlr_xwayland_surface_configure(view->wlr_xwayland_surface, - ox + loutput->x, oy + loutput->y, - view->wlr_xwayland_surface->width, - view->wlr_xwayland_surface->height); + view->sway_xwayland_surface->pending_width = width; + view->sway_xwayland_surface->pending_height = height; + wlr_xwayland_surface_configure(xsurface, ox + loutput->x, oy + loutput->y, + width, height); } static void set_activated(struct sway_view *view, bool activated) { @@ -81,77 +98,58 @@ static void set_activated(struct sway_view *view, bool activated) { wlr_xwayland_surface_activate(surface, activated); } -static void close_view(struct sway_view *view) { +static void _close(struct sway_view *view) { if (!assert_xwayland(view)) { return; } wlr_xwayland_surface_close(view->wlr_xwayland_surface); } +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_xwayland_surface *sway_surface = wl_container_of(listener, sway_surface, commit); struct sway_view *view = sway_surface->view; // NOTE: We intentionally discard the view's desired width here // 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_destroy(struct wl_listener *listener, void *data) { struct sway_xwayland_surface *sway_surface = wl_container_of(listener, sway_surface, destroy); - wl_list_remove(&sway_surface->commit.link); wl_list_remove(&sway_surface->destroy.link); wl_list_remove(&sway_surface->request_configure.link); - wl_list_remove(&sway_surface->view->unmanaged_view_link); - container_view_destroy(sway_surface->view->swayc); - sway_surface->view->swayc = NULL; - sway_surface->view->surface = NULL; + wl_list_remove(&sway_surface->map.link); + wl_list_remove(&sway_surface->unmap.link); + view_destroy(sway_surface->view); + free(sway_surface); } static void handle_unmap(struct wl_listener *listener, void *data) { struct sway_xwayland_surface *sway_surface = wl_container_of(listener, sway_surface, unmap); - view_damage_whole(sway_surface->view); - wl_list_remove(&sway_surface->view->unmanaged_view_link); - wl_list_init(&sway_surface->view->unmanaged_view_link); - 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_xwayland_surface *sway_surface = wl_container_of(listener, sway_surface, map); struct wlr_xwayland_surface *xsurface = data; - - sway_surface->view->surface = xsurface->surface; + struct sway_view *view = sway_surface->view; // put it back into the tree - if (wlr_xwayland_surface_is_unmanaged(xsurface) || - xsurface->override_redirect) { - wl_list_remove(&sway_surface->view->unmanaged_view_link); - wl_list_insert(&root_container.sway_root->unmanaged_views, - &sway_surface->view->unmanaged_view_link); - } else { - struct sway_view *view = sway_surface->view; - container_view_destroy(view->swayc); - - wlr_xwayland_surface_set_maximized(xsurface, true); - - 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); + wlr_xwayland_surface_set_maximized(xsurface, true); + view_map(view, xsurface->surface); } static void handle_request_configure(struct wl_listener *listener, void *data) { @@ -171,34 +169,32 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { listener, server, xwayland_surface); struct wlr_xwayland_surface *xsurface = data; + if (wlr_xwayland_surface_is_unmanaged(xsurface) || + xsurface->override_redirect) { + wlr_log(L_DEBUG, "New xwayland unmanaged surface"); + create_unmanaged(xsurface); + return; + } + wlr_log(L_DEBUG, "New xwayland surface title='%s' class='%s'", - xsurface->title, xsurface->class); + xsurface->title, xsurface->class); struct sway_xwayland_surface *sway_surface = calloc(1, sizeof(struct sway_xwayland_surface)); - if (!sway_assert(sway_surface, "Failed to allocate surface!")) { + if (!sway_assert(sway_surface, "Failed to allocate surface")) { 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_XWAYLAND_VIEW, &view_impl); + if (!sway_assert(view, "Failed to allocate view")) { return; } - sway_view->type = SWAY_XWAYLAND_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_view; - sway_view->wlr_xwayland_surface = xsurface; - sway_view->sway_xwayland_surface = sway_surface; - sway_surface->view = sway_view; - - wl_list_init(&sway_view->unmanaged_view_link); + view->wlr_xwayland_surface = xsurface; + view->sway_xwayland_surface = 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 wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit); |