-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-power-manager-dbus.py
110 lines (97 loc) · 2.95 KB
/
simple-power-manager-dbus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from commands import getoutput,getstatusoutput
import pyxhook
import time
import os
import dbus
inactiveTime=time.time()
settings=[["powerButton",1],["keyBright",1],["lidScreen",1],["screensaverOnSuspend",1],["notify",1],["batteryLow",20],["batteryCritic",5],["dynamicBright",0],["unplugInactiveTime",5],["unplugInactiveBright",10],["plugInactiveTime",30],["plugInactiveBright",20],["suspendTime",30]]
KBD = "269025027"
KBU = "269025026"
KSD = "269025066"
SLD = "269025201"
def getSettings():
try:
global settings
configFile=open(os.environ['HOME']+"/.config/simple-power-manager/config.conf","r")
#configFile=open("/home/kirbylife/.config/simple-power-manager/config.conf","r")
config=configFile.read()
configFile.close()
config=config.split("\n")
for c in range(len(config)):
config[c]=config[c].split("=")
for c in settings:
for f in config:
if c[0]==f[0]:
c[1]=f[1]
break
except:
configFile=open(os.environ['HOME']+"/.config/simple-power-manager/config.conf","w")
for c in settings:
configFile.write(c[0]+"="+str(c[1])+"\n")
configFile.close()
getSettings()
def resetTime(event=None):
global inactiveTime
inactiveTime=time.time()
def suspend(order,ssorder):
if(ssorder=="1"):
getoutput("xdg-screensaver lock")
if(order=="1"):
getoutput("systemctl suspend")
elif(order=="2"):
getoutput("systemctl hibernate")
def changeBright(value,dir):
print ("entro")
bus=dbus.SystemBus()
kbdBacklightProxy = bus.get_object('org.freedesktop.UPower','/org/freedesktop/UPower/KbdBacklight')
kbdBacklight = dbus.Interface(kbdBacklightProxy,'org.freedesktop.UPower.KbdBacklight')
#max=int(kbdBacklight.GetMaxBrightness())
#current=1
max=100
current=int(kbdBacklight.GetBrightness())
if value:
if(current<max):
current=current+(5*max/100)%max
else:
if(current>0):
current=current-(5*max/100)
if(current<0):
current=0
#kbdBacklight.SetBrightness(current)
def kbevent(event):
global running,settings,KBD,KBU,KSD,SLD
resetTime()
getSettings()
key = str(event.Key)
print (key)
print (KBD)
if KBD in key and settings[1][1]=="1":
graphicCards=getoutput("ls /sys/class/backlight").split("\n")
for c in graphicCards:
changeBright(False,c)
elif KBU in key and settings[1][1]=="1":
graphicCards=getoutput("ls /sys/class/backlight").split("\n")
for c in graphicCards:
changeBright(True,c)
elif KSD in key and settings[0][1]!="0":
suspend(settings[0][1])
elif SLD in key and settings[2][1]!="0":
suspend(settings[2][1],settings[3][1])
def main(args):
hookman = pyxhook.HookManager()
hookman.KeyDown = kbevent
hookman.KeyUp=hookman.MouseAllButtonsDown=hookman.MouseAllButtonsUp=hookman.MouseMovement=resetTime
hookman.HookKeyboard()
hookman.HookMouse()
hookman.start()
getSettings()
while True:
#(time.time()-inactiveTime)
time.sleep(0.1)
hookman.cancel()
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))