func (hds *Heads) ApplyStruts(clients Clients) { hds.workarea = make(xinerama.Heads, len(hds.geom)) for i, hd := range hds.geom { hds.workarea[i] = xrect.New(hd.X(), hd.Y(), hd.Width(), hd.Height()) } rgeom := xwindow.RootGeometry(hds.X) for i := 0; i < clients.Len(); i++ { c := clients.Get(i) strut, _ := ewmh.WmStrutPartialGet(hds.X, c.Id()) if strut == nil { continue } xrect.ApplyStrut(hds.workarea, 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) } for _, wrk := range hds.workspaces.Wrks { wrk.Place() } }
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 main() { X, err := xgbutil.NewConn() if err != nil { log.Fatalln(err) } // The message box uses the keybind module, so we must initialize it. keybind.Initialize(X) // Creating a new message prompt is as simple as supply an X connection, // a theme and a configuration. We use built in defaults here. msgPrompt := prompt.NewMessage(X, prompt.DefaultMessageTheme, prompt.DefaultMessageConfig) // Show maps the message prompt window. // If a duration is specified, the window does NOT acquire focus and // automatically disappears after the specified time. // If a duration is not specified (i.e., '0'), then the window is mapped, // and acquires focus. It does not disappear until it loses focus or when // the user hits the "confirm" or "cancel" keys (usually "enter" and // "escape"). timeout := 2 * time.Second // or "0" for no timeout. msgPrompt.Show(xwindow.RootGeometry(X), "Hello, world!", timeout, hidden) xevent.Main(X) }
func ewmhDesktopGeometry() { rgeom := xwindow.RootGeometry(X) ewmh.DesktopGeometrySet(X, &ewmh.DesktopGeometry{ Width: rgeom.Width(), Height: rgeom.Height(), }) }
func getPrimaryScreenBestResolution() (w uint16, h uint16) { // if connect to x failed, just return 1024x768 w, h = 1024, 768 XU, err := xgbutil.NewConn() if err != nil { return } err = randr.Init(XU.Conn()) if err != nil { return } _, err = randr.QueryVersion(XU.Conn(), 1, 4).Reply() if err != nil { return } Root := xproto.Setup(XU.Conn()).DefaultScreen(XU.Conn()).Root resources, err := randr.GetScreenResources(XU.Conn(), Root).Reply() if err != nil { return } bestModes := make([]uint32, 0) for _, output := range resources.Outputs { reply, err := randr.GetOutputInfo(XU.Conn(), output, 0).Reply() if err == nil && reply.NumModes > 1 { bestModes = append(bestModes, uint32(reply.Modes[0])) } } w, h = 0, 0 for _, m := range resources.Modes { for _, id := range bestModes { if id == m.Id { bw, bh := m.Width, m.Height if w == 0 || h == 0 { w, h = bw, bh } else if uint32(bw)*uint32(bh) < uint32(w)*uint32(h) { w, h = bw, bh } } } } if w == 0 || h == 0 { // get resource failed, use root window's geometry rootRect := xwindow.RootGeometry(XU) w, h = uint16(rootRect.Width()), uint16(rootRect.Height()) } if w == 0 || h == 0 { w, h = 1024, 768 // default value } logger.Debugf("primary screen's best resolution is %dx%d", w, h) return }
func main() { X, err := xgbutil.NewConn() if err != nil { log.Fatalln(err) } // The input box uses the keybind module, so we must initialize it. keybind.Initialize(X) // Creating a new input prompt is as simple as supply an X connection, // a theme and a configuration. We use built in defaults here. inpPrompt := prompt.NewInput(X, prompt.DefaultInputTheme, prompt.DefaultInputConfig) // Show maps the input prompt window and sets the focus. It returns // immediately, and the main X event loop is started. // Also, we use the root window geometry to make sure the prompt is // centered in the middle of the screen. 'response' and 'canceled' are // callback functions. See their respective commends for more details. inpPrompt.Show(xwindow.RootGeometry(X), "What is your name?", response, canceled) xevent.Main(X) }
func (wrk *Sticky) HeadGeom() xrect.Rect { return xwindow.RootGeometry(wrk.X) }