Cleanup add brace (#6545)

* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line
This commit is contained in:
Sylvain Becker
2022-11-27 17:38:43 +01:00
committed by GitHub
parent 4958dafdc3
commit 6a2200823c
387 changed files with 6094 additions and 4633 deletions
+7 -6
View File
@@ -239,17 +239,17 @@ LoadSprite(const char *file)
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */ /* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h); sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
if (!sprites[i]) { if (!sprites[i]) {
return (-1); return -1;
} }
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) { if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
SDL_DestroyTexture(sprites[i]); SDL_DestroyTexture(sprites[i]);
return (-1); return -1;
} }
} }
/* We're ready to roll. :) */ /* We're ready to roll. :) */
return (0); return 0;
} }
void void
@@ -364,8 +364,9 @@ loop()
#endif #endif
} }
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL) if (state->windows[i] == NULL) {
continue; continue;
}
DrawSprites(state->renderers[i], sprites[i]); DrawSprites(state->renderers[i], sprites[i]);
} }
} }
@@ -382,7 +383,7 @@ main(int argc, char *argv[])
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (!state) { if (state == NULL) {
return 1; return 1;
} }
@@ -445,7 +446,7 @@ main(int argc, char *argv[])
/* Create the windows, initialize the renderers, and load the textures */ /* Create the windows, initialize the renderers, and load the textures */
sprites = sprites =
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
if (!sprites) { if (sprites == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2); quit(2);
} }
+2 -2
View File
@@ -127,7 +127,7 @@ initializeTextures(SDL_Renderer *renderer)
/* create ship texture from surface */ /* create ship texture from surface */
ship = SDL_CreateTextureFromSurface(renderer, bmp_surface); ship = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (!ship) { if (ship == NULL) {
fatalError("could not create ship texture"); fatalError("could not create ship texture");
} }
SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);
@@ -145,7 +145,7 @@ initializeTextures(SDL_Renderer *renderer)
} }
/* create space texture from surface */ /* create space texture from surface */
space = SDL_CreateTextureFromSurface(renderer, bmp_surface); space = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (!space) { if (space == NULL) {
fatalError("could not create space texture"); fatalError("could not create space texture");
} }
SDL_FreeSurface(bmp_surface); SDL_FreeSurface(bmp_surface);
+16 -9
View File
@@ -84,14 +84,16 @@ stepParticles(double deltaTime)
/* is the particle actually active, or is it marked for deletion? */ /* is the particle actually active, or is it marked for deletion? */
if (curr->isActive) { if (curr->isActive) {
/* is the particle off the screen? */ /* is the particle off the screen? */
if (curr->y > screen_h) if (curr->y > screen_h) {
curr->isActive = 0; curr->isActive = 0;
else if (curr->y < 0) } else if (curr->y < 0) {
curr->isActive = 0; curr->isActive = 0;
if (curr->x > screen_w) }
if (curr->x > screen_w) {
curr->isActive = 0; curr->isActive = 0;
else if (curr->x < 0) } else if (curr->x < 0) {
curr->isActive = 0; curr->isActive = 0;
}
/* step velocity, then step position */ /* step velocity, then step position */
curr->yvel += ACCEL * deltaMilliseconds; curr->yvel += ACCEL * deltaMilliseconds;
@@ -133,15 +135,17 @@ stepParticles(double deltaTime)
} }
/* if we're a dust particle, shrink our size */ /* if we're a dust particle, shrink our size */
if (curr->type == dust) if (curr->type == dust) {
curr->size -= deltaMilliseconds * 0.010f; curr->size -= deltaMilliseconds * 0.010f;
}
} }
/* if we're still active, pack ourselves in the array next /* if we're still active, pack ourselves in the array next
to the last active guy (pack the array tightly) */ to the last active guy (pack the array tightly) */
if (curr->isActive) if (curr->isActive) {
*(slot++) = *curr; *(slot++) = *curr;
}
} /* endif (curr->isActive) */ } /* endif (curr->isActive) */
curr++; curr++;
} }
@@ -188,8 +192,9 @@ explodeEmitter(struct particle *emitter)
int i; int i;
for (i = 0; i < 200; i++) { for (i = 0; i < 200; i++) {
if (num_active_particles >= MAX_PARTICLES) if (num_active_particles >= MAX_PARTICLES) {
return; return;
}
/* come up with a random angle and speed for new particle */ /* come up with a random angle and speed for new particle */
float theta = randomFloat(0, 2.0f * 3.141592); float theta = randomFloat(0, 2.0f * 3.141592);
@@ -226,8 +231,9 @@ void
spawnTrailFromEmitter(struct particle *emitter) spawnTrailFromEmitter(struct particle *emitter)
{ {
if (num_active_particles >= MAX_PARTICLES) if (num_active_particles >= MAX_PARTICLES) {
return; return;
}
/* select the particle at the slot at the end of our array */ /* select the particle at the slot at the end of our array */
struct particle *p = &particles[num_active_particles]; struct particle *p = &particles[num_active_particles];
@@ -262,8 +268,9 @@ void
spawnEmitterParticle(GLfloat x, GLfloat y) spawnEmitterParticle(GLfloat x, GLfloat y)
{ {
if (num_active_particles >= MAX_PARTICLES) if (num_active_particles >= MAX_PARTICLES) {
return; return;
}
/* find particle at endpoint of array */ /* find particle at endpoint of array */
struct particle *p = &particles[num_active_particles]; struct particle *p = &particles[num_active_particles];
+1 -1
View File
@@ -117,7 +117,7 @@ initializeTexture(SDL_Renderer *renderer)
/* convert RGBA surface to texture */ /* convert RGBA surface to texture */
texture = SDL_CreateTextureFromSurface(renderer, bmp_surface); texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (!texture) { if (texture == NULL) {
fatalError("could not create texture"); fatalError("could not create texture");
} }
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
+2 -2
View File
@@ -165,7 +165,7 @@ loadFont(void)
{ {
SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp"); SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");
if (!surface) { if (surface == NULL) {
printf("Error loading bitmap: %s\n", SDL_GetError()); printf("Error loading bitmap: %s\n", SDL_GetError());
return 0; return 0;
} else { } else {
@@ -183,7 +183,7 @@ loadFont(void)
SDL_BlitSurface(surface, NULL, converted, NULL); SDL_BlitSurface(surface, NULL, converted, NULL);
/* create our texture */ /* create our texture */
texture = SDL_CreateTextureFromSurface(renderer, converted); texture = SDL_CreateTextureFromSurface(renderer, converted);
if (!texture) { if (texture == NULL) {
printf("texture creation failed: %s\n", SDL_GetError()); printf("texture creation failed: %s\n", SDL_GetError());
} else { } else {
/* set blend mode for our texture */ /* set blend mode for our texture */
+2 -2
View File
@@ -207,9 +207,9 @@ playSound(struct sound *s)
break; break;
} }
/* if this channel's sound is older than the oldest so far, set it to oldest */ /* if this channel's sound is older than the oldest so far, set it to oldest */
if (mixer.channels[i].timestamp < if (mixer.channels[i].timestamp < mixer.channels[oldest_channel].timestamp) {
mixer.channels[oldest_channel].timestamp)
oldest_channel = i; oldest_channel = i;
}
} }
/* no empty channels, take the oldest one */ /* no empty channels, take the oldest one */
+2 -2
View File
@@ -58,11 +58,11 @@ main(int argc, char *argv[])
/* create window and renderer */ /* create window and renderer */
window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI); window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
if (!window) { if (window == NULL) {
fatalError("Could not initialize Window"); fatalError("Could not initialize Window");
} }
renderer = SDL_CreateRenderer(window, -1, 0); renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) { if (renderer == NULL) {
fatalError("Could not create renderer"); fatalError("Could not create renderer");
} }
+1 -1
View File
@@ -63,7 +63,7 @@ initializeTexture(SDL_Renderer *renderer)
brush = brush =
SDL_CreateTextureFromSurface(renderer, bmp_surface); SDL_CreateTextureFromSurface(renderer, bmp_surface);
SDL_FreeSurface(bmp_surface); SDL_FreeSurface(bmp_surface);
if (!brush) { if (brush == NULL) {
fatalError("could not create brush texture"); fatalError("could not create brush texture");
} }
/* additive blending -- laying strokes on top of eachother makes them brighter */ /* additive blending -- laying strokes on top of eachother makes them brighter */
+10 -11
View File
@@ -216,7 +216,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the timer subsystem */ /* Initialize the timer subsystem */
if ((flags & SDL_INIT_TIMER)){ if ((flags & SDL_INIT_TIMER)) {
#if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY #if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) { if (SDL_TimerInit() < 0) {
@@ -232,7 +232,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the video subsystem */ /* Initialize the video subsystem */
if ((flags & SDL_INIT_VIDEO)){ if ((flags & SDL_INIT_VIDEO)) {
#if !SDL_VIDEO_DISABLED #if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) { if (SDL_VideoInit(NULL) < 0) {
@@ -248,7 +248,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the audio subsystem */ /* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO)){ if ((flags & SDL_INIT_AUDIO)) {
#if !SDL_AUDIO_DISABLED #if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) { if (SDL_AudioInit(NULL) < 0) {
@@ -264,7 +264,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the joystick subsystem */ /* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK)){ if ((flags & SDL_INIT_JOYSTICK)) {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) { if (SDL_JoystickInit() < 0) {
@@ -279,7 +279,7 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
} }
if ((flags & SDL_INIT_GAMECONTROLLER)){ if ((flags & SDL_INIT_GAMECONTROLLER)) {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) { if (SDL_GameControllerInit() < 0) {
@@ -295,7 +295,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the haptic subsystem */ /* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC)){ if ((flags & SDL_INIT_HAPTIC)) {
#if !SDL_HAPTIC_DISABLED #if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) { if (SDL_HapticInit() < 0) {
@@ -311,7 +311,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the sensor subsystem */ /* Initialize the sensor subsystem */
if ((flags & SDL_INIT_SENSOR)){ if ((flags & SDL_INIT_SENSOR)) {
#if !SDL_SENSOR_DISABLED #if !SDL_SENSOR_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
if (SDL_SensorInit() < 0) { if (SDL_SensorInit() < 0) {
@@ -328,11 +328,11 @@ SDL_InitSubSystem(Uint32 flags)
(void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */ (void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
return (0); return 0;
quit_and_error: quit_and_error:
SDL_QuitSubSystem(flags_initialized); SDL_QuitSubSystem(flags_initialized);
return (-1); return -1;
} }
int int
@@ -500,8 +500,7 @@ SDL_GetVersion(SDL_version * ver)
static SDL_bool check_hint = SDL_TRUE; static SDL_bool check_hint = SDL_TRUE;
static SDL_bool legacy_version = SDL_FALSE; static SDL_bool legacy_version = SDL_FALSE;
if (!ver) { if (ver == NULL) { return;
return;
} }
SDL_VERSION(ver); SDL_VERSION(ver);
+1 -4
View File
@@ -244,10 +244,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
} else { } else {
state = (SDL_assert_state)selected; state = (SDL_assert_state)selected;
} }
} } else {
else
{
#if defined(__EMSCRIPTEN__) #if defined(__EMSCRIPTEN__)
/* This is nasty, but we can't block on a custom UI. */ /* This is nasty, but we can't block on a custom UI. */
for ( ; ; ) { for ( ; ; ) {
+11 -11
View File
@@ -57,7 +57,7 @@ SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
{ {
SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue)); SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue));
if (!queue) { if (queue == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} else { } else {
@@ -101,7 +101,7 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
SDL_DataQueuePacket *prev = NULL; SDL_DataQueuePacket *prev = NULL;
size_t i; size_t i;
if (!queue) { if (queue == NULL) {
return; return;
} }
@@ -180,7 +180,7 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
size_t origlen; size_t origlen;
size_t datalen; size_t datalen;
if (!queue) { if (queue == NULL) {
return SDL_InvalidParamError("queue"); return SDL_InvalidParamError("queue");
} }
@@ -190,13 +190,13 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
while (len > 0) { while (len > 0) {
SDL_DataQueuePacket *packet = queue->tail; SDL_DataQueuePacket *packet = queue->tail;
SDL_assert(!packet || (packet->datalen <= packet_size)); SDL_assert(packet == NULL || (packet->datalen <= packet_size));
if (!packet || (packet->datalen >= packet_size)) { if (packet == NULL || (packet->datalen >= packet_size)) {
/* tail packet missing or completely full; we need a new packet. */ /* tail packet missing or completely full; we need a new packet. */
packet = AllocateDataQueuePacket(queue); packet = AllocateDataQueuePacket(queue);
if (!packet) { if (packet == NULL) {
/* uhoh, reset so we've queued nothing new, free what we can. */ /* uhoh, reset so we've queued nothing new, free what we can. */
if (!origtail) { if (origtail == NULL) {
packet = queue->head; /* whole queue. */ packet = queue->head; /* whole queue. */
} else { } else {
packet = origtail->next; /* what we added to existing queue. */ packet = origtail->next; /* what we added to existing queue. */
@@ -231,7 +231,7 @@ SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
Uint8 *ptr = buf; Uint8 *ptr = buf;
SDL_DataQueuePacket *packet; SDL_DataQueuePacket *packet;
if (!queue) { if (queue == NULL) {
return 0; return 0;
} }
@@ -256,7 +256,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
Uint8 *ptr = buf; Uint8 *ptr = buf;
SDL_DataQueuePacket *packet; SDL_DataQueuePacket *packet;
if (!queue) { if (queue == NULL) {
return 0; return 0;
} }
@@ -299,7 +299,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
{ {
SDL_DataQueuePacket *packet; SDL_DataQueuePacket *packet;
if (!queue) { if (queue == NULL) {
SDL_InvalidParamError("queue"); SDL_InvalidParamError("queue");
return NULL; return NULL;
} else if (len == 0) { } else if (len == 0) {
@@ -323,7 +323,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
/* Need a fresh packet. */ /* Need a fresh packet. */
packet = AllocateDataQueuePacket(queue); packet = AllocateDataQueuePacket(queue);
if (!packet) { if (packet == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
+3 -3
View File
@@ -51,15 +51,15 @@ void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
static unsigned char nibble(unsigned char c) static unsigned char nibble(unsigned char c)
{ {
if ((c >= '0') && (c <= '9')) { if ((c >= '0') && (c <= '9')) {
return (c - '0'); return c - '0';
} }
if ((c >= 'A') && (c <= 'F')) { if ((c >= 'A') && (c <= 'F')) {
return (c - 'A' + 0x0a); return c - 'A' + 0x0a;
} }
if ((c >= 'a') && (c <= 'f')) { if ((c >= 'a') && (c <= 'f')) {
return (c - 'a' + 0x0a); return c - 'a' + 0x0a;
} }
/* received an invalid character, and no real way to return an error */ /* received an invalid character, and no real way to return an error */
+9 -9
View File
@@ -50,7 +50,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
SDL_Hint *hint; SDL_Hint *hint;
SDL_HintWatch *entry; SDL_HintWatch *entry;
if (!name) { if (name == NULL) {
return SDL_FALSE; return SDL_FALSE;
} }
@@ -65,7 +65,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
return SDL_FALSE; return SDL_FALSE;
} }
if (hint->value != value && if (hint->value != value &&
(!value || !hint->value || SDL_strcmp(hint->value, value) != 0)) { (value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
for (entry = hint->callbacks; entry; ) { for (entry = hint->callbacks; entry; ) {
/* Save the next entry in case this one is deleted */ /* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next; SDL_HintWatch *next = entry->next;
@@ -82,7 +82,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
/* Couldn't find the hint, add a new one */ /* Couldn't find the hint, add a new one */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) { if (hint == NULL) {
return SDL_FALSE; return SDL_FALSE;
} }
hint->name = SDL_strdup(name); hint->name = SDL_strdup(name);
@@ -101,7 +101,7 @@ SDL_ResetHint(const char *name)
SDL_Hint *hint; SDL_Hint *hint;
SDL_HintWatch *entry; SDL_HintWatch *entry;
if (!name) { if (name == NULL) {
return SDL_FALSE; return SDL_FALSE;
} }
@@ -179,7 +179,7 @@ SDL_GetHint(const char *name)
SDL_bool SDL_bool
SDL_GetStringBoolean(const char *value, SDL_bool default_value) SDL_GetStringBoolean(const char *value, SDL_bool default_value)
{ {
if (!value || !*value) { if (value == NULL || !*value) {
return default_value; return default_value;
} }
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) { if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
@@ -202,7 +202,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
SDL_HintWatch *entry; SDL_HintWatch *entry;
const char *value; const char *value;
if (!name || !*name) { if (name == NULL || !*name) {
SDL_InvalidParamError("name"); SDL_InvalidParamError("name");
return; return;
} }
@@ -214,7 +214,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
SDL_DelHintCallback(name, callback, userdata); SDL_DelHintCallback(name, callback, userdata);
entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry)); entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
if (!entry) { if (entry == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return; return;
} }
@@ -226,10 +226,10 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
break; break;
} }
} }
if (!hint) { if (hint == NULL) {
/* Need to add a hint entry for this watcher */ /* Need to add a hint entry for this watcher */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) { if (hint == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_free(entry); SDL_free(entry);
return; return;
+6 -4
View File
@@ -105,7 +105,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
void void
SDL_LogInit(void) SDL_LogInit(void)
{ {
if (!log_function_mutex) { if (log_function_mutex == NULL) {
/* if this fails we'll try to continue without it. */ /* if this fails we'll try to continue without it. */
log_function_mutex = SDL_CreateMutex(); log_function_mutex = SDL_CreateMutex();
} }
@@ -313,7 +313,7 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
return; return;
} }
if (!log_function_mutex) { if (log_function_mutex == NULL) {
/* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */ /* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */
log_function_mutex = SDL_CreateMutex(); log_function_mutex = SDL_CreateMutex();
} }
@@ -323,15 +323,17 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq); len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq);
va_end(aq); va_end(aq);
if (len < 0) if (len < 0) {
return; return;
}
/* If message truncated, allocate and re-render */ /* If message truncated, allocate and re-render */
if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) { if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) {
/* Allocate exactly what we need, including the zero-terminator */ /* Allocate exactly what we need, including the zero-terminator */
message = (char *)SDL_malloc(len_plus_term); message = (char *)SDL_malloc(len_plus_term);
if (!message) if (message == NULL) {
return; return;
}
va_copy(aq, ap); va_copy(aq, ap);
len = SDL_vsnprintf(message, len_plus_term, fmt, aq); len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
va_end(aq); va_end(aq);
+14 -14
View File
@@ -128,15 +128,15 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
{ {
#ifdef HAVE_MSC_ATOMICS #ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(long) == sizeof(a->value)); SDL_COMPILE_TIME_ASSERT(atomic_cas, sizeof(long) == sizeof(a->value));
return (_InterlockedCompareExchange((long*)&a->value, (long)newval, (long)oldval) == (long)oldval); return _InterlockedCompareExchange((long *)&a->value, (long)newval, (long)oldval) == (long)oldval;
#elif defined(HAVE_WATCOM_ATOMICS) #elif defined(HAVE_WATCOM_ATOMICS)
return (SDL_bool) _SDL_cmpxchg_watcom(&a->value, newval, oldval); return (SDL_bool)_SDL_cmpxchg_watcom(&a->value, newval, oldval);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval); return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ #elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value); return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
return (SDL_bool) ((int) atomic_cas_uint((volatile uint_t*)&a->value, (uint_t)oldval, (uint_t)newval) == oldval); return (SDL_bool)((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
#elif EMULATE_CAS #elif EMULATE_CAS
SDL_bool retval = SDL_FALSE; SDL_bool retval = SDL_FALSE;
@@ -157,17 +157,17 @@ SDL_bool
SDL_AtomicCASPtr(void **a, void *oldval, void *newval) SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
{ {
#if defined(HAVE_MSC_ATOMICS) #if defined(HAVE_MSC_ATOMICS)
return (_InterlockedCompareExchangePointer(a, newval, oldval) == oldval); return _InterlockedCompareExchangePointer(a, newval, oldval) == oldval;
#elif defined(HAVE_WATCOM_ATOMICS) #elif defined(HAVE_WATCOM_ATOMICS)
return (SDL_bool) _SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval); return (SDL_bool)_SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return __sync_bool_compare_and_swap(a, oldval, newval); return __sync_bool_compare_and_swap(a, oldval, newval);
#elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ #elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t*) a); return (SDL_bool) OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t*) a);
#elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ #elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a); return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
return (SDL_bool) (atomic_cas_ptr(a, oldval, newval) == oldval); return (SDL_bool)(atomic_cas_ptr(a, oldval, newval) == oldval);
#elif EMULATE_CAS #elif EMULATE_CAS
SDL_bool retval = SDL_FALSE; SDL_bool retval = SDL_FALSE;
@@ -189,13 +189,13 @@ SDL_AtomicSet(SDL_atomic_t *a, int v)
{ {
#ifdef HAVE_MSC_ATOMICS #ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value)); SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value));
return _InterlockedExchange((long*)&a->value, v); return _InterlockedExchange((long *)&a->value, v);
#elif defined(HAVE_WATCOM_ATOMICS) #elif defined(HAVE_WATCOM_ATOMICS)
return _SDL_xchg_watcom(&a->value, v); return _SDL_xchg_watcom(&a->value, v);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return __sync_lock_test_and_set(&a->value, v); return __sync_lock_test_and_set(&a->value, v);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
return (int) atomic_swap_uint((volatile uint_t*)&a->value, v); return (int)atomic_swap_uint((volatile uint_t *)&a->value, v);
#else #else
int value; int value;
do { do {
@@ -211,7 +211,7 @@ SDL_AtomicSetPtr(void **a, void *v)
#if defined(HAVE_MSC_ATOMICS) #if defined(HAVE_MSC_ATOMICS)
return _InterlockedExchangePointer(a, v); return _InterlockedExchangePointer(a, v);
#elif defined(HAVE_WATCOM_ATOMICS) #elif defined(HAVE_WATCOM_ATOMICS)
return (void *) _SDL_xchg_watcom((int *)a, (long)v); return (void *)_SDL_xchg_watcom((int *)a, (long)v);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return __sync_lock_test_and_set(a, v); return __sync_lock_test_and_set(a, v);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
@@ -230,7 +230,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
{ {
#ifdef HAVE_MSC_ATOMICS #ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value)); SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value));
return _InterlockedExchangeAdd((long*)&a->value, v); return _InterlockedExchangeAdd((long *)&a->value, v);
#elif defined(HAVE_WATCOM_ATOMICS) #elif defined(HAVE_WATCOM_ATOMICS)
return _SDL_xadd_watcom(&a->value, v); return _SDL_xadd_watcom(&a->value, v);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
@@ -261,7 +261,7 @@ SDL_AtomicGet(SDL_atomic_t *a)
return _SDL_xadd_watcom(&a->value, 0); return _SDL_xadd_watcom(&a->value, 0);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return __sync_or_and_fetch(&a->value, 0); return __sync_or_and_fetch(&a->value, 0);
#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ #elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return sizeof(a->value) == sizeof(uint32_t) ? OSAtomicOr32Barrier(0, (volatile uint32_t *)&a->value) : OSAtomicAdd64Barrier(0, (volatile int64_t *)&a->value); return sizeof(a->value) == sizeof(uint32_t) ? OSAtomicOr32Barrier(0, (volatile uint32_t *)&a->value) : OSAtomicAdd64Barrier(0, (volatile int64_t *)&a->value);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
return atomic_or_uint((volatile uint_t *)&a->value, 0); return atomic_or_uint((volatile uint_t *)&a->value, 0);
+11 -11
View File
@@ -63,7 +63,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
/* Terrible terrible damage */ /* Terrible terrible damage */
static SDL_mutex *_spinlock_mutex; static SDL_mutex *_spinlock_mutex;
if (!_spinlock_mutex) { if (_spinlock_mutex == NULL) {
/* Race condition on first lock... */ /* Race condition on first lock... */
_spinlock_mutex = SDL_CreateMutex(); _spinlock_mutex = SDL_CreateMutex();
} }
@@ -78,14 +78,14 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
} }
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
return (__sync_lock_test_and_set(lock, 1) == 0); return __sync_lock_test_and_set(lock, 1) == 0;
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
return (_InterlockedExchange_acq(lock, 1) == 0); return _InterlockedExchange_acq(lock, 1) == 0;
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return (InterlockedExchange((long*)lock, 1) == 0); return InterlockedExchange((long *)lock, 1) == 0;
#elif defined(__WATCOMC__) && defined(__386__) #elif defined(__WATCOMC__) && defined(__386__)
return _SDL_xchg_watcom(lock, 1) == 0; return _SDL_xchg_watcom(lock, 1) == 0;
@@ -102,28 +102,28 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
__asm__ __volatile__ ( __asm__ __volatile__ (
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0); return result == 0;
} }
#endif #endif
__asm__ __volatile__ ( __asm__ __volatile__ (
"swp %0, %1, [%2]\n" "swp %0, %1, [%2]\n"
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory"); : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
return (result == 0); return result == 0;
#elif defined(__GNUC__) && defined(__arm__) #elif defined(__GNUC__) && defined(__arm__)
int result; int result;
__asm__ __volatile__ ( __asm__ __volatile__ (
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0); return result == 0;
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
int result; int result;
__asm__ __volatile__( __asm__ __volatile__(
"lock ; xchgl %0, (%1)\n" "lock ; xchgl %0, (%1)\n"
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory"); : "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
return (result == 0); return result == 0;
#elif defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__) #elif defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__)
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */ /* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
@@ -131,11 +131,11 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
#elif defined(__SOLARIS__) && defined(_LP64) #elif defined(__SOLARIS__) && defined(_LP64)
/* Used for Solaris with non-gcc compilers. */ /* Used for Solaris with non-gcc compilers. */
return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0); return (SDL_bool)((int)atomic_cas_64((volatile uint64_t *)lock, 0, 1) == 0);
#elif defined(__SOLARIS__) && !defined(_LP64) #elif defined(__SOLARIS__) && !defined(_LP64)
/* Used for Solaris with non-gcc compilers. */ /* Used for Solaris with non-gcc compilers. */
return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)lock, 0, 1) == 0); return (SDL_bool)((int)atomic_cas_32((volatile uint32_t *)lock, 0, 1) == 0);
#elif defined(PS2) #elif defined(PS2)
uint32_t oldintr; uint32_t oldintr;
SDL_bool res = SDL_FALSE; SDL_bool res = SDL_FALSE;
@@ -147,7 +147,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
res = SDL_TRUE; res = SDL_TRUE;
} }
// enable interuption // enable interuption
if(oldintr) { EIntr(); } if (oldintr) { EIntr(); }
return res; return res;
#else #else
#error Please implement for your platform. #error Please implement for your platform.
+3 -5
View File
@@ -509,11 +509,9 @@ SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle)
} else { } else {
mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved); mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved);
} }
for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++) for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++) {
{
device = open_devices[device_index]; device = open_devices[device_index];
if (device != NULL && device->handle == handle) if (device != NULL && device->handle == handle) {
{
device_was_opened = SDL_TRUE; device_was_opened = SDL_TRUE;
SDL_OpenedAudioDeviceDisconnected(device); SDL_OpenedAudioDeviceDisconnected(device);
break; break;
@@ -977,7 +975,7 @@ SDL_AudioInit(const char *driver_name)
} }
} else { } else {
for (i = 0; (!initialized) && (bootstrap[i]); ++i) { for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
if(bootstrap[i]->demand_only) { if (bootstrap[i]->demand_only) {
continue; continue;
} }
+22 -20
View File
@@ -180,7 +180,7 @@ ResamplerPadding(const int inrate, const int outrate)
return 0; return 0;
} }
if (inrate > outrate) { if (inrate > outrate) {
return (int) SDL_ceilf(((float) (RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float) outrate))); return (int)SDL_ceilf(((float)(RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float)outrate)));
} }
return RESAMPLER_SAMPLES_PER_ZERO_CROSSING; return RESAMPLER_SAMPLES_PER_ZERO_CROSSING;
} }
@@ -246,7 +246,7 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
outtime = outtimeincr * i; outtime = outtimeincr * i;
} }
return outframes * chans * sizeof (float); return outframes * chans * sizeof(float);
} }
int int
@@ -485,7 +485,7 @@ SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format
/* we keep no streaming state here, so pad with silence on both ends. */ /* we keep no streaming state here, so pad with silence on both ends. */
padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float)); padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float));
if (!padding) { if (padding == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return; return;
} }
@@ -583,7 +583,7 @@ SDL_BuildAudioResampleCVT(SDL_AudioCVT * cvt, const int dst_channels,
!!! FIXME in 2.1: We need to store data for this resampler, because the cvt structure doesn't store the original sample rates, !!! FIXME in 2.1: We need to store data for this resampler, because the cvt structure doesn't store the original sample rates,
!!! FIXME in 2.1: so we steal the ninth and tenth slot. :( */ !!! FIXME in 2.1: so we steal the ninth and tenth slot. :( */
if (cvt->filter_index >= (SDL_AUDIOCVT_MAX_FILTERS-2)) { if (cvt->filter_index >= (SDL_AUDIOCVT_MAX_FILTERS-2)) {
return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS-2); return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS - 2);
} }
cvt->filters[SDL_AUDIOCVT_MAX_FILTERS-1] = (SDL_AudioFilter) (uintptr_t) src_rate; cvt->filters[SDL_AUDIOCVT_MAX_FILTERS-1] = (SDL_AudioFilter) (uintptr_t) src_rate;
cvt->filters[SDL_AUDIOCVT_MAX_FILTERS] = (SDL_AudioFilter) (uintptr_t) dst_rate; cvt->filters[SDL_AUDIOCVT_MAX_FILTERS] = (SDL_AudioFilter) (uintptr_t) dst_rate;
@@ -785,7 +785,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
} }
cvt->needed = (cvt->filter_index != 0); cvt->needed = (cvt->filter_index != 0);
return (cvt->needed); return cvt->needed;
} }
typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen); typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen);
@@ -832,7 +832,7 @@ EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
ptr = stream->work_buffer_base; ptr = stream->work_buffer_base;
} else { } else {
ptr = (Uint8 *) SDL_realloc(stream->work_buffer_base, newlen + 32); ptr = (Uint8 *) SDL_realloc(stream->work_buffer_base, newlen + 32);
if (!ptr) { if (ptr == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@@ -908,12 +908,12 @@ SetupLibSampleRateResampling(SDL_AudioStream *stream)
if (SRC_available) { if (SRC_available) {
state = SRC_src_new(SRC_converter, stream->pre_resample_channels, &result); state = SRC_src_new(SRC_converter, stream->pre_resample_channels, &result);
if (!state) { if (state == NULL) {
SDL_SetError("src_new() failed: %s", SRC_src_strerror(result)); SDL_SetError("src_new() failed: %s", SRC_src_strerror(result));
} }
} }
if (!state) { if (state == NULL) {
SDL_CleanupAudioStreamResampler_SRC(stream); SDL_CleanupAudioStreamResampler_SRC(stream);
return SDL_FALSE; return SDL_FALSE;
} }
@@ -980,7 +980,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
SDL_AudioStream *retval; SDL_AudioStream *retval;
retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream)); retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
if (!retval) { if (retval == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@@ -1123,7 +1123,7 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
#endif #endif
workbuf = EnsureStreamBufferSize(stream, workbuflen); workbuf = EnsureStreamBufferSize(stream, workbuflen);
if (!workbuf) { if (workbuf == NULL) {
return -1; /* probably out of memory. */ return -1; /* probably out of memory. */
} }
@@ -1190,8 +1190,9 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
if (maxputbytes) { if (maxputbytes) {
const int maxbytes = *maxputbytes; const int maxbytes = *maxputbytes;
if (buflen > maxbytes) if (buflen > maxbytes) {
buflen = maxbytes; buflen = maxbytes;
}
*maxputbytes -= buflen; *maxputbytes -= buflen;
} }
@@ -1214,10 +1215,10 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
SDL_Log("AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen); SDL_Log("AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen);
#endif #endif
if (!stream) { if (stream == NULL) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
} }
if (!buf) { if (buf == NULL) {
return SDL_InvalidParamError("buf"); return SDL_InvalidParamError("buf");
} }
if (len == 0) { if (len == 0) {
@@ -1269,7 +1270,7 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
int SDL_AudioStreamFlush(SDL_AudioStream *stream) int SDL_AudioStreamFlush(SDL_AudioStream *stream)
{ {
if (!stream) { if (stream == NULL) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
} }
@@ -1287,8 +1288,9 @@ int SDL_AudioStreamFlush(SDL_AudioStream *stream)
const SDL_bool first_run = stream->first_run; const SDL_bool first_run = stream->first_run;
const int filled = stream->staging_buffer_filled; const int filled = stream->staging_buffer_filled;
int actual_input_frames = filled / stream->src_sample_frame_size; int actual_input_frames = filled / stream->src_sample_frame_size;
if (!first_run) if (!first_run) {
actual_input_frames += stream->resampler_padding_samples / stream->pre_resample_channels; actual_input_frames += stream->resampler_padding_samples / stream->pre_resample_channels;
}
if (actual_input_frames > 0) { /* don't bother if nothing to flush. */ if (actual_input_frames > 0) { /* don't bother if nothing to flush. */
/* This is how many bytes we're expecting without silence appended. */ /* This is how many bytes we're expecting without silence appended. */
@@ -1327,10 +1329,10 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
SDL_Log("AUDIOSTREAM: want to get %d converted bytes\n", len); SDL_Log("AUDIOSTREAM: want to get %d converted bytes\n", len);
#endif #endif
if (!stream) { if (stream == NULL) {
return SDL_InvalidParamError("stream"); return SDL_InvalidParamError("stream");
} }
if (!buf) { if (buf == NULL) {
return SDL_InvalidParamError("buf"); return SDL_InvalidParamError("buf");
} }
if (len <= 0) { if (len <= 0) {
@@ -1340,20 +1342,20 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
return SDL_SetError("Can't request partial sample frames"); return SDL_SetError("Can't request partial sample frames");
} }
return (int) SDL_ReadFromDataQueue(stream->queue, buf, len); return (int)SDL_ReadFromDataQueue(stream->queue, buf, len);
} }
/* number of converted/resampled bytes available */ /* number of converted/resampled bytes available */
int int
SDL_AudioStreamAvailable(SDL_AudioStream *stream) SDL_AudioStreamAvailable(SDL_AudioStream *stream)
{ {
return stream ? (int) SDL_CountDataQueue(stream->queue) : 0; return stream ? (int)SDL_CountDataQueue(stream->queue) : 0;
} }
void void
SDL_AudioStreamClear(SDL_AudioStream *stream) SDL_AudioStreamClear(SDL_AudioStream *stream)
{ {
if (!stream) { if (stream == NULL) {
SDL_InvalidParamError("stream"); SDL_InvalidParamError("stream");
} else { } else {
SDL_ClearDataQueue(stream->queue, stream->packetlen * 2); SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);
+2 -1
View File
@@ -83,8 +83,9 @@ SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*
const char *audiodev; const char *audiodev;
char audiopath[1024]; char audiopath[1024];
if (test == NULL) if (test == NULL) {
test = test_stub; test = test_stub;
}
/* Figure out what our audio device is */ /* Figure out what our audio device is */
if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) && if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
+9 -5
View File
@@ -818,7 +818,7 @@ IMA_ADPCM_Init(WaveFile *file, size_t datalength)
/* There's no specification for this, but it's basically the same /* There's no specification for this, but it's basically the same
* format because the extensible header has wSampePerBlocks too. * format because the extensible header has wSampePerBlocks too.
*/ */
} else { } else {
/* The Standards Update says there 'should' be 2 bytes for wSamplesPerBlock. */ /* The Standards Update says there 'should' be 2 bytes for wSamplesPerBlock. */
if (chunk->size >= 20 && format->extsize >= 2) { if (chunk->size >= 20 && format->extsize >= 2) {
format->samplesperblock = chunk->data[18] | ((Uint16)chunk->data[19] << 8); format->samplesperblock = chunk->data[18] | ((Uint16)chunk->data[19] << 8);
@@ -899,14 +899,18 @@ IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
* (nybble & 0x8 ? -1 : 1) * ((nybble & 0x7) * step / 4 + step / 8) * (nybble & 0x8 ? -1 : 1) * ((nybble & 0x7) * step / 4 + step / 8)
*/ */
delta = step >> 3; delta = step >> 3;
if (nybble & 0x04) if (nybble & 0x04) {
delta += step; delta += step;
if (nybble & 0x02) }
if (nybble & 0x02) {
delta += step >> 1; delta += step >> 1;
if (nybble & 0x01) }
if (nybble & 0x01) {
delta += step >> 2; delta += step >> 2;
if (nybble & 0x08) }
if (nybble & 0x08) {
delta = -delta; delta = -delta;
}
sample = lastsample + delta; sample = lastsample + delta;
+1 -1
View File
@@ -439,7 +439,7 @@ SDL_bool aaudio_DetectBrokenPlayState( void )
int64_t framePosition, timeNanoseconds; int64_t framePosition, timeNanoseconds;
aaudio_result_t res; aaudio_result_t res;
if ( !audioDevice || !audioDevice->hidden ) { if (audioDevice == NULL || !audioDevice->hidden ) {
return SDL_FALSE; return SDL_FALSE;
} }
+32 -37
View File
@@ -230,7 +230,7 @@ get_audio_device(void *handle, const int channels)
const char *device; const char *device;
if (handle != NULL) { if (handle != NULL) {
return (const char *) handle; return (const char *)handle;
} }
/* !!! FIXME: we also check "SDL_AUDIO_DEVICE_NAME" at the higher level. */ /* !!! FIXME: we also check "SDL_AUDIO_DEVICE_NAME" at the higher level. */
@@ -398,8 +398,7 @@ ALSA_PlayDevice(_THIS)
return; return;
} }
continue; continue;
} } else if (status == 0) {
else if (status == 0) {
/* No frames were written (no available space in pcm device). /* No frames were written (no available space in pcm device).
Allow other threads to catch up. */ Allow other threads to catch up. */
Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq; Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq;
@@ -414,7 +413,7 @@ ALSA_PlayDevice(_THIS)
static Uint8 * static Uint8 *
ALSA_GetDeviceBuf(_THIS) ALSA_GetDeviceBuf(_THIS)
{ {
return (this->hidden->mixbuf); return this->hidden->mixbuf;
} }
static int static int
@@ -438,8 +437,7 @@ ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
if (status == -EAGAIN) { if (status == -EAGAIN) {
ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time); ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time);
status = 0; status = 0;
} } else if (status < 0) {
else if (status < 0) {
/*printf("ALSA: capture error %d\n", status);*/ /*printf("ALSA: capture error %d\n", status);*/
status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0); status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
if (status < 0) { if (status < 0) {
@@ -500,7 +498,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
status = ALSA_snd_pcm_hw_params_set_period_size_near( status = ALSA_snd_pcm_hw_params_set_period_size_near(
this->hidden->pcm_handle, hwparams, &persize, NULL); this->hidden->pcm_handle, hwparams, &persize, NULL);
if ( status < 0 ) { if ( status < 0 ) {
return(-1); return -1;
} }
/* Need to at least double buffer */ /* Need to at least double buffer */
@@ -508,19 +506,19 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
status = ALSA_snd_pcm_hw_params_set_periods_min( status = ALSA_snd_pcm_hw_params_set_periods_min(
this->hidden->pcm_handle, hwparams, &periods, NULL); this->hidden->pcm_handle, hwparams, &periods, NULL);
if ( status < 0 ) { if ( status < 0 ) {
return(-1); return -1;
} }
status = ALSA_snd_pcm_hw_params_set_periods_first( status = ALSA_snd_pcm_hw_params_set_periods_first(
this->hidden->pcm_handle, hwparams, &periods, NULL); this->hidden->pcm_handle, hwparams, &periods, NULL);
if ( status < 0 ) { if ( status < 0 ) {
return(-1); return -1;
} }
/* "set" the hardware with the desired parameters */ /* "set" the hardware with the desired parameters */
status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams); status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams);
if ( status < 0 ) { if ( status < 0 ) {
return(-1); return -1;
} }
this->spec.samples = persize; this->spec.samples = persize;
@@ -536,7 +534,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
persize, periods, bufsize); persize, periods, bufsize);
} }
return(0); return 0;
} }
static int static int
@@ -572,8 +570,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
SND_PCM_NONBLOCK); SND_PCM_NONBLOCK);
if (status < 0) { if (status < 0) {
return SDL_SetError("ALSA: Couldn't open audio device: %s", return SDL_SetError("ALSA: Couldn't open audio device: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
this->hidden->pcm_handle = pcm_handle; this->hidden->pcm_handle = pcm_handle;
@@ -582,16 +579,14 @@ ALSA_OpenDevice(_THIS, const char *devname)
snd_pcm_hw_params_alloca(&hwparams); snd_pcm_hw_params_alloca(&hwparams);
status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams); status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
if (status < 0) { if (status < 0) {
return SDL_SetError("ALSA: Couldn't get hardware config: %s", return SDL_SetError("ALSA: Couldn't get hardware config: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
/* SDL only uses interleaved sample output */ /* SDL only uses interleaved sample output */
status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams, status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED); SND_PCM_ACCESS_RW_INTERLEAVED);
if (status < 0) { if (status < 0) {
return SDL_SetError("ALSA: Couldn't set interleaved access: %s", return SDL_SetError("ALSA: Couldn't set interleaved access: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
/* Try for a closest match on audio format */ /* Try for a closest match on audio format */
@@ -673,8 +668,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
&rate, NULL); &rate, NULL);
if (status < 0) { if (status < 0) {
return SDL_SetError("ALSA: Couldn't set audio frequency: %s", return SDL_SetError("ALSA: Couldn't set audio frequency: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
this->spec.freq = rate; this->spec.freq = rate;
@@ -688,24 +682,20 @@ ALSA_OpenDevice(_THIS, const char *devname)
snd_pcm_sw_params_alloca(&swparams); snd_pcm_sw_params_alloca(&swparams);
status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams); status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
if (status < 0) { if (status < 0) {
return SDL_SetError("ALSA: Couldn't get software config: %s", return SDL_SetError("ALSA: Couldn't get software config: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples); status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
if (status < 0) { if (status < 0) {
return SDL_SetError("Couldn't set minimum available samples: %s", return SDL_SetError("Couldn't set minimum available samples: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
status = status =
ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1); ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
if (status < 0) { if (status < 0) {
return SDL_SetError("ALSA: Couldn't set start threshold: %s", return SDL_SetError("ALSA: Couldn't set start threshold: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
status = ALSA_snd_pcm_sw_params(pcm_handle, swparams); status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
if (status < 0) { if (status < 0) {
return SDL_SetError("Couldn't set software audio parameters: %s", return SDL_SetError("Couldn't set software audio parameters: %s", ALSA_snd_strerror(status));
ALSA_snd_strerror(status));
} }
/* Calculate the final parameters for this audio specification */ /* Calculate the final parameters for this audio specification */
@@ -746,7 +736,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
char *handle = NULL; char *handle = NULL;
char *ptr; char *ptr;
if (!dev) { if (dev == NULL) {
return; return;
} }
@@ -756,7 +746,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
Make sure not to free the storage associated with desc in this case */ Make sure not to free the storage associated with desc in this case */
if (hint) { if (hint) {
desc = ALSA_snd_device_name_get_hint(hint, "DESC"); desc = ALSA_snd_device_name_get_hint(hint, "DESC");
if (!desc) { if (desc == NULL) {
SDL_free(dev); SDL_free(dev);
return; return;
} }
@@ -776,7 +766,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
/*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/ /*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/
handle = SDL_strdup(name); handle = SDL_strdup(name);
if (!handle) { if (handle == NULL) {
if (hint) { if (hint) {
free(desc); free(desc);
} }
@@ -789,8 +779,9 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
* enumeration time * enumeration time
*/ */
SDL_AddAudioDevice(iscapture, desc, NULL, handle); SDL_AddAudioDevice(iscapture, desc, NULL, handle);
if (hint) if (hint) {
free(desc); free(desc);
}
dev->name = handle; dev->name = handle;
dev->iscapture = iscapture; dev->iscapture = iscapture;
dev->next = *pSeen; dev->next = *pSeen;
@@ -829,7 +820,7 @@ ALSA_HotplugIteration(void)
if we can find a preferred prefix for the system. */ if we can find a preferred prefix for the system. */
for (i = 0; hints[i]; i++) { for (i = 0; hints[i]; i++) {
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) { if (name == NULL) {
continue; continue;
} }
@@ -858,17 +849,17 @@ ALSA_HotplugIteration(void)
char *name; char *name;
/* if we didn't find a device name prefix we like at all... */ /* if we didn't find a device name prefix we like at all... */
if ((!match) && (defaultdev != i)) { if ((match == NULL) && (defaultdev != i)) {
continue; /* ...skip anything that isn't the default device. */ continue; /* ...skip anything that isn't the default device. */
} }
name = ALSA_snd_device_name_get_hint(hints[i], "NAME"); name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
if (!name) { if (name == NULL) {
continue; continue;
} }
/* only want physical hardware interfaces */ /* only want physical hardware interfaces */
if (!match || (SDL_strncmp(name, match, match_len) == 0)) { if (match == NULL || (SDL_strncmp(name, match, match_len) == 0)) {
char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID"); char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0); const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0); const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
@@ -893,8 +884,12 @@ ALSA_HotplugIteration(void)
} }
dev->next = seen; dev->next = seen;
seen = dev; seen = dev;
if (isinput) have_input = SDL_TRUE; if (isinput) {
if (isoutput) have_output = SDL_TRUE; have_input = SDL_TRUE;
}
if (isoutput) {
have_output = SDL_TRUE;
}
} else { } else {
prev = dev; prev = dev;
} }
+6 -8
View File
@@ -146,26 +146,24 @@ void ANDROIDAUDIO_PauseDevices(void)
{ {
/* TODO: Handle multiple devices? */ /* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
if(audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden; private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
if (SDL_AtomicGet(&audioDevice->paused)) { if (SDL_AtomicGet(&audioDevice->paused)) {
/* The device is already paused, leave it alone */ /* The device is already paused, leave it alone */
private->resume = SDL_FALSE; private->resume = SDL_FALSE;
} } else {
else {
SDL_LockMutex(audioDevice->mixer_lock); SDL_LockMutex(audioDevice->mixer_lock);
SDL_AtomicSet(&audioDevice->paused, 1); SDL_AtomicSet(&audioDevice->paused, 1);
private->resume = SDL_TRUE; private->resume = SDL_TRUE;
} }
} }
if(captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden; private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
if (SDL_AtomicGet(&captureDevice->paused)) { if (SDL_AtomicGet(&captureDevice->paused)) {
/* The device is already paused, leave it alone */ /* The device is already paused, leave it alone */
private->resume = SDL_FALSE; private->resume = SDL_FALSE;
} } else {
else {
SDL_LockMutex(captureDevice->mixer_lock); SDL_LockMutex(captureDevice->mixer_lock);
SDL_AtomicSet(&captureDevice->paused, 1); SDL_AtomicSet(&captureDevice->paused, 1);
private->resume = SDL_TRUE; private->resume = SDL_TRUE;
@@ -178,7 +176,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
{ {
/* TODO: Handle multiple devices? */ /* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
if(audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden; private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
if (private->resume) { if (private->resume) {
SDL_AtomicSet(&audioDevice->paused, 0); SDL_AtomicSet(&audioDevice->paused, 0);
@@ -187,7 +185,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
} }
} }
if(captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden; private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
if (private->resume) { if (private->resume) {
SDL_AtomicSet(&captureDevice->paused, 0); SDL_AtomicSet(&captureDevice->paused, 0);
+3 -3
View File
@@ -293,7 +293,7 @@ DSOUND_GetDeviceBuf(_THIS)
} }
if (result != DS_OK) { if (result != DS_OK) {
SetDSerror("DirectSound GetCurrentPosition", result); SetDSerror("DirectSound GetCurrentPosition", result);
return (NULL); return NULL;
} }
cursor /= this->spec.size; cursor /= this->spec.size;
#ifdef DEBUG_SOUND #ifdef DEBUG_SOUND
@@ -328,9 +328,9 @@ DSOUND_GetDeviceBuf(_THIS)
} }
if (result != DS_OK) { if (result != DS_OK) {
SetDSerror("DirectSound Lock", result); SetDSerror("DirectSound Lock", result);
return (NULL); return NULL;
} }
return (this->hidden->locked_buf); return this->hidden->locked_buf;
} }
static int static int
+1 -1
View File
@@ -65,7 +65,7 @@ DISKAUDIO_PlayDevice(_THIS)
static Uint8 * static Uint8 *
DISKAUDIO_GetDeviceBuf(_THIS) DISKAUDIO_GetDeviceBuf(_THIS)
{ {
return (_this->hidden->mixbuf); return _this->hidden->mixbuf;
} }
static int static int
+6 -5
View File
@@ -80,12 +80,13 @@ DSP_OpenDevice(_THIS, const char *devname)
/* Make sure fragment size stays a power of 2, or OSS fails. */ /* Make sure fragment size stays a power of 2, or OSS fails. */
/* I don't know which of these are actually legal values, though... */ /* I don't know which of these are actually legal values, though... */
if (this->spec.channels > 8) if (this->spec.channels > 8) {
this->spec.channels = 8; this->spec.channels = 8;
else if (this->spec.channels > 4) } else if (this->spec.channels > 4) {
this->spec.channels = 4; this->spec.channels = 4;
else if (this->spec.channels > 2) } else if (this->spec.channels > 2) {
this->spec.channels = 2; this->spec.channels = 2;
}
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *) this->hidden = (struct SDL_PrivateAudioData *)
@@ -258,13 +259,13 @@ DSP_PlayDevice(_THIS)
static Uint8 * static Uint8 *
DSP_GetDeviceBuf(_THIS) DSP_GetDeviceBuf(_THIS)
{ {
return (this->hidden->mixbuf); return this->hidden->mixbuf;
} }
static int static int
DSP_CaptureFromDevice(_THIS, void *buffer, int buflen) DSP_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
return (int) read(this->hidden->audio_fd, buffer, buflen); return (int)read(this->hidden->audio_fd, buffer, buflen);
} }
static void static void
+1 -1
View File
@@ -206,7 +206,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
/* create context */ /* create context */
result = MAIN_THREAD_EM_ASM_INT({ result = MAIN_THREAD_EM_ASM_INT({
if(typeof(Module['SDL3']) === 'undefined') { if (typeof(Module['SDL3']) === 'undefined') {
Module['SDL3'] = {}; Module['SDL3'] = {};
} }
var SDL3 = Module['SDL3']; var SDL3 = Module['SDL3'];
+1 -1
View File
@@ -310,7 +310,7 @@ JACK_OpenDevice(_THIS, const char *devname)
} }
devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags); devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags);
if (!devports || !devports[0]) { if (devports == NULL || !devports[0]) {
return SDL_SetError("No physical JACK ports available"); return SDL_SetError("No physical JACK ports available");
} }
+1 -1
View File
@@ -144,7 +144,7 @@ NETBSDAUDIO_PlayDevice(_THIS)
static Uint8 * static Uint8 *
NETBSDAUDIO_GetDeviceBuf(_THIS) NETBSDAUDIO_GetDeviceBuf(_THIS)
{ {
return (this->hidden->mixbuf); return this->hidden->mixbuf;
} }
+2 -2
View File
@@ -423,7 +423,7 @@ openslES_CreatePCMPlayer(_THIS)
it can be done as described here: it can be done as described here:
https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point https://developer.android.com/ndk/guides/audio/opensl/android-extensions.html#floating-point
*/ */
if(SDL_GetAndroidSDKVersion() >= 21) { if (SDL_GetAndroidSDKVersion() >= 21) {
SDL_AudioFormat test_format; SDL_AudioFormat test_format;
for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) { for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
if (SDL_AUDIO_ISSIGNED(test_format)) { if (SDL_AUDIO_ISSIGNED(test_format)) {
@@ -498,7 +498,7 @@ openslES_CreatePCMPlayer(_THIS)
break; break;
} }
if(SDL_AUDIO_ISFLOAT(this->spec.format)) { if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
/* Copy all setup into PCM EX structure */ /* Copy all setup into PCM EX structure */
format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX; format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
format_pcm_ex.endianness = format_pcm.endianness; format_pcm_ex.endianness = format_pcm.endianness;
+5 -5
View File
@@ -1062,7 +1062,7 @@ input_callback(void *data)
} }
pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream); pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
if (!pw_buf) { if (pw_buf == NULL) {
return; return;
} }
@@ -1186,15 +1186,15 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
/* Get the hints for the application name, stream name and role */ /* Get the hints for the application name, stream name and role */
app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME); app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
if (!app_name || *app_name == '\0') { if (app_name == NULL || *app_name == '\0') {
app_name = SDL_GetHint(SDL_HINT_APP_NAME); app_name = SDL_GetHint(SDL_HINT_APP_NAME);
if (!app_name || *app_name == '\0') { if (app_name == NULL || *app_name == '\0') {
app_name = "SDL Application"; app_name = "SDL Application";
} }
} }
stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME); stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME);
if (!stream_name || *stream_name == '\0') { if (stream_name == NULL || *stream_name == '\0') {
stream_name = "Audio Stream"; stream_name = "Audio Stream";
} }
@@ -1203,7 +1203,7 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
* but 'Game' seems more appropriate for the majority of SDL applications. * but 'Game' seems more appropriate for the majority of SDL applications.
*/ */
stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE); stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE);
if (!stream_role || *stream_role == '\0') { if (stream_role == NULL || *stream_role == '\0') {
stream_role = "Game"; stream_role = "Game";
} }
+2 -1
View File
@@ -154,8 +154,9 @@ static void PS2AUDIO_Deinitialize(void)
static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl * impl) static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl * impl)
{ {
if(init_audio_driver() < 0) if (init_audio_driver() < 0) {
return SDL_FALSE; return SDL_FALSE;
}
/* Set the function pointers */ /* Set the function pointers */
impl->OpenDevice = PS2AUDIO_OpenDevice; impl->OpenDevice = PS2AUDIO_OpenDevice;
+2 -2
View File
@@ -102,7 +102,7 @@ PSPAUDIO_OpenDevice(_THIS, const char *devname)
static void PSPAUDIO_PlayDevice(_THIS) static void PSPAUDIO_PlayDevice(_THIS)
{ {
if (this->spec.freq != 44100){ if (this->spec.freq != 44100) {
Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer]; Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
SDL_assert(this->spec.channels == 2); SDL_assert(this->spec.channels == 2);
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, mixbuf); sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, mixbuf);
@@ -128,7 +128,7 @@ static Uint8 *PSPAUDIO_GetDeviceBuf(_THIS)
static void PSPAUDIO_CloseDevice(_THIS) static void PSPAUDIO_CloseDevice(_THIS)
{ {
if (this->hidden->channel >= 0) { if (this->hidden->channel >= 0) {
if (this->spec.freq != 44100){ if (this->spec.freq != 44100) {
sceAudioSRCChRelease(); sceAudioSRCChRelease();
} else { } else {
sceAudioChRelease(this->hidden->channel); sceAudioChRelease(this->hidden->channel);
+4 -10
View File
@@ -49,17 +49,11 @@ static SDL_bool include_monitors = SDL_FALSE;
#if (PA_API_VERSION < 12) #if (PA_API_VERSION < 12)
/** Return non-zero if the passed state is one of the connected states */ /** Return non-zero if the passed state is one of the connected states */
static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x) { static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x) {
return return x == PA_CONTEXT_CONNECTING || x == PA_CONTEXT_AUTHORIZING || x == PA_CONTEXT_SETTING_NAME || x == PA_CONTEXT_READY;
x == PA_CONTEXT_CONNECTING ||
x == PA_CONTEXT_AUTHORIZING ||
x == PA_CONTEXT_SETTING_NAME ||
x == PA_CONTEXT_READY;
} }
/** Return non-zero if the passed state is one of the connected states */ /** Return non-zero if the passed state is one of the connected states */
static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) { static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
return return x == PA_STREAM_CREATING || x == PA_STREAM_READY;
x == PA_STREAM_CREATING ||
x == PA_STREAM_READY;
} }
#endif /* pulseaudio <= 0.9.10 */ #endif /* pulseaudio <= 0.9.10 */
@@ -308,7 +302,7 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
SDL_assert(mainloop_api); /* this never fails, right? */ SDL_assert(mainloop_api); /* this never fails, right? */
context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName()); context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
if (!context) { if (context == NULL) {
PULSEAUDIO_pa_mainloop_free(mainloop); PULSEAUDIO_pa_mainloop_free(mainloop);
return SDL_SetError("pa_context_new() failed"); return SDL_SetError("pa_context_new() failed");
} }
@@ -541,7 +535,7 @@ FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *h
SinkDeviceNameCallback, &h->device_name)); SinkDeviceNameCallback, &h->device_name));
} }
return (h->device_name != NULL); return h->device_name != NULL;
} }
static int static int
+2 -2
View File
@@ -78,7 +78,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
} }
} }
if(!test_format) { if (!test_format) {
return SDL_SetError("Unsupported audio format"); return SDL_SetError("Unsupported audio format");
} }
@@ -108,7 +108,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
format = SCE_AUDIO_OUT_MODE_STEREO; format = SCE_AUDIO_OUT_MODE_STEREO;
} }
if(this->spec.freq < 48000) { if (this->spec.freq < 48000) {
port = SCE_AUDIO_OUT_PORT_TYPE_BGM; port = SCE_AUDIO_OUT_PORT_TYPE_BGM;
} }
+2 -3
View File
@@ -387,8 +387,7 @@ WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
if (SDL_wcscmp(i->str, devid) == 0) { if (SDL_wcscmp(i->str, devid) == 0) {
if (prev) { if (prev) {
prev->next = next; prev->next = next;
} } else {
else {
deviceid_list = next; deviceid_list = next;
} }
SDL_RemoveAudioDevice(iscapture, i->str); SDL_RemoveAudioDevice(iscapture, i->str);
@@ -419,7 +418,7 @@ WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTENS
} }
devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist)); devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist));
if (!devidlist) { if (devidlist == NULL) {
return; /* oh well. */ return; /* oh well. */
} }
+11 -16
View File
@@ -727,7 +727,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
library_file = (*env)->GetStringUTFChars(env, library, NULL); library_file = (*env)->GetStringUTFChars(env, library, NULL);
library_handle = dlopen(library_file, RTLD_GLOBAL); library_handle = dlopen(library_file, RTLD_GLOBAL);
if (!library_handle) { if (library_handle == NULL) {
/* When deploying android app bundle format uncompressed native libs may not extract from apk to filesystem. /* When deploying android app bundle format uncompressed native libs may not extract from apk to filesystem.
In this case we should use lib name without path. https://bugzilla.libsdl.org/show_bug.cgi?id=4739 */ In this case we should use lib name without path. https://bugzilla.libsdl.org/show_bug.cgi?id=4739 */
const char *library_name = SDL_strrchr(library_file, '/'); const char *library_name = SDL_strrchr(library_file, '/');
@@ -770,7 +770,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
} }
(*env)->DeleteLocalRef(env, string); (*env)->DeleteLocalRef(env, string);
} }
if (!arg) { if (arg == NULL) {
arg = SDL_strdup(""); arg = SDL_strdup("");
} }
argv[argc++] = arg; argv[argc++] = arg;
@@ -867,8 +867,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
{ {
SDL_LockMutex(Android_ActivityMutex); SDL_LockMutex(Android_ActivityMutex);
if (Android_Window) if (Android_Window) {
{
Android_SendResize(Android_Window); Android_SendResize(Android_Window);
} }
@@ -883,8 +882,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
displayOrientation = (SDL_DisplayOrientation)orientation; displayOrientation = (SDL_DisplayOrientation)orientation;
if (Android_Window) if (Android_Window) {
{
SDL_VideoDisplay *display = SDL_GetDisplay(0); SDL_VideoDisplay *display = SDL_GetDisplay(0);
SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation); SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
} }
@@ -993,8 +991,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, j
{ {
SDL_LockMutex(Android_ActivityMutex); SDL_LockMutex(Android_ActivityMutex);
if (Android_Window) if (Android_Window) {
{
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata; SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
data->native_window = Android_JNI_GetNativeWindow(); data->native_window = Android_JNI_GetNativeWindow();
@@ -1012,8 +1009,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j
SDL_LockMutex(Android_ActivityMutex); SDL_LockMutex(Android_ActivityMutex);
#if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_EGL
if (Android_Window) if (Android_Window) {
{
SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata; SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
@@ -1038,8 +1034,7 @@ retry:
SDL_LockMutex(Android_ActivityMutex); SDL_LockMutex(Android_ActivityMutex);
if (Android_Window) if (Android_Window) {
{
SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata; SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
@@ -1873,7 +1868,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
if (result > 0) { if (result > 0) {
/* Number of chuncks */ /* Number of chuncks */
return (result / size); return result / size;
} else { } else {
/* Error or EOF */ /* Error or EOF */
return result; return result;
@@ -2258,7 +2253,7 @@ void *SDL_AndroidGetActivity(void)
/* See SDL_system.h for caveats on using this function. */ /* See SDL_system.h for caveats on using this function. */
JNIEnv *env = Android_JNI_GetEnv(); JNIEnv *env = Android_JNI_GetEnv();
if (!env) { if (env == NULL) {
return NULL; return NULL;
} }
@@ -2312,7 +2307,7 @@ const char * SDL_AndroidGetInternalStoragePath(void)
{ {
static char *s_AndroidInternalFilesPath = NULL; static char *s_AndroidInternalFilesPath = NULL;
if (!s_AndroidInternalFilesPath) { if (s_AndroidInternalFilesPath == NULL) {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
jmethodID mid; jmethodID mid;
jobject context; jobject context;
@@ -2405,7 +2400,7 @@ const char * SDL_AndroidGetExternalStoragePath(void)
{ {
static char *s_AndroidExternalFilesPath = NULL; static char *s_AndroidExternalFilesPath = NULL;
if (!s_AndroidExternalFilesPath) { if (s_AndroidExternalFilesPath == NULL) {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
jmethodID mid; jmethodID mid;
jobject context; jobject context;
+66 -45
View File
@@ -67,7 +67,7 @@ struct SDL_EVDEV_keyboard_state
static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd) static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd)
{ {
return (ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0); return ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0;
} }
static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL; static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL;
@@ -95,7 +95,9 @@ static void kbd_cleanup(void)
SDL_zero(mData); SDL_zero(mData);
mData.operation = MOUSE_SHOW; mData.operation = MOUSE_SHOW;
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode); ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
if (kbd->keyboard_fd != kbd->console_fd) close(kbd->keyboard_fd); if (kbd->keyboard_fd != kbd->console_fd) {
close(kbd->keyboard_fd);
}
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index)); ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
ioctl(kbd->console_fd, CONS_MOUSECTL, &mData); ioctl(kbd->console_fd, CONS_MOUSECTL, &mData);
} }
@@ -151,13 +153,14 @@ static void kbd_unregister_emerg_cleanup()
old_action_p = &(old_sigaction[signum]); old_action_p = &(old_sigaction[signum]);
/* Examine current signal action */ /* Examine current signal action */
if (sigaction(signum, NULL, &cur_action)) if (sigaction(signum, NULL, &cur_action)) {
continue; continue;
}
/* Check if action installed and not modifed */ /* Check if action installed and not modifed */
if (!(cur_action.sa_flags & SA_SIGINFO) if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
|| cur_action.sa_sigaction != &kbd_cleanup_signal_action)
continue; continue;
}
/* Restore original action */ /* Restore original action */
sigaction(signum, old_action_p, NULL); sigaction(signum, old_action_p, NULL);
@@ -201,16 +204,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
struct sigaction new_action; struct sigaction new_action;
signum = fatal_signals[tabidx]; signum = fatal_signals[tabidx];
old_action_p = &(old_sigaction[signum]); old_action_p = &(old_sigaction[signum]);
if (sigaction(signum, NULL, old_action_p)) if (sigaction(signum, NULL, old_action_p)) {
continue; continue;
}
/* Skip SIGHUP and SIGPIPE if handler is already installed /* Skip SIGHUP and SIGPIPE if handler is already installed
* - assume the handler will do the cleanup * - assume the handler will do the cleanup
*/ */
if ((signum == SIGHUP || signum == SIGPIPE) if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
&& (old_action_p->sa_handler != SIG_DFL
|| (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
continue; continue;
}
new_action = *old_action_p; new_action = *old_action_p;
new_action.sa_flags |= SA_SIGINFO; new_action.sa_flags |= SA_SIGINFO;
@@ -230,7 +233,7 @@ SDL_EVDEV_kbd_init(void)
SDL_zero(mData); SDL_zero(mData);
mData.operation = MOUSE_HIDE; mData.operation = MOUSE_HIDE;
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state)); kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
if (!kbd) { if (kbd == NULL) {
return NULL; return NULL;
} }
@@ -252,8 +255,7 @@ SDL_EVDEV_kbd_init(void)
kbd->ledflagstate = flag_state; kbd->ledflagstate = flag_state;
} }
if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) if (ioctl(kbd->console_fd, GIO_DEADKEYMAP, kbd->accents) < 0) {
{
SDL_free(kbd->accents); SDL_free(kbd->accents);
kbd->accents = &accentmap_default_us_acc; kbd->accents = &accentmap_default_us_acc;
} }
@@ -261,8 +263,7 @@ SDL_EVDEV_kbd_init(void)
if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) { if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
/* Set the keyboard in XLATE mode and load the keymaps */ /* Set the keyboard in XLATE mode and load the keymaps */
ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE)); ioctl(kbd->console_fd, KDSKBMODE, (unsigned long)(K_XLATE));
if(!SDL_EVDEV_kbd_load_keymaps(kbd)) if (!SDL_EVDEV_kbd_load_keymaps(kbd)) {
{
SDL_free(kbd->key_map); SDL_free(kbd->key_map);
kbd->key_map = &keymap_default_us_acc; kbd->key_map = &keymap_default_us_acc;
} }
@@ -274,8 +275,7 @@ SDL_EVDEV_kbd_init(void)
ioctl(kbd->console_fd, CONS_RELKBD, 1ul); ioctl(kbd->console_fd, CONS_RELKBD, 1ul);
SDL_asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index); SDL_asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index);
kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC); kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC);
if (kbd->keyboard_fd == -1) if (kbd->keyboard_fd == -1) {
{
// Give keyboard back. // Give keyboard back.
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index)); ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
kbd->keyboard_fd = kbd->console_fd; kbd->keyboard_fd = kbd->console_fd;
@@ -288,8 +288,7 @@ SDL_EVDEV_kbd_init(void)
kbd_register_emerg_cleanup(kbd); kbd_register_emerg_cleanup(kbd);
} }
SDL_free(devicePath); SDL_free(devicePath);
} } else kbd->keyboard_fd = kbd->console_fd;
else kbd->keyboard_fd = kbd->console_fd;
} }
return kbd; return kbd;
@@ -300,7 +299,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{ {
struct mouse_info mData; struct mouse_info mData;
if (!kbd) { if (kbd == NULL) {
return; return;
} }
SDL_zero(mData); SDL_zero(mData);
@@ -314,8 +313,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode); ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
close(kbd->keyboard_fd); close(kbd->keyboard_fd);
if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) if (kbd->console_fd != kbd->keyboard_fd && kbd->console_fd >= 0) {
{
// Give back keyboard. // Give back keyboard.
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index)); ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
} }
@@ -346,10 +344,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
put_queue(kbd, 0xc0 | (c >> 6)); put_queue(kbd, 0xc0 | (c >> 6));
put_queue(kbd, 0x80 | (c & 0x3f)); put_queue(kbd, 0x80 | (c & 0x3f));
} else if (c < 0x10000) { } else if (c < 0x10000) {
if (c >= 0xD800 && c < 0xE000) if (c >= 0xD800 && c < 0xE000) {
return; return;
if (c == 0xFFFF) }
if (c == 0xFFFF) {
return; return;
}
/* 1110**** 10****** 10****** */ /* 1110**** 10****** 10****** */
put_queue(kbd, 0xe0 | (c >> 12)); put_queue(kbd, 0xe0 | (c >> 12));
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f)); put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
@@ -378,13 +378,14 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
kbd->diacr = 0; kbd->diacr = 0;
for (i = 0; i < kbd->accents->n_accs; i++) { for (i = 0; i < kbd->accents->n_accs; i++) {
if (kbd->accents->acc[i].accchar == d) if (kbd->accents->acc[i].accchar == d) {
{
for (j = 0; j < NUM_ACCENTCHARS; ++j) { for (j = 0; j < NUM_ACCENTCHARS; ++j) {
if (kbd->accents->acc[i].map[j][0] == 0) /* end of table */ if (kbd->accents->acc[i].map[j][0] == 0) { /* end of table */
break; break;
if (kbd->accents->acc[i].map[j][0] == ch) }
if (kbd->accents->acc[i].map[j][0] == ch) {
return kbd->accents->acc[i].map[j][1]; return kbd->accents->acc[i].map[j][1];
}
} }
} }
} }
@@ -415,11 +416,13 @@ static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag) static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag)
{ {
if (up_flag) if (up_flag) {
return; /* no action, if this is a key release */ return; /* no action, if this is a key release */
}
if (kbd->diacr) if (kbd->diacr) {
value = handle_diacr(kbd, value); value = handle_diacr(kbd, value);
}
if (kbd->dead_key_next) { if (kbd->dead_key_next) {
kbd->dead_key_next = SDL_FALSE; kbd->dead_key_next = SDL_FALSE;
@@ -449,8 +452,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
* handle the case that two shift or control * handle the case that two shift or control
* keys are depressed simultaneously * keys are depressed simultaneously
*/ */
if (kbd->shift_down[value]) if (kbd->shift_down[value]) {
kbd->shift_down[value]--; kbd->shift_down[value]--;
}
} else } else
kbd->shift_down[value]++; kbd->shift_down[value]++;
@@ -476,7 +480,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
key_map = *kbd->key_map; key_map = *kbd->key_map;
if (!kbd) { if (kbd == NULL) {
return; return;
} }
@@ -487,10 +491,10 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
/* These constitute unprintable language-related keys, so ignore them. */ /* These constitute unprintable language-related keys, so ignore them. */
return; return;
} }
if (keycode > 95) if (keycode > 95) {
keycode -= 7; keycode -= 7;
if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8)) }
{ if (vc_kbd_led(kbd, ALKED) || (kbd->shift_state & 0x8)) {
keycode += ALTGR_OFFSET; keycode += ALTGR_OFFSET;
} }
keysym = key_map.key[keycode]; keysym = key_map.key[keycode];
@@ -499,18 +503,21 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
} }
final_key_state = kbd->shift_state & 0x7; final_key_state = kbd->shift_state & 0x7;
if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP)) if ((keysym.flgs & FLAG_LOCK_C) && vc_kbd_led(kbd, LED_CAP)) {
final_key_state ^= 0x1; final_key_state ^= 0x1;
if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM)) }
if ((keysym.flgs & FLAG_LOCK_N) && vc_kbd_led(kbd, LED_NUM)) {
final_key_state ^= 0x1; final_key_state ^= 0x1;
}
map_from_key_sym = keysym.map[final_key_state]; map_from_key_sym = keysym.map[final_key_state];
if ((keysym.spcl & (0x80 >> final_key_state)) || (map_from_key_sym & SPCLKEY)) { if ((keysym.spcl & (0x80 >> final_key_state)) || (map_from_key_sym & SPCLKEY)) {
/* Special function.*/ /* Special function.*/
if (map_from_key_sym == 0) if (map_from_key_sym == 0)
return; /* Nothing to do. */ return; /* Nothing to do. */
if (map_from_key_sym & SPCLKEY) if (map_from_key_sym & SPCLKEY) {
map_from_key_sym &= ~SPCLKEY; map_from_key_sym &= ~SPCLKEY;
}
if (map_from_key_sym >= F_ACC && map_from_key_sym <= L_ACC) { if (map_from_key_sym >= F_ACC && map_from_key_sym <= L_ACC) {
/* Accent function.*/ /* Accent function.*/
unsigned int accent_index = map_from_key_sym - F_ACC; unsigned int accent_index = map_from_key_sym - F_ACC;
@@ -524,36 +531,50 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
break; break;
case LSHA: /* left shift + alt lock */ case LSHA: /* left shift + alt lock */
case RSHA: /* right shift + alt lock */ case RSHA: /* right shift + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED); if (down == 0) {
chg_vc_kbd_led(kbd, ALKED);
}
case LSH: /* left shift */ case LSH: /* left shift */
case RSH: /* right shift */ case RSH: /* right shift */
k_shift(kbd, 0, down == 0); k_shift(kbd, 0, down == 0);
break; break;
case LCTRA: /* left ctrl + alt lock */ case LCTRA: /* left ctrl + alt lock */
case RCTRA: /* right ctrl + alt lock */ case RCTRA: /* right ctrl + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED); if (down == 0) {
chg_vc_kbd_led(kbd, ALKED);
}
case LCTR: /* left ctrl */ case LCTR: /* left ctrl */
case RCTR: /* right ctrl */ case RCTR: /* right ctrl */
k_shift(kbd, 1, down == 0); k_shift(kbd, 1, down == 0);
break; break;
case LALTA: /* left alt + alt lock */ case LALTA: /* left alt + alt lock */
case RALTA: /* right alt + alt lock */ case RALTA: /* right alt + alt lock */
if (down == 0) chg_vc_kbd_led(kbd, ALKED); if (down == 0) {
chg_vc_kbd_led(kbd, ALKED);
}
case LALT: /* left alt */ case LALT: /* left alt */
case RALT: /* right alt */ case RALT: /* right alt */
k_shift(kbd, 2, down == 0); k_shift(kbd, 2, down == 0);
break; break;
case ALK: /* alt lock */ case ALK: /* alt lock */
if (down == 1) chg_vc_kbd_led(kbd, ALKED); if (down == 1) {
chg_vc_kbd_led(kbd, ALKED);
}
break; break;
case CLK: /* caps lock*/ case CLK: /* caps lock*/
if (down == 1) chg_vc_kbd_led(kbd, CLKED); if (down == 1) {
chg_vc_kbd_led(kbd, CLKED);
}
break; break;
case NLK: /* num lock */ case NLK: /* num lock */
if (down == 1) chg_vc_kbd_led(kbd, NLKED); if (down == 1) {
chg_vc_kbd_led(kbd, NLKED);
}
break; break;
case SLK: /* scroll lock */ case SLK: /* scroll lock */
if (down == 1) chg_vc_kbd_led(kbd, SLKED); if (down == 1) {
chg_vc_kbd_led(kbd, SLKED);
}
break; break;
default: default:
return; return;
+2 -2
View File
@@ -105,13 +105,13 @@ SDL_GDKRunApp(SDL_main_func mainFunction, void *reserved)
/* Parse it into argv and argc */ /* Parse it into argv and argc */
argv = (char **) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv)); argv = (char **) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv));
if (!argv) { if (argv == NULL) {
return OutOfMemory(); return OutOfMemory();
} }
for (i = 0; i < argc; ++i) { for (i = 0; i < argc; ++i) {
DWORD len; DWORD len;
char *arg = WIN_StringToUTF8W(argvw[i]); char *arg = WIN_StringToUTF8W(argvw[i]);
if (!arg) { if (arg == NULL) {
return OutOfMemory(); return OutOfMemory();
} }
len = (DWORD) SDL_strlen(arg); len = (DWORD) SDL_strlen(arg);
+15 -10
View File
@@ -198,7 +198,7 @@ SDL_DBus_Quit(void)
SDL_DBusContext * SDL_DBusContext *
SDL_DBus_GetContext(void) SDL_DBus_GetContext(void)
{ {
if (!dbus_handle || !dbus.session_conn) { if (dbus_handle == NULL || !dbus.session_conn) {
SDL_DBus_Init(); SDL_DBus_Init();
} }
@@ -376,20 +376,25 @@ SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, cons
{ {
DBusMessageIter iterDict, iterEntry, iterValue; DBusMessageIter iterDict, iterEntry, iterValue;
if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict)) if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict)) {
goto failed; goto failed;
}
if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) {
goto failed; goto failed;
}
if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) {
goto failed; goto failed;
}
if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) {
goto failed; goto failed;
}
if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) {
goto failed; goto failed;
}
if (!dbus.message_iter_close_container(&iterEntry, &iterValue) if (!dbus.message_iter_close_container(&iterEntry, &iterValue)
|| !dbus.message_iter_close_container(&iterDict, &iterEntry) || !dbus.message_iter_close_container(&iterDict, &iterEntry)
@@ -436,12 +441,12 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
const char *key = "reason"; const char *key = "reason";
const char *reply = NULL; const char *reply = NULL;
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME); const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (!reason || !reason[0]) { if (reason == NULL || !reason[0]) {
reason = default_inhibit_reason; reason = default_inhibit_reason;
} }
msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit"); msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit");
if (!msg) { if (msg == NULL) {
return SDL_FALSE; return SDL_FALSE;
} }
@@ -478,10 +483,10 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
if (inhibit) { if (inhibit) {
const char *app = SDL_GetHint(SDL_HINT_APP_NAME); const char *app = SDL_GetHint(SDL_HINT_APP_NAME);
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME); const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
if (!app || !app[0]) { if (app == NULL || !app[0]) {
app = "My SDL application"; app = "My SDL application";
} }
if (!reason || !reason[0]) { if (reason == NULL || !reason[0]) {
reason = default_inhibit_reason; reason = default_inhibit_reason;
} }
+50 -30
View File
@@ -188,11 +188,11 @@ SDL_EVDEV_Init(void)
while ((spec = SDL_strtokr(rest, ",", &rest))) { while ((spec = SDL_strtokr(rest, ",", &rest))) {
char* endofcls = 0; char* endofcls = 0;
long cls = SDL_strtol(spec, &endofcls, 0); long cls = SDL_strtol(spec, &endofcls, 0);
if (endofcls) if (endofcls) {
SDL_EVDEV_device_added(endofcls + 1, cls); SDL_EVDEV_device_added(endofcls + 1, cls);
}
} }
} } else {
else {
/* TODO: Scan the devices manually, like a caveman */ /* TODO: Scan the devices manually, like a caveman */
} }
} }
@@ -226,7 +226,7 @@ SDL_EVDEV_Quit(void)
SDL_EVDEV_kbd_quit(_this->kbd); SDL_EVDEV_kbd_quit(_this->kbd);
/* Remove existing devices */ /* Remove existing devices */
while(_this->first != NULL) { while (_this->first != NULL) {
SDL_EVDEV_device_removed(_this->first->path); SDL_EVDEV_device_removed(_this->first->path);
} }
@@ -249,11 +249,13 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
switch(udev_event) { switch(udev_event) {
case SDL_UDEV_DEVICEADDED: case SDL_UDEV_DEVICEADDED:
if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD))) if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD))) {
return; return;
}
if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK)) if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
return; return;
}
SDL_EVDEV_device_added(dev_path, udev_class); SDL_EVDEV_device_added(dev_path, udev_class);
break; break;
@@ -338,13 +340,15 @@ SDL_EVDEV_Poll(void)
case EV_ABS: case EV_ABS:
switch(events[i].code) { switch(events[i].code) {
case ABS_MT_SLOT: case ABS_MT_SLOT:
if (!item->is_touchscreen) /* FIXME: temp hack */ if (!item->is_touchscreen) { /* FIXME: temp hack */
break; break;
}
item->touchscreen_data->current_slot = events[i].value; item->touchscreen_data->current_slot = events[i].value;
break; break;
case ABS_MT_TRACKING_ID: case ABS_MT_TRACKING_ID:
if (!item->is_touchscreen) /* FIXME: temp hack */ if (!item->is_touchscreen) { /* FIXME: temp hack */
break; break;
}
if (events[i].value >= 0) { if (events[i].value >= 0) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value; item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value;
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN; item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
@@ -353,24 +357,27 @@ SDL_EVDEV_Poll(void)
} }
break; break;
case ABS_MT_POSITION_X: case ABS_MT_POSITION_X:
if (!item->is_touchscreen) /* FIXME: temp hack */ if (!item->is_touchscreen) { /* FIXME: temp hack */
break; break;
}
item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value; item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value;
if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
} }
break; break;
case ABS_MT_POSITION_Y: case ABS_MT_POSITION_Y:
if (!item->is_touchscreen) /* FIXME: temp hack */ if (!item->is_touchscreen) { /* FIXME: temp hack */
break; break;
}
item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value; item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value;
if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
} }
break; break;
case ABS_MT_PRESSURE: case ABS_MT_PRESSURE:
if (!item->is_touchscreen) /* FIXME: temp hack */ if (!item->is_touchscreen) { /* FIXME: temp hack */
break; break;
}
item->touchscreen_data->slots[item->touchscreen_data->current_slot].pressure = events[i].value; item->touchscreen_data->slots[item->touchscreen_data->current_slot].pressure = events[i].value;
if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) { if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE; item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
@@ -378,8 +385,9 @@ SDL_EVDEV_Poll(void)
break; break;
case ABS_X: case ABS_X:
if (item->is_touchscreen) { if (item->is_touchscreen) {
if (item->touchscreen_data->max_slots != 1) if (item->touchscreen_data->max_slots != 1) {
break; break;
}
item->touchscreen_data->slots[0].x = events[i].value; item->touchscreen_data->slots[0].x = events[i].value;
} else if (!item->relative_mouse) { } else if (!item->relative_mouse) {
/* FIXME: Normalize to input device's reported input range (EVIOCGABS) */ /* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
@@ -388,8 +396,9 @@ SDL_EVDEV_Poll(void)
break; break;
case ABS_Y: case ABS_Y:
if (item->is_touchscreen) { if (item->is_touchscreen) {
if (item->touchscreen_data->max_slots != 1) if (item->touchscreen_data->max_slots != 1) {
break; break;
}
item->touchscreen_data->slots[0].y = events[i].value; item->touchscreen_data->slots[0].y = events[i].value;
} else if (!item->relative_mouse) { } else if (!item->relative_mouse) {
/* FIXME: Normalize to input device's reported input range (EVIOCGABS) */ /* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
@@ -403,24 +412,28 @@ SDL_EVDEV_Poll(void)
case EV_REL: case EV_REL:
switch(events[i].code) { switch(events[i].code) {
case REL_X: case REL_X:
if (item->relative_mouse) if (item->relative_mouse) {
item->mouse_x += events[i].value; item->mouse_x += events[i].value;
}
break; break;
case REL_Y: case REL_Y:
if (item->relative_mouse) if (item->relative_mouse) {
item->mouse_y += events[i].value; item->mouse_y += events[i].value;
}
break; break;
case REL_WHEEL: case REL_WHEEL:
if (!item->high_res_wheel) if (!item->high_res_wheel) {
item->mouse_wheel += events[i].value; item->mouse_wheel += events[i].value;
}
break; break;
case REL_WHEEL_HI_RES: case REL_WHEEL_HI_RES:
SDL_assert(item->high_res_wheel); SDL_assert(item->high_res_wheel);
item->mouse_wheel += events[i].value; item->mouse_wheel += events[i].value;
break; break;
case REL_HWHEEL: case REL_HWHEEL:
if (!item->high_res_hwheel) if (!item->high_res_hwheel) {
item->mouse_hwheel += events[i].value; item->mouse_hwheel += events[i].value;
}
break; break;
case REL_HWHEEL_HI_RES: case REL_HWHEEL_HI_RES:
SDL_assert(item->high_res_hwheel); SDL_assert(item->high_res_hwheel);
@@ -446,10 +459,11 @@ SDL_EVDEV_Poll(void)
item->mouse_wheel = item->mouse_hwheel = 0; item->mouse_wheel = item->mouse_hwheel = 0;
} }
if (!item->is_touchscreen) /* FIXME: temp hack */ if (!item->is_touchscreen) { /* FIXME: temp hack */
break; break;
}
for(j = 0; j < item->touchscreen_data->max_slots; j++) { for (j = 0; j < item->touchscreen_data->max_slots; j++) {
norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) / norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) /
(float)item->touchscreen_data->range_x; (float)item->touchscreen_data->range_x;
norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) / norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
@@ -485,12 +499,14 @@ SDL_EVDEV_Poll(void)
} }
} }
if (item->out_of_sync) if (item->out_of_sync) {
item->out_of_sync = SDL_FALSE; item->out_of_sync = SDL_FALSE;
}
break; break;
case SYN_DROPPED: case SYN_DROPPED:
if (item->is_touchscreen) if (item->is_touchscreen) {
item->out_of_sync = SDL_TRUE; item->out_of_sync = SDL_TRUE;
}
SDL_EVDEV_sync_device(item); SDL_EVDEV_sync_device(item);
break; break;
default: default:
@@ -533,12 +549,14 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
char name[64]; char name[64];
struct input_absinfo abs_info; struct input_absinfo abs_info;
if (!item->is_touchscreen) if (!item->is_touchscreen) {
return 0; return 0;
}
item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data)); item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
if (item->touchscreen_data == NULL) if (item->touchscreen_data == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
}
ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name); ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
if (ret < 0) { if (ret < 0) {
@@ -608,7 +626,7 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
for(i = 0; i < item->touchscreen_data->max_slots; i++) { for (i = 0; i < item->touchscreen_data->max_slots; i++) {
item->touchscreen_data->slots[i].tracking_id = -1; item->touchscreen_data->slots[i].tracking_id = -1;
} }
@@ -627,8 +645,9 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
static void static void
SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) { SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
if (!item->is_touchscreen) if (!item->is_touchscreen) {
return; return;
}
SDL_DelTouch(item->fd); SDL_DelTouch(item->fd);
SDL_free(item->touchscreen_data->slots); SDL_free(item->touchscreen_data->slots);
@@ -655,8 +674,9 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
size_t mt_req_size; size_t mt_req_size;
/* TODO: sync devices other than touchscreen */ /* TODO: sync devices other than touchscreen */
if (!item->is_touchscreen) if (!item->is_touchscreen) {
return; return;
}
mt_req_size = sizeof(*mt_req_code) + mt_req_size = sizeof(*mt_req_code) +
sizeof(*mt_req_values) * item->touchscreen_data->max_slots; sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
@@ -674,7 +694,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code); SDL_free(mt_req_code);
return; return;
} }
for(i = 0; i < item->touchscreen_data->max_slots; i++) { for (i = 0; i < item->touchscreen_data->max_slots; i++) {
/* /*
* This doesn't account for the very edge case of the user removing their * This doesn't account for the very edge case of the user removing their
* finger and replacing it on the screen during the time we're out of sync, * finger and replacing it on the screen during the time we're out of sync,
@@ -701,7 +721,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code); SDL_free(mt_req_code);
return; return;
} }
for(i = 0; i < item->touchscreen_data->max_slots; i++) { for (i = 0; i < item->touchscreen_data->max_slots; i++) {
if (item->touchscreen_data->slots[i].tracking_id >= 0 && if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
item->touchscreen_data->slots[i].x != mt_req_values[i]) { item->touchscreen_data->slots[i].x != mt_req_values[i]) {
item->touchscreen_data->slots[i].x = mt_req_values[i]; item->touchscreen_data->slots[i].x = mt_req_values[i];
@@ -719,7 +739,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code); SDL_free(mt_req_code);
return; return;
} }
for(i = 0; i < item->touchscreen_data->max_slots; i++) { for (i = 0; i < item->touchscreen_data->max_slots; i++) {
if (item->touchscreen_data->slots[i].tracking_id >= 0 && if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
item->touchscreen_data->slots[i].y != mt_req_values[i]) { item->touchscreen_data->slots[i].y != mt_req_values[i]) {
item->touchscreen_data->slots[i].y = mt_req_values[i]; item->touchscreen_data->slots[i].y = mt_req_values[i];
@@ -737,7 +757,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
SDL_free(mt_req_code); SDL_free(mt_req_code);
return; return;
} }
for(i = 0; i < item->touchscreen_data->max_slots; i++) { for (i = 0; i < item->touchscreen_data->max_slots; i++) {
if (item->touchscreen_data->slots[i].tracking_id >= 0 && if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
item->touchscreen_data->slots[i].pressure != mt_req_values[i]) { item->touchscreen_data->slots[i].pressure != mt_req_values[i]) {
item->touchscreen_data->slots[i].pressure = mt_req_values[i]; item->touchscreen_data->slots[i].pressure = mt_req_values[i];
+2 -1
View File
@@ -138,8 +138,9 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
/* the first 32 bits are ESC, numbers, and Q to D; if we have any of /* the first 32 bits are ESC, numbers, and Q to D; if we have any of
* those, consider it a keyboard device; do not test KEY_RESERVED, though */ * those, consider it a keyboard device; do not test KEY_RESERVED, though */
keyboard_mask = 0xFFFFFFFE; keyboard_mask = 0xFFFFFFFE;
if ((bitmask_key[0] & keyboard_mask) != 0) if ((bitmask_key[0] & keyboard_mask) != 0) {
devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */ devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */
}
return devclass; return devclass;
} }
+39 -25
View File
@@ -269,13 +269,14 @@ static void kbd_unregister_emerg_cleanup()
old_action_p = &(old_sigaction[signum]); old_action_p = &(old_sigaction[signum]);
/* Examine current signal action */ /* Examine current signal action */
if (sigaction(signum, NULL, &cur_action)) if (sigaction(signum, NULL, &cur_action)) {
continue; continue;
}
/* Check if action installed and not modifed */ /* Check if action installed and not modifed */
if (!(cur_action.sa_flags & SA_SIGINFO) if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
|| cur_action.sa_sigaction != &kbd_cleanup_signal_action)
continue; continue;
}
/* Restore original action */ /* Restore original action */
sigaction(signum, old_action_p, NULL); sigaction(signum, old_action_p, NULL);
@@ -319,16 +320,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
struct sigaction new_action; struct sigaction new_action;
signum = fatal_signals[tabidx]; signum = fatal_signals[tabidx];
old_action_p = &(old_sigaction[signum]); old_action_p = &(old_sigaction[signum]);
if (sigaction(signum, NULL, old_action_p)) if (sigaction(signum, NULL, old_action_p)) {
continue; continue;
}
/* Skip SIGHUP and SIGPIPE if handler is already installed /* Skip SIGHUP and SIGPIPE if handler is already installed
* - assume the handler will do the cleanup * - assume the handler will do the cleanup
*/ */
if ((signum == SIGHUP || signum == SIGPIPE) if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
&& (old_action_p->sa_handler != SIG_DFL
|| (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
continue; continue;
}
new_action = *old_action_p; new_action = *old_action_p;
new_action.sa_flags |= SA_SIGINFO; new_action.sa_flags |= SA_SIGINFO;
@@ -346,7 +347,7 @@ SDL_EVDEV_kbd_init(void)
char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0}; char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0};
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd)); kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
if (!kbd) { if (kbd == NULL) {
return NULL; return NULL;
} }
@@ -412,7 +413,7 @@ SDL_EVDEV_kbd_init(void)
void void
SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
{ {
if (!kbd) { if (kbd == NULL) {
return; return;
} }
@@ -460,10 +461,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
put_queue(kbd, 0xc0 | (c >> 6)); put_queue(kbd, 0xc0 | (c >> 6));
put_queue(kbd, 0x80 | (c & 0x3f)); put_queue(kbd, 0x80 | (c & 0x3f));
} else if (c < 0x10000) { } else if (c < 0x10000) {
if (c >= 0xD800 && c < 0xE000) if (c >= 0xD800 && c < 0xE000) {
return; return;
if (c == 0xFFFF) }
if (c == 0xFFFF) {
return; return;
}
/* 1110**** 10****** 10****** */ /* 1110**** 10****** 10****** */
put_queue(kbd, 0xe0 | (c >> 12)); put_queue(kbd, 0xe0 | (c >> 12));
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f)); put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
@@ -498,8 +501,9 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
} }
} }
if (ch == ' ' || ch == d) if (ch == ' ' || ch == d) {
return d; return d;
}
put_utf8(kbd, d); put_utf8(kbd, d);
@@ -553,24 +557,27 @@ static void fn_enter(SDL_EVDEV_keyboard_state *kbd)
static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd) static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd)
{ {
if (kbd->rep) if (kbd->rep) {
return; return;
}
chg_vc_kbd_led(kbd, K_CAPSLOCK); chg_vc_kbd_led(kbd, K_CAPSLOCK);
} }
static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd) static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd)
{ {
if (kbd->rep) if (kbd->rep) {
return; return;
}
set_vc_kbd_led(kbd, K_CAPSLOCK); set_vc_kbd_led(kbd, K_CAPSLOCK);
} }
static void fn_num(SDL_EVDEV_keyboard_state *kbd) static void fn_num(SDL_EVDEV_keyboard_state *kbd)
{ {
if (!kbd->rep) if (!kbd->rep) {
chg_vc_kbd_led(kbd, K_NUMLOCK); chg_vc_kbd_led(kbd, K_NUMLOCK);
}
} }
static void fn_compose(SDL_EVDEV_keyboard_state *kbd) static void fn_compose(SDL_EVDEV_keyboard_state *kbd)
@@ -588,12 +595,15 @@ static void k_ignore(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up
static void k_spec(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) static void k_spec(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
{ {
if (up_flag) if (up_flag) {
return; return;
if (value >= SDL_arraysize(fn_handler)) }
if (value >= SDL_arraysize(fn_handler)) {
return; return;
if (fn_handler[value]) }
if (fn_handler[value]) {
fn_handler[value](kbd); fn_handler[value](kbd);
}
} }
static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
@@ -602,11 +612,13 @@ static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char
static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
{ {
if (up_flag) if (up_flag) {
return; /* no action, if this is a key release */ return; /* no action, if this is a key release */
}
if (kbd->diacr) if (kbd->diacr) {
value = handle_diacr(kbd, value); value = handle_diacr(kbd, value);
}
if (kbd->dead_key_next) { if (kbd->dead_key_next) {
kbd->dead_key_next = SDL_FALSE; kbd->dead_key_next = SDL_FALSE;
@@ -675,8 +687,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
*/ */
if (value == KVAL(K_CAPSSHIFT)) { if (value == KVAL(K_CAPSSHIFT)) {
value = KVAL(K_SHIFT); value = KVAL(K_SHIFT);
if (!up_flag) if (!up_flag) {
clr_vc_kbd_led(kbd, K_CAPSLOCK); clr_vc_kbd_led(kbd, K_CAPSLOCK);
}
} }
if (up_flag) { if (up_flag) {
@@ -684,8 +697,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
* handle the case that two shift or control * handle the case that two shift or control
* keys are depressed simultaneously * keys are depressed simultaneously
*/ */
if (kbd->shift_down[value]) if (kbd->shift_down[value]) {
kbd->shift_down[value]--; kbd->shift_down[value]--;
}
} else } else
kbd->shift_down[value]++; kbd->shift_down[value]++;
@@ -761,7 +775,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
unsigned short *key_map; unsigned short *key_map;
unsigned short keysym; unsigned short keysym;
if (!kbd) { if (kbd == NULL) {
return; return;
} }
@@ -769,7 +783,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate; shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate;
key_map = kbd->key_maps[shift_final]; key_map = kbd->key_maps[shift_final];
if (!key_map) { if (key_map == NULL) {
/* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */ /* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */
kbd->shift_state = 0; kbd->shift_state = 0;
kbd->slockstate = 0; kbd->slockstate = 0;
+25 -9
View File
@@ -347,14 +347,30 @@ Fcitx_ModState(void)
Uint32 fcitx_mods = 0; Uint32 fcitx_mods = 0;
SDL_Keymod sdl_mods = SDL_GetModState(); SDL_Keymod sdl_mods = SDL_GetModState();
if (sdl_mods & KMOD_SHIFT) fcitx_mods |= (1 << 0); if (sdl_mods & KMOD_SHIFT) {
if (sdl_mods & KMOD_CAPS) fcitx_mods |= (1 << 1); fcitx_mods |= (1 << 0);
if (sdl_mods & KMOD_CTRL) fcitx_mods |= (1 << 2); }
if (sdl_mods & KMOD_ALT) fcitx_mods |= (1 << 3); if (sdl_mods & KMOD_CAPS) {
if (sdl_mods & KMOD_NUM) fcitx_mods |= (1 << 4); fcitx_mods |= (1 << 1);
if (sdl_mods & KMOD_MODE) fcitx_mods |= (1 << 7); }
if (sdl_mods & KMOD_LGUI) fcitx_mods |= (1 << 6); if (sdl_mods & KMOD_CTRL) {
if (sdl_mods & KMOD_RGUI) fcitx_mods |= (1 << 28); fcitx_mods |= (1 << 2);
}
if (sdl_mods & KMOD_ALT) {
fcitx_mods |= (1 << 3);
}
if (sdl_mods & KMOD_NUM) {
fcitx_mods |= (1 << 4);
}
if (sdl_mods & KMOD_MODE) {
fcitx_mods |= (1 << 7);
}
if (sdl_mods & KMOD_LGUI) {
fcitx_mods |= (1 << 6);
}
if (sdl_mods & KMOD_RGUI) {
fcitx_mods |= (1 << 28);
}
return fcitx_mods; return fcitx_mods;
} }
@@ -436,7 +452,7 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
} }
focused_win = SDL_GetKeyboardFocus(); focused_win = SDL_GetKeyboardFocus();
if (!focused_win) { if (focused_win == NULL) {
return ; return ;
} }
+48 -25
View File
@@ -64,14 +64,30 @@ IBus_ModState(void)
SDL_Keymod sdl_mods = SDL_GetModState(); SDL_Keymod sdl_mods = SDL_GetModState();
/* Not sure about MOD3, MOD4 and HYPER mappings */ /* Not sure about MOD3, MOD4 and HYPER mappings */
if (sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK; if (sdl_mods & KMOD_LSHIFT) {
if (sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_MASK; ibus_mods |= IBUS_SHIFT_MASK;
if (sdl_mods & KMOD_LCTRL) ibus_mods |= IBUS_CONTROL_MASK; }
if (sdl_mods & KMOD_LALT) ibus_mods |= IBUS_MOD1_MASK; if (sdl_mods & KMOD_CAPS) {
if (sdl_mods & KMOD_NUM) ibus_mods |= IBUS_MOD2_MASK; ibus_mods |= IBUS_LOCK_MASK;
if (sdl_mods & KMOD_MODE) ibus_mods |= IBUS_MOD5_MASK; }
if (sdl_mods & KMOD_LGUI) ibus_mods |= IBUS_SUPER_MASK; if (sdl_mods & KMOD_LCTRL) {
if (sdl_mods & KMOD_RGUI) ibus_mods |= IBUS_META_MASK; ibus_mods |= IBUS_CONTROL_MASK;
}
if (sdl_mods & KMOD_LALT) {
ibus_mods |= IBUS_MOD1_MASK;
}
if (sdl_mods & KMOD_NUM) {
ibus_mods |= IBUS_MOD2_MASK;
}
if (sdl_mods & KMOD_MODE) {
ibus_mods |= IBUS_MOD5_MASK;
}
if (sdl_mods & KMOD_LGUI) {
ibus_mods |= IBUS_SUPER_MASK;
}
if (sdl_mods & KMOD_RGUI) {
ibus_mods |= IBUS_META_MASK;
}
return ibus_mods; return ibus_mods;
} }
@@ -98,7 +114,7 @@ IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *
} }
dbus->message_iter_get_basic(inside, &struct_id); dbus->message_iter_get_basic(inside, &struct_id);
if (!struct_id || SDL_strncmp(struct_id, struct_id, id_size) != 0) { if (struct_id == NULL || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_TRUE; return SDL_TRUE;
@@ -248,13 +264,12 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
dbus->message_iter_init(msg, &iter); dbus->message_iter_init(msg, &iter);
has_dec_pos = IBus_GetDecorationPosition(conn, &iter, dbus, &start_pos, &end_pos); has_dec_pos = IBus_GetDecorationPosition(conn, &iter, dbus, &start_pos, &end_pos);
if (!has_dec_pos) if (!has_dec_pos) {
{
dbus->message_iter_init(msg, &iter); dbus->message_iter_init(msg, &iter);
has_pos = IBus_GetVariantCursorPos(conn, &iter, dbus, &pos); has_pos = IBus_GetVariantCursorPos(conn, &iter, dbus, &pos);
} }
if(has_dec_pos) { if (has_dec_pos) {
SDL_SendEditingText(text, start_pos, end_pos - start_pos); SDL_SendEditingText(text, start_pos, end_pos - start_pos);
} else if (has_pos) { } else if (has_pos) {
SDL_SendEditingText(text, pos, -1); SDL_SendEditingText(text, pos, -1);
@@ -298,15 +313,19 @@ IBus_ReadAddressFromFile(const char *file_path)
FILE *addr_file; FILE *addr_file;
addr_file = fopen(file_path, "r"); addr_file = fopen(file_path, "r");
if (!addr_file) { if (addr_file == NULL) {
return NULL; return NULL;
} }
while (fgets(addr_buf, sizeof(addr_buf), addr_file)) { while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) { if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
size_t sz = SDL_strlen(addr_buf); size_t sz = SDL_strlen(addr_buf);
if (addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0; if (addr_buf[sz - 1] == '\n') {
if (addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0; addr_buf[sz - 1] = 0;
}
if (addr_buf[sz - 2] == '\r') {
addr_buf[sz - 2] = 0;
}
success = SDL_TRUE; success = SDL_TRUE;
break; break;
} }
@@ -340,7 +359,7 @@ IBus_GetDBusAddressFilename(void)
} }
dbus = SDL_DBus_GetContext(); dbus = SDL_DBus_GetContext();
if (!dbus) { if (dbus == NULL) {
return NULL; return NULL;
} }
@@ -354,7 +373,7 @@ IBus_GetDBusAddressFilename(void)
and look up the address from a filepath using all those bits, eek. */ and look up the address from a filepath using all those bits, eek. */
disp_env = SDL_getenv("DISPLAY"); disp_env = SDL_getenv("DISPLAY");
if (!disp_env || !*disp_env) { if (disp_env == NULL || !*disp_env) {
display = SDL_strdup(":0.0"); display = SDL_strdup(":0.0");
} else { } else {
display = SDL_strdup(disp_env); display = SDL_strdup(disp_env);
@@ -364,7 +383,7 @@ IBus_GetDBusAddressFilename(void)
disp_num = SDL_strrchr(display, ':'); disp_num = SDL_strrchr(display, ':');
screen_num = SDL_strrchr(display, '.'); screen_num = SDL_strrchr(display, '.');
if (!disp_num) { if (disp_num == NULL) {
SDL_free(display); SDL_free(display);
return NULL; return NULL;
} }
@@ -392,7 +411,7 @@ IBus_GetDBusAddressFilename(void)
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir)); SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
} else { } else {
const char *home_env = SDL_getenv("HOME"); const char *home_env = SDL_getenv("HOME");
if (!home_env || !*home_env) { if (home_env == NULL || !*home_env) {
SDL_free(display); SDL_free(display);
return NULL; return NULL;
} }
@@ -460,7 +479,7 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
ibus_input_interface = IBUS_INPUT_INTERFACE; ibus_input_interface = IBUS_INPUT_INTERFACE;
ibus_conn = dbus->connection_open_private(addr, NULL); ibus_conn = dbus->connection_open_private(addr, NULL);
if (!ibus_conn) { if (ibus_conn == NULL) {
return SDL_FALSE; /* oh well. */ return SDL_FALSE; /* oh well. */
} }
@@ -498,7 +517,9 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
static SDL_bool static SDL_bool
IBus_CheckConnection(SDL_DBusContext *dbus) IBus_CheckConnection(SDL_DBusContext *dbus)
{ {
if (!dbus) return SDL_FALSE; if (dbus == NULL) {
return SDL_FALSE;
}
if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) { if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) {
return SDL_TRUE; return SDL_TRUE;
@@ -516,7 +537,9 @@ IBus_CheckConnection(SDL_DBusContext *dbus)
struct inotify_event *event = (struct inotify_event*) p; struct inotify_event *event = (struct inotify_event*) p;
if (event->len > 0) { if (event->len > 0) {
char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/'); char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
if (!addr_file_no_path) return SDL_FALSE; if (addr_file_no_path == NULL) {
return SDL_FALSE;
}
if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) { if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) {
file_updated = SDL_TRUE; file_updated = SDL_TRUE;
@@ -552,7 +575,7 @@ SDL_IBus_Init(void)
char *addr; char *addr;
char *addr_file_dir; char *addr_file_dir;
if (!addr_file) { if (addr_file == NULL) {
return SDL_FALSE; return SDL_FALSE;
} }
@@ -560,7 +583,7 @@ SDL_IBus_Init(void)
ibus_addr_file = SDL_strdup(addr_file); ibus_addr_file = SDL_strdup(addr_file);
addr = IBus_ReadAddressFromFile(addr_file); addr = IBus_ReadAddressFromFile(addr_file);
if (!addr) { if (addr == NULL) {
SDL_free(addr_file); SDL_free(addr_file);
return SDL_FALSE; return SDL_FALSE;
} }
@@ -699,7 +722,7 @@ SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
} }
focused_win = SDL_GetKeyboardFocus(); focused_win = SDL_GetKeyboardFocus();
if (!focused_win) { if (focused_win == NULL) {
return; return;
} }
+17 -10
View File
@@ -49,16 +49,17 @@ InitIME()
const char *xmodifiers = SDL_getenv("XMODIFIERS"); const char *xmodifiers = SDL_getenv("XMODIFIERS");
#endif #endif
if (inited == SDL_TRUE) if (inited == SDL_TRUE) {
return; return;
}
inited = SDL_TRUE; inited = SDL_TRUE;
/* See if fcitx IME support is being requested */ /* See if fcitx IME support is being requested */
#ifdef HAVE_FCITX #ifdef HAVE_FCITX
if (!SDL_IME_Init_Real && if (SDL_IME_Init_Real == NULL &&
((im_module && SDL_strcmp(im_module, "fcitx") == 0) || ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
(!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) { (im_module == NULL && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
SDL_IME_Init_Real = SDL_Fcitx_Init; SDL_IME_Init_Real = SDL_Fcitx_Init;
SDL_IME_Quit_Real = SDL_Fcitx_Quit; SDL_IME_Quit_Real = SDL_Fcitx_Quit;
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus; SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
@@ -71,7 +72,7 @@ InitIME()
/* default to IBus */ /* default to IBus */
#ifdef HAVE_IBUS_IBUS_H #ifdef HAVE_IBUS_IBUS_H
if (!SDL_IME_Init_Real) { if (SDL_IME_Init_Real == NULL) {
SDL_IME_Init_Real = SDL_IBus_Init; SDL_IME_Init_Real = SDL_IBus_Init;
SDL_IME_Quit_Real = SDL_IBus_Quit; SDL_IME_Quit_Real = SDL_IBus_Quit;
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus; SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
@@ -109,29 +110,33 @@ SDL_IME_Init(void)
void void
SDL_IME_Quit(void) SDL_IME_Quit(void)
{ {
if (SDL_IME_Quit_Real) if (SDL_IME_Quit_Real) {
SDL_IME_Quit_Real(); SDL_IME_Quit_Real();
}
} }
void void
SDL_IME_SetFocus(SDL_bool focused) SDL_IME_SetFocus(SDL_bool focused)
{ {
if (SDL_IME_SetFocus_Real) if (SDL_IME_SetFocus_Real) {
SDL_IME_SetFocus_Real(focused); SDL_IME_SetFocus_Real(focused);
}
} }
void void
SDL_IME_Reset(void) SDL_IME_Reset(void)
{ {
if (SDL_IME_Reset_Real) if (SDL_IME_Reset_Real) {
SDL_IME_Reset_Real(); SDL_IME_Reset_Real();
}
} }
SDL_bool SDL_bool
SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state) SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
{ {
if (SDL_IME_ProcessKeyEvent_Real) if (SDL_IME_ProcessKeyEvent_Real) {
return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, state); return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, state);
}
return SDL_FALSE; return SDL_FALSE;
} }
@@ -139,15 +144,17 @@ SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
void void
SDL_IME_UpdateTextRect(const SDL_Rect *rect) SDL_IME_UpdateTextRect(const SDL_Rect *rect)
{ {
if (SDL_IME_UpdateTextRect_Real) if (SDL_IME_UpdateTextRect_Real) {
SDL_IME_UpdateTextRect_Real(rect); SDL_IME_UpdateTextRect_Real(rect);
}
} }
void void
SDL_IME_PumpEvents() SDL_IME_PumpEvents()
{ {
if (SDL_IME_PumpEvents_Real) if (SDL_IME_PumpEvents_Real) {
SDL_IME_PumpEvents_Real(); SDL_IME_PumpEvents_Real();
}
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
+22 -24
View File
@@ -116,20 +116,20 @@ rtkit_initialize()
dbus_conn = get_rtkit_dbus_connection(); dbus_conn = get_rtkit_dbus_connection();
/* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */ /* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel", if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
DBUS_TYPE_INT32, &rtkit_min_nice_level)) { DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
rtkit_min_nice_level = -20; rtkit_min_nice_level = -20;
} }
/* Try getting maximum realtime priority: this can be less than the POSIX default (99). */ /* Try getting maximum realtime priority: this can be less than the POSIX default (99). */
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority", if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) { DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
rtkit_max_realtime_priority = 99; rtkit_max_realtime_priority = 99;
} }
/* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */ /* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax", if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) { DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
rtkit_max_rttime_usec = 200000; rtkit_max_rttime_usec = 200000;
} }
} }
@@ -168,8 +168,7 @@ rtkit_initialize_realtime_thread()
// Requirement #1: Set RLIMIT_RTTIME // Requirement #1: Set RLIMIT_RTTIME
err = getrlimit(nLimit, &rlimit); err = getrlimit(nLimit, &rlimit);
if (err) if (err) {
{
return SDL_FALSE; return SDL_FALSE;
} }
@@ -177,21 +176,18 @@ rtkit_initialize_realtime_thread()
rlimit.rlim_max = rtkit_max_rttime_usec; rlimit.rlim_max = rtkit_max_rttime_usec;
rlimit.rlim_cur = rlimit.rlim_max / 2; rlimit.rlim_cur = rlimit.rlim_max / 2;
err = setrlimit(nLimit, &rlimit); err = setrlimit(nLimit, &rlimit);
if (err) if (err) {
{
return SDL_FALSE; return SDL_FALSE;
} }
// Requirement #2: Add SCHED_RESET_ON_FORK to the scheduler policy // Requirement #2: Add SCHED_RESET_ON_FORK to the scheduler policy
err = sched_getparam(nPid, &schedParam); err = sched_getparam(nPid, &schedParam);
if (err) if (err) {
{
return SDL_FALSE; return SDL_FALSE;
} }
err = sched_setscheduler(nPid, nSchedPolicy, &schedParam); err = sched_setscheduler(nPid, nSchedPolicy, &schedParam);
if (err) if (err) {
{
return SDL_FALSE; return SDL_FALSE;
} }
@@ -209,13 +205,14 @@ rtkit_setpriority_nice(pid_t thread, int nice_level)
pthread_once(&rtkit_initialize_once, rtkit_initialize); pthread_once(&rtkit_initialize_once, rtkit_initialize);
dbus_conn = get_rtkit_dbus_connection(); dbus_conn = get_rtkit_dbus_connection();
if (nice < rtkit_min_nice_level) if (nice < rtkit_min_nice_level) {
nice = rtkit_min_nice_level; nice = rtkit_min_nice_level;
}
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn, if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID", rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID, DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) { DBUS_TYPE_INVALID)) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_TRUE; return SDL_TRUE;
@@ -232,8 +229,9 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
pthread_once(&rtkit_initialize_once, rtkit_initialize); pthread_once(&rtkit_initialize_once, rtkit_initialize);
dbus_conn = get_rtkit_dbus_connection(); dbus_conn = get_rtkit_dbus_connection();
if (priority > rtkit_max_realtime_priority) if (priority > rtkit_max_realtime_priority) {
priority = rtkit_max_realtime_priority; priority = rtkit_max_realtime_priority;
}
// We always perform the thread state changes necessary for rtkit. // We always perform the thread state changes necessary for rtkit.
// This wastes some system calls if the state is already set but // This wastes some system calls if the state is already set but
@@ -243,10 +241,10 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
// go through to determine whether it really needs to fail or not. // go through to determine whether it really needs to fail or not.
rtkit_initialize_realtime_thread(); rtkit_initialize_realtime_thread();
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn, if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID", rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID, DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
DBUS_TYPE_INVALID)) { DBUS_TYPE_INVALID)) {
return SDL_FALSE; return SDL_FALSE;
} }
return SDL_TRUE; return SDL_TRUE;
+5 -6
View File
@@ -115,7 +115,7 @@ SDL_UDEV_Init(void)
if (_this == NULL) { if (_this == NULL) {
_this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this)); _this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
if(_this == NULL) { if (_this == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -323,14 +323,13 @@ SDL_UDEV_LoadLibrary(void)
#endif #endif
if (_this->udev_handle == NULL) { if (_this->udev_handle == NULL) {
for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) { for ( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
_this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]); _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
if (_this->udev_handle != NULL) { if (_this->udev_handle != NULL) {
retval = SDL_UDEV_load_syms(); retval = SDL_UDEV_load_syms();
if (retval < 0) { if (retval < 0) {
SDL_UDEV_UnloadLibrary(); SDL_UDEV_UnloadLibrary();
} } else {
else {
break; break;
} }
} }
@@ -355,7 +354,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask)); SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
value = _this->syms.udev_device_get_sysattr_value(pdev, attr); value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
if (!value) { if (value == NULL) {
return; return;
} }
@@ -390,7 +389,7 @@ guess_device_class(struct udev_device *dev)
while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) { while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL); pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
} }
if (!pdev) { if (pdev == NULL) {
return 0; return 0;
} }
+110 -45
View File
@@ -229,14 +229,15 @@ static struct SDL_wscons_compose_tab_s {
static keysym_t ksym_upcase(keysym_t ksym) static keysym_t ksym_upcase(keysym_t ksym)
{ {
if (ksym >= KS_f1 && ksym <= KS_f20) if (ksym >= KS_f1 && ksym <= KS_f20) {
return(KS_F1 - KS_f1 + ksym); return KS_F1 - KS_f1 + ksym;
}
if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff && if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff && latin1_to_upper[ksym] != 0x00) {
latin1_to_upper[ksym] != 0x00) return latin1_to_upper[ksym];
return(latin1_to_upper[ksym]); }
return(ksym); return ksym;
} }
static struct wscons_keycode_to_SDL { static struct wscons_keycode_to_SDL {
keysym_t sourcekey; keysym_t sourcekey;
@@ -410,7 +411,7 @@ static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev)
#endif #endif
SDL_WSCONS_input_data* input = (SDL_WSCONS_input_data*)SDL_calloc(1, sizeof(SDL_WSCONS_input_data)); SDL_WSCONS_input_data* input = (SDL_WSCONS_input_data*)SDL_calloc(1, sizeof(SDL_WSCONS_input_data));
if (!input) { if (input == NULL) {
return input; return input;
} }
input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC); input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC);
@@ -487,10 +488,12 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
put_queue(input, 0xc0 | (c >> 6)); put_queue(input, 0xc0 | (c >> 6));
put_queue(input, 0x80 | (c & 0x3f)); put_queue(input, 0x80 | (c & 0x3f));
} else if (c < 0x10000) { } else if (c < 0x10000) {
if (c >= 0xD800 && c <= 0xF500) if (c >= 0xD800 && c <= 0xF500) {
return; return;
if (c == 0xFFFF) }
if (c == 0xFFFF) {
return; return;
}
/* 1110**** 10****** 10****** */ /* 1110**** 10****** 10****** */
put_queue(input, 0xe0 | (c >> 12)); put_queue(input, 0xe0 | (c >> 12));
put_queue(input, 0x80 | ((c >> 6) & 0x3f)); put_queue(input, 0x80 | ((c >> 6) & 0x3f));
@@ -507,7 +510,9 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym) static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
{ {
if (KS_GROUP(ksym) == KS_GROUP_Keypad) { if (KS_GROUP(ksym) == KS_GROUP_Keypad) {
if (SDL_isprint(ksym & 0xFF)) ksym &= 0xFF; if (SDL_isprint(ksym & 0xFF)) {
ksym &= 0xFF;
}
} }
switch(ksym) { switch(ksym) {
case KS_Escape: case KS_Escape:
@@ -565,7 +570,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
keysym_t *group; keysym_t *group;
keysym_t ksym, result; keysym_t ksym, result;
if (!input) return; if (input == NULL) {
return;
}
if ((n = read(input->fd, events, sizeof(events))) > 0) { if ((n = read(input->fd, events, sizeof(events))) > 0) {
n /= sizeof(struct wscons_event); n /= sizeof(struct wscons_event);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
@@ -574,21 +581,27 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
case WSCONS_EVENT_KEY_DOWN: { case WSCONS_EVENT_KEY_DOWN: {
switch (input->keymap.map[events[i].value].group1[0]) { switch (input->keymap.map[events[i].value].group1[0]) {
case KS_Hold_Screen: { case KS_Hold_Screen: {
if (input->lockheldstate[0] >= 1) break; if (input->lockheldstate[0] >= 1) {
break;
}
input->ledstate ^= LED_SCR; input->ledstate ^= LED_SCR;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[0] = 1; input->lockheldstate[0] = 1;
break; break;
} }
case KS_Num_Lock: { case KS_Num_Lock: {
if (input->lockheldstate[1] >= 1) break; if (input->lockheldstate[1] >= 1) {
break;
}
input->ledstate ^= LED_NUM; input->ledstate ^= LED_NUM;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[1] = 1; input->lockheldstate[1] = 1;
break; break;
} }
case KS_Caps_Lock: { case KS_Caps_Lock: {
if (input->lockheldstate[2] >= 1) break; if (input->lockheldstate[2] >= 1) {
break;
}
input->ledstate ^= LED_CAP; input->ledstate ^= LED_CAP;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[2] = 1; input->lockheldstate[2] = 1;
@@ -596,7 +609,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
} }
#ifndef __NetBSD__ #ifndef __NetBSD__
case KS_Mode_Lock: { case KS_Mode_Lock: {
if (input->lockheldstate[3] >= 1) break; if (input->lockheldstate[3] >= 1) {
break;
}
input->ledstate ^= 1 << 4; input->ledstate ^= 1 << 4;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[3] = 1; input->lockheldstate[3] = 1;
@@ -604,50 +619,66 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
} }
#endif #endif
case KS_Shift_Lock: { case KS_Shift_Lock: {
if (input->lockheldstate[4] >= 1) break; if (input->lockheldstate[4] >= 1) {
break;
}
input->ledstate ^= 1 << 5; input->ledstate ^= 1 << 5;
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate); ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
input->lockheldstate[4] = 1; input->lockheldstate[4] = 1;
break; break;
} }
case KS_Shift_L: { case KS_Shift_L: {
if (input->shiftheldstate[0]) break; if (input->shiftheldstate[0]) {
break;
}
input->shiftstate[0]++; input->shiftstate[0]++;
input->shiftheldstate[0] = 1; input->shiftheldstate[0] = 1;
break; break;
} }
case KS_Shift_R: { case KS_Shift_R: {
if (input->shiftheldstate[1]) break; if (input->shiftheldstate[1]) {
break;
}
input->shiftstate[0]++; input->shiftstate[0]++;
input->shiftheldstate[1] = 1; input->shiftheldstate[1] = 1;
break; break;
} }
case KS_Alt_L: { case KS_Alt_L: {
if (input->shiftheldstate[2]) break; if (input->shiftheldstate[2]) {
break;
}
input->shiftstate[1]++; input->shiftstate[1]++;
input->shiftheldstate[2] = 1; input->shiftheldstate[2] = 1;
break; break;
} }
case KS_Alt_R: { case KS_Alt_R: {
if (input->shiftheldstate[3]) break; if (input->shiftheldstate[3]) {
break;
}
input->shiftstate[1]++; input->shiftstate[1]++;
input->shiftheldstate[3] = 1; input->shiftheldstate[3] = 1;
break; break;
} }
case KS_Control_L: { case KS_Control_L: {
if (input->shiftheldstate[4]) break; if (input->shiftheldstate[4]) {
break;
}
input->shiftstate[2]++; input->shiftstate[2]++;
input->shiftheldstate[4] = 1; input->shiftheldstate[4] = 1;
break; break;
} }
case KS_Control_R: { case KS_Control_R: {
if (input->shiftheldstate[5]) break; if (input->shiftheldstate[5]) {
break;
}
input->shiftstate[2]++; input->shiftstate[2]++;
input->shiftheldstate[5] = 1; input->shiftheldstate[5] = 1;
break; break;
} }
case KS_Mode_switch: { case KS_Mode_switch: {
if (input->shiftheldstate[6]) break; if (input->shiftheldstate[6]) {
break;
}
input->shiftstate[3]++; input->shiftstate[3]++;
input->shiftheldstate[6] = 1; input->shiftheldstate[6] = 1;
break; break;
@@ -658,60 +689,84 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
case WSCONS_EVENT_KEY_UP: { case WSCONS_EVENT_KEY_UP: {
switch(input->keymap.map[events[i].value].group1[0]) { switch(input->keymap.map[events[i].value].group1[0]) {
case KS_Hold_Screen: { case KS_Hold_Screen: {
if (input->lockheldstate[0]) input->lockheldstate[0] = 0; if (input->lockheldstate[0]) {
input->lockheldstate[0] = 0;
}
} }
break; break;
case KS_Num_Lock: { case KS_Num_Lock: {
if (input->lockheldstate[1]) input->lockheldstate[1] = 0; if (input->lockheldstate[1]) {
input->lockheldstate[1] = 0;
}
} }
break; break;
case KS_Caps_Lock: { case KS_Caps_Lock: {
if (input->lockheldstate[2]) input->lockheldstate[2] = 0; if (input->lockheldstate[2]) {
input->lockheldstate[2] = 0;
}
} }
break; break;
#ifndef __NetBSD__ #ifndef __NetBSD__
case KS_Mode_Lock: { case KS_Mode_Lock: {
if (input->lockheldstate[3]) input->lockheldstate[3] = 0; if (input->lockheldstate[3]) {
input->lockheldstate[3] = 0;
}
} }
break; break;
#endif #endif
case KS_Shift_Lock: { case KS_Shift_Lock: {
if (input->lockheldstate[4]) input->lockheldstate[4] = 0; if (input->lockheldstate[4]) {
input->lockheldstate[4] = 0;
}
} }
break; break;
case KS_Shift_L: { case KS_Shift_L: {
input->shiftheldstate[0] = 0; input->shiftheldstate[0] = 0;
if (input->shiftstate[0]) input->shiftstate[0]--; if (input->shiftstate[0]) {
input->shiftstate[0]--;
}
break; break;
} }
case KS_Shift_R: { case KS_Shift_R: {
input->shiftheldstate[1] = 0; input->shiftheldstate[1] = 0;
if (input->shiftstate[0]) input->shiftstate[0]--; if (input->shiftstate[0]) {
input->shiftstate[0]--;
}
break; break;
} }
case KS_Alt_L: { case KS_Alt_L: {
input->shiftheldstate[2] = 0; input->shiftheldstate[2] = 0;
if (input->shiftstate[1]) input->shiftstate[1]--; if (input->shiftstate[1]) {
input->shiftstate[1]--;
}
break; break;
} }
case KS_Alt_R: { case KS_Alt_R: {
input->shiftheldstate[3] = 0; input->shiftheldstate[3] = 0;
if (input->shiftstate[1]) input->shiftstate[1]--; if (input->shiftstate[1]) {
input->shiftstate[1]--;
}
break; break;
} }
case KS_Control_L: { case KS_Control_L: {
input->shiftheldstate[4] = 0; input->shiftheldstate[4] = 0;
if (input->shiftstate[2]) input->shiftstate[2]--; if (input->shiftstate[2]) {
input->shiftstate[2]--;
}
break; break;
} }
case KS_Control_R: { case KS_Control_R: {
input->shiftheldstate[5] = 0; input->shiftheldstate[5] = 0;
if (input->shiftstate[2]) input->shiftstate[2]--; if (input->shiftstate[2]) {
input->shiftstate[2]--;
}
break; break;
} }
case KS_Mode_switch: { case KS_Mode_switch: {
input->shiftheldstate[6] = 0; input->shiftheldstate[6] = 0;
if (input->shiftstate[3]) input->shiftstate[3]--; if (input->shiftstate[3]) {
input->shiftstate[3]--;
}
break; break;
} }
} }
@@ -729,7 +784,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
else else
Translate_to_keycode(input, type, events[i].value); Translate_to_keycode(input, type, events[i].value);
if (type == WSCONS_EVENT_KEY_UP) continue; if (type == WSCONS_EVENT_KEY_UP) {
continue;
}
if (IS_ALTGR_MODE && !IS_CONTROL_HELD) if (IS_ALTGR_MODE && !IS_CONTROL_HELD)
group = &input->keymap.map[events[i].value].group2[0]; group = &input->keymap.map[events[i].value].group2[0];
@@ -774,7 +831,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
} else result = ksym; } else result = ksym;
break; break;
} }
if (result == KS_voidSymbol) continue; if (result == KS_voidSymbol) {
continue;
}
if (input->composelen > 0) { if (input->composelen > 0) {
if (input->composelen == 2 && group == &input->keymap.map[events[i].value].group2[0]) { if (input->composelen == 2 && group == &input->keymap.map[events[i].value].group2[0]) {
@@ -805,21 +864,24 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
if (KS_GROUP(result) == KS_GROUP_Ascii) { if (KS_GROUP(result) == KS_GROUP_Ascii) {
if (IS_CONTROL_HELD) { if (IS_CONTROL_HELD) {
if ((result >= KS_at && result <= KS_z) || result == KS_space) if ((result >= KS_at && result <= KS_z) || result == KS_space) {
result = result & 0x1f; result = result & 0x1f;
else if (result == KS_2) } else if (result == KS_2) {
result = 0x00; result = 0x00;
else if (result >= KS_3 && result <= KS_7) } else if (result >= KS_3 && result <= KS_7) {
result = KS_Escape + (result - KS_3); result = KS_Escape + (result - KS_3);
else if (result == KS_8) } else if (result == KS_8) {
result = KS_Delete; result = KS_Delete;
}
} }
if (IS_ALT_HELD) { if (IS_ALT_HELD) {
if (input->encoding & KB_METAESC) { if (input->encoding & KB_METAESC) {
Translate_to_keycode(input, WSCONS_EVENT_KEY_DOWN, KS_Escape); Translate_to_keycode(input, WSCONS_EVENT_KEY_DOWN, KS_Escape);
Translate_to_text(input, result); Translate_to_text(input, result);
continue; continue;
} else result |= 0x80; } else {
result |= 0x80;
}
} }
} }
Translate_to_text(input,result); Translate_to_text(input,result);
@@ -831,7 +893,10 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
void SDL_WSCONS_PumpEvents() void SDL_WSCONS_PumpEvents()
{ {
int i = 0; int i = 0;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
updateKeyboard(inputs[i]); updateKeyboard(inputs[i]);
if (mouseInputData != NULL) updateMouse(mouseInputData); }
if (mouseInputData != NULL) {
updateMouse(mouseInputData);
}
} }
+8 -6
View File
@@ -41,7 +41,9 @@ SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
#endif #endif
SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data)); SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
if (!mouseInputData) return NULL; if (mouseInputData == NULL) {
return NULL;
}
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK | O_CLOEXEC); mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; } if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
#ifdef WSMOUSEIO_SETMODE #ifdef WSMOUSEIO_SETMODE
@@ -60,11 +62,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
int n,i; int n,i;
SDL_Mouse* mouse = SDL_GetMouse(); SDL_Mouse* mouse = SDL_GetMouse();
if ((n = read(inputData->fd, events, sizeof(events))) > 0) if ((n = read(inputData->fd, events, sizeof(events))) > 0) {
{
n /= sizeof(struct wscons_event); n /= sizeof(struct wscons_event);
for (i = 0; i < n; i++) for (i = 0; i < n; i++) {
{
type = events[i].type; type = events[i].type;
switch(type) switch(type)
{ {
@@ -127,7 +127,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* inputData) void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* inputData)
{ {
if (!inputData) return; if (inputData == NULL) {
return;
}
close(inputData->fd); close(inputData->fd);
free(inputData); free(inputData);
} }

Some files were not shown because too many files have changed in this diff Show More