@@ -2,19 +2,19 @@ package main
22
33import (
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.
1311type 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.
3437func (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 {
4346func (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