Skip to content
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

Support Drag and Drop SDL_EVENT_DROP_TEXT in Cocoa #10323

Merged
merged 1 commit into from
Jul 21, 2024

Conversation

Dragon-Baroque
Copy link
Contributor

Into src/video/cocoa/SDL_cocoawindow.m

  • Support Copy in addition to Generic as Drag and Drop operation,
  • Register and Support public.utf8-plain-text for SDL_EVENT_DROP_TEXT.
    This is the equivalent of text/plain;charset=utf-8 for macOS.

Description

Main target : Provide TEXT Drag and Drop SDL_EVENT_DROP_TEXT to macOS ( Cocoa )

  • Add kUTTypeUTF8PlainText or public.utf8-plain-text into RegisterForDraggedTypes on the NSWindow
  • Add NSPasteboardTypeString or public.utf8-plain-text into AvailableTypesFromArray on the NSPasteboard,
  • Handle NSPasteboardTypeString as NSString, split it by lines like the text/plain;charset=utf-8 Drags and Drops, submit each line to SDL_SendDropText.

Secondary target : Support Drag and Drop Copy in addition to Drag and Drop Generic

  • in draggingEntered and draggingUpdated.

Secondary target : Report properly the pointer location at Drop

  • Use SDL_SendDropPosition instead of SDL_SendMouseMotion in performDragOperation.

Secondary target : Print suitable messages in the SDL Log

  • When entering draggingEntered on Window Enter, draggingUpdated on Pointer Move in Window, performDragOperation on Drop,
  • Displaying the Pasteboard types and string contents in performDragOperation on Drop,
  • When about to emit File and Text Drop events by SDL_SendDropFile and SDL_SendDropText in performDragOperation on Drop.

@DominusExult
Copy link
Contributor

DominusExult commented Jul 20, 2024

I've tested this on macOS 14.5 for arm64 and for intel I tested this on macOS 10.11/10.14/14.5.
This is part 1 of three PRs, the others for Linux and Windows, to add drop text to SDL3.

Edit: we are using this with Exult (which has already been ported to SDL3 by the OP) and Exult Studio. Exult Studio is a GTK+3 app and is our world editor. You can drag graphics onto Exult to change the game world. Not too long ago we changed our drag and drop from native ways to use the SDL 2 code to drop the files onto Exult. But this is a bit limited and extending SDL's drop code would help a lot.
And overall (apart from our wants) we think being able to drop text into an SDL app makes sense.

@slouken
Copy link
Collaborator

slouken commented Jul 20, 2024

In general this looks good. You should wrap the verbose logging with #ifdef DEBUG_DRAG_AND_DROP or something similar.

@Dragon-Baroque
Copy link
Contributor Author

Dragon-Baroque commented Jul 20, 2024

You should wrap the verbose logging with #ifdef DEBUG_DRAG_AND_DROP or something similar.

I placed them into the INPUT log category to avoid having them displayed by default as they would be in the APPLICATION category.
Could you make a SDL_LOG_CATEGORY_DRAGDROP category ?

Add-on

I could also push them to log priority DEBUG instead of INFO.
But then, DEBUG being so verbose in general, I would very much like a DRAGDROP category...

@slouken
Copy link
Collaborator

slouken commented Jul 21, 2024

I don't think drag and drop is a large enough subsystem to warrant its own category (e.g. audio, video, etc.) but we can move a bunch of the input logging to the verbose level if it's too much. Which ones are particularly verbose?

@slouken
Copy link
Collaborator

slouken commented Jul 21, 2024

These diagnostic messages should definitely be at the debug level.

  src/video/cocoa/SDL_cocoawindow.m
    Support Copy in addition to Generic as Drag and Drop operation,
    Register and Support public.utf8-plain-text for SDL_EVENT_DROP_TEXT.
@Dragon-Baroque
Copy link
Contributor Author

Dragon-Baroque commented Jul 21, 2024

These diagnostic messages should definitely be at the debug level.

Done ( and Rebased to main ).

But I found DEBUG to be too verbose not in the category INPUT, but in all categories, because I thought that I only could control the Log subsystem programmatically , using SDL_SetLogPriority or SDL_SetLogPriorities and that only enabling SDL_SetLogPriorities(SDL_LOG_PRIORITY_DEBUG) for all categories, when building Exult in DEBUG mode, made sense long term.

I was ignorant of the SDL_HINT_LOGGING hint, in other words.

But now that I know about it, I feel that it is the most important hint in SDL 3 for us application developers, before even the backend choosing hints SDL_HINT_ AUDIO + VIDEO + RENDER_DRIVER.
It is well documented in SDL_hints.h provided you know its name.

Could you highlight it in some way in the Migration README, for example in carrying into it the sample in SDL_hints.h under a header like How to enable SDL Log with only an environment variable... It should be illuminated like a lamp post.

@slouken
Copy link
Collaborator

slouken commented Jul 21, 2024

Looks good! I'll go ahead and merge this, and I created a separate issue to track illuminating SDL_HINT_LOGGING.

Thanks for the feedback!

@slouken slouken merged commit 68cabc2 into libsdl-org:main Jul 21, 2024
39 checks passed
@Dragon-Baroque Dragon-Baroque deleted the sdl3-droptext-macos branch August 1, 2024 14:43
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