コード例 #1
0
ファイル: window_linux.go プロジェクト: yulon/go-oswnd
func New() *Window {
	xWnd := C.XCreateWindow(
		dpy,
		root,
		0,
		0,
		500,
		500,
		0,
		C.XDefaultDepth(dpy, 0),
		C.InputOutput,
		C.XDefaultVisual(dpy, 0),
		C.CWBackPixel,
		&attributes,
	)
	wdw := C.CString("WM_DELETE_WINDOW")
	wmDelete := C.XInternAtom(dpy, wdw, 1)
	C.free(unsafe.Pointer(wdw))
	fmt.Println(wmDelete)
	C.XSetWMProtocols(dpy, xWnd, &wmDelete, 1)
	C.XSelectInput(dpy, xWnd, C.ExposureMask|C.KeyPressMask)
	C.XMapWindow(dpy, xWnd)

	wnd := &Window{
		id: uintptr(xWnd),
	}

	wndMap[wnd.id] = wnd
	return wnd
}
コード例 #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
}
コード例 #3
0
ファイル: gowitt.go プロジェクト: jonvaldes/gowitt
func main() {

	window, err := CreateXWindow(500, 500)
	if err != nil {
		panic(err)
	}

	defer C.XCloseDisplay(window.Display)

	DB, err := initDB()
	if err != nil {
		panic(err)
	}

	//getTwitterData(DB)
	tweetsList, err := regenerateViewData(window, DB, 20)
	if err != nil {
		panic(err)
	}

	wmDeleteMessage := C.XInternAtom(window.Display, C.CString("WM_DELETE_WINDOW"), 0)
	C.XSetWMProtocols(window.Display, window.Window, &wmDeleteMessage, 1)
	mouseClick := [2]int{-1, -1}
	var event C.XEvent
	for {
		pendingRedraws := false
		processedOneEvent := false
		for !processedOneEvent || C.XPending(window.Display) != 0 {
			C.XNextEvent(window.Display, &event)
			processedOneEvent = true

			switch C.getXEventType(event) {
			case C.Expose:
				pendingRedraws = true
			case C.KeyPress:
				ke := C.eventAsKeyEvent(event)
				//fmt.Println("Key pressed", ke.keycode)
				switch ke.keycode {
				case 116: // down
					window.Scroll -= 10
				case 111: // up
					window.Scroll += 10
				}
				pendingRedraws = true
			case C.ButtonPress:
				b := C.eventAsButtonEvent(event)
				switch b.button {
				case 4: // scroll up
					window.Scroll += 10
				case 5: // scroll down
					window.Scroll -= 10
				case 1:
					// left mouse down
					butEv := (*C.XButtonEvent)(unsafe.Pointer(&event))
					mouseClick[0] = int(butEv.x)
					mouseClick[1] = int(butEv.y)
				}
				pendingRedraws = true
			case C.ClientMessage:
				if C.clientMessageType(event) == C.long(wmDeleteMessage) {
					return
				}
			}
		}
		if pendingRedraws {
			RedrawWindow(window, tweetsList, mouseClick)
			mouseClick[0] = -1
			mouseClick[1] = -1
		}
	}
}