fix(panel): draggable header and configurable translation text size

Add a native AppKit drag grip to the non-activating panel header; it accepts the first mouse and calls performDrag, so the panel can be moved before it becomes key. Keep a moved position while the panel stays visible and only recenter near the cursor when it is shown again (DeepL-like transient position).

Add persisted translationFontSize (default 17 pt, range 12–28) to AppSettings and PanelConfiguration, apply it to the translation text, and expose a native Settings stepper. Add English/German strings and AppSettings clamp/round-trip tests.

Verified: make verify green; synthetic double-copy opened the panel, dragging the grip moved the window, and a 22 pt capture showed the larger translation text.
This commit is contained in:
schihei committed 2026-11-26 14:35:34 +01:00
1 parent 2cce12ff17
commit 40733473c5
12 files changed
+98 -5

No files matched your search

+1
View File
@@ -214,6 +214,7 @@ final class AppEnvironment {
keepAlive: settings.keepModelLoaded,
sampling: settings.samplingOptions,
showSourcePreview: settings.showSourcePreview,
translationFontSize: settings.translationFontSize,
recentTargets: settings.recentTargets
)
}
+19 -2
View File
@@ -20,6 +20,7 @@ final class PanelController: NSObject, NSWindowDelegate {
super.init()
panel.delegate = self
panel.isFloatingPanel = true
panel.isMovable = true
panel.becomesKeyOnlyIfNeeded = true
panel.level = .floating
panel.hidesOnDeactivate = false
@@ -34,7 +35,7 @@ final class PanelController: NSObject, NSWindowDelegate {
panel.standardWindowButton(.closeButton)?.isHidden = true
panel.standardWindowButton(.miniaturizeButton)?.isHidden = true
panel.standardWindowButton(.zoomButton)?.isHidden = true
panel.contentView = NSHostingView(
panel.contentView = PanelHostingView(
rootView: PanelView(
model: viewModel,
onClose: { [weak self] in self?.close() }
@@ -45,7 +46,9 @@ final class PanelController: NSObject, NSWindowDelegate {
/// Shows the panel near the mouse without activating the app.
func show() {
positionNearMouse()
if !panel.isVisible {
positionNearMouse()
}
panel.orderFrontRegardless()
}
@@ -59,6 +62,20 @@ final class PanelController: NSObject, NSWindowDelegate {
Task { await viewModel.close() }
}
private final class PanelHostingView: NSHostingView<PanelView> {
required init(rootView: PanelView) {
super.init(rootView: rootView)
}
required init?(coder: NSCoder) {
nil
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
true
}
}
private func positionNearMouse() {
let mouse = NSEvent.mouseLocation
let screen = NSScreen.screens.first { $0.frame.contains(mouse) } ?? NSScreen.main
+11 -1
View File
@@ -41,6 +41,16 @@ struct PanelView: View {
private var header: some View {
HStack(spacing: 10) {
ZStack {
Image(systemName: "line.3.horizontal")
.font(.caption2)
.foregroundStyle(.tertiary)
.allowsHitTesting(false)
WindowDragArea()
}
.frame(width: 18, height: 28)
.accessibilityLabel(String(localized: "Move panel"))
Image(systemName: "character.bubble")
.font(.title2)
.foregroundStyle(.tint)
@@ -107,7 +117,7 @@ struct PanelView: View {
private var translationArea: some View {
ScrollView {
Text(translationText)
.font(.body)
.font(.system(size: CGFloat(model.configuration.translationFontSize)))
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundStyle(model.translation.isEmpty ? .secondary : .primary)
+30
View File
@@ -0,0 +1,30 @@
import AppKit
import SwiftUI
/// An AppKit drag surface for the non-activating panel. SwiftUI's hosting view consumes mouse
/// events, so this view starts a native window drag on the first click.
struct WindowDragArea: NSViewRepresentable {
func makeNSView(context: Context) -> NSView {
DragView()
}
func updateNSView(_ nsView: NSView, context: Context) {}
}
private final class DragView: NSView {
override var mouseDownCanMoveWindow: Bool {
true
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
true
}
override func mouseDown(with event: NSEvent) {
window?.performDrag(with: event)
}
override func resetCursorRects() {
addCursorRect(bounds, cursor: .openHand)
}
}
@@ -10,6 +10,8 @@
"Settings…" = "Einstellungen…";
"Quit Sprachmittler" = "Sprachmittler beenden";
"Translate" = "Übersetzen";
"Move panel" = "Panel verschieben";
"Translation text size" = "Schriftgröße der Übersetzung";
"Source" = "Quelle";
"Settings" = "Einstellungen";
"Search languages" = "Sprachen suchen";
@@ -10,6 +10,8 @@
"Settings…" = "Settings…";
"Quit Sprachmittler" = "Quit Sprachmittler";
"Translate" = "Translate";
"Move panel" = "Move panel";
"Translation text size" = "Translation text size";
"Source" = "Source";
"Settings" = "Settings";
"Search languages" = "Search languages";
+7
View File
@@ -96,6 +96,13 @@ struct SettingsView: View {
.accessibilityLabel(String(localized: "Target language"))
}
Toggle(String(localized: "Show source preview"), isOn: $draft.showSourcePreview)
Stepper(value: $draft.translationFontSize, in: 12 ... 28) {
LabeledContent(
String(localized: "Translation text size"),
value: "\(draft.translationFontSize) pt"
)
}
.accessibilityLabel(String(localized: "Translation text size"))
}
Section(String(localized: "Double copy")) {
@@ -59,6 +59,8 @@ public struct AppSettings: Codable, Sendable, Equatable {
public var autoCopy: Bool
/// Show the source preview in the panel.
public var showSourcePreview: Bool
/// Translation text size in points (12–28).
public var translationFontSize: Int
/// Reflect the login-item setting.
public var launchAtLogin: Bool
/// Keep the last translation in memory for the panel.
@@ -91,6 +93,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
promptVariantPolicy = .defaultOnly
autoCopy = false
showSourcePreview = true
translationFontSize = 17
launchAtLogin = false
keepRecentTranslationInMemory = true
hasCompletedOnboarding = false
@@ -132,6 +135,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
topP = min(max(topP, 0), 1)
topK = Self.clamp(topK, to: 1 ... 100)
repeatPenalty = min(max(repeatPenalty, 0.5), 2)
translationFontSize = Self.clamp(translationFontSize, to: 12 ... 28)
if !["5m", "30m", "1h", "0"].contains(keepModelLoaded) {
keepModelLoaded = HyMT3ModelPreset.defaultKeepAlive
}
@@ -161,6 +165,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
let cjk: Int
let numCtx: Int
let numPredict: Int
let fontSize: Int
}
private struct DecodedSampling {
@@ -197,6 +202,11 @@ public struct AppSettings: Codable, Sendable, Equatable {
numPredict: clamp(
container.decodeIfPresent(Int.self, forKey: .numPredict) ?? defaults.numPredict,
to: 1 ... 8192
),
fontSize: clamp(
container.decodeIfPresent(Int.self, forKey: .translationFontSize)
?? defaults.translationFontSize,
to: 12 ... 28
)
)
}
@@ -225,7 +235,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
case endpoint, allowRemoteEndpoint, model, fastModel, targetLanguage, recentTargetLanguages
case doubleCopyWindowMs, maxCharactersLatin, maxCharactersCJK, numCtx, numPredict
case temperature, topP, topK, repeatPenalty, keepModelLoaded, warmUpOnLaunch
case promptVariantPolicy, autoCopy, showSourcePreview, launchAtLogin
case promptVariantPolicy, autoCopy, showSourcePreview, translationFontSize, launchAtLogin
case keepRecentTranslationInMemory, hasCompletedOnboarding, settingsVersion
}
@@ -257,6 +267,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
maxCharactersCJK = limits.cjk
numCtx = limits.numCtx
numPredict = limits.numPredict
translationFontSize = limits.fontSize
let sampling = try Self.decodeSampling(from: container, defaults: defaults)
temperature = sampling.temperature
topP = sampling.topP
@@ -307,6 +318,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
try container.encode(promptVariantPolicy, forKey: .promptVariantPolicy)
try container.encode(autoCopy, forKey: .autoCopy)
try container.encode(showSourcePreview, forKey: .showSourcePreview)
try container.encode(translationFontSize, forKey: .translationFontSize)
try container.encode(launchAtLogin, forKey: .launchAtLogin)
try container.encode(keepRecentTranslationInMemory, forKey: .keepRecentTranslationInMemory)
try container.encode(hasCompletedOnboarding, forKey: .hasCompletedOnboarding)
@@ -28,6 +28,8 @@ public struct PanelConfiguration: Sendable, Equatable {
public var sampling: SamplingOptions
/// Whether to show the source preview.
public var showSourcePreview: Bool
/// Translation text size in points.
public var translationFontSize: Int
/// Recent targets, most recent first.
public var recentTargets: [ModelLanguage]
@@ -38,6 +40,7 @@ public struct PanelConfiguration: Sendable, Equatable {
keepAlive: String,
sampling: SamplingOptions = .publisherDefault,
showSourcePreview: Bool = true,
translationFontSize: Int = 17,
recentTargets: [ModelLanguage] = []
) {
self.target = target
@@ -45,6 +48,7 @@ public struct PanelConfiguration: Sendable, Equatable {
self.keepAlive = keepAlive
self.sampling = sampling
self.showSourcePreview = showSourcePreview
self.translationFontSize = translationFontSize
self.recentTargets = recentTargets
}
}
@@ -17,6 +17,7 @@ struct AppSettingsTests {
#expect(settings.maxCharactersLatin == 4000)
#expect(settings.maxCharactersCJK == 2000)
#expect(settings.numCtx == 8192)
#expect(settings.translationFontSize == 17)
#expect(!settings.autoCopy)
#expect(!settings.hasCompletedOnboarding)
}
@@ -28,6 +29,7 @@ struct AppSettingsTests {
settings.targetLanguage = "de"
settings.noteTarget(HyMT3Languages.german)
settings.temperature = 0.2
settings.translationFontSize = 22
settings.launchAtLogin = true
settings.hasCompletedOnboarding = true
@@ -82,6 +84,7 @@ struct AppSettingsTests {
"topK": 0,
"repeatPenalty": 9,
"keepModelLoaded": "forever",
"translationFontSize": 99,
"targetLanguage": "xx"
}
"""
@@ -96,6 +99,7 @@ struct AppSettingsTests {
#expect(decoded.topK == 1)
#expect(decoded.repeatPenalty == 2)
#expect(decoded.keepModelLoaded == HyMT3ModelPreset.defaultKeepAlive)
#expect(decoded.translationFontSize == 28)
#expect(HyMT3Languages.resolve(decoded.targetLanguage) != nil)
}
@@ -106,6 +110,7 @@ struct AppSettingsTests {
settings.topP = -1
settings.topK = 0
settings.keepModelLoaded = "forever"
settings.translationFontSize = 99
settings.autoCopy = true
settings.targetLanguage = "xx"
settings.sanitize()
@@ -115,6 +120,7 @@ struct AppSettingsTests {
#expect(settings.topP == 0)
#expect(settings.topK == 1)
#expect(settings.keepModelLoaded == HyMT3ModelPreset.defaultKeepAlive)
#expect(settings.translationFontSize == 28)
#expect(!settings.autoCopy)
#expect(HyMT3Languages.resolve(settings.targetLanguage) != nil)
}
+2 -1
View File
@@ -554,7 +554,7 @@ stateDiagram-v2
| Onboarding | `NSWindow` (not a SwiftUI `Window` scene) | Ollama reachable + version, Hy-MT3 installed, target language, optional Accessibility for Replace; each with a fix button |
| Diagnostics | Window from the menu | Server version, model digests, last 50 timings and error kinds; copy as text; no text or translations |
Panel keyboard: **Esc** close, **⌘C** copy translation, **⌘↩** Replace, **⌘R** retry, **⌘,** Settings. The panel becomes key only when clicked; the source app keeps focus until then.
Panel keyboard: **Esc** close, **⌘C** copy translation, **⌘↩** Replace, **⌘R** retry, **⌘,** Settings. The panel becomes key only when clicked; the source app keeps focus until then. The header has a drag grip; moving the panel keeps its position while it stays open, and a newly shown panel is placed near the cursor (DeepL-like transient position). The translation text size is a Settings value.
Accessibility: every control has an `accessibilityLabel`; the panel exposes source and translation as read-only text elements; full keyboard navigation; respects Reduce Motion and Increase Contrast.
@@ -586,6 +586,7 @@ Accessibility: every control has an `accessibilityLabel`; the panel exposes sour
| `promptVariantPolicy` | `.defaultOnly` / `.contentAware` | `.defaultOnly` until M7 |
| `autoCopy` | Bool | **false** (never copy automatically) |
| `showSourcePreview` | Bool | true |
| `translationFontSize` | Int | 17 pt (12–28) |
| `launchAtLogin` | Bool | false |
| `keepRecentTranslationInMemory` | Bool | true (cleared on quit; no disk) |
| `hasCompletedOnboarding` | Bool | false |
+1
View File
@@ -150,3 +150,4 @@ Legend: `[ ]` open · `[~]` in progress · `[x]` done · `[!]` blocked (explain)
2026-11-26 · T8.5 · Added `scripts/release.sh` (archive unsigned, Developer ID sign, notarise/staple, DMG, `--dry-run`) and `make release`.
2026-11-26 · T8.6 · The compatibility matrix remains a manual 10-app pass; no untested cell is claimed.
2026-11-26 · T8.5 · Added a sibling-family app icon (`make icon`), `CFBundleIconName`/asset catalog wiring, `make install` from the Release build, and `make dmg`/`scripts/make-dmg.sh` with a mounted-image signature check. Dry-run release and local DMG/install were verified.
2026-11-26 · M4 polish · Added a header drag grip backed by an AppKit `performDrag` area; the panel keeps a moved position while visible and only recenters near the cursor when shown again. Added a persisted `translationFontSize` setting (default 17 pt, 12–28) with a Settings stepper and applied it to the translation text.