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

Commit 941b4189 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Mouse: Plumb swap mouse primary button setting" into main

parents b13bf71c 5c3835ce
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ 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.touchpadVisualizer;
import static com.android.input.flags.Flags.enableInputFilterRustImpl;
@@ -371,6 +372,14 @@ public class InputSettings {
        return mouseReverseVerticalScrolling();
    }

    /**
     * Returns true if the feature flag for mouse swap primary button is enabled.
     * @hide
     */
    public static boolean isMouseSwapPrimaryButtonFeatureFlagEnabled() {
        return mouseSwapPrimaryButton();
    }

    /**
     * Returns true if the touchpad visualizer is allowed to appear.
     *
@@ -548,6 +557,47 @@ public class InputSettings {
                UserHandle.USER_CURRENT);
    }

    /**
     * Whether the primary mouse button is swapped on connected mice.
     *
     * @param context The application context.
     * @return Whether mice will have their primary buttons swapped, so that left clicking will
     * perform the secondary action (e.g. show menu) and right clicking will perform the primary
     * action.
     *
     * @hide
     */
    public static boolean isMouseSwapPrimaryButtonEnabled(@NonNull Context context) {
        if (!isMouseSwapPrimaryButtonFeatureFlagEnabled()) {
            return false;
        }

        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.MOUSE_SWAP_PRIMARY_BUTTON, 0, UserHandle.USER_CURRENT)
                != 0;
    }

    /**
     * Sets whether mice will have their primary buttons swapped between left and right
     * clicks.
     *
     * @param context The application context.
     * @param swapPrimaryButton Whether swapping the primary button is enabled.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setMouseSwapPrimaryButton(@NonNull Context context,
            boolean swapPrimaryButton) {
        if (!isMouseSwapPrimaryButtonFeatureFlagEnabled()) {
            return;
        }

        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.MOUSE_SWAP_PRIMARY_BUTTON, swapPrimaryButton ? 1 : 0,
                UserHandle.USER_CURRENT);
    }

    /**
     * Whether Accessibility bounce keys feature is enabled.
     *
+11 −0
Original line number Diff line number Diff line
@@ -6218,6 +6218,16 @@ public final class Settings {
        public static final String MOUSE_REVERSE_VERTICAL_SCROLLING =
                "mouse_reverse_vertical_scrolling";
        /**
         * Whether to enable swapping the primary button for connected mice.
         *
         * When enabled, right clicking will be the primary button and left clicking will be the
         * secondary button (e.g. show menu).
         * @hide
         */
        public static final String MOUSE_SWAP_PRIMARY_BUTTON =
                "mouse_swap_primary_button";
        /**
         * Pointer fill style, specified by
         * {@link android.view.PointerIcon.PointerIconVectorStyleFill} constants.
@@ -6457,6 +6467,7 @@ public final class Settings {
            PRIVATE_SETTINGS.add(SCREEN_FLASH_NOTIFICATION_COLOR);
            PRIVATE_SETTINGS.add(DEFAULT_DEVICE_FONT_SCALE);
            PRIVATE_SETTINGS.add(MOUSE_REVERSE_VERTICAL_SCROLLING);
            PRIVATE_SETTINGS.add(MOUSE_SWAP_PRIMARY_BUTTON);
        }
        /**
+1 −0
Original line number Diff line number Diff line
@@ -224,6 +224,7 @@ message SystemSettingsProto {
        option (android.msg_privacy).dest = DEST_EXPLICIT;

        optional SettingProto reverse_vertical_scrolling = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
        optional SettingProto swap_primary_button = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
    }

    optional Mouse mouse = 38;
+1 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ public class SystemSettings {
                Settings.System.AUTO_LAUNCH_MEDIA_CONTROLS,
                Settings.System.LOCALE_PREFERENCES,
                Settings.System.MOUSE_REVERSE_VERTICAL_SCROLLING,
                Settings.System.MOUSE_SWAP_PRIMARY_BUTTON,
                Settings.System.TOUCHPAD_POINTER_SPEED,
                Settings.System.TOUCHPAD_NATURAL_SCROLLING,
                Settings.System.TOUCHPAD_TAP_TO_CLICK,
+1 −0
Original line number Diff line number Diff line
@@ -222,6 +222,7 @@ public class SystemSettingsValidators {
        VALIDATORS.put(System.POINTER_SCALE,
                new InclusiveFloatRangeValidator(DEFAULT_POINTER_SCALE, LARGE_POINTER_SCALE));
        VALIDATORS.put(System.MOUSE_REVERSE_VERTICAL_SCROLLING, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.MOUSE_SWAP_PRIMARY_BUTTON, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.TOUCHPAD_POINTER_SPEED, new InclusiveIntegerRangeValidator(-7, 7));
        VALIDATORS.put(System.TOUCHPAD_NATURAL_SCROLLING, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.TOUCHPAD_TAP_TO_CLICK, BOOLEAN_VALIDATOR);
Loading