How can I stack a window on top of the one further on the right? #1312
Unanswered
stefanopagliari
asked this question in
Q&A
Replies: 2 comments 9 replies
-
I ended up using this but I'm sure some more elegant solutions exist:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Here you go, I added two focus commands to fix the ID glitch that happens when new stack is created: package main
import (
"encoding/json"
"io"
"net"
"os"
"os/user"
"strconv"
"strings"
)
type window struct {
ID int `json:"id"`
IsVisible bool `json:"is-visible"`
SplitType string `json:"split-type"`
}
type space struct {
LastWindow int `json:"last-window"`
}
func main() {
newId := os.Args[1]
newIdInt, _ := strconv.Atoi(newId)
u, _ := user.Current()
addr := "/tmp/yabai_" + u.Username + ".socket"
var w []window
c, _ := net.Dial("unix", addr)
c.Write([]byte("query\x00--windows\x00--space\x00\x00"))
r, _ := io.ReadAll(c)
json.Unmarshal(r, &w)
var n int
for _, v := range w {
if v.IsVisible {
n++
}
}
if n <= 3 {
for _, v := range w {
if v.ID == newIdInt && v.SplitType == "horizontal" {
s := strings.Join([]string{"window", newId, "--toggle", "split", "\x00"}, "\x00")
c, _ = net.Dial("unix", addr)
c.Write([]byte(s))
s = strings.Join([]string{"space", "--balance", "\x00"}, "\x00")
c, _ = net.Dial("unix", addr)
_, _ = c.Write([]byte(s))
return
} else {
s := strings.Join([]string{"space", "--balance", "\x00"}, "\x00")
c, _ = net.Dial("unix", addr)
_, _ = c.Write([]byte(s))
return
}
}
}
if n > 3 {
var sp space
c, _ = net.Dial("unix", addr)
c.Write([]byte("query\x00--spaces\x00--space\x00\x00"))
r, _ = io.ReadAll(c)
json.Unmarshal(r, &sp)
targetWindow := strconv.Itoa(sp.LastWindow)
if newIdInt == sp.LastWindow {
targetWindow = "prev"
}
c, _ = net.Dial("unix", addr)
s := strings.Join([]string{"window", targetWindow, "--stack", newId, "\x00"}, "\x00")
c.Write([]byte(s))
c, _ = net.Dial("unix", addr)
s = strings.Join([]string{"window", "--focus", "stack.prev", "\x00"}, "\x00")
c.Write([]byte(s))
c, _ = net.Dial("unix", addr)
s = strings.Join([]string{"window", "--focus", "stack.next", "\x00"}, "\x00")
c.Write([]byte(s))
}
} |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a widescreen monitor and I usually stack on the right end of the monitor apps that are not the main activity I'm working on the moment (e.g. email, calendar, etc...).
Is there a way to set a key so that a newly opened app is stacked upon the app on the right?
Beta Was this translation helpful? Give feedback.
All reactions