Repository navigation
Added modifier support to mouse events - #328
Conversation
|
Please make it clear somewhere (for example by adding a |
|
Will do! I'll take a quick crack at implementing modifier support for it first. I didn't previously because prior to the commit this morning all modifiers were stubs in the Wayland implementation. |
|
I see. This will require some non-trivial changes to the backend, as the information of modifiers state is not currently available in the callback handling pointer events. |
b83e3ce to
8322b52
Compare
|
@vberger Thanks for the heads up. I've added a comment indicating that the Wayland implementation is currently a stub. I will look into a solution, however it sounds as though it might be best to leave the Wayland implementation a stub and potentially implement it in a follow up pull request. In it's current state this PR only contains relatively simple changes. |
|
Unfortunately Our options for supporting modifiers on mouse events under wayland are:
I'm not very familiar with any of these apis, Is there any value in using |
|
This API change doesn't make sense to me. Mouse events aren't out of parity with keyboard events for lack of having keyboard event information in them any more than, say, resize events are. Why can't downstream apps track the state they care about themselves? |
|
Hmmm ... it seems to make pretty good sense to me, but I guess I'm looking at it from the point X11/xlib (which I use primarily). which treats mouse motion events (XBindingEvent), mouse button click events (XButtonEvent), and keypress events (XKeyEvent) similarly, passing along modifier state with each. Reference: https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html I don't really think comparing mouse input to resize events is a fair comparison. Mouse input such as button clicks are commonly bound to actions just as frequently as keypresses and I believe a consistent api for both would be desirable. I guess it's a question of ergonomics more than anything else, but I don't really see any dounside to including the modifier state here. The complexity of this change is very small, with supporting Wayland only being slightly non-trivial. |
|
@Ralith Also I'm just curious, especially in case this pull request is rejected ... You make it sound pretty simple to track the state of the modifiers in a downstream app. Is there a reasobably easy way to do this in a cross platform way without reproducing much of the code in this library? How would you implement this? |
|
The same way I'd track the state of any input; set the state on press, unset it on release. Admittedly, this may lead to desync if focus is lost across state boundaries on at least some platforms, which is why platform APIs treat modifiers specially at all. That said, I'm not happy about working around platform API design bugs by polluting winit events with random fragments of unrelated state. X11 is really not a great reference for sane API design. The above is my opinion only; I'm not speaking on behalf of the project. |
|
@Ralith we used to take that approach in Alacritty before winit ever supported sending mods with key input events, and it had the desync issue you’re mentioning. |
|
@gilbertw1 Thus, I suggest to keep the possible implementation details for wayland to an other follow-up PR, and focus here on the question of whether we want this is winit at all. At first I had the same reaction as @Ralith , aka "what does this have to do with pointer events at all?", but I understand the need of having this information when processing pointer events (many games behave differently on click/shift+click/ctrl+click. And given the way winit treats it, it's not easy for downstream apps to track them precisely, mostly in case of lost/gained focus. To solve this, I currently see two alternatives:
Thoughts @tomaka , @Ralith , @mitchmindtree ? |
|
@vberger wouldn't a Since most platforms simply include the modifier state with each native event already, it seems like the most reliable solution is to just forward them as part of the winit event. This has the added benefit of being easier for developers using winit to consume. We discussed these same points in the PR which added keyboard mods to the winit keyboard events. |
Fair point. If wayland is the only platform to emit "modifiers changed" events, then sure, the simplest is to align it with what other platforms to. |
|
Accurate modifier state tracking, regardless of focus, can be implemented on X11 via the No idea about windows/OSX, though. At worst you could poll the modifier state before emitting other events. |
|
@Ralith The main issue I think is a scenario like this: The winit app is not focused. The user holds Currently, winit's API has no way to reflect this, unless maybe emulating keypresses to forward the modifiers state, but this seems wrong to me. |
|
@vberger what's wrong with emulating keypresses to communicate the fact that some keypresses happened? |
|
To be honest it's mostly edge cases. But imagine a game has some special action bound on a modifier keypress, and the person playing this game also has a meta action configured on their desktop environment using this key as well. There could be interfering. On the other hand, I'll admit the keypress emulation would be nice for some projects using winit, like smithay, so... I have no hard opinion on that. |
|
Any more thoughts on this? I personally lean towards forwarding the modifiers state with each event since the precedent is already set with keypress events, it's the simplest solution from an implementation and consumer standpoint, and removes any ambiguity. Whichever option is ultimately decided upon, I'd be happy to amend this pull request or create a new one implementing the desired behavior. Thanks! |
|
I'd like to propose that we move forward with the API implemented in this PR, and here's why.
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
|
|
I don't have code for a better solution, and the proposed solution is arguably conventional, so my concerns shouldn't be blockers. |
939bb8e to
1222b70
Compare
|
Just a heads up, I've rebased this PR against master and added emscripten support to it. |
tomaka
left a comment
There was a problem hiding this comment.
Looks good.
Please also add an entry in the CHANGELOG.
| device_id: ::DeviceId(::platform::DeviceId::Wayland(DeviceId)), | ||
| state: state, | ||
| button: button, | ||
| modifiers: ModifiersState::default(), |
There was a problem hiding this comment.
Please add a // TODO comment whenever you use this dummy value.
1222b70 to
47ea7d2
Compare
|
@tomaka I've updated the PR to relect both of your comments. |
Only define `precision highp sampler2D` in OpenGL ES.
This pull request adds modifier suppport to the
MouseMoved,MouseWheel, andMouseInputevents. This is modeled after the modifier support added forKeyboardInputin #112.This will allow mouse events to achieve parity with keyboard events and support use cases like: alacritty/alacritty#146.