Beispiel #1
0
static void qemulator_refresh(QEmulator* emulator)
{
    SDL_Event      ev;
    SkinWindow*    window   = emulator->window;
    SkinKeyboard*  keyboard = emulator->keyboard;

    qframebuffer_check_updates();

    if (window == NULL)
        return;

    while(SDL_PollEvent(&ev)){
        switch(ev.type){
        case SDL_VIDEOEXPOSE:
            skin_window_redraw( window, NULL );
            break;

        case SDL_KEYDOWN:
#ifdef _WIN32
            
            if (ev.key.keysym.sym == SDLK_F4 &&
                ev.key.keysym.mod & KMOD_ALT) {
              goto CleanExit;
            }
#endif
#ifdef __APPLE__
            
            if (ev.key.keysym.sym == SDLK_q &&
                ev.key.keysym.mod & KMOD_META) {
              goto CleanExit;
            }
#endif
            skin_keyboard_process_event( keyboard, &ev, 1 );
            break;

        case SDL_KEYUP:
            skin_keyboard_process_event( keyboard, &ev, 0 );
            break;

        case SDL_MOUSEMOTION:
            skin_window_process_event( window, &ev );
            break;

        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
            {
                int  down = (ev.type == SDL_MOUSEBUTTONDOWN);
                if (ev.button.button == 4)
                {
                    
                    AndroidKeyCode  kcode;

                    kcode = 
                        android_keycode_rotate(kKeyCodeDpadUp,
                            skin_layout_get_dpad_rotation(qemulator_get_layout(qemulator_get())));
                    user_event_key( kcode, down );
                }
                else if (ev.button.button == 5)
                {
                    
                    AndroidKeyCode  kcode;

                    kcode = 
                        android_keycode_rotate(kKeyCodeDpadDown,
                            skin_layout_get_dpad_rotation(qemulator_get_layout(qemulator_get())));
                    user_event_key( kcode, down );
                }
                else if (ev.button.button == SDL_BUTTON_LEFT) {
                    skin_window_process_event( window, &ev );
                }
#if 0
                else {
                fprintf(stderr, "... mouse button %s: button=%d state=%04x x=%d y=%d\n",
                                down ? "down" : "up  ",
                                ev.button.button, ev.button.state, ev.button.x, ev.button.y);
                }
#endif
            }
            break;

        case SDL_QUIT:
#if defined _WIN32 || defined __APPLE__
        CleanExit:
#endif
            
            qemulator_done(qemulator_get());
            qemu_system_shutdown_request();
            return;
        }
    }

    skin_keyboard_flush( keyboard );
}
Beispiel #2
0
bool skin_ui_process_events(SkinUI* ui) {
    SkinEvent ev;

#ifdef _WIN32
    if (ui->ui_params.win32_ignore_events) {
        // In QT, Windows messages are received by the QT thread, which is
        // the thread that creates all of its windows, so that should be
        // okay. However, in GPU accelerated images, there's a native window
        // that's created that represents the actual OpenGL output pane, and
        // that window is created from this thread and not the QT thread. We
        // need to keep its message queue from getting jammed up with
        // messages, so we need to grab any messages we see and drop
        // unnecessary ones on the floor.
        MSG message;
        PeekMessage(&message, NULL, 0, 0, PM_REMOVE);
    }
#endif  // _WIN32

    while(skin_event_poll(&ev)) {
        switch(ev.type) {
        case kEventVideoExpose:
            DE("EVENT: kEventVideoExpose\n");
            skin_window_redraw(ui->window, NULL);
            break;

        case kEventKeyDown:
            DE("EVENT: kEventKeyDown scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 1);
            break;

        case kEventKeyUp:
            DE("EVENT: kEventKeyUp scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 0);
            break;

        case kEventTextInput:
            DE("EVENT: kEventTextInput text=[%s] down=%s\n",
               ev.u.text.text, ev.u.text.down ? "true" : "false");
            skin_keyboard_process_event(ui->keyboard, &ev, ev.u.text.down);
            break;

        case kEventMouseMotion:
            DE("EVENT: kEventMouseMotion x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            skin_window_process_event(ui->window, &ev);
            break;

        case kEventMouseButtonDown:
        case kEventMouseButtonUp:
            DE("EVENT: kEventMouseButton x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            {
                int  down = (ev.type == kEventMouseButtonDown);
                if (ev.u.mouse.button == kMouseButtonScrollUp)
                {
                    /* scroll-wheel simulates DPad up */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadUp,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonScrollDown)
                {
                    /* scroll-wheel simulates DPad down */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadDown,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonLeft) {
                    skin_window_process_event(ui->window, &ev);
                }
            }
            break;

        case kEventQuit:
            DE("EVENT: kEventQuit\n");
            /* only save emulator config through clean exit */
            return true;
        }
    }

    skin_keyboard_flush(ui->keyboard);
    return false;
}
/* called periodically to poll for user input events */
static void qemulator_refresh(QEmulator* emulator)
{
    SDL_Event      ev;
    SkinWindow*    window   = emulator->window;
    SkinKeyboard*  keyboard = emulator->keyboard;

   /* this will eventually call sdl_update if the content of the VGA framebuffer
    * has changed */
    qframebuffer_check_updates();

    if (window == NULL)
        return;

    while(SDL_PollEvent(&ev)){
        switch(ev.type){
        case SDL_VIDEOEXPOSE:
            skin_window_redraw( window, NULL );
            break;

        case SDL_KEYDOWN:
#ifdef _WIN32
            /* special code to deal with Alt-F4 properly */
            if (ev.key.keysym.sym == SDLK_F4 &&
                ev.key.keysym.mod & KMOD_ALT) {
              goto CleanExit;
            }
#endif
#ifdef __APPLE__
            /* special code to deal with Command-Q properly */
            if (ev.key.keysym.sym == SDLK_q &&
                ev.key.keysym.mod & KMOD_META) {
              goto CleanExit;
            }
#endif
            skin_keyboard_process_event( keyboard, &ev, 1 );
            break;

        case SDL_KEYUP:
            skin_keyboard_process_event( keyboard, &ev, 0 );
            break;

        case SDL_MOUSEMOTION:
            skin_window_process_event( window, &ev );
            break;

        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
            {
                int  down = (ev.type == SDL_MOUSEBUTTONDOWN);
                if (ev.button.button == 4)
                {
                    /* scroll-wheel simulates DPad up */
                    AndroidKeyCode  kcode;

                    kcode = // qemulator_rotate_keycode(kKeyCodeDpadUp);
                        android_keycode_rotate(kKeyCodeDpadUp,
                            skin_layout_get_dpad_rotation(qemulator_get_layout(qemulator_get())));
                    user_event_key( kcode, down );
                }
                else if (ev.button.button == 5)
                {
                    /* scroll-wheel simulates DPad down */
                    AndroidKeyCode  kcode;

                    kcode = // qemulator_rotate_keycode(kKeyCodeDpadDown);
                        android_keycode_rotate(kKeyCodeDpadDown,
                            skin_layout_get_dpad_rotation(qemulator_get_layout(qemulator_get())));
                    user_event_key( kcode, down );
                }
                else if (ev.button.button == SDL_BUTTON_LEFT) {
                    skin_window_process_event( window, &ev );
                }
#if 0
                else {
                fprintf(stderr, "... mouse button %s: button=%d state=%04x x=%d y=%d\n",
                                down ? "down" : "up  ",
                                ev.button.button, ev.button.state, ev.button.x, ev.button.y);
                }
#endif
            }
            break;

        case SDL_QUIT:
#if defined _WIN32 || defined __APPLE__
        CleanExit:
#endif
            /* only save emulator config through clean exit */
            qemulator_done(qemulator_get());
            qemu_system_shutdown_request();
            return;
        }
    }

    skin_keyboard_flush( keyboard );
}
Beispiel #4
0
void
skin_keyboard_process_event( SkinKeyboard*  kb, SDL_Event*  ev, int  down )
{
    unsigned         code;
    int              unicode = ev->key.keysym.unicode;
    int              sym     = ev->key.keysym.sym;
    int              mod     = ev->key.keysym.mod;

    /* ignore key events if we're not enabled */
    if (!kb->enabled) {
        printf( "ignoring key event sym=%d mod=0x%x unicode=%d\n",
                sym, mod, unicode );
        return;
    }

    /* first, try the keyboard-mode-independent keys */
    code = skin_keyboard_key_to_code( kb, sym, mod, down );
    if (code == 0)
        return;

    if ((int)code > 0) {
        skin_keyboard_do_key_event(kb, code, down);
        skin_keyboard_flush(kb);
        return;
    }

    /* Ctrl-K is used to switch between 'unicode' and 'raw' modes */
    if (sym == SDLK_k)
    {
        int  mod2 = mod & 0x7ff;

        if ( mod2 == KMOD_LCTRL || mod2 == KMOD_RCTRL ) {
            if (down) {
                skin_keyboard_clear_last(kb);
                kb->raw_keys = !kb->raw_keys;
                SDL_EnableUNICODE(!kb->raw_keys);
                D( "switching keyboard to %s mode", kb->raw_keys ? "raw" : "unicode" );
            }
            return;
        }
    }

    if (!kb->raw_keys) {
       /* ev->key.keysym.unicode is only valid on keydown events, and will be 0
        * on the corresponding keyup ones, so remember the set of last pressed key
        * syms to "undo" the job
        */
        if ( !down && unicode == 0 ) {
            LastKey*  k = skin_keyboard_find_last(kb, sym);
            if (k != NULL) {
                unicode = k->unicode;
                skin_keyboard_remove_last(kb, sym);
            }
        }
    }
    if (!kb->raw_keys &&
        skin_keyboard_process_unicode_event( kb, unicode, down ) > 0)
    {
        if (down)
            skin_keyboard_add_last( kb, sym, mod, unicode );

        skin_keyboard_flush( kb );
        return;
    }

    code = skin_keyboard_raw_key_to_code( kb, sym, down );

    if ( !kb->raw_keys &&
         (code == kKeyCodeAltLeft  || code == kKeyCodeAltRight ||
          code == kKeyCodeCapLeft  || code == kKeyCodeCapRight ||
          code == kKeyCodeSym) )
        return;

    if (code == -1) {
        D("ignoring keysym %d", sym );
    } else if (code > 0) {
        skin_keyboard_do_key_event(kb, code, down);
        skin_keyboard_flush(kb);
    }
}
bool skin_ui_process_events(SkinUI* ui) {
    SkinEvent ev;

    while(skin_event_poll(&ev)) {
        switch(ev.type) {
        case kEventVideoExpose:
            DE("EVENT: kEventVideoExpose\n");
            skin_window_redraw(ui->window, NULL);
            break;

        case kEventKeyDown:
            DE("EVENT: kEventKeyDown scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 1);
            break;

        case kEventKeyUp:
            DE("EVENT: kEventKeyUp scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 0);
            break;

        case kEventTextInput:
            DE("EVENT: kEventTextInput text=[%s] down=%s\n",
               ev.u.text.text, ev.u.text.down ? "true" : "false");
            skin_keyboard_process_event(ui->keyboard, &ev, ev.u.text.down);
            break;

        case kEventMouseMotion:
            DE("EVENT: kEventMouseMotion x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            skin_window_process_event(ui->window, &ev);
            break;

        case kEventMouseButtonDown:
        case kEventMouseButtonUp:
            DE("EVENT: kEventMouseButton x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            {
                int  down = (ev.type == kEventMouseButtonDown);
                if (ev.u.mouse.button == kMouseButtonScrollUp)
                {
                    /* scroll-wheel simulates DPad up */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadUp,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonScrollDown)
                {
                    /* scroll-wheel simulates DPad down */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadDown,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonLeft) {
                    skin_window_process_event(ui->window, &ev);
                }
            }
            break;

        case kEventQuit:
            DE("EVENT: kEventQuit\n");
            /* only save emulator config through clean exit */
            return true;
        }
    }

    skin_keyboard_flush(ui->keyboard);
    return false;
}