The mouse has moved with a button held down. The current button state is in Fl::event_state(). The mouse position is in Fl::event_x() and Fl::event_y().
In order to receive FL_DRAG
events, the widget must return non-zero when handling FL_PUSH.
Yeah - that might work - ... here's Greg's example tweaked to track the button state, and this does seem like it might be an option:
Ian, on which platform did you test this code?
I noticed that it works well on Windows (cross-compiled, executed by `wine`) but it doesn't work correctly on Linux. The problem is - AFAICT - within FLTK event delivery under Linux because Fl::event_button() does not always return the correct value. Note that it should return one for left and 3 for right button.
This means that we have *two* issues:
(1) Wrong button state delivery on Linux when two or more buttons are pressed simultaneously and then released. This prevents Ian's workaround to work correctly on Linux.
(2) The supposedly wrong termination of the "drag" status when one of two buttons is released and the other button is still down. This is what the OP reported.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/6badefc3-75f0-4758-81b0-4fa340464b50n%40googlegroups.com.
On Wednesday, 12 July 2023 at 15:25:02 UTC+1 Albrecht Schlosser wrote:
Ian, on which platform did you test this code?
Windows-10. (It's what I have access to here.)TBH I assumed it would Just Work elsewhere, but...
I noticed that it works well on Windows (cross-compiled, executed by `wine`) but it doesn't work correctly on Linux. The problem is - AFAICT - within FLTK event delivery under Linux because Fl::event_button() does not always return the correct value. Note that it should return one for left and 3 for right button.
Ah...
OK, that's a problem.And, now that you state it, I think it is not a new problem, I think this (or variations of it) have been observed in the past...
If you are using my code, it might be interesting to see what happens if you:
- click left and hold, drag,
- click MIDDLE,
- release MIDDLE,
- release left button
And also:
- click RIGHT and hold, drag,
- click MIDDLE,
- release MIDDLE,
- release RIGHT button
[ 62, win(0,0,240,240), screen 0, scale 100%] FL_PUSH at ( 68, 57), button 1 down [ 63, win(0,0,240,240), screen 0, scale 100%] FL_PUSH at ( 68, 57), button 2 down [ 64, win(0,0,240,240), screen 0, scale 100%] FL_DRAG at ( 68, 57) [ 65, win(0,0,240,240), screen 0, scale 100%] FL_DRAG at ( 69, 57) [ 66, win(0,0,240,240), screen 0, scale 100%] FL_DRAG at ( 69, 58) [ 67, win(0,0,240,240), screen 0, scale 100%] FL_RELEASE at ( 69, 58), button 2 up [ 68, win(0,0,240,240), screen 0, scale 100%] FL_MOVE at ( 69, 58) [ 69, win(0,0,240,240), screen 0, scale 100%] FL_RELEASE at ( 69, 58), button 2 up [ 70, win(0,0,240,240), screen 0, scale 100%] FL_MOVE at ( 69, 58)
I specifically separated out the middle and right button cases because (with the OP / Greg code) I could get odd behaviours by clicking the middle button (the original code treated right and middle as "the same button" when they are not so I got release events for "the wrong" button...)
This means that we have *two* issues:
(1) Wrong button state delivery on Linux when two or more buttons are pressed simultaneously and then released. This prevents Ian's workaround to work correctly on Linux.
I'm not sure this is new, now I think about it.ISTR it relates to the way that the X11 system (or such...) handles event delivery. I think it is like the way that keyboard key-up / key-down modifiers keys issue, where you can't reliably see the state of the modifier keys until you get the next key-down.
I have a (very vague) recollection that with the mouse you don't know which mouse buttons are down until the next push event, or something like that, so the release event often just reports the last pushed button... Or something.Anyway, my recollection was that it was a Hard Thing to fix.
Are you using X11 or Wayland?
Maybe Wayland is better?
[ 86, win(10,80,240,240), screen 0, scale 100%] FL_PUSH at ( 94, 51), button 1 down [ 87, win(10,80,240,240), screen 0, scale 100%] FL_PUSH at ( 94, 51), button 3 down [ 88, win(10,80,240,240), screen 0, scale 100%] FL_DRAG at ( 95, 51) [ 89, win(10,80,240,240), screen 0, scale 100%] FL_RELEASE at ( 95, 51), button 3 up [ 90, win(10,80,240,240), screen 0, scale 100%] FL_MOVE at ( 95, 51) [ 91, win(10,80,240,240), screen 0, scale 100%] FL_RELEASE at ( 95, 51), button 1 up [ 92, win(10,80,240,240), screen 0, scale 100%] FL_MOVE at ( 95, 51)As one can see, the correct buttons are reported but the first FL_RELEASE terminates the drag operation.
(2) The supposedly wrong termination of the "drag" status when one of two buttons is released and the other button is still down. This is what the OP reported.
And if we do this, we need to be aware how many buttons there are - just the 2 or 3 we currently support might not trap all the edge cases since modern mice (and the USB HID protocol) support a lot more buttons, potentially.
The behavior is "the same" (similar), i.e. whenever two buttons are pressed and released, at least one FL_RELEASE event returns the wrong value for Fl::event_button().
You can see the issue in our test/handle_events.cxx demo program as well. No matter which button I release first, it always returns the wrong button state.
I'm not sure this is new, now I think about it.ISTR it relates to the way that the X11 system (or such...) handles event delivery. I think it is like the way that keyboard key-up / key-down modifiers keys issue, where you can't reliably see the state of the modifier keys until you get the next key-down.I remember this regarding keyboard events, but I was not aware of such an issue with mouse buttons.
Are you using X11 or Wayland?Good question. Really good question !!!
Maybe Wayland is better?
Nope, actually I *was* using Wayland which exhibited this issue.
Testing with X11 shows that X11 is correct!
However, the premature termination of FL_DRAG is still an issue under X11: My tests on Windows, macOS, X11 and Wayland showed that this particular behavior is the same on all supported platforms.
commit 44840af076569ab6c692d7dcbcc70022d1d40087
Wayland: keep mouse button state across push/release events
Notes:
(1) Fl::e_state holds the current state of all mouse buttons which is
returned by Fl::event_buttons() - "plural form".
(2) Fl::e_keysym holds the "key" of the current event which can be a
mouse button, returned by Fl::event_button() - "singular form".
I hope I didn't miss anything. My tests with a modified demo program
(Erco's demo with Ian's mods plus mine) seems to indicate that this
is correct across platforms (macOS not yet tested).OK, I'm confident that I fixed the wrong behavior in commit 44840af076569ab6c692d7dcbcc70022d1d40087.
This also fixes the previous wrong behavior (before my last commit) which reset the mouse button state in Fl::e_state whenever a button press or release was handled. See the commit log why this was wrong:
commit 44840af076569ab6c692d7dcbcc70022d1d40087
On Wednesday, 12 July 2023 at 16:37:01 UTC+1 Albrecht Schlosser wrote:
However, the premature termination of FL_DRAG is still an issue under X11: My tests on Windows, macOS, X11 and Wayland showed that this particular behavior is the same on all supported platforms.
Yes. Which means it is something we are doing internally, I imagine. Which is unfortunate...