-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnight-vision.cpp
75 lines (58 loc) · 2.6 KB
/
night-vision.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <X11/Xlib.h>
#include <unistd.h>
#include <cstdlib>
int main(int argc, char* argv[]) {
Display* display = XOpenDisplay(nullptr);
if (!display) return -1;
Window root = DefaultRootWindow(display);
int screen = DefaultScreen(display);
Colormap colormap = DefaultColormap(display, screen);
XColor bgColor, exactBgColor;
XAllocNamedColor(display, colormap, "#2D353B", &bgColor, &bgColor);
XColor crossColor, exactCrossColor;
XAllocNamedColor(display, colormap, "#6FA07E", &crossColor, &crossColor);
XColor borderColor, exactBorderColor;
XAllocNamedColor(display, colormap, "#485953", &borderColor, &borderColor);
Window window = XCreateSimpleWindow(display, root, 0, 0, 24, 24, 2,
borderColor.pixel, bgColor.pixel);
XSetWindowAttributes attrs;
attrs.override_redirect = True;
attrs.background_pixel = bgColor.pixel;
XChangeWindowAttributes(display, window, CWOverrideRedirect | CWBackPixel, &attrs);
XMapRaised(display, window);
GC gc = XCreateGC(display, window, 0, nullptr);
XSetForeground(display, gc, crossColor.pixel);
int sleepTime = 100000; // Default sleep time in microseconds (100ms)
if (argc > 1) {
sleepTime = atoi(argv[1]) * 1000; // Convert milliseconds to microseconds
}
int lastX = -1, lastY = -1; // Variables to track the last known mouse position
int minHeight = 0; // TODO: User-defined via dotfile settings
while (true) {
Window dummy;
int x, y, dummy2;
unsigned int dummy3;
if (XQueryPointer(display, root, &dummy, &dummy, &x, &y, &dummy2, &dummy2, &dummy3)) {
if (x != lastX || y != lastY) { // Check if the mouse has actually moved
lastX = x;
lastY = y;
XMoveWindow(display, window, x - 12, y - 12); // Move the window only if necessary
XClearWindow(display, window);
for (int offset = -1; offset <= 1; ++offset) {
XDrawLine(display, window, gc, 12 + offset, 4, 12 + offset, 20);
XDrawLine(display, window, gc, 4, 12 + offset, 20, 12 + offset);
}
XWindowAttributes winAttrs;
if (XGetWindowAttributes(display, root, &winAttrs)) {
if (winAttrs.height >= minHeight) {
XRaiseWindow(display, window); // Conditionally raise the cursor window
}
}
XFlush(display);
}
}
usleep(sleepTime);
}
XCloseDisplay(display);
return 0;
}