annoying/main.c

69 lines
1.6 KiB
C
Raw Normal View History

2019-06-02 15:26:49 +00:00
#include <stdlib.h>
2019-06-02 14:46:54 +00:00
#include <X11/Xlib.h>
2019-06-02 15:26:49 +00:00
#include <time.h>
#include <stdbool.h>
2019-06-02 15:35:31 +00:00
#include <zconf.h>
2019-06-03 17:59:29 +00:00
#include <string.h>
#include <stdio.h>
2019-06-02 15:26:49 +00:00
2019-06-03 17:59:29 +00:00
bool debugEnabled = false;
unsigned int getRandom(int lower, int upper) {
2019-06-02 15:41:43 +00:00
unsigned int seed = (unsigned int) time(NULL);
srand(seed);
2019-06-03 17:59:29 +00:00
return (unsigned int) (rand() % (upper - lower + 1) + lower);
2019-06-02 15:41:43 +00:00
}
void moveCursor() {
2019-06-02 15:26:49 +00:00
Display *dpy;
Window root_window;
dpy = XOpenDisplay(0);
2019-06-02 15:41:43 +00:00
Screen *screen = XScreenOfDisplay(dpy, 0);
2019-06-02 15:26:49 +00:00
root_window = XRootWindow(dpy, 0);
2019-06-02 15:46:09 +00:00
unsigned int width = (unsigned int) XWidthOfScreen(screen);
unsigned int height = (unsigned int) XHeightOfScreen(screen);
2019-06-02 15:26:49 +00:00
2019-06-02 15:41:43 +00:00
int destX = getRandom(0, width);
int destY = getRandom(0, height);
XWarpPointer(dpy, None, root_window, 0, 0, width, height, destX, destY);
XFlush(dpy);
2019-06-03 17:59:29 +00:00
if (debugEnabled) {
printf("Moved cursor to x: %d y: %d.\n", destX, destY);
}
2019-06-02 15:26:49 +00:00
}
2019-06-02 14:46:54 +00:00
2019-06-03 17:59:29 +00:00
int main(int argc, char **argv) {
int minSleep = 60;
int maxSleep = 600;
if(argc > 1) {
for (int i = 1; i <= (argc - 1); ++i) {
if (strcmp(argv[i], "--debug") == 0) {
debugEnabled = true;
minSleep = 1;
maxSleep = 10;
}
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
2019-06-02 15:35:31 +00:00
while(true) {
2019-06-03 17:59:29 +00:00
unsigned int sleepTime = getRandom(minSleep, maxSleep);
if (debugEnabled) {
printf("Sleeping for %d seconds.\n", sleepTime);
}
sleep(sleepTime);
2019-06-02 15:35:31 +00:00
if (getRandom(0, 100) > 50) {
continue;
}
2019-06-02 15:26:49 +00:00
2019-06-02 15:41:43 +00:00
moveCursor();
2019-06-02 15:26:49 +00:00
}
2019-06-03 17:59:29 +00:00
#pragma clang diagnostic pop
2019-06-02 14:32:57 +00:00
}