void processDescriptor(const pollfd& pfd)
  {
    assert(pfd.fd != -1);
    assert(pfd.revents & POLLIN);

    int i = 0;

    input_event e;
    read(pfd.fd, &e, sizeof(input_event));

    switch (e.type)
    {
      case EV_KEY:
        switch (e.code)
        {
          case BTN_LEFT:
          case BTN_RIGHT:
          case BTN_MIDDLE:
          case BTN_SIDE:
          case BTN_EXTRA:
            handleMouseEvent(e, true);
            break;

          default:
            handleKeyboardEvent(e);
            break;
        }
        break;

      case EV_REL:
        switch (e.code)
        {
          case REL_X:
            i = pxClamp(mMousePosition.x() + (e.value * mMouseAccelerator), mMouseExtents.upperLeft().x(),
              mMouseExtents.lowerRight().x());
            mMousePosition.setX(i);
            mMouseMoved = true;
            break;
          case REL_Y:
            i = pxClamp(mMousePosition.y() + (e.value * mMouseAccelerator), mMouseExtents.upperLeft().y(),
              mMouseExtents.lowerRight().y());
            mMousePosition.setY(i);
            mMouseMoved = true;
            break;
        }
        break;

      case EV_SYN:
        if (mMouseMoved)
          handleMouseEvent(e, false);
        break;

        // There are a bunch.
        // https://www.kernel.org/doc/Documentation/input/event-codes.txt
      default:
        break;
    }
  }
Beispiel #2
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;
	}
}
void WebPluginContainerImpl::handleEvent(Event* event)
{
    if (!m_webPlugin->acceptsInputEvents())
        return;

    // The events we pass are defined at:
    //    http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structures5.html#1000000
    // Don't take the documentation as truth, however.  There are many cases
    // where mozilla behaves differently than the spec.
    if (event->isMouseEvent())
        handleMouseEvent(static_cast<MouseEvent*>(event));
    else if (event->isWheelEvent())
        handleWheelEvent(static_cast<WheelEvent*>(event));
    else if (event->isKeyboardEvent())
        handleKeyboardEvent(static_cast<KeyboardEvent*>(event));
}
Beispiel #4
0
void QBBEventThread::dispatchEvent(screen_event_t event)
{
    // get the event type
    errno = 0;
    int qnxType;
    int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType);
    if (result) {
        qFatal("QBB: failed to query event type, errno=%d", errno);
    }

    switch (qnxType) {
    case SCREEN_EVENT_MTOUCH_TOUCH:
    case SCREEN_EVENT_MTOUCH_MOVE:
    case SCREEN_EVENT_MTOUCH_RELEASE:
        handleTouchEvent(event, qnxType);
        break;

    case SCREEN_EVENT_KEYBOARD:
        handleKeyboardEvent(event);
        break;

    case SCREEN_EVENT_POINTER:
        handlePointerEvent(event);
        break;

    case SCREEN_EVENT_CLOSE:
        handleCloseEvent(event);
        break;

    case SCREEN_EVENT_USER:
        // treat all user events as shutdown requests
#if defined(QBBEVENTTHREAD_DEBUG)
        qDebug() << "QBB: QNX user event";
#endif
        mQuit = true;
        break;

    default:
        // event ignored
#if defined(QBBEVENTTHREAD_DEBUG)
        qDebug() << "QBB: QNX unknown event";
#endif
        break;
    }
}
void InputMethodFilter::sendCompositionAndPreeditWithFakeKeyEvents(ResultsToSend resultsToSend)
{
    // The Windows composition key event code is 299 or VK_PROCESSKEY. We need to
    // emit this code for web compatibility reasons when key events trigger
    // composition results. GDK doesn't have an equivalent, so we send VoidSymbol
    // here to WebCore. PlatformKeyEvent knows to convert this code into
    // VK_PROCESSKEY.
    static const int compositionEventKeyCode = GDK_KEY_VoidSymbol;

    GUniquePtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS));
    event->key.time = GDK_CURRENT_TIME;
    event->key.keyval = compositionEventKeyCode;
    handleKeyboardEventWithCompositionResults(&event->key, resultsToSend, EventFaked);

    m_confirmedComposition = String();
    if (resultsToSend & Composition)
        m_composingTextCurrently = false;

    event->type = GDK_KEY_RELEASE;
    handleKeyboardEvent(&event->key, String(), EventFaked);
    m_justSentFakeKeyUp = true;
}
bool QQnxScreenEventHandler::handleEvent(screen_event_t event, int qnxType)
{
    switch (qnxType) {
    case SCREEN_EVENT_MTOUCH_TOUCH:
    case SCREEN_EVENT_MTOUCH_MOVE:
    case SCREEN_EVENT_MTOUCH_RELEASE:
        handleTouchEvent(event, qnxType);
        break;

    case SCREEN_EVENT_KEYBOARD:
        handleKeyboardEvent(event);
        break;

    case SCREEN_EVENT_POINTER:
        handlePointerEvent(event);
        break;

    case SCREEN_EVENT_CREATE:
        handleCreateEvent(event);
        break;

    case SCREEN_EVENT_CLOSE:
        handleCloseEvent(event);
        break;

    case SCREEN_EVENT_DISPLAY:
        handleDisplayEvent(event);
        break;

    default:
        // event ignored
        qScreenEventDebug() << Q_FUNC_INFO << "unknown event" << qnxType;
        return false;
    }

    return true;
}
void GameEngine::handleEvents(sf::Time &elapsedTime)
{
    sf::Event event;
	
    while (window->pollEvent(event))
    {
		switch (event.type)
		{
		case sf::Event::Closed:
			close();
			break;

		case sf::Event::KeyPressed:
			if (data.state == RUNNING)
				handleKeyboardEvent(event, elapsedTime);
			else if (data.state == MAIN_MENU)
				menu->handleKeyboardEvent(event, elapsedTime);
			break;

		default:
			break;
		}
    }
}
void InputMethodFilter::filterKeyEvent(GdkEventKey* event, FilterKeyEventCompletionHandler&& completionHandler)
{
#if ENABLE(API_TESTS)
    ASSERT(m_page || m_testingMode);
#else
    ASSERT(m_page);
#endif
    m_filterKeyEventCompletionHandler = WTF::move(completionHandler);
    if (!m_enabled) {
        handleKeyboardEvent(event);
        return;
    }

    m_preeditChanged = false;
    m_filteringKeyEvent = true;

    unsigned lastFilteredKeyPressCodeWithNoResults = m_lastFilteredKeyPressCodeWithNoResults;
    m_lastFilteredKeyPressCodeWithNoResults = GDK_KEY_VoidSymbol;

    bool filtered = gtk_im_context_filter_keypress(m_context.get(), event);
    m_filteringKeyEvent = false;

    bool justSentFakeKeyUp = m_justSentFakeKeyUp;
    m_justSentFakeKeyUp = false;
    if (justSentFakeKeyUp && event->type == GDK_KEY_RELEASE)
        return;

    // Simple input methods work such that even normal keystrokes fire the
    // commit signal. We detect those situations and treat them as normal
    // key events, supplying the commit string as the key character.
    if (filtered && !m_composingTextCurrently && !m_preeditChanged && m_confirmedComposition.length() == 1) {
        handleKeyboardEvent(event, m_confirmedComposition);
        m_confirmedComposition = String();
        return;
    }

    if (filtered && event->type == GDK_KEY_PRESS) {
        if (!m_preeditChanged && m_confirmedComposition.isNull()) {
            m_composingTextCurrently = true;
            m_lastFilteredKeyPressCodeWithNoResults = event->keyval;
            return;
        }

        handleKeyboardEventWithCompositionResults(event);
        if (!m_confirmedComposition.isEmpty()) {
            m_composingTextCurrently = false;
            m_confirmedComposition = String();
        }
        return;
    }

    // If we previously filtered a key press event and it yielded no results. Suppress
    // the corresponding key release event to avoid confusing the web content.
    if (event->type == GDK_KEY_RELEASE && lastFilteredKeyPressCodeWithNoResults == event->keyval)
        return;

    // At this point a keystroke was either:
    // 1. Unfiltered
    // 2. A filtered keyup event. As the IME code in EditorClient.h doesn't
    //    ever look at keyup events, we send any composition results before
    //    the key event.
    // Both might have composition results or not.
    //
    // It's important to send the composition results before the event
    // because some IM modules operate that way. For example (taken from
    // the Chromium source), the latin-post input method gives this sequence
    // when you press 'a' and then backspace:
    //  1. keydown 'a' (filtered)
    //  2. preedit changed to "a"
    //  3. keyup 'a' (unfiltered)
    //  4. keydown Backspace (unfiltered)
    //  5. commit "a"
    //  6. preedit end
    if (!m_confirmedComposition.isEmpty())
        confirmComposition();
    if (m_preeditChanged)
        updatePreedit();
    handleKeyboardEvent(event);
}
/***********************************************************
synopsis: a big while loop that runs the full length of the
	  game, checks the game events and responds
	  accordingly

	  event		action
	  -------------------------------------------------
	  winGame	stop the clock and solve puzzle
	  timeRemaining update the clock tick
	  timeUp	stop the clock and solve puzzle
	  solvePuzzle	trigger solve puzzle and stop clock
	  updateAnswers trigger update answers
	  startNew      trigger start new
	  updateScore	trigger update score
	  shuffle	trigger shuffle
	  clear		trigger clear answer
	  quit		end loop
	  poll events   check for keyboard/mouse and quit

	  finally, move the sprites -this is always called
	  so the sprites are always considered to be moving
	  no "move sprites" event exists - sprites x&y just
	  needs to be updated and they will always be moved

inputs: head - first node in the answers list (in/out)
        dblHead - first node in the dictionary list
	screen - the SDL_Surface to display the image
	letters - first node in the letter sprites (in/out)

outputs: n/a
***********************************************************/
static void
gameLoop(struct node **head, struct dlb_node *dlbHead, 
         SDL_Surface *screen, struct sprite **letters)
{
	int j,k;
    int done=0;
	int numofwords=1;
    SDL_Event event;
    time_t timeNow;
    SDL_TimerID timer;
    int timer_delay = 20;
    char buffer[512];

	#ifdef demo
	
	if (conf.totalgames < 0){
		conf.totalgames=8;
	}
	conf.totalgames +=1;//demo tags
	sprintf(buffer,"globaldata/agdemo.cfg");
	saveCFG(buffer,&conf);
	#endif

    timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
	/* main game loop */
	while (!done) {

		if (winGame) {
			stopTheClock = 1;
			solvePuzzle = 1;
		}

		if ((gameTime < AVAILABLE_TIME) && !stopTheClock) {
			timeNow = time(0) - gameStart;
			if (timeNow != gameTime){
				gameTime = timeNow;
				updateTime(screen);
			}
		} else {
			if (!stopTheClock){
				stopTheClock = 1;
				solvePuzzle = 1;
			}
		}

		/* check messages */
		if (solvePuzzle) {
			/* walk the list, setting everything to found */
			solveIt(*head);
			clearWord(letters);
			strcpy(shuffle, SPACE_FILLED_STRING);
			strcpy(answer, rootWord);
			/*displayLetters(screen);*/
			displayAnswerBoxes(*head, screen);
			gamePaused = 1;
			if (!stopTheClock){
				stopTheClock = 1;
			}
			solvePuzzle = 0;
		}

		if (updateAnswers){
			/* move letters back down again */
			clearWord(letters);
			/* displayLetters(screen);*/
			displayAnswerBoxes(*head, screen);

			updateAnswers = 0;
		}


		if ((stopTheClock && !gotBigWord && !checkScore)||(startNewGame&&!gotBigWord& !checkScore)){
			//Error("inside highscore\n");
			for(j=9;j>=0 && hiscore[j].score<totalScore;j--);
				//Error("score position: %i\n",j);
			/* the player will be in the hall of fame? */
			if(j<9) {
				for(k=8;k>j;k--)
					hiscore[k+1]=hiscore[k];

				/* put the new score */
				hiscore[j+1].score=totalScore;
				hiscore[j+1].stage=numofwords;
				
				 //hiscore[j+1].name[0]=0;
				//if(!getName(hiscore[j+1].name, j+2,i+1))
				//	break; /* probably a problem if the user closes the window */

				/* show the hall of fame */
				//hiscores();

				/* save hi-scores */
				#ifdef demo
				sprintf(buffer,"/media/internal/appdata/com.cribme.aghddemo/ag-hiscore");
				#else
				sprintf(buffer,"/media/internal/appdata/com.cribme.aghd/ag-hiscore");
				#endif
				//sprintf(buffer,"globaldata/ag-hiscore");
				if(!saveScore(buffer,hiscore))
				fprintf(stderr,"unable to save hi-scores\ndo you have permissions to write into %s?\n" ,buffer);
				
			}
			checkScore=1;
		}

		if (startNewGame) {
			/* move letters back down again */
			if (!gotBigWord){
				totalScore = 0;
				numofwords=0;
			}
			newGame(head, dlbHead, screen, letters);

			#ifdef demo
			conf.totalgames +=1;//demo tags
			char buffer[512];
			sprintf(buffer,"globaldata/agdemo.cfg");
			//Error("Buffer :%s\n",buffer);
			//Error("TotalGames Written to file :%i\n",conf.totalgames);
			saveCFG(buffer,&conf);
			#endif

			numofwords+=1;
			checkScore = 0;
			startNewGame = 0;
		}

		if (updateTheScore) {
			updateScore(screen);
			updateTheScore = 0;
		}

		if (shuffleRemaining) {
			/* shuffle up the shuffle box */
			char shuffler[8];
			strcpy(shuffler, shuffle);
			shuffleAvailableLetters(shuffler, letters);
			strcpy(shuffle, shuffler);
			shuffleRemaining = 0;
		}

		if (clearGuess) {
			/* clear the guess; */
			if (clearWord(letters) > 0) {
				Mix_PlayChannel(-1, getSound("clear"),0);
            }
			clearGuess = 0;
		}
		#ifdef demo
		//Error("TotalGames:%i\n",conf.totalgames);//conf.totalgames
		if (conf.totalgames > 8){//conf.totalgames
		    destroyLetters(letters);
			strcpy(txt, language);
			ShowBMP(strcat(txt,"images/demo.bmp"),screen, 100,75);
			done=1;
		}

		#endif

		if (quitGame) {
			done = 1;
		}
		if (inactive){
			SDL_WaitEvent(&event);
				if (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) {
				inactive = 0;
				timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
				}
		}
		else {
		while (SDL_WaitEvent(&event)) {
			if (event.type == SDL_ACTIVEEVENT && event.active.gain == 0) {
				inactive = 1;
				break;
			}
			if (event.type == SDL_USEREVENT) {
                timer_delay = anySpritesMoving(letters) ? 10 : 100;
                moveSprites(&screen, letters, letterSpeed);
                timer = SDL_AddTimer(timer_delay, TimerCallback, NULL);
                break;
            } else if (event.type == SDL_MOUSEBUTTONDOWN) {
                clickDetect(event.button.button, event.button.x,
                            event.button.y, screen, *head, letters);
				moveSprites(&screen, letters, letterSpeed);//added by me
            } else if (event.type == SDL_KEYUP) {
                handleKeyboardEvent(&event, *head, letters);
            } else if (event.type == SDL_QUIT) {
                done = 1;
                break;	
			} 
				
		}
		}
    }
	#ifdef demo
	while(conf.totalgames > 8){//conf.totalgames
		while(SDL_WaitEvent(&event)){
				if (event.type == SDL_MOUSEBUTTONDOWN) {
				PDL_ServiceCall("palm://com.palm.applicationManager/open", "{\"target\":\"http://developer.palm.com/appredirect/?packageid=com.cribme.aghd\"}");
					//PDL_LaunchBrowser("http://developer.palm.com/appredirect/?packageid=com.cribme.aghd");
				}
		}
	}
	#endif

	
}