update block workspace_apps to show every apps in one call
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Simon Vieille 2022-08-30 22:42:10 +02:00
parent f1771fe367
commit 2cd37bbda4
Signed by: deblan
GPG key ID: 579388D585F70417
2 changed files with 47 additions and 48 deletions

View file

@ -210,17 +210,9 @@ interval=2
Add blocks that represent opened apps and create a task bar.
```
[workspace_apps_0]
command=/path/to/workspace_apps 0 $BLOCK_BUTTON
[workspace_apps]
command=/path/to/workspace_apps -x=$relative_x
format=json
markup=pango
interval=1
[workspace_apps_1]
command=/path/to/workspace_apps 1 $BLOCK_BUTTON
format=json
markup=pango
interval=1
...
```

View file

@ -4,7 +4,8 @@ import (
"encoding/json"
"fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os"
// "os"
"flag"
"os/exec"
"strconv"
"strings"
@ -117,50 +118,56 @@ func main() {
tree := GetTree()
nodes := GetVisibleNodes(tree, workspaces)
appNumber, _ := strconv.Atoi(os.Args[1])
blockButton := ""
argX := flag.String("x", "", "")
flag.Parse()
for k, v := range os.Args {
if k == 2 {
blockButton = v
}
x := 0
minX := 0
if *argX != "" {
x, _ = strconv.Atoi(*argX)
}
for key, app := range nodes {
if key == appNumber {
foreground := "#9cb7d1"
background := "#222222"
options := r.NewBlockOptions()
if app.Urgent {
foreground = "#ffffff"
background = "#07c0d4"
} else if app.Focused {
foreground = "#07c0d4"
background = "#333333"
} else if app.Output == "__i3" {
foreground = "#bababa"
}
for _, app := range nodes {
foreground := "#9cb7d1"
background := "#222222"
fb := r.FB{
Foreground: foreground,
Background: background,
}
title := strings.ToUpper(app.WindowProperties.Title)
title := strings.ToUpper(app.WindowProperties.Title)
size := (len(title) + 2) * 4
maxX := minX + size
isClicked := (x > minX && x < maxX)
if len(title) > 25 {
title = fmt.Sprintf("%s…", title[0:22])
}
options := r.NewBlockOptions()
options.FullText = r.TextWithPadding(title, fb)
block := r.Block(fmt.Sprintf("workspace_apps_%d", appNumber), options)
fmt.Println(block)
if blockButton == "1" {
Focus(app.Window)
}
if len(title) > 30 {
title = fmt.Sprintf("%s…", title[0:29])
}
if app.Urgent {
foreground = "#ffffff"
background = "#07c0d4"
} else if app.Focused || isClicked {
foreground = "#07c0d4"
background = "#333333"
} else if app.Output == "__i3" {
foreground = "#bababa"
}
if isClicked {
Focus(app.Window)
}
fb := r.FB{
Foreground: foreground,
Background: background,
}
options.FullText = fmt.Sprintf("%s%s", options.FullText, r.TextWithPadding(title, fb))
minX = maxX
}
block := r.Block("workspace_apps", options)
fmt.Println(block)
}