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

SDL_DragEvent: Add SDL_DragEvents #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

SDL_DragEvent: Add SDL_DragEvents #13

wants to merge 8 commits into from

Conversation

zbaylin
Copy link
Member

@zbaylin zbaylin commented May 6, 2020

These closely mirror the Drop events, specifically with BEGIN and COMPLETE. When dragging n files, 1 BEGIN, n FILE and 1 COMPLETE events are sent per mouse movement.

Note that currently only the macOS implementation works, but the scaffolding is there for easy Windows/Linux additions!

These closely mirror the Drop events, specifically with
BEGIN and COMPLETE. When dragging n files, 1 BEGIN, n FILE
and 1 COMPLETE events are sent per mouse movement.
@zbaylin zbaylin added the enhancement New feature or request label May 6, 2020
@zbaylin zbaylin requested review from bryphe and glennsl May 6, 2020 23:00
@bryphe
Copy link
Member

bryphe commented May 7, 2020

Awesome!

Just to solidify my understanding of the API:

When dragging n files, 1 BEGIN, n FILE and 1 COMPLETE events are sent per mouse movement.

Does this mean, for every mouse-move, we would get a BEGIN - FILE - COMPLETE set of events?

I wonder if we could simplify and just use a single event (either DRAGFILE or DRAGTEXT - containing the mouse coordinates) - and worry about the complete set of files once the 'DROP' occurs? Is there a use case for sending the full list of files for each drag-movement?

@bryphe
Copy link
Member

bryphe commented May 7, 2020

Trying to fix up the CI here: #14 - the 10.13 macOS image is no longer supported by Azure Pipelines. Also deleted the duplicate pipeline

@zbaylin
Copy link
Member Author

zbaylin commented May 7, 2020

Awesome!

Just to solidify my understanding of the API:

When dragging n files, 1 BEGIN, n FILE and 1 COMPLETE events are sent per mouse movement.

Does this mean, for every mouse-move, we would get a BEGIN - FILE - COMPLETE set of events?

I wonder if we could simplify and just use a single event (either DRAGFILE or DRAGTEXT - containing the mouse coordinates) - and worry about the complete set of files once the 'DROP' occurs? Is there a use case for sending the full list of files for each drag-movement?

This is correct. I did this for two reasons:

  1. It mirrors almost exactly the drop API -- I know this isn't a great reason in and of itself, but I think it's helpful to understand if you understand the drop API.
  2. There are reasons you would want to know what files are being dragged over -- for instance, what if you had a drop target that you wanted to only have accept .png/.jpg files. If you didn't carry the file names being dragged with you, there would be no way to visually identify that dragging, for instance a .gif is unintended behavior.

There are probably other reasons as well, but that was the main one I thought of. Let me know if you can think of a way around this -- I agree that it's pretty convoluted!

@bryphe
Copy link
Member

bryphe commented May 7, 2020

Cool, those seem like reasonable considerations to me - thanks Zach!

You might want to merge master and I think the build should be green now. Otherwise, looks great!

@zbaylin zbaylin requested review from bryphe and glennsl May 8, 2020 17:53
@zbaylin
Copy link
Member Author

zbaylin commented May 8, 2020

Interestingly enough it looks like Wayland responds to all those X events I set up! So Linux is done in theory 😄

@bryphe
Copy link
Member

bryphe commented May 9, 2020

That's awesome, @zbaylin !

Comment on lines +28 to +31
posted = (SDL_PushEvent(&event) > 0);
if (!posted) {
return 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment seems unnecessary, and a bit confusing. I'd expect posted to be read from again later, but it isn't. So it would be simpler to just check the result directly I think:

Suggested change
posted = (SDL_PushEvent(&event) > 0);
if (!posted) {
return 0;
}
if (SDL_PushEvent(&event) == 0) {
return 0;
}

event.drag.windowID = window ? window->id : 0;
event.drag.x = x;
event.drag.y = y;
posted = (SDL_PushEvent(&event) > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

posted is an ambiguous name. It's not immediately obvious whether it refers to a boolean or a count of items posted, for example. Therefore I prefer using isPosted for booleans.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. All the variable names I used I either borrowed from other functions (see SDL_dropevents.c) or modeled them closely after others. In this case it doesn't matter because I can remove the posted reference altogether though!

Comment on lines +70 to +71
SDL_bool dragging;
SDL_bool dropping;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

Suggested change
SDL_bool dragging;
SDL_bool dropping;
SDL_bool isDragging;
SDL_bool isDropping;

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

Successfully merging this pull request may close these issues.

3 participants