aboutsummaryrefslogtreecommitdiff
path: root/sway/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop')
-rw-r--r--sway/desktop/layer_shell.c7
-rw-r--r--sway/desktop/output.c339
-rw-r--r--sway/desktop/render.c132
-rw-r--r--sway/desktop/transaction.c87
-rw-r--r--sway/desktop/xdg_shell.c105
-rw-r--r--sway/desktop/xdg_shell_v6.c106
-rw-r--r--sway/desktop/xwayland.c60
7 files changed, 544 insertions, 292 deletions
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c
index a7d96717..a2935883 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -7,11 +7,13 @@
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_output.h>
#include <wlr/util/log.h>
+#include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/layers.h"
#include "sway/output.h"
#include "sway/server.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/layout.h"
#include "log.h"
@@ -245,6 +247,9 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
output_damage_surface(output, layer->geo.x, layer->geo.y,
layer_surface->surface, false);
}
+
+ arrange_windows(output->swayc);
+ transaction_commit_dirty();
}
static void unmap(struct sway_layer_surface *sway_layer) {
@@ -282,6 +287,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_output *output = sway_layer->layer_surface->output->data;
if (output != NULL && output->swayc != NULL) {
arrange_layers(output);
+ arrange_windows(output->swayc);
+ transaction_commit_dirty();
}
wl_list_remove(&sway_layer->output_destroy.link);
sway_layer->layer_surface->output = NULL;
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index a9808406..66747a3f 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -14,6 +14,7 @@
#include <wlr/types/wlr_surface.h>
#include <wlr/util/region.h>
#include "log.h"
+#include "config.h"
#include "sway/config.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
@@ -56,9 +57,21 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh,
*sy = ry + ph/2 - sh/2;
}
-bool output_get_surface_box(struct root_geometry *geo,
- struct sway_output *output, struct wlr_surface *surface, int sx, int sy,
+struct surface_iterator_data {
+ sway_surface_iterator_func_t user_iterator;
+ void *user_data;
+
+ struct sway_output *output;
+ double ox, oy;
+ int width, height;
+ float rotation;
+};
+
+static bool get_surface_box(struct surface_iterator_data *data,
+ struct wlr_surface *surface, int sx, int sy,
struct wlr_box *surface_box) {
+ struct sway_output *output = data->output;
+
if (!wlr_surface_has_buffer(surface)) {
return false;
}
@@ -67,12 +80,12 @@ bool output_get_surface_box(struct root_geometry *geo,
int sh = surface->current.height;
double _sx = sx, _sy = sy;
- rotate_child_position(&_sx, &_sy, sw, sh, geo->width, geo->height,
- geo->rotation);
+ rotate_child_position(&_sx, &_sy, sw, sh, data->width, data->height,
+ data->rotation);
struct wlr_box box = {
- .x = geo->x + _sx,
- .y = geo->y + _sy,
+ .x = data->ox + _sx,
+ .y = data->oy + _sy,
.width = sw,
.height = sh,
};
@@ -81,7 +94,7 @@ bool output_get_surface_box(struct root_geometry *geo,
}
struct wlr_box rotated_box;
- wlr_box_rotated_bounds(&box, geo->rotation, &rotated_box);
+ wlr_box_rotated_bounds(&box, data->rotation, &rotated_box);
struct wlr_box output_box = {
.width = output->swayc->current.swayc_width,
@@ -92,46 +105,90 @@ bool output_get_surface_box(struct root_geometry *geo,
return wlr_box_intersection(&output_box, &rotated_box, &intersection);
}
-void output_surface_for_each_surface(struct wlr_surface *surface,
- double ox, double oy, struct root_geometry *geo,
- wlr_surface_iterator_func_t iterator, void *user_data) {
- geo->x = ox;
- geo->y = oy;
- geo->width = surface->current.width;
- geo->height = surface->current.height;
- geo->rotation = 0;
+static void output_for_each_surface_iterator(struct wlr_surface *surface,
+ int sx, int sy, void *_data) {
+ struct surface_iterator_data *data = _data;
- wlr_surface_for_each_surface(surface, iterator, user_data);
+ struct wlr_box box;
+ bool intersects = get_surface_box(data, surface, sx, sy, &box);
+ if (!intersects) {
+ return;
+ }
+
+ data->user_iterator(data->output, surface, &box, data->rotation,
+ data->user_data);
+}
+
+void output_surface_for_each_surface(struct sway_output *output,
+ struct wlr_surface *surface, double ox, double oy,
+ sway_surface_iterator_func_t iterator, void *user_data) {
+ struct surface_iterator_data data = {
+ .user_iterator = iterator,
+ .user_data = user_data,
+ .output = output,
+ .ox = ox,
+ .oy = oy,
+ .width = surface->current.width,
+ .height = surface->current.height,
+ .rotation = 0,
+ };
+
+ wlr_surface_for_each_surface(surface,
+ output_for_each_surface_iterator, &data);
}
-void output_view_for_each_surface(struct sway_view *view,
- struct sway_output *output, struct root_geometry *geo,
- wlr_surface_iterator_func_t iterator, void *user_data) {
- geo->x = view->swayc->current.view_x - output->swayc->current.swayc_x;
- geo->y = view->swayc->current.view_y - output->swayc->current.swayc_y;
- geo->width = view->swayc->current.view_width;
- geo->height = view->swayc->current.view_height;
- geo->rotation = 0; // TODO
+void output_view_for_each_surface(struct sway_output *output,
+ struct sway_view *view, sway_surface_iterator_func_t iterator,
+ void *user_data) {
+ struct surface_iterator_data data = {
+ .user_iterator = iterator,
+ .user_data = user_data,
+ .output = output,
+ .ox = view->swayc->current.view_x - output->swayc->current.swayc_x,
+ .oy = view->swayc->current.view_y - output->swayc->current.swayc_y,
+ .width = view->swayc->current.view_width,
+ .height = view->swayc->current.view_height,
+ .rotation = 0, // TODO
+ };
- view_for_each_surface(view, iterator, user_data);
+ view_for_each_surface(view,
+ output_for_each_surface_iterator, &data);
}
-void output_layer_for_each_surface(struct wl_list *layer_surfaces,
- struct root_geometry *geo, wlr_surface_iterator_func_t iterator,
+void output_view_for_each_popup(struct sway_output *output,
+ struct sway_view *view, sway_surface_iterator_func_t iterator,
+ void *user_data) {
+ struct surface_iterator_data data = {
+ .user_iterator = iterator,
+ .user_data = user_data,
+ .output = output,
+ .ox = view->swayc->current.view_x - output->swayc->current.swayc_x,
+ .oy = view->swayc->current.view_y - output->swayc->current.swayc_y,
+ .width = view->swayc->current.view_width,
+ .height = view->swayc->current.view_height,
+ .rotation = 0, // TODO
+ };
+
+ view_for_each_popup(view, output_for_each_surface_iterator, &data);
+}
+
+void output_layer_for_each_surface(struct sway_output *output,
+ struct wl_list *layer_surfaces, sway_surface_iterator_func_t iterator,
void *user_data) {
struct sway_layer_surface *layer_surface;
wl_list_for_each(layer_surface, layer_surfaces, link) {
struct wlr_layer_surface *wlr_layer_surface =
layer_surface->layer_surface;
- output_surface_for_each_surface(wlr_layer_surface->surface,
- layer_surface->geo.x, layer_surface->geo.y, geo, iterator,
+ output_surface_for_each_surface(output, wlr_layer_surface->surface,
+ layer_surface->geo.x, layer_surface->geo.y, iterator,
user_data);
}
}
-void output_unmanaged_for_each_surface(struct wl_list *unmanaged,
- struct sway_output *output, struct root_geometry *geo,
- wlr_surface_iterator_func_t iterator, void *user_data) {
+#ifdef HAVE_XWAYLAND
+void output_unmanaged_for_each_surface(struct sway_output *output,
+ struct wl_list *unmanaged, sway_surface_iterator_func_t iterator,
+ void *user_data) {
struct sway_xwayland_unmanaged *unmanaged_surface;
wl_list_for_each(unmanaged_surface, unmanaged, link) {
struct wlr_xwayland_surface *xsurface =
@@ -139,22 +196,24 @@ void output_unmanaged_for_each_surface(struct wl_list *unmanaged,
double ox = unmanaged_surface->lx - output->swayc->current.swayc_x;
double oy = unmanaged_surface->ly - output->swayc->current.swayc_y;
- output_surface_for_each_surface(xsurface->surface, ox, oy, geo,
+ output_surface_for_each_surface(output, xsurface->surface, ox, oy,
iterator, user_data);
}
}
+#endif
-void output_drag_icons_for_each_surface(struct wl_list *drag_icons,
- struct sway_output *output, struct root_geometry *geo,
- wlr_surface_iterator_func_t iterator, void *user_data) {
+void output_drag_icons_for_each_surface(struct sway_output *output,
+ struct wl_list *drag_icons, sway_surface_iterator_func_t iterator,
+ void *user_data) {
struct sway_drag_icon *drag_icon;
wl_list_for_each(drag_icon, drag_icons, link) {
double ox = drag_icon->x - output->swayc->x;
double oy = drag_icon->y - output->swayc->y;
if (drag_icon->wlr_drag_icon->mapped) {
- output_surface_for_each_surface(drag_icon->wlr_drag_icon->surface,
- ox, oy, geo, iterator, user_data);
+ output_surface_for_each_surface(output,
+ drag_icon->wlr_drag_icon->surface, ox, oy,
+ iterator, user_data);
}
}
}
@@ -181,21 +240,14 @@ struct sway_container *output_get_active_workspace(struct sway_output *output) {
return workspace;
}
-bool output_has_opaque_lockscreen(struct sway_output *output,
- struct sway_seat *seat) {
- if (!seat->exclusive_client) {
- return false;
- }
-
+bool output_has_opaque_overlay_layer_surface(struct sway_output *output) {
struct wlr_layer_surface *wlr_layer_surface;
wl_list_for_each(wlr_layer_surface, &server.layer_shell->surfaces, link) {
- if (wlr_layer_surface->output != output->wlr_output) {
+ if (wlr_layer_surface->output != output->wlr_output ||
+ wlr_layer_surface->layer != ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
continue;
}
struct wlr_surface *wlr_surface = wlr_layer_surface->surface;
- if (wlr_surface->resource->client != seat->exclusive_client) {
- continue;
- }
struct sway_layer_surface *sway_layer_surface =
layer_from_wlr_layer_surface(wlr_layer_surface);
pixman_box32_t output_box = {
@@ -217,46 +269,38 @@ bool output_has_opaque_lockscreen(struct sway_output *output,
return false;
}
-struct send_frame_done_data {
- struct root_geometry root_geo;
- struct sway_output *output;
- struct timespec *when;
- struct wl_client *exclusive_client;
-};
-
-static void send_frame_done_iterator(struct wlr_surface *surface,
- int sx, int sy, void *_data) {
- struct send_frame_done_data *data = _data;
- if (data->exclusive_client &&
- data->exclusive_client != surface->resource->client) {
- return;
- }
-
- bool intersects = output_get_surface_box(&data->root_geo, data->output, surface,
- sx, sy, NULL);
- if (intersects) {
- wlr_surface_send_frame_done(surface, data->when);
- }
+static void send_frame_done_iterator(struct sway_output *output,
+ struct wlr_surface *surface, struct wlr_box *box, float rotation,
+ void *_data) {
+ struct timespec *when = _data;
+ wlr_surface_send_frame_done(surface, when);
}
-static void send_frame_done_layer(struct send_frame_done_data *data,
- struct wl_list *layer_surfaces) {
- output_layer_for_each_surface(layer_surfaces, &data->root_geo,
- send_frame_done_iterator, data);
+static void send_frame_done_layer(struct sway_output *output,
+ struct wl_list *layer_surfaces, struct timespec *when) {
+ output_layer_for_each_surface(output, layer_surfaces,
+ send_frame_done_iterator, when);
}
-static void send_frame_done_unmanaged(struct send_frame_done_data *data,
- struct wl_list *unmanaged) {
- output_unmanaged_for_each_surface(unmanaged, data->output, &data->root_geo,
- send_frame_done_iterator, data);
+#ifdef HAVE_XWAYLAND
+static void send_frame_done_unmanaged(struct sway_output *output,
+ struct wl_list *unmanaged, struct timespec *when) {
+ output_unmanaged_for_each_surface(output, unmanaged,
+ send_frame_done_iterator, when);
}
+#endif
-static void send_frame_done_drag_icons(struct send_frame_done_data *data,
- struct wl_list *drag_icons) {
- output_drag_icons_for_each_surface(drag_icons, data->output, &data->root_geo,
- send_frame_done_iterator, data);
+static void send_frame_done_drag_icons(struct sway_output *output,
+ struct wl_list *drag_icons, struct timespec *when) {
+ output_drag_icons_for_each_surface(output, drag_icons,
+ send_frame_done_iterator, when);
}
+struct send_frame_done_data {
+ struct sway_output *output;
+ struct timespec *when;
+};
+
static void send_frame_done_container_iterator(struct sway_container *con,
void *_data) {
struct send_frame_done_data *data = _data;
@@ -268,52 +312,62 @@ static void send_frame_done_container_iterator(struct sway_container *con,
return;
}
- output_view_for_each_surface(con->sway_view, data->output, &data->root_geo,
- send_frame_done_iterator, data);
-}
-
-static void send_frame_done_container(struct send_frame_done_data *data,
- struct sway_container *con) {
- container_descendants(con, C_VIEW,
- send_frame_done_container_iterator, data);
+ output_view_for_each_surface(data->output, con->sway_view,
+ send_frame_done_iterator, data->when);
}
-static void send_frame_done(struct sway_output *output, struct timespec *when) {
- struct sway_seat *seat = input_manager_current_seat(input_manager);
+static void send_frame_done_container(struct sway_output *output,
+ struct sway_container *con, struct timespec *when) {
struct send_frame_done_data data = {
.output = output,
.when = when,
- .exclusive_client = output_has_opaque_lockscreen(output, seat) ?
- seat->exclusive_client : NULL,
};
+ container_descendants(con, C_VIEW,
+ send_frame_done_container_iterator, &data);
+}
+
+static void send_frame_done(struct sway_output *output, struct timespec *when) {
+ if (output_has_opaque_overlay_layer_surface(output)) {
+ goto send_frame_overlay;
+ }
struct sway_container *workspace = output_get_active_workspace(output);
if (workspace->current.ws_fullscreen) {
- send_frame_done_container_iterator(
- workspace->current.ws_fullscreen->swayc, &data);
-
- if (workspace->current.ws_fullscreen->type == SWAY_VIEW_XWAYLAND) {
- send_frame_done_unmanaged(&data,
- &root_container.sway_root->xwayland_unmanaged);
+ if (workspace->current.ws_fullscreen->type == C_VIEW) {
+ output_view_for_each_surface(output,
+ workspace->current.ws_fullscreen->sway_view,
+ send_frame_done_iterator, when);
+ } else {
+ send_frame_done_container(output, workspace->current.ws_fullscreen,
+ when);
}
+#ifdef HAVE_XWAYLAND
+ send_frame_done_unmanaged(output,
+ &root_container.sway_root->xwayland_unmanaged, when);
+#endif
} else {
- send_frame_done_layer(&data,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
- send_frame_done_layer(&data,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
-
- send_frame_done_container(&data, workspace);
- send_frame_done_container(&data, workspace->sway_workspace->floating);
-
- send_frame_done_unmanaged(&data,
- &root_container.sway_root->xwayland_unmanaged);
- send_frame_done_layer(&data,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
+ send_frame_done_layer(output,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], when);
+ send_frame_done_layer(output,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], when);
+
+ send_frame_done_container(output, workspace, when);
+ send_frame_done_container(output, workspace->sway_workspace->floating,
+ when);
+
+#ifdef HAVE_XWAYLAND
+ send_frame_done_unmanaged(output,
+ &root_container.sway_root->xwayland_unmanaged, when);
+#endif
+ send_frame_done_layer(output,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], when);
}
- send_frame_done_layer(&data,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
- send_frame_done_drag_icons(&data, &root_container.sway_root->drag_icons);
+send_frame_overlay:
+ send_frame_done_layer(output,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], when);
+ send_frame_done_drag_icons(output, &root_container.sway_root->drag_icons,
+ when);
}
static void damage_handle_frame(struct wl_listener *listener, void *data) {
@@ -348,26 +402,13 @@ void output_damage_whole(struct sway_output *output) {
wlr_output_damage_add_whole(output->damage);
}
-struct damage_data {
- struct root_geometry root_geo;
- struct sway_output *output;
- bool whole;
-};
-
-static void damage_surface_iterator(struct wlr_surface *surface, int sx, int sy,
+static void damage_surface_iterator(struct sway_output *output,
+ struct wlr_surface *surface, struct wlr_box *_box, float rotation,
void *_data) {
- struct damage_data *data = _data;
- struct sway_output *output = data->output;
- float rotation = data->root_geo.rotation;
- bool whole = data->whole;
-
- struct wlr_box box;
- bool intersects = output_get_surface_box(&data->root_geo, data->output, surface,
- sx, sy, &box);
- if (!intersects) {
- return;
- }
+ bool *data = _data;
+ bool whole = *data;
+ struct wlr_box box = *_box;
scale_box(&box, output->wlr_output->scale);
int center_x = box.x + box.width/2;
@@ -407,13 +448,8 @@ static void damage_surface_iterator(struct wlr_surface *surface, int sx, int sy,
void output_damage_surface(struct sway_output *output, double ox, double oy,
struct wlr_surface *surface, bool whole) {
- struct damage_data data = {
- .output = output,
- .whole = whole,
- };
-
- output_surface_for_each_surface(surface, ox, oy, &data.root_geo,
- damage_surface_iterator, &data);
+ output_surface_for_each_surface(output, surface, ox, oy,
+ damage_surface_iterator, &whole);
}
static void output_damage_view(struct sway_output *output,
@@ -426,13 +462,7 @@ static void output_damage_view(struct sway_output *output,
return;
}
- struct damage_data data = {
- .output = output,
- .whole = whole,
- };
-
- output_view_for_each_surface(view, output, &data.root_geo,
- damage_surface_iterator, &data);
+ output_view_for_each_surface(output, view, damage_surface_iterator, &whole);
}
void output_damage_from_view(struct sway_output *output,
@@ -463,11 +493,12 @@ static void output_damage_whole_container_iterator(struct sway_container *con,
void output_damage_whole_container(struct sway_output *output,
struct sway_container *con) {
+ // Pad the box by 1px, because the width is a double and might be a fraction
struct wlr_box box = {
- .x = con->current.swayc_x - output->wlr_output->lx,
- .y = con->current.swayc_y - output->wlr_output->ly,
- .width = con->current.swayc_width,
- .height = con->current.swayc_height,
+ .x = con->current.swayc_x - output->wlr_output->lx - 1,
+ .y = con->current.swayc_y - output->wlr_output->ly - 1,
+ .width = con->current.swayc_width + 2,
+ .height = con->current.swayc_height + 2,
};
scale_box(&box, output->wlr_output->scale);
wlr_output_damage_add_box(output->damage, &box);
@@ -509,22 +540,14 @@ static void handle_transform(struct wl_listener *listener, void *data) {
transaction_commit_dirty();
}
-static void handle_scale_iterator(struct sway_container *view, void *data) {
- view_update_marks_textures(view->sway_view);
-}
-
static void handle_scale(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, scale);
arrange_layers(output);
- container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL);
+ container_update_textures_recursive(output->swayc);
arrange_windows(output->swayc);
transaction_commit_dirty();
}
-struct sway_output *output_from_wlr_output(struct wlr_output *wlr_output) {
- return wlr_output->data;
-}
-
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;
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 4c85e516..cdac9c72 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -14,6 +14,7 @@
#include <wlr/types/wlr_surface.h>
#include <wlr/util/region.h>
#include "log.h"
+#include "config.h"
#include "sway/config.h"
#include "sway/debug.h"
#include "sway/input/input-manager.h"
@@ -28,10 +29,7 @@
#include "sway/tree/workspace.h"
struct render_data {
- struct root_geometry root_geo;
- struct sway_output *output;
pixman_region32_t *damage;
- struct sway_view *view;
float alpha;
};
@@ -91,11 +89,11 @@ damage_finish:
pixman_region32_fini(&damage);
}
-static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy,
+static void render_surface_iterator(struct sway_output *output,
+ struct wlr_surface *surface, struct wlr_box *_box, float rotation,
void *_data) {
struct render_data *data = _data;
- struct wlr_output *wlr_output = data->output->wlr_output;
- float rotation = data->root_geo.rotation;
+ struct wlr_output *wlr_output = output->wlr_output;
pixman_region32_t *output_damage = data->damage;
float alpha = data->alpha;
@@ -104,13 +102,7 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy,
return;
}
- struct wlr_box box;
- bool intersects = output_get_surface_box(&data->root_geo, data->output,
- surface, sx, sy, &box);
- if (!intersects) {
- return;
- }
-
+ struct wlr_box box = *_box;
scale_box(&box, wlr_output->scale);
float matrix[9];
@@ -125,33 +117,32 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy,
static void render_layer(struct sway_output *output,
pixman_region32_t *damage, struct wl_list *layer_surfaces) {
struct render_data data = {
- .output = output,
.damage = damage,
.alpha = 1.0f,
};
- output_layer_for_each_surface(layer_surfaces, &data.root_geo,
+ output_layer_for_each_surface(output, layer_surfaces,
render_surface_iterator, &data);
}
+#ifdef HAVE_XWAYLAND
static void render_unmanaged(struct sway_output *output,
pixman_region32_t *damage, struct wl_list *unmanaged) {
struct render_data data = {
- .output = output,
.damage = damage,
.alpha = 1.0f,
};
- output_unmanaged_for_each_surface(unmanaged, output, &data.root_geo,
+ output_unmanaged_for_each_surface(output, unmanaged,
render_surface_iterator, &data);
}
+#endif
static void render_drag_icons(struct sway_output *output,
pixman_region32_t *damage, struct wl_list *drag_icons) {
struct render_data data = {
- .output = output,
.damage = damage,
.alpha = 1.0f,
};
- output_drag_icons_for_each_surface(drag_icons, output, &data.root_geo,
+ output_drag_icons_for_each_surface(output, drag_icons,
render_surface_iterator, &data);
}
@@ -195,33 +186,51 @@ static void premultiply_alpha(float color[4], float opacity) {
color[2] *= color[3];
}
-static void render_view_surfaces(struct sway_view *view,
+static void render_view_toplevels(struct sway_view *view,
struct sway_output *output, pixman_region32_t *damage, float alpha) {
struct render_data data = {
- .output = output,
.damage = damage,
- .view = view,
.alpha = alpha,
};
- output_view_for_each_surface(view, output, &data.root_geo,
- render_surface_iterator, &data);
+ // Render all toplevels without descending into popups
+ output_surface_for_each_surface(output, view->surface,
+ view->swayc->current.view_x - output->wlr_output->lx,
+ view->swayc->current.view_y - output->wlr_output->ly,
+ render_surface_iterator, &data);
+}
+
+static void render_popup_iterator(struct sway_output *output,
+ struct wlr_surface *surface, struct wlr_box *box, float rotation,
+ void *data) {
+ // Render this popup's surface
+ render_surface_iterator(output, surface, box, rotation, data);
+
+ // Render this popup's child toplevels
+ output_surface_for_each_surface(output, surface, box->x, box->y,
+ render_surface_iterator, data);
+}
+
+static void render_view_popups(struct sway_view *view,
+ struct sway_output *output, pixman_region32_t *damage, float alpha) {
+ struct render_data data = {
+ .damage = damage,
+ .alpha = alpha,
+ };
+ output_view_for_each_popup(output, view, render_popup_iterator, &data);
}
static void render_saved_view(struct sway_view *view,
struct sway_output *output, pixman_region32_t *damage, float alpha) {
struct wlr_output *wlr_output = output->wlr_output;
- int width, height;
- struct wlr_texture *texture =
- transaction_get_saved_texture(view, &width, &height);
- if (!texture) {
+ if (!view->saved_buffer || !view->saved_buffer->texture) {
return;
}
struct wlr_box box = {
.x = view->swayc->current.view_x - output->swayc->current.swayc_x,
.y = view->swayc->current.view_y - output->swayc->current.swayc_y,
- .width = width,
- .height = height,
+ .width = view->saved_buffer_width,
+ .height = view->saved_buffer_height,
};
struct wlr_box output_box = {
@@ -241,7 +250,8 @@ static void render_saved_view(struct sway_view *view,
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
wlr_output->transform_matrix);
- render_texture(wlr_output, damage, texture, &box, matrix, alpha);
+ render_texture(wlr_output, damage, view->saved_buffer->texture,
+ &box, matrix, alpha);
}
/**
@@ -250,10 +260,10 @@ static void render_saved_view(struct sway_view *view,
static void render_view(struct sway_output *output, pixman_region32_t *damage,
struct sway_container *con, struct border_colors *colors) {
struct sway_view *view = con->sway_view;
- if (view->swayc->instructions->length) {
+ if (view->saved_buffer) {
render_saved_view(view, output, damage, view->swayc->alpha);
} else {
- render_view_surfaces(view, output, damage, view->swayc->alpha);
+ render_view_toplevels(view, output, damage, view->swayc->alpha);
}
if (view->using_csd) {
@@ -778,7 +788,7 @@ static void render_floating_container(struct sway_output *soutput,
}
render_view(soutput, damage, con, colors);
} else {
- render_container(soutput, damage, con, false);
+ render_container(soutput, damage, con, con->current.focused);
}
}
@@ -835,22 +845,13 @@ void output_render(struct sway_output *output, struct timespec *when,
}
struct sway_container *workspace = output_get_active_workspace(output);
- struct sway_view *fullscreen_view = workspace->current.ws_fullscreen;
- struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *fullscreen_con = workspace->current.ws_fullscreen;
+
+ if (output_has_opaque_overlay_layer_surface(output)) {
+ goto render_overlay;
+ }
- if (output_has_opaque_lockscreen(output, seat)) {
- struct wlr_layer_surface *wlr_layer_surface = seat->focused_layer;
- struct sway_layer_surface *sway_layer_surface =
- layer_from_wlr_layer_surface(seat->focused_layer);
- struct render_data data = {
- .output = output,
- .damage = damage,
- .alpha = 1.0f,
- };
- output_surface_for_each_surface(wlr_layer_surface->surface,
- sway_layer_surface->geo.x, sway_layer_surface->geo.y,
- &data.root_geo, render_surface_iterator, &data);
- } else if (fullscreen_view) {
+ if (fullscreen_con) {
float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f};
int nrects;
@@ -861,16 +862,22 @@ void output_render(struct sway_output *output, struct timespec *when,
}
// TODO: handle views smaller than the output
- if (fullscreen_view->swayc->instructions->length) {
- render_saved_view(fullscreen_view, output, damage, 1.0f);
+ if (fullscreen_con->type == C_VIEW) {
+ if (fullscreen_con->sway_view->saved_buffer) {
+ render_saved_view(fullscreen_con->sway_view,
+ output, damage, 1.0f);
+ } else {
+ render_view_toplevels(fullscreen_con->sway_view,
+ output, damage, 1.0f);
+ }
} else {
- render_view_surfaces(fullscreen_view, output, damage, 1.0f);
- }
-
- if (fullscreen_view->type == SWAY_VIEW_XWAYLAND) {
- render_unmanaged(output, damage,
- &root_container.sway_root->xwayland_unmanaged);
+ render_container(output, damage, fullscreen_con,
+ fullscreen_con->current.focused);
}
+#ifdef HAVE_XWAYLAND
+ render_unmanaged(output, damage,
+ &root_container.sway_root->xwayland_unmanaged);
+#endif
} else {
float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f};
@@ -888,12 +895,21 @@ void output_render(struct sway_output *output, struct timespec *when,
render_container(output, damage, workspace, workspace->current.focused);
render_floating(output, damage);
-
+#ifdef HAVE_XWAYLAND
render_unmanaged(output, damage,
&root_container.sway_root->xwayland_unmanaged);
+#endif
render_layer(output, damage,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
}
+
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *focus = seat_get_focus(seat);
+ if (focus && focus->type == C_VIEW) {
+ render_view_popups(focus->sway_view, output, damage, focus->alpha);
+ }
+
+render_overlay:
render_layer(output, damage,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
render_drag_icons(output, damage, &root_container.sway_root->drag_icons);
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index 19f41efc..4e6af86a 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200809L
+#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -40,8 +41,6 @@ struct sway_transaction_instruction {
struct sway_transaction *transaction;
struct sway_container *container;
struct sway_container_state state;
- struct wlr_buffer *saved_buffer;
- int saved_buffer_width, saved_buffer_height;
uint32_t serial;
bool ready;
};
@@ -56,27 +55,6 @@ static struct sway_transaction *transaction_create() {
return transaction;
}
-static void remove_saved_view_buffer(
- struct sway_transaction_instruction *instruction) {
- if (instruction->saved_buffer) {
- wlr_buffer_unref(instruction->saved_buffer);
- instruction->saved_buffer = NULL;
- }
-}
-
-static void save_view_buffer(struct sway_view *view,
- struct sway_transaction_instruction *instruction) {
- if (!sway_assert(instruction->saved_buffer == NULL,
- "Didn't expect instruction to have a saved buffer already")) {
- remove_saved_view_buffer(instruction);
- }
- if (view->surface && wlr_surface_has_buffer(view->surface)) {
- instruction->saved_buffer = wlr_buffer_ref(view->surface->buffer);
- instruction->saved_buffer_width = view->surface->current.width;
- instruction->saved_buffer_height = view->surface->current.height;
- }
-}
-
static void transaction_destroy(struct sway_transaction *transaction) {
// Free instructions
for (int i = 0; i < transaction->instructions->length; ++i) {
@@ -92,7 +70,6 @@ static void transaction_destroy(struct sway_transaction *transaction) {
if (con->destroying && !con->instructions->length) {
container_free(con);
}
- remove_saved_view_buffer(instruction);
free(instruction);
}
list_free(transaction->instructions);
@@ -110,6 +87,7 @@ static void copy_pending_state(struct sway_container *container,
state->swayc_y = container->y;
state->swayc_width = container->width;
state->swayc_height = container->height;
+ state->is_fullscreen = container->is_fullscreen;
state->has_gaps = container->has_gaps;
state->current_gaps = container->current_gaps;
state->gaps_inner = container->gaps_inner;
@@ -122,7 +100,6 @@ static void copy_pending_state(struct sway_container *container,
state->view_y = view->y;
state->view_width = view->width;
state->view_height = view->height;
- state->is_fullscreen = view->is_fullscreen;
state->border = view->border;
state->border_thickness = view->border_thickness;
state->border_top = view->border_top;
@@ -157,9 +134,6 @@ static void transaction_add_container(struct sway_transaction *transaction,
copy_pending_state(container, &instruction->state);
- if (container->type == C_VIEW) {
- save_view_buffer(container->sway_view, instruction);
- }
list_add(transaction->instructions, instruction);
}
@@ -219,27 +193,35 @@ static void transaction_apply(struct sway_transaction *transaction) {
memcpy(&container->current, &instruction->state,
sizeof(struct sway_container_state));
+
+ if (container->type == C_VIEW) {
+ if (container->destroying) {
+ if (container->instructions->length == 1 &&
+ container->sway_view->saved_buffer) {
+ view_remove_saved_buffer(container->sway_view);
+ }
+ } else {
+ if (container->sway_view->saved_buffer) {
+ view_remove_saved_buffer(container->sway_view);
+ }
+ if (container->instructions->length > 1) {
+ view_save_buffer(container->sway_view);
+ }
+ }
+ }
}
}
-/**
- * For simplicity, we only progress the queue if it can be completely flushed.
- */
static void transaction_progress_queue() {
- // We iterate this list in reverse because we're more likely to find a
- // waiting transactions at the end of the list.
- for (int i = server.transactions->length - 1; i >= 0; --i) {
- struct sway_transaction *transaction = server.transactions->items[i];
+ while (server.transactions->length) {
+ struct sway_transaction *transaction = server.transactions->items[0];
if (transaction->num_waiting) {
return;
}
- }
- for (int i = 0; i < server.transactions->length; ++i) {
- struct sway_transaction *transaction = server.transactions->items[i];
transaction_apply(transaction);
transaction_destroy(transaction);
+ list_del(server.transactions, 0);
}
- server.transactions->length = 0;
idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
}
@@ -302,6 +284,9 @@ static void transaction_commit(struct sway_transaction *transaction) {
struct timespec when;
wlr_surface_send_frame_done(con->sway_view->surface, &when);
}
+ if (con->type == C_VIEW && !con->sway_view->saved_buffer) {
+ view_save_buffer(con->sway_view);
+ }
list_add(con->instructions, instruction);
}
transaction->num_configures = transaction->num_waiting;
@@ -324,7 +309,14 @@ static void transaction_commit(struct sway_transaction *transaction) {
// Set up a timer which the views must respond within
transaction->timer = wl_event_loop_add_timer(server.wl_event_loop,
handle_timeout, transaction);
- wl_event_source_timer_update(transaction->timer, txn_timeout_ms);
+ if (transaction->timer) {
+ wl_event_source_timer_update(transaction->timer, txn_timeout_ms);
+ } else {
+ wlr_log(WLR_ERROR, "Unable to create transaction timer (%s). "
+ "Some imperfect frames might be rendered.",
+ strerror(errno));
+ handle_timeout(transaction);
+ }
}
// The debug tree shows the pending/live tree. Here is a good place to
@@ -352,13 +344,11 @@ static void set_instruction_ready(
}
- // If all views are ready, apply the transaction.
// If the transaction has timed out then its num_waiting will be 0 already.
if (transaction->num_waiting > 0 && --transaction->num_waiting == 0) {
if (!txn_debug) {
wlr_log(WLR_DEBUG, "Transaction %p is ready", transaction);
wl_event_source_timer_update(transaction->timer, 0);
- transaction_progress_queue();
}
}
}
@@ -375,6 +365,7 @@ static void set_instructions_ready(struct sway_view *view, int index) {
set_instruction_ready(instruction);
}
}
+ transaction_progress_queue();
}
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) {
@@ -401,18 +392,6 @@ void transaction_notify_view_ready_by_size(struct sway_view *view,
}
}
-struct wlr_texture *transaction_get_saved_texture(struct sway_view *view,
- int *width, int *height) {
- struct sway_transaction_instruction *instruction =
- view->swayc->instructions->items[0];
- if (!instruction->saved_buffer) {
- return NULL;
- }
- *width = instruction->saved_buffer_width;
- *height = instruction->saved_buffer_height;
- return instruction->saved_buffer->texture;
-}
-
void transaction_commit_dirty(void) {
if (!server.dirty_containers->length) {
return;
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 98c16faf..b364663d 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 199309L
+#include <float.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server.h>
@@ -95,6 +96,16 @@ static struct sway_xdg_shell_view *xdg_shell_view_from_view(
return (struct sway_xdg_shell_view *)view;
}
+static void get_constraints(struct sway_view *view, double *min_width,
+ double *max_width, double *min_height, double *max_height) {
+ struct wlr_xdg_toplevel_state *state =
+ &view->wlr_xdg_surface->toplevel->current;
+ *min_width = state->min_width > 0 ? state->min_width : DBL_MIN;
+ *max_width = state->max_width > 0 ? state->max_width : DBL_MAX;
+ *min_height = state->min_height > 0 ? state->min_height : DBL_MIN;
+ *max_height = state->max_height > 0 ? state->max_height : DBL_MAX;
+}
+
static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) {
if (xdg_shell_view_from_view(view) == NULL) {
return NULL;
@@ -168,6 +179,14 @@ static void for_each_surface(struct sway_view *view,
user_data);
}
+static void for_each_popup(struct sway_view *view,
+ wlr_surface_iterator_func_t iterator, void *user_data) {
+ if (xdg_shell_view_from_view(view) == NULL) {
+ return;
+ }
+ wlr_xdg_surface_for_each_popup(view->wlr_xdg_surface, iterator, user_data);
+}
+
static void _close(struct sway_view *view) {
if (xdg_shell_view_from_view(view) == NULL) {
return;
@@ -178,6 +197,18 @@ static void _close(struct sway_view *view) {
}
}
+static void close_popups_iterator(struct wlr_surface *surface,
+ int sx, int sy, void *data) {
+ struct wlr_xdg_surface *xdg_surface =
+ wlr_xdg_surface_from_wlr_surface(surface);
+ wlr_xdg_surface_send_close(xdg_surface);
+}
+
+static void close_popups(struct sway_view *view) {
+ wlr_xdg_surface_for_each_popup(view->wlr_xdg_surface,
+ close_popups_iterator, NULL);
+}
+
static void destroy(struct sway_view *view) {
struct sway_xdg_shell_view *xdg_shell_view =
xdg_shell_view_from_view(view);
@@ -188,6 +219,7 @@ static void destroy(struct sway_view *view) {
}
static const struct sway_view_impl view_impl = {
+ .get_constraints = get_constraints,
.get_string_prop = get_string_prop,
.configure = configure,
.set_activated = set_activated,
@@ -195,7 +227,9 @@ static const struct sway_view_impl view_impl = {
.set_fullscreen = set_fullscreen,
.wants_floating = wants_floating,
.for_each_surface = for_each_surface,
+ .for_each_popup = for_each_popup,
.close = _close,
+ .close_popups = close_popups,
.destroy = destroy,
};
@@ -213,10 +247,24 @@ static void handle_commit(struct wl_listener *listener, void *data) {
transaction_notify_view_ready(view, xdg_surface->configure_serial);
}
- view_update_title(view, false);
view_damage_from(view);
}
+static void handle_set_title(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_view *xdg_shell_view =
+ wl_container_of(listener, xdg_shell_view, set_title);
+ struct sway_view *view = &xdg_shell_view->view;
+ view_update_title(view, false);
+ view_execute_criteria(view);
+}
+
+static void handle_set_app_id(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_view *xdg_shell_view =
+ wl_container_of(listener, xdg_shell_view, set_app_id);
+ struct sway_view *view = &xdg_shell_view->view;
+ view_execute_criteria(view);
+}
+
static void handle_new_popup(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view =
wl_container_of(listener, xdg_shell_view, new_popup);
@@ -241,13 +289,41 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return;
}
- view_set_fullscreen(view, e->fullscreen);
+ container_set_fullscreen(view->swayc, e->fullscreen);
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
arrange_windows(output);
transaction_commit_dirty();
}
+static void handle_request_move(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_view *xdg_shell_view =
+ wl_container_of(listener, xdg_shell_view, request_move);
+ struct sway_view *view = &xdg_shell_view->view;
+ if (!container_is_floating(view->swayc)) {
+ return;
+ }
+ struct wlr_xdg_toplevel_move_event *e = data;
+ struct sway_seat *seat = e->seat->seat->data;
+ if (e->serial == seat->last_button_serial) {
+ seat_begin_move(seat, view->swayc, seat->last_button);
+ }
+}
+
+static void handle_request_resize(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_view *xdg_shell_view =
+ wl_container_of(listener, xdg_shell_view, request_resize);
+ struct sway_view *view = &xdg_shell_view->view;
+ if (!container_is_floating(view->swayc)) {
+ return;
+ }
+ struct wlr_xdg_toplevel_resize_event *e = data;
+ struct sway_seat *seat = e->seat->seat->data;
+ if (e->serial == seat->last_button_serial) {
+ seat_begin_resize(seat, view->swayc, seat->last_button, e->edges);
+ }
+}
+
static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view =
wl_container_of(listener, xdg_shell_view, unmap);
@@ -262,6 +338,10 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
wl_list_remove(&xdg_shell_view->commit.link);
wl_list_remove(&xdg_shell_view->new_popup.link);
wl_list_remove(&xdg_shell_view->request_fullscreen.link);
+ wl_list_remove(&xdg_shell_view->request_move.link);
+ wl_list_remove(&xdg_shell_view->request_resize.link);
+ wl_list_remove(&xdg_shell_view->set_title.link);
+ wl_list_remove(&xdg_shell_view->set_app_id.link);
}
static void handle_map(struct wl_listener *listener, void *data) {
@@ -280,7 +360,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
view_map(view, view->wlr_xdg_surface->surface);
if (xdg_surface->toplevel->client_pending.fullscreen) {
- view_set_fullscreen(view, true);
+ container_set_fullscreen(view->swayc, true);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_windows(ws);
} else {
@@ -299,6 +379,22 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_view->request_fullscreen.notify = handle_request_fullscreen;
wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen,
&xdg_shell_view->request_fullscreen);
+
+ xdg_shell_view->request_move.notify = handle_request_move;
+ wl_signal_add(&xdg_surface->toplevel->events.request_move,
+ &xdg_shell_view->request_move);
+
+ xdg_shell_view->request_resize.notify = handle_request_resize;
+ wl_signal_add(&xdg_surface->toplevel->events.request_resize,
+ &xdg_shell_view->request_resize);
+
+ xdg_shell_view->set_title.notify = handle_set_title;
+ wl_signal_add(&xdg_surface->toplevel->events.set_title,
+ &xdg_shell_view->set_title);
+
+ xdg_shell_view->set_app_id.notify = handle_set_app_id;
+ wl_signal_add(&xdg_surface->toplevel->events.set_app_id,
+ &xdg_shell_view->set_app_id);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -344,9 +440,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl);
xdg_shell_view->view.wlr_xdg_surface = xdg_surface;
- // TODO:
- // - Look up pid and open on appropriate workspace
-
xdg_shell_view->map.notify = handle_map;
wl_signal_add(&xdg_surface->events.map, &xdg_shell_view->map);
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 4d76f0a7..ffea03ad 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 199309L
+#include <float.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server.h>
@@ -94,6 +95,16 @@ static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view(
return (struct sway_xdg_shell_v6_view *)view;
}
+static void get_constraints(struct sway_view *view, double *min_width,
+ double *max_width, double *min_height, double *max_height) {
+ struct wlr_xdg_toplevel_v6_state *state =
+ &view->wlr_xdg_surface_v6->toplevel->current;
+ *min_width = state->min_width > 0 ? state->min_width : DBL_MIN;
+ *max_width = state->max_width > 0 ? state->max_width : DBL_MAX;
+ *min_height = state->min_height > 0 ? state->min_height : DBL_MIN;
+ *max_height = state->max_height > 0 ? state->max_height : DBL_MAX;
+}
+
static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) {
if (xdg_shell_v6_view_from_view(view) == NULL) {
return NULL;
@@ -164,6 +175,15 @@ static void for_each_surface(struct sway_view *view,
user_data);
}
+static void for_each_popup(struct sway_view *view,
+ wlr_surface_iterator_func_t iterator, void *user_data) {
+ if (xdg_shell_v6_view_from_view(view) == NULL) {
+ return;
+ }
+ wlr_xdg_surface_v6_for_each_popup(view->wlr_xdg_surface_v6, iterator,
+ user_data);
+}
+
static void _close(struct sway_view *view) {
if (xdg_shell_v6_view_from_view(view) == NULL) {
return;
@@ -174,6 +194,18 @@ static void _close(struct sway_view *view) {
}
}
+static void close_popups_iterator(struct wlr_surface *surface,
+ int sx, int sy, void *data) {
+ struct wlr_xdg_surface_v6 *xdg_surface_v6 =
+ wlr_xdg_surface_v6_from_wlr_surface(surface);
+ wlr_xdg_surface_v6_send_close(xdg_surface_v6);
+}
+
+static void close_popups(struct sway_view *view) {
+ wlr_xdg_surface_v6_for_each_popup(view->wlr_xdg_surface_v6,
+ close_popups_iterator, NULL);
+}
+
static void destroy(struct sway_view *view) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
xdg_shell_v6_view_from_view(view);
@@ -184,6 +216,7 @@ static void destroy(struct sway_view *view) {
}
static const struct sway_view_impl view_impl = {
+ .get_constraints = get_constraints,
.get_string_prop = get_string_prop,
.configure = configure,
.set_activated = set_activated,
@@ -191,7 +224,9 @@ static const struct sway_view_impl view_impl = {
.set_fullscreen = set_fullscreen,
.wants_floating = wants_floating,
.for_each_surface = for_each_surface,
+ .for_each_popup = for_each_popup,
.close = _close,
+ .close_popups = close_popups,
.destroy = destroy,
};
@@ -208,10 +243,24 @@ static void handle_commit(struct wl_listener *listener, void *data) {
transaction_notify_view_ready(view, xdg_surface_v6->configure_serial);
}
- view_update_title(view, false);
view_damage_from(view);
}
+static void handle_set_title(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
+ wl_container_of(listener, xdg_shell_v6_view, set_title);
+ struct sway_view *view = &xdg_shell_v6_view->view;
+ view_update_title(view, false);
+ view_execute_criteria(view);
+}
+
+static void handle_set_app_id(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
+ wl_container_of(listener, xdg_shell_v6_view, set_app_id);
+ struct sway_view *view = &xdg_shell_v6_view->view;
+ view_execute_criteria(view);
+}
+
static void handle_new_popup(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, new_popup);
@@ -236,13 +285,41 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return;
}
- view_set_fullscreen(view, e->fullscreen);
+ container_set_fullscreen(view->swayc, e->fullscreen);
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
arrange_windows(output);
transaction_commit_dirty();
}
+static void handle_request_move(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
+ wl_container_of(listener, xdg_shell_v6_view, request_move);
+ struct sway_view *view = &xdg_shell_v6_view->view;
+ if (!container_is_floating(view->swayc)) {
+ return;
+ }
+ struct wlr_xdg_toplevel_v6_move_event *e = data;
+ struct sway_seat *seat = e->seat->seat->data;
+ if (e->serial == seat->last_button_serial) {
+ seat_begin_move(seat, view->swayc, seat->last_button);
+ }
+}
+
+static void handle_request_resize(struct wl_listener *listener, void *data) {
+ struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
+ wl_container_of(listener, xdg_shell_v6_view, request_resize);
+ struct sway_view *view = &xdg_shell_v6_view->view;
+ if (!container_is_floating(view->swayc)) {
+ return;
+ }
+ struct wlr_xdg_toplevel_v6_resize_event *e = data;
+ struct sway_seat *seat = e->seat->seat->data;
+ if (e->serial == seat->last_button_serial) {
+ seat_begin_resize(seat, view->swayc, seat->last_button, e->edges);
+ }
+}
+
static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, unmap);
@@ -257,6 +334,10 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
wl_list_remove(&xdg_shell_v6_view->commit.link);
wl_list_remove(&xdg_shell_v6_view->new_popup.link);
wl_list_remove(&xdg_shell_v6_view->request_fullscreen.link);
+ wl_list_remove(&xdg_shell_v6_view->request_move.link);
+ wl_list_remove(&xdg_shell_v6_view->request_resize.link);
+ wl_list_remove(&xdg_shell_v6_view->set_title.link);
+ wl_list_remove(&xdg_shell_v6_view->set_app_id.link);
}
static void handle_map(struct wl_listener *listener, void *data) {
@@ -275,7 +356,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
view_map(view, view->wlr_xdg_surface_v6->surface);
if (xdg_surface->toplevel->client_pending.fullscreen) {
- view_set_fullscreen(view, true);
+ container_set_fullscreen(view->swayc, true);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_windows(ws);
} else {
@@ -294,6 +375,22 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_v6_view->request_fullscreen.notify = handle_request_fullscreen;
wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen,
&xdg_shell_v6_view->request_fullscreen);
+
+ xdg_shell_v6_view->request_move.notify = handle_request_move;
+ wl_signal_add(&xdg_surface->toplevel->events.request_move,
+ &xdg_shell_v6_view->request_move);
+
+ xdg_shell_v6_view->request_resize.notify = handle_request_resize;
+ wl_signal_add(&xdg_surface->toplevel->events.request_resize,
+ &xdg_shell_v6_view->request_resize);
+
+ xdg_shell_v6_view->set_title.notify = handle_set_title;
+ wl_signal_add(&xdg_surface->toplevel->events.set_title,
+ &xdg_shell_v6_view->set_title);
+
+ xdg_shell_v6_view->set_app_id.notify = handle_set_app_id;
+ wl_signal_add(&xdg_surface->toplevel->events.set_app_id,
+ &xdg_shell_v6_view->set_app_id);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -335,9 +432,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view_init(&xdg_shell_v6_view->view, SWAY_VIEW_XDG_SHELL_V6, &view_impl);
xdg_shell_v6_view->view.wlr_xdg_surface_v6 = xdg_surface;
- // TODO:
- // - Look up pid and open on appropriate workspace
-
xdg_shell_v6_view->map.notify = handle_map;
wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map);
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index bce0a37b..398446f8 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -69,11 +69,13 @@ static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
surface->ly = xsurface->y;
desktop_damage_surface(xsurface->surface, surface->lx, surface->ly, true);
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct wlr_xwayland *xwayland =
- seat->input->server->xwayland.wlr_xwayland;
- wlr_xwayland_set_seat(xwayland, seat->wlr_seat);
- seat_set_focus_surface(seat, xsurface->surface, false);
+ if (wlr_xwayland_or_surface_wants_focus(xsurface)) {
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct wlr_xwayland *xwayland =
+ seat->input->server->xwayland.wlr_xwayland;
+ wlr_xwayland_set_seat(xwayland, seat->wlr_seat);
+ seat_set_focus_surface(seat, xsurface->surface, false);
+ }
}
static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) {
@@ -305,6 +307,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&xwayland_view->destroy.link);
wl_list_remove(&xwayland_view->request_configure.link);
wl_list_remove(&xwayland_view->request_fullscreen.link);
+ wl_list_remove(&xwayland_view->request_move.link);
+ wl_list_remove(&xwayland_view->request_resize.link);
wl_list_remove(&xwayland_view->set_title.link);
wl_list_remove(&xwayland_view->set_class.link);
wl_list_remove(&xwayland_view->set_window_type.link);
@@ -355,7 +359,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
view_map(view, xsurface->surface);
if (xsurface->fullscreen) {
- view_set_fullscreen(view, true);
+ container_set_fullscreen(view->swayc, true);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_windows(ws);
} else {
@@ -393,13 +397,44 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
if (!xsurface->mapped) {
return;
}
- view_set_fullscreen(view, xsurface->fullscreen);
+ container_set_fullscreen(view->swayc, xsurface->fullscreen);
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
arrange_windows(output);
transaction_commit_dirty();
}
+static void handle_request_move(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_view *xwayland_view =
+ wl_container_of(listener, xwayland_view, request_move);
+ struct sway_view *view = &xwayland_view->view;
+ struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
+ if (!xsurface->mapped) {
+ return;
+ }
+ if (!container_is_floating(view->swayc)) {
+ return;
+ }
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ seat_begin_move(seat, view->swayc, seat->last_button);
+}
+
+static void handle_request_resize(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_view *xwayland_view =
+ wl_container_of(listener, xwayland_view, request_resize);
+ struct sway_view *view = &xwayland_view->view;
+ struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
+ if (!xsurface->mapped) {
+ return;
+ }
+ if (!container_is_floating(view->swayc)) {
+ return;
+ }
+ struct wlr_xwayland_resize_event *e = data;
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ seat_begin_resize(seat, view->swayc, seat->last_button, e->edges);
+}
+
static void handle_set_title(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, set_title);
@@ -481,9 +516,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view_init(&xwayland_view->view, SWAY_VIEW_XWAYLAND, &view_impl);
xwayland_view->view.wlr_xwayland_surface = xsurface;
- // TODO:
- // - Look up pid and open on appropriate workspace
-
wl_signal_add(&xsurface->events.destroy, &xwayland_view->destroy);
xwayland_view->destroy.notify = handle_destroy;
@@ -495,6 +527,14 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
&xwayland_view->request_fullscreen);
xwayland_view->request_fullscreen.notify = handle_request_fullscreen;
+ wl_signal_add(&xsurface->events.request_move,
+ &xwayland_view->request_move);
+ xwayland_view->request_move.notify = handle_request_move;
+
+ wl_signal_add(&xsurface->events.request_resize,
+ &xwayland_view->request_resize);
+ xwayland_view->request_resize.notify = handle_request_resize;
+
wl_signal_add(&xsurface->events.set_title, &xwayland_view->set_title);
xwayland_view->set_title.notify = handle_set_title;