From 83fc6c7e4e1bebe0daa85f8d7e464470078b91b8 Mon Sep 17 00:00:00 2001 From: Stackia Date: Fri, 24 Oct 2014 18:30:46 +0800 Subject: [PATCH] Add a build script to kill current running XIME instances. Rewrite updateComposition: and cancelComposition: methods in inputController. SDK provided version causes crash when using ARC. --- XIME.xcodeproj/project.pbxproj | 15 +++++++++++++++ XIME/Source/AppDelegate.m | 1 - XIME/Source/CandidateWindowController.m | 10 +++------- XIME/Source/InputController.m | 11 +++++++++++ XIME/Supporting Files/Info.plist | 2 +- XIME/Supporting Files/XIME.pch | 2 ++ 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/XIME.xcodeproj/project.pbxproj b/XIME.xcodeproj/project.pbxproj index ed57f2f..4b546b3 100644 --- a/XIME.xcodeproj/project.pbxproj +++ b/XIME.xcodeproj/project.pbxproj @@ -561,6 +561,7 @@ C13DA3D519F30F27004B2348 /* Copy opencc Dictionary Files */, C13DA3DE19F31359004B2348 /* Copy Library Files */, C1A26E2619F4D0EB007BF527 /* Auto Increase Build Number */, + C107775E19FA5AAC00D3E673 /* Kill Running XIME Instances */, ); buildRules = ( C19AE36719F3E75900592E35 /* PBXBuildRule */, @@ -652,6 +653,20 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + C107775E19FA5AAC00D3E673 /* Kill Running XIME Instances */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Kill Running XIME Instances"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "#!/bin/bash\n(kill $(ps aux | grep '[X]IME' | awk '{print $2}')) 2>/dev/null || true"; + }; C1A26E2619F4D0EB007BF527 /* Auto Increase Build Number */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/XIME/Source/AppDelegate.m b/XIME/Source/AppDelegate.m index affbe20..ab859a6 100644 --- a/XIME/Source/AppDelegate.m +++ b/XIME/Source/AppDelegate.m @@ -15,7 +15,6 @@ @implementation AppDelegate #pragma mark Application Delegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // Create IMKServer if ([IMKServer sharedServer] == nil) { NSLog(@"Failed to create IMKServer."); diff --git a/XIME/Source/CandidateWindowController.m b/XIME/Source/CandidateWindowController.m index 3cdef01..829b673 100644 --- a/XIME/Source/CandidateWindowController.m +++ b/XIME/Source/CandidateWindowController.m @@ -27,14 +27,13 @@ - (void)updateWithRimeContext:(XRimeContext *)context caretRect:(NSRect)caretRec // Hide window [[self window] orderOut:self]; } else { - const int verticalOffet = 5; // Resize window NSRect windowRect = [[self window] frame]; // Reposition window windowRect.origin.x = NSMinX(caretRect); - windowRect.origin.y = NSMinY(caretRect) - NSHeight(caretRect) - verticalOffet; + windowRect.origin.y = NSMaxY(caretRect) + kXIMECandidateWindowPositionVerticalOffset; // Fit in current screen NSRect screenRect = [[NSScreen mainScreen] frame]; @@ -54,13 +53,10 @@ - (void)updateWithRimeContext:(XRimeContext *)context caretRect:(NSRect)caretRec windowRect.origin.x = NSMinX(screenRect); } if (NSMinY(windowRect) < NSMinY(screenRect)) { - windowRect.origin.y = NSMaxY(caretRect) + verticalOffet; + windowRect.origin.y = NSMinY(screenRect); } if (NSMaxY(windowRect) > NSMaxY(screenRect)) { - windowRect.origin.y = NSMaxY(screenRect) - NSHeight(windowRect); - } - if (NSMinY(windowRect) < NSMinY(screenRect)) { - windowRect.origin.y = NSMinY(screenRect); + windowRect.origin.y = NSMinY(caretRect) - NSHeight(windowRect) - kXIMECandidateWindowPositionVerticalOffset; } // Show window diff --git a/XIME/Source/InputController.m b/XIME/Source/InputController.m index aa7980a..bc505bc 100644 --- a/XIME/Source/InputController.m +++ b/XIME/Source/InputController.m @@ -202,6 +202,17 @@ - (NSRange)selectionRange { return NSMakeRange(cursorPosition_, 0); } +// Rewrite this method because the original one will crash when using ARC +- (void)updateComposition { + NSAttributedString *composedString = [self composedString:self]; + [[self client] setMarkedText:composedString selectionRange:[self selectionRange] replacementRange:[self replacementRange]]; +} + +// Rewrite this method because the original one will crash when using ARC +- (void)cancelComposition { + [[self client] insertText:[self originalString:self] replacementRange:[self replacementRange]]; +} + - (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)inputClient { if (self = [super initWithServer:server delegate:delegate client:inputClient]) { rimeSessionId_ = [RimeWrapper createSession]; // Try to create Rime session diff --git a/XIME/Supporting Files/Info.plist b/XIME/Supporting Files/Info.plist index 9628b53..efb527c 100644 --- a/XIME/Supporting Files/Info.plist +++ b/XIME/Supporting Files/Info.plist @@ -23,7 +23,7 @@ CFBundleSignature ???? CFBundleVersion - 198 + 222 InputMethodConnectionName com.Stackia.inputmethod.XIME.IMKConnection InputMethodServerControllerClass diff --git a/XIME/Supporting Files/XIME.pch b/XIME/Supporting Files/XIME.pch index e91f56a..e9ad2f7 100644 --- a/XIME/Supporting Files/XIME.pch +++ b/XIME/Supporting Files/XIME.pch @@ -14,6 +14,8 @@ #import #endif +// All const definitions here #define kXIMEUserDataDirectoryKey @"XIMEUserDataDirectory" +#define kXIMECandidateWindowPositionVerticalOffset 5; #endif