Example #1
0
func sendEvents() {
	//
	var tst bool
	tst = true
	tst = false
	//
	var typ C.int
	var ev *C.XEvent
	if C.XCheckMaskEvent(display, C.ExposureMask+C.StructureNotifyMask+C.SubstructureNotifyMask, &actualEvent) == C.True {
		aT := C.typ(&actualEvent)
		switch aT {
		case C.Expose, C.ConfigureNotify:
			for C.XCheckTypedEvent(display, C.int(aT), &actualEvent) == C.True {
				ev = &actualEvent
				typ = C.typ(ev)
				if tst {
					println("... got " + txt[typ] + " event")
				}
				//      pp2ff ()
				//  C.XFlush (display)
				if typ != C.ConfigureNotify {
					println("init sendEvents " + txt[typ])
				}
			}
			//      pp2ff ()
		}
	}
	var event Event
	xM, yM = 0, 0
	// println ("sendEvents before for-loop")
	for {
		//    if tst { println ("x is waiting for next event ...") }
		C.XNextEvent(display, &actualEvent)
		event.C, event.S = 0, 0
		ev = &actualEvent
		typ = C.typ(ev)
		if tst {
			println("... got " + txt[typ] + " event")
		}
		switch typ {
		case KeyPress:
			event.C, event.S = uint(C.xKeyCode(ev)), uint(C.xKeyState(ev))
		case KeyRelease:
			event.C, event.S = uint(C.xKeyCode(ev)), uint(C.xKeyState(ev))
		case ButtonPress:
			event.C, event.S = uint(C.xButtonButton(ev)), uint(C.xButtonState(ev))
			xM, yM = int(C.xButtonX(ev)), int(C.xButtonY(ev))
			if xM < int(xMin) || xM > int(xMax) || yM < int(yMin) || yM > int(yMax) {
				event.C, event.S, xM, yM, typ = 0, 0, 0, 0, C.LASTEvent
			}
		case ButtonRelease:
			event.C, event.S = uint(C.xButtonButton(ev)), uint(C.xButtonState(ev))
			xM, yM = int(C.xButtonX(ev)), int(C.xButtonY(ev))
			if xM < int(xMin) || xM > int(xMax) || yM < int(yMin) || yM > int(yMax) {
				event.C, event.S, xM, yM, typ = 0, 0, 0, 0, C.LASTEvent
			}
		case MotionNotify:
			event.C, event.S = uint(0), uint(C.xMotionState(ev))
			xM, yM = int(C.xMotionX(ev)), int(C.xMotionY(ev))
			if xM < int(xMin) || xM > int(xMax) || yM < int(yMin) || yM > int(yMax) {
				event.C, event.S, xM, yM, typ = 0, 0, 0, 0, C.LASTEvent
			}
		case EnterNotify:
			//      pp2ff ()
			//      println (txt [typ])
		case LeaveNotify:
			//      println (txt [typ])
		case FocusIn:
			//      println (txt [typ])
		case FocusOut:
			//      println (txt [typ])
		case KeymapNotify:
			//      println (txt [typ])
		case Expose:
			pp2ff()
			//      println (txt [typ])
		case GraphicsExpose:
			//      println (txt [typ])
		case NoExpose:
			//      println (txt [typ])
		case VisibilityNotify:
			println(txt[typ])
		case CreateNotify:
			//      println (txt [typ])
		case DestroyNotify:
			//      println (txt [typ])
		case UnmapNotify:
			//      println (txt [typ])
		case MapNotify:
			//  C.XSync (display, C.False)
			//  C.XSync (display, C.True)
			//      pp2ff ()
		case MapRequest:
			//      println (txt [typ])
		case ReparentNotify:
			//      println (txt [typ])
		case ConfigureNotify:
			//      println (txt [typ])
		case ConfigureRequest:
			//      println (txt [typ])
		case GravityNotify:
			//      println (txt [typ])
		case ResizeRequest:
			//      pp2ff ()
			//      println (txt [typ])
		case CirculateNotify:
			//      println (txt [typ])
		case CirculateRequest:
			//      println (txt [typ])
		case PropertyNotify:
			//      println (txt [typ])
		case SelectionClear:
			//      println (txt [typ])
		case SelectionRequest:
			//      println (txt [typ])
		case SelectionNotify:
			//      println (txt [typ])
		case ColormapNotify:
			//      println (txt [typ])
		case ClientMessage:
			println(txt[typ])
			//      mT:= C.mT (ev)
			//      if mT != naviAtom { println ("unknown xclient.message_type ", uint32(mT)) }
		case MappingNotify:
			println(txt[typ])
		case GenericEvent:
			println(txt[typ])
		default:
			println("strange sort of XEvent: ", typ)
		}
		switch typ {
		case KeyPress, ButtonPress, ButtonRelease, MotionNotify:
			event.T = uint(typ)
			Eventpipe <- event
		}
	}
}
Example #2
0
func Init(w, h uint, cF, cB col.Colour) (uint, uint, uint) {
	//
	initialized = false
	//
	maxX, maxY, bitdepth = Screen()
	bdp := uint(bitdepth)
	switch bdp {
	case 15, 16, 24, 32:
		col.SetColourDepth(bdp)
	default:
		panic("strange colourdepth") /* Terminate (); */ os.Exit(1)
	}
	colourdepth := (bdp + 1) / 8
	col.ScreenF, col.ScreenB = cF, cB
	xx, yy = C.uint(w), C.uint(h)
	window = C.XCreateSimpleWindow(display, C.Window(window0), 0, 0, xx, yy, C.uint(0), C.ulong(0), cc(col.ScreenB))
	//  var E C.XEvent
	//  C.XNextEvent (display, &E) // XCreate... did not produce an XEvent
	C.initialize(display, screen, window)
	t := C.CString(env.Par(0))
	defer C.free(unsafe.Pointer(t))
	C.XStoreName(display, window, t)
	C.XMapRaised(display, window)
	const inputmask = (C.KeyPressMask + // C.KeyReleaseMask +
		C.ButtonPressMask + C.ButtonReleaseMask + C.PointerMotionMask +
		C.ExposureMask + C.StructureNotifyMask)
	C.XSelectInput(display, window, inputmask)
	cursor := C.XCreateFontCursor(display, C.XC_gumby)
	C.XDefineCursor(display, window, cursor)
	graphicsContext = C.XDefaultGC(display, screen)
	//  C.XFlushGC (display graphicsContext)
	C.XSetGraphicsExposures(display, graphicsContext, C.False)
	SetFontsize(16)
	initialized = true
	Colours(cF, cB)
	C.XSetForeground(display, graphicsContext, cc(col.ScreenB))

	C.XFillRectangle(display, C.Drawable(window), graphicsContext, 0, 0, xx, yy)
	pixmap = C.XCreatePixmap(display, C.Drawable(window), xx, yy, bitdepth)
	pixmap1 = C.XCreatePixmap(display, C.Drawable(window), maxX, maxY, bitdepth)
	C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, 0, 0, xx, yy)
	C.XFillRectangle(display, C.Drawable(pixmap1), graphicsContext, 0, 0, xx, yy)
	C.XSetForeground(display, graphicsContext, cc(col.ScreenF))

	MouseDef(0, 0, int(xx-1), int(yy-1))
	var E C.XEvent
	C.XNextEvent(display, &E)
	var et C.int = C.typ(&E) // et == *E.type
	switch et {
	case C.Expose, C.ConfigureNotify: // zur Erstausgabe
		for C.XCheckTypedEvent(display, et, &E) == C.True {
		}
		//    pp2ff ()
	case KeyPress, KeyRelease, ButtonPress, ButtonRelease, MotionNotify:
		C.XPutBackEvent(display, &E)
	case C.ReparentNotify: // at Switch (?)
		// ignore
	default: // for test purposes
		//    println ("at initializing x:" + txt [et])
	}
	p := C.CString("WM_PROTOCOLS")
	defer C.free(unsafe.Pointer(p))
	wm_protocols := C.XInternAtom(display, p, C.False)
	C.XSetWMProtocols(display, window, &wm_protocols, 1)
	s := C.CString("_NET_WM_STATE")
	defer C.free(unsafe.Pointer(s))
	netwm_state = C.XInternAtom(display, s, C.False)
	f := C.CString("_NET_WM_STATE_FULLSCREEN")
	defer C.free(unsafe.Pointer(f))
	fullscreen = C.XInternAtom(display, f, C.False)
	m := C.CString("navi")
	defer C.free(unsafe.Pointer(m))
	naviAtom = C.XInternAtom(display, m, C.False)
	Eventpipe = make(chan Event)
	go sendEvents()
	//  C.XFlush (display)
	//  println ("init ok")
	return uint(maxX), uint(maxY), colourdepth
}