Esempio n. 1
0
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
}
Esempio n. 2
0
func newGradientWindow(width, height int) {
	win := createWindow()
	xproto.ConfigureWindow(
		X.Conn(), win, xproto.ConfigWindowWidth|xproto.ConfigWindowHeight,
		[]uint32{uint32(width), uint32(height)})
	xwindow.Listen(X, win, xproto.EventMaskStructureNotify)

	xproto.MapWindow(X.Conn(), win)

	xgraphics.PaintImg(X, win, gradient(width, height))

	xevent.ConfigureNotifyFun(
		func(X *xgbutil.XUtil, ev xevent.ConfigureNotifyEvent) {
			img := gradient(int(ev.Width), int(ev.Height))
			log.Printf("Painting new image (%d, %d)", ev.Width, ev.Height)
			xgraphics.PaintImg(X, win, img)
		}).Connect(X, win)
}
Esempio n. 3
0
func main() {
	sleepy := time.Millisecond
	X, _ := xgbutil.NewConn()
	conn := X.Conn()

	aDesktop := "_NET_WM_DESKTOP"
	aActive := "_NET_ACTIVE_WINDOW"

	xwindow.Listen(X, X.RootWin(), xproto.EventMaskPropertyChange)
	xevent.PropertyNotifyFun(
		func(X *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
			for i := 0; i < 1; i++ {
				log.Println("PROPERTY CHANGE")
			}
		}).Connect(X, X.RootWin())

	go func() {
		for {
			reply, err := xproto.InternAtom(conn, true, uint16(len(aDesktop)),
				aDesktop).Reply()
			if err != nil {
				log.Fatal(err)
			}

			log.Println("A1-299", reply.Sequence, reply.Atom)
			time.Sleep(sleepy)
		}
	}()

	go func() {
		for {
			reply, err := xproto.InternAtom(conn, true, uint16(len(aActive)),
				aActive).Reply()
			if err != nil {
				log.Fatal(err)
			}

			log.Println("A2-294", reply.Sequence, reply.Atom)
			time.Sleep(sleepy)
		}
	}()

	go func() {
		for {
			reply, err := xproto.GetGeometry(conn, 0x1).Reply()
			if err != nil {
				log.Println("0x1:", err)
			} else {
				log.Println("0x1:", reply)
			}
			time.Sleep(sleepy)
		}
	}()

	go func() {
		for {
			reply, err := xproto.GetGeometry(conn, 0x2).Reply()
			if err != nil {
				log.Println("0x2:", err)
			} else {
				log.Println("0x2:", reply)
			}
			time.Sleep(sleepy)
		}
	}()

	go xevent.Main(X)
	select {}
}
Esempio n. 4
0
File: main.go Progetto: 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)
}