コード例 #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
ファイル: xtypekeys.go プロジェクト: foutaise/xtypekeys
// Open X display
func (x *X) OpenDisplay() error {
	x.dpy = C.XOpenDisplay(nil)
	if x.dpy == nil {
		return errors.New("Unable to open display")
	}
	return nil
}
コード例 #3
0
ファイル: xlib.go プロジェクト: stephenwithav/gocairo
func XMain(callbacks Callbacks) {
	dpy := C.XOpenDisplay(nil)

	w := C.XCreateSimpleWindow(dpy, C.XDefaultRootWindow(dpy),
		0, 0, 600, 400,
		0, 0, 0)
	C.XSelectInput(dpy, w, C.StructureNotifyMask|C.SubstructureNotifyMask|C.ExposureMask)
	C.XMapWindow(dpy, w)

	win := Window{dpy: dpy, xw: w}
	visual := C.XDefaultVisual(dpy, 0)

	surf := cairo.XlibSurfaceCreate(unsafe.Pointer(dpy), uint64(win.xw), unsafe.Pointer(visual), 10, 10)

	for {
		var e C.XEvent
		C.XNextEvent(dpy, &e)
		typ := XEventType(*(*C.int)(unsafe.Pointer(&e)))
		// log.Printf("X event: %s", typ)
		switch typ {
		case C.ConfigureNotify:
			e := (*C.XConfigureEvent)(unsafe.Pointer(&e))
			surf.SetSize(int(e.width), int(e.height))
		case C.Expose:
			cr := cairo.Create(surf.Surface)
			callbacks.Draw(cr, surf)
		default:
			// log.Printf("unknown X event %s", typ)
		}
	}
}
コード例 #4
0
ファイル: sct.go プロジェクト: takeyourhatoff/go-sct
// SetColorTemp changes the Xrandr colors to reflect the specified color temperature.
func SetColorTemp(temp int) {
	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)

		if temp < 1000 || temp > 10000 {
			temp = 6500
		}
		temp -= 1000
		ratio := float64((temp-1000)%500) / 500.0
		point := whitepoints[temp/500]
		gammar := point.r*(1-ratio) + point.r*ratio
		gammag := point.g*(1-ratio) + point.g*ratio
		gammab := point.b*(1-ratio) + point.b*ratio

		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(crtc_gamma.red, i, C.ushort(g*gammar))
				C.ushortSet(crtc_gamma.green, i, C.ushort(g*gammag))
				C.ushortSet(crtc_gamma.blue, i, C.ushort(g*gammab))
			}
			C.XRRSetCrtcGamma(dpy, crtcxid, crtc_gamma)
			C.XFree(unsafe.Pointer(crtc_gamma))
		}
	}
}
コード例 #5
0
ファイル: xlib.go プロジェクト: evmar/smash
func OpenDisplay(anims *base.AnimSet) *Display {
	return &Display{
		dpy:        C.XOpenDisplay(nil),
		eventReady: make(chan bool),
		drawReady:  make(chan bool, 1),
		quit:       make(chan bool, 1),
		funcs:      make(chan func(), 5),
		anims:      anims,
	}
}
コード例 #6
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
}
コード例 #7
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Screen() (C.uint, C.uint, C.uint) {
	//
	d := C.CString(dspl)
	defer C.free(unsafe.Pointer(d))
	display = C.XOpenDisplay(d)
	if display == nil {
		panic("display == nil") /* Terminate (); */ os.Exit(1)
	}
	window0 = C.XDefaultRootWindow(display)
	screen = C.XDefaultScreen(display)
	return C.uint(C.XDisplayWidth(display, screen)),
		C.uint(C.XDisplayHeight(display, screen)),
		C.uint(C.XDefaultDepth(display, screen))
}
コード例 #8
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")
}
コード例 #9
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
}
コード例 #10
0
ファイル: dwmstatus.go プロジェクト: vladimir-ch/dwmstatus
package main

// #cgo LDFLAGS: -lX11
// #include <X11/Xlib.h>
import "C"

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
	"time"
)

var dpy = C.XOpenDisplay(nil)

func setStatus(status string) {
	C.XStoreName(dpy, C.XDefaultRootWindow(dpy), C.CString(status))
	C.XSync(dpy, 1)
}

func cpuLoad() string {
	loadavg, err := ioutil.ReadFile("/proc/loadavg")
	if err != nil {
		return "CPUERR"
	}
	fields := strings.Split(string(loadavg), " ")
	return "CPU " + strings.Join(fields[:3], " ")
}
コード例 #11
0
ファイル: tinywm.go プロジェクト: mantyr/tinywm
func main() {
	var dpy *C.Display
	var attr C.XWindowAttributes
	var start C.XButtonEvent
	var ev C.XEvent
	var ch *C.char

	if dpy != C.XOpenDisplay(ch) {
		return
	}

	C.XGrabKey(
		dpy,
		C.int(C.XKeysymToKeycode(dpy, C.XStringToKeysym(C.CString("F1")))),
		C.Mod1Mask,
		C.XDefaultRootWindow(dpy),
		1,
		C.GrabModeAsync,
		C.GrabModeAsync,
	)

	C.XGrabButton(
		dpy,
		1,
		C.Mod1Mask,
		C.XDefaultRootWindow(dpy),
		1,
		C.ButtonPressMask|C.ButtonReleaseMask|C.PointerMotionMask,
		C.GrabModeAsync,
		C.GrabModeAsync,
		C.None,
		C.None,
	)

	C.XGrabButton(
		dpy,
		3,
		C.Mod1Mask,
		C.XDefaultRootWindow(dpy),
		1,
		C.ButtonPressMask|C.ButtonReleaseMask|C.PointerMotionMask,
		C.GrabModeAsync,
		C.GrabModeAsync,
		C.None,
		C.None,
	)

	start.subwindow = C.None

	for {
		C.XNextEvent(dpy, &ev)
		if unionToInt(ev) == C.KeyPress && unionToXKeyEvent(ev).subwindow != C.None {
			C.XRaiseWindow(dpy, unionToXKeyEvent(ev).subwindow)
		} else if unionToInt(ev) == C.ButtonPress && unionToXButtonEvent(ev).subwindow != C.None {
			C.XGetWindowAttributes(dpy, unionToXButtonEvent(ev).subwindow, &attr)
			start = *unionToXButtonEvent(ev)
		} else if unionToInt(ev) == C.MotionNotify && start.subwindow != C.None {
			xdiff := unionToXButtonEvent(ev).x_root - start.x_root
			ydiff := unionToXButtonEvent(ev).y_root - start.y_root

			var toDiffX C.int
			var toDiffY C.int

			if start.button == 1 {
				toDiffX = xdiff
				toDiffY = ydiff
			}

			var toWidth C.int
			var toHeight C.int

			if start.button == 3 {
				toWidth = xdiff
				toHeight = ydiff
			}

			C.XMoveResizeWindow(
				dpy,
				start.subwindow,
				attr.x+toDiffX,
				attr.y+toDiffY,
				max(1, attr.width+toWidth),
				max(1, attr.height+toHeight))
		} else if unionToInt(ev) == C.ButtonRelease {
			start.subwindow = C.None
		}
	}
}
コード例 #12
0
ファイル: window_linux.go プロジェクト: yulon/go-oswnd
func init() {
	dpy = C.XOpenDisplay(nil)
	attributes.background_pixel = C.XWhitePixel(dpy, 0)
	root = C.XRootWindow(dpy, 0)
}
コード例 #13
0
ファイル: watcher.go プロジェクト: andaru/midihitter
		return m.Value == cur
	} else if mtype == ValueIncreasing {
		return cur > prev
	} else if mtype == ValueDecreasing {
		return cur < prev
	} else if mtype == ValuePassesIncreasing {
		return cur > m.Passing && prev <= m.Passing
	} else if mtype == ValuePassesDecreasing {
		return cur < m.Passing && prev >= m.Passing
	}
	panic("should never get here")
}

var (
	x11display = C.CString(os.Getenv("DISPLAY"))
	dpy        = C.XOpenDisplay(x11display)
)

func sendKey(disp *C.struct__XDisplay, strname string) {
	if disp == nil {
		fmt.Println("no X11 display available")
		return
	}

	var mod _Ctype_KeyCode

	if strings.HasPrefix(strname, "Ctrl+") {
		strname = strname[len("Ctrl+"):]
		modkey := "Control_L"
		mod = C.XKeysymToKeycode(disp, C.XStringToKeysym(C.CString(modkey)))
		if debug {