Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 更新日志

## [0.2.96] - 2026-11-18

### 改进

- 显示标题栏时,空间不足会从文件名中间省略,优先保留文件大小、像素尺寸和缩放比例。窗口拉宽后恢复完整文件名。
- 隐藏标题栏时,顶部移窗会将原始按下事件交给 macOS。系统未接管且应用继续收到拖动事件时,PicSee 会尝试跟随指针移动窗口。

## [0.2.95] - 2026-11-18

### 新增
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ PICSEE_SKIP_LOCAL_INSTALL=1 Scripts/build-app.sh
指定版本号构建:

```bash
PICSEE_VERSION=0.2.95 PICSEE_BUILD_NUMBER=95 Scripts/build-app.sh
PICSEE_VERSION=0.2.96 PICSEE_BUILD_NUMBER=96 Scripts/build-app.sh
```

## 生成 DMG 安装包
Expand All @@ -187,15 +187,15 @@ Scripts/build-dmg.sh

构建完成后会得到:

- DMG: `build/dmg/PicSee-0.2.95.dmg`
- DMG: `build/dmg/PicSee-0.2.96.dmg`

同样可以指定版本号:

```bash
PICSEE_VERSION=0.2.95 Scripts/build-dmg.sh
PICSEE_VERSION=0.2.96 Scripts/build-dmg.sh
```

可运行 `bash Tests/build-dmg-tests.sh` 检查打包参数传递,运行 `bash Tests/verify-dmg.sh build/dmg/PicSee-0.2.95.dmg` 挂载并验证实际安装包的应用签名、应用内容与构建产物一致、Applications 链接、背景和图标布局。GitHub Actions 会在公证前执行安装包验证。
可运行 `bash Tests/build-dmg-tests.sh` 检查打包参数传递,运行 `bash Tests/verify-dmg.sh build/dmg/PicSee-0.2.96.dmg` 挂载并验证实际安装包的应用签名、应用内容与构建产物一致、Applications 链接、背景和图标布局。GitHub Actions 会在公证前执行安装包验证。

## 使用方式

Expand Down Expand Up @@ -329,14 +329,14 @@ git push origin master
再创建版本标签并推送:

```bash
git tag v0.2.95
git push origin v0.2.95
git tag v0.2.96
git push origin v0.2.96
```

工作流会自动生成:

- Release: `v0.2.95`
- Asset: `PicSee-0.2.95.dmg`
- Release: `v0.2.96`
- Asset: `PicSee-0.2.96.dmg`

## Release 说明

Expand Down
2 changes: 1 addition & 1 deletion Scripts/build-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ICON_ICNS="$ROOT_DIR/build/AppIcon.icns"
cd "$ROOT_DIR"
ARM64_BUILD_DIR="$ROOT_DIR/.build-arm64"
X64_BUILD_DIR="$ROOT_DIR/.build-x86_64"
APP_VERSION="${PICSEE_VERSION:-0.2.95}"
APP_VERSION="${PICSEE_VERSION:-0.2.96}"
APP_BUILD_NUMBER="${PICSEE_BUILD_NUMBER:-1}"
SKIP_LOCAL_INSTALL="${PICSEE_SKIP_LOCAL_INSTALL:-0}"
CODESIGN_IDENTITY="${PICSEE_CODESIGN_IDENTITY:--}"
Expand Down
2 changes: 1 addition & 1 deletion Scripts/build-dmg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ APP_DIR="$ROOT_DIR/build/PicSee.app"
DMG_STAGE_DIR="$ROOT_DIR/build/dmg-stage"
DMG_DIR="$ROOT_DIR/build/dmg"
LEGACY_PKG_ROOT_DIR="$ROOT_DIR/build/pkg-root"
APP_VERSION="${PICSEE_VERSION:-0.2.95}"
APP_VERSION="${PICSEE_VERSION:-0.2.96}"
APP_BUILD_NUMBER="${PICSEE_BUILD_NUMBER:-${APP_VERSION##*.}}"
CODESIGN_IDENTITY="${PICSEE_CODESIGN_IDENTITY:--}"
DMG_NAME="PicSee-${APP_VERSION}.dmg"
Expand Down
1 change: 1 addition & 0 deletions Scripts/test-swift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cd "$(dirname "$0")/.."
# Tests requiring WindowServer, actual presentation layers, OCR hardware or
# pasteboard services are an explicit separate group, never silently skipped.
UI_TESTS='ImageDefaultDisplayInteractionTests|DesktopWallpaperInteractionTests|MouseWheelBehaviorTests|UpdateSessionTests|ImagePrintingTests|AppMenuTests|AuthorizationFocusRecoveryTests|ImageCanvasAnimationTests|ImageCanvasAnimationPreferenceTests|ImageCanvasPixelScaleTests|ImageCanvasCursorZoomTests|ImageCloseGestureInteractionTests|ImageCanvasFileDragTests|ImageCanvasOCRTests|ScreenshotCaretLayoutTests|ScreenshotNavigationInteractionTests|ScreenshotShortcutTests|ScreenshotSizeFieldLayoutTests|SettingsMenuRoutingTests|SettingsWindowTests|SingleWindowTests|TransparencyBackgroundTests|ViewerTitleBarPreferenceTests|ViewerWindowTests|WindowActivationTests|WindowPinningTests|testSavedPNGUsesChosenDimensionsAndIncludesAnnotations|testScreenSamplingPreservesOffsetCropAndRotationAtNativeScale|testScreenSizeExportUsesLinearSamplingForFineStrokesAtElevenPercent|testGeneratedFinderScriptCompiles|reattachingViewerDuringFullScreenDoesNotStopPlayback|testPreferenceWrittenByAnotherProcessRefreshesOpenSettings|DefaultImageFormatRegistrationTests'
UI_TESTS+='|testWindowResizeTruncatesOnlyFilenameAndRestoresFullTitle'
MODE="${1:-logic}"
if [ "$#" -gt 0 ]; then shift; fi
case "$MODE" in
Expand Down
30 changes: 19 additions & 11 deletions Sources/PicSee/App/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ final class ViewerWindow: NSWindow {
override var canBecomeKey: Bool { true }
override var canBecomeMain: Bool { true }

func updateImageTitle(from viewModel: ImageViewerViewModel, titleBarVisible: Bool) {
let newTitle = titleBarVisible
? viewModel.titleBarText(fitting: frame.width, styleMask: styleMask)
: viewModel.currentFilename
if title != newTitle {
title = newTitle
}
}

override func animationResizeTime(_ newFrame: NSRect) -> TimeInterval {
if let automaticImageResizeTarget,
newFrame.isApproximatelyEqual(to: automaticImageResizeTarget) {
Expand Down Expand Up @@ -359,7 +368,7 @@ final class WindowManager {
guard let self, let window else { return }
self.applyTitleBarVisibility(visible, to: window)
if let viewModel {
window.title = visible ? viewModel.titleBarText : viewModel.currentFilename
window.updateImageTitle(from: viewModel, titleBarVisible: visible)
}
},
onFixedWindowChanged: { [weak self, weak window] fixed in
Expand Down Expand Up @@ -394,19 +403,14 @@ final class WindowManager {
appearanceObserver = ViewerPreferences.shared.$snapshot.map(\.theme).removeDuplicates()
.sink { [weak window] theme in window?.appearance = theme.appearance }
window.collectionBehavior = [.fullScreenPrimary, .fullScreenAllowsTiling]
let updateTitle = { [weak window, weak viewModel] in
guard let window, let viewModel else { return }
window.updateImageTitle(from: viewModel, titleBarVisible: ViewerTitleBarPreference.isVisible())
}
titleObserver = viewModel.$currentURL
.combineLatest(viewModel.$displayScale, viewModel.$image)
.receive(on: RunLoop.main)
.sink { [weak window, weak viewModel] _, _, _ in
guard let window, let viewModel else { return }
window.title = ViewerTitleBarPreference.isVisible() ? viewModel.titleBarText : viewModel.currentFilename
}

LanguageSettings.bind(window) { [weak viewModel] window in
guard let viewModel else { return }
window.title = ViewerTitleBarPreference.isVisible() ? viewModel.titleBarText : viewModel.currentFilename
}
window.title = titleBarVisible ? viewModel.titleBarText : viewModel.currentFilename
.sink { _, _, _ in updateTitle() }
window.isMovableByWindowBackground = false
window.isOpaque = true
window.backgroundColor = .windowBackgroundColor
Expand All @@ -426,6 +430,7 @@ final class WindowManager {
window.minSize = minimumWindowSize
window.contentViewController = hostingController
window.setFrame(initialWindowFrame, display: false)
LanguageSettings.bind(window) { _ in updateTitle() }
applyFixedWindowState(WindowFramePreference.isFixedEnabled(), to: window)
automaticSizePreferenceObserver = ViewerPreferences.shared.$snapshot
.map(\.automaticWindowSizeEnabled).removeDuplicates().dropFirst()
Expand Down Expand Up @@ -516,6 +521,7 @@ final class WindowManager {
self.automaticSizingPausedByUser = true
},
onWindowResized: { [weak self, weak window] in
updateTitle()
guard let self, let window, !self.isApplyingAutomaticFrame,
self.updateViewerRestoreURL == nil,
!window.isNativeFullScreenTransitionActive,
Expand Down Expand Up @@ -569,13 +575,15 @@ final class WindowManager {
onExitFullScreen: { [weak self, weak window] in
guard let self, let window else { return }
self.restoreStyleMaskAfterFullScreen(to: window)
updateTitle()
// Navigation in full screen defers sizing until the normal frame is restored.
if let image = self.currentViewModel?.image {
self.resizeWindowToImage(image, in: window)
}
},
onFailToEnterFullScreen: { [weak window] in
window?.restoreStyleMaskAfterFailedFullScreenEntry()
updateTitle()
},
slideshow: viewModel.slideshow
)
Expand Down
37 changes: 32 additions & 5 deletions Sources/PicSee/Viewer/ImageCanvasView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ final class CanvasNSView: NSView, NSMenuItemValidation {

private enum DragType {
case none
case window
case window(pendingMouseDown: NSEvent?)
case windowMovingInApp
case longPressWindow(pendingMouseDown: NSEvent?)
case pan
case textSelection
Expand Down Expand Up @@ -1521,8 +1522,10 @@ final class CanvasNSView: NSView, NSMenuItemValidation {
return
}

if isInTopDragRegion(point) {
dragType = .window
if isInTopDragRegion(point), let window {
dragType = .window(pendingMouseDown: event)
dragStartPoint = window.convertPoint(toScreen: event.locationInWindow)
dragStartWindowFrame = window.frame
return
}

Expand Down Expand Up @@ -1564,8 +1567,22 @@ final class CanvasNSView: NSView, NSMenuItemValidation {
switch dragType {
case .none, .fileExport:
break
case .window:
window?.performDrag(with: event)
case .window(let pendingMouseDown):
guard let window else { return }
if let pendingMouseDown {
dragType = .window(pendingMouseDown: nil)
window.performDrag(with: pendingMouseDown)
return
}
// If the window server took over, leave the movement to it.
guard window.frame.origin == dragStartWindowFrame?.origin else {
dragType = .none
return
}
dragType = .windowMovingInApp
moveWindow(with: event)
case .windowMovingInApp:
moveWindow(with: event)
case .longPressWindow(let pendingMouseDown):
guard let pendingMouseDown, let window else { return }
// AppKit uses the original mouse-down event to hand off the drag.
Expand Down Expand Up @@ -1615,6 +1632,16 @@ final class CanvasNSView: NSView, NSMenuItemValidation {
resetMouseDrag()
}

private func moveWindow(with event: NSEvent) {
guard let window, window.isMovable, !window.styleMask.contains(.fullScreen),
let dragStartPoint, let dragStartWindowFrame else { return }
let point = window.convertPoint(toScreen: event.locationInWindow)
window.setFrameOrigin(CGPoint(
x: dragStartWindowFrame.minX + (point.x - dragStartPoint.x),
y: dragStartWindowFrame.minY + (point.y - dragStartPoint.y)
))
}

private func cancelImageDragCandidate() {
guard fileDragStartScreenPoint != nil || windowLongPressCandidate != nil || isLongPressMovingWindow else { return }
resetMouseDrag()
Expand Down
18 changes: 15 additions & 3 deletions Sources/PicSee/Viewer/ImageViewerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,22 @@ final class ImageViewerViewModel: ObservableObject {
}

var titleBarText: String {
titleBarText()
}

func titleBarText(
fitting frameWidth: CGFloat = .infinity,
styleMask: NSWindow.StyleMask = []
) -> String {
if isFolderEmpty { return L10n.text("%1$@ — 此文件夹中没有可浏览的图片", String(describing: currentFilename)) }
return [imageMetadataText, zoomPercentageText]
.compactMap { $0 }
.joined(separator: " | ")
return ViewerTitleBarText.fitting(
filename: currentFilename,
fileSize: fileSizeText,
pixelSize: imagePixelSizeText,
zoom: zoomPercentageText,
frameWidth: frameWidth,
styleMask: styleMask
)
}

var previousURL: URL? {
Expand Down
56 changes: 56 additions & 0 deletions Sources/PicSee/Viewer/ViewerTitleBarText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import AppKit

@MainActor
enum ViewerTitleBarText {
static func fitting(
filename: String,
fileSize: String?,
pixelSize: String?,
zoom: String,
frameWidth: CGFloat,
styleMask: NSWindow.StyleMask
) -> String {
let separator = " | "
let details = [fileSize, pixelSize, zoom].compactMap { $0 }.joined(separator: separator)
let fullTitle = filename + separator + details

func fits(_ title: String) -> Bool {
NSWindow.minFrameWidth(withTitle: title, styleMask: styleMask) <= frameWidth
}

if frameWidth == .infinity || fits(fullTitle) { return fullTitle }
if !fits(details) {
let compactDetails = [pixelSize, zoom].compactMap { $0 }.joined(separator: separator)
return fits(compactDetails) ? compactDetails : pixelSize ?? zoom
}

let ellipsis = "…"
let suffix = separator + details
guard fits(ellipsis + suffix) else { return details }

let characters = Array(filename)
let pathExtension = (filename as NSString).pathExtension
let extensionLength = pathExtension.isEmpty ? 0 : 1 + pathExtension.count
let keepsExtension = extensionLength > 0 && extensionLength < characters.count &&
fits(String(characters.prefix(1)) + ellipsis + String(characters.suffix(extensionLength)) + suffix)
let minimumEndLength = keepsExtension ? extensionLength : 0

// Measure each complete candidate so the separator and all metadata fit in AppKit's title area.
var lower = keepsExtension ? extensionLength + 1 : 0
var upper = characters.count - 1
var best = ellipsis + suffix
while lower <= upper {
let length = lower + (upper - lower) / 2
let endLength = max(minimumEndLength, length / 2)
let candidate = String(characters.prefix(length - endLength)) + ellipsis
+ String(characters.suffix(endLength)) + suffix
if fits(candidate) {
best = candidate
lower = length + 1
} else {
upper = length - 1
}
}
return best
}
}
39 changes: 37 additions & 2 deletions Tests/PicSeeTests/ImageCanvasFileDragTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,48 @@ final class ImageCanvasFileDragTests: XCTestCase {
XCTAssertEqual(canvas.panOffset.width, 20, accuracy: 0.001)
}

func testTitlelessTopDragKeepsMovingWindowEvenOutsideBoundary() throws {
try down(200, 285)
func testTitlelessTopDragMovesWindowIfNativeDragDoesNotTakeOver() throws {
let original = window.frame
let mouseDown = try event(.leftMouseDown, 200, 285)
canvas.mouseDown(with: mouseDown)
XCTAssertEqual(window.moveCount, 0)
try drag(430, 330)
XCTAssertTrue(window.lastWindowDragEvent === mouseDown)
try drag(450, 340)
XCTAssertEqual(window.frame.origin, CGPoint(x: original.minX + 250, y: original.minY + 55))
XCTAssertEqual(window.frame.size, original.size)
try drag(215, 295)
XCTAssertEqual(window.frame.origin, CGPoint(x: original.minX + 265, y: original.minY + 65))
try up(450, 340)
let frameAfterRelease = window.frame
try drag(460, 350)
XCTAssertEqual(window.frame, frameAfterRelease)
XCTAssertEqual(window.moveCount, 1)
XCTAssertTrue(startedURLs.isEmpty)
}

func testTitlelessTopDragLeavesMovementToNativeDragAfterItMovesWindow() throws {
try down(200, 285)
try drag(230, 290)
window.setFrameOrigin(CGPoint(x: 300, y: 300))
try drag(250, 300)
XCTAssertEqual(window.frame.origin, CGPoint(x: 300, y: 300))
XCTAssertEqual(window.moveCount, 1)
}

func testTitlelessTopClickDoesNotStartDragOrReuseItsPress() throws {
try down(200, 285)
try up(200, 285)
try drag(230, 290)
XCTAssertEqual(window.moveCount, 0)

let nextMouseDown = try event(.leftMouseDown, 205, 285)
canvas.mouseDown(with: nextMouseDown)
try drag(430, 330)
XCTAssertEqual(window.moveCount, 1)
XCTAssertTrue(window.lastWindowDragEvent === nextMouseDown)
}

func testTitlelessBottomRightDragKeepsResizingEvenOutsideBoundary() throws {
XCTAssertNil(canvas.debugResizeAnchor(at: CGPoint(x: 360, y: 40)),
"The old interior resize area must remain available for image interaction")
Expand Down
Loading
Loading