summaryrefslogtreecommitdiff
path: root/stuff.go
blob: d3e5debf8f60a1212ee0ba2093612214f6fabbc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main

import (
	"fmt"
	"os"
	"os/exec"
	"time"

	"github.com/BurntSushi/xgb"
	"github.com/BurntSushi/xgb/xproto"
	"go.wit.com/log"
)

func main() {
	conn, err := xgb.NewConn()
	if err != nil {
		fmt.Println("Failed to connect to X server:", err)
		os.Exit(1)
	}
	defer conn.Close()

	// 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)
		}
	}()

	// Wait for the window to appear
	time.Sleep(2 * time.Second)

	// 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 {
		nameReply, err := xproto.GetProperty(conn, false, child,
			xproto.AtomWmName, xproto.AtomString, 0, (1<<32)-1).Reply()
		if err != nil || len(nameReply.Value) == 0 {
			continue
		}

		name := string(nameReply.Value)
		log.Info("found name:", name)
		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.")
}