From 2cd37bbda49708b5056e208ebe092d425204d075 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 30 Aug 2022 22:42:10 +0200 Subject: [PATCH] update block workspace_apps to show every apps in one call --- README.md | 12 +---- blocks/workspace_apps/main.go | 83 +++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 705007a..ef1e85e 100644 --- a/README.md +++ b/README.md @@ -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 - -... ``` diff --git a/blocks/workspace_apps/main.go b/blocks/workspace_apps/main.go index 91bcf79..48901f9 100644 --- a/blocks/workspace_apps/main.go +++ b/blocks/workspace_apps/main.go @@ -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) }