2022-02-06 21:10:06 +01:00
|
|
|
import std/os
|
|
|
|
import std/times
|
|
|
|
import std/osproc
|
2022-02-06 23:07:32 +01:00
|
|
|
import std/re
|
2022-02-06 21:10:06 +01:00
|
|
|
import i3bar_base
|
|
|
|
|
|
|
|
let args = getArguments()
|
|
|
|
|
|
|
|
proc getObject(date: string): i3barData =
|
2022-04-28 16:52:45 +02:00
|
|
|
var data = newi3barData()
|
|
|
|
data.title = "Date : "
|
|
|
|
data.full_text = date
|
|
|
|
data.border = blue
|
2022-02-06 21:10:06 +01:00
|
|
|
return data
|
|
|
|
|
2022-02-12 14:20:21 +01:00
|
|
|
#proc openCalendar(datestr: string) =
|
2022-04-28 16:52:45 +02:00
|
|
|
proc newCalendar(): string =
|
2022-02-06 23:07:32 +01:00
|
|
|
var c = """yad --calendar \
|
|
|
|
--undecorated --fixed --close-on-unfocus --no-buttons \
|
|
|
|
--width="222" --height="193" \
|
2022-02-12 16:19:43 +01:00
|
|
|
--posx="%pos_x" --posy="%pos_y" \
|
2022-02-06 23:07:32 +01:00
|
|
|
--title="yad-calendar" --borders 0 > /dev/null
|
|
|
|
"""
|
2022-04-28 16:52:45 +02:00
|
|
|
return c
|
|
|
|
proc openCalendar*(input: i3barInput) =
|
|
|
|
var c = newCalendar()
|
|
|
|
|
2022-02-12 16:19:43 +01:00
|
|
|
c = replace(c,re"%pos_x", $(input.x - 111))
|
|
|
|
c = replace(c,re"%pos_y", $input.y)
|
2022-02-06 23:07:32 +01:00
|
|
|
|
|
|
|
discard execCmd(c)
|
2022-02-06 21:10:06 +01:00
|
|
|
|
2022-04-28 16:52:45 +02:00
|
|
|
proc dmenuCalendar() =
|
|
|
|
var c = newCalendar()
|
|
|
|
|
|
|
|
c = replace(c,re"%pos_x", "100")
|
|
|
|
c = replace(c,re"%pos_y", "0")
|
|
|
|
|
|
|
|
discard execCmd(c)
|
|
|
|
|
|
|
|
|
|
|
|
proc getDate*() =
|
2022-02-12 16:19:43 +01:00
|
|
|
var last_date = ""
|
2022-02-12 14:20:21 +01:00
|
|
|
while true:
|
|
|
|
let now = now()
|
|
|
|
let d = now.format("yyyy-MM-dd")
|
2022-02-12 16:19:43 +01:00
|
|
|
if d != last_date:
|
|
|
|
let data = getObject(d)
|
2022-04-28 16:52:45 +02:00
|
|
|
let args = @["open calendar"]
|
|
|
|
case outputJSON(data, args):
|
|
|
|
of "open calendar":
|
|
|
|
dmenuCalendar()
|
2022-02-12 16:19:43 +01:00
|
|
|
last_date = d
|
2022-04-28 16:52:45 +02:00
|
|
|
if stoploop:
|
|
|
|
break
|
2022-02-12 16:19:43 +01:00
|
|
|
sleep(5000)
|
2022-02-12 14:20:21 +01:00
|
|
|
|
2022-02-06 21:10:06 +01:00
|
|
|
proc main() =
|
2022-04-28 16:52:45 +02:00
|
|
|
getDate()
|
|
|
|
|
2022-02-06 21:10:06 +01:00
|
|
|
|
2022-04-28 16:52:45 +02:00
|
|
|
if isMainModule:
|
|
|
|
main()
|
2022-02-06 21:10:06 +01:00
|
|
|
|
|
|
|
#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 &
|