From 13b4a13ae3f4e2384fdc227618fbca4806a111a9 Mon Sep 17 00:00:00 2001 From: Ilia Bozhinov Date: Fri, 6 Oct 2023 10:21:23 +0200 Subject: [PATCH] background-view: remove idle inhibitors for background views --- src/background-view.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/background-view.cpp b/src/background-view.cpp index 9576cfd..d704c80 100644 --- a/src/background-view.cpp +++ b/src/background-view.cpp @@ -223,6 +223,9 @@ class wayfire_background_view : public wf::plugin_interface_t // List of all background views assigned to an output std::map> views; + wf::wl_listener_wrapper on_new_inhibitor; + wf::wl_idle_call idle_cleanup_inhibitors; + public: void init() override { @@ -230,6 +233,9 @@ class wayfire_background_view : public wf::plugin_interface_t file.set_callback(option_changed); wf::get_core().connect(&on_view_pre_map); option_changed(); + + on_new_inhibitor.set_callback([=] (auto) { remove_idle_inhibitors(); }); + on_new_inhibitor.connect(&wf::get_core().protocols.idle_inhibit->events.new_inhibitor); } void close_all_views() @@ -288,6 +294,9 @@ class wayfire_background_view : public wf::plugin_interface_t views.erase(o); }); views[o] = new_view; + + // Remove any idle inhibitors which were already set + remove_idle_inhibitors(); } wf::signal::connection_t on_view_pre_map = [=] (wf::view_pre_map_signal *ev) @@ -326,6 +335,30 @@ class wayfire_background_view : public wf::plugin_interface_t } } + void remove_idle_inhibitors() + { + + idle_cleanup_inhibitors.run_once([=] () + { + auto& mgr = wf::get_core().protocols.idle_inhibit; + wlr_idle_inhibitor_v1 *inhibitor; + + wl_list_for_each(inhibitor, &mgr->inhibitors, link) + { + for (auto& [_, view] : views) + { + if (inhibitor->surface == view->get_wlr_surface()) + { + // Tell core that the inhibitor was destroyed. It was not really destroyed, but core will + // adjust its internal state as if the inhibitor wasn't there. + wl_signal_emit(&inhibitor->events.destroy, inhibitor->surface); + break; + } + } + } + }); + } + void fini() override { close_all_views();