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

bug: horizontal scrolling is inverted for Allegro5 backend with touchpads #3394

Closed
nobody-special666 opened this issue Aug 8, 2020 · 4 comments

Comments

@nobody-special666
Copy link

nobody-special666 commented Aug 8, 2020

Branch:
docking + tables merged

Back-end/Renderer/Compiler/OS
Allegro5 / Linux / Synaptics touchpad

Back-ends: imgui_impl_XXX.cpp + imgui_impl_XXX.cpp (or specify if using a custom engine/back-end)
imgui_impl_allegro5.cpp

Operating System:
Ubuntu 20.04

Issue:
I was testing with the imgui_demo compiled using the Allegro5 backend
and my touchpad configured for natural scrolling and I noticed the horizontal scrollbars
are all moving in the opposite direction to what they should be. Vertical scrollbars are working fine.
Here is a patch to correct.
P.S: I don't know if this would break mouse wheels and haven't tested it with Allegro5 backend on other platforms.
Thanks for ImGui

diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp
index 4a467c30..1f328732 100644
--- a/examples/imgui_impl_allegro5.cpp
+++ b/examples/imgui_impl_allegro5.cpp
@@ -332,7 +332,7 @@ bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* ev)
         if (ev->mouse.display == g_Display)
         {
             io.MouseWheel += ev->mouse.dz;
-            io.MouseWheelH += ev->mouse.dw;
+            io.MouseWheelH -= ev->mouse.dw;
             io.MousePos = ImVec2(ev->mouse.x, ev->mouse.y);
         }
         return true;
@ocornut
Copy link
Owner

ocornut commented Aug 10, 2020

and my touchpad configured for natural scrolling

Could you clarify what this means? Does toggling the settings means you get opposite values in the ev->mouse.dw field ?

How do SDL and GLFW behave for you in term of horizontal scrolling direction?

@nobody-special666
Copy link
Author

nobody-special666 commented Aug 10, 2020

Yes I mean the sign for the ev->mouse.dw field appears to be inverted,
but it's coming from Allegro5 that way so I just flipped it.
I tested demo with SDL2 and GLFW and scrolling direction is working fine without change.
I'll try test it on a different windows laptop and see if I can reproduce the error.

@ocornut
Copy link
Owner

ocornut commented Aug 10, 2020

Yes I mean the sign for the ev->mouse.dw field appears to be inverted,

My question is, can you confirm if altering your OS/WM/X11 setting changes the sign of any value reported to Allegro?

Allegro Windows:

      case WM_MOUSEHWHEEL: {
         if (accept_mouse_event()) {
            int d = GET_WHEEL_DELTA_WPARAM(wParam);
            _al_win_mouse_handle_hwheel(d, false, win_display);
            return TRUE;
         }
[....]

void _al_win_mouse_handle_hwheel(int raw_dw, bool abs, ALLEGRO_DISPLAY_WIN *win_disp)
{
   int d;
   int new_w;

   if (!installed)
      return;

   if (!abs) {
      raw_mouse_w += raw_dw;
   }
   else {
      raw_mouse_w = raw_dw;
   }

   new_w = al_get_mouse_wheel_precision() * raw_mouse_w / WHEEL_DELTA;
   d = new_w - mouse_state.w;
   mouse_state.w = new_w;

   generate_mouse_event(ALLEGRO_EVENT_MOUSE_AXES,
      mouse_state.x, mouse_state.y, mouse_state.z, mouse_state.w, mouse_state.pressure,
      0, 0, 0, d,
      0, (void*)win_disp);
}

Allegro X11:
https://github.com/liballeg/allegro5/blob/5.2.6/src/linux/lmouse.c

static void wheel_motion_handler(int x_button, ALLEGRO_DISPLAY *display)
{
   int dz = 0, dw = 0;
   if (x_button == Button4) dz = 1;
   if (x_button == Button5) dz = -1;
   if (x_button == 6) dw = -1;
   if (x_button == 7) dw = 1;
   if (dz == 0 && dw == 0) return;

GLFW Window:

        case WM_MOUSEHWHEEL:
        {
            // This message is only sent on Windows Vista and later
            // NOTE: The X-axis is inverted for consistency with macOS and X11
            _glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0);
            return 0;
        }

GLFW X11:

            // Modern X provides scroll events as mouse button presses
            else if (event->xbutton.button == Button4)
                _glfwInputScroll(window, 0.0, 1.0);
            else if (event->xbutton.button == Button5)
                _glfwInputScroll(window, 0.0, -1.0);
            else if (event->xbutton.button == Button6)
                _glfwInputScroll(window, 1.0, 0.0);
            else if (event->xbutton.button == Button7)
                _glfwInputScroll(window, -1.0, 0.0);

Looking at all this it seems Allegro does the opposite of GLFW but is consistent (at least accross X11/windows) in doing so and therefore your patch seems correct..

ocornut added a commit that referenced this issue Aug 10, 2020
@ocornut
Copy link
Owner

ocornut commented Aug 10, 2020

Merged with 009276b, thank you,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants