From 117ba68d892f27ac0d64275e4d41479fa13c5799 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sun, 6 Feb 2022 22:07:32 +0000 Subject: [PATCH] added direct yad execute rather than script --- debug.txt | 14 ++++++++++++++ i3bar_base.nim | 22 ++++++++++++++++++++++ i3bar_brightness.nim | 2 -- i3bar_date.nim | 32 +++++++++++++++++--------------- 4 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 debug.txt diff --git a/debug.txt b/debug.txt new file mode 100644 index 0000000..36f97f0 --- /dev/null +++ b/debug.txt @@ -0,0 +1,14 @@ +(full_text: "🌗 70%", short_text: "", color: "#dfdfdf", border: "#ffb52a")(full_text: "🌗 70%", short_text: "", color: "#dfdfdf", border: "#ffb52a") +5 +(full_text: "🌗 65%", short_text: "", color: "#dfdfdf", border: "#ffb52a") +4 +(full_text: "🌗 70%", short_text: "", color: "#dfdfdf", border: "#ffb52a") +5 +(full_text: "🌗 65%", short_text: "", color: "#dfdfdf", border: "#ffb52a") +(full_text: "🌗 65%", short_text: "", color: "#dfdfdf", border: "#ffb52a") +(full_text: "🌗 65%", short_text: "", color: "#dfdfdf", border: "#ffb52a") +(full_text: "🌗 65%", short_text: "", color: "#dfdfdf", border: "#ffb52a") + + +5 +4 diff --git a/i3bar_base.nim b/i3bar_base.nim index 84ed7cf..484620d 100644 --- a/i3bar_base.nim +++ b/i3bar_base.nim @@ -1,3 +1,6 @@ +import std/os +import std/json +import std/rdstdin import marshal import argparse @@ -8,6 +11,10 @@ type color*: string border*: string +type + i3BarInput* = object + button*: int + const background* = "#000000" const backgroundalt* = "#bb222222" const backgroundalt2* = "#bb333333" @@ -28,6 +35,21 @@ const primary* = yellow const secondary* = red const alert* = "#bd2c40" +proc debugLog*(str: string) = + let f = open("/tmp/debug.txt",fmAppend) + defer: f.close() + f.writeLine(str) + +proc parseInput*(): i3BarInput = + let input = readLineFromStdin("") + debugLog($input) + try: + let jsonNode = parseJson(input) + let i3input = to(jsonNode, i3BarInput) + return i3input + except: + return i3BarInput() + proc getArguments*(): seq[string] = let args = commandLineParams() return args diff --git a/i3bar_brightness.nim b/i3bar_brightness.nim index b4d87ab..e61f6ab 100644 --- a/i3bar_brightness.nim +++ b/i3bar_brightness.nim @@ -30,8 +30,6 @@ proc getDesign(pcnt: float): string = let text = icon & " " & $percent & "%" return text - - proc getBrightness() = let current = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/actual_brightness"))) let pcnt = (current/limit)*100 diff --git a/i3bar_date.nim b/i3bar_date.nim index 5ba4ab1..5a008d8 100644 --- a/i3bar_date.nim +++ b/i3bar_date.nim @@ -1,6 +1,7 @@ import std/os import std/times import std/osproc +import std/re import i3bar_base let args = getArguments() @@ -13,32 +14,33 @@ proc getObject(date: string): i3barData = ) return data -proc openCalendar() = - let cmd = "~/Nextcloud/Backups/Linux/dotFiles/scripts/popup-calendar.sh" - discard execCmd(cmd) +proc openCalendar(datestr: string) = + var c = """yad --calendar \ + --undecorated --fixed --close-on-unfocus --no-buttons \ + --width="222" --height="193" \ + --posx="1650" --posy="25" \ + --title="yad-calendar" --borders 0 > /dev/null + """ + + + discard execCmd(c) proc getDate() = let now = now() let d = now.format("yyyy-MM-dd") let data = getObject(d) outputJSON(data) + if len(args) > 0 and args[0] == "1": + openCalendar(now.format("ddd dd HH:MM")) proc main() = - if len(args) == 0: - #while true: - getDate() - # sleep(5000) - else: - if args[0] == "1": - openCalendar() - getDate() + getDate() + #while true: + # let input = parseInput() + # if input.button == 1: main() -#BAR_HEIGHT=28 # polybar height -#BORDER_SIZE=1 # border size from your wm settings -#YAD_WIDTH=222 # 222 is minimum possible value -#YAD_HEIGHT=193 # 193 is minimum possible value #DATE="$(date +"%a %d %H:%M")" #if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then # exit 0