Skip to content

Commit

Permalink
Added clock widget
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jul 19, 2019
1 parent fda69da commit 0da9260
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions decks/main.deck
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
[keys.widget.config]
window = "5"

[[keys]]
index = 10
[keys.widget]
id = "clock"

[[keys]]
index = 14
[keys.widget]
Expand Down
2 changes: 2 additions & 0 deletions widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func NewWidget(index uint8, id string, action *ActionConfig, config map[string]s
return &RecentWindowWidget{BaseWidget: bw, window: uint8(i)}
case "top":
return &TopWidget{bw}
case "clock":
return &ClockWidget{bw}
case "launcher":
return &LauncherWidget{BaseWidget: bw, launch: config["exec"], icon: config["icon"]}
}
Expand Down
34 changes: 34 additions & 0 deletions widget_clock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"image"
"log"
"time"

"github.com/golang/freetype"
"github.com/muesli/streamdeck"
)

type ClockWidget struct {
BaseWidget
}

func (w *ClockWidget) Update(dev *streamdeck.Device) {
img := image.NewRGBA(image.Rect(0, 0, 72, 72))

t := time.Now()
hour := t.Format("15")
min := t.Format("04")
sec := t.Format("05")
drawString(img, ttfBoldFont, hour, 22, freetype.Pt(-1, 20))
drawString(img, ttfFont, min, 22, freetype.Pt(-1, 43))
drawString(img, ttfThinFont, sec, 22, freetype.Pt(-1, 66))

err := dev.SetImage(w.key, img)
if err != nil {
log.Fatal(err)
}
}

func (w *ClockWidget) TriggerAction() {
}

0 comments on commit 0da9260

Please sign in to comment.