21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_X11
25 #include <X11/cursorfont.h>
30 #include "../../events/SDL_mouse_c.h"
34 static Cursor x11_empty_cursor = None;
43 X11_CreateEmptyCursor()
45 if (x11_empty_cursor == None) {
46 Display *display = GetDisplay();
53 pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
56 x11_empty_cursor = X11_XCreatePixmapCursor(display,
pixmap,
pixmap,
58 X11_XFreePixmap(display,
pixmap);
61 return x11_empty_cursor;
65 X11_DestroyEmptyCursor(
void)
67 if (x11_empty_cursor != None) {
68 X11_XFreeCursor(GetDisplay(), x11_empty_cursor);
69 x11_empty_cursor = None;
74 X11_CreateDefaultCursor()
89 #if SDL_VIDEO_DRIVER_X11_XCURSOR
93 Display *display = GetDisplay();
110 cursor = X11_XcursorImageLoadCursor(display,
image);
112 X11_XcursorImageDestroy(
image);
121 Display *display = GetDisplay();
125 Uint8 *data_bits, *mask_bits;
126 Pixmap data_pixmap, mask_pixmap;
128 unsigned int rfg, gfg, bfg, rbg, gbg, bbg, fgBits, bgBits;
129 unsigned int width_bytes = ((
surface->w + 7) & ~7) / 8;
147 rfg = gfg = bfg = rbg = gbg = bbg = fgBits = bgBits = 0;
152 int red = (*
ptr >> 16) & 0xff;
156 mask_bits[
y * width_bytes +
x / 8] |= (0x01 << (
x % 8));
163 data_bits[
y * width_bytes +
x / 8] |= (0x01 << (
x % 8));
176 fg.red = rfg * 257 / fgBits;
177 fg.green = gfg * 257 / fgBits;
178 fg.blue = bfg * 257 / fgBits;
180 else fg.red = fg.green = fg.blue = 0;
183 bg.red = rbg * 257 / bgBits;
184 bg.green = gbg * 257 / bgBits;
185 bg.blue = bbg * 257 / bgBits;
187 else bg.red = bg.green = bg.blue = 0;
189 data_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
192 mask_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
195 cursor = X11_XCreatePixmapCursor(display, data_pixmap, mask_pixmap,
196 &fg, &bg,
hot_x, hot_y);
197 X11_XFreePixmap(display, data_pixmap);
198 X11_XFreePixmap(display, mask_pixmap);
210 Cursor x11_cursor = None;
212 #if SDL_VIDEO_DRIVER_X11_XCURSOR
213 if (SDL_X11_HAVE_XCURSOR) {
214 x11_cursor = X11_CreateXCursorCursor(
surface,
hot_x, hot_y);
217 if (x11_cursor == None) {
218 x11_cursor = X11_CreatePixmapCursor(
surface,
hot_x, hot_y);
259 x11_cursor = X11_XCreateFontCursor(GetDisplay(), shape);
274 if (x11_cursor != None) {
275 X11_XFreeCursor(GetDisplay(), x11_cursor);
283 Cursor x11_cursor = 0;
288 x11_cursor = X11_CreateEmptyCursor();
294 Display *display = GetDisplay();
300 if (x11_cursor != None) {
301 X11_XDefineCursor(display,
data->xwindow, x11_cursor);
303 X11_XUndefineCursor(display,
data->xwindow);
312 WarpMouseInternal(Window xwindow,
const int x,
const int y)
315 Display *display = videodata->
display;
316 X11_XWarpPointer(display, None, xwindow, 0, 0, 0, 0,
x,
y);
317 X11_XSync(display, False);
325 WarpMouseInternal(
data->xwindow,
x,
y);
329 X11_WarpMouseGlobal(
int x,
int y)
331 WarpMouseInternal(DefaultRootWindow(GetDisplay()),
x,
y);
338 #if SDL_VIDEO_DRIVER_X11_XINPUT2
350 Display *display = GetDisplay();
354 const unsigned int mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask;
355 const int rc = X11_XGrabPointer(display,
data->xwindow, False,
356 mask, GrabModeAsync, GrabModeAsync,
357 None, None, CurrentTime);
358 if (rc != GrabSuccess) {
362 X11_XUngrabPointer(display, CurrentTime);
365 X11_XSync(display, False);
371 X11_GetGlobalMouseState(
int *
x,
int *
y)
374 Display *display = GetDisplay();
380 #if !SDL_VIDEO_DRIVER_X11_XINPUT2
387 for (
i = 0;
i < num_screens;
i++) {
391 int rootx, rooty, winx, winy;
393 if (X11_XQueryPointer(display, RootWindow(display,
data->screen), &root, &child, &rootx, &rooty, &winx, &winy, &
mask)) {
394 XWindowAttributes root_attrs;
403 X11_XGetWindowAttributes(display, root, &root_attrs);
443 X11_DestroyEmptyCursor();