Skip to content

Commit ec4edf8

Browse files
committed
Support showing window title below recent window icons
1 parent ec3a10c commit ec4edf8

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

decks/main.deck

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,36 @@
8989
id = "recentWindow"
9090
[keys.widget.config]
9191
window = 1
92+
showTitle = true
9293

9394
[[keys]]
9495
index = 11
9596
[keys.widget]
9697
id = "recentWindow"
9798
[keys.widget.config]
9899
window = 2
100+
showTitle = true
99101

100102
[[keys]]
101103
index = 12
102104
[keys.widget]
103105
id = "recentWindow"
104106
[keys.widget.config]
105107
window = 3
108+
showTitle = true
106109

107110
[[keys]]
108111
index = 13
109112
[keys.widget]
110113
id = "recentWindow"
111114
[keys.widget.config]
112115
window = 4
116+
showTitle = true
113117

114118
[[keys]]
115119
index = 14
116120
[keys.widget]
117121
id = "recentWindow"
118122
[keys.widget.config]
119123
window = 5
124+
showTitle = true

widget_recent_window.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package main
22

33
import (
44
"image"
5-
"image/draw"
65
"log"
76

87
"github.com/muesli/streamdeck"
9-
"github.com/nfnt/resize"
108
)
119

1210
// RecentWindowWidget is a widget displaying a recently activated window.
1311
type RecentWindowWidget struct {
1412
BaseWidget
15-
window uint8
1613

17-
lastClass string
14+
window uint8
15+
showTitle bool
16+
17+
lastID uint32
1818
}
1919

2020
// NewRecentWindowWidget returns a new RecentWindowWidget.
@@ -23,17 +23,20 @@ func NewRecentWindowWidget(bw BaseWidget, opts WidgetConfig) (*RecentWindowWidge
2323
if err := ConfigValue(opts.Config["window"], &window); err != nil {
2424
return nil, err
2525
}
26+
var showTitle bool
27+
_ = ConfigValue(opts.Config["showTitle"], &showTitle)
2628

2729
return &RecentWindowWidget{
2830
BaseWidget: bw,
2931
window: uint8(window),
32+
showTitle: showTitle,
3033
}, nil
3134
}
3235

3336
// RequiresUpdate returns true when the widget wants to be repainted.
3437
func (w *RecentWindowWidget) RequiresUpdate() bool {
3538
if int(w.window) < len(recentWindows) {
36-
return w.lastClass != recentWindows[w.window].Class
39+
return w.lastID != recentWindows[w.window].ID
3740
}
3841

3942
return w.BaseWidget.RequiresUpdate()
@@ -43,15 +46,26 @@ func (w *RecentWindowWidget) RequiresUpdate() bool {
4346
func (w *RecentWindowWidget) Update(dev *streamdeck.Device) error {
4447
img := image.NewRGBA(image.Rect(0, 0, int(dev.Pixels), int(dev.Pixels)))
4548

46-
size := int(dev.Pixels)
4749
if int(w.window) < len(recentWindows) {
48-
if w.lastClass == recentWindows[w.window].Class {
50+
if w.lastID == recentWindows[w.window].ID {
4951
return nil
5052
}
51-
w.lastClass = recentWindows[w.window].Class
53+
w.lastID = recentWindows[w.window].ID
54+
55+
var name string
56+
if w.showTitle {
57+
name = recentWindows[w.window].Name
58+
if len(name) > 10 {
59+
name = name[:10]
60+
}
61+
}
5262

53-
icon := resize.Resize(uint(size-8), uint(size-8), recentWindows[w.window].Icon, resize.Bilinear)
54-
draw.Draw(img, image.Rect(4, 4, size-4, size-4), icon, image.Point{0, 0}, draw.Src)
63+
bw := ButtonWidget{
64+
BaseWidget: w.BaseWidget,
65+
icon: recentWindows[w.window].Icon,
66+
label: name,
67+
}
68+
return bw.Update(dev)
5569
}
5670

5771
return w.render(dev, img)

0 commit comments

Comments
 (0)