-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
59 lines (54 loc) · 2.19 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdlib>
int main()
{
Display *display = XOpenDisplay(NULL);
if (display == NULL)
{
return 1;
}
Cursor cursor = XCreateFontCursor(display, XC_ul_angle);
XGrabPointer(display, DefaultRootWindow(display), False,
ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask,
GrabModeAsync, GrabModeAsync, RootWindow(display, DefaultScreen(display)), cursor, CurrentTime);
XGrabKeyboard(display, DefaultRootWindow(display), False, GrabModeAsync, GrabModeAsync, CurrentTime);
XEvent e;
while (true)
{
XNextEvent(display, &e);
if(e.type == ButtonPress)
{
XImage *screen;
screen = XGetImage (display, RootWindow(display, DefaultScreen(display)), e.xbutton.x, e.xbutton.y, 1, 1, AllPlanes, XYPixmap);
XColor color;
color.pixel = XGetPixel (screen, 0, 0);
XFree (screen);
XQueryColor (display, DefaultColormap(display, DefaultScreen (display)), &color);
std::cout<< std::setfill ('0') << std::setw (2) << std::hex << (255*color.red)/65535
<< std::setfill ('0') << std::setw (2) << std::hex << (255*color.green)/65535
<< std::setfill ('0') << std::setw (2) << std::hex << (255*color.blue)/65535 << std::endl;
std::stringstream ss;
ss << "printf \""
<< std::setfill ('0') << std::setw (2) << std::hex << (255*color.red)/65535
<< std::setfill ('0') << std::setw (2) << std::hex << (255*color.green)/65535
<< std::setfill ('0') << std::setw (2) << std::hex << (255*color.blue)/65535 << "\" | xsel -i -b";
std::string cmd = ss.str();
system(cmd.c_str());
break;
}
else if (e.type == KeyPress)
{
if (e.xkey.keycode == XKeysymToKeycode(display, XK_Escape))
break;
}
}
XUngrabPointer(display, CurrentTime);
XCloseDisplay(display);
return 0;
}