func connect() { var err error conn, err = xgb.Dial("") if err != nil { l.Fatal("Can't connect to display: ", err) } screen = conn.DefaultScreen() r, err := conn.GetKeyboardMapping( conn.Setup.MinKeycode, conn.Setup.MaxKeycode-conn.Setup.MinKeycode+1, ) if err != nil { l.Fatal("Can't get keybboard mapping: ", err) } // Setup keycode <-> keysym mapping minKeycode := conn.Setup.MinKeycode codeNum := int(r.Length) / int(r.KeysymsPerKeycode) keyCodeToSym = make([]xgb.Keysym, int(minKeycode)+codeNum) keySymToCode = make(map[xgb.Keysym]byte) for i := 0; i < codeNum; i++ { s := r.Keysyms[i*int(r.KeysymsPerKeycode)] keyCodeToSym[byte(i)+minKeycode] = s keySymToCode[s] = byte(i) + minKeycode } }
func main() { c, err := xgb.Dial("") if err != nil { fmt.Println(err) return } defer c.Close() for { hostname, err := os.Hostname() if err != nil { hostname = "<hostname unavailable>" } t := time.Now().Format("03:04 2 Jan 2006") title := fmt.Sprintf("%s %s ", hostname, t) c.ChangeProperty( xgb.PropModeReplace, c.DefaultScreen().Root, xgb.AtomWmName, xgb.AtomString, 8, []byte(title)) time.Sleep(time.Minute) } }
func connectToX() { lprintf("connecting to %v", envdisplay) var err error conn, err = xgb.Dial(envdisplay) if err != nil { lfatalf("%v", err) } lprintf("connected to %v", envdisplay) }
func main() { c, err := xgb.Dial(os.Getenv("DISPLAY")) if err != nil { fmt.Printf("cannot connect: %v\n", err) os.Exit(1) } fmt.Printf("vendor = '%s'\n", string(c.Setup.Vendor)) win := c.NewId() gc := c.NewId() c.CreateWindow(0, win, c.DefaultScreen().Root, 150, 150, 200, 200, 0, 0, 0, 0, nil) c.ChangeWindowAttributes(win, xgb.CWEventMask, []uint32{xgb.EventMaskExposure | xgb.EventMaskKeyRelease}) c.CreateGC(gc, win, 0, nil) c.MapWindow(win) atom, _ := c.InternAtom(false, "HELLO") fmt.Printf("atom = %d\n", atom.Atom) points := make([]xgb.Point, 2) points[0] = xgb.Point{5, 5} points[1] = xgb.Point{100, 120} hosts, _ := c.ListHosts() fmt.Printf("hosts = %+v\n", hosts) ecookie := c.ListExtensionsRequest() exts, _ := c.ListExtensionsReply(ecookie) for _, name := range exts.Names { fmt.Printf("exts = '%s'\n", name.Name) } for { reply, err := c.WaitForEvent() if err != nil { fmt.Printf("error: %v\n", err) os.Exit(1) } fmt.Printf("event %T\n", reply) switch event := reply.(type) { case xgb.ExposeEvent: c.PolyLine(xgb.CoordModeOrigin, win, gc, points) case xgb.KeyReleaseEvent: fmt.Printf("key release!\n") points[0].X = event.EventX points[0].Y = event.EventY c.PolyLine(xgb.CoordModeOrigin, win, gc, points) c.Bell(75) } } c.Close() }
func main() { c, err := xgb.Dial("") if err != nil { fmt.Println(err) return } defer c.Close() strBytes := []byte("Hello XGB!") rectangles := []xgb.Rectangle{{40, 40, 20, 20}} // get the first screen s := c.DefaultScreen() // root window win := s.Root // create black (foreground) graphic context fg := c.NewId() mask := uint32(xgb.GCForeground | xgb.GCGraphicsExposures) values := []uint32{s.BlackPixel, 0} c.CreateGC(fg, win, mask, values) // create white (background) graphic context bg := c.NewId() mask = uint32(xgb.GCBackground | xgb.GCGraphicsExposures) values[0] = s.WhitePixel // (values[1] still 0) c.CreateGC(bg, win, mask, values) // create the window win = c.NewId() mask = xgb.CWBackPixel | xgb.CWEventMask // values[0] still s.WhitePixel values[1] = xgb.EventMaskExposure | xgb.EventMaskKeyPress c.CreateWindow(0, win, s.Root, 0, 0, 150, 150, 10, xgb.WindowClassInputOutput, s.RootVisual, mask, values) c.MapWindow(win) for { event, err := c.WaitForEvent() if err != nil { fmt.Println(err) return } switch event.(type) { case xgb.ExposeEvent: c.PolyRectangle(win, fg, rectangles) c.ImageText8(win, bg, 20, 20, strBytes) case xgb.KeyPressEvent: return } } }
func main() { conn, err := xgb.Dial(":1") if err != nil { panic(err) } defer conn.Close() // height := int(conn.Setup.Roots[0].HeightInPixels) // width := int(conn.Setup.Roots[0].WidthInPixels) width := 1920 height := 1080 desktop := Desktop{width, height, 0, 0, 0, nil} s := conn.DefaultScreen() for _, v := range Shortcuts { conn.GrabKey(true, s.Root, v.Mod, v.Key, xgb.GrabModeAsync, xgb.GrabModeAsync) } conn.ChangeWindowAttributes(s.Root, xgb.CWEventMask, []uint32{xgb.EventMaskSubstructureRedirect}) for { event, _ := conn.WaitForEvent() switch ev := event.(type) { case xgb.KeyReleaseEvent: for _, v := range Shortcuts { if ev.Detail == v.Key { v.Function(conn) fmt.Println("shortcut hit:", v) } } case xgb.MapRequestEvent: if desktop.Head == 0 { desktop.Head = ev.Window } else if desktop.Clients == nil { desktop.Clients = []xgb.Id{ev.Window} } else { desktop.Clients = append(desktop.Clients, ev.Window) } desktop.Focus = ev.Window desktop.Tile(conn) conn.MapWindow(ev.Window) case xgb.DestroyNotifyEvent: fmt.Println("notify to destroy", ev) default: fmt.Println(reflect.TypeOf(ev)) } } }
func main() { str = "" c, err := xgb.Dial("") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } defer c.Close() createWindow(c) handleEvents(c) }
func NewInstance() *Jake_Graphics { jg := Jake_Graphics{m_c: nil} c, err := xgb.Dial(os.Getenv("DISPLAY")) if err != nil { fmt.Printf("Jake_Graphics: cannot connect to X server: '%v'\n", err) return nil } jg.m_c = c jg.m_keyCodeStart = int(jg.m_c.Setup.MinKeycode) jg.m_keyCodeEnd = int(jg.m_c.Setup.MaxKeycode) fmt.Printf("Jake_Graphics: keyCode:%d->%d\n", jg.m_keyCodeStart, jg.m_keyCodeEnd) return &jg }
func main() { logger := cabin.New() output := make(chan *cabin.Event) logger.Subscribe(output) go cabin.StdoutLogger(output) conn, err := xgb.Dial(os.Getenv("DISPLAY")) if err != nil { fmt.Printf("Failed to connect to the X Server (%s)\n", os.Getenv("DISPLAY")) os.Exit(1) } logger.Log("OK") logger.Log(conn) }
func main() { var err error display := os.Getenv("DISPLAY") conn, err = xgb.Dial(display) if err != nil { l.Fatal(err) } setupAtoms() root = Window(conn.DefaultScreen().Root) createWindow() tr, err := conn.QueryTree(root.Id()) for i, id := range append(tr.Children, root.Id()) { w := Window(id) inst, class := w.Class() tr, err := conn.QueryTree(id) if err != nil { l.Fatal("QueryTree: ", err) } wmName := w.Prop(AtomNetWmName, 128) info := struct { id, root, parent xgb.Id ch_num uint16 name, inst, class string g Geometry }{ id, tr.Root, tr.Parent, tr.ChildrenLen, string(wmName.Value), inst, class, Geometry{}, } var ok bool info.g, ok = w.Geometry() if !ok { return } fmt.Printf("%d: %+v\n", i, info) } }