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();
52 color.red = color.green = color.blue = 0;
53 pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
56 x11_empty_cursor = X11_XCreatePixmapCursor(display, pixmap, pixmap,
57 &color, &color, 0, 0);
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 91 X11_CreateXCursorCursor(
SDL_Surface * surface,
int hot_x,
int hot_y)
93 Display *display = GetDisplay();
97 image = X11_XcursorImageCreate(surface->
w, surface->
h);
110 cursor = X11_XcursorImageLoadCursor(display, image);
112 X11_XcursorImageDestroy(image);
119 X11_CreatePixmapCursor(
SDL_Surface * surface,
int hot_x,
int hot_y)
121 Display *display = GetDisplay();
123 Cursor cursor = None;
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;
131 data_bits =
SDL_calloc(1, surface->
h * width_bytes);
137 mask_bits =
SDL_calloc(1, surface->
h * width_bytes);
147 rfg = gfg = bfg = rbg = gbg = bbg = fgBits = bgBits = 0;
148 for (y = 0; y < surface->
h; ++
y) {
150 for (x = 0; x < surface->
w; ++
x) {
151 int alpha = (*ptr >> 24) & 0xff;
152 int red = (*ptr >> 16) & 0xff;
153 int green = (*ptr >> 8) & 0xff;
154 int blue = (*ptr >> 0) & 0xff;
156 mask_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8));
158 if ((red + green + blue) > 0x40) {
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),
191 surface->
w, surface->
h);
192 mask_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
194 surface->
w, surface->
h);
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);
204 X11_CreateCursor(
SDL_Surface * surface,
int hot_x,
int hot_y)
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);
272 Cursor x11_cursor = (Cursor)cursor->
driverdata;
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();
298 for (window = video->
windows; window; window = window->
next) {
300 if (x11_cursor != None) {
301 X11_XDefineCursor(display, data->
xwindow, x11_cursor);
303 X11_XUndefineCursor(display, data->
xwindow);
312 X11_WarpMouse(
SDL_Window * window,
int x,
int y)
317 X11_XWarpPointer(display, None, data->
xwindow, 0, 0, 0, 0, x, y);
318 X11_XSync(display, False);
322 X11_WarpMouseGlobal(
int x,
int y)
324 Display *display = GetDisplay();
326 X11_XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, x, y);
327 X11_XSync(display, False);
334 #if SDL_VIDEO_DRIVER_X11_XINPUT2 346 Display *display = GetDisplay();
350 const unsigned int mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask;
351 const int rc = X11_XGrabPointer(display, data->
xwindow, False,
352 mask, GrabModeAsync, GrabModeAsync,
353 None, None, CurrentTime);
354 if (rc != GrabSuccess) {
358 X11_XUngrabPointer(display, CurrentTime);
361 X11_XSync(display, False);
367 X11_GetGlobalMouseState(
int *x,
int *y)
370 Display *display = GetDisplay();
376 #if !SDL_VIDEO_DRIVER_X11_XINPUT2 383 for (i = 0; i < num_screens; i++) {
387 int rootx, rooty, winx, winy;
389 if (X11_XQueryPointer(display, RootWindow(display, data->
screen), &root, &child, &rootx, &rooty, &winx, &winy, &mask)) {
390 XWindowAttributes root_attrs;
399 X11_XGetWindowAttributes(display, root, &root_attrs);
439 X11_DestroyEmptyCursor();
SDL_Mouse * SDL_GetMouse(void)
int(* ShowCursor)(SDL_Cursor *cursor)
GLint GLint GLint GLint GLint x
int(* SetRelativeMouseMode)(SDL_bool enabled)
struct wl_display * display
static SDL_Window * window
A collection of pixels used in software blitting.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Uint32(* GetGlobalMouseState)(int *x, int *y)
void X11_InitMouse(_THIS)
uint32_t Uint32
An unsigned 32-bit integer type.
SDL_bool global_mouse_changed
GLfloat GLfloat GLfloat alpha
void * SDL_GetDisplayDriverData(int displayIndex)
SDL_Point global_mouse_position
#define SDL_GetNumVideoDisplays
int(* CaptureMouse)(SDL_Window *window)
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
void * SDL_calloc(size_t nmemb, size_t size)
GLint GLint GLint GLint GLint GLint y
struct SDL_VideoData * videodata
uint8_t Uint8
An unsigned 8-bit integer type.
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
void X11_QuitMouse(_THIS)
int(* WarpMouseGlobal)(int x, int y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void(* FreeCursor)(SDL_Cursor *cursor)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
Uint32 global_mouse_buttons
The type used to identify a window.
void(* WarpMouse)(SDL_Window *window, int x, int y)
SDL_VideoDevice * SDL_GetVideoDevice(void)
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
#define SDL_Unsupported()