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; }
int SDL_UDEV_Init(void) { int retval = 0; if (_this == NULL) { _this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this)); if(_this == NULL) { return SDL_OutOfMemory(); } retval = SDL_UDEV_LoadLibrary(); if (retval < 0) { SDL_UDEV_Quit(); return retval; } /* Set up udev monitoring * Listen for input devices (mouse, keyboard, joystick, etc) and sound devices */ _this->udev = _this->udev_new(); if (_this->udev == NULL) { SDL_UDEV_Quit(); return SDL_SetError("udev_new() failed"); } _this->udev_mon = _this->udev_monitor_new_from_netlink(_this->udev, "udev"); if (_this->udev_mon == NULL) { SDL_UDEV_Quit(); return SDL_SetError("udev_monitor_new_from_netlink() failed"); } _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "input", NULL); _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "sound", NULL); _this->udev_monitor_enable_receiving(_this->udev_mon); /* Do an initial scan of existing devices */ SDL_UDEV_Scan(); } _this->ref_count += 1; return retval; }
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; }
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; }