feat(ags): update to official agsV2

This commit is contained in:
matt1432 2024-11-13 19:39:01 -05:00
parent 5d27b3d975
commit f3e06554e4
105 changed files with 245 additions and 254 deletions

View file

@ -1,38 +0,0 @@
self: {
config,
lib,
...
}: {
config = let
inherit (lib) hasPrefix mkIf removePrefix;
# Configs
cfgDesktop = config.roles.desktop;
flakeDir = config.environment.variables.FLAKE;
agsConfigDir = "${removePrefix "/home/${cfgDesktop.user}/" flakeDir}/nixosModules/ags-v2/config";
in
mkIf cfgDesktop.ags-v2.enable {
assertions = [
{
assertion = hasPrefix "/home/${cfgDesktop.user}/" flakeDir;
message = ''
Your $FLAKE environment variable needs to point to a directory in
the main users' home to use the AGS module.
'';
}
];
# Machine config
security.pam.services.astal-auth = {};
services.upower.enable = true;
home-manager.users.${cfgDesktop.user}.imports = [
(import ./packages.nix {inherit self agsConfigDir;})
./hyprland.nix
];
};
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -1,150 +0,0 @@
{
self,
agsConfigDir,
}: {
lib,
osConfig,
pkgs,
...
}: let
# Inputs
inherit (self.inputs) agsV2 gtk-session-lock;
# Libs
inherit (lib) attrValues boolToString optionals removeAttrs;
# Cfg info
inherit (osConfig.networking) hostName;
cfgDesktop = osConfig.roles.desktop;
fullConfPath = "/home/${cfgDesktop.user}/${agsConfigDir}";
# Astal libraries
gtkSessionLock = gtk-session-lock.packages.${pkgs.system}.default;
agsV2Packages = agsV2.packages.${pkgs.system};
astalLibs = attrValues (removeAttrs agsV2.inputs.astal.packages.${pkgs.system} ["docs" "gjs"]) ++ [gtkSessionLock];
# Final ags package
agsFull = agsV2Packages.ags.override {extraPackages = astalLibs;};
in {
options.programs.ags-v2 = {
package = lib.mkOption {
type = with lib.types; nullOr package;
default = null;
};
lockPkg = lib.mkOption {
type = with lib.types; nullOr package;
default = null;
};
};
config = {
# Make these accessible outside these files
programs.ags-v2 = {
package = agsFull;
lockPkg = pkgs.writeShellApplication {
name = "lock";
runtimeInputs = [agsFull];
text = ''
export CONF="lock"
if [ "$#" == 0 ]; then
exec ags run ${fullConfPath}
else
exec ags "$@" -i lock
fi
'';
};
};
home = {
packages =
[
(pkgs.writeShellApplication {
name = "ags";
runtimeInputs = [agsFull];
text = ''
export CONF="${hostName}"
if [ "$#" == 0 ]; then
exec ags run ${fullConfPath}
else
exec ags "$@"
fi
'';
})
(pkgs.writeShellApplication {
name = "agsConf";
runtimeInputs = [agsFull];
text = ''
export CONF="$1"
exec ${agsFull}/bin/ags run ${fullConfPath}
'';
})
]
++ (builtins.attrValues {
inherit
(pkgs)
playerctl
pavucontrol # TODO: replace with ags widget
;
})
++ (optionals cfgDesktop.isTouchscreen (builtins.attrValues {
inherit
(pkgs)
ydotool
;
}));
file = let
inherit
(import "${self}/lib" {inherit pkgs self;})
buildNodeModules
buildGirTypes
;
in (
(buildGirTypes {
pname = "agsV2";
configPath = "${agsConfigDir}/@girs";
packages = astalLibs;
})
// {
"${agsConfigDir}/node_modules".source =
buildNodeModules ./config "sha256-cyVdjRV1o/UvAPzXigNzXATq1mRmsXhDqnG4wnBzSXE=";
"${agsConfigDir}/tsconfig.json".source = pkgs.writers.writeJSON "tsconfig.json" {
"$schema" = "https://json.schemastore.org/tsconfig";
"compilerOptions" = {
"experimentalDecorators" = true;
"strict" = true;
"target" = "ES2023";
"moduleResolution" = "Bundler";
"jsx" = "react-jsx";
"jsxImportSource" = "${agsV2Packages.gjs}/share/astal/gjs/gtk3";
"paths" = {
"astal" = ["${agsV2Packages.gjs}/share/astal/gjs"];
"astal/*" = ["${agsV2Packages.gjs}/share/astal/gjs/*"];
};
"skipLibCheck" = true;
"module" = "ES2022";
"lib" = ["ES2023"];
};
};
"${agsConfigDir}/widgets/lockscreen/vars.ts".text =
# javascript
''
export default {
mainMonitor: '${cfgDesktop.mainMonitor}',
dupeLockscreen: ${boolToString cfgDesktop.displayManager.duplicateScreen},
hasFprintd: ${boolToString (hostName == "wim")},
};
'';
}
);
};
};
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -1 +0,0 @@
# Moving to [AGSv2](https://github.com/Aylur/ags/tree/v2)

View file

@ -80,13 +80,11 @@ export const hyprMessage = (message: string) => new Promise<string>((
}
});
export const centerCursor = async(): Promise<void> => {
export const centerCursor = (): void => {
let x: number;
let y: number;
const monitor = (JSON.parse(await hyprMessage('j/monitors')) as AstalHyprland.Monitor[])
.find((m) => m.focused) as AstalHyprland.Monitor;
const monitor = Hyprland.get_monitors().find((m) => m.focused) as AstalHyprland.Monitor;
// @ts-expect-error this should be good
switch (monitor.transform) {
case 1:
x = monitor.x - (monitor.height / 2);
@ -109,7 +107,7 @@ export const centerCursor = async(): Promise<void> => {
break;
}
await hyprMessage(`dispatch movecursor ${x} ${y}`);
hyprMessage(`dispatch movecursor ${x} ${y}`);
};
export const closeAll = () => {

View file

@ -1,18 +1,18 @@
{
"name": "ags-v2",
"name": "ags",
"version": "0.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ags-v2",
"name": "ags",
"version": "0.0.0",
"dependencies": {
"@eslint/js": "9.14.0",
"@stylistic/eslint-plugin": "2.10.1",
"@types/node": "22.9.0",
"eslint": "9.14.0",
"eslint-plugin-jsdoc": "50.4.3",
"eslint-plugin-jsdoc": "50.5.0",
"fzf": "0.5.2",
"jiti": "2.4.0",
"typescript-eslint": "8.14.0"
@ -798,9 +798,9 @@
}
},
"node_modules/eslint-plugin-jsdoc": {
"version": "50.4.3",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.4.3.tgz",
"integrity": "sha512-uWtwFxGRv6B8sU63HZM5dAGDhgsatb+LONwmILZJhdRALLOkCX2HFZhdL/Kw2ls8SQMAVEfK+LmnEfxInRN8HA==",
"version": "50.5.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.5.0.tgz",
"integrity": "sha512-xTkshfZrUbiSHXBwZ/9d5ulZ2OcHXxSvm/NPo494H/hadLRJwOq5PMV0EUpMqsb9V+kQo+9BAgi6Z7aJtdBp2A==",
"license": "BSD-3-Clause",
"dependencies": {
"@es-joy/jsdoccomment": "~0.49.0",

View file

@ -1,5 +1,5 @@
{
"name": "ags-v2",
"name": "ags",
"version": "0.0.0",
"main": "app.ts",
"dependencies": {
@ -7,7 +7,7 @@
"@stylistic/eslint-plugin": "2.10.1",
"@types/node": "22.9.0",
"eslint": "9.14.0",
"eslint-plugin-jsdoc": "50.4.3",
"eslint-plugin-jsdoc": "50.5.0",
"fzf": "0.5.2",
"jiti": "2.4.0",
"typescript-eslint": "8.14.0"

View file

@ -2,10 +2,9 @@ import { App, Astal, Gtk, Widget } from 'astal/gtk3';
import { property, register } from 'astal/gobject';
import { Binding, idle } from 'astal';
import { hyprMessage } from '../../lib';
import { get_hyprland_monitor, hyprMessage } from '../../lib';
/* Types */
import AstalHyprland from 'gi://AstalHyprland';
type CloseType = 'none' | 'stay' | 'released' | 'clicked';
type HyprTransition = 'slide' | 'slide top' | 'slide bottom' | 'slide left' |
'slide right' | 'popin' | 'fade';
@ -88,15 +87,7 @@ export class PopupWindow extends Widget.Window {
const monitor = this.gdkmonitor ??
this.get_display().get_monitor_at_point(alloc.x, alloc.y);
// FIXME: switch back to this when it's fixed upstream
// const transform = get_hyprland_monitor(monitor)?.transform;
const manufacturer = monitor.manufacturer?.replace(',', '');
const model = monitor.model?.replace(',', '');
const start = `${manufacturer} ${model}`;
const transform = (JSON.parse(await hyprMessage('j/monitors')) as AstalHyprland.Monitor[])
// @ts-expect-error this will be fixed soon
.find((m) => m.description?.startsWith(start))?.transform;
const transform = get_hyprland_monitor(monitor)?.transform;
let width: number;

View file

@ -0,0 +1,62 @@
self: {
config,
lib,
...
}: let
inherit (lib) hasPrefix mkIf removePrefix;
# Configs
cfgDesktop = config.roles.desktop;
flakeDir = config.environment.variables.FLAKE;
agsConfigDir = "${removePrefix "/home/${cfgDesktop.user}/" flakeDir}/nixosModules/ags/config";
hmOpts = {lib, ...}: {
options.programs.ags = {
package = lib.mkOption {
type = with lib.types; nullOr package;
default = null;
};
astalLibs = lib.mkOption {
type = with lib.types; nullOr (listOf package);
default = null;
};
lockPkg = lib.mkOption {
type = with lib.types; nullOr package;
default = null;
};
configDir = lib.mkOption {
type = lib.types.str;
default = agsConfigDir;
};
};
};
in {
config = mkIf cfgDesktop.ags.enable {
assertions = [
{
assertion = hasPrefix "/home/${cfgDesktop.user}/" flakeDir;
message = ''
Your $FLAKE environment variable needs to point to a directory in
the main users' home to use the AGS module.
'';
}
];
# Machine config
security.pam.services.astal-auth = {};
services.upower.enable = true;
home-manager.users.${cfgDesktop.user}.imports = [
hmOpts
(import ./packages.nix self)
./hyprland.nix
];
};
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -0,0 +1,137 @@
self: {
config,
lib,
osConfig,
pkgs,
...
}: let
inherit (self.inputs) ags gtk-session-lock;
inherit (lib) attrValues boolToString optionals removeAttrs;
inherit (osConfig.networking) hostName;
cfg = config.programs.ags;
cfgDesktop = osConfig.roles.desktop;
in {
config = {
# Make these accessible outside these files
programs.ags = {
package = ags.packages.${pkgs.system}.ags.override {
extraPackages = cfg.astalLibs;
};
astalLibs =
attrValues (
removeAttrs ags.inputs.astal.packages.${pkgs.system} ["docs" "gjs"]
)
++ [gtk-session-lock.packages.${pkgs.system}.default];
lockPkg = pkgs.writeShellApplication {
name = "lock";
runtimeInputs = [cfg.package];
text = ''
export CONF="lock"
if [ "$#" == 0 ]; then
exec ags run ~/${cfg.configDir}
else
exec ags "$@" -i lock
fi
'';
};
};
home = {
packages =
[
(pkgs.writeShellApplication {
name = "ags";
runtimeInputs = [cfg.package];
text = ''
export CONF="${hostName}"
if [ "$#" == 0 ]; then
exec ags run ~/${cfg.configDir}
else
exec ags "$@"
fi
'';
})
(pkgs.writeShellApplication {
name = "agsConf";
runtimeInputs = [cfg.package];
text = ''
export CONF="$1"
exec ${cfg.package}/bin/ags run ~/${cfg.configDir}
'';
})
]
++ (builtins.attrValues {
inherit
(pkgs)
playerctl
pavucontrol # TODO: replace with ags widget
;
})
++ (optionals cfgDesktop.isTouchscreen (builtins.attrValues {
inherit
(pkgs)
ydotool
;
}));
file = let
inherit
(import "${self}/lib" {inherit pkgs self;})
buildNodeModules
buildGirTypes
;
in (
(buildGirTypes {
pname = "ags";
configPath = "${cfg.configDir}/@girs";
packages = cfg.astalLibs;
})
// {
"${cfg.configDir}/node_modules".source =
buildNodeModules ./config "sha256-DtrSplIOSudRgBCfKsDAtok0/21xzHiTJNrKLYy4mfY=";
"${cfg.configDir}/tsconfig.json".source = let
inherit (ags.packages.${pkgs.system}) gjs;
in
pkgs.writers.writeJSON "tsconfig.json" {
"$schema" = "https://json.schemastore.org/tsconfig";
"compilerOptions" = {
"experimentalDecorators" = true;
"strict" = true;
"target" = "ES2023";
"moduleResolution" = "Bundler";
"jsx" = "react-jsx";
"jsxImportSource" = "${gjs}/share/astal/gjs/gtk3";
"paths" = {
"astal" = ["${gjs}/share/astal/gjs"];
"astal/*" = ["${gjs}/share/astal/gjs/*"];
};
"skipLibCheck" = true;
"module" = "ES2022";
"lib" = ["ES2023"];
};
};
"${cfg.configDir}/widgets/lockscreen/vars.ts".text =
# javascript
''
export default {
mainMonitor: '${cfgDesktop.mainMonitor}',
dupeLockscreen: ${boolToString cfgDesktop.displayManager.duplicateScreen},
hasFprintd: ${boolToString (hostName == "wim")},
};
'';
}
);
};
};
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -36,11 +36,11 @@ in {
'';
};
ags-v2.enable = mkOption {
ags.enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether we want to enable AGSv2 for the DE shell.
Whether we want to enable AGS for the DE shell.
'';
};

View file

@ -7,7 +7,7 @@ self: {
inherit (self.inputs) hyprgrass hyprland hyprland-plugins;
in {
imports = [
(import ../../ags-v2 self)
(import ../../ags self)
./modules/dconf.nix
./modules/printer.nix

View file

@ -12,8 +12,8 @@
hmCfg = config.home-manager.users.${cfg.user};
hyprPkg = hmCfg.wayland.windowManager.hyprland.finalPackage;
# See nixosModules/ags-v2/packages.nix
lockPkg = hmCfg.programs.ags-v2.lockPkg;
# See nixosModules/ags/packages.nix
lockPkg = hmCfg.programs.ags.lockPkg;
runInDesktop = pkgs.writeShellApplication {
name = "runInDesktop";

View file

@ -1,41 +1,36 @@
self: {
config,
lib,
pkgs,
...
}: {
config = let
# Libs
inherit (lib) removePrefix;
cfg = config.roles.desktop;
agsCfg = hmCfg.programs.ags;
hmCfg = config.home-manager.users.${cfg.user};
ags = hmCfg.programs.ags-v2.package;
hyprland = hmCfg.wayland.windowManager.hyprland.finalPackage;
agsConfig = let
homeFiles = config.home-manager.users.${cfg.user}.home.file;
agsDir = "${removePrefix "/home/${cfg.user}/" config.environment.variables.FLAKE}/nixosModules/ags-v2/config";
nodeModules = homeFiles."${agsDir}/node_modules".source;
tsconfig = homeFiles."${agsDir}/tsconfig.json".source;
varsTs = homeFiles."${agsDir}/widgets/lockscreen/vars.ts".source;
nodeModules = homeFiles."${agsCfg.configDir}/node_modules".source;
tsconfig = homeFiles."${agsCfg.configDir}/tsconfig.json".source;
varsTs = homeFiles."${agsCfg.configDir}/widgets/lockscreen/vars.ts".source;
in
pkgs.runCommandLocal "agsConfig" {} ''
cp -ar ${tsconfig} ./tsconfig.json
cp -ar ${../../ags-v2/config}/* ./.
cp -ar ${../../ags/config}/* ./.
chmod +w -R ./.
cp -ar ${varsTs} ./widgets/lockscreen/vars.ts
cp -ar ${nodeModules} ./node_modules
${ags}/bin/ags bundle ./app.ts $out
${agsCfg.package}/bin/ags bundle ./app.ts $out
'';
in {
assertions = [
{
assertion = cfg.ags-v2.enable;
assertion = cfg.ags.enable;
message = ''
The Display Manager requires AGSv2 to be enabled.
The Display Manager requires AGS to be enabled.
'';
}
];
@ -54,7 +49,7 @@ self: {
name = "agsGreeter";
runtimeInputs = [
ags
agsCfg.package
hyprland
];