Skip to content

Commit 862e751

Browse files
committed
Replace rofi menu with player cycling
- Right-click now cycles through active players instead of opening rofi menu - Removes rofi dependency - Updated README to reflect cycling functionality - Player cycling persists selection across sessions
1 parent 2024e7b commit 862e751

File tree

2 files changed

+66
-40
lines changed

2 files changed

+66
-40
lines changed

README.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ Synced lyrics in tooltip:
2121
![lyrics](./showcase/lyrics.png)
2222

2323
It features:
24-
1. Progress bar
25-
2. Tooltip that displays title, author and album
26-
3. Synced lyrics in tooltip
27-
4. Album cover art (click to zoom)
28-
5. Optional notification on song change
29-
6. Click to play/pause, scroll up/down to scroll up/down on the playlist
24+
1. Multi-player support (Firefox, Chrome, Chromium, Thorium, Spotify, and more)
25+
2. Right-click to cycle through active players
26+
3. Progress bar
27+
4. Tooltip that displays title, author and album
28+
5. Synced lyrics in tooltip
29+
6. Album cover art (click to zoom)
30+
7. Optional notification on song change
31+
8. Click to play/pause, scroll up/down for next/previous track
3032

3133
## Requirements
3234

33-
[playerctl](https://github.com/altdesktop/playerctl) must be installed.
34-
35-
The default configuration use Nerd Fonts, so it requires waybar to use a Nerd Font.
36-
37-
The default configuration use [feh](https://github.com/derf/feh) to open the album art image.
35+
- [playerctl](https://github.com/altdesktop/playerctl) must be installed
36+
- The default configuration uses Nerd Fonts, so it requires waybar to use a Nerd Font
37+
- The default configuration uses [feh](https://github.com/derf/feh) to open the album art image
3838

3939
## Install
4040

@@ -67,9 +67,13 @@ The default configuration use [feh](https://github.com/derf/feh) to open the alb
6767
pip3 install -r requirements.txt
6868
```
6969
70-
1. You need to find the name of your player. To do so, run `playerctl --list-all` while your player is running.
70+
1. You can configure which players to support by editing `"$HOME/.config/waybar/waybar-mediaplayer/src/config.json`. The default configuration supports Firefox, Chrome, Chromium, Thorium, and Spotify:
7171
72-
1. Open `"$HOME/.config/waybar/waybar-mediaplayer/src/config.json` and change `player_name` with the name of your player.
72+
```json
73+
"player_name": ["firefox", "chrome", "chromium", "thorium", "spotify"]
74+
```
75+
76+
To find available players on your system, run `playerctl --list-all` while your media player is running. You can add or remove players from this list as needed.
7377
7478
1. Put the following in `$HOME/.config/waybar/config`:
7579
@@ -90,6 +94,7 @@ The default configuration use [feh](https://github.com/derf/feh) to open the alb
9094
"return-type": "json",
9195
"format": "{}",
9296
"on-click": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer play-pause",
97+
"on-click-right": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer select",
9398
"on-scroll-up": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer next",
9499
"on-scroll-down": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer previous",
95100
"min-length": 20,
@@ -110,7 +115,11 @@ The default configuration use [feh](https://github.com/derf/feh) to open the alb
110115
111116
1. Start waybar using the wrapper script `start_waybar`.
112117
113-
The mediaplayer should work. Click on the progress bar to start/stop playing, and scroll on it to change song.
118+
The mediaplayer should work with the following controls:
119+
- **Left click**: Play/pause
120+
- **Right click**: Cycle through active players
121+
- **Scroll up**: Next track
122+
- **Scroll down**: Previous track
114123
115124
## Update
116125
@@ -121,6 +130,14 @@ git pull
121130
122131
## Personalization
123132
133+
### Multiple Players
134+
135+
The widget supports monitoring multiple media players simultaneously. Right-click on the widget to cycle through all available players. The selected player becomes the active player for controls (play/pause, next, previous). Your selection persists across sessions.
136+
137+
If no player is selected, the widget automatically uses the first available player from your configured list.
138+
139+
### Other Options
140+
124141
To disable notifications, put `is_notification=false` in `config.json`.
125142
126143
To change widget's length, set `min-length` and `max-length` in `$HOME/.config/waybar/config`, and set `widget_length` in `$HOME/.config/waybar/waybar-mediaplayer/src/config.json`. These 3 variables MUST be set to the same value.
@@ -131,19 +148,21 @@ If you change the colors of the bar in `$HOME/.config/waybar/waybar-mediaplayer/
131148
132149
## Troubleshooting
133150
134-
### Firefox users
151+
### Browser Support (Firefox, Chrome, etc.)
152+
153+
Browsers with MPRIS support are now natively supported. Firefox, Chrome, Chromium, and Thorium work out of the box.
135154
136-
Although Firefox reports MPRIS metadata, the metadata it reports is not sufficient, as it doesn't report song's length. Please install the [Plasma Integration](https://addons.mozilla.org/en-US/firefox/addon/plasma-integration) add-on and use `plasma-browser-integration` as `player_name` in `$HOME/.config/waybar/waybar-mediaplayer/src/config.json`.
155+
**Note for Firefox users**: If you experience issues with the progress bar (Firefox may not always report song length), you can optionally install the [Plasma Integration](https://addons.mozilla.org/en-US/firefox/addon/plasma-integration) add-on for better metadata support. If using this add-on, add `"plasma-browser-integration"` to your `player_name` array in `config.json`.
137156
138-
To have album art, make sure to set `convert_to_jpeg` to `true` in `$HOME/.config/waybar/waybar-mediaplayer/src/config.json` (this option decreases performance, don't use it if not necessary).
157+
For album art from browsers, you may need to set `convert_to_jpeg` to `true` in `config.json` (this option may decrease performance slightly).
139158
140159
### Me progress bar doesn't work
141160
142161
It's likely cause by the player not reporting song length or position back to us. Run `$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer -vvv` to debug.
143162
144163
### Player reports its name with instance number
145164
146-
If the player reports an instance after its name, please provide only the player name without the instance number. For example, [kew](https://github.com/ravachol/kew) may report itself as `kew123456`, where `123456` is an instance number which will change with different runs of `kew`. In this case, we report only `kew` without the instance number. This software will check whether the reported player name _starts_ with the name you provide to bind the correct player.
165+
This is handled automatically. If a player reports an instance number after its name (e.g., `spotify.instance12345`), you only need to configure the base player name (e.g., `"spotify"`) in `config.json`. The software will automatically match any player whose name starts with the configured name.
147166
148167
### Me title and tooltip are empty
149168

src/mediaplayer

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -654,35 +654,42 @@ def main():
654654
f"Requested players: {requested_players}"
655655
)
656656

657-
# Handle select command
657+
# Handle select command (cycle through players)
658658
if arguments.command == "select":
659-
# Get available players
659+
# Get available players using playerctl CLI
660+
result = subprocess.run(
661+
["playerctl", "--list-all"],
662+
capture_output=True,
663+
text=True,
664+
timeout=1
665+
)
666+
660667
available = []
661-
for player in manager.props.player_names:
662-
if any(player.name.startswith(rp) for rp in requested_players):
663-
available.append(player.name)
668+
if result.returncode == 0:
669+
all_players = result.stdout.strip().split('\n')
670+
for player in all_players:
671+
if player and any(player.startswith(rp) for rp in requested_players):
672+
available.append(player)
664673

665674
if not available:
666-
print("No media players found")
675+
logger.debug("No media players found")
667676
sys.exit(0)
668677

669-
# Use rofi for player selection
670-
menu_cmd = ["rofi", "-dmenu", "-p", "Select player:"]
678+
# Get current selection
679+
current = get_selected_player()
671680

672-
# Show menu
673-
try:
674-
result = subprocess.run(
675-
menu_cmd,
676-
input="\n".join(available),
677-
capture_output=True,
678-
text=True
679-
)
680-
if result.returncode == 0 and result.stdout.strip():
681-
selected = result.stdout.strip()
682-
set_selected_player(selected)
683-
print(f"Selected player: {selected}")
684-
except Exception as e:
685-
logger.error(f"Error running menu: {e}")
681+
# Find next player in the list (cycle)
682+
if current and current in available:
683+
current_idx = available.index(current)
684+
next_idx = (current_idx + 1) % len(available)
685+
next_player = available[next_idx]
686+
else:
687+
# No current selection or not in list, use first
688+
next_player = available[0]
689+
690+
# Set new selection
691+
set_selected_player(next_player)
692+
logger.info(f"Cycled to player: {next_player}")
686693
sys.exit(0)
687694

688695
# Handle control commands using playerctl CLI (more reliable for quick actions)

0 commit comments

Comments
 (0)