termux / termux-x11

Termux X11 add-on application.
https://termux.dev
GNU General Public License v3.0
1.85k stars 290 forks source link

add Samsung Galaxy Tab trackpad gestures #587

Closed AlphaBs closed 4 months ago

AlphaBs commented 4 months ago

add some gestures of Samsung Galaxy Tab trackpad (SEC-EFDT970).

tested on Samsung Galaxy Tab S8+ (SM-X800), Android 14, OneUI 6.0

I also recorded MotionEvents when I gesture:

move
action: ACTION_HOVER_MOVE, flags: 40, state: 0

tap
action: ACTION_HOVER_EXIT, flags: 40, state: 0 
action: ACTION_DOWN, flags: 0, state: 0
action: ACTION_UP, flags: 40, state: 0
action: ACTION_HOVER_ENTER, flags: 40, state: 0

long tap
action: ACTION_HOVER_EXIT, flags: 40, state: 0
action: ACTION_DOWN, flags: 0, state: 0
action: ACTION_MOVE, flags: 0, state: 0 <- drag
action: ACTION_MOVE, flags: 2000000, state: 0 <- randomly
action: ACTION_UP, flags: 40, state: 0
action: ACTION_HOVER_ENTER, flags: 40, state: 0

two-finger tap
action: ACTION_HOVER_EXIT, flags: 40, state: 0
action: ACTION_DOWN, flags: 40, state: 2
action: ACTION_BUTTON_PRESS, flags: 0, state: 2
action: ACTION_BUTTON_RELEASE, flags: 0, state: 0
action: ACTION_UP, flags: 40, state: 0
action: ACTION_HOVER_ENTER, flags: 40, state: 0

two-finger scroll
action: ACTION_HOVER_EXIT, flags: 40, state: 0
action: ACTION_DOWN, flags: 10000040, state: 0
action: ACTION_MOVE, flags: 10000040, state: 0 <- scroll
action: ACTION_MOVE, flags: 12000040, state: 0 <- randomly
action: ACTION_UP, flags: 40, state: 0
action: ACTION_HOVER_ENTER, flags: 40, state: 0

press left button
action: ACTION_HOVER_EXIT, flags: 40, state: 0
action: ACTION_DOWN, flags: 0, state: 1
action ACTION_BUTTON_PRESS, flags: 0, state: 1
action ACTION_BUTTON_RELEASE, flags: 0, state: 0
action ACTION_UP, flags: 40, state: 0
action ACTION_HOVER_ENTER, flags: 40, state: 0
action ACTION_HOVER_EXIT, flags: 40, state: 0 <- hand off

press right button
action: ACTION_HOVER_EXIT, flags: 40, state: 0
action: ACTION_DOWN, flags: 0, state: 2
action: ACTION_BUTTON_PRESS, flags: 0, state: 2
action: ACTION_BUTTON_RELEASE, flags: 0, state: 0
action: ACTION_UP, flags: 40, state: 0
action ACTION_HOVER_ENTER, flags: 40, state: 0
action: ACTION_HOVER_EXIT, flags: 40, state: 0
twaik commented 4 months ago

I did not dive deep to changes but I already can say that kt will break support for other dex devices. Replacing one constant (0x14000000) with another one (0x10000000) is not an option. Not going to be merged in the current state.

AlphaBs commented 4 months ago

okay do we need completely different way to detect gestures? or just hasFlags(e, 0x10000000) || hasFlags(e, 0x14000000) is enough? (looks like logically same code?)

twaik commented 4 months ago

Again, I did not dive deep to the code. But it will be the first step.

AlphaBs commented 4 months ago

I reverted the constant

twaik commented 4 months ago

Ok, I need to test this on my device and request test from one other guy.

twaik commented 4 months ago

Ok, it works fine on Samsung Galaxy S20 FE (SM-G780F).

twaik commented 4 months ago

Can you please investigate why it does not work with Capture external mouse when possible?

AlphaBs commented 4 months ago

Sure, but my device behaves very strangely (inversed X/Y axis, can't use any gestures) when I turn that option on, even before the PR code.

twaik commented 4 months ago

AFAIK it should be handled by HardwareMouseListener. And I am not sure why it inverts X/Y axis, I probably will implement options like External mouse rotation to сompensate this. But gestures are still unhandled and I do not really have resources to fix this. If you fix it (in another PR) and it will not break existing mice support I will merge it.

AlphaBs commented 4 months ago

I'm just curious, why trackpad need captured pointer? I'm not sure what the expected behavior is.

twaik commented 4 months ago

The "Captured Pointer" feature offers several advantages. Firstly, the navigation and status bars do not appear when the mouse touches the top or bottom edges of the screen. Secondly, Android sends relative mouse events instead of the absolute ones typical in regular mode. This is particularly important in scenarios like 3D games or 3D editors, or in any other situation where an X11 application manipulates the cursor's position, and this behavior needs to be taken into account.

AlphaBs commented 4 months ago

in my device, just removing below code fixes the issue.

TouchInputHandler.java:

// Regular touchpads and Dex touchpad send events as finger too,
// but they should be handled as touchscreens with trackpad mode.
if  (mTouchpadHandler != null && (event.getSource() & InputDevice.SOURCE_TOUCHPAD) == InputDevice.SOURCE_TOUCHPAD) {
    return mTouchpadHandler.handleTouchEvent(view, view, event);
}

With trackpad mode, all gestures including tap, long tap to drag, two-finger tap, two-finger scroll, even three-finger tap are handled well. With direct touch mode, pinch to zoom and multi touch are available.

but X/Y axis are still ininverted. It looks like Android or my trackpad is reporting the wrong MotionEvent. As you said we might need an option to invert this.

AlphaBs commented 4 months ago

MotionEvent from my touchpad with captured pointer should be handled by mInputStrategy and gesture detectors. I don't know why it was handled by mHMListener. Maybe there was an another touchpad that should be handled by HardwareMouseListener? I don't have another touchpad I can't test futher.

twaik commented 4 months ago

There is no two-finger drag feature in the original code. I will not merge it.

twaik commented 4 months ago

Or it is only for the case of Dex? Yeah, it seems like yes.

AlphaBs commented 4 months ago

My device supports two-finger dragging. I can use this gesture in any android app, not just termux-x11. This gesture is useful when I need to drag a very long distance accurately. And I was able to achieve this by simply keeping the onTap state when ACTION_BUTTON_PRESS. (the real event is ACTION_HOVER_EXIT -> ACTION_DOWN -> ACTION_BUTTON_PRESS -> ACTION_MOVE(dragging) -> ACTION_BUTTON_RELEASE -> ACTION_UP) Is this a potential backwards compatibility breaker?

twaik commented 4 months ago

I am not really sure about this. Need some check.

AlphaBs commented 4 months ago

Or it is only for the case of Dex? Yeah, it seems like yes.

yes! Is there anything else I need to do before it merges?

twaik commented 4 months ago

Currenly I have to do some checks on real device.

twaik commented 4 months ago

Probably that is safe, but I can not reproduce two-finger drag behaviour.