PrayagS / polybar-spotify

:musical_note: Spotify status and controls module for Polybar with text scrolling
MIT License
581 stars 38 forks source link

Is there a way to completely hide the module when spotify isnt open? #7

Closed Morantoine closed 3 years ago

Morantoine commented 3 years ago

Now that I got this to work, I thought it would be a good idea

PrayagS commented 3 years ago

Yes, you definitely can! Using polybar's IPC, we can toggle the visibility of a given bar or all the running bars. See the toggle command here.

I think I should create a separate branch where this feature is enabled. You can always try it yourself and open a PR. I would be happy to accept your contributions!

Thanks for the idea! Keep 'em coming!

Morantoine commented 3 years ago

Thanks for the answer ! Id love to help but sadly my skill isnt good enough XD

KivalM commented 3 years ago

@Morantxu Take a look at my version of the module on my github page https://github.com/J0eKing/polybar-spotify

It has support for hiding the module when nothing is playing.

@PrayagS if you're interested you can add it as a branch of your main project.

PrayagS commented 3 years ago

@J0eKing Sure thing. I'll add it eventually.

TechieAndroid commented 3 years ago

I'd also like to know how to hide it when there's nothing playing. I already have the IPC flag set to enabled but I need further information on how to use the "toggle" flag to switch it on/off whenever the music is playing or not.

That wiki page barely says what it does let alone how to actually make use of it. Perhaps someone can help me out here.

PrayagS commented 3 years ago

@TechieAndroid The general format is

polybar-msg -p <pid> <type> <payload>

So if you want to toggle the visibility of a bar, that would be

polybar-msg -p <pid> cmd toggle

How you get the pid depends on how you launch the bar. Just pgrep the launch command to get the required PID. Take a look at get_spotify_status.sh for an example.

KivalM commented 3 years ago

The above solution will work if you want to completely hide polybar. If you want to just hide the module you will need to use hooks in conjunction with polybar-msg.

polybar-msg -p <pid> hook next 1 polybar-msg -p <pid> hook next 0

and then you need to have your module setup like this.

[module/next]
type = custom/ipc
hook-0 = echo ""
hook-1 = echo ""

so that when the hook is 1 it will display nothing and then just do this for all the modules. If you need an example take a look at https://github.com/J0eKing/polybar-spotify

PrayagS commented 3 years ago

@J0eKing I'm afraid you're mistaken. What I proposed will in fact completely hide the bar, but in that case, you just split your modules into multiple bars and launch them separately. So if you have a separate bar with the now playing text and the music controls, you can use polybar-msg to directly hide the bar.

If we use hooks to delete the label text, that will still display the empty bar which some people might not want.

KivalM commented 3 years ago

I understand what you mean. My solution is there for people who don't want to create a second polybar just for 1 module, and wish to include it in their current bar along with other modules.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.