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

Unverified Commit 0c9cbec9 authored by Jesse Chan's avatar Jesse Chan Committed by Michael Bestas
Browse files

Implement click to take partial screenshot [1/3]



Default to the old long press behaviour when the feature is enabled.

Change-Id: I5fc37f818b06db2bd2d315cffee2041a740781ed
Signed-off-by: default avatarJesse Chan <jc@lineageos.org>
parent 6ba963bc
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ class PolicyRequestProcessor(
                val screenshot =
                    captureDisplay(type.displayId) ?: error("Failed to capture screenshot")
                return original.copy(
                    type = TAKE_SCREENSHOT_FULLSCREEN,
                    bitmap = screenshot,
                    userHandle = params.owner,
                    topComponent = params.contentTask.component,
+19 −2
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD;
import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_KEY_OTHER;
import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_OTHER;
import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
import static android.view.WindowManagerGlobal.ADD_OKAY;
import static android.view.WindowManagerGlobal.ADD_PERMISSION_DENIED;
@@ -665,6 +666,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    private boolean mHandleVolumeKeysInWM;

    // Click volume down + power for partial screenshot
    boolean mClickPartialScreenshot;

    private boolean mPendingKeyguardOccluded;
    private boolean mKeyguardOccludedChanged;

@@ -1001,6 +1005,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.CLICK_PARTIAL_SCREENSHOT), false, this,
                    UserHandle.USER_ALL);
            updateSettings();
        }

@@ -1964,9 +1971,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private long getScreenshotChordLongPressDelay() {
        long delayMs = DeviceConfig.getLong(
        // If click to partial screenshot is enabled, restore pre Android QPR1
        // default delay (500ms) in case SCREENSHOT_KEYCHORD_DELAY is shorter than it.
        long delayMs = Long.max(mClickPartialScreenshot ? 500 : 0, DeviceConfig.getLong(
                DeviceConfig.NAMESPACE_SYSTEMUI, SCREENSHOT_KEYCHORD_DELAY,
                ViewConfiguration.get(mContext).getScreenshotChordKeyTimeout());
                ViewConfiguration.get(mContext).getScreenshotChordKeyTimeout()));
        if (mKeyguardDelegate.isShowing()) {
            // Double the time it takes to take a screenshot from the keyguard
            return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * delayMs);
@@ -1980,7 +1989,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private void cancelPendingScreenshotChordAction() {
        boolean hadMessage = mHandler.hasMessages(MSG_SCREENSHOT_CHORD);
        mHandler.removeMessages(MSG_SCREENSHOT_CHORD);
        if (mClickPartialScreenshot && hadMessage) {
            mHandler.sendMessage(mHandler.obtainMessage(
                    MSG_SCREENSHOT_CHORD, TAKE_SCREENSHOT_SELECTED_REGION, SCREENSHOT_OTHER));
        }
    }

    private void cancelPendingAccessibilityShortcutAction() {
@@ -3254,6 +3268,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mTorchTimeout = LineageSettings.System.getIntForUser(
                    resolver, LineageSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, 0,
                    UserHandle.USER_CURRENT);
            mClickPartialScreenshot = LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.CLICK_PARTIAL_SCREENSHOT, 0,
                    UserHandle.USER_CURRENT) == 1;

            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,