Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a config to set a timeout for the idle_inhibitor module #1454

Merged
merged 1 commit into from
May 4, 2022

Conversation

Psykar
Copy link
Contributor

@Psykar Psykar commented Mar 6, 2022

My C++ is almost non-existant, so I've probably made some rookie mistakes here, but this does appear to do the job.
Feel free to be brutal in review, I'm more than happy to improve this if required.

Fixes #1288

@Psykar Psykar force-pushed the idle_inhibitor_timeout branch 4 times, most recently from f08369f to b8f3048 Compare March 10, 2022 11:11
@Psykar
Copy link
Contributor Author

Psykar commented Mar 10, 2022

Looks like a recent merge causes the freebsd check to fail
#1333

In file included from ../include/factory.hpp:5:
../include/modules/clock.hpp:39:36: error: no member named '_V2' in namespace 'std::__1::chrono'
  auto timezones_text(std::chrono::_V2::system_clock::time_point *now) -> std::string;
                      ~~~~~~~~~~~~~^

@alebastr
Copy link
Contributor

Actually, it should be possible to do that without creating a thread:

// not a real code but shows the general idea. not tested!
class IdleInhibitor {
// ...
private:
static sigc::connection timeout_;
}

sigc::connection waybar::modules::IdleInhibitor::timeout_ {};

bool waybar::modules::IdleInhibitor::handleToggle(...) {
  if (e->button == 1) {
    status = !status;

    if (timeout_) {
      /* 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);
    }
    
    // ...
  }
}

@Psykar
Copy link
Contributor Author

Psykar commented Apr 10, 2022

Actually, it should be possible to do that without creating a thread:

Thanks, not being familiar with gnome programming (or C++) this helped a lot! It was pretty close to what was needed it seems.

@Alexays Alexays merged commit eec0a82 into Alexays:master May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Standby Inhibitor timeout
3 participants