some initial examples

This commit is contained in:
2025-08-14 14:16:17 +02:00
parent 3221777622
commit a09b04ab7a
5 changed files with 771 additions and 0 deletions

View File

@@ -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)
}

View File

@@ -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)
}
}

View File

@@ -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

24
_examples/tree/main.go Normal file
View File

@@ -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)
}

346
_examples/tree/tree.json Normal file
View File

@@ -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