diff --git a/App/AppEnvironment.swift b/App/AppEnvironment.swift index 13bce26..5ba2655 100644 --- a/App/AppEnvironment.swift +++ b/App/AppEnvironment.swift @@ -214,6 +214,7 @@ final class AppEnvironment { keepAlive: settings.keepModelLoaded, sampling: settings.samplingOptions, showSourcePreview: settings.showSourcePreview, + translationFontSize: settings.translationFontSize, recentTargets: settings.recentTargets ) } diff --git a/App/Panel/PanelController.swift b/App/Panel/PanelController.swift index 073181a..7bf3f34 100644 --- a/App/Panel/PanelController.swift +++ b/App/Panel/PanelController.swift @@ -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 { + 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 diff --git a/App/Panel/PanelView.swift b/App/Panel/PanelView.swift index 8aec5c8..7f17e20 100644 --- a/App/Panel/PanelView.swift +++ b/App/Panel/PanelView.swift @@ -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) diff --git a/App/Panel/WindowDragArea.swift b/App/Panel/WindowDragArea.swift new file mode 100644 index 0000000..3ed74bf --- /dev/null +++ b/App/Panel/WindowDragArea.swift @@ -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) + } +} diff --git a/App/Resources/de.lproj/Localizable.strings b/App/Resources/de.lproj/Localizable.strings index 9495f9c..fdee77e 100644 --- a/App/Resources/de.lproj/Localizable.strings +++ b/App/Resources/de.lproj/Localizable.strings @@ -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"; diff --git a/App/Resources/en.lproj/Localizable.strings b/App/Resources/en.lproj/Localizable.strings index 1b71512..122f7a9 100644 --- a/App/Resources/en.lproj/Localizable.strings +++ b/App/Resources/en.lproj/Localizable.strings @@ -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"; diff --git a/App/Settings/SettingsView.swift b/App/Settings/SettingsView.swift index 81b1672..a79433d 100644 --- a/App/Settings/SettingsView.swift +++ b/App/Settings/SettingsView.swift @@ -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")) { diff --git a/Packages/SprachmittlerKit/Sources/SprachmittlerCore/AppSettings.swift b/Packages/SprachmittlerKit/Sources/SprachmittlerCore/AppSettings.swift index 6d2be14..18dfde5 100644 --- a/Packages/SprachmittlerKit/Sources/SprachmittlerCore/AppSettings.swift +++ b/Packages/SprachmittlerKit/Sources/SprachmittlerCore/AppSettings.swift @@ -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) diff --git a/Packages/SprachmittlerKit/Sources/SprachmittlerCore/PanelViewModel.swift b/Packages/SprachmittlerKit/Sources/SprachmittlerCore/PanelViewModel.swift index e7b0b8c..8b70749 100644 --- a/Packages/SprachmittlerKit/Sources/SprachmittlerCore/PanelViewModel.swift +++ b/Packages/SprachmittlerKit/Sources/SprachmittlerCore/PanelViewModel.swift @@ -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 } } diff --git a/Packages/SprachmittlerKit/Tests/SprachmittlerCoreTests/AppSettingsTests.swift b/Packages/SprachmittlerKit/Tests/SprachmittlerCoreTests/AppSettingsTests.swift index a4e1f46..ebb838e 100644 --- a/Packages/SprachmittlerKit/Tests/SprachmittlerCoreTests/AppSettingsTests.swift +++ b/Packages/SprachmittlerKit/Tests/SprachmittlerCoreTests/AppSettingsTests.swift @@ -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) } diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 476b2c1..f2a2753 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -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 | diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 95cd4fc..9f544ce 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -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.