コード例 #1
0
ファイル: xgb.go プロジェクト: KarateCode/go.wde
func NewWindow(width, height int) (w *Window, err error) {

	w = new(Window)
	w.width, w.height = width, height
	w.buffer = image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{width, height}})

	w.xu, err = xgbutil.Dial("")
	if err != nil {
		return
	}

	w.conn = w.xu.Conn()
	screen := w.xu.Screen()

	w.id = w.conn.NewId()
	w.conn.CreateWindow(xgb.WindowClassCopyFromParent, w.id, screen.Root, 600, 500, uint16(width), uint16(height), 0, xgb.WindowClassInputOutput, screen.RootVisual, 0, []uint32{})

	xwindow.Listen(w.xu, w.id, AllEventsMask)

	keyMap, modMap := keybind.MapsGet(w.xu)
	w.xu.KeyMapSet(keyMap)
	w.xu.ModMapSet(modMap)

	w.events = make(chan interface{})

	w.SetIcon(Gordon)
	w.SetIconName("Go")

	go w.handleEvents()

	return
}
コード例 #2
0
ファイル: tst_window.go プロジェクト: droundy/xgbutil
func main() {
	X, _ := xgbutil.Dial("")

	active, _ := ewmh.ActiveWindowGet(X)
	geom, err := xwindow.GetGeometry(X, active)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(geom)
	}

	// ewmh.WmStateReqExtra(X, active, ewmh.StateToggle,
	// "_NET_WM_STATE_MAXIMIZED_VERT",
	// "_NET_WM_STATE_MAXIMIZED_HORZ", 2)
	time.Sleep(time.Millisecond)
	// err = xwindow.MoveResize(X, active, geom.X, geom.Y,
	// geom.Width - 100, geom.Height)
	fmt.Println(err)
	fmt.Printf("\n")

	rgeom, err := xwindow.RawGeometry(X, X.RootWin())
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(rgeom)
	}

	X.Conn().Close()
}
コード例 #3
0
ファイル: tst_graphics.go プロジェクト: droundy/xgbutil
func main() {
	defer Recovery()

	X, Xerr = xgbutil.Dial("")
	if Xerr != nil {
		panic(Xerr)
	}

	active, _ := ewmh.ActiveWindowGet(X)
	icons, _ := ewmh.WmIconGet(X, active)

	var width, height int = 300, 300

	work := xgraphics.FindBestIcon(width, height, icons)
	if work != nil {
		fmt.Printf("Working with icon (%d, %d)\n", work.Width, work.Height)
	} else {
		fmt.Println("No good icon... :-(")
		return
	}

	eimg, emask := xgraphics.EwmhIconToImage(work)

	img := xgraphics.Scale(eimg, int(width), int(height))
	mask := xgraphics.Scale(emask, int(width), int(height))

	dest := xgraphics.BlendBg(img, mask, 100, color.RGBA{0, 0, 255, 255})

	// Let's try to write some text...
	// xgraphics.DrawText(dest, 50, 50, color.RGBA{255, 255, 255, 255}, 20,
	// fontFile, "Hello, world!")

	// tw, th, err := xgraphics.TextExtents(fontFile, 11, "Hiya")
	// fmt.Println(tw, th, err)

	win := xgraphics.CreateImageWindow(X, dest, 3940, 0)
	X.Conn().MapWindow(win)

	// time.Sleep(20 * time.Second)
	select {}
}
コード例 #4
0
ファイル: tst_graphics_file.go プロジェクト: droundy/xgbutil
func main() {
	defer Recovery()

	X, Xerr = xgbutil.Dial("")
	if Xerr != nil {
		panic(Xerr)
	}

	simg, err := xgraphics.LoadPngFromFile("openbox.png")
	if err != nil {
		fmt.Println(err)
	}

	img := image.NewRGBA(image.Rect(0, 0, 50, 101))
	graphics.Scale(img, simg)

	dest := xgraphics.BlendBg(img, nil, 100, color.RGBA{255, 255, 255, 255})

	win := xgraphics.CreateImageWindow(X, dest, 3940, 400)
	X.Conn().MapWindow(win)

	time.Sleep(20 * time.Second)
}
コード例 #5
0
ファイル: tst_graphics_raw.go プロジェクト: droundy/xgbutil
func main() {
	defer Recovery()

	X, Xerr = xgbutil.Dial("")
	if Xerr != nil {
		panic(Xerr)
	}

	active, _ := ewmh.ActiveWindowGet(X)
	icons, _ := ewmh.WmIconGet(X, active)
	fmt.Printf("Active window's (%x) icon data: (length: %v)\n",
		active, len(icons))
	for _, icon := range icons {
		fmt.Printf("\t(%d, %d)", icon.Width, icon.Height)
		fmt.Printf(" :: %d == %d\n", icon.Width*icon.Height, len(icon.Data))
	}

	work := icons[2]
	fmt.Printf("Working with (%d, %d)\n", work.Width, work.Height)

	width, height := int(work.Width), int(work.Height)
	mask := image.NewRGBA(image.Rect(0, 0, width, height))
	img := image.NewRGBA(image.Rect(0, 0, width, height))

	for x := 0; x < width; x++ {
		for y := 0; y < height; y++ {
			argb := work.Data[x+(y*height)]
			alpha := argb >> 24
			red := ((alpha << 24) ^ argb) >> 16
			green := (((alpha << 24) + (red << 16)) ^ argb) >> 8
			blue := (((alpha << 24) + (red << 16) + (green << 8)) ^ argb) >> 0

			c := color.RGBA{
				R: uint8(red),
				G: uint8(green),
				B: uint8(blue),
				A: uint8(alpha),
			}
			img.SetRGBA(x, y, c)

			mask.Set(x, y, color.Alpha{uint8(alpha)})
		}
	}

	// blendMask := image.NewUniform(color.Alpha{127})
	// draw.DrawMask(mask, mask.Bounds(), mask, image.ZP, blendMask,
	// image.ZP, draw.Src)

	dest := image.NewRGBA(image.Rect(0, 0, width, height))
	allBlue := image.NewUniform(color.RGBA{127, 127, 127, 255})
	draw.Draw(dest, dest.Bounds(), allBlue, image.ZP, draw.Src)
	draw.DrawMask(dest, dest.Bounds(), img, image.ZP, mask, image.ZP, draw.Over)

	// Let's try to write some text...
	WriteText(dest)

	destWriter, err := os.Create("someicon.png")
	if err != nil {
		fmt.Print("could not create someicon.png")
		os.Exit(1)
	}

	png.Encode(destWriter, dest)

	// Let's see if we can paint the image we generated above to a window.

	win := X.Conn().NewId()
	gc := X.Conn().NewId()
	scrn := X.Conn().DefaultScreen()

	cursor := xcursor.CreateCursor(X, xcursor.Fleur)

	winMask := uint32(xgb.CWBackPixmap | xgb.CWOverrideRedirect |
		xgb.CWBackPixel | xgb.CWCursor)
	winVals := []uint32{xgb.BackPixmapParentRelative, scrn.BlackPixel,
		1, uint32(cursor)}
	X.Conn().CreateWindow(scrn.RootDepth, win, X.RootWin(), 100, 400,
		uint16(width), uint16(height),
		0, xgb.WindowClassInputOutput, scrn.RootVisual,
		winMask, winVals)
	X.Conn().CreateGC(gc, X.RootWin(), xgb.GCForeground,
		[]uint32{scrn.WhitePixel})
	X.Conn().MapWindow(win)

	// try paitning the image we created above...
	// First we have to transform the image into X format. (BGRA)
	// Then we have to allocate resources for the pixmap.
	// Then we can paint the pixmap.
	// Finally, we attach that pixmap as the "BackPixmap" of our window above.
	// (And free pixmap right thereafter, of course.)
	imgData := make([]byte, width*height*4)
	for x := 0; x < width; x++ {
		for y := 0; y < height; y++ {
			r, g, b, a := dest.At(x, y).RGBA()
			i := 4 * (x + (y * height))
			imgData[i+0] = byte(b)
			imgData[i+1] = byte(g)
			imgData[i+2] = byte(r)
			imgData[i+3] = byte(a)
		}
	}
	pix := X.Conn().NewId()
	X.Conn().CreatePixmap(scrn.RootDepth, pix, X.RootWin(),
		uint16(width), uint16(height))
	X.Conn().PutImage(xgb.ImageFormatZPixmap, pix, gc,
		uint16(width), uint16(height), 0, 0, 0, 24, imgData)
	X.Conn().ChangeWindowAttributes(win, uint32(xgb.CWBackPixmap),
		[]uint32{uint32(pix)})
	X.Conn().ClearArea(false, win, 0, 0, 0, 0)
	X.Conn().FreePixmap(pix)

	time.Sleep(20 * time.Second)
}
コード例 #6
0
ファイル: main.go プロジェクト: dlintw/wingo
func main() {
	X, err := xgbutil.Dial("")
	if err != nil {
		logger.Error.Println(err)
		logger.Error.Println("Error connecting to X, quitting...")
		return
	}
	defer X.Conn().Close()

	// Get command from arguments
	flag.Parse()
	if flag.NArg() < 1 {
		fmt.Fprintln(os.Stderr, "Usage: wingo-cmd CommandName [CommandArgs]")
		return
	}

	commandPieces := flag.Args()
	cmdName := commandPieces[0]
	cmdFull := strings.Join(commandPieces, " ")

	// make sure we start with failure
	cmdusage.StatusSet(X, false)
	success := false

	// Set the command before sending request to run command.
	err = cmdusage.CmdSet(X, cmdFull)
	if err != nil {
		logger.Error.Printf("Could not set command: %s", err)
		return
	}

	// Issue the command!
	ewmh.ClientEvent(X, X.RootWin(), "_WINGO_CMD")

	// Now let's set up a handler to detect when the status changes
	xevent.PropertyNotifyFun(
		func(X *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
			name, err := xprop.AtomName(X, ev.Atom)
			if err != nil {
				logger.Warning.Println(
					"Could not get property atom name for", ev.Atom)
				return
			}

			if name == "_WINGO_CMD_STATUS" {
				success = cmdusage.StatusGet(X)
				if success {
					os.Exit(0)
				} else {
					logger.Warning.Printf("Error running '%s'", cmdFull)
					cmdusage.ShowUsage(cmdName)
					os.Exit(1)
				}
			}
		}).Connect(X, X.RootWin())

	// Listen to Root property change events
	xwindow.Listen(X, X.RootWin(), xproto.EventMaskPropertyChange)

	go xevent.Main(X)

	time.Sleep(time.Second * 5)

	logger.Error.Println(
		"Timed out while trying to issue command to Wingo. " +
			"Are you sure Wingo is running?")
	os.Exit(1)
}