Apply the requested cursor shape (the same 0..=6 enum macOS uses in NSCursor calls). XCreateFontCursor uses cursor-font glyph constants from ; we cache one Cursor per shape so repeat calls don't leak server-side state.
(shape: u32)
| 340 | /// constants from <X11/cursorfont.h>; we cache one Cursor per shape |
| 341 | /// so repeat calls don't leak server-side state. |
| 342 | pub fn apply_cursor_shape(shape: u32) { |
| 343 | unsafe { |
| 344 | if DISPLAY.is_null() || X11_WINDOW == 0 || CURSOR_HIDDEN { return; } |
| 345 | if shape == LAST_APPLIED_SHAPE { return; } |
| 346 | // X11 cursor-font glyph indices (from cursorfont.h). |
| 347 | // 0 = default arrow → XC_left_ptr (68) |
| 348 | // 1 = pointing hand → XC_hand2 (60) |
| 349 | // 2 = open hand → XC_fleur (52, "move") |
| 350 | // 3 = I-beam → XC_xterm (152) |
| 351 | // 4 = resize H → XC_sb_h_double_arrow (108) |
| 352 | // 5 = resize V → XC_sb_v_double_arrow (116) |
| 353 | // 6 = crosshair → XC_crosshair (34) |
| 354 | let glyph: u32 = match shape { |
| 355 | 1 => 60, |
| 356 | 2 => 52, |
| 357 | 3 => 152, |
| 358 | 4 => 108, |
| 359 | 5 => 116, |
| 360 | 6 => 34, |
| 361 | _ => 68, |
| 362 | }; |
| 363 | let idx = (shape as usize).min(SHAPE_CURSORS.len() - 1); |
| 364 | if SHAPE_CURSORS[idx] == 0 { |
| 365 | SHAPE_CURSORS[idx] = x11::xlib::XCreateFontCursor(DISPLAY, glyph); |
| 366 | } |
| 367 | if SHAPE_CURSORS[idx] != 0 { |
| 368 | x11::xlib::XDefineCursor(DISPLAY, X11_WINDOW, SHAPE_CURSORS[idx]); |
| 369 | x11::xlib::XFlush(DISPLAY); |
| 370 | LAST_APPLIED_SHAPE = shape; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | pub fn poll_events() { |
| 376 | unsafe { |
no outgoing calls
no test coverage detected