Debug option

This commit is contained in:
psy 2019-06-03 19:59:29 +02:00
parent b47198fdc0
commit 368b869fdd
1 changed files with 33 additions and 4 deletions

37
main.c
View File

@ -3,11 +3,15 @@
#include <time.h>
#include <stdbool.h>
#include <zconf.h>
#include <string.h>
#include <stdio.h>
int getRandom(int lower, int upper) {
bool debugEnabled = false;
unsigned int getRandom(int lower, int upper) {
unsigned int seed = (unsigned int) time(NULL);
srand(seed);
return rand() % (upper - lower + 1) + lower;
return (unsigned int) (rand() % (upper - lower + 1) + lower);
}
void moveCursor() {
@ -25,15 +29,40 @@ void moveCursor() {
XWarpPointer(dpy, None, root_window, 0, 0, width, height, destX, destY);
XFlush(dpy);
if (debugEnabled) {
printf("Moved cursor to x: %d y: %d.\n", destX, destY);
}
}
int main() {
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"
while(true) {
sleep(getRandom(60, 600));
unsigned int sleepTime = getRandom(minSleep, maxSleep);
if (debugEnabled) {
printf("Sleeping for %d seconds.\n", sleepTime);
}
sleep(sleepTime);
if (getRandom(0, 100) > 50) {
continue;
}
moveCursor();
}
#pragma clang diagnostic pop
}