Example #1
0
// The event loop itself.
void GfEventLoop::operator()()
{
	SDL_Event event; // Event structure
	
	// Check for events.
	while (!_pPrivate->bQuit)
	{  	
		// Loop until there are no events left in the queue.
		while (!_pPrivate->bQuit && SDL_PollEvent(&event))
		{
		    // Process events we care about, and ignore the others.
			switch(event.type)
			{  
				case SDL_KEYDOWN:
					injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,
#if SDL_MAJOR_VERSION < 2
										event.key.keysym.unicode);
#else
										0);
#endif
					break;
				
				case SDL_KEYUP:
					injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,
#if SDL_MAJOR_VERSION < 2
										event.key.keysym.unicode);
#else
										0);
#endif
					break;

				case SDL_QUIT:
					postQuit();
					break;

				default:
					break;
			}
		}

		if (!_pPrivate->bQuit)
		{
			// Recompute if anything to.
			recompute();
		}
	}

	GfLogTrace("Quitting event loop.\n");
}
void QQnxScreenEventHandler::handleKeyboardEvent(screen_event_t event)
{
    // get flags of key event
    errno = 0;
    int flags;
    int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
    if (result) {
        qFatal("QQNX: failed to query event flags, errno=%d", errno);
    }

    // get key code
    errno = 0;
    int sym;
    result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym);
    if (result) {
        qFatal("QQNX: failed to query event sym, errno=%d", errno);
    }

    int modifiers;
    result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &modifiers);
    if (result) {
        qFatal("QQNX: failed to query event modifiers, errno=%d", errno);
    }

    int scan;
    result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SCAN, &scan);
    if (result) {
        qFatal("QQNX: failed to query event modifiers, errno=%d", errno);
    }

    int cap;
    result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap);
    if (result) {
        qFatal("QQNX: failed to query event cap, errno=%d", errno);
    }

    injectKeyboardEvent(flags, sym, modifiers, scan, cap);
}
Example #3
0
// The event loop itself.
void GfuiEventLoop::operator()()
{
	SDL_Event event; // Event structure
#if SDL_MAJOR_VERSION >= 2
	static int unicode = 0;
   static SDL_Keymod modifier = KMOD_NONE;
#endif

	// Check for events.
	while (!quitRequested())
	{
		// Loop until there are no events left in the queue.
		while (!quitRequested() && SDL_PollEvent(&event))
		{
		    // Process events we care about, and ignore the others.
			switch(event.type)
			{
				case SDL_KEYDOWN:
#if SDL_MAJOR_VERSION < 2
					   injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,event.key.keysym.unicode);
#else
					if((event.key.keysym.sym & SDLK_SCANCODE_MASK) == SDLK_SCANCODE_MASK)
					{
						injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,0);
					}
					else if(false == isprint(event.key.keysym.sym))
					{
						injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,0);
					}
					else if((event.key.keysym.mod != KMOD_NONE)
							&&(event.key.keysym.mod != KMOD_LSHIFT)
							&&(event.key.keysym.mod != KMOD_RSHIFT))
					{
						injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,0);
					}
#if 0
					else
					{
						printf("SDL_KEYDOWN: %c\r\n",(char)event.key.keysym.sym);
					}
#endif
#endif
					break;

#if SDL_MAJOR_VERSION >= 2
				case SDL_TEXTINPUT:
					unicode = (int)(event.text.text[0]);
					modifier = SDL_GetModState();
					injectKeyboardEvent(unicode,modifier, 0,0);
					//printf("SDL_TEXTINPUT: %c %X\r\n",(char)unicode,modifier);
					break;
#endif

				case SDL_KEYUP:
#if SDL_MAJOR_VERSION < 2
					injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,event.key.keysym.unicode);
#else
					if((event.key.keysym.sym & SDLK_SCANCODE_MASK) == SDLK_SCANCODE_MASK)
					{
						injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
					}
					else if(false == isprint(event.key.keysym.sym))
					{
						injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
					}
					else if((event.key.keysym.mod != KMOD_NONE)
							&&(event.key.keysym.mod != KMOD_LSHIFT)
							&&(event.key.keysym.mod != KMOD_RSHIFT))
					{
						injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
					}
					else
					{
						injectKeyboardEvent(unicode, event.key.keysym.mod, 1,0);
						//printf("SDL_KEYUP: %c unicode = %c\r\n",(char)event.key.keysym.sym,unicode);
					}
#endif
					break;

				case SDL_MOUSEMOTION:
					injectMouseMotionEvent(event.motion.state, event.motion.x, event.motion.y);
					break;


				case SDL_MOUSEBUTTONDOWN:
				case SDL_MOUSEBUTTONUP:
					injectMouseButtonEvent(event.button.button, event.button.state,
										   event.button.x, event.button.y);
					break;

				case SDL_QUIT:
					postQuit();
					break;

#if SDL_MAJOR_VERSION >= 2
#if SDL_JOYSTICK
				case SDL_JOYAXISMOTION:
					injectJoystickAxisEvent(event.jaxis.which, event.jaxis.axis, (float) event.jaxis.value / 32768);
					break;

				case SDL_JOYBUTTONDOWN:
					injectJoystickButtonEvent(event.jbutton.which, event.jbutton.button, SDL_PRESSED);
					break;

				case SDL_JOYBUTTONUP:
					injectJoystickButtonEvent(event.jbutton.which, event.jbutton.button, 0);
					break;
#endif
				case SDL_WINDOWEVENT_EXPOSED:
#else
				case SDL_VIDEOEXPOSE:
#endif
					forceRedisplay();
					break;
			}
		}

		if (!quitRequested())
		{
			// Recompute if anything to.
			recompute();

			// Redisplay if anything to.
			redisplay();
		}
	}

	GfLogTrace("Quitting GFUI event loop.\n");
}