fix(panel): drag the window manually and make the whole header a drag bar

performDrag did nothing while the app was inactive (verified: mouseDown reached the drag view, performDrag returned, the frame never changed). Move the window from the screen-space mouse delta in mouseDown/mouseDragged instead.

Make the header a full-width 56 pt bar flush with the panel top, with the drag view behind it and the language/gear buttons above, so the whole top area moves the panel.

Verified: make verify green; synthetic drags from the title, top edge, empty header and grip moved the panel by the full delta while Finder was frontmost; body drag does not move it.
This commit is contained in:
schihei committed 2026-11-26 15:03:31 +01:00
1 parent f8064ac430
commit d126124f97
4 files changed
+75 -44

No files matched your search

+48 -40
View File
@@ -12,17 +12,21 @@ struct PanelView: View {
@State private var showSource = true
var body: some View {
VStack(alignment: .leading, spacing: 10) {
VStack(alignment: .leading, spacing: 0) {
header
if model.configuration.showSourcePreview, let source = model.source {
sourcePreview(source)
VStack(alignment: .leading, spacing: 10) {
if model.configuration.showSourcePreview, let source = model.source {
sourcePreview(source)
}
translationArea
warningArea
errorArea
footer
}
translationArea
warningArea
errorArea
footer
.padding(.horizontal, 16)
.padding(.top, 10)
.padding(.bottom, 16)
}
.padding(16)
.frame(width: 540)
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 14, style: .continuous))
.clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous))
@@ -30,6 +34,7 @@ struct PanelView: View {
RoundedRectangle(cornerRadius: 14, style: .continuous)
.strokeBorder(.separator, lineWidth: 1)
)
.ignoresSafeArea(.container, edges: .top)
.onAppear { showSource = model.configuration.showSourcePreview }
.onChange(of: model.configuration.showSourcePreview) { _, newValue in
showSource = newValue
@@ -40,9 +45,10 @@ struct PanelView: View {
}
private var header: some View {
HStack(spacing: 10) {
ZStack(alignment: .leading) {
WindowDragArea()
ZStack {
WindowDragArea()
Color.primary.opacity(0.04).allowsHitTesting(false)
HStack(spacing: 10) {
HStack(spacing: 10) {
Image(systemName: "line.3.horizontal")
.font(.system(size: 12, weight: .semibold))
@@ -61,38 +67,40 @@ struct PanelView: View {
}
}
.allowsHitTesting(false)
}
.frame(height: 44)
.contentShape(Rectangle())
.help(String(localized: "Drag to move panel"))
.accessibilityLabel(String(localized: "Move panel"))
.accessibilityElement(children: .combine)
.accessibilityLabel(String(localized: "Move panel"))
Spacer()
Button {
showLanguagePicker.toggle()
} label: {
Label(model.configuration.target.localizedDisplayName, systemImage: "globe")
.labelStyle(.titleAndIcon)
Spacer().allowsHitTesting(false)
Button {
showLanguagePicker.toggle()
} label: {
Label(model.configuration.target.localizedDisplayName, systemImage: "globe")
.labelStyle(.titleAndIcon)
}
.accessibilityLabel(String(localized: "Target language"))
.popover(isPresented: $showLanguagePicker, arrowEdge: .bottom) {
LanguagePickerView(
selection: Binding(
get: { model.configuration.target },
set: { language in
Task { await model.setTarget(language) }
}
),
recent: model.configuration.recentTargets
)
}
Button {
openSettings()
} label: {
Image(systemName: "gearshape")
}
.accessibilityLabel(String(localized: "Settings"))
}
.accessibilityLabel(String(localized: "Target language"))
.popover(isPresented: $showLanguagePicker, arrowEdge: .bottom) {
LanguagePickerView(
selection: Binding(
get: { model.configuration.target },
set: { language in
Task { await model.setTarget(language) }
}
),
recent: model.configuration.recentTargets
)
}
Button {
openSettings()
} label: {
Image(systemName: "gearshape")
}
.accessibilityLabel(String(localized: "Settings"))
.padding(.horizontal, 16)
}
.frame(height: 56)
.frame(maxWidth: .infinity)
.help(String(localized: "Drag to move panel"))
}
private var sourceLanguageLabel: String {
+25 -3
View File
@@ -2,7 +2,8 @@ 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.
/// events, and `performDrag` is unreliable while the app is inactive, so the view moves the
/// window itself from the screen-space mouse delta.
struct WindowDragArea: NSViewRepresentable {
func makeNSView(context: Context) -> NSView {
DragView()
@@ -12,8 +13,11 @@ struct WindowDragArea: NSViewRepresentable {
}
private final class DragView: NSView {
private var startMouse = NSPoint.zero
private var startOrigin = NSPoint.zero
override var mouseDownCanMoveWindow: Bool {
true
false
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
@@ -21,7 +25,25 @@ private final class DragView: NSView {
}
override func mouseDown(with event: NSEvent) {
window?.performDrag(with: event)
guard let window else { return }
startMouse = NSEvent.mouseLocation
startOrigin = window.frame.origin
NSCursor.closedHand.push()
}
override func mouseDragged(with event: NSEvent) {
guard let window else { return }
let mouse = NSEvent.mouseLocation
window.setFrameOrigin(
NSPoint(
x: startOrigin.x + mouse.x - startMouse.x,
y: startOrigin.y + mouse.y - startMouse.y
)
)
}
override func mouseUp(with event: NSEvent) {
NSCursor.pop()
}
override func resetCursorRects() {
+1 -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. The left header block and its drag grip move the panel; moving it 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.
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 whole header bar (full width, flush with the top edge) moves the panel; the drag view moves the window itself from the screen-space mouse delta because `performDrag` does nothing while the app is inactive; moving it 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.
+1
View File
@@ -152,3 +152,4 @@ Legend: `[ ]` open · `[~]` in progress · `[x]` done · `[!]` blocked (explain)
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 · Enlarged the drag surface to the whole left header block, with a visible 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.
2026-11-26 · Panel · The source section now stays available as a collapsed “Show source” disclosure row after the user collapses it, instead of disappearing.
2026-11-26 · Panel · Fixed dragging: `performDrag` was a no-op while the non-activating panel's app is inactive, so `WindowDragArea` now moves the window from the screen-space mouse delta. The drag surface is a full-width 56 pt header bar flush with the panel top; buttons stay clickable above it. Verified with synthetic drags from the title, top edge, empty header and grip while Finder was frontmost.