예제 #1
0
파일: sct_nix.go 프로젝트: faf0/go-sct
// setColorTemp changes the Xrandr colors to reflect the specified color temperature.
func setColorTemp(gammar, gammag, gammab float64) {
	dpy := C.XOpenDisplay(nil)
	screenCount := C.screenCount(dpy)
	for screen := C.int(0); screen < screenCount; screen++ {
		root := C.RootWindowMacro(dpy, screen)

		res := C.XRRGetScreenResourcesCurrent(dpy, root)

		for c := C.int(0); c < res.ncrtc; c++ {
			crtcxid := C.crtcxid(res.crtcs, c)

			size := C.XRRGetCrtcGammaSize(dpy, crtcxid)
			crtc_gamma := C.XRRAllocGamma(size)
			for i := C.int(0); i < size; i++ {
				g := 65535.0 * float64(i) / float64(size)
				C.ushortSet(C.ushortCast(unsafe.Pointer(crtc_gamma.red)), i, C.double(g*gammar))
				C.ushortSet(C.ushortCast(unsafe.Pointer(crtc_gamma.green)), i, C.double(g*gammag))
				C.ushortSet(C.ushortCast(unsafe.Pointer(crtc_gamma.blue)), i, C.double(g*gammab))
			}
			C.XRRSetCrtcGamma(dpy, crtcxid, crtc_gamma)
			C.XFree(unsafe.Pointer(crtc_gamma))
		}

		C.XFree(unsafe.Pointer(res))
	}
	C.XCloseDisplay(dpy)
}
예제 #2
0
// Переключалка групп Xorg.
func switchXkbGroup(group uint) {
	var xkbEventType, xkbError, xkbReason C.int
	var majorVers, minorVers C.int

	majorVers = C.XkbMajorVersion
	minorVers = C.XkbMinorVersion
	display := C.XkbOpenDisplay(nil, &xkbEventType, &xkbError, &majorVers, &minorVers, &xkbReason)
	if display == nil {
		fmt.Printf("Can't open X display %s", C.GoString(C.XDisplayName(nil)))
		switch xkbReason {
		case C.XkbOD_BadServerVersion:
		case C.XkbOD_BadLibraryVersion:
			println("incompatible versions of client and server XKB libraries")
		case C.XkbOD_ConnectionRefused:
			println("connection to X server refused")
		case C.XkbOD_NonXkbServer:
			println("XKB extension is not present")
		default:
			println("unknown error from XkbOpenDisplay: %d", xkbReason)
		}
		return
	}

	C.XkbLockGroup(display, C.XkbUseCoreKbd, C.uint(group))
	C.XCloseDisplay(display)
}
예제 #3
0
func handleEvents() bool {
	C.XNextEvent(dpy, eventPtr)
	fmt.Println(event.message_type)
	if event._type == C.ClientMessage {
		C.XCloseDisplay(dpy)
		return false
	}
	return true
}
예제 #4
0
파일: imp.go 프로젝트: CaptainSoOmA/Uni
func terminate() {
	//
	//  C.XFreeGC (display, graphicsContext)
	//  C.XUnmapWindow (display, window)
	C.XDestroyWindow(display, window)
	C.XDestroyWindow(display, C.Window(window0))
	C.XCloseDisplay(display)
	initialized = false
}
예제 #5
0
파일: xidle.go 프로젝트: mikkeloscar/lis
// XIdle returns the xserver idle time in miliseconds.
func XIdle() (uint, error) {
	var eventBase, errorBase C.int
	var info C.XScreenSaverInfo

	display := C.XOpenDisplay(C.CString(""))
	if display == nil {
		return 0, fmt.Errorf("xidle: unable to open X display")
	}
	defer C.XCloseDisplay(display)

	if C.XScreenSaverQueryExtension(display, &eventBase, &errorBase) > 0 {
		C.XScreenSaverQueryInfo(display, C.wrap_DefaultRootWindow(display), &info)
		return uint(info.idle), nil
	}

	return 0, fmt.Errorf("XScreenSaver Extension not present")
}
예제 #6
0
// Close X display
func (x *X) CloseDisplay() {
	if x.dpy != nil {
		C.XCloseDisplay(x.dpy)
	}
}
예제 #7
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
		}
	}
}