Skip to content

File drag & drop support for Windows, Linux and WASM #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2022

Conversation

urholaukkarinen
Copy link
Contributor

@urholaukkarinen urholaukkarinen commented Apr 17, 2022

Miniquad can now handle dropped files on Windows, Linux and WASM.

A file path on Windows may be at most 260 characters long (16 bits each). On Mac it is 1024 bytes and on Linux it is 4096 bytes. Is it okay to have a 4096 bytes long array in sapp_event? If PathBuf is used, the event can no longer be Copy.

In browsers you cannot read a file from the filesystem with a path, so the file bytes are read immediately in the file drop event. In native applications the file reading can be left to the client.

Miniquad can now handle dropped files on Windows and WASM.
Since WASM cannot read the filesystem directly, the file bytes are
read on Javascript side and sent to WASM.
@urholaukkarinen
Copy link
Contributor Author

looks like sokol has functions for getting dropped file paths and data, and the event itself does not have anything except the event type. That's probably better than having file path and data in the event.

A single FILES_DROPPED event is sent when one or more files are dropped.
File count, paths and bytes can be requested with functions
`dropped_file_count`, `dropped_file_path` and `dropped_file_bytes`.
@urholaukkarinen urholaukkarinen force-pushed the file-drag-drop-support branch from 79fe982 to a8f0e33 Compare April 21, 2022 14:26
@urholaukkarinen
Copy link
Contributor Author

I changed the implementation so that sapp_event no longer carries the file path or bytes. Currently the drag & drop feature is always enabled. I've tested this with modified egui-miniquad demo on Windows, Linux and web.

@urholaukkarinen urholaukkarinen marked this pull request as ready for review April 21, 2022 14:35
@urholaukkarinen urholaukkarinen changed the title Initial file drag & drop support for Windows and WASM File drag & drop support for Windows, Linux and WASM Apr 21, 2022
@not-fl3
Copy link
Owner

not-fl3 commented Apr 23, 2022

Wow, impressive work, thank you!

I was thinking how to merge it for a little bit, sorry for delay :)

I have some opinions on the API here, but, taking into account that all sapp-related stuff is being heavily refactored right now (yes, I still did not opened this PR...) - I would rather merge this as is and later on will change a few things. Hope this sounds good to you!

Thanks again!

@not-fl3 not-fl3 merged commit 41ff52f into not-fl3:master Apr 23, 2022
@urholaukkarinen
Copy link
Contributor Author

Sounds good to me! I tried to mimic the existing api a bit when implementing this, but I did also expect I would need to make some changes after reviews.

@nokola
Copy link
Contributor

nokola commented Apr 23, 2022

This is awesome! Adding some info: on Windows you can have > 260 character paths:

  1. Press the Windows key, type gpedit.msc and press Enter.
  2. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS.
  3. Double click the Enable NTFS long paths option and enable it.

@urholaukkarinen
Copy link
Contributor Author

@nokola very good point. Currently this implementation assumes the path is at most 260 characters, but it would be easy to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants