Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/core/freebsd/SDL_evdev_kbd_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
SDL_free(kbd);
}

void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted)
{
}

void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data)
{
}

void SDL_EVDEV_kbd_update(SDL_EVDEV_keyboard_state *state)
{
}

/*
* Helper Functions.
*/
Expand Down Expand Up @@ -467,10 +479,6 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
}
}

void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted)
{
}

void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down)
{
keymap_t key_map;
Expand Down
10 changes: 10 additions & 0 deletions src/core/linux/SDL_evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
}
#endif /* SDL_USE_LIBUDEV */

void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void*), void *release_callback_data,
void (*acquire_callback)(void*), void *acquire_callback_data)
{
SDL_EVDEV_kbd_set_vt_switch_callbacks(_this->kbd,
release_callback, release_callback_data,
acquire_callback, acquire_callback_data);
}

int SDL_EVDEV_GetDeviceCount(int device_class)
{
SDL_evdevlist_item *item;
Expand Down Expand Up @@ -319,6 +327,8 @@ void SDL_EVDEV_Poll(void)
SDL_UDEV_Poll();
#endif

SDL_EVDEV_kbd_update(_this->kbd);

mouse = SDL_GetMouse();

for (item = _this->first; item != NULL; item = item->next) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/linux/SDL_evdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct input_event;

extern int SDL_EVDEV_Init(void);
extern void SDL_EVDEV_Quit(void);
extern void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void*), void *release_callback_data,
void (*acquire_callback)(void*), void *acquire_callback_data);
extern int SDL_EVDEV_GetDeviceCount(int device_class);
extern void SDL_EVDEV_Poll(void);
extern Uint64 SDL_EVDEV_GetEventTimestamp(struct input_event *event);
Expand Down
211 changes: 185 additions & 26 deletions src/core/linux/SDL_evdev_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ struct SDL_EVDEV_keyboard_state
char shift_state;
char text[128];
unsigned int text_len;
void (*vt_release_callback)(void *);
void *vt_release_callback_data;
void (*vt_acquire_callback)(void *);
void *vt_acquire_callback_data;
};

#ifdef DUMP_ACCENTS
Expand Down Expand Up @@ -296,6 +300,128 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
}
}

enum {
VT_SIGNAL_NONE,
VT_SIGNAL_RELEASE,
VT_SIGNAL_ACQUIRE,
};
static int vt_release_signal;
static int vt_acquire_signal;
static SDL_AtomicInt vt_signal_pending;

typedef void (*signal_handler)(int signum);

static void kbd_vt_release_signal_action(int signum)
{
printf("kbd_vt_release_signal_action\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgotten debug prints?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep :)

SDL_AtomicSet(&vt_signal_pending, VT_SIGNAL_RELEASE);
}

static void kbd_vt_acquire_signal_action(int signum)
{
printf("kbd_vt_acquire_signal_action\n");
SDL_AtomicSet(&vt_signal_pending, VT_SIGNAL_ACQUIRE);
}

static SDL_bool setup_vt_signal(int signum, signal_handler handler)
{
struct sigaction *old_action_p;
struct sigaction new_action;
old_action_p = &(old_sigaction[signum]);
SDL_zero(new_action);
new_action.sa_handler = handler;
new_action.sa_flags = SA_RESTART;
if (sigaction(signum, &new_action, old_action_p) < 0) {
return SDL_FALSE;
}
if (old_action_p->sa_handler != SIG_DFL) {
/* This signal is already in use */
sigaction(signum, old_action_p, NULL);
return SDL_FALSE;
}
return SDL_TRUE;
}

static int find_free_signal(signal_handler handler)
{
#ifdef SIGRTMIN
int i;

for (i = SIGRTMIN + 2; i <= SIGRTMAX; ++i) {
if (setup_vt_signal(i, handler)) {
return i;
}
}
#endif
if (setup_vt_signal(SIGUSR1, handler)) {
return SIGUSR1;
}
if (setup_vt_signal(SIGUSR2, handler)) {
return SIGUSR2;
}
return 0;
}

static void kbd_vt_quit(int console_fd)
{
struct vt_mode mode;

if (vt_release_signal) {
sigaction(vt_release_signal, &old_sigaction[vt_release_signal], NULL);
vt_release_signal = 0;
}
if (vt_acquire_signal) {
sigaction(vt_acquire_signal, &old_sigaction[vt_acquire_signal], NULL);
vt_acquire_signal = 0;
}

SDL_zero(mode);
mode.mode = VT_AUTO;
ioctl(console_fd, VT_SETMODE, &mode);
}

static int kbd_vt_init(int console_fd)
{
struct vt_mode mode;

vt_release_signal = find_free_signal(kbd_vt_release_signal_action);
vt_acquire_signal = find_free_signal(kbd_vt_acquire_signal_action);
if (!vt_release_signal || !vt_acquire_signal ) {
kbd_vt_quit(console_fd);
return -1;
}

SDL_zero(mode);
mode.mode = VT_PROCESS;
mode.relsig = vt_release_signal;
mode.acqsig = vt_acquire_signal;
mode.frsig = SIGIO;
if (ioctl(console_fd, VT_SETMODE, &mode) < 0) {
kbd_vt_quit(console_fd);
return -1;
}
return 0;
}

static void kbd_vt_update(SDL_EVDEV_keyboard_state *state)
{
int signal_pending = SDL_AtomicGet(&vt_signal_pending);
if (signal_pending != VT_SIGNAL_NONE) {
if (signal_pending == VT_SIGNAL_RELEASE) {
if (state->vt_release_callback) {
state->vt_release_callback(state->vt_release_callback_data);
}
ioctl(state->console_fd, VT_RELDISP, 1);
} else {
if (state->vt_acquire_callback) {
state->vt_acquire_callback(state->vt_acquire_callback_data);
}
ioctl(state->console_fd, VT_RELDISP, VT_ACKACQ);
}
SDL_AtomicCAS(&vt_signal_pending, signal_pending, VT_SIGNAL_NONE);
}
}

SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
{
SDL_EVDEV_keyboard_state *kbd;
Expand Down Expand Up @@ -333,33 +459,9 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
ioctl(kbd->console_fd, KDSKBMODE, K_UNICODE);
}

return kbd;
}
kbd_vt_init(kbd->console_fd);

void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
{
if (state == NULL) {
return;
}

SDL_EVDEV_kbd_set_muted(state, SDL_FALSE);

if (state->console_fd >= 0) {
close(state->console_fd);
state->console_fd = -1;
}

if (state->key_maps && state->key_maps != default_key_maps) {
int i;
for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
if (state->key_maps[i]) {
SDL_free(state->key_maps[i]);
}
}
SDL_free(state->key_maps);
}

SDL_free(state);
return kbd;
}

void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted)
Expand Down Expand Up @@ -396,6 +498,55 @@ void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted)
state->muted = muted;
}

void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data)
{
if (state == NULL) {
return;
}

state->vt_release_callback = release_callback;
state->vt_release_callback_data = release_callback_data;
state->vt_acquire_callback = acquire_callback;
state->vt_acquire_callback_data = acquire_callback_data;
}

void SDL_EVDEV_kbd_update(SDL_EVDEV_keyboard_state *state)
{
if (!state) {
return;
}

kbd_vt_update(state);
}

void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
{
if (state == NULL) {
return;
}

SDL_EVDEV_kbd_set_muted(state, SDL_FALSE);

kbd_vt_quit(state->console_fd);

if (state->console_fd >= 0) {
close(state->console_fd);
state->console_fd = -1;
}

if (state->key_maps && state->key_maps != default_key_maps) {
int i;
for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
if (state->key_maps[i]) {
SDL_free(state->key_maps[i]);
}
}
SDL_free(state->key_maps);
}

SDL_free(state);
}

/*
* Helper Functions.
*/
Expand Down Expand Up @@ -830,6 +981,14 @@ void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted)
{
}

void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data)
{
}

void SDL_EVDEV_kbd_update(SDL_EVDEV_keyboard_state *state)
{
}

void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down)
{
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/linux/SDL_evdev_kbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ typedef struct SDL_EVDEV_keyboard_state SDL_EVDEV_keyboard_state;

extern SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void);
extern void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted);
extern void SDL_EVDEV_kbd_set_vt_switch_callbacks(SDL_EVDEV_keyboard_state *state, void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data);
extern void SDL_EVDEV_kbd_update(SDL_EVDEV_keyboard_state *state);
extern void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down);
extern void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state);

Expand Down
9 changes: 8 additions & 1 deletion src/video/kmsdrm/SDL_kmsdrmopengles.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
even if you do async flips. */
uint32_t flip_flags = DRM_MODE_PAGE_FLIP_EVENT;

/* Skip the swap if we've switched away to another VT */
if (windata->egl_surface == EGL_NO_SURFACE) {
/* Wait a bit, throttling to ~100 FPS */
SDL_Delay(10);
return 0;
}

/* Recreate the GBM / EGL surfaces if the display mode has changed */
if (windata->egl_surface_dirty) {
KMSDRM_CreateSurfaces(_this, window);
Expand All @@ -116,7 +123,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)

windata->bo = windata->next_bo;

/* Mark a buffer to becume the next front buffer.
/* Mark a buffer to become the next front buffer.
This won't happen until pagelip completes. */
if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display,
windata->egl_surface))) {
Expand Down
1 change: 1 addition & 0 deletions src/video/kmsdrm/SDL_kmsdrmsym.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SDL_KMSDRM_SYM(void,drmModeFreeConnector,(drmModeConnectorPtr ptr))
SDL_KMSDRM_SYM(void,drmModeFreeEncoder,(drmModeEncoderPtr ptr))
SDL_KMSDRM_SYM(int,drmGetCap,(int fd, uint64_t capability, uint64_t *value))
SDL_KMSDRM_SYM(int,drmSetMaster,(int fd))
SDL_KMSDRM_SYM(int,drmDropMaster,(int fd))
SDL_KMSDRM_SYM(int,drmAuthMagic,(int fd, drm_magic_t magic))
SDL_KMSDRM_SYM(drmModeResPtr,drmModeGetResources,(int fd))
SDL_KMSDRM_SYM(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_t depth,
Expand Down
Loading