Move deprecated scripts to deprecated/
This commit is contained in:
1 parent
9720decf7e
commit
eb2297554a
11 files changed
+280
-279
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Executable
+77
@@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Ferit Yiğit BALABAN, <fyb@duck.com>
|
||||||
|
#
|
||||||
|
# modeset.py is a handy theme switcher for multiple applications.
|
||||||
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from subprocess import run
|
||||||
|
|
||||||
|
|
||||||
|
HOME_FOLDR = '/home/ferit'
|
||||||
|
PATH_LOGFL = f'{HOME_FOLDR}/navi.log'
|
||||||
|
DARK_THEME = f'Hardcore'
|
||||||
|
LGHT_THEME = f'Tango Light'
|
||||||
|
DARK_WLLPR = f'{HOME_FOLDR}/sources/wallpapers/6kkzj7.png'
|
||||||
|
LGHT_WLLPR = f'{HOME_FOLDR}/sources/wallpapers/5dd9v9.png'
|
||||||
|
DARK_FETCH = f'{HOME_FOLDR}/scripts/fetchdark.theme'
|
||||||
|
LGHT_FETCH = f'{HOME_FOLDR}/scripts/fetchlight.theme'
|
||||||
|
PATH_KITTY = f'{HOME_FOLDR}/.config/kitty/theme.conf'
|
||||||
|
PATH_FETCH = f'{HOME_FOLDR}/scripts/fetch.theme'
|
||||||
|
KBD_NAME = 'asus::kbd_backlight'
|
||||||
|
|
||||||
|
|
||||||
|
def write(status: str):
|
||||||
|
log = f'[{datetime.now().strftime("%d/%m/%y-%H.%M.%S")}]'
|
||||||
|
log += ' navi is going dark.\n' if status == 'dark' else ' navi is enlightened.\n'
|
||||||
|
with open(PATH_LOGFL, 'a') as f:
|
||||||
|
f.write(log)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
def set_kbdlight(intensity: int):
|
||||||
|
run(['brightnessctl', 'set', '--device', KBD_NAME, str(intensity)])
|
||||||
|
|
||||||
|
|
||||||
|
def set_wallpaper(wallpaper: str):
|
||||||
|
run(['nitrogen', '--set-centered', '--save', wallpaper])
|
||||||
|
|
||||||
|
|
||||||
|
def set_fetchpy(theme: str):
|
||||||
|
try:
|
||||||
|
os.remove(PATH_FETCH)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
os.symlink(theme, PATH_FETCH)
|
||||||
|
|
||||||
|
|
||||||
|
def set_kitty(theme: str):
|
||||||
|
run(['kitty', '+kitten', 'themes', '--reload-in=all', theme])
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
sys.argv.reverse()
|
||||||
|
sys.argv.pop()
|
||||||
|
if len(sys.argv) != 0:
|
||||||
|
mode = sys.argv.pop()
|
||||||
|
if mode == 'd' or mode == 'dark':
|
||||||
|
set_kitty(DARK_THEME)
|
||||||
|
set_wallpaper(DARK_WLLPR)
|
||||||
|
set_fetchpy(DARK_FETCH)
|
||||||
|
set_kbdlight(1)
|
||||||
|
write('dark')
|
||||||
|
elif mode == 'l' or mode == 'light':
|
||||||
|
set_kitty(LGHT_THEME)
|
||||||
|
set_wallpaper(LGHT_WLLPR)
|
||||||
|
set_fetchpy(LGHT_FETCH)
|
||||||
|
set_kbdlight(0)
|
||||||
|
write('light')
|
||||||
|
else:
|
||||||
|
print("Error: expected d, dark, l or light as argument.")
|
||||||
|
exit(1)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
File renamed without changes.
File renamed without changes.
+203
-51
@@ -1,74 +1,226 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Ferit Yiğit BALABAN, <fyb@duck.com>
|
# Ferit Yiğit BALABAN <f@fybx.dev>, 2022
|
||||||
#
|
#
|
||||||
# modeset.py is a handy theme switcher for multiple applications.
|
from datetime import datetime as dt
|
||||||
from datetime import datetime
|
from subprocess import run, Popen, PIPE, DEVNULL
|
||||||
import os
|
import shlex
|
||||||
|
import random
|
||||||
import sys
|
import sys
|
||||||
from subprocess import run
|
import os
|
||||||
|
|
||||||
|
START_NIGHT = "22.30"
|
||||||
|
START_DAY = "8.20"
|
||||||
|
PATH_SCPT_KEYBRD = "$HOME/scripts/keyboard"
|
||||||
|
PATH_SCPT_LOCKER = "$HOME/scripts/wait_unlock.sh"
|
||||||
|
PATH_RESC_VOLUME = "$HOME/.config/navi/volume"
|
||||||
|
PATH_RESC_KBDLGT = "$HOME/.config/navi/keyboard"
|
||||||
|
PATH_RESC_SCRLGT = "$HOME/.config/navi/screen"
|
||||||
|
PATH_RESC_LIGHTW = "$HOME/sources/wallpapers/light/"
|
||||||
|
PATH_RESC_DARKW = "$HOME/sources/wallpapers/dark/"
|
||||||
|
PATH_RESC_WALLPS = "$HOME/.config/navi/wallpapers"
|
||||||
|
PATH_RESC_NAVILG = "$HOME/navi.log"
|
||||||
|
VAR_KBDNAME = "asus::kbd_backlight"
|
||||||
|
|
||||||
|
|
||||||
HOME_FOLDR = '/home/ferit'
|
def set_brightness(device: int, value: int, save_state=False):
|
||||||
PATH_LOGFL = f'{HOME_FOLDR}/navi.log'
|
state_kbdlgt = get_brightness(1)
|
||||||
DARK_THEME = f'Hardcore'
|
state_scrlgt = get_brightness(0)
|
||||||
LGHT_THEME = f'Tango Light'
|
if value == -1:
|
||||||
DARK_WLLPR = f'{HOME_FOLDR}/sources/wallpapers/6kkzj7.png'
|
with open(os.path.expandvars(PATH_RESC_SCRLGT if device == 0 else PATH_RESC_KBDLGT), 'r') as f:
|
||||||
LGHT_WLLPR = f'{HOME_FOLDR}/sources/wallpapers/5dd9v9.png'
|
value = int(f.read())
|
||||||
DARK_FETCH = f'{HOME_FOLDR}/scripts/fetchdark.theme'
|
f.close()
|
||||||
LGHT_FETCH = f'{HOME_FOLDR}/scripts/fetchlight.theme'
|
command = f"brightnessctl set {value}%" if device == 0 else f"brightnessctl --device {VAR_KBDNAME} set {value}%"
|
||||||
PATH_KITTY = f'{HOME_FOLDR}/.config/kitty/theme.conf'
|
run_command(command)
|
||||||
PATH_FETCH = f'{HOME_FOLDR}/scripts/fetch.theme'
|
if save_state:
|
||||||
KBD_NAME = 'asus::kbd_backlight'
|
with open(os.path.expandvars(PATH_RESC_SCRLGT if device == 0 else PATH_RESC_KBDLGT), 'w') as f:
|
||||||
|
f.write(str(state_scrlgt if device == 0 else state_kbdlgt))
|
||||||
|
|
||||||
def write(status: str):
|
|
||||||
log = f'[{datetime.now().strftime("%d/%m/%y-%H.%M.%S")}]'
|
|
||||||
log += ' navi is going dark.\n' if status == 'dark' else ' navi is enlightened.\n'
|
|
||||||
with open(PATH_LOGFL, 'a') as f:
|
|
||||||
f.write(log)
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def set_kbdlight(intensity: int):
|
def connect_keyboard():
|
||||||
run(['brightnessctl', 'set', '--device', KBD_NAME, str(intensity)])
|
run_command(f"bash {PATH_SCPT_KEYBRD}")
|
||||||
|
|
||||||
|
|
||||||
def set_wallpaper(wallpaper: str):
|
def set_volume(value: int, save_state=False):
|
||||||
run(['nitrogen', '--set-centered', '--save', wallpaper])
|
state = get_volume()
|
||||||
|
if value == -1:
|
||||||
|
with open(os.path.expandvars(PATH_RESC_VOLUME), 'r') as f:
|
||||||
|
value = int(f.read())
|
||||||
|
f.close()
|
||||||
|
value = 100 if value > 100 else 0 if value < 0 else value
|
||||||
|
run_command(f'pactl set-sink-volume @DEFAULT_SINK@ {value}%')
|
||||||
|
if save_state:
|
||||||
|
with open(os.path.expandvars(PATH_RESC_VOLUME), 'w') as f:
|
||||||
|
f.write(str(state))
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def set_fetchpy(theme: str):
|
def run_command(cmd: str):
|
||||||
try:
|
Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
|
||||||
os.remove(PATH_FETCH)
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
os.symlink(theme, PATH_FETCH)
|
|
||||||
|
|
||||||
|
|
||||||
def set_kitty(theme: str):
|
def do_query(cmd: str):
|
||||||
run(['kitty', '+kitten', 'themes', '--reload-in=all', theme])
|
return run(shlex.split(cmd), text=True, capture_output=True).stdout
|
||||||
|
|
||||||
|
|
||||||
|
def change_wallpaper(mode: int, cringe=False):
|
||||||
|
if not os.path.exists(PATH_RESC_WALLPS):
|
||||||
|
get_wallpapers()
|
||||||
|
with open(PATH_RESC_WALLPS, 'r') as f:
|
||||||
|
file = f.read()
|
||||||
|
f.close()
|
||||||
|
wlist = file.split(f"{mode}{1 if cringe else 0}")[1].split("EOR")[0].lstrip('\n').splitlines()
|
||||||
|
wallpaper = random.choice(wlist)
|
||||||
|
run_command(f"wal -i {wallpaper}")
|
||||||
|
run_command(f"betterlockscreen -u {wallpaper}")
|
||||||
|
|
||||||
|
|
||||||
|
def lock():
|
||||||
|
Popen(["bash", PATH_SCPT_LOCKER])
|
||||||
|
Popen(["betterlockscreen", "-l", '--off', '5'], stdout=DEVNULL)
|
||||||
|
|
||||||
|
|
||||||
|
def pause_media():
|
||||||
|
if do_query("playerctl status") == "Playing":
|
||||||
|
run_command("playerctl pause")
|
||||||
|
|
||||||
|
|
||||||
|
def get_wallpapers():
|
||||||
|
l0 = os.listdir(PATH_RESC_LIGHTW)
|
||||||
|
d0 = os.listdir(PATH_RESC_DARKW)
|
||||||
|
l0.remove('cringe')
|
||||||
|
d0.remove('cringe')
|
||||||
|
l0 = [PATH_RESC_LIGHTW + x + '\n' for x in l0]
|
||||||
|
d0 = [PATH_RESC_DARKW + x + '\n' for x in d0]
|
||||||
|
l1 = os.listdir(PATH_RESC_LIGHTW + "cringe/")
|
||||||
|
d1 = os.listdir(PATH_RESC_DARKW + "cringe/")
|
||||||
|
l1 = [PATH_RESC_LIGHTW + "cringe/" + x + '\n' for x in l1]
|
||||||
|
d1 = [PATH_RESC_DARKW + "cringe/" + x + '\n' for x in d1]
|
||||||
|
with open(PATH_RESC_WALLPS, 'w') as f:
|
||||||
|
f.write("00:\n")
|
||||||
|
f.writelines(l0)
|
||||||
|
f.write("EOR\n01:\n")
|
||||||
|
f.writelines(l1)
|
||||||
|
f.write("EOR\n10:\n")
|
||||||
|
f.writelines(d0)
|
||||||
|
f.write("EOR\n11:\n")
|
||||||
|
f.writelines(d1)
|
||||||
|
f.write("EOR")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_brightness(device: int):
|
||||||
|
command = "brightnessctl" if device == 0 else f"brightnessctl --device {VAR_KBDNAME}"
|
||||||
|
return int(do_query(command).split('(')[1].split(')')[0].replace('%', ''))
|
||||||
|
|
||||||
|
|
||||||
|
def get_volume():
|
||||||
|
r = do_query("pactl list")
|
||||||
|
for x in r.split("Sink #0")[1].split("Base Volume:")[0].split(' '):
|
||||||
|
if '%' in x:
|
||||||
|
return int(x.replace('%', ''))
|
||||||
|
|
||||||
|
|
||||||
|
def log(message: str):
|
||||||
|
with open(PATH_RESC_NAVILG, 'a') as f:
|
||||||
|
f.write(f"[{dt.now().strftime('%m/%d/%y-%H.%M.%S')}] {message}\n")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_hour():
|
||||||
|
if 0 <= dt.now().minute <= 9:
|
||||||
|
return f"{dt.now().hour}.0{dt.now().minute}"
|
||||||
|
return f"{dt.now().hour}.{dt.now().minute}"
|
||||||
|
|
||||||
|
|
||||||
|
def get_hour_spec(hour_str=None):
|
||||||
|
if hour_str is not None:
|
||||||
|
return (int(hour_str.split('.')[0]) * 60) + int(hour_str.split('.')[0])
|
||||||
|
return (dt.now().hour * 60) + dt.now().minute
|
||||||
|
|
||||||
|
|
||||||
|
def get_mode():
|
||||||
|
low = get_hour_spec(START_DAY)
|
||||||
|
now = get_hour_spec()
|
||||||
|
hgh = get_hour_spec(START_NIGHT)
|
||||||
|
return 0 if low <= now < hgh else 1
|
||||||
|
|
||||||
|
|
||||||
|
def expand_vars():
|
||||||
|
global PATH_SCPT_KEYBRD
|
||||||
|
global PATH_SCPT_LOCKER
|
||||||
|
global PATH_RESC_VOLUME
|
||||||
|
global PATH_RESC_KBDLGT
|
||||||
|
global PATH_RESC_SCRLGT
|
||||||
|
global PATH_RESC_LIGHTW
|
||||||
|
global PATH_RESC_DARKW
|
||||||
|
global PATH_RESC_WALLPS
|
||||||
|
global PATH_RESC_NAVILG
|
||||||
|
PATH_SCPT_KEYBRD = os.path.expandvars(PATH_SCPT_KEYBRD)
|
||||||
|
PATH_SCPT_LOCKER = os.path.expandvars(PATH_SCPT_LOCKER)
|
||||||
|
PATH_RESC_VOLUME = os.path.expandvars(PATH_RESC_VOLUME)
|
||||||
|
PATH_RESC_KBDLGT = os.path.expandvars(PATH_RESC_KBDLGT)
|
||||||
|
PATH_RESC_SCRLGT = os.path.expandvars(PATH_RESC_SCRLGT)
|
||||||
|
PATH_RESC_LIGHTW = os.path.expandvars(PATH_RESC_LIGHTW)
|
||||||
|
PATH_RESC_DARKW = os.path.expandvars(PATH_RESC_DARKW)
|
||||||
|
PATH_RESC_WALLPS = os.path.expandvars(PATH_RESC_WALLPS)
|
||||||
|
PATH_RESC_NAVILG = os.path.expandvars(PATH_RESC_NAVILG)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
sys.argv.remove(sys.argv[0])
|
||||||
sys.argv.reverse()
|
sys.argv.reverse()
|
||||||
sys.argv.pop()
|
expand_vars()
|
||||||
if len(sys.argv) != 0:
|
mode = get_mode()
|
||||||
mode = sys.argv.pop()
|
if len(sys.argv) == 1:
|
||||||
if mode == 'd' or mode == 'dark':
|
if sys.argv[0] == "--login":
|
||||||
set_kitty(DARK_THEME)
|
log("modeset started with \"--login\"")
|
||||||
set_wallpaper(DARK_WLLPR)
|
connect_keyboard()
|
||||||
set_fetchpy(DARK_FETCH)
|
set_volume(0)
|
||||||
set_kbdlight(1)
|
if mode == 0:
|
||||||
write('dark')
|
set_brightness(0, 70)
|
||||||
elif mode == 'l' or mode == 'light':
|
set_brightness(1, 0)
|
||||||
set_kitty(LGHT_THEME)
|
|
||||||
set_wallpaper(LGHT_WLLPR)
|
|
||||||
set_fetchpy(LGHT_FETCH)
|
|
||||||
set_kbdlight(0)
|
|
||||||
write('light')
|
|
||||||
else:
|
else:
|
||||||
print("Error: expected d, dark, l or light as argument.")
|
set_brightness(0, 40)
|
||||||
|
set_brightness(1, 100)
|
||||||
|
change_wallpaper(mode)
|
||||||
|
elif sys.argv[0] == "--lock":
|
||||||
|
log("modeset started with \"--lock\"")
|
||||||
|
set_volume(0, save_state=True)
|
||||||
|
set_brightness(0, 0, save_state=True)
|
||||||
|
set_brightness(1, 0, save_state=True)
|
||||||
|
pause_media()
|
||||||
|
lock()
|
||||||
|
elif sys.argv[0] == "--unlock":
|
||||||
|
log("modeset started with \"--unlock\"")
|
||||||
|
set_volume(-1)
|
||||||
|
set_brightness(0, -1)
|
||||||
|
set_brightness(1, -1)
|
||||||
|
elif sys.argv[0] == "--shutdown":
|
||||||
|
log("modeset started with \"--shutdown\"")
|
||||||
|
set_brightness(0, 50)
|
||||||
|
set_brightness(1, 100)
|
||||||
|
elif sys.argv[0] == "--wallc":
|
||||||
|
log("modeset started with \"--wallc\"")
|
||||||
|
change_wallpaper(mode, cringe=True)
|
||||||
|
elif sys.argv[0] == "--wallp":
|
||||||
|
log("modeset started with \"--wallp\"")
|
||||||
|
change_wallpaper(mode)
|
||||||
|
elif len(sys.argv) == 0:
|
||||||
|
print("modeset by fyb")
|
||||||
|
print(f"local machine time: {get_hour()}")
|
||||||
|
print(f"current mode is: {get_mode()}")
|
||||||
|
print(f"current sink volume: {get_volume()}")
|
||||||
|
print("""Available options:
|
||||||
|
1. Login
|
||||||
|
2. Lock
|
||||||
|
3. Unlock
|
||||||
|
4. Shutdown
|
||||||
|
5. Wallpaper (Make me cringe)
|
||||||
|
6. Wallpaper (Panic mode on)""")
|
||||||
|
else:
|
||||||
|
print("Issuing more than 1 argument to modeset is not supported yet. Aborting...")
|
||||||
exit(1)
|
exit(1)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|||||||
-228
@@ -1,228 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
|
||||||
# Ferit Yiğit BALABAN <f@fybx.dev>, 2022
|
|
||||||
#
|
|
||||||
from datetime import datetime as dt
|
|
||||||
from subprocess import run, Popen, PIPE, DEVNULL
|
|
||||||
import shlex
|
|
||||||
import random
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
START_NIGHT = "22.30"
|
|
||||||
START_DAY = "8.20"
|
|
||||||
PATH_SCPT_KEYBRD = "$HOME/scripts/keyboard"
|
|
||||||
PATH_SCPT_LOCKER = "$HOME/scripts/wait_unlock.sh"
|
|
||||||
PATH_RESC_VOLUME = "$HOME/.config/navi/volume"
|
|
||||||
PATH_RESC_KBDLGT = "$HOME/.config/navi/keyboard"
|
|
||||||
PATH_RESC_SCRLGT = "$HOME/.config/navi/screen"
|
|
||||||
PATH_RESC_LIGHTW = "$HOME/sources/wallpapers/light/"
|
|
||||||
PATH_RESC_DARKW = "$HOME/sources/wallpapers/dark/"
|
|
||||||
PATH_RESC_WALLPS = "$HOME/.config/navi/wallpapers"
|
|
||||||
PATH_RESC_NAVILG = "$HOME/navi.log"
|
|
||||||
VAR_KBDNAME = "asus::kbd_backlight"
|
|
||||||
|
|
||||||
|
|
||||||
def set_brightness(device: int, value: int, save_state=False):
|
|
||||||
state_kbdlgt = get_brightness(1)
|
|
||||||
state_scrlgt = get_brightness(0)
|
|
||||||
if value == -1:
|
|
||||||
with open(os.path.expandvars(PATH_RESC_SCRLGT if device == 0 else PATH_RESC_KBDLGT), 'r') as f:
|
|
||||||
value = int(f.read())
|
|
||||||
f.close()
|
|
||||||
command = f"brightnessctl set {value}%" if device == 0 else f"brightnessctl --device {VAR_KBDNAME} set {value}%"
|
|
||||||
run_command(command)
|
|
||||||
if save_state:
|
|
||||||
with open(os.path.expandvars(PATH_RESC_SCRLGT if device == 0 else PATH_RESC_KBDLGT), 'w') as f:
|
|
||||||
f.write(str(state_scrlgt if device == 0 else state_kbdlgt))
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def connect_keyboard():
|
|
||||||
run_command(f"bash {PATH_SCPT_KEYBRD}")
|
|
||||||
|
|
||||||
|
|
||||||
def set_volume(value: int, save_state=False):
|
|
||||||
state = get_volume()
|
|
||||||
if value == -1:
|
|
||||||
with open(os.path.expandvars(PATH_RESC_VOLUME), 'r') as f:
|
|
||||||
value = int(f.read())
|
|
||||||
f.close()
|
|
||||||
value = 100 if value > 100 else 0 if value < 0 else value
|
|
||||||
run_command(f'pactl set-sink-volume @DEFAULT_SINK@ {value}%')
|
|
||||||
if save_state:
|
|
||||||
with open(os.path.expandvars(PATH_RESC_VOLUME), 'w') as f:
|
|
||||||
f.write(str(state))
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def run_command(cmd: str):
|
|
||||||
Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
|
|
||||||
|
|
||||||
|
|
||||||
def do_query(cmd: str):
|
|
||||||
return run(shlex.split(cmd), text=True, capture_output=True).stdout
|
|
||||||
|
|
||||||
|
|
||||||
def change_wallpaper(mode: int, cringe=False):
|
|
||||||
if not os.path.exists(PATH_RESC_WALLPS):
|
|
||||||
get_wallpapers()
|
|
||||||
with open(PATH_RESC_WALLPS, 'r') as f:
|
|
||||||
file = f.read()
|
|
||||||
f.close()
|
|
||||||
wlist = file.split(f"{mode}{1 if cringe else 0}")[1].split("EOR")[0].lstrip('\n').splitlines()
|
|
||||||
wallpaper = random.choice(wlist)
|
|
||||||
run_command(f"wal -i {wallpaper}")
|
|
||||||
run_command(f"betterlockscreen -u {wallpaper}")
|
|
||||||
|
|
||||||
|
|
||||||
def lock():
|
|
||||||
Popen(["bash", PATH_SCPT_LOCKER])
|
|
||||||
Popen(["betterlockscreen", "-l"], stdout=DEVNULL)
|
|
||||||
|
|
||||||
|
|
||||||
def pause_media():
|
|
||||||
if do_query("playerctl status") == "Playing":
|
|
||||||
run_command("playerctl pause")
|
|
||||||
|
|
||||||
|
|
||||||
def get_wallpapers():
|
|
||||||
l0 = os.listdir(PATH_RESC_LIGHTW)
|
|
||||||
d0 = os.listdir(PATH_RESC_DARKW)
|
|
||||||
l0.remove('cringe')
|
|
||||||
d0.remove('cringe')
|
|
||||||
l0 = [PATH_RESC_LIGHTW + x + '\n' for x in l0]
|
|
||||||
d0 = [PATH_RESC_DARKW + x + '\n' for x in d0]
|
|
||||||
l1 = os.listdir(PATH_RESC_LIGHTW + "cringe/")
|
|
||||||
d1 = os.listdir(PATH_RESC_DARKW + "cringe/")
|
|
||||||
l1 = [PATH_RESC_LIGHTW + "cringe/" + x + '\n' for x in l1]
|
|
||||||
d1 = [PATH_RESC_DARKW + "cringe/" + x + '\n' for x in d1]
|
|
||||||
with open(PATH_RESC_WALLPS, 'w') as f:
|
|
||||||
f.write("00:\n")
|
|
||||||
f.writelines(l0)
|
|
||||||
f.write("EOR\n01:\n")
|
|
||||||
f.writelines(l1)
|
|
||||||
f.write("EOR\n10:\n")
|
|
||||||
f.writelines(d0)
|
|
||||||
f.write("EOR\n11:\n")
|
|
||||||
f.writelines(d1)
|
|
||||||
f.write("EOR")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def get_brightness(device: int):
|
|
||||||
command = "brightnessctl" if device == 0 else f"brightnessctl --device {VAR_KBDNAME}"
|
|
||||||
return int(do_query(command).split('(')[1].split(')')[0].replace('%', ''))
|
|
||||||
|
|
||||||
|
|
||||||
def get_volume():
|
|
||||||
r = do_query("pactl list")
|
|
||||||
for x in r.split("Sink #0")[1].split("Base Volume:")[0].split(' '):
|
|
||||||
if '%' in x:
|
|
||||||
return int(x.replace('%', ''))
|
|
||||||
|
|
||||||
|
|
||||||
def log(message: str):
|
|
||||||
with open(PATH_RESC_NAVILG, 'a') as f:
|
|
||||||
f.write(f"[{dt.now().strftime('%m/%d/%y-%H.%M.%S')}] {message}\n")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def get_hour():
|
|
||||||
if 0 <= dt.now().minute <= 9:
|
|
||||||
return f"{dt.now().hour}.0{dt.now().minute}"
|
|
||||||
return f"{dt.now().hour}.{dt.now().minute}"
|
|
||||||
|
|
||||||
|
|
||||||
def get_hour_spec(hour_str=None):
|
|
||||||
if hour_str is not None:
|
|
||||||
return (int(hour_str.split('.')[0]) * 60) + int(hour_str.split('.')[0])
|
|
||||||
return (dt.now().hour * 60) + dt.now().minute
|
|
||||||
|
|
||||||
|
|
||||||
def get_mode():
|
|
||||||
low = get_hour_spec(START_DAY)
|
|
||||||
now = get_hour_spec()
|
|
||||||
hgh = get_hour_spec(START_NIGHT)
|
|
||||||
return 0 if low <= now < hgh else 1
|
|
||||||
|
|
||||||
|
|
||||||
def expand_vars():
|
|
||||||
global PATH_SCPT_KEYBRD
|
|
||||||
global PATH_SCPT_LOCKER
|
|
||||||
global PATH_RESC_VOLUME
|
|
||||||
global PATH_RESC_KBDLGT
|
|
||||||
global PATH_RESC_SCRLGT
|
|
||||||
global PATH_RESC_LIGHTW
|
|
||||||
global PATH_RESC_DARKW
|
|
||||||
global PATH_RESC_WALLPS
|
|
||||||
global PATH_RESC_NAVILG
|
|
||||||
PATH_SCPT_KEYBRD = os.path.expandvars(PATH_SCPT_KEYBRD)
|
|
||||||
PATH_SCPT_LOCKER = os.path.expandvars(PATH_SCPT_LOCKER)
|
|
||||||
PATH_RESC_VOLUME = os.path.expandvars(PATH_RESC_VOLUME)
|
|
||||||
PATH_RESC_KBDLGT = os.path.expandvars(PATH_RESC_KBDLGT)
|
|
||||||
PATH_RESC_SCRLGT = os.path.expandvars(PATH_RESC_SCRLGT)
|
|
||||||
PATH_RESC_LIGHTW = os.path.expandvars(PATH_RESC_LIGHTW)
|
|
||||||
PATH_RESC_DARKW = os.path.expandvars(PATH_RESC_DARKW)
|
|
||||||
PATH_RESC_WALLPS = os.path.expandvars(PATH_RESC_WALLPS)
|
|
||||||
PATH_RESC_NAVILG = os.path.expandvars(PATH_RESC_NAVILG)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
sys.argv.remove(sys.argv[0])
|
|
||||||
sys.argv.reverse()
|
|
||||||
expand_vars()
|
|
||||||
mode = get_mode()
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
if sys.argv[0] == "--login":
|
|
||||||
log("modeset2 started with \"--login\"")
|
|
||||||
connect_keyboard()
|
|
||||||
set_volume(0)
|
|
||||||
if mode == 0:
|
|
||||||
set_brightness(0, 70)
|
|
||||||
set_brightness(1, 0)
|
|
||||||
else:
|
|
||||||
set_brightness(0, 40)
|
|
||||||
set_brightness(1, 100)
|
|
||||||
change_wallpaper(mode)
|
|
||||||
elif sys.argv[0] == "--lock":
|
|
||||||
log("modeset2 started with \"--lock\"")
|
|
||||||
set_volume(0, save_state=True)
|
|
||||||
set_brightness(0, 0, save_state=True)
|
|
||||||
set_brightness(1, 0, save_state=True)
|
|
||||||
pause_media()
|
|
||||||
lock()
|
|
||||||
elif sys.argv[0] == "--unlock":
|
|
||||||
log("modeset2 started with \"--unlock\"")
|
|
||||||
set_volume(-1)
|
|
||||||
set_brightness(0, -1)
|
|
||||||
set_brightness(1, -1)
|
|
||||||
elif sys.argv[0] == "--shutdown":
|
|
||||||
log("modeset2 started with \"--shutdown\"")
|
|
||||||
print("Shutdown")
|
|
||||||
elif sys.argv[0] == "--wallc":
|
|
||||||
log("modeset started with \"--wallc\"")
|
|
||||||
change_wallpaper(mode, cringe=True)
|
|
||||||
elif sys.argv[0] == "--wallp":
|
|
||||||
log("modeset started with \"--wallp\"")
|
|
||||||
change_wallpaper(mode)
|
|
||||||
elif len(sys.argv) == 0:
|
|
||||||
print("modeset2 by fyb")
|
|
||||||
print(f"local machine time: {get_hour()}")
|
|
||||||
print(f"current mode is: {get_mode()}")
|
|
||||||
print(f"current sink volume: {get_volume()}")
|
|
||||||
print("""Available options:
|
|
||||||
1. Login
|
|
||||||
2. Lock
|
|
||||||
3. Unlock
|
|
||||||
4. Shutdown
|
|
||||||
5. Wallpaper (Make me cringe)
|
|
||||||
6. Wallpaper (Panic mode on)""")
|
|
||||||
else:
|
|
||||||
print("Issuing more than 1 argument to modeset2 is not supported yet. Aborting...")
|
|
||||||
exit(1)
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
Reference in new issue
Block a user