19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mouse.h"
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h"
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_cursor_c.h"
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_ph_mouse_c.h"
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct WMcursor
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    PhCursorDef_t *ph_cursor ;
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ph_FreeWMCursor(_THIS, WMcursor *cursor)
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (window != NULL)
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_Lock_EventThread();
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if (PtSetResource(window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) < 0)
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* TODO: output error msg */
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_Unlock_EventThread();
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_free(cursor);
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallWMcursor *ph_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    WMcursor* cursor;
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int clen, i;
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned char bit, databit, maskbit;
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Allocate and initialize the cursor memory */
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if ((cursor = (WMcursor*)SDL_malloc(sizeof(WMcursor))) == NULL)
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_OutOfMemory();
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return(NULL);
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_memset(cursor,0,sizeof(WMcursor));
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor = (PhCursorDef_t *) SDL_malloc(sizeof(PhCursorDef_t) + 32*4*2);
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (cursor->ph_cursor == NULL)
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_SetError("ph_CreateWMCursor(): cursor malloc failed !\n");
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return NULL;
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->size1.x = (short)w;
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->size1.y = (short)h;
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->offset1.x = (short)hot_x;
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->offset1.y = (short)hot_y;
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->bytesperline1 = (char)w/8;
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->color1 = Pg_WHITE;
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->size2.x = (short)w;
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->size2.y = (short)h;
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->offset2.x = (short)hot_x;
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->offset2.y = (short)hot_y;
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->bytesperline2 = (char)w/8;
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->color2 = Pg_BLACK;
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    clen = (w/8)*h;
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Copy the mask and the data to different bitmap planes */
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (i=0; i<clen; ++i)
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        for (bit = 0; bit < 8; bit++)
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        {
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            databit = data[i] & (1 << bit);
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            maskbit = mask[i] & (1 << bit);
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            cursor->ph_cursor->images[i] |= (databit == 0) ? maskbit : 0;
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            /* If the databit != 0, treat it as a black pixel and
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             * ignore the maskbit (can't do an inverted color) */
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            cursor->ph_cursor->images[i+clen] |= databit;
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* #bytes following the hdr struct */
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t);
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return (cursor);
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallPhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return (*cursor->ph_cursor);
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint ph_ShowWMCursor(_THIS, WMcursor* cursor)
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    PtArg_t args[3];
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int nargs = 0;
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Don't do anything if the display is gone */
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (window == NULL)
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return (0);
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* looks like photon can't draw mouse cursor in direct mode */
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         /* disable the fake mouse in the fullscreen OpenGL mode */
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         if ((this->screen->flags & SDL_OPENGL) == SDL_OPENGL)
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         {
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             cursor=NULL;
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         }
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         else
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         {
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             return (0);
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         }
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Set the photon cursor, or blank if cursor is NULL */
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (cursor!=NULL)
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* Could set next to any PgColor_t value */
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        PtSetArg(&args[1], Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR , 0);
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        PtSetArg(&args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)));
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        nargs = 3;
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else /* Ph_CURSOR_NONE */
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        nargs = 1;
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_Lock_EventThread();
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (PtSetResources(window, nargs, args) < 0 )
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return (0);
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_Unlock_EventThread();
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return (1);
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    short abs_x, abs_y;
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_Lock_EventThread();
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    PtGetAbsPosition( window, &abs_x, &abs_y );
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_Unlock_EventThread();
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ph_CheckMouseMode(_THIS)
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* If the mouse is hidden and input is grabbed, we use relative mode */
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF))
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mouse_relative = 1;
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mouse_relative = 0;
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid ph_UpdateMouse(_THIS)
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    PhCursorInfo_t phcursor;
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    short abs_x;
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    short abs_y;
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Lock the event thread, in multi-threading environments */
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_Lock_EventThread();
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    PtGetAbsPosition(window, &abs_x, &abs_y);
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    PhQueryCursor(PhInputGroup(NULL), &phcursor);
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (((phcursor.pos.x >= abs_x) && (phcursor.pos.x <= abs_x + this->screen->w)) &&
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ((phcursor.pos.y >= abs_y) && (phcursor.pos.y <= abs_y + this->screen->h)))
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateMouseMotion(0, 0, phcursor.pos.x-abs_x, phcursor.pos.y-abs_y);
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Unlock the event thread, in multi-threading environments */
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_Unlock_EventThread();
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
221