On Tue, May 12, 2009 at 11:21:09AM +0200, Frank Blendinger wrote:
> > I guess I have to switch back to my own solution.
>
> What would that be?
I wrote a little tool that uses the cursor hide/show functions from
libxfixes. It's nothing that I'd recommend using, but I've attached it
if you want to take a look.
Andreas
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
static const int FREQ = 250; // timer frequency in ms
static const int TIMEOUT = 2000; // timeout for cursor hiding
typedef struct {
int x;
int y;
} point;
static point get_pointer_coords(Display *dpy) {
point coords;
Window root, child;
int win_x, win_y, mask;
Bool ret = XQueryPointer(dpy, DefaultRootWindow(dpy), &root, &child,
&coords.x, &coords.y, &win_x, &win_y, &mask);
return coords;
}
static Bool pointer_moved(Display *dpy, point old_coords) {
point new_coords = get_pointer_coords(dpy);
if ((old_coords.x == new_coords.x)
&& (old_coords.y == new_coords.y))
return False;
else
return True;
}
int main (int argv, char** argc) {
// open display
Display *dpy = XOpenDisplay(getenv("DISPLAY"));
if (dpy == NULL) {
perror("XOpenDisplay");
exit(1);
}
// setup signal
sigset_t sig_timer;
sigemptyset(&sig_timer);
sigaddset(&sig_timer, SIGALRM);
int ret = sigprocmask(SIG_BLOCK, &sig_timer, NULL);
if (ret == -1) {
perror("sigprocmask");
exit(2);
}
// setup timer
struct itimerval itval;
itval.it_interval.tv_sec = 0;
itval.it_interval.tv_usec = FREQ * 1000;
itval.it_value.tv_sec = 0;
itval.it_value.tv_usec = FREQ * 1000;
ret = setitimer(ITIMER_REAL, &itval, NULL);
if (ret == -1) {
perror("setitimer");
exit(3);
}
int timer_ticks = 0;
const int timeout_ticks = TIMEOUT / FREQ;
point pointer_coords = get_pointer_coords(dpy);
Bool pointer_hidden = False;
// wait for signal
while (sigwaitinfo(&sig_timer, NULL) != -1) {
if (pointer_moved(dpy, pointer_coords)) {
if (pointer_hidden) {
XFixesShowCursor(dpy, DefaultRootWindow(dpy));
XFlush(dpy);
pointer_hidden = False;
}
timer_ticks = 0;
}
else {
timer_ticks++;
if (!pointer_hidden && (timer_ticks >= timeout_ticks)) {
XFixesHideCursor(dpy, DefaultRootWindow(dpy));
XFlush(dpy);
pointer_hidden = True;
}
}
pointer_coords = get_pointer_coords(dpy);
}
XCloseDisplay(dpy);
return 0;
/*
// Alternative solution is to make an invisible pointer
Pixmap pix;
static char bits[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
XColor cfg;
cfg.red = cfg.green = cfg.blue = 0;
pix = XCreateBitmapFromData(gp->dc->display, gp->gwin, bits, 8, 8);
MyCursor = XCreatePixmapCursor(gp->dc->display, pix, pix, &cfg, &cfg, 0,0);
XFreePixmap(gp->dc->display, pix);
// hide
XDefineCursor(display , window , MyCursor);
// show
XDefineCursor(display , window , some_other_cursor);
*/
}