Skip to content

Commit

Permalink
Simply color parsing, add color for widget_command and README improve…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
zMoooooritz authored and muesli committed Jun 8, 2021
1 parent 41061de commit 272f939
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ WantedBy=default.target

Then enable and start the `streamdeck.path` unit:

```
```bash
systemctl --user enable streamdeck.path
systemctl --user start streamdeck.path
```

This comment has been minimized.

Copy link
@zMoooooritz

zMoooooritz Jun 8, 2021

Author Contributor

Just have seen the first discussion concerning the problems with "finding" the .deck files.
Is it common to have the Usage-section right at the bottom of the README?
Otherwise we could move it above Configuration, since the first step will be to get it running and configure it afterwards.

This comment has been minimized.

Copy link
@muesli

muesli Jun 8, 2021

Owner

Yeah, wouldn't mind moving it up. The README grew a bit the last couple of days 😄

This comment has been minimized.

Copy link
@muesli

muesli Jun 8, 2021

Owner

Heads up: I'm taking care of this just now.

Expand All @@ -111,38 +111,36 @@ directory. Edit them to your needs!

Any widget is build up the following way:

```
```toml
[[keys]]
index = 0
interval = 500
interval = 500 # optional
```

`index` needs to be present in every widget and describes the position of the widget on the streamdeck.
`index` is 0-indexed and counted from top to bottom and left to right.
The attribute `interval` is optional and defines the time in `ms` between two consecutive updates of the widget.
The attribute `interval` defines the time in `ms` between two consecutive updates of the widget.

#### Button

A simple button that can display an image and/or a label.

```
```toml
[keys.widget]
id = "button"
[keys.widget.config]
icon = "/some/image.png"
label = "My Button"
fontsize = 10.0
color = "#fefefe"
icon = "/some/image.png" # optional
label = "My Button" # optional
fontsize = 10.0 # optional
color = "#fefefe" # optional
```

The config options `icon`, `label`, and `fontsize` are optional.

#### Recent Window (requires X11)

Displays the icon of a recently used window/application. Pressing the button
activates the window.

```
```toml
[keys.widget]
id = "recentWindow"
[keys.widget.config]
Expand All @@ -153,13 +151,13 @@ activates the window.

A flexible widget that can display the current time or date.

```
```toml
[keys.widget]
id = "time"
[keys.widget.config]
format = "%H;%i;%s"
font = "bold;regular;thin"
color = "#fefefe"
font = "bold;regular;thin" # optional
color = "#fefefe" # optional
```

Values for `format` are:
Expand All @@ -185,36 +183,36 @@ Values for `format` are:

This widget shows the current CPU or memory utilization as a bar graph.

```
```toml
[keys.widget]
id = "top"
[keys.widget.config]
mode = "cpu"
color = "#fefefe"
fillColor = "#d497de"
color = "#fefefe" # optional
fillColor = "#d497de" # optional
```

There are two values for `mode`: `cpu` and `memory`. The config option
`fillColor` is optional.
There are two values for `mode`: `cpu` and `memory`.

#### Command

A widget that displays the output of commands.

```
```toml
[keys.widget]
id = "command"
[keys.widget.config]
command = "echo 'Files:'; ls -a ~ | wc -l"
font = "regular;bold"
font = "regular;bold" # optional
color = "#fefefe" # optional
```

### Background Image

You can configure each deck to display an individual wallpaper behind its
widgets:

```
```toml
background = "/some/image.png"
```

Expand All @@ -224,21 +222,21 @@ You can hook up any key with several actions:

#### Run a command

```
```toml
[keys.action]
exec = "some_command --with-parameters"
```

#### Emulate key-presses

```
```toml
[keys.action]
keycode = "Leftctrl-C"
```

Emulate a series of key-presses with delay in between:

```
```toml
[keys.action]
keycode = "Leftctrl-X+500 / Leftctrl-V / Num1"
```
Expand All @@ -247,14 +245,14 @@ A list of available keycodes can be found here: [keycodes](https://github.com/mu

#### Paste to clipboard

```
```toml
[keys.action]
paste = "a text"
```

#### Trigger a dbus call

```
```toml
[keys.action]
[dbus]
object = "object"
Expand Down
13 changes: 0 additions & 13 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"image/color"
"io/ioutil"
"math"
"reflect"
"strconv"

Expand Down Expand Up @@ -130,18 +129,6 @@ func ConfigValue(v interface{}, dst interface{}) error {

case *color.Color:
switch vt := v.(type) {
case int64:
x := math.Min(1.0, math.Max(0.0, float64(vt)/255))
*d = colorful.Color{x, x, x}
case float64:
x := math.Min(1.0, math.Max(0.0, vt/255))
*d = colorful.Color{x, x, x}
case bool:
if vt {
*d = colorful.Color{1.0, 1.0, 1.0}
} else {
*d = colorful.Color{0.0, 0.0, 0.0}
}
case string:
x, _ := colorful.Hex(vt)
*d = x
Expand Down
11 changes: 11 additions & 0 deletions widget_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"image"
"image/color"
"os/exec"
"strings"

Expand All @@ -12,8 +13,10 @@ import (
// CommandWidget is a widget displaying the output of command(s).
type CommandWidget struct {
BaseWidget

command string
font string
color color.Color
}

// NewCommandWidget returns a new CommandWidget.
Expand All @@ -23,11 +26,14 @@ func NewCommandWidget(bw BaseWidget, opts WidgetConfig) *CommandWidget {
var command, font string
_ = ConfigValue(opts.Config["command"], &command)
_ = ConfigValue(opts.Config["font"], &font)
var color color.Color
_ = ConfigValue(opts.Config["color"], &color)

return &CommandWidget{
BaseWidget: bw,
command: command,
font: font,
color: color,
}
}

Expand All @@ -48,6 +54,10 @@ func (w *CommandWidget) Update(dev *streamdeck.Device) error {
fonts = append(fonts, "regular")
}

if w.color == nil {
w.color = DefaultColor
}

for i := 0; i < len(commands); i++ {
str, err := runCommand(commands[i])
if err != nil {
Expand All @@ -62,6 +72,7 @@ func (w *CommandWidget) Update(dev *streamdeck.Device) error {
str,
dev.DPI,
-1,
w.color,
image.Pt(-1, -1))
}

Expand Down

0 comments on commit 272f939

Please sign in to comment.