From a09b04ab7a5fbf78f08c892cbb0794213e5872de Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Thu, 14 Aug 2025 14:16:17 +0200 Subject: [PATCH] some initial examples --- _examples/current_workspace/main.go | 26 +++ _examples/focusedwindow/main.go | 29 +++ _examples/focusedwindow/tree.json | 346 ++++++++++++++++++++++++++++ _examples/tree/main.go | 24 ++ _examples/tree/tree.json | 346 ++++++++++++++++++++++++++++ 5 files changed, 771 insertions(+) create mode 100644 _examples/current_workspace/main.go create mode 100644 _examples/focusedwindow/main.go create mode 100644 _examples/focusedwindow/tree.json create mode 100644 _examples/tree/main.go create mode 100644 _examples/tree/tree.json diff --git a/_examples/current_workspace/main.go b/_examples/current_workspace/main.go new file mode 100644 index 0000000..e023164 --- /dev/null +++ b/_examples/current_workspace/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "log" + + "github.com/tlinden/i3ipc" +) + +func main() { + ipc := i3ipc.NewI3ipc("SWAYSOCK") + + err := ipc.Connect() + if err != nil { + log.Fatal(err) + } + + tree, err := ipc.GetTree() + if err != nil { + log.Fatal(err) + } + + workspace := tree.FindCurrentWorkspace() + + fmt.Printf("current workspace: %s\n", workspace) +} diff --git a/_examples/focusedwindow/main.go b/_examples/focusedwindow/main.go new file mode 100644 index 0000000..06f57a7 --- /dev/null +++ b/_examples/focusedwindow/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "log" + + "github.com/tlinden/i3ipc" +) + +func main() { + ipc := i3ipc.NewI3ipc("SWAYSOCK") + + err := ipc.Connect() + if err != nil { + log.Fatal(err) + } + + tree, err := ipc.GetTree() + if err != nil { + log.Fatal(err) + } + + focused := tree.FindFocused() + + if focused != nil { + fmt.Printf("focused node: %s\n id: %d\n Geometry: %dx%d\n", + focused.Name, focused.Id, focused.Geometry.Width, focused.Geometry.Height) + } +} diff --git a/_examples/focusedwindow/tree.json b/_examples/focusedwindow/tree.json new file mode 100644 index 0000000..24eaa5a --- /dev/null +++ b/_examples/focusedwindow/tree.json @@ -0,0 +1,346 @@ +&i3ipc.Node{ + Id: 1, + Type: "root", + Name: "root", + Nodes: []*i3ipc.Node{ + { + Id: 2147483647, + Type: "output", + Name: "__i3", + Nodes: []*i3ipc.Node{ + { + Id: 2147483646, + Type: "workspace", + Name: "__i3_scratch", + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Rect: i3ipc.Rect{ + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "output", + Orientation: "horizontal", + Focus: []int{ + 2147483646, + }, + Rect: i3ipc.Rect{ + Width: 3440, + }, + }, + { + Id: 4, + Type: "output", + Name: "HDMI-A-1", + Nodes: []*i3ipc.Node{ + { + Id: 7, + Type: "workspace", + Name: "2", + Nodes: []*i3ipc.Node{ + { + Id: 8, + Type: "con", + Name: "Terminal - 1:2:sh - \"tripod\" ", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.21511628, + X11Window: "xfce4-terminal", + Rect: i3ipc.Rect{ + Y: 26, + Width: 740, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 736, + }, + Geometry: i3ipc.Rect{ + Width: 882, + }, + }, + { + Id: 10, + Type: "con", + Name: "postgreslet - F-I-TS-Chat - Chromium", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.78488374, + Window: 4194311, + Rect: i3ipc.Rect{ + X: 740, + Y: 26, + Width: 2700, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 2696, + }, + Geometry: i3ipc.Rect{ + Width: 1142, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 10, + 8, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 11, + Type: "workspace", + Name: "3", + Nodes: []*i3ipc.Node{ + { + Id: 14, + Type: "con", + Name: "AdZ Desktop (SSL/TLS Secured, 256 bit)", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.3604651, + Window: 14680067, + Rect: i3ipc.Rect{ + Y: 26, + Width: 1240, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 1236, + }, + Geometry: i3ipc.Rect{ + Width: 2752, + }, + }, + { + Id: 12, + Type: "con", + Name: "E-Mail – Thomas.vonDein@f-i-ts.de - Chromium", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.6395349, + Window: 4194324, + Rect: i3ipc.Rect{ + X: 1240, + Y: 26, + Width: 2200, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 2196, + }, + Geometry: i3ipc.Rect{ + Width: 1142, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 12, + 14, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 15, + Type: "workspace", + Name: "4", + Nodes: []*i3ipc.Node{ + { + Id: 16, + Type: "con", + Name: "AR System Customizable Home Page (Suchen) - Chromium", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 1, + Window: 4194338, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + WindowRect: i3ipc.Rect{ + Width: 3440, + }, + Geometry: i3ipc.Rect{ + Width: 1142, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 16, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 17, + Type: "workspace", + Name: "5", + Nodes: []*i3ipc.Node{ + { + Id: 19, + Type: "con", + Name: "Terminal - 0:5:go - \"tripod\" ", + Focused: true, + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.50581396, + X11Window: "xfce4-terminal", + Rect: i3ipc.Rect{ + Y: 26, + Width: 1740, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 1736, + }, + Geometry: i3ipc.Rect{ + Width: 882, + }, + }, + { + Id: 18, + Type: "con", + Name: "emacs /home/scip/dev/i3ipc/_examples/tree/main.go", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.49418604, + Window: 18874540, + Rect: i3ipc.Rect{ + X: 1740, + Y: 26, + Width: 1700, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 1696, + }, + Geometry: i3ipc.Rect{ + Width: 752, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 19, + 18, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 20, + Type: "workspace", + Name: "6", + FloatingNodes: []*i3ipc.Node{ + { + Id: 21, + Type: "floating_con", + Name: "Home - Webex - Google Chrome", + Border: "csd", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.7971424, + X11Window: "google-chrome", + Rect: i3ipc.Rect{ + X: 481, + Y: 35, + Width: 2822, + }, + WindowRect: i3ipc.Rect{ + Width: 2822, + }, + Geometry: i3ipc.Rect{ + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 21, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "output", + Orientation: "none", + Percent: 1, + Focus: []int{ + 17, + 7, + 20, + 11, + 15, + }, + Current_workspace: "5", + Rect: i3ipc.Rect{ + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 4, + }, + Rect: i3ipc.Rect{ + Width: 3440, + }, +} +root: root +node: __i3 + focus: false +recursing +node: __i3_scratch + focus: false +recursing +nil diff --git a/_examples/tree/main.go b/_examples/tree/main.go new file mode 100644 index 0000000..7323a71 --- /dev/null +++ b/_examples/tree/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alecthomas/repr" + "github.com/tlinden/i3ipc" +) + +func main() { + ipc := i3ipc.NewI3ipc("SWAYSOCK") + + err := ipc.Connect() + if err != nil { + log.Fatal(err) + } + + tree, err := ipc.GetTree() + if err != nil { + log.Fatal(err) + } + + repr.Println(tree) +} diff --git a/_examples/tree/tree.json b/_examples/tree/tree.json new file mode 100644 index 0000000..24eaa5a --- /dev/null +++ b/_examples/tree/tree.json @@ -0,0 +1,346 @@ +&i3ipc.Node{ + Id: 1, + Type: "root", + Name: "root", + Nodes: []*i3ipc.Node{ + { + Id: 2147483647, + Type: "output", + Name: "__i3", + Nodes: []*i3ipc.Node{ + { + Id: 2147483646, + Type: "workspace", + Name: "__i3_scratch", + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Rect: i3ipc.Rect{ + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "output", + Orientation: "horizontal", + Focus: []int{ + 2147483646, + }, + Rect: i3ipc.Rect{ + Width: 3440, + }, + }, + { + Id: 4, + Type: "output", + Name: "HDMI-A-1", + Nodes: []*i3ipc.Node{ + { + Id: 7, + Type: "workspace", + Name: "2", + Nodes: []*i3ipc.Node{ + { + Id: 8, + Type: "con", + Name: "Terminal - 1:2:sh - \"tripod\" ", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.21511628, + X11Window: "xfce4-terminal", + Rect: i3ipc.Rect{ + Y: 26, + Width: 740, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 736, + }, + Geometry: i3ipc.Rect{ + Width: 882, + }, + }, + { + Id: 10, + Type: "con", + Name: "postgreslet - F-I-TS-Chat - Chromium", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.78488374, + Window: 4194311, + Rect: i3ipc.Rect{ + X: 740, + Y: 26, + Width: 2700, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 2696, + }, + Geometry: i3ipc.Rect{ + Width: 1142, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 10, + 8, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 11, + Type: "workspace", + Name: "3", + Nodes: []*i3ipc.Node{ + { + Id: 14, + Type: "con", + Name: "AdZ Desktop (SSL/TLS Secured, 256 bit)", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.3604651, + Window: 14680067, + Rect: i3ipc.Rect{ + Y: 26, + Width: 1240, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 1236, + }, + Geometry: i3ipc.Rect{ + Width: 2752, + }, + }, + { + Id: 12, + Type: "con", + Name: "E-Mail – Thomas.vonDein@f-i-ts.de - Chromium", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.6395349, + Window: 4194324, + Rect: i3ipc.Rect{ + X: 1240, + Y: 26, + Width: 2200, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 2196, + }, + Geometry: i3ipc.Rect{ + Width: 1142, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 12, + 14, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 15, + Type: "workspace", + Name: "4", + Nodes: []*i3ipc.Node{ + { + Id: 16, + Type: "con", + Name: "AR System Customizable Home Page (Suchen) - Chromium", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 1, + Window: 4194338, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + WindowRect: i3ipc.Rect{ + Width: 3440, + }, + Geometry: i3ipc.Rect{ + Width: 1142, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 16, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 17, + Type: "workspace", + Name: "5", + Nodes: []*i3ipc.Node{ + { + Id: 19, + Type: "con", + Name: "Terminal - 0:5:go - \"tripod\" ", + Focused: true, + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.50581396, + X11Window: "xfce4-terminal", + Rect: i3ipc.Rect{ + Y: 26, + Width: 1740, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 1736, + }, + Geometry: i3ipc.Rect{ + Width: 882, + }, + }, + { + Id: 18, + Type: "con", + Name: "emacs /home/scip/dev/i3ipc/_examples/tree/main.go", + Border: "pixel", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.49418604, + Window: 18874540, + Rect: i3ipc.Rect{ + X: 1740, + Y: 26, + Width: 1700, + }, + WindowRect: i3ipc.Rect{ + X: 2, + Y: 2, + Width: 1696, + }, + Geometry: i3ipc.Rect{ + Width: 752, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 19, + 18, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + { + Id: 20, + Type: "workspace", + Name: "6", + FloatingNodes: []*i3ipc.Node{ + { + Id: 21, + Type: "floating_con", + Name: "Home - Webex - Google Chrome", + Border: "csd", + Layout: "none", + Orientation: "none", + CurrentBorderWidth: 2, + Percent: 0.7971424, + X11Window: "google-chrome", + Rect: i3ipc.Rect{ + X: 481, + Y: 35, + Width: 2822, + }, + WindowRect: i3ipc.Rect{ + Width: 2822, + }, + Geometry: i3ipc.Rect{ + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 21, + }, + Rect: i3ipc.Rect{ + Y: 26, + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "output", + Orientation: "none", + Percent: 1, + Focus: []int{ + 17, + 7, + 20, + 11, + 15, + }, + Current_workspace: "5", + Rect: i3ipc.Rect{ + Width: 3440, + }, + }, + }, + Border: "none", + Layout: "splith", + Orientation: "horizontal", + Focus: []int{ + 4, + }, + Rect: i3ipc.Rect{ + Width: 3440, + }, +} +root: root +node: __i3 + focus: false +recursing +node: __i3_scratch + focus: false +recursing +nil