[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#549375: mouse pointer not visible after changing resolution or refresh rate



Am Wed, 25. Nov 2009, 10:30:48 +0100 schrieb Jö Fahlke:
> Found a simpler workaround: lock the screen using xscreensaver.  Of course I
> have to type in my password to unlock it but it's better than putting the
> laptop into standby.

Attached are the relevant parts lifted from xscreensaver.  The program creates
a window covering the whole screen and sets the windows cursor to a cursor
created with XCreatePixmapCursor() from a 1x1 transparent pixmap.  The window
is then briefly mapped so the mouse pointer enters it.  After the window is
destroyed, the usual cursor is is visible again.

Creating the cursor with XCreateFontCursor() instead is not enough and I
haven't tried XCreateGlyphCursor().

To compile the program use

  gcc -lX11 -o fix-x-cursor fix-x-cursor.c

Bye,
Jö.


-- 
F: Was ist der Sinn des Menschen?
A: Die Menschheit voranzubringen.
F: Aber was ist der Sinn der Menschheit?
#include <stddef.h>
#include <stdio.h>

#include <X11/Xlib.h>

int main() {
  XSetWindowAttributes attrs;

  /* open X connections */
  Display* display = XOpenDisplay(NULL);
  if(display == NULL) {
    fprintf(stderr, "Can't open display\n");
    return 1;
  }

  /* get screen an root window */
  Screen* screen = ScreenOfDisplay(display, DefaultScreen(display));
  Window root = RootWindowOfScreen(screen);

  /* setup blank cursor */
  XColor black;
  black.red = black.green = black.blue = 0;
  Pixmap bit = XCreatePixmapFromBitmapData(display,
                                           root,
                                           "\000", 1, 1,
                                           BlackPixelOfScreen(screen),
                                           BlackPixelOfScreen(screen),
                                           1);
  attrs.cursor = XCreatePixmapCursor (display, bit, bit, &black, &black,
                                      0, 0);
  XFreePixmap (display, bit);

  /* we don't want a frame from the window manager */
  attrs.override_redirect = True;
  /* create a window covering the whole screen with the given cursor */
  Window window = XCreateWindow(display, root, 0, 0, WidthOfScreen(screen),
                                HeightOfScreen(screen), 0,
                                CopyFromParent, CopyFromParent, CopyFromParent,
                                CWOverrideRedirect|CWCursor, &attrs);
  XFreeCursor(display, attrs.cursor);
  /* make the window actually appear */
  XMapWindow(display, window);
  XSync(display, False);

  /* tear down */
  XCloseDisplay(display);
  return 0;
}

Attachment: signature.asc
Description: Digital signature


Reply to: