java-cef
java-cef copied to clipboard
Wrong scroll direction on Linux with OSR enabled.
Describe the bug Scroll direction is reversed on Linux when OSR is enabled.
To Reproduce Steps to reproduce the behavior:
- Open a web page with JCEF (make sure it's long enough with vertical scroll bar)
- Scroll with mouse wheel
- Scroll down
- 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
Scroll direction is usually an OS configuration option. I'm not sure how that is read/represented in Java.
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;
}