Skip to content

Commit a92f450

Browse files
committed
drop pointer usages in getCaretCoordinates
1 parent 095defa commit a92f450

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

macosfrontend/macosfrontend.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,12 @@ std::tuple<double, double, double>
342342
MacosInputContext::getCaretCoordinates(bool followCaret) {
343343
// Memorize to avoid jumping to origin on failure.
344344
static double x = 0, y = 0, height = 0;
345-
if (!SwiftFrontend::getCaretCoordinates(client_, followCaret, &x, &y,
346-
&height)) {
345+
auto res = SwiftFrontend::getCaretCoordinates(client_, followCaret);
346+
if (res.getCount() == 3) {
347+
x = res[0];
348+
y = res[1];
349+
height = res[2];
350+
} else {
347351
FCITX_DEBUG() << "Failed to get caret coordinates";
348352
}
349353
return std::make_tuple(x, y, height);

macosfrontend/macosfrontend.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,10 @@ public func commitAsync(_ clientPtr: UnsafeMutableRawPointer, _ commit: String)
139139
public func getCaretCoordinates(
140140
_ clientPtr: UnsafeMutableRawPointer,
141141
_ followCaret: Bool,
142-
_ x: UnsafeMutablePointer<Double>,
143-
_ y: UnsafeMutablePointer<Double>,
144-
_ height: UnsafeMutablePointer<Double>
145-
) -> Bool {
142+
) -> [Double] {
146143
let client: AnyObject = Unmanaged.fromOpaque(clientPtr).takeUnretainedValue()
147144
guard let client = client as? IMKTextInput else {
148-
return false
145+
return []
149146
}
150147
var rect = NSRect(x: 0, y: 0, width: 0, height: 0)
151148
// n characters have n+1 caret positions, but character index only accepts 0 to n-1,
@@ -155,13 +152,13 @@ public func getCaretCoordinates(
155152
forCharacterIndex: followCaret ? (isEnd ? u16pos - 1 : u16pos) : 0,
156153
lineHeightRectangle: &rect)
157154
if rect.width == 0 && rect.height == 0 {
158-
return false
155+
return []
159156
}
160-
x.pointee = Double(NSMinX(rect))
161-
y.pointee = Double(NSMinY(rect))
162-
height.pointee = Double(rect.height)
157+
var x = Double(NSMinX(rect))
158+
let y = Double(NSMinY(rect))
159+
let height = Double(rect.height)
163160
if followCaret && isEnd {
164-
x.pointee += 10
161+
x += 10
165162
}
166-
return true
163+
return [x, y, height]
167164
}

0 commit comments

Comments
 (0)