示例#1
0
func initConsole() {
	//
	colbits := uint(0)
	XX, YY, colbits, fbmem = ker.Framebuffer()
	if fbmem == nil {
		//    terminateConsole ()
		panic("framebuffer was not initialized! (is /dev/fb0 crw-rw-rw ?)") // Speicherzugriffsfehler
	}
	maxMode = Mode(0)
	for {
		if XX == nX[maxMode] && YY == nY[maxMode] {
			mode = maxMode
			break
		} else if maxMode+1 < NModes {
			maxMode++
		} else {
			mode = defaultMode
			XX, YY = nX[mode], nY[mode]
			break
		}
	}
	switch colbits {
	case 4, 8:
		colourdepth = 1
	case 15, 16:
		colourdepth = 2
	case 24:
		colourdepth = 3
	case 32:
		colourdepth = 4
	default:
		ker.Stop(pack, 100+colbits)
	}
	col.SetColourDepth(colbits)
	fbmemsize := nY[maxMode] * nX[maxMode] * uint(colourdepth)
	if uint(len(fbmem)) != fbmemsize {
		terminateConsole()
		println("len(fbmem) == ", len(fbmem), " != fbmemsize == ", fbmemsize)
		panic("len(fbmem) not ok !")
	}
	swFontsize(font.Normal)
	fbcop = make([]byte, fbmemsize)
	archive = make([]byte, fbmemsize)
	//  for n:= 0; n < int(len(fbmem)) - int(colourdepth); n += int(colourdepth) {
	//    copy (archive[n:n+int(colourdepth)], cc (col.EncodeF))
	//  }
	emptyBackground = make([]byte, fbmemsize)
	print(esc1 + "2J" + esc1 + "?1c" + esc1 + "?25l")
	Colours(col.ScreenF, col.ScreenB)
	initMouse()
	visible = true
	go blink()
	ker.InitConsole()
	ker.SetAction(syscall.SIGUSR1, consoleOff)
	ker.SetAction(syscall.SIGUSR2, consoleOn)
	ker.InstallTerm(terminateConsole)
	go ker.CatchSignals()
	initConsoleFonts()
}
示例#2
0
文件: imp.go 项目: CaptainSoOmA/Uni
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
}