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

[MPRIS module] Widget disappears when ignored player starts playing while non-ignored player is active #3879

Open
Crystal4276 opened this issue Jan 11, 2025 · 0 comments
Labels
bug Something isn't working clock custom

Comments

@Crystal4276
Copy link

Crystal4276 commented Jan 11, 2025

Description

When using the ignored-players configuration option in the MPRIS module, if one of the ignored players starts playing, the waybar display of the currently active player disappears, even if the current player is not in the ignored list.

Steps to Reproduce

  1. Configure waybar with MPRIS module using ignored-players
  2. Example configuration:
    "mpris": {
        "format": "{player_icon} {status_icon}  {artist} - {title}",
        "format-paused": "{player_icon} {status_icon} {artist} - {title}",
        "format-stopped": "{player_icon}",
        "player-icons": {
            "default": "",
            "spotify": "",
            "discord": "",
        },
        "status-icons": {
            "paused": "",
        },
         "ignored-players": ["io","chromium","firefox"],
    },
  1. Start playing media in a non-ignored player (e.g., spotify)
  2. While spotify is playing, start playing media in firefox
  3. Observe that the spotify display in waybar disappears

Expected Behavior

  • When an ignored player starts playing, the current non-ignored player should remain displayed
  • The widget should only disappear when:
    • Using playerctld and all active players are in the ignored list
    • Using a specific player that is in the ignored list

Actual Behavior

The display disappears completely when any ignored player starts playing, regardless of whether there are active non-ignored players.

Suggested Root Cause from Claude

In the getPlayerInfo() method, when using playerctld, the code immediately returns nullopt if the first active player is in the ignored list, without checking for other non-ignored active players.

Proposed fix
auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
  if (!player) {
    return std::nullopt;
  }

  GError* error = nullptr;
  waybar::util::ScopeGuard error_deleter([error]() {
    if (error) {
      g_error_free(error);
    }
  });

  char* player_status = nullptr;
  auto player_playback_status = PLAYERCTL_PLAYBACK_STATUS_STOPPED;
  g_object_get(player, "status", &player_status, "playback-status", &player_playback_status, NULL);

  std::string player_name = player_;
  if (player_name == "playerctld") {
    GList* players = playerctl_list_players(&error);
    if (error) {
      throw std::runtime_error(fmt::format("unable to list players: {}", error->message));
    }
    // > get the list of players [..] in order of activity
    // https://github.com/altdesktop/playerctl/blob/b19a71cb9dba635df68d271bd2b3f6a99336a223/playerctl/playerctl-common.c#L248-L249
    players = g_list_first(players);
    
    // Find the first non-ignored player
    while (players) {
      player_name = static_cast<PlayerctlPlayerName*>(players->data)->name;
      if (std::none_of(ignored_players_.begin(), ignored_players_.end(),
                    [&](const std::string& pn) { return player_name == pn; })) {
        break;
      }
      players = g_list_next(players);
    }
    
    // If all players are ignored, return nullopt
    if (!players) {
      spdlog::debug("mpris: all active players are ignored");
      return std::nullopt;
    }
  } else {
    // For specific player selection, respect ignored_players
    if (std::any_of(ignored_players_.begin(), ignored_players_.end(),
                    [&](const std::string& pn) { return player_name == pn; })) {
      spdlog::warn("mpris[{}]: ignoring player update", player_name);
      return std::nullopt;
    }
  }

  // make status lowercase
  player_status[0] = std::tolower(player_status[0]);

  PlayerInfo info = {
      .name = player_name,
      .status = player_playback_status,
      .status_string = player_status,
      .artist = std::nullopt,
      .album = std::nullopt,
      .title = std::nullopt,
      .length = std::nullopt,
  };

Environment

  • Waybar version: 0.11.0
  • OS: Arch Linux
@github-actions github-actions bot added custom bug Something isn't working clock labels Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working clock custom
Projects
None yet
Development

No branches or pull requests

1 participant