added wlan, battery and volume
This commit is contained in:
parent
8bf1a1e381
commit
ec9c5742b1
7 changed files with 206 additions and 15 deletions
|
@ -9,10 +9,13 @@ type
|
|||
short_text*: string
|
||||
color*: string
|
||||
border*: string
|
||||
background*: string
|
||||
|
||||
type
|
||||
i3BarInput* = object
|
||||
button*: int
|
||||
x*: int
|
||||
y*: int
|
||||
|
||||
const background* = "#000000"
|
||||
const backgroundalt* = "#bb222222"
|
||||
|
@ -20,6 +23,7 @@ const backgroundalt2* = "#bb333333"
|
|||
const foreground* = "#dfdfdf"
|
||||
const foregroundalt* = "#777"
|
||||
const foregroundalt2* = "#ccc"
|
||||
const black* = "#000000"
|
||||
const yellow* = "#ffb52a"
|
||||
const red* = "#e60053"
|
||||
const purple* = "#9f78e1"
|
||||
|
@ -49,7 +53,7 @@ proc parseInput*(): i3BarInput =
|
|||
except:
|
||||
return i3BarInput()
|
||||
proc clearInput*(count: int = 1) =
|
||||
for x in countup(0, count):
|
||||
for x in countup(1, count):
|
||||
discard readLineFromStdin("")
|
||||
|
||||
proc getArguments*(): seq[string] =
|
||||
|
|
95
i3bar_battery.nim
Executable file
95
i3bar_battery.nim
Executable file
|
@ -0,0 +1,95 @@
|
|||
import i3bar_base
|
||||
import strutils
|
||||
import std/times
|
||||
import std/os
|
||||
|
||||
proc battery_exists(): bool =
|
||||
let state = strip(readFile("/sys/class/power_supply/BAT0/present"))
|
||||
if state == "1":
|
||||
return true
|
||||
return false
|
||||
|
||||
proc is_charging(): bool =
|
||||
let state = strip(readFile("/sys/class/power_supply/BAT0/status"))
|
||||
case state:
|
||||
of "Charging":
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
proc get_charge(): int =
|
||||
var charge = 0
|
||||
let chg = strip(readFile("/sys/class/power_supply/BAT0/capacity"))
|
||||
if chg != "":
|
||||
charge = parseInt(chg)
|
||||
return charge
|
||||
|
||||
proc get_design(charge: int, state: bool): (string, string, string, string) =
|
||||
var icon = " "
|
||||
var icon_colour = lightgreen
|
||||
var col = foreground
|
||||
var bg = black
|
||||
var border = lightgreen
|
||||
if is_charging():
|
||||
icon = " "
|
||||
else:
|
||||
case charge:
|
||||
of 0..5:
|
||||
icon_colour = black
|
||||
col = black
|
||||
bg = red
|
||||
of 6..19:
|
||||
icon_colour = alert
|
||||
border = alert
|
||||
of 20..39:
|
||||
icon_colour = yellow
|
||||
border = yellow
|
||||
icon = " "
|
||||
of 40..59:
|
||||
icon_colour = green
|
||||
border= green
|
||||
icon = " "
|
||||
of 60..79:
|
||||
icon_colour = green
|
||||
border= green
|
||||
icon = " "
|
||||
of 80..100:
|
||||
icon_colour = lightgreen
|
||||
border = lightgreen
|
||||
icon = " "
|
||||
else:
|
||||
icon = "x "
|
||||
|
||||
let text = "<span foreground=\"" & icon_colour & "\">" & icon & "</span>" & $charge & "%"
|
||||
return (text, col, bg, border)
|
||||
|
||||
proc get_output(charge: int, state: bool): i3barData =
|
||||
let (text,col,bg_col,bord_col) = get_design(charge, state)
|
||||
let data = i3barData(
|
||||
full_text: text,
|
||||
color: col,
|
||||
border: bord_col,
|
||||
background: bg_col
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
proc get_battery_info() =
|
||||
var last_charge = 0
|
||||
var last_state = false
|
||||
while true:
|
||||
let charge = get_charge()
|
||||
let state = is_charging()
|
||||
if charge != last_charge or state != last_state:
|
||||
let data = get_output(charge, state)
|
||||
outputJSON(data)
|
||||
last_charge = charge
|
||||
last_state = state
|
||||
sleep(1000)
|
||||
|
||||
proc main() =
|
||||
if battery_exists():
|
||||
get_battery_info()
|
||||
|
||||
main()
|
||||
|
|
@ -16,30 +16,35 @@ proc getObject(date: string): i3barData =
|
|||
return data
|
||||
|
||||
#proc openCalendar(datestr: string) =
|
||||
proc openCalendar() =
|
||||
proc openCalendar(input: i3barInput) =
|
||||
|
||||
var c = """yad --calendar \
|
||||
--undecorated --fixed --close-on-unfocus --no-buttons \
|
||||
--width="222" --height="193" \
|
||||
--posx="1650" --posy="25" \
|
||||
--posx="%pos_x" --posy="%pos_y" \
|
||||
--title="yad-calendar" --borders 0 > /dev/null
|
||||
"""
|
||||
|
||||
c = replace(c,re"%pos_x", $(input.x - 111))
|
||||
c = replace(c,re"%pos_y", $input.y)
|
||||
|
||||
discard execCmd(c)
|
||||
|
||||
proc getDate() =
|
||||
var last_date = ""
|
||||
while true:
|
||||
let now = now()
|
||||
let d = now.format("yyyy-MM-dd")
|
||||
if d != last_date:
|
||||
let data = getObject(d)
|
||||
outputJSON(data)
|
||||
sleep(30000)
|
||||
last_date = d
|
||||
sleep(5000)
|
||||
|
||||
proc await_click_info() =
|
||||
while true:
|
||||
let input = parseInput()
|
||||
if input.button == 1:
|
||||
openCalendar()
|
||||
openCalendar(input)
|
||||
|
||||
proc main() =
|
||||
spawn getDate()
|
||||
|
|
|
@ -77,11 +77,14 @@ proc getObject(time: string): i3barData =
|
|||
|
||||
|
||||
proc main() =
|
||||
var last_time = ""
|
||||
while true:
|
||||
let time = get_fuzzytime()
|
||||
if time != last_time:
|
||||
let data = getObject(time)
|
||||
outputJSON(data)
|
||||
last_time = time
|
||||
|
||||
sleep(10000)
|
||||
sleep(2000)
|
||||
|
||||
main()
|
||||
|
|
|
@ -30,10 +30,13 @@ proc getObject(ping: string): i3barData =
|
|||
|
||||
|
||||
proc main() =
|
||||
var last_ping = ""
|
||||
while true:
|
||||
let ping = get_pingms()
|
||||
if ping != last_ping:
|
||||
let data = getObject(ping)
|
||||
outputJSON(data)
|
||||
last_ping = ping
|
||||
|
||||
sleep(time_secs * 1000)
|
||||
|
||||
|
|
|
@ -50,10 +50,13 @@ proc getObject(temp: int): i3barData =
|
|||
|
||||
proc main() =
|
||||
let zones = getThermalZones()
|
||||
var last_temp = 0
|
||||
while true:
|
||||
let temp = getAverageTemp(zones)
|
||||
if temp != last_temp:
|
||||
let data = getObject(temp)
|
||||
outputJSON(data)
|
||||
last_temp = temp
|
||||
sleep(10000)
|
||||
|
||||
main()
|
||||
|
|
78
i3bar_volume.nim
Normal file
78
i3bar_volume.nim
Normal file
|
@ -0,0 +1,78 @@
|
|||
import std/os
|
||||
import strutils
|
||||
import std/osproc
|
||||
import std/math
|
||||
import i3bar_base
|
||||
import std/threadpool
|
||||
|
||||
proc getDesign(vol: string): string =
|
||||
var icon = " "
|
||||
if vol == "muted":
|
||||
return icon & "muted"
|
||||
let pcnt = parseInt(strip(vol))
|
||||
case pcnt:
|
||||
of 85..100:
|
||||
icon = " "
|
||||
of 55..84:
|
||||
icon = " "
|
||||
of 35..54:
|
||||
icon = " "
|
||||
of 10..34:
|
||||
icon = " "
|
||||
else:
|
||||
icon = " "
|
||||
let text = icon & $pcnt & "%"
|
||||
return text
|
||||
|
||||
proc get_current_volume(): string =
|
||||
let mute = execCmdEx("pamixer --get-mute")
|
||||
if strip(mute.output) == "true":
|
||||
return "muted"
|
||||
let vol = execCmdEx("pamixer --get-volume")
|
||||
return vol.output
|
||||
|
||||
proc get_volume(run_once: bool = false) =
|
||||
var last_vol: string = ""
|
||||
while true:
|
||||
let vol = get_current_volume()
|
||||
if vol != last_vol:
|
||||
let text = getDesign(vol)
|
||||
let data = i3barData(
|
||||
full_text: text,
|
||||
color: foreground,
|
||||
border: green
|
||||
)
|
||||
outputJSON(data)
|
||||
if run_once:
|
||||
break
|
||||
last_vol = vol
|
||||
sleep(1000)
|
||||
|
||||
proc await_click_info() =
|
||||
while true:
|
||||
let input = parseInput()
|
||||
case input.button:
|
||||
of 4:
|
||||
discard execCmd("pamixer -i 5")
|
||||
get_volume(true)
|
||||
clearInput(2)
|
||||
of 5:
|
||||
discard execCmd("pamixer -d 5")
|
||||
get_volume(true)
|
||||
clearInput(2)
|
||||
of 1:
|
||||
discard execCmd("pamixer -t")
|
||||
get_volume(true)
|
||||
of 3:
|
||||
discard execCmd("alacritty -e ncpamixer")
|
||||
get_volume(true)
|
||||
else:
|
||||
let no = false
|
||||
|
||||
|
||||
proc main() =
|
||||
spawn get_volume()
|
||||
spawn await_click_info()
|
||||
sync()
|
||||
|
||||
main()
|
Loading…
Reference in a new issue