Guest User

Untitled

a guest
Jul 10th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.07 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4. import "errors"
  5. import "code.google.com/p/x-go-binding/xgb"
  6.  
  7. func main() {
  8.     // open the connection to the default X server
  9.     display, err := xgb.Dial("")
  10.     if err != nil {
  11.         panic(errors.New("unable to open X server"))
  12.     }
  13.  
  14.     // get the root window
  15.     screen := display.DefaultScreen()
  16.     root := screen.Root
  17.  
  18.     // intern the "WM_NAME" atom    
  19.     atomTitle, err := display.InternAtom(false, "WM_NAME")
  20.     if err != nil {
  21.         panic(errors.New("unable to intern WM_NAME"))
  22.     }
  23.  
  24.     // get the list of windows
  25.     tree, err := display.QueryTree(root)
  26.     if err != nil {
  27.         panic(errors.New("unable to get the tree of windows"))
  28.     }
  29.  
  30.     // display the title and ID of each window
  31.     for _, child := range tree.Children {
  32.         title, err := display.GetProperty(false, child, atomTitle.Atom, xgb.GetPropertyTypeAny, 0, 1024)
  33.         if err != nil {
  34.             panic(errors.New("unable to get window title"))
  35.         }
  36.         fmt.Println("found window", child, string(title.Value))
  37.     }
  38. }
Add Comment
Please, Sign In to add comment