简体   繁体   中英

Set X11 cursor to arrow

I attempted the following in a call to XCreateWindow():

unsigned long ctt_attribute_mask = CWWinGravity | CWCursor;

ctt_attributes->win_gravity = NorthEastGravity;
ctt_attributes->cursor = XC_arrow;

ctt_window = XCreateWindow(dpy, parent, ctt_xpos, ctt_ypos,
             ctt_xy_size, ctt_xy_size, ctt_border,
             ctt_depth, ctt_class, ctt_visual,
             ctt_attribute_mask, ctt_attributes);

This creates the window, but it doesn't affect the pointer when it rolls over the window.

I want to use the user's desktop environment's standard pointer cursor when the mouse appears over my window.

Xlib is required, because this is a toolkit-agnostic program.

ETA : Additional context is available; see create_ctt_window starting on line 35 in thesource file .

  1. ctt_attributes->cursor = XCreateFontCursor(dpy, XC_arrow);
  2. This is not the desktop environment's standard pointer cursor, this is the X11 rather ugly bitmapped cursor. If you want themed cursors, use libXcursor. I have no experience with it.

Here's the example from The Xlib Programming Manual, vol 1, p 182.

#include <X11/cursorfont.h>
int cursor_shape = XC_arrow;
Window window;
Cursor cursor;
cursor = XCreateFontCursor(display, cursor_shape);
XDefineCursor(display, window, cursor);
/* Now cursor will appear when pointer is in window */ 

So it looks like nm is spot-on. You need to call XCreateFontCursor to translate XC_arrow (which is just an integer that designates the cursor's location in the font's encoding vector) into a Cursor resource. I think the Cursor resource is just an integer, too. That's why you get no compile error. But you do indeed have a type mismatch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM