2024-11-24 06:57:05 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2024-11-24 09:46:07 -06:00
|
|
|
"reflect"
|
2024-11-24 06:57:05 -06:00
|
|
|
|
|
|
|
"github.com/BurntSushi/xgb"
|
|
|
|
"github.com/BurntSushi/xgb/xproto"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
conn, err := xgb.NewConn()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Failed to connect to X server:", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
2024-11-24 09:46:07 -06:00
|
|
|
/*
|
|
|
|
// Start the terminal (replace with your app)
|
|
|
|
go func() {
|
|
|
|
if err := exec.Command("mate-terminal", "--title", "Workspace1-Terminal").Start(); err != nil {
|
|
|
|
fmt.Println("Error starting terminal:", err)
|
|
|
|
}
|
|
|
|
}()
|
2024-11-24 06:57:05 -06:00
|
|
|
|
2024-11-24 09:46:07 -06:00
|
|
|
// Wait for the window to appear
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
*/
|
2024-11-24 06:57:05 -06:00
|
|
|
|
|
|
|
// Get the root window
|
|
|
|
setup := xproto.Setup(conn)
|
|
|
|
root := setup.DefaultScreen(conn).Root
|
|
|
|
|
|
|
|
// List children windows
|
|
|
|
reply, err := xproto.QueryTree(conn, root).Reply()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Failed to query windows:", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the window with the specified title
|
|
|
|
var target xproto.Window
|
|
|
|
for _, child := range reply.Children {
|
2024-11-24 09:46:07 -06:00
|
|
|
// fmt.Printf("child: %+v\n", child)
|
|
|
|
/*
|
|
|
|
// Get the atom for _NET_WM_NAME
|
|
|
|
atomReply, err := xproto.InternAtom(conn, true, uint16(len("_NET_WM_NAME")), "_NET_WM_NAME").Reply()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to intern atom _NET_WM_NAME: %v", err)
|
|
|
|
}
|
|
|
|
netWmNameAtom := atomReply.Atom // Correct field to use
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Get the property for _NET_WM_NAME
|
|
|
|
nameReply, err := xproto.GetProperty(conn, false, child, netWmNameAtom, xproto.AtomString, 0, (1<<32)-1).Reply()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to get property _NET_WM_NAME: %v", err)
|
|
|
|
} else if len(nameReply.Value) > 0 {
|
|
|
|
fmt.Printf("Window name: %s\n", string(nameReply.Value))
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Get the atom for _NET_WM_NAME
|
|
|
|
atomReply, err := xproto.InternAtom(conn, true, uint16(len("_NET_WM_NAME")), "_NET_WM_NAME").Reply()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to intern atom _NET_WM_NAME: %v", err)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("found atomic name: %s\n", string(atomReply.Value))
|
|
|
|
}
|
|
|
|
netWmNameAtom := atomReply.Atom
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Get the property for _NET_WM_NAME
|
|
|
|
nameReply, err := xproto.GetProperty(conn, false, child, netWmNameAtom, xproto.AtomString, 0, (1<<32)-1).Reply()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to get property _NET_WM_NAME: %v", err)
|
|
|
|
} else if len(nameReply.Value) > 0 {
|
|
|
|
fmt.Printf("Window name: %s\n", string(nameReply.Value))
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var test xproto.Drawable
|
|
|
|
geomReply, err := xproto.GetGeometry(conn, test).Reply()
|
|
|
|
if err != nil {
|
|
|
|
// fmt.Printf("err: %+v\n", err)
|
|
|
|
// fmt.Printf("child geomReply: %+v\n", geomReply)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("child geomReply: %+v\n", geomReply)
|
|
|
|
}
|
|
|
|
|
|
|
|
nameReply, err := xproto.GetProperty(conn, false, child, xproto.AtomWmName, xproto.AtomString, 0, (1<<32)-1).Reply()
|
|
|
|
if err != nil {
|
|
|
|
// fmt.Printf("child err: %+v\n", err)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("child %+v nameReply: %+v %s\n", reflect.TypeOf(child), nameReply, string(nameReply.Value))
|
|
|
|
}
|
2024-11-24 06:57:05 -06:00
|
|
|
if err != nil || len(nameReply.Value) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
name := string(nameReply.Value)
|
|
|
|
if name == "Workspace1-Terminal" {
|
|
|
|
target = child
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if target == 0 {
|
|
|
|
fmt.Println("Window not found.")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move the window to workspace 1 and set its geometry
|
|
|
|
xproto.ConfigureWindow(conn, target, xproto.ConfigWindowX|xproto.ConfigWindowY|xproto.ConfigWindowWidth|xproto.ConfigWindowHeight,
|
|
|
|
[]uint32{100, 100, 800, 600})
|
|
|
|
fmt.Println("Window moved and resized.")
|
|
|
|
}
|