Last active
June 13, 2017 23:23
-
-
Save hugopeixoto/2bcf00bb88e8e6ff2da97d3edde5609c to your computer and use it in GitHub Desktop.
simple color picker
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
#include <X11/Xlib.h> | |
#include <X11/Xutil.h> | |
#include <X11/cursorfont.h> | |
#include <stdio.h> | |
int main() { | |
int x = 0; | |
int y = 0; | |
Display* display = NULL; | |
XImage* image = NULL; | |
Window root; | |
Cursor crosshair; | |
XEvent ev; | |
display = XOpenDisplay(NULL); | |
root = DefaultRootWindow(display); | |
crosshair = XCreateFontCursor(display, XC_crosshair); | |
XGrabPointer( | |
display, root, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, | |
crosshair, CurrentTime | |
); | |
while (1) { | |
XNextEvent(display, &ev); | |
if (ev.type == ButtonPress) { | |
x = ev.xbutton.x; | |
y = ev.xbutton.y; | |
break; | |
} | |
} | |
image = XGetImage(display, root, x, y, 1, 1, AllPlanes, ZPixmap); | |
printf("#%06X\n", XGetPixel(image, 0, 0)); | |
XDestroyImage(image); | |
XUngrabPointer(display, CurrentTime); | |
XFreeCursor(display, crosshair); | |
XCloseDisplay(display); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment