Commit 26fe2f2e authored by Benedikt Vollmerhaus's avatar Benedikt Vollmerhaus

Add current ping script to Polybar, Change module order

parent b155b1f3
......@@ -26,8 +26,8 @@ color8 = ${xrdb:color8:#373b41}
[color]
base-bg = #8c0a0a0a
glyph-bg = #b40a0a0a
module-bg = #dc0a0a0a
glyph-bg = #de0a0a0a
module-bg = #f00a0a0a
selected-bg = #dc1a1a1a
text-fg = #c8c8c8
......@@ -93,9 +93,8 @@ font-4 = mplus Nerd Font:style=Medium:size=7;3
[bar/top-primary]
inherit = bar/base
modules-left = now-playing volume right-end-top
modules-center = left-end-bottom date right-end-top
modules-right = left-end-top wlan eth filesystem battery
modules-left = now-playing volume right-end-top left-end-bottom ping right-end-top
modules-right = left-end-top wlan eth right-end-bottom left-end-top date right-end-bottom left-end-top
tray-background = ${color.module-bg}
tray-padding = ${layout.module-padding}
......@@ -118,7 +117,7 @@ inherit = bar/base
bottom = true
modules-left = i3 right-end-bottom left-end-top xwindow right-end-bottom
modules-right = left-end-bottom wlan-netspeed eth-netspeed cpu memory temp consumption
modules-right = left-end-bottom cpu memory right-end-top left-end-bottom temp battery
[bar/bottom-secondary]
......@@ -224,7 +223,7 @@ label-mode-padding = ${layout.module-padding}
type = internal/xwindow
inherit = generic-format-style
label = %title:0:30:...%
label = %title:0:35:...%
;
......@@ -239,7 +238,7 @@ inherit = generic-format-style
format = <label> <bar-load>
format-prefix =
label = %percentage:2% %
label = %percentage:2%
; Bar
bar-load-format = ${layout.bar-format}
......@@ -268,7 +267,7 @@ label = %gb_used%
type = internal/temperature
interval = 2
thermal-zone = 0
units = false
warn-temperature = 80
; Normal
......@@ -280,7 +279,7 @@ format-prefix-font = ${layout.icon-font}
format-prefix-foreground = ${color.icon-fg}
format-prefix-padding-right = ${layout.icon-padding}
label = %temperature-c%
label = %temperature-c% °C
; Warning
format-warn-background = ${color.module-bg}
......@@ -292,7 +291,7 @@ format-warn-prefix-font = ${layout.icon-font}
format-warn-prefix-foreground = ${color.icon-fg}
format-warn-prefix-padding-right = ${layout.icon-padding}
label-warn = %temperature-c%
label-warn = ${self.label}
label-warn-foreground = ${color.red}
......@@ -369,7 +368,7 @@ inherit = module/network
interface = ${env:IFACE_WLAN}
format-connected-prefix =
label-connected = %essid% (%signal% %)
label-connected = %essid%
format-disconnected-prefix =
label-disconnected = オフ
......@@ -385,15 +384,15 @@ label-connected = %local_ip%
format-disconnected =
[module/wlan-netspeed]
inherit = module/wlan
label-connected = %downspeed%%{F#174282}↓%{F-} %upspeed%%{F#174282}↑%{F-}
format-disconnected =
[module/ping]
type = custom/script
inherit = generic-format-style
exec = $HOME/.config/polybar/modules/measure_ping.py
tail = true
click-left = kill -USR1 %pid%
[module/eth-netspeed]
inherit = module/eth
label-connected = %downspeed%%{F#174282}↓%{F-} %upspeed%%{F#174282}↑%{F-}
format-prefix =
; ___
......@@ -406,15 +405,15 @@ type = internal/date
inherit = generic-format-style
interval = 1
; Date format is "YYYY 年 MM 月 DD 日", with a smaller font size used for
; the spaces to achieve a smaller spacing while using a monospaced font.
date = %Y%%{F#404040}%{T5} %{T-}年%{T5} %{T-}%%{F-}%m%%{F#404040}%{T5} %{T-}月%{T5} %{T-}%%{F-}%d%%{F#404040}%{T5} %{T-}日%{T5} %{T-}%%{F-}
; Date format is "MM 月 DD 日", with a smaller font size used for
; the spaces to achieve a tighter spacing using a monospaced font.
date = %m%{T5} %{T-}%{F#404040}月%{F-}%{T5} %{T-}%d%{T5} %{T-}%{F#404040}日%{F-}
date-alt = %A
time = %H:%M
time-alt = %H:%M:%S
label = %date% %time%
label = %date% %time%
;
......@@ -426,7 +425,7 @@ label = %date% %time%
type = custom/script
inherit = generic-format-style
exec = $HOME/.config/polybar/now_playing.py
exec = $HOME/.config/polybar/modules/now_playing.py
tail = true
click-left = playerctl next
......@@ -491,23 +490,23 @@ ramp-capacity-font = ${layout.icon-font}
ramp-capacity-foreground = ${color.icon-fg}
ramp-capacity-padding-right = ${layout.icon-padding}
ramp-capacity-0 =
ramp-capacity-1 =
ramp-capacity-2 =
ramp-capacity-3 =
ramp-capacity-4 =
ramp-capacity-5 =
ramp-capacity-6 =
ramp-capacity-7 =
ramp-capacity-8 =
ramp-capacity-9 =
ramp-capacity-0 =
ramp-capacity-1 =
ramp-capacity-2 =
ramp-capacity-3 =
ramp-capacity-4 =
ramp-capacity-5 =
ramp-capacity-6 =
ramp-capacity-7 =
ramp-capacity-8 =
ramp-capacity-9 =
ramp-capacity-10 =
label-discharging = %percentage% %
label-discharging = %percentage%
; Charging
format-charging = <animation-charging><label-charging>
format-charging-background = ${color.module-bg}
format-charging-overline = ${xcolor.color5}
format-charging-padding = ${layout.module-padding}
animation-charging-font = ${layout.icon-font}
......@@ -515,17 +514,17 @@ animation-charging-foreground = ${color.icon-fg}
animation-charging-padding-right = ${layout.icon-padding}
animation-charging-framerate = 1000
animation-charging-0 =
animation-charging-1 =
animation-charging-2 =
animation-charging-3 =
animation-charging-4 =
animation-charging-0 =
animation-charging-1 =
animation-charging-2 =
animation-charging-3 =
animation-charging-4 =
animation-charging-5 =
label-charging = ${self.label-discharging}
; Full
format-full-background = ${color.module-bg}
format-full-overline = ${xcolor.color5}
format-full-padding = ${layout.module-padding}
format-full-prefix =
......@@ -536,8 +535,7 @@ format-full-prefix-padding-right = ${layout.icon-padding}
label-full = ${self.label-discharging}
[module/consumption]
type = internal/battery
[module/wattage]
inherit = module/battery
; Discharging
......@@ -548,19 +546,17 @@ format-discharging-prefix-font = ${layout.icon-font}
format-discharging-prefix-foreground = ${color.icon-fg}
format-discharging-prefix-padding-right = ${layout.icon-padding}
label-discharging = -%consumption% W
label-discharging = -%consumption:0:4% W
; Charging
format-charging = <label-charging>
format-charging-overline =
format-charging-underline = ${xcolor.color5}
format-charging-prefix = ${self.format-discharging-prefix}
format-charging-prefix-font = ${layout.icon-font}
format-charging-prefix-foreground = ${color.icon-fg}
format-charging-prefix-padding-right = ${layout.icon-padding}
label-charging = +%consumption% W
label-charging = +%consumption:0:4% W
; Full
format-full =
......
#!/usr/bin/env python3
"""
A custom module script for Polybar which measures and outputs the
current ping time periodically or upon receiving a SIGUSR1 signal.
Author: Benedikt Vollmerhaus
License: MIT
"""
import signal
import subprocess
import threading
PING_CMD = ("ping 8.8.8.8 -c 1 | "
"sed -En 's/.*time=([0-9]+(\\.[0-9]+)?) ms$/\\1/p'")
def update_output(_signum=None, _frame=None) -> None:
"""
Measure the current ping time, output it and (re-) start the
function timer for triggering the next automatic measurement.
This may also be called upon receiving a SIGUSR1 signal, which
therefore updates the output immediately and resets the timer.
:param _signum: The signal number, if called by one
:param _frame: The signal's stack frame, if called by one
:return: None
"""
if update_output.timer is not None:
update_output.timer.cancel()
try:
ping = float(measure_ping_time())
print(f'{str(ping)} ms', flush=True)
except ValueError:
print('- ms', flush=True)
update_output.timer = threading.Timer(10, update_output)
update_output.timer.start()
update_output.timer = None
def measure_ping_time() -> str:
"""
Measure the current round-trip time (RTT), i.e. ping.
:return: The current ping
"""
ping = subprocess.check_output(PING_CMD, shell=True)
return ping.decode("utf-8").strip()
if __name__ == '__main__':
update_output()
signal.signal(signal.SIGUSR1, update_output)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment