mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-18 00:35:03 +08:00
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
(cherry picked from commit 6a2200823c to reduce conflicts merging between SDL2 and SDL3)
This commit is contained in:
committed by
Sam Lantinga
parent
0739d237ad
commit
fb0ce375f0
@@ -239,17 +239,17 @@ LoadSprite(const char *file)
|
||||
/* 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);
|
||||
if (!sprites[i]) {
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -364,8 +364,9 @@ loop()
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
DrawSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
}
|
||||
@@ -382,7 +383,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -445,7 +446,7 @@ main(int argc, char *argv[])
|
||||
/* Create the windows, initialize the renderers, and load the textures */
|
||||
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");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ initializeTextures(SDL_Renderer *renderer)
|
||||
|
||||
/* create ship texture from surface */
|
||||
ship = SDL_CreateTextureFromSurface(renderer, bmp_surface);
|
||||
if (!ship) {
|
||||
if (ship == NULL) {
|
||||
fatalError("could not create ship texture");
|
||||
}
|
||||
SDL_SetTextureBlendMode(ship, SDL_BLENDMODE_BLEND);
|
||||
@@ -145,7 +145,7 @@ initializeTextures(SDL_Renderer *renderer)
|
||||
}
|
||||
/* create space texture from surface */
|
||||
space = SDL_CreateTextureFromSurface(renderer, bmp_surface);
|
||||
if (!space) {
|
||||
if (space == NULL) {
|
||||
fatalError("could not create space texture");
|
||||
}
|
||||
SDL_FreeSurface(bmp_surface);
|
||||
|
||||
@@ -84,14 +84,16 @@ stepParticles(double deltaTime)
|
||||
/* is the particle actually active, or is it marked for deletion? */
|
||||
if (curr->isActive) {
|
||||
/* is the particle off the screen? */
|
||||
if (curr->y > screen_h)
|
||||
if (curr->y > screen_h) {
|
||||
curr->isActive = 0;
|
||||
else if (curr->y < 0)
|
||||
} else if (curr->y < 0) {
|
||||
curr->isActive = 0;
|
||||
if (curr->x > screen_w)
|
||||
}
|
||||
if (curr->x > screen_w) {
|
||||
curr->isActive = 0;
|
||||
else if (curr->x < 0)
|
||||
} else if (curr->x < 0) {
|
||||
curr->isActive = 0;
|
||||
}
|
||||
|
||||
/* step velocity, then step position */
|
||||
curr->yvel += ACCEL * deltaMilliseconds;
|
||||
@@ -133,15 +135,17 @@ stepParticles(double deltaTime)
|
||||
}
|
||||
|
||||
/* if we're a dust particle, shrink our size */
|
||||
if (curr->type == dust)
|
||||
if (curr->type == dust) {
|
||||
curr->size -= deltaMilliseconds * 0.010f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* if we're still active, pack ourselves in the array next
|
||||
to the last active guy (pack the array tightly) */
|
||||
if (curr->isActive)
|
||||
if (curr->isActive) {
|
||||
*(slot++) = *curr;
|
||||
}
|
||||
} /* endif (curr->isActive) */
|
||||
curr++;
|
||||
}
|
||||
@@ -188,8 +192,9 @@ explodeEmitter(struct particle *emitter)
|
||||
int i;
|
||||
for (i = 0; i < 200; i++) {
|
||||
|
||||
if (num_active_particles >= MAX_PARTICLES)
|
||||
if (num_active_particles >= MAX_PARTICLES) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* come up with a random angle and speed for new particle */
|
||||
float theta = randomFloat(0, 2.0f * 3.141592);
|
||||
@@ -226,8 +231,9 @@ void
|
||||
spawnTrailFromEmitter(struct particle *emitter)
|
||||
{
|
||||
|
||||
if (num_active_particles >= MAX_PARTICLES)
|
||||
if (num_active_particles >= MAX_PARTICLES) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* select the particle at the slot at the end of our array */
|
||||
struct particle *p = &particles[num_active_particles];
|
||||
@@ -262,8 +268,9 @@ void
|
||||
spawnEmitterParticle(GLfloat x, GLfloat y)
|
||||
{
|
||||
|
||||
if (num_active_particles >= MAX_PARTICLES)
|
||||
if (num_active_particles >= MAX_PARTICLES) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* find particle at endpoint of array */
|
||||
struct particle *p = &particles[num_active_particles];
|
||||
|
||||
@@ -117,7 +117,7 @@ initializeTexture(SDL_Renderer *renderer)
|
||||
|
||||
/* convert RGBA surface to texture */
|
||||
texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
|
||||
if (!texture) {
|
||||
if (texture == NULL) {
|
||||
fatalError("could not create texture");
|
||||
}
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
@@ -165,7 +165,7 @@ loadFont(void)
|
||||
{
|
||||
SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
printf("Error loading bitmap: %s\n", SDL_GetError());
|
||||
return 0;
|
||||
} else {
|
||||
@@ -183,7 +183,7 @@ loadFont(void)
|
||||
SDL_BlitSurface(surface, NULL, converted, NULL);
|
||||
/* create our texture */
|
||||
texture = SDL_CreateTextureFromSurface(renderer, converted);
|
||||
if (!texture) {
|
||||
if (texture == NULL) {
|
||||
printf("texture creation failed: %s\n", SDL_GetError());
|
||||
} else {
|
||||
/* set blend mode for our texture */
|
||||
|
||||
@@ -207,9 +207,9 @@ playSound(struct sound *s)
|
||||
break;
|
||||
}
|
||||
/* if this channel's sound is older than the oldest so far, set it to oldest */
|
||||
if (mixer.channels[i].timestamp <
|
||||
mixer.channels[oldest_channel].timestamp)
|
||||
if (mixer.channels[i].timestamp < mixer.channels[oldest_channel].timestamp) {
|
||||
oldest_channel = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* no empty channels, take the oldest one */
|
||||
|
||||
@@ -58,11 +58,11 @@ main(int argc, char *argv[])
|
||||
|
||||
/* create window and renderer */
|
||||
window = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
fatalError("Could not initialize Window");
|
||||
}
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
fatalError("Could not create renderer");
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ initializeTexture(SDL_Renderer *renderer)
|
||||
brush =
|
||||
SDL_CreateTextureFromSurface(renderer, bmp_surface);
|
||||
SDL_FreeSurface(bmp_surface);
|
||||
if (!brush) {
|
||||
if (brush == NULL) {
|
||||
fatalError("could not create brush texture");
|
||||
}
|
||||
/* additive blending -- laying strokes on top of eachother makes them brighter */
|
||||
|
||||
@@ -231,7 +231,7 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
}
|
||||
|
||||
/* Initialize the timer subsystem */
|
||||
if ((flags & SDL_INIT_TIMER)){
|
||||
if ((flags & SDL_INIT_TIMER)) {
|
||||
#if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY
|
||||
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
|
||||
if (SDL_TimerInit() < 0) {
|
||||
@@ -247,7 +247,7 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
}
|
||||
|
||||
/* Initialize the video subsystem */
|
||||
if ((flags & SDL_INIT_VIDEO)){
|
||||
if ((flags & SDL_INIT_VIDEO)) {
|
||||
#if !SDL_VIDEO_DISABLED
|
||||
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
|
||||
if (SDL_VideoInit(NULL) < 0) {
|
||||
@@ -263,7 +263,7 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
}
|
||||
|
||||
/* Initialize the audio subsystem */
|
||||
if ((flags & SDL_INIT_AUDIO)){
|
||||
if ((flags & SDL_INIT_AUDIO)) {
|
||||
#if !SDL_AUDIO_DISABLED
|
||||
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
|
||||
if (SDL_AudioInit(NULL) < 0) {
|
||||
@@ -279,7 +279,7 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
}
|
||||
|
||||
/* Initialize the joystick subsystem */
|
||||
if ((flags & SDL_INIT_JOYSTICK)){
|
||||
if ((flags & SDL_INIT_JOYSTICK)) {
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
|
||||
if (SDL_JoystickInit() < 0) {
|
||||
@@ -294,7 +294,7 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((flags & SDL_INIT_GAMECONTROLLER)){
|
||||
if ((flags & SDL_INIT_GAMECONTROLLER)) {
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
|
||||
if (SDL_GameControllerInit() < 0) {
|
||||
@@ -310,7 +310,7 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
}
|
||||
|
||||
/* Initialize the haptic subsystem */
|
||||
if ((flags & SDL_INIT_HAPTIC)){
|
||||
if ((flags & SDL_INIT_HAPTIC)) {
|
||||
#if !SDL_HAPTIC_DISABLED
|
||||
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
|
||||
if (SDL_HapticInit() < 0) {
|
||||
@@ -326,7 +326,7 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
}
|
||||
|
||||
/* Initialize the sensor subsystem */
|
||||
if ((flags & SDL_INIT_SENSOR)){
|
||||
if ((flags & SDL_INIT_SENSOR)) {
|
||||
#if !SDL_SENSOR_DISABLED
|
||||
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
|
||||
if (SDL_SensorInit() < 0) {
|
||||
@@ -343,11 +343,11 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
|
||||
(void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
|
||||
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
quit_and_error:
|
||||
SDL_QuitSubSystem(flags_initialized);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -522,8 +522,7 @@ SDL_GetVersion(SDL_version * ver)
|
||||
static SDL_bool check_hint = SDL_TRUE;
|
||||
static SDL_bool legacy_version = SDL_FALSE;
|
||||
|
||||
if (!ver) {
|
||||
return;
|
||||
if (ver == NULL) { return;
|
||||
}
|
||||
|
||||
SDL_VERSION(ver);
|
||||
|
||||
+1
-4
@@ -252,10 +252,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
|
||||
} else {
|
||||
state = (SDL_assert_state)selected;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
/* This is nasty, but we can't block on a custom UI. */
|
||||
for ( ; ; ) {
|
||||
|
||||
+11
-11
@@ -58,7 +58,7 @@ SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
|
||||
{
|
||||
SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue));
|
||||
|
||||
if (!queue) {
|
||||
if (queue == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
} else {
|
||||
@@ -102,7 +102,7 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
|
||||
SDL_DataQueuePacket *prev = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!queue) {
|
||||
if (queue == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
|
||||
size_t origlen;
|
||||
size_t datalen;
|
||||
|
||||
if (!queue) {
|
||||
if (queue == NULL) {
|
||||
return SDL_InvalidParamError("queue");
|
||||
}
|
||||
|
||||
@@ -191,13 +191,13 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
|
||||
|
||||
while (len > 0) {
|
||||
SDL_DataQueuePacket *packet = queue->tail;
|
||||
SDL_assert(!packet || (packet->datalen <= packet_size));
|
||||
if (!packet || (packet->datalen >= packet_size)) {
|
||||
SDL_assert(packet == NULL || (packet->datalen <= packet_size));
|
||||
if (packet == NULL || (packet->datalen >= packet_size)) {
|
||||
/* tail packet missing or completely full; we need a new packet. */
|
||||
packet = AllocateDataQueuePacket(queue);
|
||||
if (!packet) {
|
||||
if (packet == NULL) {
|
||||
/* uhoh, reset so we've queued nothing new, free what we can. */
|
||||
if (!origtail) {
|
||||
if (origtail == NULL) {
|
||||
packet = queue->head; /* whole queue. */
|
||||
} else {
|
||||
packet = origtail->next; /* what we added to existing queue. */
|
||||
@@ -232,7 +232,7 @@ SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
|
||||
Uint8 *ptr = buf;
|
||||
SDL_DataQueuePacket *packet;
|
||||
|
||||
if (!queue) {
|
||||
if (queue == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
|
||||
Uint8 *ptr = buf;
|
||||
SDL_DataQueuePacket *packet;
|
||||
|
||||
if (!queue) {
|
||||
if (queue == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
|
||||
{
|
||||
SDL_DataQueuePacket *packet;
|
||||
|
||||
if (!queue) {
|
||||
if (queue == NULL) {
|
||||
SDL_InvalidParamError("queue");
|
||||
return NULL;
|
||||
} else if (len == 0) {
|
||||
@@ -324,7 +324,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
|
||||
|
||||
/* Need a fresh packet. */
|
||||
packet = AllocateDataQueuePacket(queue);
|
||||
if (!packet) {
|
||||
if (packet == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+3
-3
@@ -52,15 +52,15 @@ void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
|
||||
static unsigned char nibble(unsigned char c)
|
||||
{
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
return (c - '0');
|
||||
return c - '0';
|
||||
}
|
||||
|
||||
if ((c >= 'A') && (c <= 'F')) {
|
||||
return (c - 'A' + 0x0a);
|
||||
return c - 'A' + 0x0a;
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
+9
-9
@@ -52,7 +52,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
|
||||
SDL_Hint *hint;
|
||||
SDL_HintWatch *entry;
|
||||
|
||||
if (!name) {
|
||||
if (name == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
|
||||
return SDL_FALSE;
|
||||
}
|
||||
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; ) {
|
||||
/* Save the next entry in case this one is deleted */
|
||||
SDL_HintWatch *next = entry->next;
|
||||
@@ -84,7 +84,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
|
||||
|
||||
/* Couldn't find the hint, add a new one */
|
||||
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
|
||||
if (!hint) {
|
||||
if (hint == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
hint->name = SDL_strdup(name);
|
||||
@@ -103,7 +103,7 @@ SDL_ResetHint(const char *name)
|
||||
SDL_Hint *hint;
|
||||
SDL_HintWatch *entry;
|
||||
|
||||
if (!name) {
|
||||
if (name == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ SDL_GetHint(const char *name)
|
||||
SDL_bool
|
||||
SDL_GetStringBoolean(const char *value, SDL_bool default_value)
|
||||
{
|
||||
if (!value || !*value) {
|
||||
if (value == NULL || !*value) {
|
||||
return default_value;
|
||||
}
|
||||
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
|
||||
@@ -204,7 +204,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
|
||||
SDL_HintWatch *entry;
|
||||
const char *value;
|
||||
|
||||
if (!name || !*name) {
|
||||
if (name == NULL || !*name) {
|
||||
SDL_InvalidParamError("name");
|
||||
return;
|
||||
}
|
||||
@@ -216,7 +216,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
|
||||
SDL_DelHintCallback(name, callback, userdata);
|
||||
|
||||
entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
|
||||
if (!entry) {
|
||||
if (entry == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return;
|
||||
}
|
||||
@@ -228,10 +228,10 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hint) {
|
||||
if (hint == NULL) {
|
||||
/* Need to add a hint entry for this watcher */
|
||||
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
|
||||
if (!hint) {
|
||||
if (hint == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(entry);
|
||||
return;
|
||||
|
||||
+6
-4
@@ -108,7 +108,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
|
||||
void
|
||||
SDL_LogInit(void)
|
||||
{
|
||||
if (!log_function_mutex) {
|
||||
if (log_function_mutex == NULL) {
|
||||
/* if this fails we'll try to continue without it. */
|
||||
log_function_mutex = SDL_CreateMutex();
|
||||
}
|
||||
@@ -316,7 +316,7 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
|
||||
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! */
|
||||
log_function_mutex = SDL_CreateMutex();
|
||||
}
|
||||
@@ -326,15 +326,17 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
|
||||
len = SDL_vsnprintf(stack_buf, sizeof(stack_buf), fmt, aq);
|
||||
va_end(aq);
|
||||
|
||||
if (len < 0)
|
||||
if (len < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* If message truncated, allocate and re-render */
|
||||
if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) {
|
||||
/* Allocate exactly what we need, including the zero-terminator */
|
||||
message = (char *)SDL_malloc(len_plus_term);
|
||||
if (!message)
|
||||
if (message == NULL) {
|
||||
return;
|
||||
}
|
||||
va_copy(aq, ap);
|
||||
len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
|
||||
va_end(aq);
|
||||
|
||||
+10
-10
@@ -129,15 +129,15 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
|
||||
{
|
||||
#ifdef HAVE_MSC_ATOMICS
|
||||
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)
|
||||
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)
|
||||
return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
|
||||
#elif defined(__MACOSX__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
|
||||
return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
|
||||
#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
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
|
||||
@@ -158,9 +158,9 @@ SDL_bool
|
||||
SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
|
||||
{
|
||||
#if defined(HAVE_MSC_ATOMICS)
|
||||
return (_InterlockedCompareExchangePointer(a, newval, oldval) == oldval);
|
||||
return _InterlockedCompareExchangePointer(a, newval, oldval) == oldval;
|
||||
#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)
|
||||
return __sync_bool_compare_and_swap(a, oldval, newval);
|
||||
#elif defined(__MACOSX__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
|
||||
@@ -168,7 +168,7 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
|
||||
#elif defined(__MACOSX__) && !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);
|
||||
#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
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
|
||||
@@ -190,13 +190,13 @@ SDL_AtomicSet(SDL_atomic_t *a, int v)
|
||||
{
|
||||
#ifdef HAVE_MSC_ATOMICS
|
||||
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)
|
||||
return _SDL_xchg_watcom(&a->value, v);
|
||||
#elif defined(HAVE_GCC_ATOMICS)
|
||||
return __sync_lock_test_and_set(&a->value, v);
|
||||
#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
|
||||
int value;
|
||||
do {
|
||||
@@ -212,7 +212,7 @@ SDL_AtomicSetPtr(void **a, void *v)
|
||||
#if defined(HAVE_MSC_ATOMICS)
|
||||
return _InterlockedExchangePointer(a, v);
|
||||
#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)
|
||||
return __sync_lock_test_and_set(a, v);
|
||||
#elif defined(__SOLARIS__)
|
||||
@@ -231,7 +231,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
|
||||
{
|
||||
#ifdef HAVE_MSC_ATOMICS
|
||||
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)
|
||||
return _SDL_xadd_watcom(&a->value, v);
|
||||
#elif defined(HAVE_GCC_ATOMICS)
|
||||
|
||||
+11
-11
@@ -66,7 +66,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
/* Terrible terrible damage */
|
||||
static SDL_mutex *_spinlock_mutex;
|
||||
|
||||
if (!_spinlock_mutex) {
|
||||
if (_spinlock_mutex == NULL) {
|
||||
/* Race condition on first lock... */
|
||||
_spinlock_mutex = SDL_CreateMutex();
|
||||
}
|
||||
@@ -81,14 +81,14 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
}
|
||||
|
||||
#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))
|
||||
return (_InterlockedExchange_acq(lock, 1) == 0);
|
||||
return _InterlockedExchange_acq(lock, 1) == 0;
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
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__)
|
||||
return _SDL_xchg_watcom(lock, 1) == 0;
|
||||
@@ -105,28 +105,28 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
__asm__ __volatile__ (
|
||||
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
|
||||
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
||||
return (result == 0);
|
||||
return result == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"swp %0, %1, [%2]\n"
|
||||
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
|
||||
return (result == 0);
|
||||
return result == 0;
|
||||
|
||||
#elif defined(__GNUC__) && defined(__arm__)
|
||||
int result;
|
||||
__asm__ __volatile__ (
|
||||
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
|
||||
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
||||
return (result == 0);
|
||||
return result == 0;
|
||||
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
int result;
|
||||
__asm__ __volatile__(
|
||||
"lock ; xchgl %0, (%1)\n"
|
||||
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
|
||||
return (result == 0);
|
||||
return result == 0;
|
||||
|
||||
#elif defined(__MACOSX__) || defined(__IPHONEOS__)
|
||||
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
|
||||
@@ -134,11 +134,11 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
|
||||
#elif defined(__SOLARIS__) && defined(_LP64)
|
||||
/* 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)
|
||||
/* 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)
|
||||
uint32_t oldintr;
|
||||
SDL_bool res = SDL_FALSE;
|
||||
@@ -150,7 +150,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
res = SDL_TRUE;
|
||||
}
|
||||
// enable interuption
|
||||
if(oldintr) { EIntr(); }
|
||||
if (oldintr) { EIntr(); }
|
||||
return res;
|
||||
#else
|
||||
#error Please implement for your platform.
|
||||
|
||||
@@ -541,11 +541,9 @@ SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle)
|
||||
} else {
|
||||
mark_device_removed(handle, current_audio.outputDevices, ¤t_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];
|
||||
if (device != NULL && device->handle == handle)
|
||||
{
|
||||
if (device != NULL && device->handle == handle) {
|
||||
device_was_opened = SDL_TRUE;
|
||||
SDL_OpenedAudioDeviceDisconnected(device);
|
||||
break;
|
||||
@@ -1009,7 +1007,7 @@ SDL_AudioInit(const char *driver_name)
|
||||
}
|
||||
} else {
|
||||
for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
|
||||
if(bootstrap[i]->demand_only) {
|
||||
if (bootstrap[i]->demand_only) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+22
-20
@@ -184,7 +184,7 @@ ResamplerPadding(const int inrate, const int outrate)
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
|
||||
outtime = ((ResampleFloatType) i) / ((ResampleFloatType) outrate);
|
||||
}
|
||||
|
||||
return outframes * chans * sizeof (float);
|
||||
return outframes * chans * sizeof(float);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -488,7 +488,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. */
|
||||
padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float));
|
||||
if (!padding) {
|
||||
if (padding == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return;
|
||||
}
|
||||
@@ -586,7 +586,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: so we steal the ninth and tenth slot. :( */
|
||||
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] = (SDL_AudioFilter) (uintptr_t) dst_rate;
|
||||
@@ -788,7 +788,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -835,7 +835,7 @@ EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
|
||||
ptr = stream->work_buffer_base;
|
||||
} else {
|
||||
ptr = (Uint8 *) SDL_realloc(stream->work_buffer_base, newlen + 32);
|
||||
if (!ptr) {
|
||||
if (ptr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -911,12 +911,12 @@ SetupLibSampleRateResampling(SDL_AudioStream *stream)
|
||||
|
||||
if (SRC_available) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
SDL_CleanupAudioStreamResampler_SRC(stream);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -983,7 +983,7 @@ SDL_NewAudioStream(const SDL_AudioFormat src_format,
|
||||
SDL_AudioStream *retval;
|
||||
|
||||
retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -1126,7 +1126,7 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
|
||||
#endif
|
||||
|
||||
workbuf = EnsureStreamBufferSize(stream, workbuflen);
|
||||
if (!workbuf) {
|
||||
if (workbuf == NULL) {
|
||||
return -1; /* probably out of memory. */
|
||||
}
|
||||
|
||||
@@ -1193,8 +1193,9 @@ SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, in
|
||||
|
||||
if (maxputbytes) {
|
||||
const int maxbytes = *maxputbytes;
|
||||
if (buflen > maxbytes)
|
||||
if (buflen > maxbytes) {
|
||||
buflen = maxbytes;
|
||||
}
|
||||
*maxputbytes -= buflen;
|
||||
}
|
||||
|
||||
@@ -1217,10 +1218,10 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
|
||||
SDL_Log("AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen);
|
||||
#endif
|
||||
|
||||
if (!stream) {
|
||||
if (stream == NULL) {
|
||||
return SDL_InvalidParamError("stream");
|
||||
}
|
||||
if (!buf) {
|
||||
if (buf == NULL) {
|
||||
return SDL_InvalidParamError("buf");
|
||||
}
|
||||
if (len == 0) {
|
||||
@@ -1272,7 +1273,7 @@ SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
|
||||
|
||||
int SDL_AudioStreamFlush(SDL_AudioStream *stream)
|
||||
{
|
||||
if (!stream) {
|
||||
if (stream == NULL) {
|
||||
return SDL_InvalidParamError("stream");
|
||||
}
|
||||
|
||||
@@ -1290,8 +1291,9 @@ int SDL_AudioStreamFlush(SDL_AudioStream *stream)
|
||||
const SDL_bool first_run = stream->first_run;
|
||||
const int filled = stream->staging_buffer_filled;
|
||||
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;
|
||||
}
|
||||
|
||||
if (actual_input_frames > 0) { /* don't bother if nothing to flush. */
|
||||
/* This is how many bytes we're expecting without silence appended. */
|
||||
@@ -1330,10 +1332,10 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
|
||||
SDL_Log("AUDIOSTREAM: want to get %d converted bytes\n", len);
|
||||
#endif
|
||||
|
||||
if (!stream) {
|
||||
if (stream == NULL) {
|
||||
return SDL_InvalidParamError("stream");
|
||||
}
|
||||
if (!buf) {
|
||||
if (buf == NULL) {
|
||||
return SDL_InvalidParamError("buf");
|
||||
}
|
||||
if (len <= 0) {
|
||||
@@ -1343,20 +1345,20 @@ SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
|
||||
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 */
|
||||
int
|
||||
SDL_AudioStreamAvailable(SDL_AudioStream *stream)
|
||||
{
|
||||
return stream ? (int) SDL_CountDataQueue(stream->queue) : 0;
|
||||
return stream ? (int)SDL_CountDataQueue(stream->queue) : 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AudioStreamClear(SDL_AudioStream *stream)
|
||||
{
|
||||
if (!stream) {
|
||||
if (stream == NULL) {
|
||||
SDL_InvalidParamError("stream");
|
||||
} else {
|
||||
SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);
|
||||
|
||||
@@ -84,8 +84,9 @@ SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*
|
||||
const char *audiodev;
|
||||
char audiopath[1024];
|
||||
|
||||
if (test == NULL)
|
||||
if (test == NULL) {
|
||||
test = test_stub;
|
||||
}
|
||||
|
||||
/* Figure out what our audio device is */
|
||||
if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
|
||||
|
||||
@@ -820,7 +820,7 @@ IMA_ADPCM_Init(WaveFile *file, size_t datalength)
|
||||
/* There's no specification for this, but it's basically the same
|
||||
* format because the extensible header has wSampePerBlocks too.
|
||||
*/
|
||||
} else {
|
||||
} else {
|
||||
/* The Standards Update says there 'should' be 2 bytes for wSamplesPerBlock. */
|
||||
if (chunk->size >= 20 && format->extsize >= 2) {
|
||||
format->samplesperblock = chunk->data[18] | ((Uint16)chunk->data[19] << 8);
|
||||
@@ -901,14 +901,18 @@ IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
|
||||
* (nybble & 0x8 ? -1 : 1) * ((nybble & 0x7) * step / 4 + step / 8)
|
||||
*/
|
||||
delta = step >> 3;
|
||||
if (nybble & 0x04)
|
||||
if (nybble & 0x04) {
|
||||
delta += step;
|
||||
if (nybble & 0x02)
|
||||
}
|
||||
if (nybble & 0x02) {
|
||||
delta += step >> 1;
|
||||
if (nybble & 0x01)
|
||||
}
|
||||
if (nybble & 0x01) {
|
||||
delta += step >> 2;
|
||||
if (nybble & 0x08)
|
||||
}
|
||||
if (nybble & 0x08) {
|
||||
delta = -delta;
|
||||
}
|
||||
|
||||
sample = lastsample + delta;
|
||||
|
||||
|
||||
@@ -441,7 +441,7 @@ SDL_bool aaudio_DetectBrokenPlayState( void )
|
||||
int64_t framePosition, timeNanoseconds;
|
||||
aaudio_result_t res;
|
||||
|
||||
if ( !audioDevice || !audioDevice->hidden ) {
|
||||
if (audioDevice == NULL || !audioDevice->hidden ) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ get_audio_device(void *handle, const int channels)
|
||||
const char *device;
|
||||
|
||||
if (handle != NULL) {
|
||||
return (const char *) handle;
|
||||
return (const char *)handle;
|
||||
}
|
||||
|
||||
/* !!! FIXME: we also check "SDL_AUDIO_DEVICE_NAME" at the higher level. */
|
||||
@@ -401,8 +401,7 @@ ALSA_PlayDevice(_THIS)
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (status == 0) {
|
||||
} else if (status == 0) {
|
||||
/* No frames were written (no available space in pcm device).
|
||||
Allow other threads to catch up. */
|
||||
Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq;
|
||||
@@ -417,7 +416,7 @@ ALSA_PlayDevice(_THIS)
|
||||
static Uint8 *
|
||||
ALSA_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
return this->hidden->mixbuf;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -441,8 +440,7 @@ ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
||||
if (status == -EAGAIN) {
|
||||
ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time);
|
||||
status = 0;
|
||||
}
|
||||
else if (status < 0) {
|
||||
} else if (status < 0) {
|
||||
/*printf("ALSA: capture error %d\n", status);*/
|
||||
status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
|
||||
if (status < 0) {
|
||||
@@ -503,7 +501,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
|
||||
status = ALSA_snd_pcm_hw_params_set_period_size_near(
|
||||
this->hidden->pcm_handle, hwparams, &persize, NULL);
|
||||
if ( status < 0 ) {
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Need to at least double buffer */
|
||||
@@ -511,19 +509,19 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
|
||||
status = ALSA_snd_pcm_hw_params_set_periods_min(
|
||||
this->hidden->pcm_handle, hwparams, &periods, NULL);
|
||||
if ( status < 0 ) {
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = ALSA_snd_pcm_hw_params_set_periods_first(
|
||||
this->hidden->pcm_handle, hwparams, &periods, NULL);
|
||||
if ( status < 0 ) {
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* "set" the hardware with the desired parameters */
|
||||
status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams);
|
||||
if ( status < 0 ) {
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
this->spec.samples = persize;
|
||||
@@ -539,7 +537,7 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
|
||||
persize, periods, bufsize);
|
||||
}
|
||||
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -575,8 +573,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
|
||||
SND_PCM_NONBLOCK);
|
||||
|
||||
if (status < 0) {
|
||||
return SDL_SetError("ALSA: Couldn't open audio device: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("ALSA: Couldn't open audio device: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
|
||||
this->hidden->pcm_handle = pcm_handle;
|
||||
@@ -585,16 +582,14 @@ ALSA_OpenDevice(_THIS, const char *devname)
|
||||
snd_pcm_hw_params_alloca(&hwparams);
|
||||
status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
|
||||
if (status < 0) {
|
||||
return SDL_SetError("ALSA: Couldn't get hardware config: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("ALSA: Couldn't get hardware config: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
|
||||
/* SDL only uses interleaved sample output */
|
||||
status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||
if (status < 0) {
|
||||
return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("ALSA: Couldn't set interleaved access: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
|
||||
/* Try for a closest match on audio format */
|
||||
@@ -676,8 +671,7 @@ ALSA_OpenDevice(_THIS, const char *devname)
|
||||
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
|
||||
&rate, NULL);
|
||||
if (status < 0) {
|
||||
return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("ALSA: Couldn't set audio frequency: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
this->spec.freq = rate;
|
||||
|
||||
@@ -691,24 +685,20 @@ ALSA_OpenDevice(_THIS, const char *devname)
|
||||
snd_pcm_sw_params_alloca(&swparams);
|
||||
status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
|
||||
if (status < 0) {
|
||||
return SDL_SetError("ALSA: Couldn't get software config: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("ALSA: Couldn't get software config: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
|
||||
if (status < 0) {
|
||||
return SDL_SetError("Couldn't set minimum available samples: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("Couldn't set minimum available samples: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
status =
|
||||
ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
|
||||
if (status < 0) {
|
||||
return SDL_SetError("ALSA: Couldn't set start threshold: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("ALSA: Couldn't set start threshold: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
|
||||
if (status < 0) {
|
||||
return SDL_SetError("Couldn't set software audio parameters: %s",
|
||||
ALSA_snd_strerror(status));
|
||||
return SDL_SetError("Couldn't set software audio parameters: %s", ALSA_snd_strerror(status));
|
||||
}
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
@@ -749,7 +739,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
|
||||
char *handle = NULL;
|
||||
char *ptr;
|
||||
|
||||
if (!dev) {
|
||||
if (dev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -759,7 +749,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 */
|
||||
if (hint) {
|
||||
desc = ALSA_snd_device_name_get_hint(hint, "DESC");
|
||||
if (!desc) {
|
||||
if (desc == NULL) {
|
||||
SDL_free(dev);
|
||||
return;
|
||||
}
|
||||
@@ -779,7 +769,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);*/
|
||||
|
||||
handle = SDL_strdup(name);
|
||||
if (!handle) {
|
||||
if (handle == NULL) {
|
||||
if (hint) {
|
||||
free(desc);
|
||||
}
|
||||
@@ -792,8 +782,9 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
|
||||
* enumeration time
|
||||
*/
|
||||
SDL_AddAudioDevice(iscapture, desc, NULL, handle);
|
||||
if (hint)
|
||||
if (hint) {
|
||||
free(desc);
|
||||
}
|
||||
dev->name = handle;
|
||||
dev->iscapture = iscapture;
|
||||
dev->next = *pSeen;
|
||||
@@ -832,7 +823,7 @@ ALSA_HotplugIteration(void)
|
||||
if we can find a preferred prefix for the system. */
|
||||
for (i = 0; hints[i]; i++) {
|
||||
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
||||
if (!name) {
|
||||
if (name == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -861,17 +852,17 @@ ALSA_HotplugIteration(void)
|
||||
char *name;
|
||||
|
||||
/* 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. */
|
||||
}
|
||||
|
||||
name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
||||
if (!name) {
|
||||
if (name == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 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");
|
||||
const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
|
||||
const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
|
||||
@@ -896,8 +887,12 @@ ALSA_HotplugIteration(void)
|
||||
}
|
||||
dev->next = seen;
|
||||
seen = dev;
|
||||
if (isinput) have_input = SDL_TRUE;
|
||||
if (isoutput) have_output = SDL_TRUE;
|
||||
if (isinput) {
|
||||
have_input = SDL_TRUE;
|
||||
}
|
||||
if (isoutput) {
|
||||
have_output = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
prev = dev;
|
||||
}
|
||||
|
||||
@@ -147,26 +147,24 @@ void ANDROIDAUDIO_PauseDevices(void)
|
||||
{
|
||||
/* TODO: Handle multiple devices? */
|
||||
struct SDL_PrivateAudioData *private;
|
||||
if(audioDevice != NULL && audioDevice->hidden != NULL) {
|
||||
if (audioDevice != NULL && audioDevice->hidden != NULL) {
|
||||
private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
|
||||
if (SDL_AtomicGet(&audioDevice->paused)) {
|
||||
/* The device is already paused, leave it alone */
|
||||
private->resume = SDL_FALSE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SDL_LockMutex(audioDevice->mixer_lock);
|
||||
SDL_AtomicSet(&audioDevice->paused, 1);
|
||||
private->resume = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if(captureDevice != NULL && captureDevice->hidden != NULL) {
|
||||
if (captureDevice != NULL && captureDevice->hidden != NULL) {
|
||||
private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
|
||||
if (SDL_AtomicGet(&captureDevice->paused)) {
|
||||
/* The device is already paused, leave it alone */
|
||||
private->resume = SDL_FALSE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SDL_LockMutex(captureDevice->mixer_lock);
|
||||
SDL_AtomicSet(&captureDevice->paused, 1);
|
||||
private->resume = SDL_TRUE;
|
||||
@@ -179,7 +177,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
|
||||
{
|
||||
/* TODO: Handle multiple devices? */
|
||||
struct SDL_PrivateAudioData *private;
|
||||
if(audioDevice != NULL && audioDevice->hidden != NULL) {
|
||||
if (audioDevice != NULL && audioDevice->hidden != NULL) {
|
||||
private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
|
||||
if (private->resume) {
|
||||
SDL_AtomicSet(&audioDevice->paused, 0);
|
||||
@@ -188,7 +186,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
|
||||
}
|
||||
}
|
||||
|
||||
if(captureDevice != NULL && captureDevice->hidden != NULL) {
|
||||
if (captureDevice != NULL && captureDevice->hidden != NULL) {
|
||||
private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
|
||||
if (private->resume) {
|
||||
SDL_AtomicSet(&captureDevice->paused, 0);
|
||||
|
||||
@@ -296,7 +296,7 @@ DSOUND_GetDeviceBuf(_THIS)
|
||||
}
|
||||
if (result != DS_OK) {
|
||||
SetDSerror("DirectSound GetCurrentPosition", result);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
cursor /= this->spec.size;
|
||||
#ifdef DEBUG_SOUND
|
||||
@@ -331,9 +331,9 @@ DSOUND_GetDeviceBuf(_THIS)
|
||||
}
|
||||
if (result != DS_OK) {
|
||||
SetDSerror("DirectSound Lock", result);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
return (this->hidden->locked_buf);
|
||||
return this->hidden->locked_buf;
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -68,7 +68,7 @@ DISKAUDIO_PlayDevice(_THIS)
|
||||
static Uint8 *
|
||||
DISKAUDIO_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (_this->hidden->mixbuf);
|
||||
return _this->hidden->mixbuf;
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -82,12 +82,13 @@ DSP_OpenDevice(_THIS, const char *devname)
|
||||
|
||||
/* Make sure fragment size stays a power of 2, or OSS fails. */
|
||||
/* 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;
|
||||
else if (this->spec.channels > 4)
|
||||
} else if (this->spec.channels > 4) {
|
||||
this->spec.channels = 4;
|
||||
else if (this->spec.channels > 2)
|
||||
} else if (this->spec.channels > 2) {
|
||||
this->spec.channels = 2;
|
||||
}
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
@@ -260,13 +261,13 @@ DSP_PlayDevice(_THIS)
|
||||
static Uint8 *
|
||||
DSP_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
return this->hidden->mixbuf;
|
||||
}
|
||||
|
||||
static int
|
||||
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
|
||||
|
||||
@@ -313,7 +313,7 @@ JACK_OpenDevice(_THIS, const char *devname)
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ NETBSDAUDIO_PlayDevice(_THIS)
|
||||
static Uint8 *
|
||||
NETBSDAUDIO_GetDeviceBuf(_THIS)
|
||||
{
|
||||
return (this->hidden->mixbuf);
|
||||
return this->hidden->mixbuf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -424,7 +424,7 @@ openslES_CreatePCMPlayer(_THIS)
|
||||
it can be done as described here:
|
||||
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;
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
|
||||
if (SDL_AUDIO_ISSIGNED(test_format)) {
|
||||
@@ -499,7 +499,7 @@ openslES_CreatePCMPlayer(_THIS)
|
||||
break;
|
||||
}
|
||||
|
||||
if(SDL_AUDIO_ISFLOAT(this->spec.format)) {
|
||||
if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
|
||||
/* Copy all setup into PCM EX structure */
|
||||
format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
|
||||
format_pcm_ex.endianness = format_pcm.endianness;
|
||||
|
||||
@@ -1065,7 +1065,7 @@ input_callback(void *data)
|
||||
}
|
||||
|
||||
pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
|
||||
if (!pw_buf) {
|
||||
if (pw_buf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1189,15 +1189,15 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
|
||||
|
||||
/* Get the hints for the application name, stream name and role */
|
||||
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);
|
||||
if (!app_name || *app_name == '\0') {
|
||||
if (app_name == NULL || *app_name == '\0') {
|
||||
app_name = "SDL Application";
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
@@ -1206,7 +1206,7 @@ PIPEWIRE_OpenDevice(_THIS, const char *devname)
|
||||
* but 'Game' seems more appropriate for the majority of SDL applications.
|
||||
*/
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
@@ -156,8 +156,9 @@ static void PS2AUDIO_Deinitialize(void)
|
||||
|
||||
static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
if(init_audio_driver() < 0)
|
||||
if (init_audio_driver() < 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = PS2AUDIO_OpenDevice;
|
||||
|
||||
@@ -105,7 +105,7 @@ PSPAUDIO_OpenDevice(_THIS, const char *devname)
|
||||
|
||||
static void PSPAUDIO_PlayDevice(_THIS)
|
||||
{
|
||||
if (this->spec.freq != 44100){
|
||||
if (this->spec.freq != 44100) {
|
||||
Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
|
||||
SDL_assert(this->spec.channels == 2);
|
||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, mixbuf);
|
||||
@@ -131,7 +131,7 @@ static Uint8 *PSPAUDIO_GetDeviceBuf(_THIS)
|
||||
static void PSPAUDIO_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden->channel >= 0) {
|
||||
if (this->spec.freq != 44100){
|
||||
if (this->spec.freq != 44100) {
|
||||
sceAudioSRCChRelease();
|
||||
} else {
|
||||
sceAudioChRelease(this->hidden->channel);
|
||||
|
||||
@@ -53,17 +53,11 @@ static SDL_bool include_monitors = SDL_FALSE;
|
||||
#if (PA_API_VERSION < 12)
|
||||
/** 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) {
|
||||
return
|
||||
x == PA_CONTEXT_CONNECTING ||
|
||||
x == PA_CONTEXT_AUTHORIZING ||
|
||||
x == PA_CONTEXT_SETTING_NAME ||
|
||||
x == PA_CONTEXT_READY;
|
||||
return 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 */
|
||||
static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
|
||||
return
|
||||
x == PA_STREAM_CREATING ||
|
||||
x == PA_STREAM_READY;
|
||||
return x == PA_STREAM_CREATING || x == PA_STREAM_READY;
|
||||
}
|
||||
#endif /* pulseaudio <= 0.9.10 */
|
||||
|
||||
@@ -312,7 +306,7 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
|
||||
SDL_assert(mainloop_api); /* this never fails, right? */
|
||||
|
||||
context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
|
||||
if (!context) {
|
||||
if (context == NULL) {
|
||||
PULSEAUDIO_pa_mainloop_free(mainloop);
|
||||
return SDL_SetError("pa_context_new() failed");
|
||||
}
|
||||
@@ -545,7 +539,7 @@ FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *h
|
||||
SinkDeviceNameCallback, &h->device_name));
|
||||
}
|
||||
|
||||
return (h->device_name != NULL);
|
||||
return h->device_name != NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -81,7 +81,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
|
||||
}
|
||||
}
|
||||
|
||||
if(!test_format) {
|
||||
if (!test_format) {
|
||||
return SDL_SetError("Unsupported audio format");
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
|
||||
format = SCE_AUDIO_OUT_MODE_STEREO;
|
||||
}
|
||||
|
||||
if(this->spec.freq < 48000) {
|
||||
if (this->spec.freq < 48000) {
|
||||
port = SCE_AUDIO_OUT_PORT_TYPE_BGM;
|
||||
}
|
||||
|
||||
|
||||
@@ -389,8 +389,7 @@ WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
|
||||
if (SDL_wcscmp(i->str, devid) == 0) {
|
||||
if (prev) {
|
||||
prev->next = next;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
deviceid_list = next;
|
||||
}
|
||||
SDL_RemoveAudioDevice(iscapture, i->str);
|
||||
@@ -421,7 +420,7 @@ WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTENS
|
||||
}
|
||||
|
||||
devidlist = (DevIdList *)SDL_malloc(sizeof(*devidlist));
|
||||
if (!devidlist) {
|
||||
if (devidlist == NULL) {
|
||||
return; /* oh well. */
|
||||
}
|
||||
|
||||
|
||||
@@ -734,7 +734,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
|
||||
library_file = (*env)->GetStringUTFChars(env, library, NULL);
|
||||
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.
|
||||
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, '/');
|
||||
@@ -777,7 +777,7 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
|
||||
}
|
||||
(*env)->DeleteLocalRef(env, string);
|
||||
}
|
||||
if (!arg) {
|
||||
if (arg == NULL) {
|
||||
arg = SDL_strdup("");
|
||||
}
|
||||
argv[argc++] = arg;
|
||||
@@ -874,8 +874,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
|
||||
{
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
|
||||
if (Android_Window)
|
||||
{
|
||||
if (Android_Window) {
|
||||
Android_SendResize(Android_Window);
|
||||
}
|
||||
|
||||
@@ -890,8 +889,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)(
|
||||
|
||||
displayOrientation = (SDL_DisplayOrientation)orientation;
|
||||
|
||||
if (Android_Window)
|
||||
{
|
||||
if (Android_Window) {
|
||||
SDL_VideoDisplay *display = SDL_GetDisplay(0);
|
||||
SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
|
||||
}
|
||||
@@ -1000,8 +998,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, j
|
||||
{
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
|
||||
if (Android_Window)
|
||||
{
|
||||
if (Android_Window) {
|
||||
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
|
||||
|
||||
data->native_window = Android_JNI_GetNativeWindow();
|
||||
@@ -1019,8 +1016,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
if (Android_Window)
|
||||
{
|
||||
if (Android_Window) {
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
|
||||
|
||||
@@ -1045,8 +1041,7 @@ retry:
|
||||
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
|
||||
if (Android_Window)
|
||||
{
|
||||
if (Android_Window) {
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
|
||||
|
||||
@@ -1880,7 +1875,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
|
||||
|
||||
if (result > 0) {
|
||||
/* Number of chuncks */
|
||||
return (result / size);
|
||||
return result / size;
|
||||
} else {
|
||||
/* Error or EOF */
|
||||
return result;
|
||||
@@ -2265,7 +2260,7 @@ void *SDL_AndroidGetActivity(void)
|
||||
/* See SDL_system.h for caveats on using this function. */
|
||||
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
if (!env) {
|
||||
if (env == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2319,7 +2314,7 @@ const char * SDL_AndroidGetInternalStoragePath(void)
|
||||
{
|
||||
static char *s_AndroidInternalFilesPath = NULL;
|
||||
|
||||
if (!s_AndroidInternalFilesPath) {
|
||||
if (s_AndroidInternalFilesPath == NULL) {
|
||||
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
|
||||
jmethodID mid;
|
||||
jobject context;
|
||||
@@ -2412,7 +2407,7 @@ const char * SDL_AndroidGetExternalStoragePath(void)
|
||||
{
|
||||
static char *s_AndroidExternalFilesPath = NULL;
|
||||
|
||||
if (!s_AndroidExternalFilesPath) {
|
||||
if (s_AndroidExternalFilesPath == NULL) {
|
||||
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
|
||||
jmethodID mid;
|
||||
jobject context;
|
||||
|
||||
@@ -68,7 +68,7 @@ struct SDL_EVDEV_keyboard_state
|
||||
|
||||
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;
|
||||
@@ -96,7 +96,9 @@ static void kbd_cleanup(void)
|
||||
SDL_zero(mData);
|
||||
mData.operation = MOUSE_SHOW;
|
||||
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_MOUSECTL, &mData);
|
||||
}
|
||||
@@ -152,13 +154,14 @@ static void kbd_unregister_emerg_cleanup()
|
||||
old_action_p = &(old_sigaction[signum]);
|
||||
|
||||
/* Examine current signal action */
|
||||
if (sigaction(signum, NULL, &cur_action))
|
||||
if (sigaction(signum, NULL, &cur_action)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check if action installed and not modifed */
|
||||
if (!(cur_action.sa_flags & SA_SIGINFO)
|
||||
|| cur_action.sa_sigaction != &kbd_cleanup_signal_action)
|
||||
if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Restore original action */
|
||||
sigaction(signum, old_action_p, NULL);
|
||||
@@ -202,16 +205,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
|
||||
struct sigaction new_action;
|
||||
signum = fatal_signals[tabidx];
|
||||
old_action_p = &(old_sigaction[signum]);
|
||||
if (sigaction(signum, NULL, old_action_p))
|
||||
if (sigaction(signum, NULL, old_action_p)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Skip SIGHUP and SIGPIPE if handler is already installed
|
||||
* - assume the handler will do the cleanup
|
||||
*/
|
||||
if ((signum == SIGHUP || signum == SIGPIPE)
|
||||
&& (old_action_p->sa_handler != SIG_DFL
|
||||
|| (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
|
||||
if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
new_action = *old_action_p;
|
||||
new_action.sa_flags |= SA_SIGINFO;
|
||||
@@ -231,7 +234,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
SDL_zero(mData);
|
||||
mData.operation = MOUSE_HIDE;
|
||||
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
|
||||
if (!kbd) {
|
||||
if (kbd == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -253,8 +256,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
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);
|
||||
kbd->accents = &accentmap_default_us_acc;
|
||||
}
|
||||
@@ -262,8 +264,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
|
||||
/* Set the keyboard in XLATE mode and load the keymaps */
|
||||
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);
|
||||
kbd->key_map = &keymap_default_us_acc;
|
||||
}
|
||||
@@ -275,8 +276,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
ioctl(kbd->console_fd, CONS_RELKBD, 1ul);
|
||||
SDL_asprintf(&devicePath, "/dev/kbd%d", kbd->kbInfo->kb_index);
|
||||
kbd->keyboard_fd = open(devicePath, O_WRONLY | O_CLOEXEC);
|
||||
if (kbd->keyboard_fd == -1)
|
||||
{
|
||||
if (kbd->keyboard_fd == -1) {
|
||||
// Give keyboard back.
|
||||
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
|
||||
kbd->keyboard_fd = kbd->console_fd;
|
||||
@@ -289,8 +289,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
kbd_register_emerg_cleanup(kbd);
|
||||
}
|
||||
SDL_free(devicePath);
|
||||
}
|
||||
else kbd->keyboard_fd = kbd->console_fd;
|
||||
} else kbd->keyboard_fd = kbd->console_fd;
|
||||
}
|
||||
|
||||
return kbd;
|
||||
@@ -301,7 +300,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
struct mouse_info mData;
|
||||
|
||||
if (!kbd) {
|
||||
if (kbd == NULL) {
|
||||
return;
|
||||
}
|
||||
SDL_zero(mData);
|
||||
@@ -315,8 +314,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
|
||||
ioctl(kbd->keyboard_fd, KDSKBMODE, kbd->old_kbd_mode);
|
||||
|
||||
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.
|
||||
ioctl(kbd->console_fd, CONS_SETKBD, (unsigned long)(kbd->kbInfo->kb_index));
|
||||
}
|
||||
@@ -347,10 +345,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
|
||||
put_queue(kbd, 0xc0 | (c >> 6));
|
||||
put_queue(kbd, 0x80 | (c & 0x3f));
|
||||
} else if (c < 0x10000) {
|
||||
if (c >= 0xD800 && c < 0xE000)
|
||||
if (c >= 0xD800 && c < 0xE000) {
|
||||
return;
|
||||
if (c == 0xFFFF)
|
||||
}
|
||||
if (c == 0xFFFF) {
|
||||
return;
|
||||
}
|
||||
/* 1110**** 10****** 10****** */
|
||||
put_queue(kbd, 0xe0 | (c >> 12));
|
||||
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
|
||||
@@ -379,13 +379,14 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
|
||||
kbd->diacr = 0;
|
||||
|
||||
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) {
|
||||
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;
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -416,11 +417,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)
|
||||
{
|
||||
if (up_flag)
|
||||
return; /* no action, if this is a key release */
|
||||
if (up_flag) {
|
||||
return; /* no action, if this is a key release */
|
||||
}
|
||||
|
||||
if (kbd->diacr)
|
||||
if (kbd->diacr) {
|
||||
value = handle_diacr(kbd, value);
|
||||
}
|
||||
|
||||
if (kbd->dead_key_next) {
|
||||
kbd->dead_key_next = SDL_FALSE;
|
||||
@@ -450,8 +453,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
|
||||
* handle the case that two shift or control
|
||||
* keys are depressed simultaneously
|
||||
*/
|
||||
if (kbd->shift_down[value])
|
||||
if (kbd->shift_down[value]) {
|
||||
kbd->shift_down[value]--;
|
||||
}
|
||||
} else
|
||||
kbd->shift_down[value]++;
|
||||
|
||||
@@ -477,7 +481,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
|
||||
|
||||
key_map = *kbd->key_map;
|
||||
|
||||
if (!kbd) {
|
||||
if (kbd == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -488,10 +492,10 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
|
||||
/* These constitute unprintable language-related keys, so ignore them. */
|
||||
return;
|
||||
}
|
||||
if (keycode > 95)
|
||||
if (keycode > 95) {
|
||||
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;
|
||||
}
|
||||
keysym = key_map.key[keycode];
|
||||
@@ -500,18 +504,21 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
map_from_key_sym = keysym.map[final_key_state];
|
||||
if ((keysym.spcl & (0x80 >> final_key_state)) || (map_from_key_sym & SPCLKEY)) {
|
||||
/* Special function.*/
|
||||
if (map_from_key_sym == 0)
|
||||
return; /* Nothing to do. */
|
||||
if (map_from_key_sym & SPCLKEY)
|
||||
if (map_from_key_sym & SPCLKEY) {
|
||||
map_from_key_sym &= ~SPCLKEY;
|
||||
}
|
||||
if (map_from_key_sym >= F_ACC && map_from_key_sym <= L_ACC) {
|
||||
/* Accent function.*/
|
||||
unsigned int accent_index = map_from_key_sym - F_ACC;
|
||||
@@ -525,36 +532,50 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
|
||||
break;
|
||||
case LSHA: /* left 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 RSH: /* right shift */
|
||||
k_shift(kbd, 0, down == 0);
|
||||
break;
|
||||
case LCTRA: /* left 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 RCTR: /* right ctrl */
|
||||
k_shift(kbd, 1, down == 0);
|
||||
break;
|
||||
case LALTA: /* left 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 RALT: /* right alt */
|
||||
k_shift(kbd, 2, down == 0);
|
||||
break;
|
||||
case ALK: /* alt lock */
|
||||
if (down == 1) chg_vc_kbd_led(kbd, ALKED);
|
||||
if (down == 1) {
|
||||
chg_vc_kbd_led(kbd, ALKED);
|
||||
}
|
||||
break;
|
||||
case CLK: /* caps lock*/
|
||||
if (down == 1) chg_vc_kbd_led(kbd, CLKED);
|
||||
if (down == 1) {
|
||||
chg_vc_kbd_led(kbd, CLKED);
|
||||
}
|
||||
break;
|
||||
case NLK: /* num lock */
|
||||
if (down == 1) chg_vc_kbd_led(kbd, NLKED);
|
||||
if (down == 1) {
|
||||
chg_vc_kbd_led(kbd, NLKED);
|
||||
}
|
||||
break;
|
||||
case SLK: /* scroll lock */
|
||||
if (down == 1) chg_vc_kbd_led(kbd, SLKED);
|
||||
if (down == 1) {
|
||||
chg_vc_kbd_led(kbd, SLKED);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
@@ -109,13 +109,13 @@ SDL_GDKRunApp(SDL_main_func mainFunction, void *reserved)
|
||||
|
||||
/* Parse it into argv and argc */
|
||||
argv = (char **) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (argc + 1) * sizeof(*argv));
|
||||
if (!argv) {
|
||||
if (argv == NULL) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
for (i = 0; i < argc; ++i) {
|
||||
DWORD len;
|
||||
char *arg = WIN_StringToUTF8W(argvw[i]);
|
||||
if (!arg) {
|
||||
if (arg == NULL) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
len = (DWORD) SDL_strlen(arg);
|
||||
|
||||
+15
-10
@@ -201,7 +201,7 @@ SDL_DBus_Quit(void)
|
||||
SDL_DBusContext *
|
||||
SDL_DBus_GetContext(void)
|
||||
{
|
||||
if (!dbus_handle || !dbus.session_conn) {
|
||||
if (dbus_handle == NULL || !dbus.session_conn) {
|
||||
SDL_DBus_Init();
|
||||
}
|
||||
|
||||
@@ -379,20 +379,25 @@ SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, cons
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key))
|
||||
if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value))
|
||||
if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (!dbus.message_iter_close_container(&iterEntry, &iterValue)
|
||||
|| !dbus.message_iter_close_container(&iterDict, &iterEntry)
|
||||
@@ -439,12 +444,12 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
const char *key = "reason";
|
||||
const char *reply = NULL;
|
||||
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
|
||||
if (!reason || !reason[0]) {
|
||||
if (reason == NULL || !reason[0]) {
|
||||
reason = default_inhibit_reason;
|
||||
}
|
||||
|
||||
msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit");
|
||||
if (!msg) {
|
||||
if (msg == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -481,10 +486,10 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
if (inhibit) {
|
||||
const char *app = SDL_GetHint(SDL_HINT_APP_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";
|
||||
}
|
||||
if (!reason || !reason[0]) {
|
||||
if (reason == NULL || !reason[0]) {
|
||||
reason = default_inhibit_reason;
|
||||
}
|
||||
|
||||
|
||||
+52
-32
@@ -188,14 +188,14 @@ SDL_EVDEV_Init(void)
|
||||
ROM. */
|
||||
char* rest = (char*) devices;
|
||||
char* spec;
|
||||
while ((spec = strtok_r(rest, ",", &rest))) {
|
||||
while ((spec = SDL_strtokr(rest, ",", &rest))) {
|
||||
char* endofcls = 0;
|
||||
long cls = strtol(spec, &endofcls, 0);
|
||||
if (endofcls)
|
||||
long cls = SDL_strtol(spec, &endofcls, 0);
|
||||
if (endofcls) {
|
||||
SDL_EVDEV_device_added(endofcls + 1, cls);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* TODO: Scan the devices manually, like a caveman */
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,7 @@ SDL_EVDEV_Quit(void)
|
||||
SDL_EVDEV_kbd_quit(_this->kbd);
|
||||
|
||||
/* Remove existing devices */
|
||||
while(_this->first != NULL) {
|
||||
while (_this->first != NULL) {
|
||||
SDL_EVDEV_device_removed(_this->first->path);
|
||||
}
|
||||
|
||||
@@ -252,11 +252,13 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
|
||||
|
||||
switch(udev_event) {
|
||||
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;
|
||||
}
|
||||
|
||||
if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK))
|
||||
if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_EVDEV_device_added(dev_path, udev_class);
|
||||
break;
|
||||
@@ -341,13 +343,15 @@ SDL_EVDEV_Poll(void)
|
||||
case EV_ABS:
|
||||
switch(events[i].code) {
|
||||
case ABS_MT_SLOT:
|
||||
if (!item->is_touchscreen) /* FIXME: temp hack */
|
||||
if (!item->is_touchscreen) { /* FIXME: temp hack */
|
||||
break;
|
||||
}
|
||||
item->touchscreen_data->current_slot = events[i].value;
|
||||
break;
|
||||
case ABS_MT_TRACKING_ID:
|
||||
if (!item->is_touchscreen) /* FIXME: temp hack */
|
||||
if (!item->is_touchscreen) { /* FIXME: temp hack */
|
||||
break;
|
||||
}
|
||||
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].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
|
||||
@@ -356,24 +360,27 @@ SDL_EVDEV_Poll(void)
|
||||
}
|
||||
break;
|
||||
case ABS_MT_POSITION_X:
|
||||
if (!item->is_touchscreen) /* FIXME: temp hack */
|
||||
if (!item->is_touchscreen) { /* FIXME: temp hack */
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
|
||||
}
|
||||
break;
|
||||
case ABS_MT_POSITION_Y:
|
||||
if (!item->is_touchscreen) /* FIXME: temp hack */
|
||||
if (!item->is_touchscreen) { /* FIXME: temp hack */
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
|
||||
}
|
||||
break;
|
||||
case ABS_MT_PRESSURE:
|
||||
if (!item->is_touchscreen) /* FIXME: temp hack */
|
||||
if (!item->is_touchscreen) { /* FIXME: temp hack */
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
|
||||
@@ -381,8 +388,9 @@ SDL_EVDEV_Poll(void)
|
||||
break;
|
||||
case ABS_X:
|
||||
if (item->is_touchscreen) {
|
||||
if (item->touchscreen_data->max_slots != 1)
|
||||
if (item->touchscreen_data->max_slots != 1) {
|
||||
break;
|
||||
}
|
||||
item->touchscreen_data->slots[0].x = events[i].value;
|
||||
} else if (!item->relative_mouse) {
|
||||
/* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
|
||||
@@ -391,8 +399,9 @@ SDL_EVDEV_Poll(void)
|
||||
break;
|
||||
case ABS_Y:
|
||||
if (item->is_touchscreen) {
|
||||
if (item->touchscreen_data->max_slots != 1)
|
||||
if (item->touchscreen_data->max_slots != 1) {
|
||||
break;
|
||||
}
|
||||
item->touchscreen_data->slots[0].y = events[i].value;
|
||||
} else if (!item->relative_mouse) {
|
||||
/* FIXME: Normalize to input device's reported input range (EVIOCGABS) */
|
||||
@@ -406,24 +415,28 @@ SDL_EVDEV_Poll(void)
|
||||
case EV_REL:
|
||||
switch(events[i].code) {
|
||||
case REL_X:
|
||||
if (item->relative_mouse)
|
||||
if (item->relative_mouse) {
|
||||
item->mouse_x += events[i].value;
|
||||
}
|
||||
break;
|
||||
case REL_Y:
|
||||
if (item->relative_mouse)
|
||||
if (item->relative_mouse) {
|
||||
item->mouse_y += events[i].value;
|
||||
}
|
||||
break;
|
||||
case REL_WHEEL:
|
||||
if (!item->high_res_wheel)
|
||||
if (!item->high_res_wheel) {
|
||||
item->mouse_wheel += events[i].value;
|
||||
}
|
||||
break;
|
||||
case REL_WHEEL_HI_RES:
|
||||
SDL_assert(item->high_res_wheel);
|
||||
item->mouse_wheel += events[i].value;
|
||||
break;
|
||||
case REL_HWHEEL:
|
||||
if (!item->high_res_hwheel)
|
||||
if (!item->high_res_hwheel) {
|
||||
item->mouse_hwheel += events[i].value;
|
||||
}
|
||||
break;
|
||||
case REL_HWHEEL_HI_RES:
|
||||
SDL_assert(item->high_res_hwheel);
|
||||
@@ -449,10 +462,11 @@ SDL_EVDEV_Poll(void)
|
||||
item->mouse_wheel = item->mouse_hwheel = 0;
|
||||
}
|
||||
|
||||
if (!item->is_touchscreen) /* FIXME: temp hack */
|
||||
if (!item->is_touchscreen) { /* FIXME: temp hack */
|
||||
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) /
|
||||
(float)item->touchscreen_data->range_x;
|
||||
norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
|
||||
@@ -488,12 +502,14 @@ SDL_EVDEV_Poll(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (item->out_of_sync)
|
||||
if (item->out_of_sync) {
|
||||
item->out_of_sync = SDL_FALSE;
|
||||
}
|
||||
break;
|
||||
case SYN_DROPPED:
|
||||
if (item->is_touchscreen)
|
||||
if (item->is_touchscreen) {
|
||||
item->out_of_sync = SDL_TRUE;
|
||||
}
|
||||
SDL_EVDEV_sync_device(item);
|
||||
break;
|
||||
default:
|
||||
@@ -536,12 +552,14 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
|
||||
char name[64];
|
||||
struct input_absinfo abs_info;
|
||||
|
||||
if (!item->is_touchscreen)
|
||||
if (!item->is_touchscreen) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
|
||||
if (item->touchscreen_data == NULL)
|
||||
if (item->touchscreen_data == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
|
||||
if (ret < 0) {
|
||||
@@ -611,7 +629,7 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -630,8 +648,9 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
|
||||
|
||||
static void
|
||||
SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
|
||||
if (!item->is_touchscreen)
|
||||
if (!item->is_touchscreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_DelTouch(item->fd);
|
||||
SDL_free(item->touchscreen_data->slots);
|
||||
@@ -658,8 +677,9 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
size_t mt_req_size;
|
||||
|
||||
/* TODO: sync devices other than touchscreen */
|
||||
if (!item->is_touchscreen)
|
||||
if (!item->is_touchscreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
mt_req_size = sizeof(*mt_req_code) +
|
||||
sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
|
||||
@@ -677,7 +697,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
SDL_free(mt_req_code);
|
||||
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
|
||||
* finger and replacing it on the screen during the time we're out of sync,
|
||||
@@ -704,7 +724,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
SDL_free(mt_req_code);
|
||||
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 &&
|
||||
item->touchscreen_data->slots[i].x != mt_req_values[i]) {
|
||||
item->touchscreen_data->slots[i].x = mt_req_values[i];
|
||||
@@ -722,7 +742,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
SDL_free(mt_req_code);
|
||||
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 &&
|
||||
item->touchscreen_data->slots[i].y != mt_req_values[i]) {
|
||||
item->touchscreen_data->slots[i].y = mt_req_values[i];
|
||||
@@ -740,7 +760,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
SDL_free(mt_req_code);
|
||||
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 &&
|
||||
item->touchscreen_data->slots[i].pressure != mt_req_values[i]) {
|
||||
item->touchscreen_data->slots[i].pressure = mt_req_values[i];
|
||||
|
||||
@@ -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
|
||||
* those, consider it a keyboard device; do not test KEY_RESERVED, though */
|
||||
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 */
|
||||
}
|
||||
|
||||
return devclass;
|
||||
}
|
||||
|
||||
@@ -270,13 +270,14 @@ static void kbd_unregister_emerg_cleanup()
|
||||
old_action_p = &(old_sigaction[signum]);
|
||||
|
||||
/* Examine current signal action */
|
||||
if (sigaction(signum, NULL, &cur_action))
|
||||
if (sigaction(signum, NULL, &cur_action)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check if action installed and not modifed */
|
||||
if (!(cur_action.sa_flags & SA_SIGINFO)
|
||||
|| cur_action.sa_sigaction != &kbd_cleanup_signal_action)
|
||||
if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Restore original action */
|
||||
sigaction(signum, old_action_p, NULL);
|
||||
@@ -320,16 +321,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
|
||||
struct sigaction new_action;
|
||||
signum = fatal_signals[tabidx];
|
||||
old_action_p = &(old_sigaction[signum]);
|
||||
if (sigaction(signum, NULL, old_action_p))
|
||||
if (sigaction(signum, NULL, old_action_p)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Skip SIGHUP and SIGPIPE if handler is already installed
|
||||
* - assume the handler will do the cleanup
|
||||
*/
|
||||
if ((signum == SIGHUP || signum == SIGPIPE)
|
||||
&& (old_action_p->sa_handler != SIG_DFL
|
||||
|| (void (*)(int))old_action_p->sa_sigaction != SIG_DFL))
|
||||
if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
new_action = *old_action_p;
|
||||
new_action.sa_flags |= SA_SIGINFO;
|
||||
@@ -347,7 +348,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0};
|
||||
|
||||
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
|
||||
if (!kbd) {
|
||||
if (kbd == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -413,7 +414,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
void
|
||||
SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
if (!kbd) {
|
||||
if (kbd == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -461,10 +462,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
|
||||
put_queue(kbd, 0xc0 | (c >> 6));
|
||||
put_queue(kbd, 0x80 | (c & 0x3f));
|
||||
} else if (c < 0x10000) {
|
||||
if (c >= 0xD800 && c < 0xE000)
|
||||
if (c >= 0xD800 && c < 0xE000) {
|
||||
return;
|
||||
if (c == 0xFFFF)
|
||||
}
|
||||
if (c == 0xFFFF) {
|
||||
return;
|
||||
}
|
||||
/* 1110**** 10****** 10****** */
|
||||
put_queue(kbd, 0xe0 | (c >> 12));
|
||||
put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
|
||||
@@ -499,8 +502,9 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == ' ' || ch == d)
|
||||
if (ch == ' ' || ch == d) {
|
||||
return d;
|
||||
}
|
||||
|
||||
put_utf8(kbd, d);
|
||||
|
||||
@@ -554,24 +558,27 @@ static void fn_enter(SDL_EVDEV_keyboard_state *kbd)
|
||||
|
||||
static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
if (kbd->rep)
|
||||
if (kbd->rep) {
|
||||
return;
|
||||
}
|
||||
|
||||
chg_vc_kbd_led(kbd, K_CAPSLOCK);
|
||||
}
|
||||
|
||||
static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
if (kbd->rep)
|
||||
if (kbd->rep) {
|
||||
return;
|
||||
}
|
||||
|
||||
set_vc_kbd_led(kbd, K_CAPSLOCK);
|
||||
}
|
||||
|
||||
static void fn_num(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
if (!kbd->rep)
|
||||
if (!kbd->rep) {
|
||||
chg_vc_kbd_led(kbd, K_NUMLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
static void fn_compose(SDL_EVDEV_keyboard_state *kbd)
|
||||
@@ -589,12 +596,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)
|
||||
{
|
||||
if (up_flag)
|
||||
if (up_flag) {
|
||||
return;
|
||||
if (value >= SDL_arraysize(fn_handler))
|
||||
}
|
||||
if (value >= SDL_arraysize(fn_handler)) {
|
||||
return;
|
||||
if (fn_handler[value])
|
||||
}
|
||||
if (fn_handler[value]) {
|
||||
fn_handler[value](kbd);
|
||||
}
|
||||
}
|
||||
|
||||
static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
|
||||
@@ -603,11 +613,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)
|
||||
{
|
||||
if (up_flag)
|
||||
return; /* no action, if this is a key release */
|
||||
if (up_flag) {
|
||||
return; /* no action, if this is a key release */
|
||||
}
|
||||
|
||||
if (kbd->diacr)
|
||||
if (kbd->diacr) {
|
||||
value = handle_diacr(kbd, value);
|
||||
}
|
||||
|
||||
if (kbd->dead_key_next) {
|
||||
kbd->dead_key_next = SDL_FALSE;
|
||||
@@ -676,8 +688,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
|
||||
*/
|
||||
if (value == KVAL(K_CAPSSHIFT)) {
|
||||
value = KVAL(K_SHIFT);
|
||||
if (!up_flag)
|
||||
if (!up_flag) {
|
||||
clr_vc_kbd_led(kbd, K_CAPSLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
if (up_flag) {
|
||||
@@ -685,8 +698,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_
|
||||
* handle the case that two shift or control
|
||||
* keys are depressed simultaneously
|
||||
*/
|
||||
if (kbd->shift_down[value])
|
||||
if (kbd->shift_down[value]) {
|
||||
kbd->shift_down[value]--;
|
||||
}
|
||||
} else
|
||||
kbd->shift_down[value]++;
|
||||
|
||||
@@ -762,7 +776,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
|
||||
unsigned short *key_map;
|
||||
unsigned short keysym;
|
||||
|
||||
if (!kbd) {
|
||||
if (kbd == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -770,7 +784,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d
|
||||
|
||||
shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate;
|
||||
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 */
|
||||
kbd->shift_state = 0;
|
||||
kbd->slockstate = 0;
|
||||
|
||||
@@ -347,14 +347,30 @@ Fcitx_ModState(void)
|
||||
Uint32 fcitx_mods = 0;
|
||||
SDL_Keymod sdl_mods = SDL_GetModState();
|
||||
|
||||
if (sdl_mods & KMOD_SHIFT) fcitx_mods |= (1 << 0);
|
||||
if (sdl_mods & KMOD_CAPS) fcitx_mods |= (1 << 1);
|
||||
if (sdl_mods & KMOD_CTRL) 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);
|
||||
if (sdl_mods & KMOD_SHIFT) {
|
||||
fcitx_mods |= (1 << 0);
|
||||
}
|
||||
if (sdl_mods & KMOD_CAPS) {
|
||||
fcitx_mods |= (1 << 1);
|
||||
}
|
||||
if (sdl_mods & KMOD_CTRL) {
|
||||
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;
|
||||
}
|
||||
@@ -436,7 +452,7 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
|
||||
}
|
||||
|
||||
focused_win = SDL_GetKeyboardFocus();
|
||||
if (!focused_win) {
|
||||
if (focused_win == NULL) {
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
+48
-25
@@ -65,14 +65,30 @@ IBus_ModState(void)
|
||||
SDL_Keymod sdl_mods = SDL_GetModState();
|
||||
|
||||
/* Not sure about MOD3, MOD4 and HYPER mappings */
|
||||
if (sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK;
|
||||
if (sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_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_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;
|
||||
if (sdl_mods & KMOD_LSHIFT) {
|
||||
ibus_mods |= IBUS_SHIFT_MASK;
|
||||
}
|
||||
if (sdl_mods & KMOD_CAPS) {
|
||||
ibus_mods |= IBUS_LOCK_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_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;
|
||||
}
|
||||
@@ -99,7 +115,7 @@ IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *
|
||||
}
|
||||
|
||||
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_TRUE;
|
||||
@@ -249,13 +265,12 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
||||
|
||||
dbus->message_iter_init(msg, &iter);
|
||||
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);
|
||||
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);
|
||||
} else if (has_pos) {
|
||||
SDL_SendEditingText(text, pos, -1);
|
||||
@@ -299,15 +314,19 @@ IBus_ReadAddressFromFile(const char *file_path)
|
||||
FILE *addr_file;
|
||||
|
||||
addr_file = fopen(file_path, "r");
|
||||
if (!addr_file) {
|
||||
if (addr_file == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
|
||||
if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
|
||||
size_t sz = SDL_strlen(addr_buf);
|
||||
if (addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0;
|
||||
if (addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0;
|
||||
if (addr_buf[sz - 1] == '\n') {
|
||||
addr_buf[sz - 1] = 0;
|
||||
}
|
||||
if (addr_buf[sz - 2] == '\r') {
|
||||
addr_buf[sz - 2] = 0;
|
||||
}
|
||||
success = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
@@ -341,7 +360,7 @@ IBus_GetDBusAddressFilename(void)
|
||||
}
|
||||
|
||||
dbus = SDL_DBus_GetContext();
|
||||
if (!dbus) {
|
||||
if (dbus == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -355,7 +374,7 @@ IBus_GetDBusAddressFilename(void)
|
||||
and look up the address from a filepath using all those bits, eek. */
|
||||
disp_env = SDL_getenv("DISPLAY");
|
||||
|
||||
if (!disp_env || !*disp_env) {
|
||||
if (disp_env == NULL || !*disp_env) {
|
||||
display = SDL_strdup(":0.0");
|
||||
} else {
|
||||
display = SDL_strdup(disp_env);
|
||||
@@ -365,7 +384,7 @@ IBus_GetDBusAddressFilename(void)
|
||||
disp_num = SDL_strrchr(display, ':');
|
||||
screen_num = SDL_strrchr(display, '.');
|
||||
|
||||
if (!disp_num) {
|
||||
if (disp_num == NULL) {
|
||||
SDL_free(display);
|
||||
return NULL;
|
||||
}
|
||||
@@ -393,7 +412,7 @@ IBus_GetDBusAddressFilename(void)
|
||||
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
|
||||
} else {
|
||||
const char *home_env = SDL_getenv("HOME");
|
||||
if (!home_env || !*home_env) {
|
||||
if (home_env == NULL || !*home_env) {
|
||||
SDL_free(display);
|
||||
return NULL;
|
||||
}
|
||||
@@ -461,7 +480,7 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
|
||||
ibus_input_interface = IBUS_INPUT_INTERFACE;
|
||||
ibus_conn = dbus->connection_open_private(addr, NULL);
|
||||
|
||||
if (!ibus_conn) {
|
||||
if (ibus_conn == NULL) {
|
||||
return SDL_FALSE; /* oh well. */
|
||||
}
|
||||
|
||||
@@ -499,7 +518,9 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
|
||||
static SDL_bool
|
||||
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)) {
|
||||
return SDL_TRUE;
|
||||
@@ -517,7 +538,9 @@ IBus_CheckConnection(SDL_DBusContext *dbus)
|
||||
struct inotify_event *event = (struct inotify_event*) p;
|
||||
if (event->len > 0) {
|
||||
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) {
|
||||
file_updated = SDL_TRUE;
|
||||
@@ -553,7 +576,7 @@ SDL_IBus_Init(void)
|
||||
char *addr;
|
||||
char *addr_file_dir;
|
||||
|
||||
if (!addr_file) {
|
||||
if (addr_file == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -561,7 +584,7 @@ SDL_IBus_Init(void)
|
||||
ibus_addr_file = SDL_strdup(addr_file);
|
||||
|
||||
addr = IBus_ReadAddressFromFile(addr_file);
|
||||
if (!addr) {
|
||||
if (addr == NULL) {
|
||||
SDL_free(addr_file);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -700,7 +723,7 @@ SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
|
||||
}
|
||||
|
||||
focused_win = SDL_GetKeyboardFocus();
|
||||
if (!focused_win) {
|
||||
if (focused_win == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+17
-10
@@ -49,16 +49,17 @@ InitIME()
|
||||
const char *xmodifiers = SDL_getenv("XMODIFIERS");
|
||||
#endif
|
||||
|
||||
if (inited == SDL_TRUE)
|
||||
if (inited == SDL_TRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
inited = SDL_TRUE;
|
||||
|
||||
/* See if fcitx IME support is being requested */
|
||||
#ifdef HAVE_FCITX
|
||||
if (!SDL_IME_Init_Real &&
|
||||
if (SDL_IME_Init_Real == NULL &&
|
||||
((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_Quit_Real = SDL_Fcitx_Quit;
|
||||
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
|
||||
@@ -71,7 +72,7 @@ InitIME()
|
||||
|
||||
/* default to IBus */
|
||||
#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_Quit_Real = SDL_IBus_Quit;
|
||||
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
|
||||
@@ -109,29 +110,33 @@ SDL_IME_Init(void)
|
||||
void
|
||||
SDL_IME_Quit(void)
|
||||
{
|
||||
if (SDL_IME_Quit_Real)
|
||||
if (SDL_IME_Quit_Real) {
|
||||
SDL_IME_Quit_Real();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_SetFocus(SDL_bool focused)
|
||||
{
|
||||
if (SDL_IME_SetFocus_Real)
|
||||
if (SDL_IME_SetFocus_Real) {
|
||||
SDL_IME_SetFocus_Real(focused);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_Reset(void)
|
||||
{
|
||||
if (SDL_IME_Reset_Real)
|
||||
if (SDL_IME_Reset_Real) {
|
||||
SDL_IME_Reset_Real();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
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_FALSE;
|
||||
}
|
||||
@@ -139,15 +144,17 @@ SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
|
||||
void
|
||||
SDL_IME_UpdateTextRect(const SDL_Rect *rect)
|
||||
{
|
||||
if (SDL_IME_UpdateTextRect_Real)
|
||||
if (SDL_IME_UpdateTextRect_Real) {
|
||||
SDL_IME_UpdateTextRect_Real(rect);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_PumpEvents()
|
||||
{
|
||||
if (SDL_IME_PumpEvents_Real)
|
||||
if (SDL_IME_PumpEvents_Real) {
|
||||
SDL_IME_PumpEvents_Real();
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -120,20 +120,20 @@ rtkit_initialize()
|
||||
dbus_conn = get_rtkit_dbus_connection();
|
||||
|
||||
/* 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",
|
||||
DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
|
||||
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)) {
|
||||
rtkit_min_nice_level = -20;
|
||||
}
|
||||
|
||||
/* 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",
|
||||
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
|
||||
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)) {
|
||||
rtkit_max_realtime_priority = 99;
|
||||
}
|
||||
|
||||
/* 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",
|
||||
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
|
||||
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)) {
|
||||
rtkit_max_rttime_usec = 200000;
|
||||
}
|
||||
}
|
||||
@@ -172,8 +172,7 @@ rtkit_initialize_realtime_thread()
|
||||
|
||||
// Requirement #1: Set RLIMIT_RTTIME
|
||||
err = getrlimit(nLimit, &rlimit);
|
||||
if (err)
|
||||
{
|
||||
if (err) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -181,21 +180,18 @@ rtkit_initialize_realtime_thread()
|
||||
rlimit.rlim_max = rtkit_max_rttime_usec;
|
||||
rlimit.rlim_cur = rlimit.rlim_max / 2;
|
||||
err = setrlimit(nLimit, &rlimit);
|
||||
if (err)
|
||||
{
|
||||
if (err) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
// Requirement #2: Add SCHED_RESET_ON_FORK to the scheduler policy
|
||||
err = sched_getparam(nPid, &schedParam);
|
||||
if (err)
|
||||
{
|
||||
if (err) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
err = sched_setscheduler(nPid, nSchedPolicy, &schedParam);
|
||||
if (err)
|
||||
{
|
||||
if (err) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -213,13 +209,14 @@ rtkit_setpriority_nice(pid_t thread, int nice_level)
|
||||
pthread_once(&rtkit_initialize_once, rtkit_initialize);
|
||||
dbus_conn = get_rtkit_dbus_connection();
|
||||
|
||||
if (nice < rtkit_min_nice_level)
|
||||
if (nice < rtkit_min_nice_level) {
|
||||
nice = rtkit_min_nice_level;
|
||||
}
|
||||
|
||||
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
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_INVALID)) {
|
||||
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
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_INVALID)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
@@ -236,8 +233,9 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
|
||||
pthread_once(&rtkit_initialize_once, rtkit_initialize);
|
||||
dbus_conn = get_rtkit_dbus_connection();
|
||||
|
||||
if (priority > rtkit_max_realtime_priority)
|
||||
if (priority > rtkit_max_realtime_priority) {
|
||||
priority = rtkit_max_realtime_priority;
|
||||
}
|
||||
|
||||
// We always perform the thread state changes necessary for rtkit.
|
||||
// This wastes some system calls if the state is already set but
|
||||
@@ -247,10 +245,10 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
|
||||
// go through to determine whether it really needs to fail or not.
|
||||
rtkit_initialize_realtime_thread();
|
||||
|
||||
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
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_INVALID)) {
|
||||
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
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_INVALID)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
|
||||
@@ -119,7 +119,7 @@ SDL_UDEV_Init(void)
|
||||
|
||||
if (_this == NULL) {
|
||||
_this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
|
||||
if(_this == NULL) {
|
||||
if (_this == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -327,14 +327,13 @@ SDL_UDEV_LoadLibrary(void)
|
||||
#endif
|
||||
|
||||
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]);
|
||||
if (_this->udev_handle != NULL) {
|
||||
retval = SDL_UDEV_load_syms();
|
||||
if (retval < 0) {
|
||||
SDL_UDEV_UnloadLibrary();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -359,7 +358,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
|
||||
|
||||
SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
|
||||
value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
|
||||
if (!value) {
|
||||
if (value == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -394,7 +393,7 @@ guess_device_class(struct udev_device *dev)
|
||||
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);
|
||||
}
|
||||
if (!pdev) {
|
||||
if (pdev == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,14 +233,15 @@ static struct SDL_wscons_compose_tab_s {
|
||||
|
||||
static keysym_t ksym_upcase(keysym_t ksym)
|
||||
{
|
||||
if (ksym >= KS_f1 && ksym <= KS_f20)
|
||||
return(KS_F1 - KS_f1 + ksym);
|
||||
if (ksym >= KS_f1 && ksym <= KS_f20) {
|
||||
return KS_F1 - KS_f1 + ksym;
|
||||
}
|
||||
|
||||
if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff &&
|
||||
latin1_to_upper[ksym] != 0x00)
|
||||
return(latin1_to_upper[ksym]);
|
||||
if (KS_GROUP(ksym) == KS_GROUP_Ascii && ksym <= 0xff && latin1_to_upper[ksym] != 0x00) {
|
||||
return latin1_to_upper[ksym];
|
||||
}
|
||||
|
||||
return(ksym);
|
||||
return ksym;
|
||||
}
|
||||
static struct wscons_keycode_to_SDL {
|
||||
keysym_t sourcekey;
|
||||
@@ -414,7 +415,7 @@ static SDL_WSCONS_input_data* SDL_WSCONS_Init_Keyboard(const char* dev)
|
||||
#endif
|
||||
SDL_WSCONS_input_data* input = (SDL_WSCONS_input_data*)SDL_calloc(1, sizeof(SDL_WSCONS_input_data));
|
||||
|
||||
if (!input) {
|
||||
if (input == NULL) {
|
||||
return input;
|
||||
}
|
||||
input->fd = open(dev,O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
@@ -491,10 +492,12 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
|
||||
put_queue(input, 0xc0 | (c >> 6));
|
||||
put_queue(input, 0x80 | (c & 0x3f));
|
||||
} else if (c < 0x10000) {
|
||||
if (c >= 0xD800 && c <= 0xF500)
|
||||
if (c >= 0xD800 && c <= 0xF500) {
|
||||
return;
|
||||
if (c == 0xFFFF)
|
||||
}
|
||||
if (c == 0xFFFF) {
|
||||
return;
|
||||
}
|
||||
/* 1110**** 10****** 10****** */
|
||||
put_queue(input, 0xe0 | (c >> 12));
|
||||
put_queue(input, 0x80 | ((c >> 6) & 0x3f));
|
||||
@@ -511,7 +514,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)
|
||||
{
|
||||
if (KS_GROUP(ksym) == KS_GROUP_Keypad) {
|
||||
if (SDL_isprint(ksym & 0xFF)) ksym &= 0xFF;
|
||||
if (SDL_isprint(ksym & 0xFF)) {
|
||||
ksym &= 0xFF;
|
||||
}
|
||||
}
|
||||
switch(ksym) {
|
||||
case KS_Escape:
|
||||
@@ -569,7 +574,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
keysym_t *group;
|
||||
keysym_t ksym, result;
|
||||
|
||||
if (!input) return;
|
||||
if (input == NULL) {
|
||||
return;
|
||||
}
|
||||
if ((n = read(input->fd, events, sizeof(events))) > 0) {
|
||||
n /= sizeof(struct wscons_event);
|
||||
for (i = 0; i < n; i++) {
|
||||
@@ -578,21 +585,27 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
case WSCONS_EVENT_KEY_DOWN: {
|
||||
switch (input->keymap.map[events[i].value].group1[0]) {
|
||||
case KS_Hold_Screen: {
|
||||
if (input->lockheldstate[0] >= 1) break;
|
||||
if (input->lockheldstate[0] >= 1) {
|
||||
break;
|
||||
}
|
||||
input->ledstate ^= LED_SCR;
|
||||
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
|
||||
input->lockheldstate[0] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Num_Lock: {
|
||||
if (input->lockheldstate[1] >= 1) break;
|
||||
if (input->lockheldstate[1] >= 1) {
|
||||
break;
|
||||
}
|
||||
input->ledstate ^= LED_NUM;
|
||||
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
|
||||
input->lockheldstate[1] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Caps_Lock: {
|
||||
if (input->lockheldstate[2] >= 1) break;
|
||||
if (input->lockheldstate[2] >= 1) {
|
||||
break;
|
||||
}
|
||||
input->ledstate ^= LED_CAP;
|
||||
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
|
||||
input->lockheldstate[2] = 1;
|
||||
@@ -600,7 +613,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
}
|
||||
#ifndef __NetBSD__
|
||||
case KS_Mode_Lock: {
|
||||
if (input->lockheldstate[3] >= 1) break;
|
||||
if (input->lockheldstate[3] >= 1) {
|
||||
break;
|
||||
}
|
||||
input->ledstate ^= 1 << 4;
|
||||
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
|
||||
input->lockheldstate[3] = 1;
|
||||
@@ -608,50 +623,66 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
}
|
||||
#endif
|
||||
case KS_Shift_Lock: {
|
||||
if (input->lockheldstate[4] >= 1) break;
|
||||
if (input->lockheldstate[4] >= 1) {
|
||||
break;
|
||||
}
|
||||
input->ledstate ^= 1 << 5;
|
||||
ioctl(input->fd, WSKBDIO_SETLEDS, &input->ledstate);
|
||||
input->lockheldstate[4] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Shift_L: {
|
||||
if (input->shiftheldstate[0]) break;
|
||||
if (input->shiftheldstate[0]) {
|
||||
break;
|
||||
}
|
||||
input->shiftstate[0]++;
|
||||
input->shiftheldstate[0] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Shift_R: {
|
||||
if (input->shiftheldstate[1]) break;
|
||||
if (input->shiftheldstate[1]) {
|
||||
break;
|
||||
}
|
||||
input->shiftstate[0]++;
|
||||
input->shiftheldstate[1] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Alt_L: {
|
||||
if (input->shiftheldstate[2]) break;
|
||||
if (input->shiftheldstate[2]) {
|
||||
break;
|
||||
}
|
||||
input->shiftstate[1]++;
|
||||
input->shiftheldstate[2] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Alt_R: {
|
||||
if (input->shiftheldstate[3]) break;
|
||||
if (input->shiftheldstate[3]) {
|
||||
break;
|
||||
}
|
||||
input->shiftstate[1]++;
|
||||
input->shiftheldstate[3] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Control_L: {
|
||||
if (input->shiftheldstate[4]) break;
|
||||
if (input->shiftheldstate[4]) {
|
||||
break;
|
||||
}
|
||||
input->shiftstate[2]++;
|
||||
input->shiftheldstate[4] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Control_R: {
|
||||
if (input->shiftheldstate[5]) break;
|
||||
if (input->shiftheldstate[5]) {
|
||||
break;
|
||||
}
|
||||
input->shiftstate[2]++;
|
||||
input->shiftheldstate[5] = 1;
|
||||
break;
|
||||
}
|
||||
case KS_Mode_switch: {
|
||||
if (input->shiftheldstate[6]) break;
|
||||
if (input->shiftheldstate[6]) {
|
||||
break;
|
||||
}
|
||||
input->shiftstate[3]++;
|
||||
input->shiftheldstate[6] = 1;
|
||||
break;
|
||||
@@ -662,60 +693,84 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
case WSCONS_EVENT_KEY_UP: {
|
||||
switch(input->keymap.map[events[i].value].group1[0]) {
|
||||
case KS_Hold_Screen: {
|
||||
if (input->lockheldstate[0]) input->lockheldstate[0] = 0;
|
||||
if (input->lockheldstate[0]) {
|
||||
input->lockheldstate[0] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KS_Num_Lock: {
|
||||
if (input->lockheldstate[1]) input->lockheldstate[1] = 0;
|
||||
if (input->lockheldstate[1]) {
|
||||
input->lockheldstate[1] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KS_Caps_Lock: {
|
||||
if (input->lockheldstate[2]) input->lockheldstate[2] = 0;
|
||||
if (input->lockheldstate[2]) {
|
||||
input->lockheldstate[2] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#ifndef __NetBSD__
|
||||
case KS_Mode_Lock: {
|
||||
if (input->lockheldstate[3]) input->lockheldstate[3] = 0;
|
||||
if (input->lockheldstate[3]) {
|
||||
input->lockheldstate[3] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case KS_Shift_Lock: {
|
||||
if (input->lockheldstate[4]) input->lockheldstate[4] = 0;
|
||||
if (input->lockheldstate[4]) {
|
||||
input->lockheldstate[4] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KS_Shift_L: {
|
||||
input->shiftheldstate[0] = 0;
|
||||
if (input->shiftstate[0]) input->shiftstate[0]--;
|
||||
if (input->shiftstate[0]) {
|
||||
input->shiftstate[0]--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KS_Shift_R: {
|
||||
input->shiftheldstate[1] = 0;
|
||||
if (input->shiftstate[0]) input->shiftstate[0]--;
|
||||
if (input->shiftstate[0]) {
|
||||
input->shiftstate[0]--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KS_Alt_L: {
|
||||
input->shiftheldstate[2] = 0;
|
||||
if (input->shiftstate[1]) input->shiftstate[1]--;
|
||||
if (input->shiftstate[1]) {
|
||||
input->shiftstate[1]--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KS_Alt_R: {
|
||||
input->shiftheldstate[3] = 0;
|
||||
if (input->shiftstate[1]) input->shiftstate[1]--;
|
||||
if (input->shiftstate[1]) {
|
||||
input->shiftstate[1]--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KS_Control_L: {
|
||||
input->shiftheldstate[4] = 0;
|
||||
if (input->shiftstate[2]) input->shiftstate[2]--;
|
||||
if (input->shiftstate[2]) {
|
||||
input->shiftstate[2]--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KS_Control_R: {
|
||||
input->shiftheldstate[5] = 0;
|
||||
if (input->shiftstate[2]) input->shiftstate[2]--;
|
||||
if (input->shiftstate[2]) {
|
||||
input->shiftstate[2]--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KS_Mode_switch: {
|
||||
input->shiftheldstate[6] = 0;
|
||||
if (input->shiftstate[3]) input->shiftstate[3]--;
|
||||
if (input->shiftstate[3]) {
|
||||
input->shiftstate[3]--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -733,7 +788,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
else
|
||||
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)
|
||||
group = &input->keymap.map[events[i].value].group2[0];
|
||||
@@ -778,7 +835,9 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
} else result = ksym;
|
||||
break;
|
||||
}
|
||||
if (result == KS_voidSymbol) continue;
|
||||
if (result == KS_voidSymbol) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (input->composelen > 0) {
|
||||
if (input->composelen == 2 && group == &input->keymap.map[events[i].value].group2[0]) {
|
||||
@@ -809,21 +868,24 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
|
||||
if (KS_GROUP(result) == KS_GROUP_Ascii) {
|
||||
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;
|
||||
else if (result == KS_2)
|
||||
} else if (result == KS_2) {
|
||||
result = 0x00;
|
||||
else if (result >= KS_3 && result <= KS_7)
|
||||
} else if (result >= KS_3 && result <= KS_7) {
|
||||
result = KS_Escape + (result - KS_3);
|
||||
else if (result == KS_8)
|
||||
result = KS_Delete;
|
||||
} else if (result == KS_8) {
|
||||
result = KS_Delete;
|
||||
}
|
||||
}
|
||||
if (IS_ALT_HELD) {
|
||||
if (input->encoding & KB_METAESC) {
|
||||
Translate_to_keycode(input, WSCONS_EVENT_KEY_DOWN, KS_Escape);
|
||||
Translate_to_text(input, result);
|
||||
continue;
|
||||
} else result |= 0x80;
|
||||
} else {
|
||||
result |= 0x80;
|
||||
}
|
||||
}
|
||||
}
|
||||
Translate_to_text(input,result);
|
||||
@@ -835,7 +897,10 @@ static void updateKeyboard(SDL_WSCONS_input_data* input)
|
||||
void SDL_WSCONS_PumpEvents()
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < 4; i++)
|
||||
for (i = 0; i < 4; i++) {
|
||||
updateKeyboard(inputs[i]);
|
||||
if (mouseInputData != NULL) updateMouse(mouseInputData);
|
||||
}
|
||||
if (mouseInputData != NULL) {
|
||||
updateMouse(mouseInputData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
|
||||
#endif
|
||||
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);
|
||||
if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
|
||||
#ifdef WSMOUSEIO_SETMODE
|
||||
@@ -61,11 +63,9 @@ void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
|
||||
int n,i;
|
||||
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);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
for (i = 0; i < n; i++) {
|
||||
type = events[i].type;
|
||||
switch(type)
|
||||
{
|
||||
@@ -128,7 +128,9 @@ void updateMouse(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);
|
||||
free(inputData);
|
||||
}
|
||||
|
||||
@@ -61,9 +61,9 @@ WIN_LoadHIDDLL(void)
|
||||
SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
|
||||
SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
|
||||
SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
|
||||
if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString ||
|
||||
!SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps ||
|
||||
!SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) {
|
||||
if (SDL_HidD_GetManufacturerString == NULL || SDL_HidD_GetProductString == NULL ||
|
||||
SDL_HidP_GetCaps == NULL || SDL_HidP_GetButtonCaps == NULL ||
|
||||
SDL_HidP_GetValueCaps == NULL || SDL_HidP_MaxDataListLength == NULL || SDL_HidP_GetData == NULL) {
|
||||
WIN_UnloadHIDDLL();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user