Ejemplo n.º 1
0
int HandleWsEvent(_THIS, const TWsEvent& aWsEvent)
{
    switch (aWsEvent.Type())
		{    
		case EEventSwitchOff:
			SDL_PrivateQuit();
			return 0;
    	case EEventPointerBufferReady:
    	    return PointerBufferReadyEvent(_this/*, aWsEvent.Time()*/);
        case EEventPointer: /* Mouse pointer events */
            return PointerEvent(_this, aWsEvent);
        case EEventKeyDown: /* Key events */
            return KeyDownEvent(_this, aWsEvent);
        case EEventKeyUp: /* Key events */
            return KeyUpEvent(_this, aWsEvent);
        case EEventFocusGained: /* SDL window got focus */
            return FocusGainedEvent(_this);	   
        case EEventFocusLost: /* SDL window lost focus */
        	return FocusLostEvent(_this);
        case EEventModifiersChanged: 
            return ModifiersChangedEvent(aWsEvent);         
    	case EEventScreenDeviceChanged:
    	    return ScreenDeviceChanged();
    	case ESDLWsEvent:
    	    return InternalEvent(aWsEvent);
        default:            
            return 0;
		} 
    }
JNIEXPORT void JNICALL 
JAVA_EXPORT_NAME(DemoRenderer_nativeDone) ( JNIEnv*  env, jobject  thiz )
{
	__android_log_print(ANDROID_LOG_INFO, "libSDL", "quitting...");
	SDL_PrivateQuit();
	__android_log_print(ANDROID_LOG_INFO, "libSDL", "quit OK");
}
Ejemplo n.º 3
0
static void SDL_HandleSIG(int sig)
{
	/* Reset the signal handler */
	signal(sig, SDL_HandleSIG);

	/* Signal a quit interrupt */
	SDL_PrivateQuit();
}
Ejemplo n.º 4
0
void
PLAYBOOK_PumpEvents(_THIS)
{
	while (1)
	{
		int rc = screen_get_event(this->hidden->screenContext, this->hidden->screenEvent, 0 /*timeout*/);
		if (rc)
			break;

		int type;
		rc = screen_get_event_property_iv(this->hidden->screenEvent, SCREEN_PROPERTY_TYPE, &type);
		if (rc || type == SCREEN_EVENT_NONE)
			break;

		screen_window_t window;
		screen_get_event_property_pv(this->hidden->screenEvent, SCREEN_PROPERTY_WINDOW, (void **)&window);
		if (!window && type != SCREEN_EVENT_KEYBOARD)
			break;

		switch (type)
		{
		case SCREEN_EVENT_CLOSE:
			SDL_PrivateQuit(); // We can't stop it from closing anyway
			break;
		case SCREEN_EVENT_PROPERTY:
			{
				int val;
				screen_get_event_property_iv(this->hidden->screenEvent, SCREEN_PROPERTY_NAME, &val);

				//fprintf(stderr, "Property change (property val=%d)\n", val);
			}
			break;
		case SCREEN_EVENT_POINTER:
			handlePointerEvent(this->hidden->screenEvent, window);
			break;
		case SCREEN_EVENT_KEYBOARD:
			handleKeyboardEvent(this->hidden->screenEvent);
			break;
		case SCREEN_EVENT_MTOUCH_TOUCH:
		case SCREEN_EVENT_MTOUCH_MOVE:
		case SCREEN_EVENT_MTOUCH_RELEASE:
			handleMtouchEvent(this->hidden->screenEvent, window, type);
			break;
		}
	}

#ifdef TOUCHPAD_SIMULATE
	if (state.pending[0] || state.pending[1]) {
		SDL_PrivateMouseMotion(state.mask, 1, state.pending[0], state.pending[1]);
		state.pending[0] = 0;
		state.pending[1] = 0;
	}
#endif
	if (moveEvent.pending) {
		SDL_PrivateMouseMotion((moveEvent.touching?SDL_BUTTON_LEFT:0), 0, moveEvent.pos[0], moveEvent.pos[1]);
		moveEvent.pending = 0;
	}
}
Ejemplo n.º 5
0
/* Call to finalize the graphics state */
extern void JAVA_EXPORT_NAME(DemoRenderer_nativeDone)(JNIEnv* env, jobject thiz) {
	if (mainThread) {
		__android_log_print(ANDROID_LOG_INFO, "libSDL", "quitting...");
		SDL_PrivateQuit();
		SDL_WaitThread(mainThread, NULL);
		mainThread = NULL;
		__android_log_print(ANDROID_LOG_INFO, "libSDL", "quit OK");
	}
}
Ejemplo n.º 6
0
JNIEXPORT void JNICALL 
JAVA_EXPORT_NAME(DemoRenderer_nativeDone) ( JNIEnv*  env, jobject  thiz )
{
	__android_log_print(ANDROID_LOG_INFO, "libSDL", "quitting...");
#if SDL_VERSION_ATLEAST(1,3,0)
	SDL_SendQuit();
#else
	SDL_PrivateQuit();
#endif
	__android_log_print(ANDROID_LOG_INFO, "libSDL", "quit OK");
}
Ejemplo n.º 7
0
static int do_messages(_THIS, short *message)
{
	int quit, posted;

	quit=0;
	switch (message[0]) {
		case WM_CLOSED:
		case AP_TERM:    
			posted = SDL_PrivateQuit();
			quit=1;
			break;
		case WM_MOVED:
			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
			break;
		case WM_TOPPED:
			wind_set(message[3],WF_TOP,message[4],0,0,0);
			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
			break;
		case WM_REDRAW:
			GEM_wind_redraw(this, message[3],&message[4]);
			break;
		case WM_ICONIFY:
		case WM_ALLICONIFY:
			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
			/* If we're active, make ourselves inactive */
			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
				/* Send an internal deactivate event */
				SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
			}
			/* Update window title */
			if (GEM_refresh_name && GEM_icon_name) {
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
				GEM_refresh_name = SDL_FALSE;
			}
			break;
		case WM_UNICONIFY:
			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
			/* If we're not active, make ourselves active */
			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
				/* Send an internal activate event */
				SDL_PrivateAppActive(1, SDL_APPACTIVE);
			}
			if (GEM_refresh_name && GEM_title_name) {
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
				GEM_refresh_name = SDL_FALSE;
			}
Ejemplo n.º 8
0
void NX_PumpEvents (_THIS)
{
    GR_EVENT         event ;
    static GR_BUTTON last_button_down = 0 ;

    GrCheckNextEvent (& event) ;
    while (event.type != GR_EVENT_TYPE_NONE) {

        // dispatch event
        switch (event.type) {
            case GR_EVENT_TYPE_MOUSE_ENTER :
            {
                Dprintf ("mouse enter\n") ;
                SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ;
                break ;
            }

            case GR_EVENT_TYPE_MOUSE_EXIT :
            {
                Dprintf ("mouse exit\n") ;
                SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ;
                break ;
            }

            case GR_EVENT_TYPE_FOCUS_IN :
            {
                Dprintf ("focus in\n") ;
                SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS) ;
                break ;
            }

            case GR_EVENT_TYPE_FOCUS_OUT :
            {
                Dprintf ("focus out\n") ;
                SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS) ;
                break ;
            }

            case GR_EVENT_TYPE_MOUSE_MOTION :
            {               
                Dprintf ("mouse motion\n") ;

                if (SDL_VideoSurface) {
                    if (currently_fullscreen) {
                        if (check_boundary (this, event.button.x, event.button.y)) {
                            SDL_PrivateMouseMotion (0, 0, event.button.x - OffsetX, 
                                event.button.y - OffsetY) ;
                        }
                    } else {
                        SDL_PrivateMouseMotion (0, 0, event.button.x, event.button.y) ;
                    }
                }
                break ;
            }

            case GR_EVENT_TYPE_BUTTON_DOWN :
            {
                int button = event.button.buttons ;
                
                Dprintf ("button down\n") ;

                switch (button) {
                    case MWBUTTON_L :
                        button = 1 ;
                        break ;
                    case MWBUTTON_M :
                        button = 2 ;
                        break ;
                    case MWBUTTON_R :
                        button = 3 ;
                        break ;
                    default :
                        button = 0 ;
                }
                last_button_down = button ;
                
                if (currently_fullscreen) {
                    if (check_boundary (this, event.button.x, event.button.y)) {
                        SDL_PrivateMouseButton (SDL_PRESSED, button, 
                            event.button.x - OffsetX, event.button.y - OffsetY) ;
                    }
                } else {
                    SDL_PrivateMouseButton (SDL_PRESSED, button, 
                        event.button.x, event.button.y) ;
                }
                break ;
            }

            // do not konw which button is released
            case GR_EVENT_TYPE_BUTTON_UP :
            {   
                Dprintf ("button up\n") ;

                if (currently_fullscreen) {
                    if (check_boundary (this, event.button.x, event.button.y)) {
                        SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, 
                            event.button.x - OffsetX, event.button.y - OffsetY) ;
                    }
                } else {
                    SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, 
                        event.button.x, event.button.y) ;
                }
                last_button_down = 0 ;
                break ;
            }

            case GR_EVENT_TYPE_KEY_DOWN :
            {
                SDL_keysym keysym ;

                Dprintf ("key down\n") ;
                SDL_PrivateKeyboard (SDL_PRESSED,
                    NX_TranslateKey (& event.keystroke, & keysym)) ;
                break ;
            }

            case GR_EVENT_TYPE_KEY_UP :
            {
                SDL_keysym keysym ;

                Dprintf ("key up\n") ;
                SDL_PrivateKeyboard (SDL_RELEASED,
                    NX_TranslateKey (& event.keystroke, & keysym)) ;
                break ;
            }

            case GR_EVENT_TYPE_CLOSE_REQ :
            {
                Dprintf ("close require\n") ;
                SDL_PrivateQuit () ;
                break ;
            }

            case GR_EVENT_TYPE_EXPOSURE :
            {
                Dprintf ("event_type_exposure\n") ;
                if (SDL_VideoSurface) {
                    NX_RefreshDisplay (this) ;//, & event.exposure) ;
                }
                break ;
            }

            case GR_EVENT_TYPE_UPDATE :
            {
                switch (event.update.utype) {
                    case GR_UPDATE_MAP :
                    {
                        Dprintf ("GR_UPDATE_MAP\n") ;
                        // If we're not active, make ourselves active
                        if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
                            // Send an internal activate event
                            SDL_PrivateAppActive (1, SDL_APPACTIVE) ;
                        }
                        if (SDL_VideoSurface) {
                            NX_RefreshDisplay (this) ;
                        }
                        break ;
                    }
                    
                    case GR_UPDATE_UNMAP :
                    case GR_UPDATE_UNMAPTEMP :
                    {
                        Dprintf ("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n") ;
                        // If we're active, make ourselves inactive
                        if (SDL_GetAppState () & SDL_APPACTIVE) {
                            // Send an internal deactivate event
                            SDL_PrivateAppActive (0, SDL_APPACTIVE | SDL_APPINPUTFOCUS) ;
                        }
                        break ; 
                    }
                    
                    case GR_UPDATE_SIZE :
                    {
                        Dprintf ("GR_UPDATE_SIZE\n") ;
                        SDL_PrivateResize (event.update.width, event.update.height) ;
                        break ; 
                    }

                    case GR_UPDATE_MOVE :
		    case GR_UPDATE_REPARENT :
                    {
                        Dprintf ("GR_UPDATE_MOVE or GR_UPDATE_REPARENT\n") ;
#ifdef ENABLE_NANOX_DIRECT_FB
			if (Clientfb) {
			    /* Get current window position and fb pointer*/
			    if (currently_fullscreen) 
				GrGetWindowFBInfo(FSwindow, &fbinfo);
			    else
				GrGetWindowFBInfo(SDL_Window, &fbinfo);
			}
#endif
                        break ; 
                    }
                    
                    default :
                        Dprintf ("unknown GR_EVENT_TYPE_UPDATE\n") ;
                        break ; 
                }
                break ; 
            }
                
            default :
            {
                Dprintf ("pump event default\n") ;
            }
        }

        GrCheckNextEvent (& event) ;
    }
}
Ejemplo n.º 9
0
int PG_HandleClose(struct pgEvent *evt)
{
        SDL_PrivateQuit();
	return 1;               /* Intercept the event's normal quit handling */
}
Ejemplo n.º 10
0
static int ph_DispatchEvent(_THIS)
{
    int posted;
    PhRect_t* rect;
    PhPointerEvent_t* pointerEvent;
    PhKeyEvent_t* keyEvent;
    PhWindowEvent_t* winEvent;
    int i, buttons;
    SDL_Rect sdlrects[50]; 
	
    posted = 0;
	
    switch (event->type)
    {
        case Ph_EV_BOUNDARY:
        {
            if (event->subtype == Ph_EV_PTR_ENTER)
            {
                posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
            }
            else if (event->subtype ==Ph_EV_PTR_LEAVE)
            {
                posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
            }
        }
        break;

        case Ph_EV_PTR_MOTION_BUTTON:
        case Ph_EV_PTR_MOTION_NOBUTTON:
        {
            if (SDL_VideoSurface)
            {
                pointerEvent = PhGetData(event);
                rect = PhGetRects(event);

                if (mouse_relative)
                {
                    posted = ph_WarpedMotion(this, event);
                }
                else
                {
                    posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);
                }
            }
        }
        break;

        case Ph_EV_BUT_PRESS:
        {
            pointerEvent = PhGetData( event );
            buttons = ph2sdl_mousebutton( pointerEvent->buttons );
            if (buttons != 0)
            {
                posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);
            }
        }
        break;

        case Ph_EV_BUT_RELEASE:
        {
            pointerEvent = PhGetData(event);
            buttons = ph2sdl_mousebutton(pointerEvent->buttons);
            if (event->subtype == Ph_EV_RELEASE_REAL && 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;

        case Ph_EV_WM:
        {
            winEvent = PhGetData(event);

            /* losing focus */
            if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
            {
                set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
                posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
            }
            /* gaining focus */
            else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
            {
                set_motion_sensitivity(this, -1);
                posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
            }
            /* request to quit */
            else if (winEvent->event_f==Ph_WM_CLOSE)
            {
                posted = SDL_PrivateQuit();
            }
            /* request to hide/unhide */
            else if (winEvent->event_f==Ph_WM_HIDE)
            {
                if (currently_hided)
                {
                   /* got unhide window event                                */
                   /* TODO: restore application's palette if in palette mode */
                   currently_hided=0;
                }
                else
                {
                   /* got hide window event                                  */
                   /* TODO: restore original palette if in palette mode      */
                   currently_hided=1;
                }
            }
            /* request to resize */
            else if (winEvent->event_f==Ph_WM_RESIZE)
            {
                SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
            }
            /* request to move */
            else if (winEvent->event_f==Ph_WM_MOVE)
            {
                if (current_overlay!=NULL)
                {
                   int lockedstate=current_overlay->hwdata->locked;
                   int chromastate=current_overlay->hwdata->ischromakey;
                   SDL_Rect target;

                   current_overlay->hwdata->locked=1;
                   target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
                   target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
                   target.w=current_overlay->hwdata->CurrentViewPort.size.w;
                   target.h=current_overlay->hwdata->CurrentViewPort.size.h;
                   current_overlay->hwdata->ischromakey=0;
                   ph_DisplayYUVOverlay(this, current_overlay, &target);
                   current_overlay->hwdata->ischromakey=chromastate;
                   current_overlay->hwdata->locked=lockedstate;
                }
            }
            /* request to maximize */
            else if (winEvent->event_f==Ph_WM_MAX)
            {
                /* window already moved and resized here */
                SDL_PrivateResize(winEvent->size.w-winEvent->pos.x, winEvent->size.h-winEvent->pos.y);
            }
            /* request to restore */
            else if (winEvent->event_f==Ph_WM_RESTORE)
            {
            }
        }
        break;

        /* window has been resized, moved or removed */
        case Ph_EV_EXPOSE:
        {
            if (event->num_rects!=0)
            {
                if (SDL_VideoSurface)
                {
                    rect = PhGetRects(event);

                    for(i=0;i<event->num_rects;i++)
                    {
                        sdlrects[i].x = rect[i].ul.x;
                        sdlrects[i].y = rect[i].ul.y;
                        sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
                        sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
                    }

                    this->UpdateRects(this, event->num_rects, sdlrects);

                    if (current_overlay!=NULL)
                    {
                        int lockedstate=current_overlay->hwdata->locked;
                        SDL_Rect target;

                        current_overlay->hwdata->locked=1;
                        target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
                        target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
                        target.w=current_overlay->hwdata->CurrentViewPort.size.w;
                        target.h=current_overlay->hwdata->CurrentViewPort.size.h;
                        current_overlay->hwdata->forcedredraw=1;
                        ph_DisplayYUVOverlay(this, current_overlay, &target);
                        current_overlay->hwdata->forcedredraw=0;
                        current_overlay->hwdata->locked=lockedstate;
                    }
                }
            }
        }
	break;

        case Ph_EV_KEY:
        {
            SDL_keysym keysym;

            posted = 0;

            keyEvent = PhGetData( event );

            if (Pk_KF_Key_Down & keyEvent->key_flags)
            {
                /* split the wheel events from real key events */
                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
                {
                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
                   break;
                }
                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
                {
                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
                   break;
                }
                posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
            }
            else /* must be key release */
            {
                /* split the wheel events from real key events */
                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
                {
                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
                   break;
                }
                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
                {
                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
                   break;
                }
                posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
            }
        }
        break;
    }

    return(posted);
}
Ejemplo n.º 11
0
void WIMP_Poll(_THIS, int waitTime)
{
	_kernel_swi_regs regs;
	int message[64];
	unsigned int code;
	int pollMask = 0;
	int doPoll = 1;
	int sysEvent;
	int sdlWindow = this->hidden->window_handle;

    if (this->PumpEvents != WIMP_PumpEvents) return;

    if (waitTime > 0)
    {
		_kernel_swi(OS_ReadMonotonicTime, &regs, &regs);
		waitTime += regs.r[0];
    }

    while (doPoll)
    {
        if (waitTime <= 0)
        {
        	regs.r[0] = pollMask; /* Poll Mask */
        	 /* For no wait time mask out null event so we wait until something happens */
        	if (waitTime < 0) regs.r[0] |= 1;
        	regs.r[1] = (int)message;
        	_kernel_swi(Wimp_Poll, &regs, &regs);
        } else
        {
        	regs.r[0] = pollMask;
        	regs.r[1] = (int)message;
        	regs.r[2] = waitTime;
        	_kernel_swi(Wimp_PollIdle, &regs, &regs);
        }

		/* Flag to specify if we post a SDL_SysWMEvent */
		sysEvent = 0;
        
        code = (unsigned int)regs.r[0];

		switch(code)
		{
		case 0:  /* Null Event - drop out for standard processing*/
		   doPoll = 0;
		   break;

		case 1:     /* Redraw window */
        	_kernel_swi(Wimp_RedrawWindow, &regs,&regs);
			if (message[0] == sdlWindow)
			{
        		while (regs.r[0])
        		{
        			WIMP_PlotSprite(this, message[1], message[2]);
        			_kernel_swi(Wimp_GetRectangle, &regs, &regs);
        		}
			} else
			{
				/* TODO: Currently we just eat them - we may need to pass them on */
        		while (regs.r[0])
        		{
        			_kernel_swi(Wimp_GetRectangle, &regs, &regs);
        		}
			}
        	break;
        	
		case 2:		/* Open window */
		   if ( resizeOnOpen && message[0] == sdlWindow)
		   {
		      /* Ensure window is correct size */
		      resizeOnOpen = 0;
		      message[3] = message[1] + (this->screen->w << this->hidden->xeig);
		      message[4] = message[2] + (this->screen->h << this->hidden->yeig);       
		   }
        	_kernel_swi(Wimp_OpenWindow, &regs, &regs);
       	    break;
        	
		case 3:		/* Close window */
			if (message[0] == sdlWindow)
			{
				/* Documentation makes it looks as if the following line is correct:
				**    if (SDL_PrivateQuit() == 1) _kernel_swi(Wimp_CloseWindow, &regs, &regs);
				** However some programs don't process this message and so sit there invisibly
				** in the background so I just post the quit message and hope the application
				** does the correct thing.
				*/
				SDL_PrivateQuit();
			} else
				sysEvent = 1;
        	doPoll = 0;
        	break;

		case 4: /* Pointer_Leaving_Window */
			if (message[0] == sdlWindow)
			{
				mouseInWindow = 0;
				//TODO: Lose buttons / dragging
				 /* Reset to default pointer */
   				 regs.r[0] = 106;
				 regs.r[1] = 1;
				 regs.r[2] = 0;
				 _kernel_swi(OS_Byte, &regs, &regs);
				 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
			} else
				sysEvent = 1;
			break;

		case 5: /* Pointer_Entering_Window */
			if (message[0] == sdlWindow) 
			{
				mouseInWindow = 1;
				WIMP_ReshowCursor(this);
				SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
			} else sysEvent = 1;
			break;

		case 6:		/* Mouse_Click */
			if (hasFocus == 0)
			{
			   /* First click gives focus if it's not a menu */
			   /* we only count non-menu clicks on a window that has the focus */
			   WIMP_SetFocus(message[3]);
			} else
				doPoll = 0; // So PollMouse gets a chance to pick it up
		   break;

		case 7: /* User_Drag_Box - Used for mouse release */
			//TODO: May need to implement this in the future
			sysEvent = 1;
			break;

		case 8: /* Keypressed */
			doPoll = 0; /* PollKeyboard should pick it up */
			if (message[0] != sdlWindow) sysEvent = 1;
			/*TODO: May want to always pass F12 etc to the wimp
			{
				regs.r[0] = message[6];
				_kernel_swi(Wimp_ProcessKey, &regs, &regs);
			}
			*/
			break;

		case 11: /* Lose Caret */
			 hasFocus = 0;
			 if (message[0] == sdlWindow) SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
			 else sysEvent = 1;
			 break;

		case 12: /* Gain Caret */
			 hasFocus = 1;
			 if (message[0] == sdlWindow) SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
			 else sysEvent = 1;
			 break;
        	
		case 17:
		case 18:
			sysEvent = 1; /* All messages are passed on */

			switch(message[4])
			{
			case 0: /* Quit Event */
				/* No choice - have to quit */
			   SDL_Quit();
        	   exit(0);
			   break;

			case 8: /* Pre Quit */
				SDL_PrivateQuit();
				break;

			case 0x400c1: /* Mode change */
				WIMP_ModeChanged(this);
				resizeOnOpen = 1;
				break;

			case 9:      /* Palette changed */
				WIMP_PaletteChanged(this);
				break;
			}
			break;

		default:
			/* Pass unknown events on */
			sysEvent = 1;
			break;
		}

		if (sysEvent)
		{
	        SDL_SysWMmsg wmmsg;

			SDL_VERSION(&wmmsg.version);
			wmmsg.eventCode = code;
			memcpy(wmmsg.pollBlock, message, 64 * sizeof(int));

			/* Fall out of polling loop if message is successfully posted */
			if (SDL_PrivateSysWMEvent(&wmmsg)) doPoll = 0;
		}

    }
}
Ejemplo n.º 12
0
static int X11_DispatchEvent(_THIS)
{
	int posted;
	XEvent xevent;

	XNextEvent(SDL_Display, &xevent);

	posted = 0;
	switch (xevent.type) {

	    /* Gaining mouse coverage? */
	    case EnterNotify: {
#ifdef DEBUG_XEVENTS
printf("EnterNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y);
if ( xevent.xcrossing.mode == NotifyGrab )
printf("Mode: NotifyGrab\n");
if ( xevent.xcrossing.mode == NotifyUngrab )
printf("Mode: NotifyUngrab\n");
#endif
		if ( (xevent.xcrossing.mode != NotifyGrab) &&
		     (xevent.xcrossing.mode != NotifyUngrab) ) {
			if ( this->input_grab == SDL_GRAB_OFF ) {
				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
			} else {
				posted = SDL_PrivateMouseMotion(0, 0,
						xevent.xcrossing.x,
						xevent.xcrossing.y);
			}
		}
	    }
	    break;

	    /* Losing mouse coverage? */
	    case LeaveNotify: {
#ifdef DEBUG_XEVENTS
printf("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y);
if ( xevent.xcrossing.mode == NotifyGrab )
printf("Mode: NotifyGrab\n");
if ( xevent.xcrossing.mode == NotifyUngrab )
printf("Mode: NotifyUngrab\n");
#endif
		if ( (xevent.xcrossing.mode != NotifyGrab) &&
		     (xevent.xcrossing.mode != NotifyUngrab) &&
		     (xevent.xcrossing.detail != NotifyInferior) ) {
			if ( this->input_grab == SDL_GRAB_OFF ) {
				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
			} else {
				posted = SDL_PrivateMouseMotion(0, 0,
						xevent.xcrossing.x,
						xevent.xcrossing.y);
			}
		}
	    }
	    break;

	    /* Gaining input focus? */
	    case FocusIn: {
#ifdef DEBUG_XEVENTS
printf("FocusIn!\n");
#endif
		posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);

		/* Queue entry into fullscreen mode */
		switch_waiting = 0x01 | SDL_FULLSCREEN;
		switch_time = SDL_GetTicks() + 1500;
	    }
	    break;

	    /* Losing input focus? */
	    case FocusOut: {
#ifdef DEBUG_XEVENTS
printf("FocusOut!\n");
#endif
		posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);

		/* Queue leaving fullscreen mode */
		switch_waiting = 0x01;
		switch_time = SDL_GetTicks() + 200;
	    }
	    break;

	    /* Generated upon EnterWindow and FocusIn */
	    case KeymapNotify: {
#ifdef DEBUG_XEVENTS
printf("KeymapNotify!\n");
#endif
		X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
	    }
	    break;

	    /* Mouse motion? */
	    case MotionNotify: {
		if ( SDL_VideoSurface ) {
			if ( mouse_relative ) {
				if ( using_dga & DGA_MOUSE ) {
#ifdef DEBUG_MOTION
  printf("DGA motion: %d,%d\n", xevent.xmotion.x_root, xevent.xmotion.y_root);
#endif
					posted = SDL_PrivateMouseMotion(0, 1,
							xevent.xmotion.x_root,
							xevent.xmotion.y_root);
				} else {
					posted = X11_WarpedMotion(this,&xevent);
				}
			} else {
#ifdef DEBUG_MOTION
  printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
#endif
				posted = SDL_PrivateMouseMotion(0, 0,
						xevent.xmotion.x,
						xevent.xmotion.y);
			}
		}
	    }
	    break;

	    /* Mouse button press? */
	    case ButtonPress: {
		posted = SDL_PrivateMouseButton(SDL_PRESSED, 
					xevent.xbutton.button, 0, 0);
	    }
	    break;

	    /* Mouse button release? */
	    case ButtonRelease: {
		posted = SDL_PrivateMouseButton(SDL_RELEASED, 
					xevent.xbutton.button, 0, 0);
	    }
	    break;

	    /* Key press? */
	    case KeyPress: {
		SDL_keysym keysym;

#ifdef DEBUG_XEVENTS
printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
#endif
		posted = SDL_PrivateKeyboard(SDL_PRESSED,
				X11_TranslateKey(SDL_Display, &xevent.xkey,
						 xevent.xkey.keycode,
						 &keysym));
	    }
	    break;

	    /* Key release? */
	    case KeyRelease: {
		SDL_keysym keysym;

#ifdef DEBUG_XEVENTS
printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
#endif
		/* Check to see if this is a repeated key */
		if ( ! X11_KeyRepeat(SDL_Display, &xevent) ) {
			posted = SDL_PrivateKeyboard(SDL_RELEASED, 
				X11_TranslateKey(SDL_Display, &xevent.xkey,
						 xevent.xkey.keycode,
						 &keysym));
		}
	    }
	    break;

	    /* Have we been iconified? */
	    case UnmapNotify: {
#ifdef DEBUG_XEVENTS
printf("UnmapNotify!\n");
#endif
		/* If we're active, make ourselves inactive */
		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
			/* Swap out the gamma before we go inactive */
			X11_SwapVidModeGamma(this);

			/* Send an internal deactivate event */
			posted = SDL_PrivateAppActive(0,
					SDL_APPACTIVE|SDL_APPINPUTFOCUS);
		}
	    }
	    break;

	    /* Have we been restored? */
	    case MapNotify: {
#ifdef DEBUG_XEVENTS
printf("MapNotify!\n");
#endif
		/* If we're not active, make ourselves active */
		if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
			/* Send an internal activate event */
			posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);

			/* Now that we're active, swap the gamma back */
			X11_SwapVidModeGamma(this);
		}

		if ( SDL_VideoSurface &&
		     (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
			X11_EnterFullScreen(this);
		} else {
			X11_GrabInputNoLock(this, this->input_grab);
		}
		X11_CheckMouseModeNoLock(this);

		if ( SDL_VideoSurface ) {
			X11_RefreshDisplay(this);
		}
	    }
	    break;

	    /* Have we been resized or moved? */
	    case ConfigureNotify: {
#ifdef DEBUG_XEVENTS
printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);
#endif
		if ( SDL_VideoSurface ) {
		    if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
		        (xevent.xconfigure.height != SDL_VideoSurface->h)) {
			/* FIXME: Find a better fix for the bug with KDE 1.2 */
			if ( ! ((xevent.xconfigure.width == 32) &&
			        (xevent.xconfigure.height == 32)) ) {
				SDL_PrivateResize(xevent.xconfigure.width,
				                  xevent.xconfigure.height);
			}
		    } else {
			/* OpenGL windows need to know about the change */
			if ( SDL_VideoSurface->flags & (SDL_OPENGL | SDL_OPENGLES) ) {
				SDL_PrivateExpose();
			}
		    }
		}
	    }
	    break;

	    /* Have we been requested to quit (or another client message?) */
	    case ClientMessage: {
		if ( (xevent.xclient.format == 32) &&
		     (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) )
		{
			posted = SDL_PrivateQuit();
		} else
		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
			SDL_SysWMmsg wmmsg;

			SDL_VERSION(&wmmsg.version);
			wmmsg.subsystem = SDL_SYSWM_X11;
			wmmsg.event.xevent = xevent;
			posted = SDL_PrivateSysWMEvent(&wmmsg);
		}
	    }
	    break;

	    /* Do we need to refresh ourselves? */
	    case Expose: {
#ifdef DEBUG_XEVENTS
printf("Expose (count = %d)\n", xevent.xexpose.count);
#endif
		if ( SDL_VideoSurface && (xevent.xexpose.count == 0) ) {
			X11_RefreshDisplay(this);
		}
	    }
	    break;

	    default: {
#ifdef DEBUG_XEVENTS
printf("Unhandled event %d\n", xevent.type);
#endif
		/* Only post the event if we're watching for it */
		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
			SDL_SysWMmsg wmmsg;

			SDL_VERSION(&wmmsg.version);
			wmmsg.subsystem = SDL_SYSWM_X11;
			wmmsg.event.xevent = xevent;
			posted = SDL_PrivateSysWMEvent(&wmmsg);
		}
	    }
	    break;
	}
	return(posted);
}