Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <X11/Xlib.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <time.h>
- #include <math.h>
- #define NANOSECONDS_MULTIPLIER 1000000
- void run(Display *display, Window *window, XEvent *event, int *screen);
- const long interval = 500 * NANOSECONDS_MULTIPLIER;
- int frame = 0;
- typedef struct Engine {
- Display *display;
- Window window;
- XEvent event;
- int screen;
- } Engine;
- int main(int argc, char** argv, char** env) {
- // Initialization
- Engine *engine = calloc(1, sizeof(Engine));
- engine->display = XOpenDisplay(NULL);
- if (engine->display == NULL) {
- fprintf(stderr, "Cannot open display\n");
- exit(1);
- }
- engine->screen = XDefaultScreen(engine->display);
- engine->window = XRootWindow(engine->display, 0);
- XSelectInput(engine->display, engine->window, KeyReleaseMask | KeyPressMask);
- run(engine->display, (Window *) engine->window, &engine->event, &engine->screen);
- XCloseDisplay(engine->display);
- free(engine);
- return 0;
- }
- void run(Display *display, Window *window, XEvent *event, int *screen) {
- while(event->type != KeyPress) {
- double x = 1000 * cos(frame);
- double y = 1000 * sin(frame);
- XWarpPointer(display, None, *window, 0, 0, 0, 0, x, y);
- if (frame > XDisplayWidth(display, *screen))
- frame = 0;
- frame++;
- fprintf(stdout, "Running! -- frame: %d\n", frame);
- nanosleep((const struct timespec[]){{0, interval}}, NULL);
- XFlush(display);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement