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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Lock screen #7

Open
WilliamVenner opened this issue Nov 22, 2022 · 6 comments
Open

[feature request] Lock screen #7

WilliamVenner opened this issue Nov 22, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@WilliamVenner
Copy link

And finally, it would be cool if we could lock the computer as well 馃敀

macOS implementation

extern void SACLockScreenImmediate();

int main() {
    SACLockScreenImmediate();
    return 0;
}

clang -F /System/Library/PrivateFrameworks -framework login -o lockscreen lockscreen.c

@silvioprog
Copy link
Member

The code above worked like a charm on macOS Monterey with Apple silicon. 馃檪

@silvioprog silvioprog added the enhancement New feature or request label Nov 23, 2022
@silvioprog silvioprog changed the title Lock [feature request] Lock screen Nov 23, 2022
@AdrianEddy
Copy link
Collaborator

AdrianEddy commented Nov 23, 2022

Windows:

windows::Win32::System::Shutdown::LockWorkStation();

https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/Shutdown/fn.LockWorkStation.html

@WilliamVenner
Copy link
Author

WilliamVenner commented Nov 23, 2022

I think it should be noted that this is a private API and I think it would cause your app to be rejected from the macOS app store -- this obviously doesn't matter for some use cases but definitely worth documenting.

I wonder if maybe a better alternative would be to run a script that locks the screen instead. A very silly and unfortunate workaround but hey-ho that's Apple for ya.

@AdrianEddy
Copy link
Collaborator

AppleScript

activate application "SystemUIServer"
tell application "System Events"
    tell process "SystemUIServer" to keystroke "q" using {command down, control down}
end tell

@AdrianEddy
Copy link
Collaborator

AdrianEddy commented Nov 23, 2022

Linux implementation is a nightmare across desktop environments, so I won't go there, but just need to figure out function names on each of these DBUS endpoints that are already implemented

org.gnome.ScreenSaver.Lock is one
org.freedesktop.ConsoleKit.Session.Lock is another
org.xfce.ScreenSaver.Lock

@WilliamVenner
Copy link
Author

AppleScript

activate application "SystemUIServer"
tell application "System Events"
    tell process "SystemUIServer" to keystroke "q" using {command down, control down}
end tell

Is it possible for the user to change this key combo somehow, thereby breaking our script?

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

3 participants