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

Feature request: Add option to only unblank on lock shortcut (Super+L etc), NOT on timeout/screensaver #17

Open
blipk opened this issue May 24, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@blipk
Copy link

blipk commented May 24, 2020

I implemented this from another extension no-screen-blank@example.com here:

const ScreenShield = imports.ui.screenShield;
const Main = imports.ui.main;
const Me = imports.misc.extensionUtils.getCurrentExtension();

let extensionActive = false;
let orig_activateFade = ScreenShield.ScreenShield.prototype._activateFade;
let orig_completeLockScreenShown = ScreenShield.ScreenShield.prototype._completeLockScreenShown;

// don't fade in a full screen black box which would obscure the view
function noFade_activateFade (lightbox, time) {
    if (!Me.keyboardSource)
        orig_activateFade.call(this, lightbox, time);
    Me.keyboardSource = false;
};

// basically a copy of the original method without the emission of the
// "active-changed" signal which would cause gnome-settings-daemon to
// blank the screen
function noFade_completeLockScreenShown () {
    if (!Me.keyboardSource) return orig_completeLockScreenShown.call(this);
    
    this._isActive = true;

    if (this._aboutToSuspend)
        this._uninhibitSuspend();

    Main.screenShield.emit('lock-screen-shown');
}

function init() {
}

function enable() {
    if (!extensionActive) {
        extensionActive = true;
        Me.keyboardSource = false;
        ScreenShield.ScreenShield.prototype._activateFade = noFade_activateFade;
        ScreenShield.ScreenShield.prototype._completeLockScreenShown = noFade_completeLockScreenShown;

        let [res, out] = imports.gi.GLib.spawn_command_line_sync("gsettings get org.gnome.settings-daemon.plugins.media-keys screensaver");
        let strout = imports.byteArray.toString(out).replace(/'/g,'"')
        let lockKeys = JSON.parse(strout);
        let action = global.display.grab_accelerator(lockKeys[0], imports.gi.Meta.KeyBindingFlags.NONE);
        let name = imports.gi.Meta.external_binding_name_for_action(action)
        Main.wm.allowKeybinding(name, imports.gi.Shell.ActionMode.ALL);
        this.lockActionKey = action;
        
        global.display.connect('accelerator-activated', (display, actionId, deviceId, timestamp) => {
            if (actionId == action) {
                Me.keyboardSource = true;
                Main.screenShield.lock(true);
            }
        });
    }
}

function disable() {
    // Only allow disabling the extension when in 'user' mode (i.e. manually),
    // but not in lock-screen mode.
    if (extensionActive && Main.sessionMode.currentMode == 'user') {
        extensionActive = false;
        ScreenShield.ScreenShield.prototype._activateFade = orig_activateFade;
        ScreenShield.ScreenShield.prototype._completeLockScreenShown = orig_completeLockScreenShown;
    }
}

I attempted to with unblank but seeing as it has a lot more function overrides I ran into a problem that it seems some signal wasn't emitting and the lock screen doesn't redisplay on user action, just the block out. Here is what I tried:
Unblank.zip

@sunwxg sunwxg added the enhancement New feature or request label May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants