aboutsummaryrefslogtreecommitdiff
path: root/sway/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop')
-rw-r--r--sway/desktop/output.c248
-rw-r--r--sway/desktop/wl_shell.c6
-rw-r--r--sway/desktop/xwayland.c87
3 files changed, 270 insertions, 71 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 2b428c30..0f00222b 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -1,9 +1,11 @@
#define _POSIX_C_SOURCE 200809L
+#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <wayland-server.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_surface.h>
+#include <wlr/types/wlr_wl_shell.h>
#include <wlr/render.h>
#include <wlr/render/matrix.h>
#include "log.h"
@@ -15,76 +17,198 @@
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
-static void output_frame_view(swayc_t *view, void *data) {
- struct sway_output *output = data;
- struct wlr_output *wlr_output = output->wlr_output;
- struct sway_view *sway_view = view->sway_view;
- struct wlr_surface *surface = sway_view->surface;
+/**
+ * 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).
+ */
+static void rotate_child_position(double *sx, double *sy, double sw, double sh,
+ double pw, double ph, float rotation) {
+ if (rotation != 0.0) {
+ // Coordinates relative to the center of the subsurface
+ double ox = *sx - pw/2 + sw/2,
+ oy = *sy - ph/2 + sh/2;
+ // Rotated coordinates
+ double rx = cos(-rotation)*ox - sin(-rotation)*oy,
+ ry = cos(-rotation)*oy + sin(-rotation)*ox;
+ *sx = rx + pw/2 - sw/2;
+ *sy = ry + ph/2 - sh/2;
+ }
+}
+
+static void render_surface(struct wlr_surface *surface,
+ struct wlr_output *wlr_output, struct timespec *when,
+ double lx, double ly, float rotation) {
if (!wlr_surface_has_buffer(surface)) {
return;
}
- // TODO
- // - Deal with wlr_output_layout
- int width = sway_view->surface->current->width;
- int height = sway_view->surface->current->height;
+ 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;
- double ox = view->x, oy = view->y;
- // TODO
- //wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
+ double ox = lx, oy = ly;
+ wlr_output_layout_output_coords(layout, wlr_output, &ox, &oy);
ox *= wlr_output->scale;
oy *= wlr_output->scale;
- // TODO
- //if (wlr_output_layout_intersects(desktop->layout, wlr_output,
- // lx, ly, lx + render_width, ly + render_height)) {
- // return;
- //}
-
- // if the shell specifies window geometry, make the top left corner of the
- // window in the top left corner of the container to avoid arbitrarily
- // sized gaps based on the attached buffer size
- int window_offset_x = 0;
- int window_offset_y = 0;
-
- if (view->sway_view->type == SWAY_XDG_SHELL_V6_VIEW) {
- window_offset_x = view->sway_view->wlr_xdg_surface_v6->geometry->x;
- window_offset_y = view->sway_view->wlr_xdg_surface_v6->geometry->y;
+
+ struct wlr_box render_box = {
+ .x = lx, .y = ly,
+ .width = render_width, .height = render_height,
+ };
+ if (wlr_output_layout_intersects(layout, wlr_output, &render_box)) {
+ float matrix[16];
+
+ float translate_center[16];
+ wlr_matrix_translate(&translate_center,
+ (int)ox + render_width / 2, (int)oy + render_height / 2, 0);
+
+ float rotate[16];
+ wlr_matrix_rotate(&rotate, rotation);
+
+ float translate_origin[16];
+ wlr_matrix_translate(&translate_origin, -render_width / 2,
+ -render_height / 2, 0);
+
+ float scale[16];
+ wlr_matrix_scale(&scale, render_width, render_height, 1);
+
+ float transform[16];
+ wlr_matrix_mul(&translate_center, &rotate, &transform);
+ wlr_matrix_mul(&transform, &translate_origin, &transform);
+ wlr_matrix_mul(&transform, &scale, &transform);
+
+ if (surface->current->transform != WL_OUTPUT_TRANSFORM_NORMAL) {
+ float surface_translate_center[16];
+ wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0);
+
+ float surface_transform[16];
+ wlr_matrix_transform(surface_transform,
+ wlr_output_transform_invert(surface->current->transform));
+
+ float surface_translate_origin[16];
+ wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0);
+
+ wlr_matrix_mul(&transform, &surface_translate_center,
+ &transform);
+ wlr_matrix_mul(&transform, &surface_transform, &transform);
+ wlr_matrix_mul(&transform, &surface_translate_origin,
+ &transform);
+ }
+
+ wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
+
+ wlr_render_with_matrix(server.renderer, surface->texture,
+ &matrix);
+
+ wlr_surface_send_frame_done(surface, when);
}
- // TODO
- double rotation = 0;
- float matrix[16];
+ 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;
+ double sw = state->buffer_width / state->scale;
+ double sh = state->buffer_height / state->scale;
+ rotate_child_position(&sx, &sy, sw, sh, width, height, rotation);
- float translate_origin[16];
- wlr_matrix_translate(&translate_origin,
- (int)ox + render_width / 2 - window_offset_x,
- (int)oy + render_height / 2 - window_offset_y,
- 0);
+ render_surface(subsurface->surface, wlr_output, when,
+ lx + sx,
+ ly + sy,
+ rotation);
+ }
+}
- float rotate[16];
- wlr_matrix_rotate(&rotate, rotation);
+static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface,
+ struct wlr_output *wlr_output, struct timespec *when, double base_x,
+ double base_y, float rotation) {
+ double width = surface->surface->current->width;
+ double height = surface->surface->current->height;
- float translate_center[16];
- wlr_matrix_translate(&translate_center,
- -render_width / 2,
- -render_height / 2, 0);
+ struct wlr_xdg_surface_v6 *popup;
+ wl_list_for_each(popup, &surface->popups, popup_link) {
+ if (!popup->configured) {
+ continue;
+ }
- float scale[16];
- wlr_matrix_scale(&scale, render_width, render_height, 1);
+ double popup_width = popup->surface->current->width;
+ double popup_height = popup->surface->current->height;
- float transform[16];
- wlr_matrix_mul(&translate_origin, &rotate, &transform);
- wlr_matrix_mul(&transform, &translate_center, &transform);
- wlr_matrix_mul(&transform, &scale, &transform);
- wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
+ 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);
- wlr_render_with_matrix(output->server->renderer, surface->texture, &matrix);
+ render_surface(popup->surface, wlr_output, when,
+ base_x + popup_sx, base_y + popup_sy, rotation);
+ render_xdg_v6_popups(popup, wlr_output, when,
+ base_x + popup_sx, base_y + popup_sy, rotation);
+ }
+}
- // TODO: move into wlroots
- struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface,
+ struct wlr_output *wlr_output, struct timespec *when,
+ double lx, double ly, float rotation,
+ bool is_child) {
+ if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) {
+ render_surface(surface->surface, wlr_output, when,
+ 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, wlr_output, when,
+ lx + popup_x, ly + popup_y, rotation, true);
+ }
+ }
+}
+
+
+static void output_frame_view(swayc_t *view, void *data) {
+ struct sway_output *output = data;
+ struct wlr_output *wlr_output = output->wlr_output;
+ struct sway_view *sway_view = view->sway_view;
+ struct wlr_surface *surface = sway_view->surface;
+
+ if (!surface) {
+ return;
+ }
- wlr_surface_send_frame_done(surface, &now);
+ switch (sway_view->type) {
+ case SWAY_XDG_SHELL_V6_VIEW: {
+ int window_offset_x = view->sway_view->wlr_xdg_surface_v6->geometry->x;
+ int window_offset_y = view->sway_view->wlr_xdg_surface_v6->geometry->y;
+ render_surface(surface, wlr_output, &output->last_frame,
+ view->x - window_offset_x,
+ view->y - window_offset_y,
+ 0);
+ render_xdg_v6_popups(sway_view->wlr_xdg_surface_v6, wlr_output,
+ &output->last_frame,
+ view->x - window_offset_x, view->y - window_offset_y,
+ 0);
+ break;
+ }
+ case SWAY_WL_SHELL_VIEW:
+ render_wl_shell_surface(sway_view->wlr_wl_shell_surface, wlr_output,
+ &output->last_frame, view->x, view->y, 0, false);
+ break;
+ case SWAY_XWAYLAND_VIEW:
+ render_surface(surface, wlr_output, &output->last_frame, view->x,
+ view->y, 0);
+ break;
+ default:
+ break;
+ }
}
static void output_frame_notify(struct wl_listener *listener, void *data) {
@@ -92,18 +216,30 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = data;
struct sway_server *server = soutput->server;
- struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
-
wlr_output_make_current(wlr_output);
wlr_renderer_begin(server->renderer, wlr_output);
swayc_descendants_of_type(
&root_container, C_VIEW, output_frame_view, soutput);
+ // 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) {
+ // the only kind of unamanged view right now is xwayland override redirect
+ int view_x = view->wlr_xwayland_surface->x;
+ int view_y = view->wlr_xwayland_surface->y;
+ render_surface(view->surface, wlr_output, &soutput->last_frame,
+ view_x, view_y, 0);
+ }
+ }
+
wlr_renderer_end(server->renderer);
wlr_output_swap_buffers(wlr_output);
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
soutput->last_frame = now;
}
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c
index 345a1398..e34f5160 100644
--- a/sway/desktop/wl_shell.c
+++ b/sway/desktop/wl_shell.c
@@ -77,11 +77,13 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
listener, server, wl_shell_surface);
struct wlr_wl_shell_surface *shell_surface = data;
- if (shell_surface->state != WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL) {
- // TODO: transient and popups should be floating
+ if (shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) {
+ // popups don't get views
return;
}
+ // TODO make transient windows floating
+
wlr_log(L_DEBUG, "New wl_shell toplevel title='%s' app_id='%s'",
shell_surface->title, shell_surface->class);
wlr_wl_shell_surface_ping(shell_surface);
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 43bb2e00..a4d9687d 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -93,13 +93,68 @@ static void handle_commit(struct wl_listener *listener, void *data) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_xwayland_surface *sway_surface =
wl_container_of(listener, sway_surface, destroy);
+ struct wlr_xwayland_surface *xsurface = data;
wl_list_remove(&sway_surface->commit.link);
wl_list_remove(&sway_surface->destroy.link);
wl_list_remove(&sway_surface->request_configure.link);
+ if (xsurface->override_redirect) {
+ if (xsurface->mapped) {
+ wl_list_remove(&sway_surface->view->unmanaged_view_link);
+ }
+ }
+
swayc_t *parent = destroy_view(sway_surface->view->swayc);
+ if (parent) {
+ arrange_windows(parent, -1, -1);
+ }
+
free(sway_surface->view);
free(sway_surface);
- arrange_windows(parent, -1, -1);
+}
+
+static void handle_unmap_notify(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_surface *sway_surface =
+ wl_container_of(listener, sway_surface, unmap_notify);
+ struct wlr_xwayland_surface *xsurface = data;
+ if (xsurface->override_redirect) {
+ wl_list_remove(&sway_surface->view->unmanaged_view_link);
+ }
+
+ // take it out of the tree
+ swayc_t *parent = destroy_view(sway_surface->view->swayc);
+ if (parent) {
+ arrange_windows(parent, -1, -1);
+ }
+
+ sway_surface->view->swayc = NULL;
+ sway_surface->view->surface = NULL;
+}
+
+static void handle_map_notify(struct wl_listener *listener, void *data) {
+ // TODO put the view back into the tree
+ struct sway_xwayland_surface *sway_surface =
+ wl_container_of(listener, sway_surface, map_notify);
+ struct wlr_xwayland_surface *xsurface = data;
+
+ sway_surface->view->surface = xsurface->surface;
+
+ // put it back into the tree
+ if (xsurface->override_redirect) {
+ wl_list_insert(&root_container.sway_root->unmanaged_views,
+ &sway_surface->view->unmanaged_view_link);
+ } else {
+ struct sway_view *view = sway_surface->view;
+ destroy_view(view->swayc);
+
+ swayc_t *parent = root_container.children->items[0];
+ parent = parent->children->items[0]; // workspace
+
+ swayc_t *cont = new_view(parent, view);
+ view->swayc = cont;
+
+ arrange_windows(cont->parent, -1, -1);
+ sway_input_manager_set_focus(input_manager, cont);
+ }
}
static void handle_configure_request(struct wl_listener *listener, void *data) {
@@ -119,11 +174,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
listener, server, xwayland_surface);
struct wlr_xwayland_surface *xsurface = data;
- if (xsurface->override_redirect) {
- // TODO: floating popups
- return;
- }
-
wlr_log(L_DEBUG, "New xwayland surface title='%s' class='%s'",
xsurface->title, xsurface->class);
@@ -144,26 +194,37 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
sway_view->iface.set_activated = set_activated;
sway_view->wlr_xwayland_surface = xsurface;
sway_view->sway_xwayland_surface = sway_surface;
- // TODO remove from the tree when the surface goes away (unmapped)
sway_view->surface = xsurface->surface;
sway_surface->view = sway_view;
// TODO:
- // - Wire up listeners
- // - Handle popups
// - Look up pid and open on appropriate workspace
// - Set new view to maximized so it behaves nicely
// - Criteria
- sway_surface->commit.notify = handle_commit;
wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit);
- sway_surface->destroy.notify = handle_destroy;
+ sway_surface->commit.notify = handle_commit;
+
wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy);
- sway_surface->request_configure.notify = handle_configure_request;
+ sway_surface->destroy.notify = handle_destroy;
+
wl_signal_add(&xsurface->events.request_configure,
&sway_surface->request_configure);
+ sway_surface->request_configure.notify = handle_configure_request;
+
+ wl_signal_add(&xsurface->events.unmap_notify, &sway_surface->unmap_notify);
+ sway_surface->unmap_notify.notify = handle_unmap_notify;
+
+ wl_signal_add(&xsurface->events.map_notify, &sway_surface->map_notify);
+ sway_surface->map_notify.notify = handle_map_notify;
+
+ if (xsurface->override_redirect) {
+ // these don't get a container in the tree
+ wl_list_insert(&root_container.sway_root->unmanaged_views,
+ &sway_view->unmanaged_view_link);
+ return;
+ }
- // TODO: actual focus semantics
swayc_t *parent = root_container.children->items[0];
parent = parent->children->items[0]; // workspace