java-cef icon indicating copy to clipboard operation
java-cef copied to clipboard

Wrong scroll direction on Linux with OSR enabled.

Open ionull opened this issue 1 year ago • 2 comments

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 avatar Oct 19 '23 02:10 ionull

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

magreenblatt avatar Jan 09 '24 19:01 magreenblatt

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;
}

1fxe avatar Jan 11 '24 01:01 1fxe