[Amadeusz Sławiński]

Fix crashes with SDL on Linux due to delayed cursor setting.
This commit is contained in:
Alexei Svitkine 2012-06-18 19:31:50 -04:00
parent a1f0283221
commit be28a8e5d4

View File

@ -132,7 +132,6 @@ static int keycode_table[256]; // X keycode -> Mac keycode translation tabl
// SDL variables
static int screen_depth; // Depth of current screen
static SDL_Cursor *sdl_cursor; // Copy of Mac cursor
static volatile bool cursor_changed = false; // Flag: cursor changed, redraw_func must update the cursor
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors
static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK;
@ -798,7 +797,6 @@ driver_window::driver_window(SDL_monitor_desc &m)
// Create cursor
if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) {
SDL_SetCursor(sdl_cursor);
cursor_changed = false;
}
#else
// Hide cursor
@ -1538,6 +1536,7 @@ void SDL_monitor_desc::switch_to_current_mode(void)
#ifdef SHEEPSHAVER
bool video_can_change_cursor(void)
{
#if defined(__APPLE__)
static char driver[] = "Quartz?";
static int quartzok = -1;
@ -1556,6 +1555,9 @@ bool video_can_change_cursor(void)
}
return quartzok;
#else
return true;
#endif
}
#endif
@ -1567,7 +1569,25 @@ bool video_can_change_cursor(void)
#ifdef SHEEPSHAVER
void video_set_cursor(void)
{
cursor_changed = true;
// Set new cursor image if it was changed
if (sdl_cursor) {
SDL_FreeCursor(sdl_cursor);
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
if (sdl_cursor) {
SDL_ShowCursor(private_data == NULL || private_data->cursorVisible);
SDL_SetCursor(sdl_cursor);
#ifdef WIN32
// XXX Windows apparently needs an extra mouse event to
// make the new cursor image visible
int visible = SDL_ShowCursor(-1);
if (visible) {
int x, y;
SDL_GetMouseState(&x, &y);
SDL_WarpMouse(x, y);
}
#endif
}
}
}
#endif
@ -2239,30 +2259,6 @@ static inline void do_video_refresh(void)
// Update display
video_refresh();
#ifdef SHEEPSHAVER
// Set new cursor image if it was changed
if (cursor_changed && sdl_cursor) {
cursor_changed = false;
LOCK_EVENTS;
SDL_FreeCursor(sdl_cursor);
sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
if (sdl_cursor) {
SDL_ShowCursor(private_data == NULL || private_data->cursorVisible);
SDL_SetCursor(sdl_cursor);
#ifdef WIN32
// XXX Windows apparently needs an extra mouse event to
// make the new cursor image visible
int visible = SDL_ShowCursor(-1);
if (visible) {
int x, y;
SDL_GetMouseState(&x, &y);
SDL_WarpMouse(x, y);
}
#endif
}
UNLOCK_EVENTS;
}
#endif
// Set new palette if it was changed
handle_palette_changes();