Skip to content

Commit

Permalink
Merge pull request #2276 from skligys/fix_mpris_ui_spamming
Browse files Browse the repository at this point in the history
Stop MPRIS module from updating every ~20ms
  • Loading branch information
Alexays committed Jul 4, 2023
2 parents 18f5af8 + c2f9d88 commit 265b4ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/modules/mpris/mpris.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Mpris : public ALabel {
std::string lastPlayer;

util::SleeperThread thread_;
std::chrono::time_point<std::chrono::system_clock> last_update_;
};

} // namespace waybar::modules::mpris
7 changes: 6 additions & 1 deletion src/modules/mpris/mpris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
ellipsis_("\u2026"),
player_("playerctld"),
manager(),
player() {
player(),
last_update_(std::chrono::system_clock::now() - interval_) {
if (config_["format-playing"].isString()) {
format_playing_ = config_["format-playing"].asString();
}
Expand Down Expand Up @@ -559,6 +560,10 @@ bool Mpris::handleToggle(GdkEventButton* const& e) {
}

auto Mpris::update() -> void {
const auto now = std::chrono::system_clock::now();
if (now - last_update_ < interval_) return;
last_update_ = now;

auto opt = getPlayerInfo();
if (!opt) {
event_box_.set_visible(false);
Expand Down

0 comments on commit 265b4ed

Please sign in to comment.