Skip to content

Instantly share code, notes, and snippets.

@proxypoke
Created April 10, 2013 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proxypoke/5359507 to your computer and use it in GitHub Desktop.
Save proxypoke/5359507 to your computer and use it in GitHub Desktop.
derp
package main
import (
"fmt"
"image"
"log"
"os"
"github.com/BurntSushi/xgb/randr"
"github.com/BurntSushi/xgbutil"
//"github.com/BurntSushi/xgbutil/xevent"
"github.com/BurntSushi/xgbutil/xgraphics"
"github.com/BurntSushi/xgbutil/xprop"
"github.com/BurntSushi/xgbutil/xwindow"
)
func GetOutputRect(X *xgbutil.XUtil, name string) (o image.Rectangle) {
root := X.RootWin()
resources, err := randr.GetScreenResources(X.Conn(), root).Reply()
if err != nil {
log.Fatal(err)
}
// By Odin's beard, this is some ugly shitcode.
var modes []randr.ModeInfo
for _, output := range resources.Outputs {
info, err := randr.GetOutputInfo(X.Conn(), output, 0).Reply()
if err != nil {
log.Fatal(err)
}
// See if we've found the correct output.
if string(info.Name) == name {
// Iterate through all ModeInfos, and only append those which are in
// the output's []Mode field to the modes slice.
//fmt.Printf("%+v\n", info)
for _, mode := range resources.Modes {
for _, id := range info.Modes {
if mode.Id == uint32(id) {
modes = append(modes, mode)
}
}
}
break
}
}
geom := xwindow.RootGeometry(X)
//fmt.Printf("%+v\n", geom)
// FIXME: For now, assume that the preferred mode is active.
// TODO: Figure out how the hell we're supposed to get the active mode.
x, y := geom.X(), geom.Y()
w, h := geom.Width(), geom.Height()
return image.Rect(x, y, x+w, y+h)
}
func main() {
X, err := xgbutil.NewConn()
if err != nil {
log.Fatal(err)
}
err = randr.Init(X.Conn())
if err != nil {
log.Fatal(err)
}
rootrect := GetOutputRect(X, "LVDS1")
fmt.Printf("%+v\n", rootrect)
}
func _main() {
X, err := xgbutil.NewConn()
if err != nil {
log.Fatal(err)
}
file, err := os.Open("bg.png")
if err != nil {
log.Fatal(err)
}
img, _, err := image.Decode(file)
if err != nil {
log.Fatal(err)
}
ximg := xgraphics.NewConvert(X, img)
rootwin := X.RootWin()
err = ximg.XSurfaceSet(rootwin)
if err != nil {
log.Fatal(err)
}
ximg.XDraw()
ximg.XPaint(rootwin)
xprop.ChangeProp32(X, rootwin, "_XROOTPMAP_ID", "PIXMAP", uint(ximg.Pixmap))
//xeven.Main(X)
//X.Conn().WaitForEvent()
//X.Conn().Sync()
//X.Conn().Close()
err = randr.Init(X.Conn())
if err != nil {
log.Fatal(err)
}
resources, err := randr.GetScreenResources(X.Conn(), rootwin).Reply()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", resources.Names)
for _, output := range resources.Outputs {
info, err := randr.GetOutputInfo(X.Conn(), output, 0).Reply()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s: %+v\n", info)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment