We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1173

Summary: No mouse wheel event on linux/x11 (incl. suggested patch)
Product: SDL Reporter: Matthias <matthias.schweinoch>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: Patched SDL_x11events.c with mouse wheel support
diff / patch file for SDL_x11events.c

Description Matthias 2011-03-20 23:07:02 UTC
Created attachment 596 [details]
Patched SDL_x11events.c with mouse wheel support

On X11, SDL 1.3 does not generate a mouse wheel event. Instead, button down/buttton up events are generated by SDL. After looking at the code in SDL_x11events.c, I assume this is due to the fact that X11 does not have a dedicated mouse wheel event.

I did a little research on the behavior of mouse wheel events on X11 systems. Apparently, mouse wheel events generate a button down/button up event with the same time, i.e. with exact same timestamp. 

Attached you can find my changes to SDL_x11events.c, which generates SDL mouse wheel events for those button down events that have a button release event immediately following it (for the same button, and with the same timestamp).

I did have to make an assumption: As standard X11 implementations know only 5 buttons, I have mapped Button4 to "wheel up" (i.e. +1), and Button5 to "wheel down" (i.e. -1).

Note that if you include this patch, no SDL button down/up events will be generated on X11 platforms for mouse wheel events (which is probably a significant change for those that have programmed their code to work with them).
Comment 1 Matthias 2011-03-20 23:07:50 UTC
Created attachment 597 [details]
diff / patch file for SDL_x11events.c
Comment 2 Sam Lantinga 2011-04-04 12:56:09 UTC
Thank you very much for your patch for SDL 1.3!

Do you give me permission to release your code with SDL 1.3 and future
versions of SDL under both the LGPL and a closed-source commercial
license?
Comment 3 Matthias 2011-04-04 22:58:50 UTC
(In reply to comment #2)
> Thank you very much for your patch for SDL 1.3!
> 
> Do you give me permission to release your code with SDL 1.3 and future
> versions of SDL under both the LGPL and a closed-source commercial
> license?

You're welcome and: Yes, I do:-)
Comment 4 Sam Lantinga 2011-04-05 09:41:48 UTC
Thanks, your patch is in!
http://hg.libsdl.org/SDL/rev/4e46a7b6773d