Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad76b221 authored by Harry Cutts's avatar Harry Cutts
Browse files

Input: add option to make 3-finger tap a shortcut

By default, it will remain as middle-click, but if the user chooses to
customize it then the native code will make a JNI call to
KeyGestureController via InputManagerService. The KeyGestureController
implementation to actually treat it like a shortcut will be implemented
later.

Test: 3-finger tap with flag enabled, check log line appears
Test: 3-finger tap with flag disabled, check button events appear at
    https://w3c.github.io/uievents/tools/mouse-event-viewer.html
Test: atest com.android.server.input.InputManagerServiceTests
Flag: com.android.hardware.input.touchpad_three_finger_tap_shortcut
Bug: 365063048
Change-Id: I6ba5e2235c7429db173b502df19fc40b28822c0f
parent 98ecea72
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -20,16 +20,18 @@ import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_BOUNCE_KEYS_FL
import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_MOUSE_KEYS;
import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_SLOW_KEYS_FLAG;
import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_STICKY_KEYS_FLAG;
import static com.android.hardware.input.Flags.enableCustomizableInputGestures;
import static com.android.hardware.input.Flags.keyboardA11yBounceKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11yMouseKeys;
import static com.android.hardware.input.Flags.keyboardA11ySlowKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11yStickyKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11yMouseKeys;
import static com.android.hardware.input.Flags.mouseReverseVerticalScrolling;
import static com.android.hardware.input.Flags.mouseSwapPrimaryButton;
import static com.android.hardware.input.Flags.touchpadTapDragging;
import static com.android.hardware.input.Flags.touchpadThreeFingerTapShortcut;
import static com.android.hardware.input.Flags.touchpadVisualizer;
import static com.android.input.flags.Flags.enableInputFilterRustImpl;
import static com.android.input.flags.Flags.FLAG_KEYBOARD_REPEAT_KEYS;
import static com.android.input.flags.Flags.enableInputFilterRustImpl;
import static com.android.input.flags.Flags.keyboardRepeatKeys;

import android.Manifest;
@@ -378,6 +380,15 @@ public class InputSettings {
        return touchpadVisualizer();
    }

    /**
     * Returns true if the feature flag for the touchpad three-finger tap shortcut is enabled.
     *
     * @hide
     */
    public static boolean isTouchpadThreeFingerTapShortcutFeatureFlagEnabled() {
        return enableCustomizableInputGestures() && touchpadThreeFingerTapShortcut();
    }

    /**
     * Returns true if the feature flag for mouse reverse vertical scrolling is enabled.
     * @hide
@@ -497,6 +508,22 @@ public class InputSettings {
                UserHandle.USER_CURRENT);
    }

    /**
     * Returns true if three-finger taps on the touchpad should trigger a customizable shortcut
     * rather than a middle click.
     *
     * The returned value only applies to gesture-compatible touchpads.
     *
     * @param context The application context.
     * @return Whether three-finger taps should trigger the shortcut.
     *
     * @hide
     */
    public static boolean useTouchpadThreeFingerTapShortcut(@NonNull Context context) {
        // TODO(b/365063048): determine whether to enable the shortcut based on the settings.
        return isTouchpadThreeFingerTapShortcutFeatureFlagEnabled();
    }

    /**
     * Whether a pointer icon will be shown over the location of a stylus pointer.
     *
+7 −0
Original line number Diff line number Diff line
@@ -155,3 +155,10 @@ flag {
  description: "Allows privileged focused windows to capture power key events."
  bug: "357144512"
}

flag {
  name: "touchpad_three_finger_tap_shortcut"
  namespace: "input"
  description: "Turns three-finger touchpad taps into a customizable shortcut."
  bug: "365063048"
}
+6 −1
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ import android.hardware.input.IKeyboardBacklightListener;
import android.hardware.input.IStickyModifierStateListener;
import android.hardware.input.ITabletModeChangedListener;
import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputGestureData;
import android.hardware.input.InputManager;
import android.hardware.input.InputSensorInfo;
import android.hardware.input.InputSettings;
@@ -2311,6 +2310,12 @@ public class InputManagerService extends IInputManager.Stub
        }
    }

    // Native callback.
    @SuppressWarnings("unused")
    private void notifyTouchpadThreeFingerTap() {
        mKeyGestureController.handleTouchpadThreeFingerTap();
    }

    // Native callback.
    @SuppressWarnings("unused")
    private void notifySwitch(long whenNanos, int switchValues, int switchMask) {
+9 −0
Original line number Diff line number Diff line
@@ -143,6 +143,10 @@ class InputSettingsObserver extends ContentObserver {
            observer.accept("just booted");
        }

        // TODO(b/365063048): add an entry to mObservers that calls this instead, once we have a
        //   setting that can be observed.
        updateTouchpadThreeFingerTapShortcutEnabled();

        configureUserActivityPokeInterval();
    }

@@ -205,6 +209,11 @@ class InputSettingsObserver extends ContentObserver {
        mNative.setTouchpadRightClickZoneEnabled(InputSettings.useTouchpadRightClickZone(mContext));
    }

    private void updateTouchpadThreeFingerTapShortcutEnabled() {
        mNative.setTouchpadThreeFingerTapShortcutEnabled(
                InputSettings.useTouchpadThreeFingerTapShortcut(mContext));
    }

    private void updateShowTouches() {
        mNative.setShowTouches(getBoolean(Settings.System.SHOW_TOUCHES, false));
    }
+7 −0
Original line number Diff line number Diff line
@@ -1061,6 +1061,13 @@ final class KeyGestureController {
        handleKeyGesture(event, null /*focusedToken*/);
    }

    public void handleTouchpadThreeFingerTap() {
        // TODO(b/365063048): trigger a custom shortcut based on the three-finger tap.
        if (DEBUG) {
            Slog.d(TAG, "Three-finger touchpad tap occurred");
        }
    }

    @MainThread
    private void notifyKeyGestureEvent(AidlKeyGestureEvent event) {
        InputDevice device = getInputDevice(event.deviceId);
Loading