Created
February 28, 2019 14:05
-
-
Save egdoc/31dea6203b349038cf4c772175d4d289 to your computer and use it in GitHub Desktop.
Use python and dbus logind API to lock the screen on suspension with i3lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # Basic example of how to use i3lock to lock the screen when system goes to sleep | |
| import subprocess | |
| from pydbus import SystemBus | |
| from gi.repository import GLib | |
| def onSuspend(value): | |
| # When suspending or hibernating the system, "value" will be True | |
| if value: | |
| subprocess.call(['i3lock', '-c', '000000']) | |
| def main(): | |
| bus = SystemBus() | |
| logind = bus.get('org.freedesktop.login1', '/org/freedesktop/login1') | |
| logind.PrepareForSleep.connect(onSuspend) | |
| loop = GLib.MainLoop() | |
| loop.run() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment