Skip to content

Instantly share code, notes, and snippets.

@xmisao
Created October 2, 2013 11:45
Show Gist options
  • Save xmisao/6792485 to your computer and use it in GitHub Desktop.
Save xmisao/6792485 to your computer and use it in GitHub Desktop.
#include<X11/Xlib.h>
#include<stdio.h>
#include<time.h>
typedef struct{
int x, y;
} Pos;
Pos get_pos(Display *dpy, Window root){
Window w;
Window root_return, child_return;
Pos root_pos;
int win_x, win_y;
unsigned int mask;
XQueryPointer(dpy, root, &root_return, &child_return, &root_pos.x, &root_pos.y, &win_x, &win_y, &mask);
return root_pos;
}
int main(){
Display* dpy;
Window root;
Pos pos;
time_t t;
dpy = XOpenDisplay(NULL);
root = DefaultRootWindow(dpy);
while(1){
time(&t);
pos = get_pos(dpy, root);
printf("%d,%d,%s", pos.x, pos.y, ctime(&t));
fflush(stdout);
sleep(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment