示例#1
0
int
SDL_EVDEV_Init(void)
{
    int retval = 0;
    
    if (_this == NULL) {
        
        _this = (SDL_EVDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
        if(_this == NULL) {
            return SDL_OutOfMemory();
        }

#if SDL_USE_LIBUDEV
        if (SDL_UDEV_Init() < 0) {
            SDL_free(_this);
            _this = NULL;
            return -1;
        }

        /* Set up the udev callback */
        if ( SDL_UDEV_AddCallback(SDL_EVDEV_udev_callback) < 0) {
            SDL_EVDEV_Quit();
            return -1;
        }
        
        /* Force a scan to build the initial device list */
        SDL_UDEV_Scan();
#else
        /* TODO: Scan the devices manually, like a caveman */
#endif /* SDL_USE_LIBUDEV */
        
        /* We need a physical terminal (not PTS) to be able to translate key code to symbols via the kernel tables */
        _this->console_fd = SDL_EVDEV_get_console_fd();
        
        /* Mute the keyboard so keystrokes only generate evdev events and do not leak through to the console */
        _this->tty = STDIN_FILENO;
        if (SDL_EVDEV_mute_keyboard(_this->tty, &_this->kb_mode) < 0) {
            /* stdin is not a tty, probably we were launched remotely, so we try to disable the active tty */
            _this->tty = SDL_EVDEV_get_active_tty();
            if (_this->tty >= 0) {
                if (SDL_EVDEV_mute_keyboard(_this->tty, &_this->kb_mode) < 0) {
                    close(_this->tty);
                    _this->tty = -1;
                }
            }
        }
    }
    
    _this->ref_count += 1;
    
    return retval;
}
示例#2
0
static int
JoystickInitWithUdev(void)
{
    if (SDL_UDEV_Init() < 0) {
        return SDL_SetError("Could not initialize UDEV");
    }

    /* Set up the udev callback */
    if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
        SDL_UDEV_Quit();
        return SDL_SetError("Could not set up joystick <-> udev callback");
    }
    
    /* Force a scan to build the initial device list */
    SDL_UDEV_Scan();

    return numjoysticks;
}
示例#3
0
int
SDL_EVDEV_Init(void)
{
    if (_this == NULL) {
        _this = (SDL_EVDEV_PrivateData*)SDL_calloc(1, sizeof(*_this));
        if (_this == NULL) {
            return SDL_OutOfMemory();
        }

#if SDL_USE_LIBUDEV
        if (SDL_UDEV_Init() < 0) {
            SDL_free(_this);
            _this = NULL;
            return -1;
        }

        /* Set up the udev callback */
        if (SDL_UDEV_AddCallback(SDL_EVDEV_udev_callback) < 0) {
            SDL_UDEV_Quit();
            SDL_free(_this);
            _this = NULL;
            return -1;
        }

        /* Force a scan to build the initial device list */
        SDL_UDEV_Scan();
#else
        /* TODO: Scan the devices manually, like a caveman */
#endif /* SDL_USE_LIBUDEV */

        _this->kbd = SDL_EVDEV_kbd_init();
    }

    _this->ref_count += 1;

    return 0;
}