started top add dmenu implementation

This commit is contained in:
Paul Wilde 2022-04-28 12:34:09 +01:00
parent 331844dfd8
commit aabcfd98c7
9 changed files with 31 additions and 7 deletions

1
i3bar_base.nim Executable file → Normal file
View file

@ -60,6 +60,7 @@ proc parseInput*(): i3BarInput =
return i3input return i3input
except: except:
return i3BarInput() return i3BarInput()
proc clearInput*(count: int = 1) = proc clearInput*(count: int = 1) =
for x in countup(1, count): for x in countup(1, count):
discard readLineFromStdin("") discard readLineFromStdin("")

View file

@ -75,7 +75,7 @@ proc get_output(charge: int, state: bool): i3barData =
proc get_battery_info() = proc get_battery_info() =
var last_charge = 0 var last_charge = -1
var last_state = false var last_state = false
while true: while true:
let charge = get_charge() let charge = get_charge()

0
i3bar_brightness.nim Executable file → Normal file
View file

0
i3bar_date.nim Executable file → Normal file
View file

0
i3bar_fuzzytime.nim Executable file → Normal file
View file

6
i3bar_nic.nim Executable file → Normal file
View file

@ -6,8 +6,6 @@ import strutils
const nics: seq[string] = @["wlan0", "enp3s0","wlp2s0","enp0s20f0u3"] const nics: seq[string] = @["wlan0", "enp3s0","wlp2s0","enp0s20f0u3"]
# /sys/class/net/*/operstate up or down if connected
proc get_ip(nic: string): string = proc get_ip(nic: string): string =
let cmd = "ifconfig " & nic & " | grep inet | awk -F\" \" '{print $2}' | head -1 | awk '{print $1}'" let cmd = "ifconfig " & nic & " | grep inet | awk -F\" \" '{print $2}' | head -1 | awk '{print $1}'"
let ip = execCmdEx(cmd) let ip = execCmdEx(cmd)
@ -25,7 +23,7 @@ proc get_net(nic: string): (string, string) =
return ("disconnected", state) return ("disconnected", state)
return (ip, state) return (ip, state)
proc getObject(conn: string): i3barData = proc getObject(conn: string, nic: string): i3barData =
var data = newi3barData() var data = newi3barData()
data.full_text = conn data.full_text = conn
data.border = purple data.border = purple
@ -37,7 +35,7 @@ proc get_net_info(nic: string) =
while true: while true:
let (ip, state) = get_net(nic) let (ip, state) = get_net(nic)
if ip != last_ip or state != last_state: if ip != last_ip or state != last_state:
let data = getObject(state & " " & ip) let data = getObject(state & " " & ip, nic)
outputJSON(data) outputJSON(data)
last_ip = ip last_ip = ip
last_state = state last_state = state

27
i3bar_pingclock.nim Executable file → Normal file
View file

@ -49,16 +49,41 @@ proc getObject(ping: float): i3barData =
) )
return data return data
proc runDMenu(data: i3BarData) =
var cmd = "echo Ping Clock : " & $data.full_text & " | dmenu "
cmd = cmd & " -nb \"" & $data.background & "\""
cmd = cmd & " -nf \"" & $data.color & "\""
cmd = cmd & " -sb \"" & $data.background & "\""
cmd = cmd & " -sf \"" & $data.color & "\""
discard execCmd(cmd)
discard execCmd("i3-msg mode \"default\"")
proc main() = proc main() =
let args = getArguments()
var loop = true
var stoploop = false
var dmenu = false
for arg in args:
if arg == "noloop":
stoploop = true
if arg == "dmenu":
stoploop = true
dmenu = true
var last_ping: float = 0 var last_ping: float = 0
while true: while loop:
let ping = get_ping() let ping = get_ping()
if ping != last_ping: if ping != last_ping:
let data = getObject(ping) let data = getObject(ping)
outputJSON(data) outputJSON(data)
last_ping = ping last_ping = ping
if dmenu:
runDMenu(data)
loop = not stoploop
if loop:
sleep(time_secs * 1000) sleep(time_secs * 1000)
main() main()

0
i3bar_temperature.nim Executable file → Normal file
View file

0
i3bar_volume.nim Executable file → Normal file
View file