Skip to content

feat(desktop): drag files out of the app from a view - #2837

Merged
houko merged 2 commits into
mainfrom
feat/2829-drag-source
Dec 1, 2026
Merged

houko merged 2 commits into
mainfrom
feat/2829-drag-source

Conversation

@houko

@houko houko commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

An app can now drag files it names out of a view to Finder, Explorer, a Linux file manager or any other app that takes files, the outgoing twin of OnFileDrop. core.View.Desktop.DragFiles returns absolute paths; the drag starts once the press moves past the platform's drag distance, so a shorter press stays a press. DragFilesMove lets the destination move the files instead of copying them, and OnDragFilesEnd receives a core.DragOperation (copied, moved, linked or cancelled). nsgotest's App.DragFilesOut(selector, op) (and Surface.DragFilesOut) returns the paths a view offers and ends the drag with the given operation, and View.Props.DragFileList() shows what a view offers.

  • Core sends a snapshot of the files as ViewProps.DragFiles and sets the view's EventDragFilesEnd bit. EventMask has no free bit, so it shares EventOpenURL's, an answer that names no view; one with an ID is a drag's end.
  • macOS: an NSDraggingSession from the view's NSView (its NSDraggingSource), one NSDraggingItem per file with an NSURL file URL and its Finder icon.
  • Windows: the files' shell item array bound to BHID_DataObject (CF_HDROP and shell ID lists), run with SHDoDragDrop; an optimized move is read from Performed DropEffect.
  • Linux: a GtkDragSource on the surface whose prepare answers only for the view the current press went down on, with a GdkFileList. Every press and release clears that view first, so a press a scroll bar, a text selection, a braked touch or a hosted widget takes, or a press released short of GTK's threshold, cannot later start a drag of another view's files.
  • Tests: core and nsgotest models, the macOS end-operation mapping and source mask, the Windows DROPEFFECT mapping, and a Linux native test that drives prepare/drag-end by hand: a press on the view released short of the threshold fires OnPress and leaves nothing to drag, a following press the text selection takes prepares no drag, and a press on the view prepares one whose cancellation reaches OnDragFilesEnd.
  • iOS, Android, the web and TSX are recorded in docs/roadmap.md.

Fixes #2829

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

Screenshots

None

Verification

  • head: 375b833fc03dfbadbfc59016149caeb9a72af6cd
  • base: a10710d3c89cd6b94c4131684d10ffc0fe7385c3 (main)
  • commands (remote darwin/amd64 build host, Go 1.27.3):
    • go tool nsgo check -target macos,windows,linux -jobs 6 → exit code 0 (vets linux, macos and windows on arm64 and x64, test files included)
    • go tool nsgo test ./core ./nsgotest ./internal/driver → exit code 0 (1545 passed, 0 failed, 1 skipped)
    • go tool nsgo test -run 'TestDragOperation|TestFileDragMask' ./internal/platform/macos → exit code 0 (2 passed)
  • result: passed
  • not covered: the Linux native test (TestFileDragOutAnswersOnlyThePressOnItsView) and the Windows test (TestDropOperationMapsTheDragsEnd) were compiled by the vet above but not run, since no Linux or Windows host was available; the macOS run was on x64 only. The below-threshold press path on macOS and Windows has no backend test (it goes through each backend's existing pan activation). Real drags to Finder, Explorer and a Linux file manager were not checked by hand on any desktop.

Checklist

  • The title is a Conventional Commit, such as fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.
  • Docs whose facts change are updated, and a capability users can see has a line in a changelog.d/ fragment, not in CHANGELOG.md.
  • New third-party code, assets and dependencies name their source and license.

houko added 2 commits December 1, 2026 12:21
Add core.View.Desktop.DragFiles, DragFilesMove and OnDragFilesEnd: a drag on the view past the platform's drag distance carries the files to Finder, Explorer, a Linux file manager or another app, through an NSDraggingSession on macOS, SHDoDragDrop with the shell's data object on Windows and a GtkDragSource with a GdkFileList on Linux. nsgotest's DragFilesOut returns the paths offered and ends the drag with an operation.

Fixes #2829
…t press

Reuse the existing g_file_new_for_path binding on Linux instead of declaring it twice, build the core test's file list with NewSignalFunc, and clear the view a press would drag files from on every press and release, so a press a scroll bar, selection, braked touch or hosted widget takes cannot start a drag of an earlier press's files. Add mapping tests for the macOS and Windows end operations and a Linux native test of the drag source.
@github-actions github-actions Bot added local-ci-skipped enhancement New feature or request labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

This pull request has no valid Local CI declaration for its head commit, so a maintainer audits it before merging:

  • base is not a commit SHA
  • result is not one of pass, fail or skipped
  • commands is missing or still the template's text
  • not covered is missing or still the template's text

Run the checks on the head commit, fill the block in the template, then push or edit the body: this label and comment update on their own.

@github-actions github-actions Bot added size/L documentation Improvements or additions to documentation macOS Windows Linux core labels Dec 1, 2026
@houko
houko merged commit 78c8239 into main Dec 1, 2026
48 checks passed
@houko
houko deleted the feat/2829-drag-source branch December 1, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core documentation Improvements or additions to documentation enhancement New feature or request Linux local-ci-skipped macOS size/L Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop: no way to drag a file out of the app to Finder, Explorer or other apps (drag source)

1 participant