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

Wrong scroll direction on Linux with OSR enabled. #452

Open
ionull opened this issue Oct 19, 2023 · 2 comments
Open

Wrong scroll direction on Linux with OSR enabled. #452

ionull opened this issue Oct 19, 2023 · 2 comments
Labels
bug Bug report

Comments

@ionull
Copy link

ionull commented Oct 19, 2023

Describe the bug
Scroll direction is reversed on Linux when OSR is enabled.

To Reproduce
Steps to reproduce the behavior:

  1. Open a web page with JCEF (make sure it's long enough with vertical scroll bar)
  2. Scroll with mouse wheel
  3. Scroll down
  4. It scroll up instead of scroll down

Expected behavior
Scroll as system side.

Versions (please complete the following information):

  • OS: Ubuntu 22.04
  • Java Version: java zulu-javafx-17.40.19
  • JCEF Version: gc6a20bc
  • CEF Version: 116.0.19
@ionull ionull added the bug Bug report label Oct 19, 2023
@magreenblatt
Copy link
Collaborator

Scroll direction is usually an OS configuration option. I'm not sure how that is read/represented in Java.

@1fxe
Copy link
Contributor

1fxe commented Jan 11, 2024

I have a proposal for a somewhat hacky solution

This is the code in X11Window class responsible for making the mouse event.

if (xev.get_type() == XConstants.ButtonPress) {
    MouseWheelEvent mwe = new MouseWheelEvent((Component)getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen,
       modifiers,
       x, y,
       xbe.get_x_root(),
       xbe.get_y_root(),
       1,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
       3,button==4 ?  -1 : 1);
    postEventToEventQueue(mwe);
}

So when scrolling down normally the button passed is 5 and delta is positive, X11Window does keep track of lastButton so in the native code we could fetch that and just reverse this behavior on linux

Made a POC that works, its just working in the case for natural scrolling, we would have to do the opposite of getWheelRotation() to calculate the delta properly

jclass xWindow = env->FindClass("sun/awt/X11/XWindow");
jfieldID lastButtonId = env->GetStaticFieldID(xWindow, "lastButton", "J");
jlong button = env->GetStaticLongField(xWindow, lastButtonId);
 
// Would check against getWheelRotation 
if (button == 5L) { 
   delta = -3;
} else {
   delta = 3;
}

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

No branches or pull requests

3 participants