From 00e9a941523baa4afa1f9c077235aa7aa5e8aeab Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Wed, 25 Sep 2024 06:35:30 -0500 Subject: [PATCH 1/5] swaybar: Fix 100% cpu usage if dbus dies. Currently, swaybar does not gracefully die if it detects that the dbus connection was lost. Although it's not recommended to restart dbus without restarting the compositor, it can very easily happen. In the case it does, compositor's tray should not consume 100% cpu until it has to be force killed. apply suggestions just setting the bar to not running will call teardown and unref the dbus. --- swaybar/bar.c | 2 +- swaybar/ipc.c | 3 +-- swaybar/tray/tray.c | 12 ++++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/swaybar/bar.c b/swaybar/bar.c index 5b1213a8dd..4d20f20f0a 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -508,7 +508,7 @@ void bar_run(struct swaybar *bar) { } #if HAVE_TRAY if (bar->tray) { - loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar->tray->bus); + loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar); } #endif while (bar->running) { diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 03500bdf3c..71c9a4c5ee 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -518,8 +518,7 @@ static bool handle_barconfig_update(struct swaybar *bar, const char *payload, #if HAVE_TRAY if (oldcfg->tray_hidden && !newcfg->tray_hidden) { bar->tray = create_tray(bar); - loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, - bar->tray->bus); + loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar); } else if (bar->tray && newcfg->tray_hidden) { loop_remove_fd(bar->eventloop, bar->tray->fd); destroy_tray(bar->tray); diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index b0545f4a70..a4f382bfbb 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -90,9 +91,16 @@ void destroy_tray(struct swaybar_tray *tray) { } void tray_in(int fd, short mask, void *data) { - sd_bus *bus = data; + struct swaybar *bar = data; int ret; - while ((ret = sd_bus_process(bus, NULL)) > 0) { + + if (mask & (POLLHUP | POLLERR)) { + sway_log(SWAY_ERROR, "D-Bus connection closed unexpectedly"); + bar->running = false; + return; + } + + while ((ret = sd_bus_process(bar->tray->bus, NULL)) > 0) { // This space intentionally left blank } if (ret < 0) { From a0b3606f1725ee56e8dc15ae51ce62d042c0668a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 29 Sep 2024 16:57:52 +0200 Subject: [PATCH 2/5] Add support for alpha-modifier-v1 --- sway/server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sway/server.c b/sway/server.c index 30896baf67..f16a55e207 100644 --- a/sway/server.c +++ b/sway/server.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -326,6 +327,7 @@ bool server_init(struct sway_server *server) { &server->pointer_constraint); wlr_presentation_create(server->wl_display, server->backend); + wlr_alpha_modifier_v1_create(server->wl_display); server->output_manager_v1 = wlr_output_manager_v1_create(server->wl_display); From a2757e5f165eae445ae550fd1d13f9ec0db44efc Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 29 Sep 2024 17:38:27 +0200 Subject: [PATCH 3/5] release: push tags before creating GitHub release Otherwise the GitHub release isn't attached to the Git tag. --- release.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/release.sh b/release.sh index 62baf4153b..c5644cfd05 100755 --- a/release.sh +++ b/release.sh @@ -28,4 +28,5 @@ archive=$prefix.tar.gz git archive --prefix="$prefix/" -o "$archive" "$next" gpg --output "$archive".sig --detach-sig "$archive" +git push --follow-tags gh release create "sway $next" -t "$next" -n "" -d "$archive" "$archive.sig" From 9a9be01ad4130e4e19b437fd064f90982974971f Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Sun, 29 Sep 2024 16:50:00 -0400 Subject: [PATCH 4/5] Fix alpha-modifier-v1 --- sway/desktop/output.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 1f1f8d682b..a4eaa4b334 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -216,6 +217,15 @@ static void output_configure_scene(struct sway_output *output, if (node->type == WLR_SCENE_NODE_BUFFER) { struct wlr_scene_buffer *buffer = wlr_scene_buffer_from_node(node); + struct wlr_scene_surface *surface = wlr_scene_surface_try_from_buffer(buffer); + + if (surface) { + const struct wlr_alpha_modifier_surface_v1_state *alpha_modifier_state = + wlr_alpha_modifier_v1_get_surface_state(surface->surface); + if (alpha_modifier_state != NULL) { + opacity *= (float)alpha_modifier_state->multiplier; + } + } // hack: don't call the scene setter because that will damage all outputs // We don't want to damage outputs that aren't our current output that From c90cb37b2a0861548461daa9b75d75317e01b679 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 2 Oct 2024 15:55:17 +0200 Subject: [PATCH 5/5] Re-init renderer for all outputs on lost context sway_root.outputs only include enabled outputs. We also need to re-init the renderer for any disabled outputs, so use sway_root.all_outputs instead. Resolves the following heap-use-after-free accessing the render formats when a disabled output is modeset after a GPU reset has occurred. --- sway/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/server.c b/sway/server.c index f16a55e207..941f4cb269 100644 --- a/sway/server.c +++ b/sway/server.c @@ -205,8 +205,8 @@ static void handle_renderer_lost(struct wl_listener *listener, void *data) { wlr_compositor_set_renderer(server->compositor, renderer); - for (int i = 0; i < root->outputs->length; ++i) { - struct sway_output *output = root->outputs->items[i]; + struct sway_output *output; + wl_list_for_each(output, &root->all_outputs, link) { wlr_output_init_render(output->wlr_output, server->allocator, server->renderer); }