-
-
Save harish2704/dc0d1759f9cf98dcbdd12e82f577747d to your computer and use it in GitHub Desktop.
Python DBus handle hibernate, sleep and resume
This file contains 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 python | |
# -*- coding: utf-8 -*- | |
__author__ = 'xanter' | |
#from datetime import datetime | |
import signal | |
import time | |
import dbus | |
import gobject | |
import urllib2 | |
import os | |
from dbus.mainloop.glib import DBusGMainLoop | |
def handle_sleep(mode): | |
if mode: | |
print("Sleep") | |
# TODO: allow to use custom commands | |
os.system('i3lock') | |
else: | |
print("Resume") | |
DBusGMainLoop(set_as_default=True) # integrate into gobject main loop | |
bus = dbus.SystemBus() # connect to system wide dbus | |
bus.add_signal_receiver( # define the signal to listen to | |
handle_sleep, # callback function | |
'PrepareForSleep', # signal name | |
'org.freedesktop.login1.Manager', # interface | |
'org.freedesktop.login1' # bus name | |
) | |
loop = gobject.MainLoop() | |
loop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment