wmtools/date.nim

89 lines
2.2 KiB
Nim

import std/os
import std/times
import std/osproc
import std/re
import base
proc getObject(date: string): Info =
var data = newInfo()
data.title = "Date : "
data.full_text = date
data.border = blue
data.selected_background = blue
data.selected_color = white
return data
#proc openCalendar(datestr: string) =
proc newCalendar(): string =
var c = """yad --calendar \
--undecorated --fixed --close-on-unfocus --no-buttons \
--width="222" --height="193" \
--posx="%pos_x" --posy="%pos_y" \
--title="yad-calendar" --borders 0 > /dev/null
"""
return c
proc openCalendar*(input: i3barInput) =
var c = newCalendar()
c = replace(c,re"%pos_x", $(input.x - 111))
c = replace(c,re"%pos_y", $input.y)
discard execCmd(c)
proc dmenuCalendar() =
var c = newCalendar()
c = replace(c,re"%pos_x", "100")
c = replace(c,re"%pos_y", "0")
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)
let args = @["open calendar"]
case outputJSON(data, args):
of "open calendar":
dmenuCalendar()
last_date = d
if stoploop:
break
sleep(5000)
proc main() =
getDate()
if isMainModule:
main()
#DATE="$(date +"%a %d %H:%M")"
#if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then
# exit 0
#fi
#eval "$(xdotool getmouselocation --shell)"
#eval "$(xdotool getdisplaygeometry --shell)"
## X
#if [ "$((X + YAD_WIDTH / 2 + BORDER_SIZE))" -gt "$WIDTH" ]; then #Right side
# : $((pos_x = WIDTH - YAD_WIDTH - BORDER_SIZE))
#elif [ "$((X - YAD_WIDTH / 2 - BORDER_SIZE))" -lt 0 ]; then #Left side
# : $((pos_x = BORDER_SIZE))
#else #Center
# : $((pos_x = X - YAD_WIDTH / 2))
#fi
## Y
#if [ "$Y" -gt "$((HEIGHT / 2))" ]; then #Bottom
# : $((pos_y = HEIGHT - YAD_HEIGHT - BAR_HEIGHT - BORDER_SIZE))
#else #Top
# : $((pos_y = BAR_HEIGHT + BORDER_SIZE))
#fi
#yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \
# --width="$YAD_WIDTH" --height="$YAD_HEIGHT" --posx="$pos_x" --posy="$pos_y" \
# --title="yad-calendar" --borders=0 >/dev/null &