macOS: Fix coding style

* brace position
* space
* length of one line
This commit is contained in:
Daijiro Fukuda 2022-04-27 11:27:41 +09:00
parent 28ea48ea38
commit 2e976c01ed

View File

@ -331,7 +331,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
window->ns.occluded = GLFW_TRUE; window->ns.occluded = GLFW_TRUE;
} }
- (void)imeStatusChangeNotified:(NSNotification *)notification { - (void)imeStatusChangeNotified:(NSNotification *)notification
{
_glfwInputIMEStatus(window); _glfwInputIMEStatus(window);
} }
@ -696,20 +697,22 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
NSUInteger i, length = [markedTextString length]; NSUInteger i, length = [markedTextString length];
int ctext = window->ctext; int ctext = window->ctext;
while (ctext < length+1) { while (ctext < length + 1)
ctext = (ctext == 0) ? 1 : ctext*2; {
ctext = ctext == 0 ? 1 : ctext * 2;
} }
if (ctext != window->ctext) { if (ctext != window->ctext)
unsigned int* preeditText = realloc(window->preeditText, sizeof(unsigned int)*ctext); {
if (preeditText == NULL) { unsigned int* preeditText = realloc(window->preeditText,
sizeof(unsigned int) * ctext);
if (preeditText == NULL)
return; return;
}
window->preeditText = preeditText; window->preeditText = preeditText;
window->ctext = ctext; window->ctext = ctext;
} }
window->ntext = length; window->ntext = length;
window->preeditText[length] = 0; window->preeditText[length] = 0;
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
const unichar codepoint = [markedTextString characterAtIndex:i]; const unichar codepoint = [markedTextString characterAtIndex:i];
window->preeditText[i] = codepoint; window->preeditText[i] = codepoint;
@ -717,28 +720,29 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
int focusedBlock = 0; int focusedBlock = 0;
NSInteger offset = 0; NSInteger offset = 0;
window->nblocks = 0; window->nblocks = 0;
while (offset < length) { while (offset < length)
{
NSRange effectiveRange; NSRange effectiveRange;
NSDictionary *attributes = [markedText attributesAtIndex:offset effectiveRange:&effectiveRange]; NSDictionary* attributes = [markedText attributesAtIndex:offset
effectiveRange:&effectiveRange];
if (window->nblocks == window->cblocks) { if (window->nblocks == window->cblocks)
{
int cblocks = window->cblocks * 2; int cblocks = window->cblocks * 2;
int* blocks = realloc(window->preeditAttributeBlocks, sizeof(int)*cblocks); int* blocks = realloc(window->preeditAttributeBlocks,
if (blocks == NULL) { sizeof(int) * cblocks);
if (blocks == NULL)
return; return;
}
window->preeditAttributeBlocks = blocks; window->preeditAttributeBlocks = blocks;
window->cblocks = cblocks; window->cblocks = cblocks;
} }
window->preeditAttributeBlocks[window->nblocks] = effectiveRange.length; window->preeditAttributeBlocks[window->nblocks] = effectiveRange.length;
offset += effectiveRange.length; offset += effectiveRange.length;
if (effectiveRange.length == 0) { if (effectiveRange.length == 0)
break; break;
}
NSNumber* underline = (NSNumber*) [attributes objectForKey:@"NSUnderline"]; NSNumber* underline = (NSNumber*) [attributes objectForKey:@"NSUnderline"];
if ([underline intValue] != 1) { if ([underline intValue] != 1)
focusedBlock = window->nblocks; focusedBlock = window->nblocks;
}
window->nblocks++; window->nblocks++;
} }
_glfwInputPreedit(window, focusedBlock); _glfwInputPreedit(window, focusedBlock);
@ -1014,10 +1018,10 @@ int _glfwCreateWindowCocoa(_GLFWwindow* window,
} }
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver: window->ns.delegate addObserver:window->ns.delegate
selector:@selector(imeStatusChangeNotified:) selector:@selector(imeStatusChangeNotified:)
name:NSTextInputContextKeyboardSelectionDidChangeNotification name:NSTextInputContextKeyboardSelectionDidChangeNotification
object: nil]; object:nil];
return GLFW_TRUE; return GLFW_TRUE;
@ -1031,7 +1035,7 @@ void _glfwDestroyWindowCocoa(_GLFWwindow* window)
if (_glfw.ns.disabledCursorWindow == window) if (_glfw.ns.disabledCursorWindow == window)
_glfw.ns.disabledCursorWindow = NULL; _glfw.ns.disabledCursorWindow = NULL;
[[NSNotificationCenter defaultCenter] removeObserver: window->ns.delegate]; [[NSNotificationCenter defaultCenter] removeObserver:window->ns.delegate];
[window->ns.object orderOut:nil]; [window->ns.object orderOut:nil];
@ -2004,22 +2008,35 @@ void _glfwPlatformSetIMEStatus(_GLFWwindow* window, int active)
{ {
// Mac OS has several input sources. // Mac OS has several input sources.
// this code assumes input methods not in ascii capable inputs using IME. // this code assumes input methods not in ascii capable inputs using IME.
NSArray* asciiInputSources = CFBridgingRelease(TISCreateASCIICapableInputSourceList()); NSArray* asciiInputSources =
TISInputSourceRef asciiSource = (__bridge TISInputSourceRef)([asciiInputSources firstObject]); CFBridgingRelease(TISCreateASCIICapableInputSourceList());
if (active) { TISInputSourceRef asciiSource =
NSArray* allInputSources = CFBridgingRelease(TISCreateInputSourceList(NULL, false)); (__bridge TISInputSourceRef) [asciiInputSources firstObject];
NSString* asciiSourceID = (__bridge NSString *)(TISGetInputSourceProperty(asciiSource, kTISPropertyInputSourceID)); if (active)
{
NSArray* allInputSources =
CFBridgingRelease(TISCreateInputSourceList(NULL, false));
NSString* asciiSourceID =
(__bridge NSString *) TISGetInputSourceProperty(asciiSource,
kTISPropertyInputSourceID);
int i; int i;
int count = [allInputSources count]; int count = [allInputSources count];
for (i = 0; i < count; i++) { for (i = 0; i < count; i++)
TISInputSourceRef source = (__bridge TISInputSourceRef)([allInputSources objectAtIndex: i]); {
NSString* sourceID = (__bridge NSString *)(TISGetInputSourceProperty(source, kTISPropertyInputSourceID)); TISInputSourceRef source =
if ([asciiSourceID compare: sourceID] != NSOrderedSame) { (__bridge TISInputSourceRef) [allInputSources objectAtIndex:i];
NSString* sourceID =
(__bridge NSString *) TISGetInputSourceProperty(source,
kTISPropertyInputSourceID);
if ([asciiSourceID compare:sourceID] != NSOrderedSame)
{
TISSelectInputSource(source); TISSelectInputSource(source);
break; break;
} }
} }
} else if (asciiSource) { }
else if (asciiSource)
{
TISSelectInputSource(asciiSource); TISSelectInputSource(asciiSource);
} }
} }
@ -2027,12 +2044,20 @@ void _glfwPlatformSetIMEStatus(_GLFWwindow* window, int active)
int _glfwPlatformGetIMEStatus(_GLFWwindow* window) int _glfwPlatformGetIMEStatus(_GLFWwindow* window)
{ {
TISInputSourceRef currentSource = TISCopyCurrentKeyboardInputSource(); TISInputSourceRef currentSource = TISCopyCurrentKeyboardInputSource();
NSString* currentSourceID = (__bridge NSString *)(TISGetInputSourceProperty(currentSource, kTISPropertyInputSourceID)); NSString* currentSourceID =
NSArray* asciiInputSources = CFBridgingRelease(TISCreateASCIICapableInputSourceList()); (__bridge NSString *) TISGetInputSourceProperty(currentSource,
TISInputSourceRef asciiSource = (__bridge TISInputSourceRef)([asciiInputSources firstObject]); kTISPropertyInputSourceID);
if (asciiSource) { NSArray* asciiInputSources =
NSString* asciiSourceID = (__bridge NSString *)(TISGetInputSourceProperty(asciiSource, kTISPropertyInputSourceID)); CFBridgingRelease(TISCreateASCIICapableInputSourceList());
return ([asciiSourceID compare: currentSourceID] == NSOrderedSame) ? GLFW_FALSE : GLFW_TRUE; TISInputSourceRef asciiSource =
(__bridge TISInputSourceRef) [asciiInputSources firstObject];
if (asciiSource)
{
NSString* asciiSourceID =
(__bridge NSString *) TISGetInputSourceProperty(asciiSource,
kTISPropertyInputSourceID);
return [asciiSourceID compare:currentSourceID] == NSOrderedSame
? GLFW_FALSE : GLFW_TRUE;
} }
return GLFW_FALSE; return GLFW_FALSE;
} }