예제 #1
0
파일: x.go 프로젝트: sixteng/goGLPro
func (window *XWindow) Create(width uint, height uint, title string) bool {
	dpy := C.XOpenDisplay(nil)
	scr := C.XDefaultScreen(dpy)
	root := C.XDefaultRootWindow(dpy)

	win := C.XCreateSimpleWindow(dpy, root, 0, 0, C.uint(width), C.uint(height), 0, C.XBlackPixel(dpy, scr), C.XBlackPixel(dpy, scr))

	C.XStoreName(dpy, win, C.CString(title))
	C.XMapWindow(dpy, win)

	window.dpy = dpy

	return true
}
예제 #2
0
파일: gowitt.go 프로젝트: jonvaldes/gowitt
func CreateXWindow(width, height int) (*XWindow, error) {
	C.XInitThreads()

	W := &XWindow{}

	W.Display = C.XOpenDisplay(nil)
	if W.Display == nil {
		return &XWindow{}, errors.New("Can't open display")
	}
	W.Window = C.XCreateSimpleWindow(W.Display, C.XDefaultRootWindow(W.Display), 0, 0, C.uint(width), C.uint(height), 0, 0, 0xFF151515)
	C.XSetWindowBackgroundPixmap(W.Display, W.Window, 0) // This avoids flickering on resize
	C.XMapWindow(W.Display, W.Window)
	C.XStoreName(W.Display, W.Window, C.CString("gowitt"))

	C.XSelectInput(W.Display, W.Window, C.ExposureMask|C.KeyPressMask|C.ButtonPressMask)
	C.XFlush(W.Display)

	// Cairo
	W.Surface = C.cairo_xlib_surface_create(W.Display, C.Drawable(W.Window), C.XDefaultVisual(W.Display, 0), C.int(width), C.int(height))
	C.cairo_xlib_surface_set_size(W.Surface, C.int(width), C.int(height))
	W.Cairo = C.cairo_create(W.Surface)

	// Pango
	InitLayoutsCache(W.Cairo)
	W.PangoContext = C.pango_cairo_create_context(W.Cairo)
	W.FontDesc = C.pango_font_description_from_string(C.CString("Sans 10"))

	W.AttrList = C.pango_attr_list_new()

	placeholderImage = C.cairo_image_surface_create_from_png(C.CString("test.png"))

	W.UserImages = NewImageCache(func() {
		var ev C.XEvent
		exev := (*C.XExposeEvent)(unsafe.Pointer(&ev))
		exev._type = C.Expose
		exev.count = 0
		exev.window = W.Window
		exev.send_event = 1
		exev.display = W.Display

		C.XSendEvent(W.Display, W.Window, 0, C.ExposureMask, &ev)
		C.XFlush(W.Display)
	})
	return W, nil
}
예제 #3
0
func setStatus(status string) {
	C.XStoreName(dpy, C.XDefaultRootWindow(dpy), C.CString(status))
	C.XSync(dpy, 1)
}
예제 #4
0
func setStatus(s *C.char) {
	C.XStoreName(dpy, C.XDefaultRootWindow(dpy), s)
	C.XSync(dpy, 1)
}
예제 #5
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
}