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

Dex touchpad fix: orientation, click, gesture, etc. #617

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

knyipab
Copy link
Contributor

@knyipab knyipab commented Apr 28, 2024

In short, it should fix #419. The suggested changes should have no impact on existing functionality. If you need to review the code changes and features added, I hope below explanation helps and won't be too long.

Root Causes of #419

  • Unlike touchscreen, the tocuchpad reports coordinates in its own (physical) orientation, does not flip along with display rotation.
  • Also, the comment at line 185 "Regular touchpads and Dex touchpad ... should be handled as touchscreens with trackpad mode" is not implemented as expected. Indeed, mTouchpadHandler.handleTouchEvent() will handle pointer inputs as hardware mouse, calling mHMListener.onTouch because of the "if condition" (|| (event.getPointerCount() == 1 && mTouchpadHandler == null && (event.getSource() & InputDevice.SOURCE_TOUCHPAD) == InputDevice.SOURCE_TOUCHPAD)) being positive.

My solution

  • Remove the "if condition" so that touchpad event can invoke TrackpadInputStrategy. Note that we could not simply create another variable to be invoked because the code logics test mInputStrategy at multiple places. I found it easiest to just override mInputStrategy in DeX (SamsungDexUtils.checkDeXEnabled(mContext)). This makes sense because (1) finger input in DeX can only be touchpad not touchscreen, and (2) mouse input handler in DeX is also overrided.
  • The flipped axis issue is tackled by introducing another option for captured pointer transformation, namely "Automatic (for touchpad)". Under this option, the rotation of display ID 1 (primary display I believe) will be checked and motion input will be handled accordingly. Hopefully this could handle both Pad and DeX touchpad issue.
  • The 3-finger down gesture to "toggle EK bar" is change to "release pointer capture" under DeX mode. This is because (1) EK bar is useless and cannot be pressed in captured pointer mode, and (2) if user enters DeX using solely soft touchpad and soft keyboard, there should be a way to exit the capture mode and the more-than-2-finger gesture is just right play that role (3-finger as shortcut to release capture plus minimize window, 4-finger to only release capture). At the end, the current way for soft touchpad & soft keyboard under DeX to use EK bar is perhaps to first release pointer capture and use volume key to toggle EK bar.

@knyipab
Copy link
Contributor Author

knyipab commented Apr 29, 2024

Force pushed fix to crash in "Automatic (for touchpad)" mode mentioned in #419.

Comment on lines +180 to +181
lorieView.releasePointerCapture();
lorieParent.releasePointerCapture();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to ask for pointer release twice. Pointer capture is activity-wide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied from somewhere else without much thinking about it. Feel free to amend if you think appropriate

Comment on lines +190 to +193
toggleKeyboardVisibility(MainActivity.this);
Log.d("MainActivity", "Toggling keyboard visibility");
if(inputMethodManager != null) {
inputMethodManager.showSoftInput(lorieView, InputMethodManager.SHOW_FORCED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to trigger toggling IME twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During my previous test, toggleKeyboardVisibility did not work. However, I cannot reproduce it now, so I think one toggleKeyboardVisibility should just work.

I was mistaken in previous test perhaps because the keyboard toggling feature disappear sometimes when the app switches from phone screen to external display or vice versa. It isn't too annoying so now I simply close and re-open everytime.

Comment on lines +406 to +413
if (capturedPointerTransformation == CapturedPointerTransformation.AUTO) {
for (Display display : mDisplayManager.getDisplays()) {
if (display.getState() == Display.STATE_ON) {
transform = display.getRotation() % 4;
break;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason to obtain display via DisplayManager and not using mActivity.getLorieView().getDisplay()? This definitely will break in multi-display mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cuz in smarphone HDMI external display DeX mode (using phone as software touchpad), the transformation should depend on phone orientation (=soft touchpad) but mActivity.getLorieView().getDisplay() return HDMI display which is useless.
This enumeration works well for case of both external display DeX + software touchpad and , tablet hardware touchpad.

I do reckon the risk of not working well in some more complex setup, such as external display DeX + hardware touchpad, or Tablet in external display DeX + hardware touchpad, and perhaps more etc.

A better approach might be depends on input device information. But I don't have both devices so I used that workaround. FYR. soft touchpad might be "sec_touchpad" but I am not so sure. In case you want to implement:

Screenshot from 2024-05-17 08-01-47

@knyipab
Copy link
Contributor Author

knyipab commented May 24, 2024

@twaik perhaps we should rehthink the gesture, though I do not have a concrete idea in mind. After some time testing this PR with soft touchpad in DeX, I found that there are not enough gesture/button to accomplish all four features below.

feature default gesture/button (with this PR) comment
escape pointer capture 3+ finger swipe down necessary cuz soft keyboard often has no "ESC" key
activate soft keyboard 3+ finger swipe up necessary cuz soft touchpad users often rely on soft keyboard
toggle EK bar vol down highly preferred feature as EK bar is useful for DeX + soft keyboard users
volume up / down None when preference set to not intercept physical vol+/- buttons, it will work adjust volume, but sacrifices the function of toggling EK bar

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

Successfully merging this pull request may close these issues.

Touchpad right-click cancel and two-finger gesture axis inversion issue
2 participants