From 9b5173a5873ed7dd3b34871072edf9c57ec82f65 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Fri, 7 Jun 2024 13:44:47 +0100 Subject: [PATCH] home-manager/gui: More screensavers and options --- home-manager/modules/gui/default.nix | 6 +- home-manager/modules/gui/enojy.jpg | Bin 0 -> 7570 bytes home-manager/modules/gui/screensaver.py | 78 +++++++++++++----------- 3 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 home-manager/modules/gui/enojy.jpg diff --git a/home-manager/modules/gui/default.nix b/home-manager/modules/gui/default.nix index 6c7a1f9..10829aa 100644 --- a/home-manager/modules/gui/default.nix +++ b/home-manager/modules/gui/default.nix @@ -15,16 +15,13 @@ let url = "https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad"; hash = "sha256-HX1DvlAeZ9kn5BXguPPinDvzMHXoWXIYFvZSpSbKx3E="; }; - # doomNcurses = pkgs.writeShellScript "doom-ncurses" '' - # SDL_AUDIODRIVER=null SDL_VIDEODRIVER=caca CACA_DRIVER=ncurses exec ${pkgs.chocolate-doom2xx}/bin/chocolate-doom -iwad ${doomWad} - # ''; - # lockCmd = "swaylock-plugin --command-each '${pkgs.windowtolayer}/bin/windowtolayer -- alacritty -e ${doomNcurses}'"; doomsaver = pkgs.runCommand "doomsaver" { inherit (pkgs) windowtolayer; chocoDoom = pkgs.chocolate-doom2xx; python = pkgs.python3.withPackages (ps: [ ps.filelock ]); inherit doomWad; + enojy = ./enojy.jpg; } '' mkdir -p "$out"/bin substituteAll ${./screensaver.py} "$out"/bin/doomsaver @@ -59,6 +56,7 @@ in cowsay fortune + jp2a terminaltexteffects screenfetch neofetch diff --git a/home-manager/modules/gui/enojy.jpg b/home-manager/modules/gui/enojy.jpg new file mode 100644 index 0000000000000000000000000000000000000000..87d1905b427b8582555197b23e2f1bd5c61c1344 GIT binary patch literal 7570 zcmbt(Wl$W>vhOZVa9v=ru$vIv2?P(pJwR~XKyX;xT@#$(1OhC!NN^1j++CL765I(E z?B;*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R4YeVmaDRdX06YPJ-Wpq)-tbyops6sXa%;~Kr#oWt zy8OV$SmQtS1%Fx`rK}G>xM$?@G|UMR33l{?$C~Y<2nw?*3_E=uL)J|4z^NHNucH2t zA06imbWe=r^f;hj5ONYhJ93+`cwdAXf^Doar$8Ss6(;XB+By_`E|k6WMxszW3)G*i z1Z5kZxMTxUz_*8VTX7q-qO!)+nD%C<5iu8O`I;L#wFrqE0dR`zkOA6-qY9mB()-Vq zvJIBGh#1McXN`Td5|pu2Wz^L5VZ#jE$!dX`S}nEj3mT>^bCHd)$U+ScY1XiI9ekbf zqU0g4TgqrEZ$N;0nZ=WqW$2um}A@L6F$E2-JGg6LpyW1H$^qTnVtZ}-0%bJJ91O$ z>}~PD?UKGcc3*7sy(&3en{VWzQUgb~jM3kQQL*SBgJ2>mwCM0J8@CPpo)371LMGv` zqDVQ?U8!~-K6<+Yj}H#B5~h{C@p*aSA1S9gI%fIbV~?dXM+qmTYZJ)4Nhab|bWq#s zir*;=2O;(YeJ_03PDQu(Zag-ep3-}_QCw%cT==$}HWJ5)nLN2u6aLd?biIfpm;Eiw zpE>K^g!9e;12U%5*-kd<|1H)3B^t?g>6%H@wuH`5J2(jEeCFg^_jyj~ua%gNu;2g= z>?Z<0@g literal 0 HcmV?d00001 diff --git a/home-manager/modules/gui/screensaver.py b/home-manager/modules/gui/screensaver.py index 0e8cc33..0575b4c 100755 --- a/home-manager/modules/gui/screensaver.py +++ b/home-manager/modules/gui/screensaver.py @@ -74,8 +74,8 @@ class TTESaver(Screensaver): def wait(self): while self.running: effect_cmd = ['tte', random.choice(self.effects)] - print(f"$ {' '.join(self.cmd)} | {' '.join(effect_cmd)}") - content = subprocess.check_output(self.cmd, env=self.env, stderr=subprocess.DEVNULL) + print(f"$ {self.cmd} | {' '.join(effect_cmd)}") + content = subprocess.check_output(self.cmd, shell=True, env=self.env, stderr=subprocess.DEVNULL) self.proc = subprocess.Popen(effect_cmd, stdin=subprocess.PIPE) self.proc.stdin.write(content) @@ -94,23 +94,27 @@ class MultiSaver: Screensaver(['cmatrix']), - TTESaver(['screenfetch', '-N']), - TTESaver(['fortune']), - TTESaver(['top', '-n1']), - TTESaver(['ss', '-nltu']), - TTESaver(['ss', '-ntu']), + TTESaver('screenfetch -N'), + TTESaver('fortune'), + TTESaver('top -n1'), + TTESaver('ss -nltu'), + TTESaver('ss -ntu'), + TTESaver('jp2a --width=100 @enojy@'), ] state_filename = 'screensaver.json' - def __init__(self): + def __init__(self, select=None): self.state_path = os.path.join(f'/run/user/{os.geteuid()}', self.state_filename) self.lock = filelock.FileLock(f'{self.state_path}.lock') - self.selected = None + if select is not None: + assert select >= 0 and select < len(self.savers), 'Invalid screensaver index' + self.selected = self.savers[select] + else: + self.selected = None self.cleaned_up = False def select(self): - assert self.selected is None with self.lock: if not os.path.exists(self.state_path): state = {'instances': []} @@ -118,33 +122,34 @@ class MultiSaver: with open(self.state_path) as f: state = json.load(f) - available = set(range(len(self.savers))) - new_instances = [] - for instance in state['instances']: - if not os.path.exists(f"/proc/{instance['pid']}"): - continue + if self.selected is None: + available = set(range(len(self.savers))) + new_instances = [] + for instance in state['instances']: + if not os.path.exists(f"/proc/{instance['pid']}"): + continue - new_instances.append(instance) - i = instance['saver'] - assert i in available - available.remove(i) - assert available, 'No screensavers left' - available = list(available) + new_instances.append(instance) + i = instance['saver'] + assert i in available + available.remove(i) + assert available, 'No screensavers left' + available = list(available) - weights = [] - for i in available: - weights.append(self.savers[i].weight) - selected_i = random.choices(available, weights=weights)[0] + weights = [] + for i in available: + weights.append(self.savers[i].weight) + selected_i = random.choices(available, weights=weights)[0] - new_instances.append({'pid': os.getpid(), 'saver': selected_i}) - state['instances'] = new_instances + new_instances.append({'pid': os.getpid(), 'saver': selected_i}) + state['instances'] = new_instances + + # print(f'Selected saver {selected_i}') + self.selected = self.savers[selected_i] with open(self.state_path, 'w') as f: json.dump(state, f) - # print(f'Selected saver {selected_i}') - self.selected = self.savers[selected_i] - def cleanup(self): if self.cleaned_up: return @@ -181,17 +186,22 @@ class MultiSaver: def main(): parser = argparse.ArgumentParser(description='Wayland terminal-based lock screen') + parser.add_argument('-l', '--locker-cmd', default='swaylock-plugin', help='swaylock-plugin command to use') parser.add_argument('-t', '--terminal', default='alacritty', help='Terminal emulator to use') parser.add_argument('-i', '--instance', action='store_true', help='Run as instance') + parser.add_argument('-s', '--screensaver', type=int, help='Force use of specific screensaver') args = parser.parse_args() if not args.instance: - subprocess.check_call([ - 'swaylock-plugin', '--command-each', - f'@windowtolayer@/bin/windowtolayer -- {args.terminal} -e {sys.argv[0]} --instance']) + cmd = [ + args.locker_cmd, '--command-each', + f'@windowtolayer@/bin/windowtolayer -- {args.terminal} -e {sys.argv[0]} --instance'] + if args.screensaver is not None: + cmd[-1] += f' --screensaver {args.screensaver}' + subprocess.check_call(cmd) return - ms = MultiSaver() + ms = MultiSaver(select=args.screensaver) ms.select() ms.run()