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. Add blocks that represent opened apps and create a task bar.
``` ```
[workspace_apps_0] [workspace_apps]
command=/path/to/workspace_apps 0 $BLOCK_BUTTON command=/path/to/workspace_apps -x=$relative_x
format=json format=json
markup=pango markup=pango
interval=1 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" "encoding/json"
"fmt" "fmt"
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os" // "os"
"flag"
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
@ -117,50 +118,56 @@ func main() {
tree := GetTree() tree := GetTree()
nodes := GetVisibleNodes(tree, workspaces) nodes := GetVisibleNodes(tree, workspaces)
appNumber, _ := strconv.Atoi(os.Args[1]) argX := flag.String("x", "", "")
blockButton := "" flag.Parse()
for k, v := range os.Args { x := 0
if k == 2 { minX := 0
blockButton = v
} if *argX != "" {
x, _ = strconv.Atoi(*argX)
} }
for key, app := range nodes { options := r.NewBlockOptions()
if key == appNumber {
foreground := "#9cb7d1"
background := "#222222"
if app.Urgent { for _, app := range nodes {
foreground = "#ffffff" foreground := "#9cb7d1"
background = "#07c0d4" background := "#222222"
} else if app.Focused {
foreground = "#07c0d4"
background = "#333333"
} else if app.Output == "__i3" {
foreground = "#bababa"
}
fb := r.FB{ title := strings.ToUpper(app.WindowProperties.Title)
Foreground: foreground,
Background: background,
}
title := strings.ToUpper(app.WindowProperties.Title) size := (len(title) + 2) * 4
maxX := minX + size
isClicked := (x > minX && x < maxX)
if len(title) > 25 { if len(title) > 30 {
title = fmt.Sprintf("%s…", title[0:22]) title = fmt.Sprintf("%s…", title[0:29])
}
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 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)
} }