Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate code to Swift #898

Merged
merged 76 commits into from
May 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
63ccd6d
Initial migration
LEOYoon-Tsaw May 11, 2024
89e57b1
Bug fixes
LEOYoon-Tsaw May 11, 2024
4286923
Continue to fix
LEOYoon-Tsaw May 11, 2024
d006dfd
Fix --build crash
LEOYoon-Tsaw May 11, 2024
2d6fdd7
Convert NSLog comments to debug print, disable app sandbox
LEOYoon-Tsaw May 11, 2024
c21446f
Fix IMKServer connection
eagleoflqj May 11, 2024
4e18a69
fix code mapping table
LEOYoon-Tsaw May 11, 2024
de9fa3f
save handling of CString to String conversion
LEOYoon-Tsaw May 11, 2024
3be453e
Update MacOSKeyCodes.swift
LEOYoon-Tsaw May 11, 2024
5ccd528
Properly initialize rime structs
LEOYoon-Tsaw May 11, 2024
f804045
fix
LEOYoon-Tsaw May 12, 2024
47b0df3
fix rime cstring assignment and input menu
LEOYoon-Tsaw May 12, 2024
63f9ebc
Fixed bug due to writingDirection attribute
LEOYoon-Tsaw May 12, 2024
546df86
fix color parsing
LEOYoon-Tsaw May 12, 2024
e81a8c5
Reenable sandbox and fix menu title in en
LEOYoon-Tsaw May 12, 2024
3ddb552
Fix a bug in shift + symbols
LEOYoon-Tsaw May 12, 2024
43f3a07
eliminate warnings
LEOYoon-Tsaw May 12, 2024
499f6ea
Bump version
LEOYoon-Tsaw May 12, 2024
485ef20
setup the flag STDBOOL
LEOYoon-Tsaw May 13, 2024
b95e539
move loading theme function to SquirrelTheme
LEOYoon-Tsaw May 13, 2024
63182f1
Fix inlineCandidate index out of bound bug
LEOYoon-Tsaw May 13, 2024
bf0eb51
Fix key modifier not properly handled bug
LEOYoon-Tsaw May 13, 2024
3327bb8
bump version
LEOYoon-Tsaw May 13, 2024
a60880a
Fix default text orientation to horizontal
LEOYoon-Tsaw May 13, 2024
01443c2
Fix mouse click bug & bump version
LEOYoon-Tsaw May 13, 2024
4130335
lint
LEOYoon-Tsaw May 14, 2024
79e9891
temporarily change librime to use std bool
LEOYoon-Tsaw May 14, 2024
90a5424
Update candidateFormat improve string interpolation
LEOYoon-Tsaw May 15, 2024
a071ad4
Add open temp dir menu item
LEOYoon-Tsaw May 15, 2024
b69528c
Gardening
LEOYoon-Tsaw May 15, 2024
b74e760
Reorganize code folder
LEOYoon-Tsaw May 15, 2024
2e585f5
preserve entitlement in codesign
LEOYoon-Tsaw May 15, 2024
fcdec58
Real entitlement, and real sandbox
LEOYoon-Tsaw May 15, 2024
c132f32
clean older tmp files
LEOYoon-Tsaw May 15, 2024
1ad8e16
Do not include entitlement by default
LEOYoon-Tsaw May 15, 2024
1de36a2
make inlineCandidate defaults to false
LEOYoon-Tsaw May 15, 2024
2344c5b
code gardening
LEOYoon-Tsaw May 15, 2024
e30aa63
Implement Sparkle SPUStandardUserDriverDelegate
LEOYoon-Tsaw May 15, 2024
346ed5d
bump version
LEOYoon-Tsaw May 15, 2024
4ffbd75
Fix fonts loading
LEOYoon-Tsaw May 16, 2024
f9698b9
fix candidate attributes
LEOYoon-Tsaw May 16, 2024
b3c5cf1
improve enable and select workflow
LEOYoon-Tsaw May 16, 2024
8ea02e2
better native color scheme
LEOYoon-Tsaw May 16, 2024
ebdafa9
Fix and optimize modifier key event
LEOYoon-Tsaw May 17, 2024
b869ed0
add env of PLUM_TAG to load specific formulae from plum
LEOYoon-Tsaw May 17, 2024
a742b94
Upgrade squirrel.yaml for new options
LEOYoon-Tsaw May 17, 2024
2920326
Update default theme
LEOYoon-Tsaw May 17, 2024
01f0589
Fix label and comment text not centered
LEOYoon-Tsaw May 17, 2024
6ba58fd
update archiving workflow
LEOYoon-Tsaw May 17, 2024
4464475
Dynamically add rime plugins
LEOYoon-Tsaw May 17, 2024
b592cb1
Update file titles
LEOYoon-Tsaw May 17, 2024
06587ad
Fix crash if client no longer exists
LEOYoon-Tsaw May 17, 2024
ea87031
Update Readme and Install instruction
LEOYoon-Tsaw May 17, 2024
5e37734
Update squirrel.yaml to 0.99
LEOYoon-Tsaw May 18, 2024
0938476
Fix line spacing bugs, and fix crash when panel size exceeds screen size
LEOYoon-Tsaw May 18, 2024
b12aeb6
Fix a bug that when loading new style, old one will have leftover
LEOYoon-Tsaw May 18, 2024
c3fba4a
remove disable-library-validation
LEOYoon-Tsaw May 18, 2024
7cfd961
Remove special handling of modifiers
LEOYoon-Tsaw May 18, 2024
0115cfa
reorganize inputSource, reduce repetitive calls
LEOYoon-Tsaw May 18, 2024
ff97af9
adopt RimeApi_stdbool
LEOYoon-Tsaw May 18, 2024
7f7ed6b
improve codesign
LEOYoon-Tsaw May 18, 2024
4f294bd
improve registration under sandbox
LEOYoon-Tsaw May 18, 2024
158c159
Bump squirrel.yaml version to 1.0
LEOYoon-Tsaw May 18, 2024
b248000
minor updates to build settings
LEOYoon-Tsaw May 18, 2024
f3aea6e
Update librime
LEOYoon-Tsaw May 19, 2024
5c4f85a
Fix a bug in enabling input source
LEOYoon-Tsaw May 19, 2024
346394b
input source command lines takes target source as extra arguments
LEOYoon-Tsaw May 19, 2024
a167c15
bump version
LEOYoon-Tsaw May 19, 2024
f63c5cb
make osxModifiersToRime takes NSEvent.ModifierFlags values
LEOYoon-Tsaw May 19, 2024
d094852
Add a help string
LEOYoon-Tsaw May 19, 2024
7532eb7
disable Sandbox
LEOYoon-Tsaw May 19, 2024
dde575c
Update release-ci
LEOYoon-Tsaw May 20, 2024
67bf288
Gracefully avoid linebreak within short candidates
LEOYoon-Tsaw May 21, 2024
a074cbb
Introduce ?= operator, only assign when righthand side is non-nil
LEOYoon-Tsaw May 22, 2024
4b6874d
Process modifier release before new modifier
LEOYoon-Tsaw May 23, 2024
bafeed5
do not showStatusMessage if no label has valid String
LEOYoon-Tsaw May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove special handling of modifiers
  • Loading branch information
LEOYoon-Tsaw committed May 19, 2024
commit 7cfd961a61c6d872340d1f7294bd80d3b89b3ac0
4 changes: 2 additions & 2 deletions sources/SquirrelApplicationDelegate.swift
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ final class SquirrelApplicationDelegate: NSObject, NSApplicationDelegate, SPUSta

func syncUserData() {
print("Sync user data")
let _ = rimeAPI.sync_user_data()
_ = rimeAPI.sync_user_data()
}

func openLogFolder() {
@@ -153,7 +153,7 @@ final class SquirrelApplicationDelegate: NSObject, NSApplicationDelegate, SPUSta
if rimeAPI.start_maintenance(fullCheck) {
// update squirrel config
// print("[DEBUG] maintenance suceeds")
let _ = rimeAPI.deploy_config_file("squirrel.yaml", "config_version")
_ = rimeAPI.deploy_config_file("squirrel.yaml", "config_version")
} else {
// print("[DEBUG] maintenance fails")
}
4 changes: 2 additions & 2 deletions sources/SquirrelConfig.swift
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ final class SquirrelConfig {

func close() {
if isOpen {
let _ = rimeAPI.config_close(&config)
_ = rimeAPI.config_close(&config)
baseConfig = nil
isOpen = false
}
@@ -117,7 +117,7 @@ final class SquirrelConfig {
let rootKey = "app_options/\(appName)"
var appOptions = [String : Bool]()
var iterator = RimeConfigIterator()
let _ = rimeAPI.config_begin_map(&iterator, &config, rootKey)
_ = rimeAPI.config_begin_map(&iterator, &config, rootKey)
while rimeAPI.config_next(&iterator) {
// print("[DEBUG] option[\(iterator.index)]: \(String(cString: iterator.key)), path: (\(String(cString: iterator.path))")
if let key = iterator.key, let path = iterator.path, let value = getBool(String(cString: path)) {
29 changes: 7 additions & 22 deletions sources/SquirrelInputController.swift
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@ final class SquirrelInputController: IMKInputController {
private var selRange: NSRange = NSMakeRange(NSNotFound, 0)
private var caretPos: Int = 0
private var lastModifiers: NSEvent.ModifierFlags = .init()
private var lastEventType: NSEvent.EventType = .init(rawValue: 0)!
private var lastModifiersChange: NSEvent.ModifierFlags = .init()
private var session: RimeSessionId = 0
private var schemaId: String = ""
private var inlinePreedit = false
@@ -61,35 +59,24 @@ final class SquirrelInputController: IMKInputController {
}
// print("[DEBUG] FLAGSCHANGED client: \(sender ?? "nil"), modifiers: \(modifiers)")
var rimeModifiers: UInt32 = SquirrelKeycode.osxModifiersToRime(modifiers: modifiers.rawValue)
let lastRimeModifiers: UInt32 = SquirrelKeycode.osxModifiersToRime(modifiers: lastModifiers.rawValue)
// For flags-changed event, keyCode is available since macOS 10.15
// (#715)
let rimeKeycode: UInt32 = SquirrelKeycode.osxKeycodeToRime(keycode: event.keyCode, keychar: nil, shift: false, caps: false)
let chording = rimeAPI.get_option(session, "_chord_typing")

if changes.contains(.capsLock) {
// NOTE: rime assumes XK_Caps_Lock to be sent before modifier changes,
// while NSFlagsChanged event has the flag changed already.
// so it is necessary to revert kLockMask.
rimeModifiers ^= kLockMask.rawValue
handled = processKey(rimeKeycode, modifiers: rimeModifiers)
_ = processKey(rimeKeycode, modifiers: rimeModifiers)
}
for flag in [NSEvent.ModifierFlags.shift, .control, .option, .command] {
if changes.contains(flag) {
// different behavier in chording
if chording {
let releaseMask = modifiers.contains(flag) ? 0 : kReleaseMask.rawValue
handled = processKey(rimeKeycode, modifiers: rimeModifiers | releaseMask)
} else {
// flag is released and the change equals last change, so no other event between pressing and releasing
if lastEventType == .flagsChanged && !modifiers.contains(flag) && changes == lastModifiersChange {
handled = processKey(rimeKeycode, modifiers: lastRimeModifiers)
}
}
let releaseMask = modifiers.contains(flag) ? 0 : kReleaseMask.rawValue
_ = processKey(rimeKeycode, modifiers: rimeModifiers | releaseMask)
}
}
lastModifiers = modifiers
lastModifiersChange = changes

rimeUpdate()

@@ -117,13 +104,11 @@ final class SquirrelInputController: IMKInputController {
rimeUpdate()
}
}
lastModifiersChange = .init()

default:
break
}

lastEventType = event.type
return handled
}

@@ -359,7 +344,7 @@ private extension SquirrelInputController {
func destroySession() {
// print("[DEBUG] destroySession:")
if session != 0 {
let _ = rimeAPI.destroy_session(session)
_ = rimeAPI.destroy_session(session)
session = 0
}
clearChord()
@@ -414,7 +399,7 @@ private extension SquirrelInputController {
if rimeAPI.get_commit(session, &commitText) {
if let text = commitText.text {
commit(string: String(cString: text))
let _ = rimeAPI.free_commit(&commitText)
_ = rimeAPI.free_commit(&commitText)
}
}
}
@@ -437,7 +422,7 @@ private extension SquirrelInputController {
rimeAPI.set_option(session, "soft_cursor", !inlinePreedit)
}
}
let _ = rimeAPI.free_status(&status)
_ = rimeAPI.free_status(&status)
}

var ctx = RimeContext.rimeStructInit()
@@ -499,7 +484,7 @@ private extension SquirrelInputController {
}
}
showPanel(preedit: inlinePreedit ? "" : preedit, selRange: NSRange(location: start.utf16Offset(in: preedit), length: preedit.utf16.distance(from: start, to: end)), caretPos: caretPos.utf16Offset(in: preedit), candidates: candidates, comments: comments, labels: labels, highlighted: Int(ctx.menu.highlighted_candidate_index))
let _ = rimeAPI.free_context(&ctx)
_ = rimeAPI.free_context(&ctx)
} else {
hidePalettes()
}
12 changes: 6 additions & 6 deletions sources/SquirrelPanel.swift
Original file line number Diff line number Diff line change
@@ -75,13 +75,13 @@ final class SquirrelPanel: NSPanel {
let (index, preeditIndex) = view.click(at: mousePosition())
if let preeditIndex = preeditIndex, preeditIndex >= 0 && preeditIndex < preedit.utf16.count {
if preeditIndex < caretPos {
let _ = inputController?.moveCaret(forward: true)
_ = inputController?.moveCaret(forward: true)
} else if preeditIndex > caretPos {
let _ = inputController?.moveCaret(forward: false)
_ = inputController?.moveCaret(forward: false)
}
}
if let index = index, index == self.index && index >= 0 && index < candidates.count {
let _ = inputController?.selectCandidate(index)
_ = inputController?.selectCandidate(index)
}
case .mouseEntered:
acceptsMouseMovedEvents = true
@@ -101,9 +101,9 @@ final class SquirrelPanel: NSPanel {
// Scrollboard span
} else if event.phase == .ended || (event.phase == .init(rawValue: 0) && event.momentumPhase != .init(rawValue: 0)) {
if abs(scrollDirection.dx) > abs(scrollDirection.dy) && abs(scrollDirection.dx) > 10 {
let _ = inputController?.page(up: (scrollDirection.dx < 0) == vertical)
_ = inputController?.page(up: (scrollDirection.dx < 0) == vertical)
} else if abs(scrollDirection.dx) < abs(scrollDirection.dy) && abs(scrollDirection.dy) > 10 {
let _ = inputController?.page(up: scrollDirection.dx > 0)
_ = inputController?.page(up: scrollDirection.dx > 0)
}
scrollDirection = .zero
// Mouse scroll wheel
@@ -118,7 +118,7 @@ final class SquirrelPanel: NSPanel {
scrollDirection = .zero
}
if abs(scrollDirection.dy) > 10 {
let _ = inputController?.page(up: scrollDirection.dy > 0)
_ = inputController?.page(up: scrollDirection.dy > 0)
scrollDirection = .zero
}
} else {