Bug#720690: wrong mouse buttons in events
Package: libsdl-ocaml
Version: 0.9.0-1
Severity: grave
libsdl-ocaml reports left mouse clicks as middle ones, middle mouse clicks as
right ones, and right mouse clicks as mouse-wheel up. This incorrect behaviour
can be verified with the attached program.
Mouse state reporting is not affected.
I believe the origin of the bug to be that the libsdl constants start with
#define SDL_BUTTON_LEFT 1
in SDL_mouse.h (in package libsdl1.2_1.2.15), while the OCaml type
Sdlmouse.button starts with
| BUTTON_LEFT
at tag value 0.
Thus a fix (until later SDL versions change the constants (again?)) would be
replacing the line
r = Val_int(b);
in
static value value_of_mouse_button(Uint8 b)
in sdlevent_stub.c by
r = Val_int(b)-1;
I set the severity to grave, because all reverse-dependencies requiring left
mouse clicks (that should be most, but not all, reverse-dependencies) become
unusable.
Best regards,
Mark Weyer
open Sdlevent
let string_of_button b =
let open Sdlmouse in
match b with
| BUTTON_LEFT -> "left"
| BUTTON_MIDDLE -> "middle"
| BUTTON_RIGHT -> "right"
| BUTTON_WHEELUP -> "up"
| BUTTON_WHEELDOWN -> "down"
| BUTTON_X x -> string_of_int x
;;
Sdl.init [`VIDEO];
let screen = Sdlvideo.set_video_mode ~w:800 ~h:600 ~bpp:32 [] in
Sdlvideo.update_rect screen;
enable_events Sdlevent.mouse_event_mask;
while true do
let e = wait_event () in
(match e with
| MOUSEBUTTONDOWN e -> prerr_string ("mousedown "^string_of_button e.mbe_button)
| MOUSEBUTTONUP e -> prerr_string ("mouseup "^string_of_button e.mbe_button)
| _ -> prerr_string (string_of_event e));
let _,_,buttons = Sdlmouse.get_state () in
prerr_string ("("^String.concat "," (List.map string_of_button buttons)^")");
prerr_string "\n";
flush stderr;
done;
Reply to: