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")) {