Skip to content

Commit

Permalink
Embed a pointer to the BaseWidgets, so we can keep the render state
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jun 10, 2021
1 parent 5ad136a commit 70b919e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,34 @@ func NewWidget(base string, kc KeyConfig, bg image.Image) (Widget, error) {

switch kc.Widget.ID {
case "button":
return NewButtonWidget(*bw, kc.Widget)
return NewButtonWidget(bw, kc.Widget)

case "clock":
kc.Widget.Config = make(map[string]interface{})
kc.Widget.Config["format"] = "%H;%i;%s"
kc.Widget.Config["font"] = "bold;regular;thin"
return NewTimeWidget(*bw, kc.Widget), nil
return NewTimeWidget(bw, kc.Widget), nil

case "date":
kc.Widget.Config = make(map[string]interface{})
kc.Widget.Config["format"] = "%l;%d;%M"
kc.Widget.Config["font"] = "regular;bold;regular"
return NewTimeWidget(*bw, kc.Widget), nil
return NewTimeWidget(bw, kc.Widget), nil

case "time":
return NewTimeWidget(*bw, kc.Widget), nil
return NewTimeWidget(bw, kc.Widget), nil

case "recentWindow":
return NewRecentWindowWidget(*bw, kc.Widget)
return NewRecentWindowWidget(bw, kc.Widget)

case "top":
return NewTopWidget(*bw, kc.Widget), nil
return NewTopWidget(bw, kc.Widget), nil

case "command":
return NewCommandWidget(*bw, kc.Widget), nil
return NewCommandWidget(bw, kc.Widget), nil

case "weather":
return NewWeatherWidget(*bw, kc.Widget), nil
return NewWeatherWidget(bw, kc.Widget)
}

// unknown widget ID
Expand Down
4 changes: 2 additions & 2 deletions widget_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// ButtonWidget is a simple widget displaying an icon and/or label.
type ButtonWidget struct {
BaseWidget
*BaseWidget

icon image.Image
label string
Expand All @@ -19,7 +19,7 @@ type ButtonWidget struct {
}

// NewButtonWidget returns a new ButtonWidget.
func NewButtonWidget(bw BaseWidget, opts WidgetConfig) (*ButtonWidget, error) {
func NewButtonWidget(bw *BaseWidget, opts WidgetConfig) (*ButtonWidget, error) {
bw.setInterval(opts.Interval, 0)

var icon, label string
Expand Down
4 changes: 2 additions & 2 deletions widget_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

// CommandWidget is a widget displaying the output of command(s).
type CommandWidget struct {
BaseWidget
*BaseWidget

command string
font string
color color.Color
}

// NewCommandWidget returns a new CommandWidget.
func NewCommandWidget(bw BaseWidget, opts WidgetConfig) *CommandWidget {
func NewCommandWidget(bw *BaseWidget, opts WidgetConfig) *CommandWidget {
bw.setInterval(opts.Interval, 1000)

var command, font string
Expand Down
4 changes: 2 additions & 2 deletions widget_recent_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// RecentWindowWidget is a widget displaying a recently activated window.
type RecentWindowWidget struct {
BaseWidget
*ButtonWidget

window uint8
showTitle bool
Expand All @@ -18,7 +18,7 @@ type RecentWindowWidget struct {
}

// NewRecentWindowWidget returns a new RecentWindowWidget.
func NewRecentWindowWidget(bw BaseWidget, opts WidgetConfig) (*RecentWindowWidget, error) {
func NewRecentWindowWidget(bw *BaseWidget, opts WidgetConfig) (*RecentWindowWidget, error) {
var window int64
if err := ConfigValue(opts.Config["window"], &window); err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions widget_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

// TimeWidget is a widget displaying the current time/date.
type TimeWidget struct {
BaseWidget
*BaseWidget

format string
font string
color color.Color
}

// NewTimeWidget returns a new TimeWidget.
func NewTimeWidget(bw BaseWidget, opts WidgetConfig) *TimeWidget {
func NewTimeWidget(bw *BaseWidget, opts WidgetConfig) *TimeWidget {
bw.setInterval(opts.Interval, 500)

var format, font string
Expand Down
4 changes: 2 additions & 2 deletions widget_top.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// TopWidget is a widget displaying the current CPU/MEM usage as a bar.
type TopWidget struct {
BaseWidget
*BaseWidget

mode string
color color.Color
Expand All @@ -24,7 +24,7 @@ type TopWidget struct {
}

// NewTopWidget returns a new TopWidget.
func NewTopWidget(bw BaseWidget, opts WidgetConfig) *TopWidget {
func NewTopWidget(bw *BaseWidget, opts WidgetConfig) *TopWidget {
bw.setInterval(opts.Interval, 500)

var mode string
Expand Down
2 changes: 1 addition & 1 deletion widget_weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func weatherImage(name string) image.Image {

// WeatherWidget is a widget displaying the current weather.
type WeatherWidget struct {
BaseWidget
*ButtonWidget

data WeatherData
color color.Color
Expand Down

0 comments on commit 70b919e

Please sign in to comment.