28 lines
646 B
Go
28 lines
646 B
Go
|
package scratchpad
|
||
|
|
||
|
import "github.com/mdirkse/i3ipc"
|
||
|
|
||
|
import "gitea.ashishdsouza.com/ashish/i3-last-scratchpad/notify"
|
||
|
|
||
|
|
||
|
func GetLastScratchpadNode(ipcSocket *i3ipc.IPCSocket) *i3ipc.I3Node {
|
||
|
var root, err = ipcSocket.GetTree()
|
||
|
if err != nil {
|
||
|
notify.SendNotification("Failed to fetch layout tree", notify.CriticalPriority)
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
var leaves = root.Leaves()
|
||
|
for i := len(leaves) - 1; i >= 0; i-- {
|
||
|
if leaves[i].Parent == nil {
|
||
|
notify.FatalNotification("Leaf node nas no parent")
|
||
|
}
|
||
|
|
||
|
// https://i3wm.org/docs/ipc.html#_tree_reply
|
||
|
if leaves[i].Parent.Scratchpad_State != "none" {
|
||
|
return leaves[i]
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|