Created
November 30, 2024 01:59
-
-
Save insom/ebdb2fee6059d2b86f7953fb71ee692f to your computer and use it in GitHub Desktop.
Just enough X11 to perform -- using CGo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo LDFLAGS: -lX11 | |
// #include <X11/Xlib.h> | |
import "C" | |
import ( | |
"time" | |
) | |
func main() { | |
d := C.XOpenDisplay(nil) | |
s := C.XDefaultScreen(d) | |
root := C.XRootWindow(d, s) | |
w := C.XCreateSimpleWindow(d, root, 10, 10, 100, 100, 0, 0, 0xff0000) | |
C.XSynchronize(d, 1) | |
C.XMapWindow(d, w) | |
C.XMoveResizeWindow(d, w, 100, 100, 200, 100) | |
gc := C.XCreateGC(d, w, 0, nil) | |
C.XSetForeground(d, gc, 0xffffff) | |
hello := C.CString("hello world") | |
C.XDrawString(d, w, gc, 10, 10, hello, 11 /*len(q)*/) | |
C.XFlush(d) | |
time.Sleep(2 * time.Second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment