From e03d34d75bbf0683c5260193a5891ef3a9a1d599 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Tue, 22 Oct 2024 00:14:39 -0400 Subject: [PATCH] feat(agsV2): add lockscreen --- .gitignore | 2 +- nixosModules/ags/default.nix | 1 + nixosModules/ags/v2/app.ts | 55 ++-- nixosModules/ags/v2/default.nix | 33 ++- nixosModules/ags/v2/style.scss | 1 + .../ags/v2/widgets/lockscreen/main.tsx | 240 ++++++++++++++++++ .../ags/v2/widgets/lockscreen/style.scss | 4 + 7 files changed, 316 insertions(+), 20 deletions(-) create mode 100644 nixosModules/ags/v2/widgets/lockscreen/main.tsx create mode 100644 nixosModules/ags/v2/widgets/lockscreen/style.scss diff --git a/.gitignore b/.gitignore index bd86ed37..f9ddc726 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ result* .nixd.json ## AGS -nixosModules/ags/config/ts/lockscreen/vars.ts +**/vars.ts **/config.js *icons **/types diff --git a/nixosModules/ags/default.nix b/nixosModules/ags/default.nix index 952c88b2..26e61e64 100644 --- a/nixosModules/ags/default.nix +++ b/nixosModules/ags/default.nix @@ -21,6 +21,7 @@ in { mkIf cfgDesktop.ags.enable { # Enable pam for ags security.pam.services.ags = {}; + security.pam.services.astal-auth = {}; services.upower.enable = true; diff --git a/nixosModules/ags/v2/app.ts b/nixosModules/ags/v2/app.ts index 72fdbf9d..c52785ab 100644 --- a/nixosModules/ags/v2/app.ts +++ b/nixosModules/ags/v2/app.ts @@ -1,5 +1,7 @@ import { App } from 'astal/gtk3'; +import GLib from 'gi://GLib?version=2.0'; + import style from './style.scss'; import AppLauncher from './widgets/applauncher/main'; @@ -13,21 +15,44 @@ import PowerMenu from './widgets/powermenu/main'; import MonitorClicks from './services/monitor-clicks'; +import Lockscreen from './widgets/lockscreen/main'; -App.start({ - css: style, - main: () => { - AppLauncher(); - Bar(); - BgFade(); - Calendar(); - Corners(); - IconBrowser(); - NotifPopups(); - NotifCenter(); - PowerMenu(); +const CONF = GLib.getenv('CONF'); - new MonitorClicks(); - }, -}); +switch (CONF) { + case 'lock': { + App.start({ + css: style, + instanceName: CONF, + + main: () => { + Lockscreen(); + }, + }); + + break; + } + + case 'wim': { + App.start({ + css: style, + + main: () => { + AppLauncher(); + Bar(); + BgFade(); + Calendar(); + Corners(); + IconBrowser(); + NotifPopups(); + NotifCenter(); + PowerMenu(); + + new MonitorClicks(); + }, + }); + + break; + } +} diff --git a/nixosModules/ags/v2/default.nix b/nixosModules/ags/v2/default.nix index 097710f8..9eea8d5f 100644 --- a/nixosModules/ags/v2/default.nix +++ b/nixosModules/ags/v2/default.nix @@ -1,15 +1,22 @@ self: { lib, + osConfig, pkgs, ... }: { config = let - inherit (lib) attrValues removeAttrs; + inherit (lib) attrValues boolToString removeAttrs; - inherit (self.inputs) agsV2; + inherit (osConfig.vars) hostName; + cfgDesktop = osConfig.roles.desktop; + + inherit (self.inputs) agsV2 gtk-session-lock; + + gtkSessionLock = gtk-session-lock.packages.${pkgs.system}.default; agsV2Packages = agsV2.packages.${pkgs.system}; - astalLibs = attrValues (removeAttrs agsV2.inputs.astal.packages.${pkgs.system} ["docs" "gjs"]); + astalLibs = attrValues (removeAttrs agsV2.inputs.astal.packages.${pkgs.system} ["docs" "gjs"]) ++ [gtkSessionLock]; + agsFull = agsV2Packages.ags.override {extraPackages = astalLibs;}; configDir = "/home/matt/.nix/nixosModules/ags/v2"; in { home = { @@ -17,7 +24,15 @@ self: { (pkgs.writeShellApplication { name = "agsV2"; text = '' - exec ${agsV2Packages.agsFull}/bin/ags --config ${configDir} "$@" + export CONF="wim" + exec ${agsFull}/bin/ags --config ${configDir} "$@" + ''; + }) + (pkgs.writeShellApplication { + name = "agsConf"; + text = '' + export CONF="$1" + exec ${agsFull}/bin/ags --config ${configDir} ''; }) ]; @@ -56,6 +71,16 @@ self: { "lib" = ["ES2023"]; }; }; + + "${configDir}/widgets/lockscreen/vars.ts".text = + # javascript + '' + export default { + mainMonitor: '${cfgDesktop.mainMonitor}', + dupeLockscreen: ${boolToString cfgDesktop.displayManager.duplicateScreen}, + hasFprintd: ${boolToString (hostName == "wim")}, + }; + ''; } ); }; diff --git a/nixosModules/ags/v2/style.scss b/nixosModules/ags/v2/style.scss index 0f7dd4f3..e8dc409f 100644 --- a/nixosModules/ags/v2/style.scss +++ b/nixosModules/ags/v2/style.scss @@ -16,5 +16,6 @@ window, viewport { @import 'widgets/bar/style.scss'; @import 'widgets/date/style.scss'; @import 'widgets/icon-browser/style.scss'; +@import 'widgets/lockscreen/style.scss'; @import 'widgets/notifs/style.scss'; @import 'widgets/powermenu/style.scss'; diff --git a/nixosModules/ags/v2/widgets/lockscreen/main.tsx b/nixosModules/ags/v2/widgets/lockscreen/main.tsx new file mode 100644 index 00000000..93bb8732 --- /dev/null +++ b/nixosModules/ags/v2/widgets/lockscreen/main.tsx @@ -0,0 +1,240 @@ +import { bind, idle, timeout, Variable } from 'astal'; +import { App, Astal, Gdk, Gtk, Widget } from 'astal/gtk3'; +import { register } from 'astal/gobject'; + +import AstalAuth from 'gi://AstalAuth'; +import Lock from 'gi://GtkSessionLock?version=0.1'; + +import Separator from '../misc/separator'; +import { get_hyprland_monitor_desc } from '../../lib'; + +declare global { + function authFinger(): void; +} + +// This file is generated by Nix +import Vars from './vars'; + + +export default () => { + const lock = Lock.prepare_lock(); + const windows = new Map(); + + @register() + class BlurredBox extends Widget.Box { + geometry = {} as { w: number, h: number }; + } + const blurBGs: BlurredBox[] = []; + + const transition_duration = 1000; + const WINDOW_MARGINS = -2; + const ENTRY_SPACING = 20; + const CLOCK_SPACING = 60; + + const bgCSS = ({ w = 1, h = 1 } = {}) => ` + border: 2px solid rgba(189, 147, 249, 0.8); + background: rgba(0, 0, 0, 0.2); + min-height: ${h}px; + min-width: ${w}px; + transition: min-height ${transition_duration / 2}ms, + min-width ${transition_duration / 2}ms; +`; + + const unlock = () => { + blurBGs.forEach((b) => { + b.css = bgCSS({ + w: b.geometry.w, + h: 1, + }); + + timeout(transition_duration / 2, () => { + b.css = bgCSS({ + w: 1, + h: 1, + }); + }); + }); + timeout(transition_duration, () => { + lock.unlock_and_destroy(); + Gdk.Display.get_default()?.sync(); + App.quit(); + }); + }; + + const Clock = () => { + const time = Variable('').poll(1000, () => { + return (new Date().toLocaleString([], { + hour: 'numeric', + minute: 'numeric', + hour12: true, + }) ?? '') + .replace('a.m.', 'AM') + .replace('p.m.', 'PM'); + }); + + return ( +