From 2e976c01edc9fa6185193d5dfcd3bdd5d01b2c6f Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 27 Apr 2022 11:27:41 +0900 Subject: [PATCH] macOS: Fix coding style * brace position * space * length of one line --- src/cocoa_window.m | 103 ++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 848e3a97..fc6dd905 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -331,7 +331,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; window->ns.occluded = GLFW_TRUE; } -- (void)imeStatusChangeNotified:(NSNotification *)notification { +- (void)imeStatusChangeNotified:(NSNotification *)notification +{ _glfwInputIMEStatus(window); } @@ -696,20 +697,22 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; NSUInteger i, length = [markedTextString length]; int ctext = window->ctext; - while (ctext < length+1) { - ctext = (ctext == 0) ? 1 : ctext*2; + while (ctext < length + 1) + { + ctext = ctext == 0 ? 1 : ctext * 2; } - if (ctext != window->ctext) { - unsigned int* preeditText = realloc(window->preeditText, sizeof(unsigned int)*ctext); - if (preeditText == NULL) { + if (ctext != window->ctext) + { + unsigned int* preeditText = realloc(window->preeditText, + sizeof(unsigned int) * ctext); + if (preeditText == NULL) return; - } window->preeditText = preeditText; window->ctext = ctext; } window->ntext = length; window->preeditText[length] = 0; - for (i = 0; i < length; i++) + for (i = 0; i < length; i++) { const unichar codepoint = [markedTextString characterAtIndex:i]; window->preeditText[i] = codepoint; @@ -717,28 +720,29 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; int focusedBlock = 0; NSInteger offset = 0; window->nblocks = 0; - while (offset < length) { + while (offset < length) + { 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* blocks = realloc(window->preeditAttributeBlocks, sizeof(int)*cblocks); - if (blocks == NULL) { + int* blocks = realloc(window->preeditAttributeBlocks, + sizeof(int) * cblocks); + if (blocks == NULL) return; - } window->preeditAttributeBlocks = blocks; window->cblocks = cblocks; } window->preeditAttributeBlocks[window->nblocks] = effectiveRange.length; offset += effectiveRange.length; - if (effectiveRange.length == 0) { + if (effectiveRange.length == 0) break; - } NSNumber* underline = (NSNumber*) [attributes objectForKey:@"NSUnderline"]; - if ([underline intValue] != 1) { + if ([underline intValue] != 1) focusedBlock = window->nblocks; - } window->nblocks++; } _glfwInputPreedit(window, focusedBlock); @@ -1014,10 +1018,10 @@ int _glfwCreateWindowCocoa(_GLFWwindow* window, } [[NSNotificationCenter defaultCenter] - addObserver: window->ns.delegate - selector:@selector(imeStatusChangeNotified:) - name:NSTextInputContextKeyboardSelectionDidChangeNotification - object: nil]; + addObserver:window->ns.delegate + selector:@selector(imeStatusChangeNotified:) + name:NSTextInputContextKeyboardSelectionDidChangeNotification + object:nil]; return GLFW_TRUE; @@ -1031,7 +1035,7 @@ void _glfwDestroyWindowCocoa(_GLFWwindow* window) if (_glfw.ns.disabledCursorWindow == window) _glfw.ns.disabledCursorWindow = NULL; - [[NSNotificationCenter defaultCenter] removeObserver: window->ns.delegate]; + [[NSNotificationCenter defaultCenter] removeObserver:window->ns.delegate]; [window->ns.object orderOut:nil]; @@ -2004,22 +2008,35 @@ void _glfwPlatformSetIMEStatus(_GLFWwindow* window, int active) { // Mac OS has several input sources. // this code assumes input methods not in ascii capable inputs using IME. - NSArray* asciiInputSources = CFBridgingRelease(TISCreateASCIICapableInputSourceList()); - TISInputSourceRef asciiSource = (__bridge TISInputSourceRef)([asciiInputSources firstObject]); - if (active) { - NSArray* allInputSources = CFBridgingRelease(TISCreateInputSourceList(NULL, false)); - NSString* asciiSourceID = (__bridge NSString *)(TISGetInputSourceProperty(asciiSource, kTISPropertyInputSourceID)); + NSArray* asciiInputSources = + CFBridgingRelease(TISCreateASCIICapableInputSourceList()); + TISInputSourceRef asciiSource = + (__bridge TISInputSourceRef) [asciiInputSources firstObject]; + if (active) + { + NSArray* allInputSources = + CFBridgingRelease(TISCreateInputSourceList(NULL, false)); + NSString* asciiSourceID = + (__bridge NSString *) TISGetInputSourceProperty(asciiSource, + kTISPropertyInputSourceID); int i; int count = [allInputSources count]; - for (i = 0; i < count; i++) { - TISInputSourceRef source = (__bridge TISInputSourceRef)([allInputSources objectAtIndex: i]); - NSString* sourceID = (__bridge NSString *)(TISGetInputSourceProperty(source, kTISPropertyInputSourceID)); - if ([asciiSourceID compare: sourceID] != NSOrderedSame) { + for (i = 0; i < count; i++) + { + TISInputSourceRef source = + (__bridge TISInputSourceRef) [allInputSources objectAtIndex:i]; + NSString* sourceID = + (__bridge NSString *) TISGetInputSourceProperty(source, + kTISPropertyInputSourceID); + if ([asciiSourceID compare:sourceID] != NSOrderedSame) + { TISSelectInputSource(source); break; } } - } else if (asciiSource) { + } + else if (asciiSource) + { TISSelectInputSource(asciiSource); } } @@ -2027,12 +2044,20 @@ void _glfwPlatformSetIMEStatus(_GLFWwindow* window, int active) int _glfwPlatformGetIMEStatus(_GLFWwindow* window) { TISInputSourceRef currentSource = TISCopyCurrentKeyboardInputSource(); - NSString* currentSourceID = (__bridge NSString *)(TISGetInputSourceProperty(currentSource, kTISPropertyInputSourceID)); - NSArray* asciiInputSources = CFBridgingRelease(TISCreateASCIICapableInputSourceList()); - TISInputSourceRef asciiSource = (__bridge TISInputSourceRef)([asciiInputSources firstObject]); - if (asciiSource) { - NSString* asciiSourceID = (__bridge NSString *)(TISGetInputSourceProperty(asciiSource, kTISPropertyInputSourceID)); - return ([asciiSourceID compare: currentSourceID] == NSOrderedSame) ? GLFW_FALSE : GLFW_TRUE; + NSString* currentSourceID = + (__bridge NSString *) TISGetInputSourceProperty(currentSource, + kTISPropertyInputSourceID); + NSArray* asciiInputSources = + CFBridgingRelease(TISCreateASCIICapableInputSourceList()); + 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; }