Skip to content

Instantly share code, notes, and snippets.

@ForgottenUmbrella
Created June 13, 2022 10:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ForgottenUmbrella/eb3df8d3a5cf470f63bccde929cfbb93 to your computer and use it in GitHub Desktop.
Save ForgottenUmbrella/eb3df8d3a5cf470f63bccde929cfbb93 to your computer and use it in GitHub Desktop.
Revised sway patch to render transparent fullscreen containers
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 68f095c0..cc884b76 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -287,51 +287,26 @@ static void output_for_each_surface(struct sway_output *output,
};
struct sway_workspace *workspace = output_get_active_workspace(output);
- struct sway_container *fullscreen_con = root->fullscreen_global;
- if (!fullscreen_con) {
- if (!workspace) {
- return;
- }
- fullscreen_con = workspace->current.fullscreen;
- }
- if (fullscreen_con) {
- for_each_surface_container_iterator(fullscreen_con, &data);
- container_for_each_child(fullscreen_con,
- for_each_surface_container_iterator, &data);
- // TODO: Show transient containers for fullscreen global
- if (fullscreen_con == workspace->current.fullscreen) {
- for (int i = 0; i < workspace->current.floating->length; ++i) {
- struct sway_container *floater =
- workspace->current.floating->items[i];
- if (container_is_transient_for(floater, fullscreen_con)) {
- for_each_surface_container_iterator(floater, &data);
- }
- }
- }
-#if HAVE_XWAYLAND
- output_unmanaged_for_each_surface(output, &root->xwayland_unmanaged,
- iterator, user_data);
-#endif
- } else {
- output_layer_for_each_surface(output,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
- iterator, user_data);
- output_layer_for_each_surface(output,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM],
- iterator, user_data);
+ output_layer_for_each_surface(output,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
+ iterator, user_data);
+ output_layer_for_each_surface(output,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM],
+ iterator, user_data);
+ if (workspace) {
workspace_for_each_container(workspace,
for_each_surface_container_iterator, &data);
+ }
#if HAVE_XWAYLAND
- output_unmanaged_for_each_surface(output, &root->xwayland_unmanaged,
- iterator, user_data);
+ output_unmanaged_for_each_surface(output, &root->xwayland_unmanaged,
+ iterator, user_data);
#endif
- output_layer_for_each_surface(output,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
- iterator, user_data);
- }
+ output_layer_for_each_surface(output,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
+ iterator, user_data);
overlay:
output_layer_for_each_surface(output,
@@ -508,7 +483,8 @@ static int output_repaint_timer_handler(void *data) {
fullscreen_con = workspace->current.fullscreen;
}
- if (fullscreen_con && fullscreen_con->view && !debug.noscanout) {
+ // TODO: Make scan-out conditionally dependent on config.
+ if (false && fullscreen_con && fullscreen_con->view && !debug.noscanout) {
// Try to scan-out the fullscreen view
static bool last_scanned_out = false;
bool scanned_out =
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 749ad580..3503920b 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -34,6 +34,8 @@ struct render_data {
struct wlr_box *clip_box;
};
+static struct sway_container *fullscreen_con;
+
/**
* Apply scale to a width or height.
*
@@ -928,6 +930,10 @@ static void render_containers_linear(struct sway_output *output,
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
+ if (child == fullscreen_con) {
+ continue;
+ }
+
if (child->view) {
struct sway_view *view = child->view;
struct border_colors *colors;
@@ -1146,6 +1152,9 @@ static void render_container(struct sway_output *output,
.focused = focused,
.active_child = con->current.focused_inactive_child,
};
+ if (con == fullscreen_con) {
+ return;
+ }
render_containers(output, damage, &data);
}
@@ -1242,7 +1251,7 @@ void output_render(struct sway_output *output, struct timespec *when,
return;
}
- struct sway_container *fullscreen_con = root->fullscreen_global;
+ fullscreen_con = root->fullscreen_global;
if (!fullscreen_con) {
fullscreen_con = workspace->current.fullscreen;
}
@@ -1268,68 +1277,54 @@ void output_render(struct sway_output *output, struct timespec *when,
goto render_overlay;
}
- if (fullscreen_con) {
- float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f};
+ float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f};
- int nrects;
- pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects);
- for (int i = 0; i < nrects; ++i) {
- scissor_output(wlr_output, &rects[i]);
- wlr_renderer_clear(renderer, clear_color);
- }
+ int nrects;
+ pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects);
+ for (int i = 0; i < nrects; ++i) {
+ scissor_output(wlr_output, &rects[i]);
+ wlr_renderer_clear(renderer, clear_color);
+ }
- if (fullscreen_con->view) {
- if (!wl_list_empty(&fullscreen_con->view->saved_buffers)) {
- render_saved_view(fullscreen_con->view, output, damage, 1.0f);
- } else if (fullscreen_con->view->surface) {
- render_view_toplevels(fullscreen_con->view,
- output, damage, 1.0f);
+ render_layer_toplevel(output, damage,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
+ render_layer_toplevel(output, damage,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
+
+ render_workspace(output, damage, workspace, workspace->current.focused);
+
+ struct sway_container *fs_con = fullscreen_con;
+ fullscreen_con = NULL;
+ if (fs_con) {
+ if (fs_con->view) {
+ if (wl_list_length(&fs_con->view->saved_buffers)) {
+ render_saved_view(fs_con->view, output, damage,
+ fs_con->alpha);
+ } else if (fs_con->view->surface) {
+ render_view_toplevels(fs_con->view,
+ output, damage,
+ fs_con->alpha);
}
} else {
- render_container(output, damage, fullscreen_con,
- fullscreen_con->current.focused);
- }
-
- for (int i = 0; i < workspace->current.floating->length; ++i) {
- struct sway_container *floater =
- workspace->current.floating->items[i];
- if (container_is_transient_for(floater, fullscreen_con)) {
- render_floating_container(output, damage, floater);
- }
- }
-#if HAVE_XWAYLAND
- render_unmanaged(output, damage, &root->xwayland_unmanaged);
-#endif
- } else {
- float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f};
-
- int nrects;
- pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects);
- for (int i = 0; i < nrects; ++i) {
- scissor_output(wlr_output, &rects[i]);
- wlr_renderer_clear(renderer, clear_color);
+ render_container(output, damage, fs_con,
+ fs_con->current.focused);
}
+ }
- render_layer_toplevel(output, damage,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
- render_layer_toplevel(output, damage,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
+ render_floating(output, damage);
- render_workspace(output, damage, workspace, workspace->current.focused);
- render_floating(output, damage);
#if HAVE_XWAYLAND
- render_unmanaged(output, damage, &root->xwayland_unmanaged);
+ render_unmanaged(output, damage, &root->xwayland_unmanaged);
#endif
- render_layer_toplevel(output, damage,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
-
- render_layer_popups(output, damage,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
- render_layer_popups(output, damage,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
- render_layer_popups(output, damage,
- &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
- }
+ render_layer_toplevel(output, damage,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
+
+ render_layer_popups(output, damage,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
+ render_layer_popups(output, damage,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
+ render_layer_popups(output, damage,
+ &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
render_seatops(output, damage);
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 1318f5fb..65685239 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -1344,13 +1344,6 @@ bool view_is_visible(struct sway_view *view) {
}
con = con->pending.parent;
}
- // Check view isn't hidden by another fullscreen view
- struct sway_container *fs = root->fullscreen_global ?
- root->fullscreen_global : workspace->fullscreen;
- if (fs && !container_is_fullscreen_or_child(view->container) &&
- !container_is_transient_for(view->container, fs)) {
- return false;
- }
return true;
}
@ForgottenUmbrella
Copy link
Author

ForgottenUmbrella commented Jun 13, 2022

Based on the original patch with fixes made via educated guess. Use at your own risk.

Known bug: floating windows appear in front of fullscreen windows. Fixing this would require reordering one of the lines (which? I can't remember), but I don't have time for that.

Also be advised that performance of fullscreen windows may suffer due to using this patch, and that you open yourself up to potential security issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment