Fast clean-up
This commit is contained in:
parent
47d639ffc3
commit
569a9d156a
36
modeset2.py
36
modeset2.py
@ -6,12 +6,10 @@ from datetime import datetime as dt
|
|||||||
from subprocess import run
|
from subprocess import run
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import asyncio
|
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
START_NIGHT = "22.30"
|
START_NIGHT = "22.30"
|
||||||
START_DAY = "8.20"
|
START_DAY = "8.20"
|
||||||
PATH_SCPT_KEYBRD = "$HOME/scripts/keyboard"
|
PATH_SCPT_KEYBRD = "$HOME/scripts/keyboard"
|
||||||
@ -20,12 +18,12 @@ PATH_RESC_VOLUME = "$HOME/.config/navi/volume"
|
|||||||
PATH_RESC_KBDLGT = "$HOME/.config/navi/keyboard"
|
PATH_RESC_KBDLGT = "$HOME/.config/navi/keyboard"
|
||||||
PATH_RESC_SCRLGT = "$HOME/.config/navi/screen"
|
PATH_RESC_SCRLGT = "$HOME/.config/navi/screen"
|
||||||
PATH_RESC_LIGHTW = "$HOME/sources/wallpapers/light/"
|
PATH_RESC_LIGHTW = "$HOME/sources/wallpapers/light/"
|
||||||
PATH_RESC_DARKW = "$HOME/sources/wallpapers/dark/"
|
PATH_RESC_DARKW = "$HOME/sources/wallpapers/dark/"
|
||||||
PATH_RESC_WALLPS = "$HOME/.config/navi/wallpapers"
|
PATH_RESC_WALLPS = "$HOME/.config/navi/wallpapers"
|
||||||
VAR_KBDNAME = "asus::kbd_backlight"
|
VAR_KBDNAME = "asus::kbd_backlight"
|
||||||
|
|
||||||
|
|
||||||
def set_brightness(device: int, value: int, save_state = False):
|
def set_brightness(device: int, value: int, save_state=False):
|
||||||
state_kbdlgt = get_brightness(1)
|
state_kbdlgt = get_brightness(1)
|
||||||
state_scrlgt = get_brightness(0)
|
state_scrlgt = get_brightness(0)
|
||||||
if value == -1:
|
if value == -1:
|
||||||
@ -45,7 +43,7 @@ def connect_keyboard():
|
|||||||
open_subprocess(command)
|
open_subprocess(command)
|
||||||
|
|
||||||
|
|
||||||
def set_volume(value: int, save_state = False):
|
def set_volume(value: int, save_state=False):
|
||||||
state = get_volume()
|
state = get_volume()
|
||||||
if value == -1:
|
if value == -1:
|
||||||
with open(os.path.expandvars(PATH_RESC_VOLUME), 'r') as f:
|
with open(os.path.expandvars(PATH_RESC_VOLUME), 'r') as f:
|
||||||
@ -61,13 +59,10 @@ def set_volume(value: int, save_state = False):
|
|||||||
|
|
||||||
|
|
||||||
def open_subprocess(cmd: str):
|
def open_subprocess(cmd: str):
|
||||||
p = subprocess.Popen(
|
subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
shlex.split(cmd),
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE)
|
|
||||||
|
|
||||||
|
|
||||||
def change_wallpaper(mode: int, cringe = False):
|
def change_wallpaper(mode: int, cringe=False):
|
||||||
if not os.path.exists(PATH_RESC_WALLPS):
|
if not os.path.exists(PATH_RESC_WALLPS):
|
||||||
get_wallpapers()
|
get_wallpapers()
|
||||||
region = f"{mode}{1 if cringe else 0}"
|
region = f"{mode}{1 if cringe else 0}"
|
||||||
@ -88,8 +83,8 @@ def lock():
|
|||||||
|
|
||||||
|
|
||||||
def pause_media():
|
def pause_media():
|
||||||
if run(["playerctl", "status"], text = True, capture_output = True).stdout == "Playing":
|
if run(["playerctl", "status"], text=True, capture_output=True).stdout == "Playing":
|
||||||
run(["playerctl", "pause"], text = True, capture_output = True)
|
run(["playerctl", "pause"], text=True, capture_output=True)
|
||||||
|
|
||||||
|
|
||||||
def get_wallpapers():
|
def get_wallpapers():
|
||||||
@ -138,13 +133,13 @@ def log(message: str):
|
|||||||
|
|
||||||
|
|
||||||
def get_hour():
|
def get_hour():
|
||||||
if 0 <= dt.now().minute and dt.now().minute <= 9:
|
if 0 <= dt.now().minute <= 9:
|
||||||
return f"{dt.now().hour}.0{dt.now().minute}"
|
return f"{dt.now().hour}.0{dt.now().minute}"
|
||||||
return f"{dt.now().hour}.{dt.now().minute}"
|
return f"{dt.now().hour}.{dt.now().minute}"
|
||||||
|
|
||||||
|
|
||||||
def get_hour_spec(hour_str = None):
|
def get_hour_spec(hour_str=None):
|
||||||
if hour_str != None:
|
if hour_str is not None:
|
||||||
return (int(hour_str.split('.')[0]) * 60) + int(hour_str.split('.')[0])
|
return (int(hour_str.split('.')[0]) * 60) + int(hour_str.split('.')[0])
|
||||||
else:
|
else:
|
||||||
return (dt.now().hour * 60) + dt.now().minute
|
return (dt.now().hour * 60) + dt.now().minute
|
||||||
@ -154,7 +149,7 @@ def get_mode():
|
|||||||
low = get_hour_spec(START_DAY)
|
low = get_hour_spec(START_DAY)
|
||||||
now = get_hour_spec()
|
now = get_hour_spec()
|
||||||
hgh = get_hour_spec(START_NIGHT)
|
hgh = get_hour_spec(START_NIGHT)
|
||||||
return 0 if low <= now and now < hgh else 1
|
return 0 if low <= now < hgh else 1
|
||||||
|
|
||||||
|
|
||||||
def expand_vars():
|
def expand_vars():
|
||||||
@ -195,9 +190,9 @@ def main():
|
|||||||
change_wallpaper(mode)
|
change_wallpaper(mode)
|
||||||
elif sys.argv[0] == "--lock":
|
elif sys.argv[0] == "--lock":
|
||||||
log("modeset2 started with \"--lock\"")
|
log("modeset2 started with \"--lock\"")
|
||||||
set_volume(0, save_state = True)
|
set_volume(0, save_state=True)
|
||||||
set_brightness(0, 0, save_state = True)
|
set_brightness(0, 0, save_state=True)
|
||||||
set_brightness(1, 0, save_state = True)
|
set_brightness(1, 0, save_state=True)
|
||||||
pause_media()
|
pause_media()
|
||||||
lock()
|
lock()
|
||||||
elif sys.argv[0] == "--unlock":
|
elif sys.argv[0] == "--unlock":
|
||||||
@ -210,7 +205,7 @@ def main():
|
|||||||
print("Shutdown")
|
print("Shutdown")
|
||||||
elif sys.argv[0] == "--wallc":
|
elif sys.argv[0] == "--wallc":
|
||||||
log("modeset started with \"--wallc\"")
|
log("modeset started with \"--wallc\"")
|
||||||
change_wallpaper(mode, cringe = True)
|
change_wallpaper(mode, cringe=True)
|
||||||
elif sys.argv[0] == "--wallp":
|
elif sys.argv[0] == "--wallp":
|
||||||
log("modeset started with \"--wallp\"")
|
log("modeset started with \"--wallp\"")
|
||||||
change_wallpaper(mode)
|
change_wallpaper(mode)
|
||||||
@ -234,4 +229,3 @@ def main():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user