diff options
Diffstat (limited to 'src/video/x11')
-rw-r--r-- | src/video/x11/SDL_x11dyn.c | 4 | ||||
-rw-r--r-- | src/video/x11/SDL_x11dyn.h | 3 | ||||
-rw-r--r-- | src/video/x11/SDL_x11mouse.c | 46 | ||||
-rw-r--r-- | src/video/x11/SDL_x11sym.h | 8 | ||||
-rw-r--r-- | src/video/x11/SDL_x11video.h | 3 |
5 files changed, 63 insertions, 1 deletions
diff --git a/src/video/x11/SDL_x11dyn.c b/src/video/x11/SDL_x11dyn.c index 66239b44..96072dad 100644 --- a/src/video/x11/SDL_x11dyn.c +++ b/src/video/x11/SDL_x11dyn.c @@ -46,6 +46,9 @@ typedef struct #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL #endif +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR NULL +#endif #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA NULL #endif @@ -65,6 +68,7 @@ typedef struct static x11dynlib x11libs[] = { {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT}, + {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT}, {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR}, diff --git a/src/video/x11/SDL_x11dyn.h b/src/video/x11/SDL_x11dyn.h index 38adf538..7a2bef16 100644 --- a/src/video/x11/SDL_x11dyn.h +++ b/src/video/x11/SDL_x11dyn.h @@ -44,6 +44,9 @@ #include <X11/extensions/XShm.h> #endif +#if SDL_VIDEO_DRIVER_X11_XCURSOR +#include <X11/Xcursor/Xcursor.h> +#endif #if SDL_VIDEO_DRIVER_X11_XINERAMA #include <X11/extensions/Xinerama.h> #endif diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c index eed2b936..448de7ac 100644 --- a/src/video/x11/SDL_x11mouse.c +++ b/src/video/x11/SDL_x11mouse.c @@ -20,6 +20,8 @@ slouken@libsdl.org */ #include "SDL_config.h" + +#include "SDL_assert.h" #include "SDL_x11video.h" #include "SDL_x11mouse.h" #include "../../events/SDL_mouse_c.h" @@ -81,6 +83,35 @@ X11_CreateDefaultCursor() return cursor; } +#if SDL_VIDEO_DRIVER_X11_XCURSOR +static Cursor +X11_CreateXCursorCursor(SDL_Surface * surface, int hot_x, int hot_y) +{ + Display *display = GetDisplay(); + Cursor cursor = None; + XcursorImage *image; + + image = XcursorImageCreate(surface->w, surface->h); + if (!image) { + SDL_OutOfMemory(); + return None; + } + image->xhot = hot_x; + image->yhot = hot_y; + image->delay = 0; + + SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); + SDL_assert(surface->pitch == surface->w * 4); + SDL_memcpy(image->pixels, surface->pixels, surface->h * surface->pitch); + + cursor = XcursorImageLoadCursor(display, image); + + XcursorImageDestroy(image); + + return cursor; +} +#endif /* SDL_VIDEO_DRIVER_X11_XCURSOR */ + static Cursor X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y) { @@ -101,6 +132,9 @@ X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y) return None; } + /* Code below assumes ARGB pixel format */ + SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); + rfg = gfg = bfg = rbg = gbg = bbg = fgBits = 0; for (y = 0; y < surface->h; ++y) { ptr = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch); @@ -162,7 +196,17 @@ X11_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { - cursor->driverdata = (void*)X11_CreatePixmapCursor(surface, hot_x, hot_y); + Cursor x11_cursor = None; + +#if SDL_VIDEO_DRIVER_X11_XCURSOR + if (SDL_X11_HAVE_XCURSOR) { + x11_cursor = X11_CreateXCursorCursor(surface, hot_x, hot_y); + } +#endif + if (x11_cursor == None) { + x11_cursor = X11_CreatePixmapCursor(surface, hot_x, hot_y); + } + cursor->driverdata = (void*)x11_cursor; } else { SDL_OutOfMemory(); } diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h index 54a070bc..fef7589d 100644 --- a/src/video/x11/SDL_x11sym.h +++ b/src/video/x11/SDL_x11sym.h @@ -175,6 +175,14 @@ SDL_X11_SYM(int,ipAllocateData,(ChannelPtr a,IPCard b,IPDataPtr * c),(a,b,c),ret SDL_X11_SYM(int,ipUnallocateAndSendData,(ChannelPtr a,IPCard b),(a,b),return) #endif +/* XCursor support */ +#if SDL_VIDEO_DRIVER_X11_XCURSOR +SDL_X11_MODULE(XCURSOR) +SDL_X11_SYM(XcursorImage*,XcursorImageCreate,(int a,int b),(a,b),) +SDL_X11_SYM(void,XcursorImageDestroy,(XcursorImage *a),(a),) +SDL_X11_SYM(Cursor,XcursorImageLoadCursor,(Display *a,const XcursorImage *b),(a,b),) +#endif + /* Xinerama support */ #if SDL_VIDEO_DRIVER_X11_XINERAMA SDL_X11_MODULE(XINERAMA) diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 86a9199c..02f5ec8c 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -32,6 +32,9 @@ #include <X11/Xutil.h> #include <X11/Xatom.h> +#if SDL_VIDEO_DRIVER_X11_XCURSOR +#include <X11/Xcursor/Xcursor.h> +#endif #if SDL_VIDEO_DRIVER_X11_XINERAMA #include <X11/extensions/Xinerama.h> #endif |