mirror of
https://github.com/outbackdingo/hyprcosmic.git
synced 2026-08-25 14:53:21 +00:00
The bar showed which windows existed but not which one had the keyboard,
and nothing at all about the GPU, the fans, the disk, or a unit that had
failed at boot. Six modules, two of which needed a script because waybar
has no module that fits.
hyprland/window, and no compositor change
Reading the active window needs `j/activewindow` on startup and
`activewindow>>` on .socket2.sock, and hypr_ipc already serves both. A
retitle of the focused window propagates too, which is the case that
usually needs a separate `windowtitle` event: this fork diffs a snapshot
on a 150 ms tick rather than emitting from call sites, so src/hypr_ipc/
sync.rs sees a (class, title) change and cannot miss it. There is already
a test for exactly that -- title_change_alone_emits_activewindow.
The rewrite rules trim the app suffix from titles written for a title bar
rather than a 60-column slot. All five now use the same [-<em dash>]
class. Vivaldi had a bare hyphen because it was written from the live
title -- j/clients reports "Inbox - ... - Gmail - Vivaldi" -- and the
others got the class in a later pass, which left the one rule that would
break if Vivaldi ever switched separators. COSMIC's own applications use
an em dash and not a hyphen, so a rule written with a hyphen matches
nothing there.
custom/fan, because neither of the obvious options can name this sensor
waybar has no fan module. Its temperature module cannot be borrowed: it
divides by 1000 to turn millidegrees into degrees, which renders 2700 rpm
as 2 C. Nor can hwmon-path-abs point at the fans. That option names a
parent directory and takes the one hwmonN inside it, which works for
k10temp and amdgpu because each has exactly one, but asus-nb-wmi has two:
hwmon9 name=asus fan1_input, fan2_input
hwmon10 name=asus_custom_fan_curve the curve's set points
Which of the two waybar picked would be down to readdir order. So the
script resolves by content instead -- any hwmon with a fan*_input -- which
also makes it work on hardware that is not this laptop. It prints nothing
where there is no readable fan, and waybar draws an empty custom module as
nothing, so a VM loses the item rather than showing a dead 0 rpm.
hyprcosmic-keybinds, and why it does not read cosmic.conf
The obvious implementation reads cosmic.conf and would be wrong. This
machine's cosmic.conf declares six bindings. The session answers to 122.
The other 116 are COSMIC's defaults, which the fork does not restate
because it has no reason to -- Super+Q closes a window whether or not
anybody wrote it down. A reference showing six entries would not look
broken, it would look complete, while missing every window, workspace and
media key on the machine.
So it reads the three RON files the compositor reads: Shortcuts/v1/
defaults for the built-ins, the user's Shortcuts/v1/custom for what
cosmic-conf projected out of cosmic.conf, and Shortcuts/v1/system_actions
to turn System(Screenshot) into cosmic-screenshot. Without the third, a
third of the list would name internal actions rather than the programs
they launch, which is the half of the question that was being asked.
Parsing RON with sed deserves a defence. The principled home for this is a
`cosmic-conf binds` subcommand, which already has the schema and the bind
grammar -- and is a compiled change and a full package build. The files
are one binding per line and nothing downstream consumes this, so the cost
of being wrong is a mangled row in a help window, not a broken keybinding.
The script refuses to show a list it could not parse rather than showing a
short one.
The binding for it was chosen with the script: Super+K and Super+I are
both focus actions in COSMIC's defaults, and Super+Shift+/ is free.
install-assets: prune dot-directories from the audit
audit_config_tree refuses to run unless every file under config/ is
classified, and it started failing on six gitignored .omc/ state files
that tooling had dropped into config/waybar/. Failing on those trains you
to ignore the one message that catches a genuinely unclassified asset.
Dot files are still walked; only directories are pruned.
Verified before committing
The generated config parses as JSON with all 23 modules defined and none
defined but unplaced. The three stylesheets concatenate and parse clean
through GTK's own CssProvider, which is the parser waybar uses, and every
@colour they name is defined. Both scripts pass a syntax check, and
hyprcosmic-keybinds was run with rofi stubbed -- nothing appeared on the
desktop -- producing 118 rows, which is 116 defaults plus 6 ours less the
4 that override. System() actions resolved to real commands, chords sorted
Super first, and the modifier-only Super binding survived, which a parser
requiring a key field would have dropped.
Every sensor was read before being wired to a module rather than after:
amdgpu edge 55 C, cpu_fan 2700 and gpu_fan 2500 rpm, zero failed units in
both scopes, / at 3 percent.
Not verified: how any of it looks. Rendering needs waybar restarted
against a session that is not at the lock screen.
237 lines
9.5 KiB
Bash
Executable File
237 lines
9.5 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
#
|
|
# Install the parts of HyprCosmic that live outside a user's home directory.
|
|
#
|
|
# WHY THIS SCRIPT EXISTS
|
|
# ----------------------
|
|
# Everything here was placed by hand with `sudo install` while the desktop was
|
|
# being built, which left two problems that this script exists to close:
|
|
#
|
|
# 1. A fresh machine has none of it. rofi's config.rasi @imports
|
|
# /usr/share/hyprcosmic/rofi/{palette,rules}.rasi by absolute path, and a
|
|
# missing @import is an error rofi renders *in place of the launcher*
|
|
# rather than a warning it skips. Miss those two files and Super+A shows a
|
|
# parse error instead of a menu.
|
|
#
|
|
# 2. Hand-installed files drift. /usr/bin/start-hyprcosmic silently gained a
|
|
# session-logging block during debugging that never made it back to the
|
|
# copy under version control; nothing noticed until the two were diffed on
|
|
# a hunch. `--check` is the cure: it compares every managed file against
|
|
# its source and exits non-zero on any difference.
|
|
#
|
|
# WHAT IT DOES NOT DO
|
|
# -------------------
|
|
# Per-user files. `cosmic-conf import-theme --assets` writes those, because they
|
|
# depend on the installed theme and on $HOME; see PER_USER below for the list
|
|
# and its owner. The cosmic-conf, cosmic-session and cosmic-comp binaries are
|
|
# also out of scope. The top-level justfile installs them -- cosmic-conf from
|
|
# its own `install` line, the other two from their component's recipe -- and
|
|
# they are build outputs, so comparing them byte-for-byte here would only ever
|
|
# report a rebuild.
|
|
#
|
|
# Usage:
|
|
# tools/install-assets.sh install (needs write access to PREFIX)
|
|
# tools/install-assets.sh --check compare only; exit 1 on any drift
|
|
# tools/install-assets.sh --dry-run print what install would do
|
|
# tools/install-assets.sh --no-session skip start-hyprcosmic and the .desktop
|
|
#
|
|
# Environment:
|
|
# PREFIX install prefix, default /usr (see the warning below)
|
|
# DESTDIR staging root for packaging, prepended to every path
|
|
|
|
set -uo pipefail
|
|
|
|
REPO="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
PREFIX="${PREFIX:-/usr}"
|
|
DESTDIR="${DESTDIR:-}"
|
|
|
|
MODE=install
|
|
WITH_SESSION=1
|
|
|
|
# Kept for the "re-run as sudo" hint, which has to quote the invocation the user
|
|
# actually made; $@ is long gone by the time a write fails.
|
|
ARGV=("$@")
|
|
|
|
die() { printf 'install-assets: %s\n' "$*" >&2; exit 1; }
|
|
warn() { printf 'install-assets: %s\n' "$*" >&2; }
|
|
|
|
while (($#)); do
|
|
case "$1" in
|
|
--check) MODE=check ;;
|
|
--dry-run) MODE=dry-run ;;
|
|
--no-session) WITH_SESSION=0 ;;
|
|
-h|--help) sed -n '2,/^set -uo/p' "${BASH_SOURCE[0]}" | sed 's/^# \?//;$d'; exit 0 ;;
|
|
*) die "unknown argument: $1 (try --help)" ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# Files under config/ that belong to the system, as "source:destination:mode".
|
|
# Destinations are relative to $PREFIX.
|
|
SHARED=(
|
|
"config/waybar/bridge-hyde.css:share/hyprcosmic/waybar/bridge-hyde.css:644"
|
|
"config/waybar/config.jsonc:share/hyprcosmic/waybar/config.jsonc:644"
|
|
"config/waybar/palette.css:share/hyprcosmic/waybar/palette.css:644"
|
|
"config/waybar/rules.css:share/hyprcosmic/waybar/rules.css:644"
|
|
"config/rofi/palette.rasi:share/hyprcosmic/rofi/palette.rasi:644"
|
|
"config/rofi/rules.rasi:share/hyprcosmic/rofi/rules.rasi:644"
|
|
"config/bin/hyprcosmic-powermenu:bin/hyprcosmic-powermenu:755"
|
|
"config/bin/hyprcosmic-fan:bin/hyprcosmic-fan:755"
|
|
"config/bin/hyprcosmic-keybinds:bin/hyprcosmic-keybinds:755"
|
|
)
|
|
|
|
# The session entry point. Kept apart from SHARED because it is versioned in the
|
|
# cosmic-session fork rather than in this repository -- that fork is a separate
|
|
# checkout and may simply be absent, in which case these are skipped.
|
|
SESSION=(
|
|
"cosmic-session/data/start-hyprcosmic:bin/start-hyprcosmic:755"
|
|
"cosmic-session/data/hyprcosmic.desktop:share/wayland-sessions/hyprcosmic.desktop:644"
|
|
)
|
|
|
|
# Files under config/ that produce a SHARED file rather than being one. They are
|
|
# inputs to a generator and have no place on the system: installing the template
|
|
# would put a file full of @@TOKEN@@ placeholders next to the real config, and
|
|
# whichever one a future reader opened first would be a coin toss.
|
|
SOURCES=(
|
|
"config/waybar/config.jsonc.in" # -> config/waybar/config.jsonc
|
|
"config/waybar/generate-config.py" # the generator, and the icon table
|
|
)
|
|
|
|
# Files under config/ that are deliberately NOT installed here, each with the
|
|
# thing that does install it. This list is not decoration: the audit below
|
|
# refuses to run unless every file under config/ appears in exactly one of the
|
|
# three lists, so adding a file forces a decision about where it belongs instead
|
|
# of letting it be quietly left out of all of them.
|
|
PER_USER=(
|
|
"config/autostart" # ~/.config/hyprcosmic/autostart, by hand
|
|
"config/cosmic.conf" # ~/.config/hyprcosmic/cosmic.conf, by hand
|
|
"config/waybar/style.css" # ~/.config/hyprcosmic/waybar/style.css; @imports a sibling theme.css
|
|
"config/rofi/config.rasi" # ~/.config/rofi/config.rasi, by `cosmic-conf import-theme --assets`
|
|
)
|
|
|
|
audit_config_tree() {
|
|
local f rel known=" ${PER_USER[*]} ${SOURCES[*]} " unclassified=()
|
|
# Built with a loop, not `${SHARED[*]%%:*}`: that form strips the suffix
|
|
# from the first element only and silently keeps the rest whole.
|
|
for f in "${SHARED[@]}"; do known+="${f%%:*} "; done
|
|
|
|
while IFS= read -r -d '' f; do
|
|
rel="${f#"$REPO"/}"
|
|
[[ "$known" == *" $rel "* ]] || unclassified+=("$rel")
|
|
# Dot-directories are pruned. Nothing shipped lives in one, and tooling
|
|
# drops state inside the tree without asking -- .omc/ appeared under
|
|
# config/waybar/ and failed this audit with six files that are gitignored
|
|
# and are not assets. Failing on those trains you to ignore the one message
|
|
# that catches a genuinely unclassified file. Dot *files* are still walked;
|
|
# only directories are pruned.
|
|
done < <(find "$REPO/config" -name '.?*' -type d -prune -o -type f -print0 | sort -z)
|
|
|
|
((${#unclassified[@]} == 0)) || die "not listed as shared or per-user: ${unclassified[*]}
|
|
Add each to SHARED or PER_USER in $(basename "${BASH_SOURCE[0]}") and say which."
|
|
}
|
|
|
|
# The prefix is only half honoured, and pretending otherwise would be worse than
|
|
# saying so. Some consumers name /usr/share/hyprcosmic as a literal because they
|
|
# have no way to interpolate one: rofi's .rasi has no variables, and the
|
|
# autostart file is explicitly not a shell. Report them by grepping rather than
|
|
# from a hardcoded list, so this warning cannot go stale.
|
|
check_prefix_assumptions() {
|
|
[[ "$PREFIX" == /usr ]] && return 0
|
|
local hits
|
|
hits="$(cd "$REPO" && grep -rl '/usr/share/hyprcosmic' config/ 2>/dev/null | sort | tr '\n' ' ')"
|
|
[[ -z "$hits" ]] && return 0
|
|
warn "PREFIX=$PREFIX, but these name /usr/share/hyprcosmic literally and cannot interpolate it:"
|
|
warn " $hits"
|
|
warn "they will keep reading /usr/share unless you edit them; rofi will show a parse error if it is empty"
|
|
}
|
|
|
|
# Fail before touching anything rather than half way through. The nearest
|
|
# existing ancestor is what matters: install(1) creates the leaf directories, so
|
|
# an absent share/hyprcosmic/rofi is fine as long as share/ can be written.
|
|
assert_writable() {
|
|
local dest="$1" dir
|
|
dir="$(dirname "$dest")"
|
|
while [[ ! -e "$dir" && "$dir" != / ]]; do dir="$(dirname "$dir")"; done
|
|
[[ -w "$dir" ]] && return 0
|
|
if ((EUID != 0)); then
|
|
die "$dir is not writable. Re-run as: sudo ${BASH_SOURCE[0]}${ARGV[*]:+ ${ARGV[*]}}"
|
|
fi
|
|
die "$dir is not writable, even as root"
|
|
}
|
|
|
|
status=0
|
|
installed=0 skipped=0 differs=0
|
|
|
|
handle() {
|
|
local src="$REPO/$1" dest="$DESTDIR$PREFIX/$2" mode="$3"
|
|
|
|
if [[ ! -f "$src" ]]; then
|
|
warn "missing source, skipped: $1"
|
|
skipped=$((skipped + 1))
|
|
return
|
|
fi
|
|
|
|
case "$MODE" in
|
|
check)
|
|
if [[ ! -e "$dest" ]]; then
|
|
printf ' MISSING %s\n' "$dest"
|
|
differs=$((differs + 1))
|
|
elif cmp -s "$src" "$dest"; then
|
|
printf ' ok %s\n' "$dest"
|
|
else
|
|
printf ' DIFFERS %s\n' "$dest"
|
|
differs=$((differs + 1))
|
|
fi
|
|
;;
|
|
dry-run)
|
|
printf ' would install -m %s %s -> %s\n' "$mode" "$1" "$dest"
|
|
;;
|
|
install)
|
|
assert_writable "$dest"
|
|
install -D -m "$mode" "$src" "$dest" || die "failed to install $dest"
|
|
printf ' %s\n' "$dest"
|
|
installed=$((installed + 1))
|
|
;;
|
|
esac
|
|
}
|
|
|
|
audit_config_tree
|
|
[[ "$MODE" == install ]] && check_prefix_assumptions
|
|
|
|
targets=("${SHARED[@]}")
|
|
if ((WITH_SESSION)); then
|
|
if [[ -d "$REPO/cosmic-session/data" ]]; then
|
|
targets+=("${SESSION[@]}")
|
|
else
|
|
warn "cosmic-session/data is absent; skipping the session entry point"
|
|
fi
|
|
fi
|
|
|
|
case "$MODE" in
|
|
check) echo "Checking against $DESTDIR$PREFIX:" ;;
|
|
dry-run) echo "Dry run against $DESTDIR$PREFIX:" ;;
|
|
install) echo "Installing to $DESTDIR$PREFIX:" ;;
|
|
esac
|
|
|
|
for spec in "${targets[@]}"; do
|
|
IFS=: read -r src dest mode <<<"$spec"
|
|
handle "$src" "$dest" "$mode"
|
|
done
|
|
|
|
case "$MODE" in
|
|
check)
|
|
if ((differs)); then
|
|
echo "$differs file(s) missing or out of date; re-run without --check to fix" >&2
|
|
status=1
|
|
else
|
|
echo "All ${#targets[@]} file(s) match."
|
|
fi
|
|
;;
|
|
install)
|
|
echo "Installed $installed file(s)."
|
|
((skipped)) && echo "Skipped $skipped missing source(s)." >&2
|
|
;;
|
|
esac
|
|
|
|
exit $status
|