func query(X *xgbutil.XUtil) xinerama.Heads { if X.ExtInitialized("XINERAMA") { heads, err := xinerama.PhysicalHeads(X) if err != nil || len(heads) == 0 { if err == nil { logger.Warning.Printf("Could not find any physical heads " + "with the Xinerama extension.") } else { logger.Warning.Printf("Could not load physical heads via "+ "Xinerama: %s", err) } logger.Warning.Printf("Assuming one head with size equivalent " + "to the root window.") } else { return heads } } // If we're here, then something went wrong or the Xinerama extension // isn't available. So query the root window for its geometry and use that. rgeom := xwindow.RootGeometry(X) return xinerama.Heads{ xrect.New(rgeom.X(), rgeom.Y(), rgeom.Width(), rgeom.Height()), } }
func headGeom(X *xgbutil.XUtil) xrect.Rect { if X.ExtInitialized("XINERAMA") { heads, err := xinerama.PhysicalHeads(X) if err == nil { return heads[0] } } geom, err := xwindow.New(X, X.RootWin()).Geometry() fatal(err) return geom }
func main() { X, _ := xgbutil.NewConn() heads, err := xinerama.PhysicalHeads(X) if err != nil { fmt.Printf("ERROR: %v\n", err) } // Test intersection r1 := xrect.New(0, 0, 100, 100) r2 := xrect.New(100, 100, 100, 100) fmt.Println(xrect.IntersectArea(r1, r2)) // Test largest overlap window := xrect.New(1800, 0, 300, 200) fmt.Println(xrect.LargestOverlap(window, heads)) // Test ApplyStrut rgeom, _ := xwindow.RawGeometry(X, xproto.Drawable(X.RootWin())) fmt.Println("---------------------------") for i, head := range heads { fmt.Printf("%d - %v\n", i, head) } // Let's actually apply struts to the current environment clients, _ := ewmh.ClientListGet(X) for _, client := range clients { strut, err := ewmh.WmStrutPartialGet(X, client) if err == nil { xrect.ApplyStrut(heads, rgeom.Width(), rgeom.Height(), strut.Left, strut.Right, strut.Top, strut.Bottom, strut.LeftStartY, strut.LeftEndY, strut.RightStartY, strut.RightEndY, strut.TopStartX, strut.TopEndX, strut.BottomStartX, strut.BottomEndX) } } fmt.Println("---------------------------") fmt.Println("After applying struts...") for i, head := range heads { fmt.Printf("%d - %v\n", i, head) } }
func main() { X, _ := xgbutil.NewConn() heads, err := xinerama.PhysicalHeads(X) if err != nil { fmt.Printf("ERROR: %v\n", err) } else { for i, head := range heads { fmt.Printf("%d - %v\n", i, head) } } wmName, err := ewmh.GetEwmhWM(X) if err != nil { fmt.Printf("ERROR: %v\n", err) } else { fmt.Printf("Window manager: %s\n", wmName) } }
func getViewport() (geom string) { // new X server connection X, err := xgbutil.NewConn() if err != nil { log.Error(err) } // get root window root := xwindow.New(X, X.RootWin()) // geometry of the root window rgeom, err := root.Geometry() if err != nil { log.Error(err) } // Get the rectangles for each of the active physical heads. // These are returned sorted in order from left to right and then top // to bottom. // But first check if Xinerama is enabled. If not, use root geometry. var heads xinerama.Heads if X.ExtInitialized("XINERAMA") { heads, err = xinerama.PhysicalHeads(X) if err != nil { log.Error(err) } } else { heads = xinerama.Heads{rgeom} } // looking for the first screen, position X: 0, Y: 0 for _, head := range heads { if head.X() == 0 && head.Y() == 0 { screenWidth = head.Width() screenHeight = head.Height() } } geom = fmt.Sprintf("%dx%d", screenWidth-165, screenHeight-165) return geom }
func main() { cfg := Config{} X, err := xgbutil.NewConn() utils.FailMeMaybe(err) heads, err := xinerama.PhysicalHeads(X) utils.FailMeMaybe(err) cfg.Width = heads[0].Width() cfg.ClockPos = (cfg.Width / 2) - 100 cfg.CommandWidth = (cfg.Width / 2) - 124 cfg.StatusPos = (cfg.Width / 2) + 100 // Look for ze fonts! cfg.ClockFont = "Put your font here!" cfg.CommandFont = cfg.ClockFont found := false for _, fontDir := range []string{"/usr/share/fonts/dejavu/", "/usr/share/fonts/TTF/"} { if exists(fontDir+"DejaVuSansMono-Bold.ttf") && exists(fontDir+"DejaVuSansMono.ttf") { cfg.ClockFont = fontDir + "DejaVuSansMono-Bold.ttf" cfg.CommandFont = fontDir + "DejaVuSansMono.ttf" found = true break } } if !found { fmt.Fprintln(os.Stderr, "# We could not locate your fonts directory, please edit the config\n") fmt.Fprintln(os.Stderr, "# Accordingly.\n") } templ.Execute(os.Stdout, cfg) }
func main() { // Connect to the X server using the DISPLAY environment variable. X, err := xgbutil.NewConn() if err != nil { log.Fatal(err) } // Wrap the root window in a nice Window type. root := xwindow.New(X, X.RootWin()) // Get the geometry of the root window. rgeom, err := root.Geometry() if err != nil { log.Fatal(err) } // Get the rectangles for each of the active physical heads. // These are returned sorted in order from left to right and then top // to bottom. // But first check if Xinerama is enabled. If not, use root geometry. var heads xinerama.Heads if X.ExtInitialized("XINERAMA") { heads, err = xinerama.PhysicalHeads(X) if err != nil { log.Fatal(err) } } else { heads = xinerama.Heads{rgeom} } // Fetch the list of top-level client window ids currently managed // by the running window manager. clients, err := ewmh.ClientListGet(X) if err != nil { log.Fatal(err) } // Output the head geometry before modifying them. fmt.Println("Workarea for each head:") for i, head := range heads { fmt.Printf("\tHead #%d: %s\n", i+1, head) } // For each client, check to see if it has struts, and if so, apply // them to our list of head rectangles. for _, clientid := range clients { strut, err := ewmh.WmStrutPartialGet(X, clientid) if err != nil { // no struts for this client continue } // Apply the struts to our heads. // This modifies 'heads' in place. xrect.ApplyStrut(heads, uint(rgeom.Width()), uint(rgeom.Height()), strut.Left, strut.Right, strut.Top, strut.Bottom, strut.LeftStartY, strut.LeftEndY, strut.RightStartY, strut.RightEndY, strut.TopStartX, strut.TopEndX, strut.BottomStartX, strut.BottomEndX) } // Now output the head geometry again after modification. fmt.Println("Workarea for each head after applying struts:") for i, head := range heads { fmt.Printf("\tHead #%d: %s\n", i+1, head) } }