src/video/x11/SDL_x11mouse.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 25 Mar 2011 10:26:25 -0700
changeset 5505 c4bb4c8ea6fd
parent 5481 22dfc3958dc3
child 5535 96594ac5fd1a
permissions -rw-r--r--
Fixed signed/unsigned warning.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
     3
    Copyright (C) 1997-2011 Sam Lantinga
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
    Lesser General Public License for more details.
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
*/
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#include "SDL_config.h"
5471
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    23
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5471
diff changeset
    24
#if SDL_VIDEO_DRIVER_X11
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5471
diff changeset
    25
5471
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    26
#include "SDL_assert.h"
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_x11video.h"
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    28
#include "SDL_x11mouse.h"
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "../../events/SDL_mouse_c.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    31
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    32
/* FIXME: Find a better place to put this... */
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    33
static Cursor x11_empty_cursor = None;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    34
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    35
static Display *
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    36
GetDisplay(void)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    37
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    38
    return ((SDL_VideoData *)SDL_GetVideoDevice()->driverdata)->display;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    39
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    40
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    41
static Cursor
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    42
X11_CreateEmptyCursor()
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    43
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    44
    if (x11_empty_cursor == None) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    45
        Display *display = GetDisplay();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    46
        char data[1];
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    47
        XColor color;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    48
        Pixmap pixmap;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    49
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    50
        SDL_zero(data);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    51
        color.red = color.green = color.blue = 0;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    52
        pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    53
                                       data, 1, 1);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    54
        if (pixmap) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    55
            x11_empty_cursor = XCreatePixmapCursor(display, pixmap, pixmap,
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    56
                                                   &color, &color, 0, 0);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    57
            XFreePixmap(display, pixmap);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    58
        }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    59
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    60
    return x11_empty_cursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    61
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    62
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    63
static void
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    64
X11_DestroyEmptyCursor(void)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    65
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    66
    if (x11_empty_cursor != None) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    67
        XFreeCursor(GetDisplay(), x11_empty_cursor);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    68
        x11_empty_cursor = None;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    69
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    70
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    71
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    72
static SDL_Cursor *
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    73
X11_CreateDefaultCursor()
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    74
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    75
    SDL_Cursor *cursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    76
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    77
    cursor = SDL_calloc(1, sizeof(*cursor));
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    78
    if (cursor) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    79
        /* None is used to indicate the default cursor */
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    80
        cursor->driverdata = (void*)None;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    81
    } else {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    82
        SDL_OutOfMemory();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    83
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    84
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    85
    return cursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    86
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    87
5471
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    88
#if SDL_VIDEO_DRIVER_X11_XCURSOR
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    89
static Cursor
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    90
X11_CreateXCursorCursor(SDL_Surface * surface, int hot_x, int hot_y)
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    91
{
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    92
    Display *display = GetDisplay();
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    93
    Cursor cursor = None;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    94
    XcursorImage *image;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    95
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    96
    image = XcursorImageCreate(surface->w, surface->h);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    97
    if (!image) {
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    98
        SDL_OutOfMemory();
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
    99
        return None;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   100
    }
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   101
    image->xhot = hot_x;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   102
    image->yhot = hot_y;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   103
    image->delay = 0;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   104
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   105
    SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   106
    SDL_assert(surface->pitch == surface->w * 4);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   107
    SDL_memcpy(image->pixels, surface->pixels, surface->h * surface->pitch);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   108
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   109
    cursor = XcursorImageLoadCursor(display, image);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   110
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   111
    XcursorImageDestroy(image);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   112
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   113
    return cursor;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   114
}
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   115
#endif /* SDL_VIDEO_DRIVER_X11_XCURSOR */
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   116
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   117
static Cursor
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   118
X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   119
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   120
    Display *display = GetDisplay();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   121
    XColor fg, bg;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   122
    Cursor cursor = None;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   123
    Uint32 *ptr;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   124
    Uint8 *data_bits, *mask_bits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   125
    Pixmap data_pixmap, mask_pixmap;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   126
    int x, y;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   127
    unsigned int rfg, gfg, bfg, rbg, gbg, bbg, fgBits, bgBits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   128
    unsigned int width_bytes = ((surface->w + 7) & ~7) / 8;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   129
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   130
    data_bits = SDL_calloc(1, surface->h * width_bytes);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   131
    mask_bits = SDL_calloc(1, surface->h * width_bytes);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   132
    if (!data_bits || !mask_bits) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   133
        SDL_OutOfMemory();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   134
        return None;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   135
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   136
5471
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   137
    /* Code below assumes ARGB pixel format */
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   138
    SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   139
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   140
    rfg = gfg = bfg = rbg = gbg = bbg = fgBits = 0;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   141
    for (y = 0; y < surface->h; ++y) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   142
        ptr = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   143
        for (x = 0; x < surface->w; ++x) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   144
            int alpha = (*ptr >> 24) & 0xff;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   145
            int red   = (*ptr >> 16) & 0xff;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   146
            int green = (*ptr >> 8) & 0xff;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   147
            int blue  = (*ptr >> 0) & 0xff;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   148
            if (alpha > 25) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   149
                mask_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8));
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   150
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   151
                if ((red + green + blue) > 0x40) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   152
                    fgBits++;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   153
                    rfg += red;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   154
                    gfg += green;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   155
                    bfg += blue;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   156
                    data_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8));
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   157
                } else {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   158
                    bgBits++;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   159
                    rbg += red;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   160
                    gbg += green;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   161
                    bbg += blue;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   162
                }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   163
            }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   164
            ++ptr;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   165
        }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   166
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   167
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   168
    if (fgBits) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   169
        fg.red   = rfg * 257 / fgBits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   170
        fg.green = gfg * 257 / fgBits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   171
        fg.blue  = bfg * 257 / fgBits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   172
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   173
    else fg.red = fg.green = fg.blue = 0;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   174
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   175
    if (bgBits) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   176
        bg.red   = rbg * 257 / bgBits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   177
        bg.green = gbg * 257 / bgBits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   178
        bg.blue  = bbg * 257 / bgBits;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   179
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   180
    else bg.red = bg.green = bg.blue = 0;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   181
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   182
    data_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
5505
c4bb4c8ea6fd Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   183
                                        (char*)data_bits,
c4bb4c8ea6fd Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   184
                                        surface->w, surface->h);
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   185
    mask_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
5505
c4bb4c8ea6fd Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   186
                                        (char*)mask_bits,
c4bb4c8ea6fd Fixed signed/unsigned warning.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
   187
                                        surface->w, surface->h);
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   188
    cursor = XCreatePixmapCursor(display, data_pixmap, mask_pixmap,
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   189
                                 &fg, &bg, hot_x, hot_y);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   190
	XFreePixmap(display, data_pixmap);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   191
	XFreePixmap(display, mask_pixmap);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   192
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   193
    return cursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   194
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   195
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   196
static SDL_Cursor *
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   197
X11_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   198
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   199
    SDL_Cursor *cursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   200
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   201
    cursor = SDL_calloc(1, sizeof(*cursor));
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   202
    if (cursor) {
5471
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   203
        Cursor x11_cursor = None;
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   204
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   205
#if SDL_VIDEO_DRIVER_X11_XCURSOR
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   206
        if (SDL_X11_HAVE_XCURSOR) {
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   207
            x11_cursor = X11_CreateXCursorCursor(surface, hot_x, hot_y);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   208
        }
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   209
#endif
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   210
        if (x11_cursor == None) {
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   211
            x11_cursor = X11_CreatePixmapCursor(surface, hot_x, hot_y);
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   212
        }
179adad3ae6f Added support for the Xcursor library for color cursors
Sam Lantinga <slouken@libsdl.org>
parents: 5470
diff changeset
   213
        cursor->driverdata = (void*)x11_cursor;
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   214
    } else {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   215
        SDL_OutOfMemory();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   216
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   217
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   218
    return cursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   219
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   220
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   221
static void
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   222
X11_FreeCursor(SDL_Cursor * cursor)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   223
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   224
    Cursor x11_cursor = (Cursor)cursor->driverdata;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   225
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   226
    if (x11_cursor != None) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   227
        XFreeCursor(GetDisplay(), x11_cursor);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   228
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   229
    SDL_free(cursor);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   230
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   231
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   232
static int
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   233
X11_ShowCursor(SDL_Cursor * cursor)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   234
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   235
    Cursor x11_cursor = 0;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   236
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   237
    if (cursor) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   238
        x11_cursor = (Cursor)cursor->driverdata;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   239
    } else {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   240
        x11_cursor = X11_CreateEmptyCursor();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   241
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   242
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   243
    /* FIXME: Is there a better way than this? */
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   244
    {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   245
        SDL_VideoDevice *video = SDL_GetVideoDevice();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   246
        Display *display = GetDisplay();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   247
        SDL_Window *window;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   248
        SDL_WindowData *data;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   249
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   250
        for (window = video->windows; window; window = window->next) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   251
            data = (SDL_WindowData *)window->driverdata;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   252
            if (x11_cursor != None) {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   253
                XDefineCursor(display, data->xwindow, x11_cursor);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   254
            } else {
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   255
                XUndefineCursor(display, data->xwindow);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   256
            }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   257
        }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   258
        XFlush(display);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   259
    }
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   260
    return 0;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   261
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   262
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   263
static void
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   264
X11_WarpMouse(SDL_Window * window, int x, int y)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   265
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   266
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   267
    Display *display = data->videodata->display;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   268
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   269
    XWarpPointer(display, None, data->xwindow, 0, 0, 0, 0, x, y);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   270
    XSync(display, False);
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   271
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   272
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   273
static int
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   274
X11_SetRelativeMouseMode(SDL_bool enabled)
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   275
{
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   276
    SDL_Unsupported();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   277
    return -1;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   278
}
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   279
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
void
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
X11_InitMouse(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
{
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   283
    SDL_Mouse *mouse = SDL_GetMouse();
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   284
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   285
    mouse->CreateCursor = X11_CreateCursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   286
    mouse->ShowCursor = X11_ShowCursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   287
    mouse->FreeCursor = X11_FreeCursor;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   288
    mouse->WarpMouse = X11_WarpMouse;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   289
    mouse->SetRelativeMouseMode = X11_SetRelativeMouseMode;
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   290
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   291
    SDL_SetDefaultCursor(X11_CreateDefaultCursor());
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
void
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
X11_QuitMouse(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
{
5470
8f5e10ec4faf Implemented X11 cursor support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   297
    X11_DestroyEmptyCursor();
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5471
diff changeset
   300
#endif /* SDL_VIDEO_DRIVER_X11 */
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5471
diff changeset
   301
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
/* vi: set ts=4 sw=4 expandtab: */