Skip to content

Instantly share code, notes, and snippets.

@macrat
Created June 29, 2015 06:19
Show Gist options
  • Select an option

  • Save macrat/aa3ef84295f6eed8b225 to your computer and use it in GitHub Desktop.

Select an option

Save macrat/aa3ef84295f6eed8b225 to your computer and use it in GitHub Desktop.
飛び交うカーソル。
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int main()
{
Display *dpy = XOpenDisplay(NULL);
int w = WidthOfScreen(XDefaultScreenOfDisplay(dpy));
int h = HeightOfScreen(XDefaultScreenOfDisplay(dpy));
int x=0, y=0;
int mx=1, my=1;
while(1)
{
XWarpPointer(dpy, None, DefaultRootWindow(dpy), 0, 0, 0, 0, x, y);
XFlush(dpy);
x += mx;
y += my;
if(x < 0 || w < x)
mx *= -1;
if(y < 0 || h < y)
my *= -1;
usleep(1000);
}
XCloseDisplay(dpy);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment