Refactor codebase to use nix modules

This commit is contained in:
Julia Lange 2024-04-14 05:40:02 -07:00
parent a4735423b4
commit ffada2703c
114 changed files with 1018 additions and 744 deletions

View file

@ -0,0 +1,9 @@
// import { Switch } from "./modules/workspace-switch.js";
import { notificationPopup } from "./modules/notifications/notificationPopup.ts"
export default {
style: App.configDir + '/modules/notifications/style.css',
windows: [
notificationPopup()
]
}

View file

@ -0,0 +1,22 @@
export const Clock = (monitor = 0) => {
return Widget.Window({
monitor,
name: `switch${monitor}`,
anchor: ['top', 'left', 'right'],
margins: [864, 1030],
css: 'background: transparent;',
child: container,
});
};
const container = Widget.Box({
css: `
min-height: 110px;
min-width: 500px;
border: 4px solid #f4d80a;
border-radius: 50px;
margin: 3px;
box-shadow: 0 0 0 3px white;
`,
});

View file

@ -0,0 +1,71 @@
const notifications = await Service.import('notifications');
const popups = notifications.bind('popups');
export const notificationPopup = (monitor = 0) => {
return Widget.Window({
name: 'notifications',
anchor: ['bottom', 'right'],
child: Widget.Box({
class_name: 'notifications',
vertical: true,
children: popups.as(popups => popups.map(Notification)),
}),
});
};
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
const Notification = n => {
const title = Widget.Label({
class_name: 'title',
xalign: 0,
justification: 'left',
hexpand: true,
max_width_chars: 24,
truncate: 'end',
wrap: true,
label: n.summary,
use_markup: true,
});
const body = Widget.Label({
class_name: 'body',
hexpand: true,
use_markup: true,
xalign: 0,
justification: 'left',
label: n.body,
wrap: true,
});
const actions = Widget.Box({
class_name: 'actions',
children: n.actions.map(({ id, label }) => Widget.Button({
class_name: 'action-button',
on_clicked: () => n.invoke(id),
hexpand: true,
child: Widget.Label(label),
})),
});
return Widget.EventBox({
on_primary_click: () => n.dismiss(),
child: Widget.Box({
class_name: `notification ${n.urgency}`,
vertical: true,
children: [
Widget.Box({
children: [
Widget.Box({
vertical: true,
children: [
title,
body,
],
}),
],
}),
actions,
],
}),
});
};

View file

@ -0,0 +1,61 @@
window#notifications {
all: unset;
}
window#notifications box.notifications {
padding: .5em;
}
.icon {
min-width: 68px;
min-height: 68px;
margin-right: 1em;
}
.icon image {
font-size: 58px;
/* to center the icon */
margin: 5px;
color: @theme_fg_color;
}
.icon box {
min-width: 68px;
min-height: 68px;
border-radius: 7px;
}
.notification {
min-width: 350px;
border-radius: 11px;
padding: 1em;
margin: .5em;
border: 1px solid @wm_borders_edge;
background-color: @theme_bg_color;
}
.notification.critical {
border: 1px solid lightcoral;
}
.title {
color: @theme_fg_color;
font-size: 1.4em;
}
.body {
color: @theme_unfocused_fg_color;
}
.actions .action-button {
margin: 0 .4em;
margin-top: .8em;
}
.actions .action-button:first-child {
margin-left: 0;
}
.actions .action-button:last-child {
margin-right: 0;
}

View file

@ -0,0 +1,22 @@
export const Switch = (monitor = 0) => {
return Widget.Window({
monitor,
name: `switch${monitor}`,
anchor: ['top', 'left', 'right'],
margins: [864, 1030],
css: 'background: transparent;',
child: container,
});
};
const container = Widget.Box({
css: `
min-height: 110px;
min-width: 500px;
border: 4px solid #f4d80a;
border-radius: 50px;
margin: 3px;
box-shadow: 0 0 0 3px white;
`,
});

View file

@ -0,0 +1,25 @@
{ config, inputs, pkgs, lib, ... }:
{
options.ags = {
enable = lib.mkEnableOption "Enable ags";
};
imports = [ inputs.ags.homeManagerModules.default ];
config = lib.mkIf config.ags.enable {
home.packages = with pkgs; [
libnotify # Notifications through ags
];
programs.ags = {
enable = true;
configDir = ./config;
extraPackages = with pkgs; [
gtksourceview
webkitgtk
accountsservice
];
};
};
}

View file

@ -0,0 +1,8 @@
{ config, pkgs, lib, ... }:
{
imports = [
./ags
./eww
];
}

View file

@ -0,0 +1,11 @@
.content-box {
border: 4px solid yellow;
border-radius: 50px;
background-color: rgba(255,255,255,10);
margin: 2px;
box-shadow: 0 0 0 3px white;
}
.switch {
background: transparent;
}

View file

@ -0,0 +1 @@
(include "modules/switch.yuck")

View file

@ -0,0 +1,40 @@
(include "./widgets/components/hyprwindow.yuck")
(include "./widgets/components/hyprworkspaces.yuck")
(include "./widgets/components/internet.yuck")
(include "./widgets/components/japanesedate.yuck")
(include "./widgets/components/japaneseaudio.yuck")
(defwidget bar []
(centerbox :orientation "horizontal"
:style "padding: 0px 8px"
(box :halign "start"
:spacing 18
:space-evenly false
(hyprworkspaces)
(hyprwindow)
)
""
(box :halign "end"
:spacing 18
:space-evenly false
(eventbox :onhover "eww open preview"
:onhoverlost "eww close preview"
barplayer
)
(internet)
(japaneseaudio)
(japanesedate)
(label :style "color: #FAE3B0"
:text bartime
)
)
)
)
(defpoll bartime :interval "10s"
"date '+%H:%M'"
)
(deflisten barplayer :initial ""
"playerctl --follow metadata --format '{{ artist }} - {{ title }}' || true"
)

View file

@ -0,0 +1,5 @@
(defwidget hyprwindow []
(label :text "${hyprwindow_listener}")
)
(deflisten hyprwindow_listener :initial "" "bash $XDG_CONFIG_HOME/eww/scripts/get-window-title")

View file

@ -0,0 +1,17 @@
(defwidget hyprworkspaces []
(eventbox :onscroll "bash ~/.config/eww/scripts/change-active-workspace {} ${current_workspace}" :class "workspaces-widget"
(box :space-evenly false
:spacing 5
(for workspace in workspaces
(eventbox :onclick "hyprctl dispatch workspace ${workspace.id}"
(box :class "workspace-entry ${workspace.id == current_workspace ? "current" : ""} ${workspace.windows > 0 ? "occupied" : "empty"}"
(label :text "${workspace.id}")
)
)
)
)
)
)
(deflisten workspaces :initial "[]" "bash $XDG_CONFIG_HOME/eww/scripts/get-workspaces")
(deflisten current_workspace :initial "1" "bash $XDG_CONFIG_HOME/eww/scripts/get-active-workspace")

View file

@ -0,0 +1,8 @@
(defwidget internet []
(box :spacing 0 :space-evenly false :style "color: #f5c2e7"
network
)
)
(defpoll network :interval "30s"
"iwgetid -r")

View file

@ -0,0 +1,11 @@
(defwidget japaneseaudio []
(eventbox :onscroll "bash -c 'if [ '{}' = 'up' ]; then pamixer -i 5; else pamixer -d 5; fi'"
(box :spacing 0 :space-evenly false :style "color: #96CDFB"
volume
"音"
)
)
)
(defpoll volume :interval "1s"
"pamixer --get-volume")

View file

@ -0,0 +1,9 @@
(defwidget japanesebattery []
(box :spacing 0 :space-evenly false :style "color: #FAB387"
power
"電"
)
)
(defpoll power :interval "1m"
"cat /sys/class/power_supply/BAT1/capacity")

View file

@ -0,0 +1,9 @@
(defwidget japanesedate []
(label :style "color: #DDB6F2"
:text japanesedate_time
)
)
(defpoll japanesedate_time :interval "100s"
"bash $XDG_CONFIG_HOME/eww/scripts/japanesedate"
)

View file

@ -0,0 +1,15 @@
(defwidget powerbar []
(box
:orientation "vertical"
:spacing 8
:space-evenly false
:style "color: #FAB387"
(progress
:orientation "v"
:value {100 - power})
"電"
)
)
(defpoll power :interval "1m"
"cat /sys/class/power_supply/BAT1/capacity")

View file

@ -0,0 +1,15 @@
(defwindow switch
:monitor 1
:stacking "fg"
:focusable false
:geometry (geometry :y "60%"
:width "500px"
:height "110px"
:anchor "top center")
(border
"Example contenting")
)
(defwidget border []
(box :class "content-box"
(children)))

View file

@ -0,0 +1,21 @@
#!/bin/sh
function clamp {
min=$1
max=$2
val=$3
python -c "print(max($min, min($val, $max)))"
}
direction=$1
current=$2
if test "$direction" = "down"
then
target=$(clamp 1 10 $(($current+1)))
echo "jumping to $target"
hyprctl dispatch workspace $target
elif test "$direction" = "up"
then
target=$(clamp 1 10 $(($current-1)))
echo "jumping to $target"
hyprctl dispatch workspace $target
fi

View file

@ -0,0 +1,3 @@
#!/bin/sh
hyprctl monitors -j | jq --raw-output .[0].activeWorkspace.id
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | stdbuf -o0 grep '^workspace>>' | stdbuf -o0 awk -F '>>|,' '{print $2}'

View file

@ -0,0 +1,3 @@
#!/bin/sh
hyprctl activewindow -j | jq --raw-output .title
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | stdbuf -o0 grep '^activewindow>>' | stdbuf -o0 awk -F '>>|,' '{print $3}'

View file

@ -0,0 +1,11 @@
#!/bin/sh
spaces (){
WORKSPACE_WINDOWS=$(hyprctl workspaces -j | jq 'map({key: .id | tostring, value: .windows}) | from_entries')
seq 1 10 | jq --argjson windows "${WORKSPACE_WINDOWS}" --slurp -Mc 'map(tostring) | map({id: ., windows: ($windows[.]//0)})'
}
spaces
socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | while read -r line; do
spaces
done

View file

@ -0,0 +1,31 @@
#!/bin/sh
readarray -t dateparts <<<"$(date "+%0m月%0d日%n%u")"
echo -n "${dateparts[0]}["
case ${dateparts[1]} in
1)
echo -n "月"
;;
2)
echo -n "火"
;;
3)
echo -n "水"
;;
4)
echo -n "木"
;;
5)
echo -n "金"
;;
6)
echo -n "土"
;;
7)
echo -n "日"
;;
esac
echo "]"

View file

@ -0,0 +1,3 @@
#!/bin/sh
playerctl --follow metadata mpris:artUrl | stdbuf -o0 cut -c 8-

View file

@ -0,0 +1,13 @@
{ config, pkgs, lib, ... }:
{
options.eww = {
enable = lib.mkEnableOption "Enables eww";
};
config = lib.mkIf config.eww.enable {
programs.eww.enable = true;
programs.eww.package = pkgs.eww-wayland;
programs.eww.configDir = ./config;
};
}