Skip to content

Commit

Permalink
background-view: remove idle inhibitors for background views
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Oct 6, 2023
1 parent 6c7cf55 commit 13b4a13
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/background-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,19 @@ class wayfire_background_view : public wf::plugin_interface_t
// List of all background views assigned to an output
std::map<wf::output_t*, std::shared_ptr<unmappable_view_t>> views;

wf::wl_listener_wrapper on_new_inhibitor;
wf::wl_idle_call idle_cleanup_inhibitors;

public:
void init() override
{
command.set_callback(option_changed);
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()
Expand Down Expand Up @@ -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<wf::view_pre_map_signal> on_view_pre_map = [=] (wf::view_pre_map_signal *ev)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 13b4a13

Please sign in to comment.