freezmi

XCreateFontCursor example to test libXcursor dlopen

Mar 23rd, 2026
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | Source Code | 0 0
  1. #include <X11/Xlib.h>
  2. #include <X11/cursorfont.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main() {
  7.     Display *display;
  8.     Window window;
  9.     int screen;
  10.     Cursor cursor;
  11.  
  12.     display = XOpenDisplay(NULL);
  13.     if (display == NULL) {
  14.         fprintf(stderr, "Cannot open display\n");
  15.         exit(1);
  16.     }
  17.  
  18.     screen = DefaultScreen(display);
  19.  
  20.     window = XCreateSimpleWindow(
  21.         display,
  22.         RootWindow(display, screen),
  23.         100, 100, 400, 300, 1,
  24.         BlackPixel(display, screen),
  25.         WhitePixel(display, screen)
  26.     );
  27.  
  28.     XSelectInput(display, window, ExposureMask | KeyPressMask);
  29.  
  30.     printf("mytrace: start\n");
  31.     cursor = XCreateFontCursor(display, XC_hand2);
  32.     printf("mytrace: end\n");
  33.  
  34.     XDefineCursor(display, window, cursor);
  35.  
  36.     XMapWindow(display, window);
  37.  
  38.     while (1) {
  39.         XEvent event;
  40.         XNextEvent(display, &event);
  41.  
  42.         if (event.type == Expose) {
  43.         } else if (event.type == KeyPress) {
  44.             break; // Exit on key press
  45.         }
  46.     }
  47.  
  48.     XFreeCursor(display, cursor);
  49.     XDestroyWindow(display, window);
  50.     XCloseDisplay(display);
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment