Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status file to track desktop tiling state #46

Merged
merged 2 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type cfg struct {
WindowsToIgnore []string `toml:"ignore"`
Gap int
Proportion float64
HideDecor bool `toml:"remove_decorations"`
TileStartup []int `toml:"tile_workspaces"`
TileStartup []int `toml:"tile_workspaces"`
HideDecor bool `toml:"remove_decorations"`
StatusFname string `toml:"status_filename"`
}

func init() {
Expand Down Expand Up @@ -78,6 +79,10 @@ proportion = 0.1
# list of workspace numbers to activate tiling for at startup
# tile_workspaces = [0, 1, 3]

# write out tiling status as it changes (optional)
# use the full path to the file
# status_filename = "/full/path/to/file"

[keybindings]
# key sequences can have zero or more modifiers and exactly one key.
# example: Control-Shift-t has two modifiers and one key.
Expand Down
3 changes: 3 additions & 0 deletions keybinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ func bindKeys(t *tracker) {
workspaces := t.workspaces
keybind.Initialize(state.X)
k := keyMapper{}
generateStatus(t)

k.bind("tile", func() {
ws := workspaces[state.CurrentDesk]
ws.IsTiling = true
ws.Tile()
generateStatus(t)
})
k.bind("untile", func() {
ws := workspaces[state.CurrentDesk]
ws.Untile()
generateStatus(t)
})
k.bind("make_active_window_master", func() {
c := t.clients[state.ActiveWin]
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"encoding/json"
"flag"
"os"

"github.com/BurntSushi/xgbutil/xevent"
"github.com/blrsn/zentile/state"
Expand Down Expand Up @@ -32,6 +34,20 @@ func main() {
xevent.Main(state.X)
}

func generateStatus(t *tracker) {
fname := Config.StatusFname
if fname == "" {
return
}

blob, _ := json.MarshalIndent(t.workspaces, "", " ")
os.Create(fname)
err := os.WriteFile(fname, blob, 0600)
if err != nil {
log.Fatal(err)
}
}

func setLogLevel() {
var verbose bool
flag.BoolVar(&verbose, "v", false, "verbose mode")
Expand Down