diff options
| author | Shubham Saini <pryr@pryr.xyz> | 2020-09-10 11:54:52 +0000 |
|---|---|---|
| committer | Shubham Saini <pryr@pryr.xyz> | 2020-09-10 11:54:52 +0000 |
| commit | baa71be6d0cc8e403c0d5b69ed4b40b4c53021ee (patch) | |
| tree | 583414afeff7832c2d1d10ce935b763c31b5f7ee /polybar | |
| parent | 17db4c5e84c1aa47ffe28e46416f55686c1c5c92 (diff) | |
no more hopping
Diffstat (limited to 'polybar')
| -rwxr-xr-x | polybar/.config/polybar/config | 18 | ||||
| -rwxr-xr-x | polybar/.config/polybar/spotify.py | 123 |
2 files changed, 5 insertions, 136 deletions
diff --git a/polybar/.config/polybar/config b/polybar/.config/polybar/config index bb61b5a..82573d1 100755 --- a/polybar/.config/polybar/config +++ b/polybar/.config/polybar/config | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | [settings] | 1 | [settings] |
| 2 | screenchange-reload = true | 2 | screenchange-reload = true |
| 3 | # wm-restack = bspwm | ||
| 3 | 4 | ||
| 4 | [colors] | 5 | [colors] |
| 5 | #background = ${xrdb:color0:#222} | 6 | #background = ${xrdb:color0:#222} |
| @@ -31,10 +32,10 @@ padding-left = 2 | |||
| 31 | padding-right = 2 | 32 | padding-right = 2 |
| 32 | module-margin-left = 1.5 | 33 | module-margin-left = 1.5 |
| 33 | module-margin-right = 1.5 | 34 | module-margin-right = 1.5 |
| 34 | font-0 = Hermit:style=medium:size=9;1 | 35 | font-0 = JetBrains Mono Nerd Font Mono:style=medium:pixelsize=10:antialias=true:autohint=true:lcdfilter=lcddefault:rgba=rgb |
| 35 | modules-left = pulseaudio battery date time bspwm | 36 | modules-left = pulseaudio battery date time cmus |
| 36 | modules-center = | 37 | modules-center = |
| 37 | modules-right = cmus | 38 | modules-right = bspwm |
| 38 | tray-position = right | 39 | tray-position = right |
| 39 | cursor-click = pointer | 40 | cursor-click = pointer |
| 40 | cursor-scroll = ns-resize | 41 | cursor-scroll = ns-resize |
| @@ -43,7 +44,6 @@ cursor-scroll = ns-resize | |||
| 43 | type = internal/xwindow | 44 | type = internal/xwindow |
| 44 | label = %title:0:20:...% | 45 | label = %title:0:20:...% |
| 45 | 46 | ||
| 46 | |||
| 47 | [module/bspwm] | 47 | [module/bspwm] |
| 48 | type = internal/bspwm | 48 | type = internal/bspwm |
| 49 | format = <label-state> <label-mode> | 49 | format = <label-state> <label-mode> |
| @@ -122,7 +122,7 @@ battery = BAT0 | |||
| 122 | adapter = ADP1 | 122 | adapter = ADP1 |
| 123 | poll-interval = 1 | 123 | poll-interval = 1 |
| 124 | ;full-at = 98 | 124 | ;full-at = 98 |
| 125 | label-discharging = -bat %percentage%% | 125 | label-discharging = bat %percentage%% |
| 126 | label-charging = +bat %percentage%% | 126 | label-charging = +bat %percentage%% |
| 127 | label-full = ^bat %percentage%% | 127 | label-full = ^bat %percentage%% |
| 128 | format-discharging = <label-discharging> | 128 | format-discharging = <label-discharging> |
| @@ -135,14 +135,6 @@ format-volume = vol <label-volume> | |||
| 135 | label-volume = %percentage%% | 135 | label-volume = %percentage%% |
| 136 | label-muted = muted | 136 | label-muted = muted |
| 137 | 137 | ||
| 138 | [module/spotify] | ||
| 139 | type = custom/script | ||
| 140 | interval = 1 | ||
| 141 | format-prefix = " " | ||
| 142 | format = <label> | ||
| 143 | format-foreground = #7b8c58 | ||
| 144 | exec = python ~/.config/polybar/spotify.py -f '{artist}: {song}' | ||
| 145 | |||
| 146 | [module/cmus] | 138 | [module/cmus] |
| 147 | type = custom/script | 139 | type = custom/script |
| 148 | exec = ~/.config/polybar/cmus.sh | 140 | exec = ~/.config/polybar/cmus.sh |
diff --git a/polybar/.config/polybar/spotify.py b/polybar/.config/polybar/spotify.py deleted file mode 100755 index aae6d81..0000000 --- a/polybar/.config/polybar/spotify.py +++ /dev/null | |||
| @@ -1,123 +0,0 @@ | |||
| 1 | #!/bin/python | ||
| 2 | |||
| 3 | import sys | ||
| 4 | import dbus | ||
| 5 | import argparse | ||
| 6 | |||
| 7 | |||
| 8 | parser = argparse.ArgumentParser() | ||
| 9 | parser.add_argument( | ||
| 10 | '-t', | ||
| 11 | '--trunclen', | ||
| 12 | type=int, | ||
| 13 | metavar='trunclen' | ||
| 14 | ) | ||
| 15 | parser.add_argument( | ||
| 16 | '-f', | ||
| 17 | '--format', | ||
| 18 | type=str, | ||
| 19 | metavar='custom format', | ||
| 20 | dest='custom_format' | ||
| 21 | ) | ||
| 22 | parser.add_argument( | ||
| 23 | '-p', | ||
| 24 | '--playpause', | ||
| 25 | type=str, | ||
| 26 | metavar='play-pause indicator', | ||
| 27 | dest='play_pause' | ||
| 28 | ) | ||
| 29 | parser.add_argument( | ||
| 30 | '--font', | ||
| 31 | type=str, | ||
| 32 | metavar='the index of the font to use for the main label', | ||
| 33 | dest='font' | ||
| 34 | ) | ||
| 35 | parser.add_argument( | ||
| 36 | '--playpause-font', | ||
| 37 | type=str, | ||
| 38 | metavar='the index of the font to use to display the playpause indicator', | ||
| 39 | dest='play_pause_font' | ||
| 40 | ) | ||
| 41 | |||
| 42 | |||
| 43 | args = parser.parse_args() | ||
| 44 | |||
| 45 | def fix_string(string): | ||
| 46 | # corrects encoding for the python version used | ||
| 47 | if sys.version_info.major == 3: | ||
| 48 | return string | ||
| 49 | else: | ||
| 50 | return string.encode('utf-8') | ||
| 51 | |||
| 52 | # Default parameters | ||
| 53 | output = fix_string(u'{play_pause} {artist}: {song}') | ||
| 54 | trunclen = 25 | ||
| 55 | play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused | ||
| 56 | |||
| 57 | label_with_font = '%{{T{font}}}{label}%{{T-}}' | ||
| 58 | font = args.font | ||
| 59 | play_pause_font = args.play_pause_font | ||
| 60 | |||
| 61 | # parameters can be overwritten by args | ||
| 62 | if args.trunclen is not None: | ||
| 63 | trunclen = args.trunclen | ||
| 64 | if args.custom_format is not None: | ||
| 65 | output = args.custom_format | ||
| 66 | if args.play_pause is not None: | ||
| 67 | play_pause = args.play_pause | ||
| 68 | |||
| 69 | try: | ||
| 70 | session_bus = dbus.SessionBus() | ||
| 71 | spotify_bus = session_bus.get_object( | ||
| 72 | 'org.mpris.MediaPlayer2.spotify', | ||
| 73 | '/org/mpris/MediaPlayer2' | ||
| 74 | ) | ||
| 75 | |||
| 76 | spotify_properties = dbus.Interface( | ||
| 77 | spotify_bus, | ||
| 78 | 'org.freedesktop.DBus.Properties' | ||
| 79 | ) | ||
| 80 | |||
| 81 | metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata') | ||
| 82 | status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus') | ||
| 83 | |||
| 84 | # Handle play/pause label | ||
| 85 | |||
| 86 | play_pause = play_pause.split(',') | ||
| 87 | |||
| 88 | if status == 'Playing': | ||
| 89 | play_pause = play_pause[0] | ||
| 90 | elif status == 'Paused': | ||
| 91 | play_pause = play_pause[1] | ||
| 92 | else: | ||
| 93 | play_pause = str() | ||
| 94 | |||
| 95 | if play_pause_font: | ||
| 96 | play_pause = label_with_font.format(font=play_pause_font, label=play_pause) | ||
| 97 | |||
| 98 | # Handle main label | ||
| 99 | |||
| 100 | artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else '' | ||
| 101 | song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else '' | ||
| 102 | |||
| 103 | if not artist and not song: | ||
| 104 | print('') | ||
| 105 | else: | ||
| 106 | if len(song) > trunclen: | ||
| 107 | song = song[0:trunclen] | ||
| 108 | song += '...' | ||
| 109 | if ('(' in song) and (')' not in song): | ||
| 110 | song += ')' | ||
| 111 | |||
| 112 | if font: | ||
| 113 | artist = label_with_font.format(font=font, label=artist) | ||
| 114 | song = label_with_font.format(font=font, label=song) | ||
| 115 | |||
| 116 | print(output.format(artist=artist, song=song, play_pause=play_pause)) | ||
| 117 | |||
| 118 | except Exception as e: | ||
| 119 | if isinstance(e, dbus.exceptions.DBusException): | ||
| 120 | print('') | ||
| 121 | else: | ||
| 122 | print(e) | ||
| 123 | |||
