Merge pull request #1454 from Psykar/idle_inhibitor_timeout

Add a config to set a timeout for the idle_inhibitor module
This commit is contained in:
Alex
2022-05-04 17:27:21 +02:00
committed by GitHub
3 changed files with 31 additions and 1 deletions

View File

@ -72,6 +72,29 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
if (e->button == 1) {
status = !status;
if (timeout_.connected()) {
/* cancel any already active timeout handler */
timeout_.disconnect();
}
if (status && config_["timeout"].isNumeric()) {
auto timeoutMins = config_["timeout"].asDouble();
int timeoutSecs = timeoutMins * 60;
timeout_ = Glib::signal_timeout().connect_seconds([]() {
/* intentionally not tied to a module instance lifetime
* as the output with `this` can be disconnected
*/
spdlog::info("deactivating idle_inhibitor by timeout");
status = false;
for (auto const& module : waybar::modules::IdleInhibitor::modules) {
module->update();
}
/* disconnect */
return false;
}, timeoutSecs);
}
// Make all other idle inhibitor modules update
for (auto const& module : waybar::modules::IdleInhibitor::modules) {
if (module != this) {