Commit c0d64563 authored by Sam Lantinga's avatar Sam Lantinga

*** empty log message ***

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40221
parent 46f0e7c9
...@@ -159,6 +159,41 @@ static inline int X11_WarpedMotion(_THIS, XEvent *xevent) ...@@ -159,6 +159,41 @@ static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
} }
*/ */
/* Control which motion flags the window has set, a flags value of -1 sets
* MOTION_BUTTON and MOTION_NOBUTTON */
static void set_motion_sensitivity(_THIS, unsigned int flags)
{
int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
PhRegion_t region;
if( window )
{
rid = PtWidgetRid( window );
if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
{
region.events_sense = ( region.events_sense & ~fields ) |
( flags & fields );
PhRegionChange( Ph_REGION_EV_SENSE, 0, &region,
NULL, NULL );
}
}
}
/* Convert the photon button state value to an SDL value */
static Uint8 ph2sdl_mousebutton( unsigned short button_state )
{
Uint8 mouse_button = 0;
if( button_state & Ph_BUTTON_SELECT )
mouse_button |= SDL_BUTTON_LEFT;
if( button_state & Ph_BUTTON_MENU )
mouse_button |= SDL_BUTTON_RIGHT;
if( button_state & Ph_BUTTON_ADJUST )
mouse_button |= SDL_BUTTON_MIDDLE;
return( mouse_button );
}
static int ph_DispatchEvent(_THIS) static int ph_DispatchEvent(_THIS)
{ {
int posted; int posted;
...@@ -166,7 +201,7 @@ static int ph_DispatchEvent(_THIS) ...@@ -166,7 +201,7 @@ static int ph_DispatchEvent(_THIS)
PhPointerEvent_t* pointerEvent; PhPointerEvent_t* pointerEvent;
PhKeyEvent_t* keyEvent; PhKeyEvent_t* keyEvent;
PhWindowEvent_t* winEvent; PhWindowEvent_t* winEvent;
int i; int i, buttons;
SDL_Rect sdlrects[50]; SDL_Rect sdlrects[50];
posted = 0; posted = 0;
...@@ -174,7 +209,6 @@ static int ph_DispatchEvent(_THIS) ...@@ -174,7 +209,6 @@ static int ph_DispatchEvent(_THIS)
switch (event->type) { switch (event->type) {
case Ph_EV_BOUNDARY: case Ph_EV_BOUNDARY:
{ {
if (event->subtype == Ph_EV_PTR_ENTER) if (event->subtype == Ph_EV_PTR_ENTER)
posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
else if (event->subtype ==Ph_EV_PTR_LEAVE) else if (event->subtype ==Ph_EV_PTR_LEAVE)
...@@ -185,46 +219,61 @@ static int ph_DispatchEvent(_THIS) ...@@ -185,46 +219,61 @@ static int ph_DispatchEvent(_THIS)
case Ph_EV_PTR_MOTION_BUTTON: case Ph_EV_PTR_MOTION_BUTTON:
case Ph_EV_PTR_MOTION_NOBUTTON: case Ph_EV_PTR_MOTION_NOBUTTON:
{ {
if ( SDL_VideoSurface ) { if ( SDL_VideoSurface ) {
pointerEvent = PhGetData( event ); pointerEvent = PhGetData( event );
rect = PhGetRects( event ); rect = PhGetRects( event );
posted = SDL_PrivateMouseMotion(0, 1, posted = SDL_PrivateMouseMotion(0, 0,
pointerEvent->pos.x - rect[0].ul.x, rect->ul.x, rect->ul.y);
pointerEvent->pos.y - rect[0].ul.y);
} }
} }
break; break;
case Ph_EV_BUT_PRESS: case Ph_EV_BUT_PRESS:
{ {
pointerEvent = PhGetData( event ); pointerEvent = PhGetData( event );
/* TODO: is 'buttons' the right mapping? */ buttons = ph2sdl_mousebutton( pointerEvent->buttons );
posted = SDL_PrivateMouseButton(SDL_PRESSED, if( buttons != 0 )
pointerEvent->buttons, 0, 0); posted = SDL_PrivateMouseButton( SDL_PRESSED, buttons,
0, 0 );
} }
break; break;
case Ph_EV_BUT_RELEASE: case Ph_EV_BUT_RELEASE:
{ {
pointerEvent = PhGetData(event);
pointerEvent = PhGetData( event ); buttons = ph2sdl_mousebutton(pointerEvent->buttons);
posted = SDL_PrivateMouseButton(SDL_RELEASED, if( event->subtype == Ph_EV_RELEASE_REAL &&
pointerEvent->buttons, 0, 0); buttons != 0 )
{
posted = SDL_PrivateMouseButton( SDL_RELEASED,
buttons, 0, 0 );
}
else if( event->subtype == Ph_EV_RELEASE_PHANTOM )
{
/* If the mouse is outside the window,
* only a phantom release event is sent, so
* check if the window doesn't have mouse focus.
* Not perfect, maybe checking the mouse button
* state for Ph_EV_BOUNDARY events would be
* better. */
if( ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) == 0 )
{
posted = SDL_PrivateMouseButton( SDL_RELEASED,
buttons, 0, 0 );
}
}
} }
break; break;
case Ph_EV_WM: case Ph_EV_WM:
{ {
winEvent = PhGetData( event ); winEvent = PhGetData( event );
/* losing focus */ /* losing focus */
if ((winEvent->event_f==Ph_WM_FOCUS)&& if ((winEvent->event_f==Ph_WM_FOCUS)&&
(winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
{ {
set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
/* Queue leaving fullscreen mode */ /* Queue leaving fullscreen mode */
...@@ -236,6 +285,7 @@ static int ph_DispatchEvent(_THIS) ...@@ -236,6 +285,7 @@ static int ph_DispatchEvent(_THIS)
else if ((winEvent->event_f==Ph_WM_FOCUS)&& else if ((winEvent->event_f==Ph_WM_FOCUS)&&
(winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
{ {
set_motion_sensitivity(this, -1);
posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
/* Queue entry into fullscreen mode */ /* Queue entry into fullscreen mode */
...@@ -254,11 +304,8 @@ static int ph_DispatchEvent(_THIS) ...@@ -254,11 +304,8 @@ static int ph_DispatchEvent(_THIS)
/* window has been resized, moved or removed */ /* window has been resized, moved or removed */
case Ph_EV_EXPOSE: case Ph_EV_EXPOSE:
{ {
if (SDL_VideoSurface) if (SDL_VideoSurface)
{ {
rect = PhGetRects( event ); rect = PhGetRects( event );
//PgSetClipping(1, rect ); //PgSetClipping(1, rect );
...@@ -266,9 +313,8 @@ static int ph_DispatchEvent(_THIS) ...@@ -266,9 +313,8 @@ static int ph_DispatchEvent(_THIS)
{ {
sdlrects[i].x = rect[i].ul.x; sdlrects[i].x = rect[i].ul.x;
sdlrects[i].y = rect[i].ul.y; sdlrects[i].y = rect[i].ul.y;
sdlrects[i].w = rect[i].lr.x - rect[i].ul.x; sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
sdlrects[i].h = rect[i].lr.y - rect[i].ul.y; sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
} }
this->UpdateRects(this, event->num_rects, sdlrects); this->UpdateRects(this, event->num_rects, sdlrects);
...@@ -313,9 +359,7 @@ static int ph_DispatchEvent(_THIS) ...@@ -313,9 +359,7 @@ static int ph_DispatchEvent(_THIS)
/* perform a blocking read if no events available */ /* perform a blocking read if no events available */
int ph_Pending(_THIS) int ph_Pending(_THIS)
{ {
/* Flush the display connection and look to see if events are queued */ /* Flush the display connection and look to see if events are queued */
PgFlush(); PgFlush();
while( 1 ) while( 1 )
...@@ -554,12 +598,12 @@ SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym) ...@@ -554,12 +598,12 @@ SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap);
break; break;
} }
keysym->scancode = key->key_scan;
return (keysym); return (keysym);
} }
void ph_InitOSKeymap(_THIS) void ph_InitOSKeymap(_THIS)
{ {
ph_InitKeymap(); ph_InitKeymap();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment