feat: piloter la lecture en cours depuis la barre et assortir les notifications
La barre ne disait rien de la musique qui joue, et les notifications gardaient le style par défaut de mako, sans rapport avec le reste du bureau. Waybar gagne un module média (pochette téléchargée puis mise en cache, titre, artiste et temps) et un panneau flottant ouvert au clic ou par SUPER+M, avec une position déplaçable, les commandes de lecture et une croix pour fermer ; mako reprend la palette violette et se place sous la barre. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
9eeb9a9095
commit
6a65913c2c
9 files changed
+778
-19
No files matched your search
+13
@@ -0,0 +1,13 @@
|
||||
# Artefacts locaux — rien de tout ceci n'a sa place dans le dépôt.
|
||||
|
||||
# Caches Python : les scripts média (waybar/scripts) sont du Python et
|
||||
# laissent un __pycache__ dès qu'on les importe ou qu'on les vérifie.
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Archives de copie du thème
|
||||
*.tar.gz
|
||||
|
||||
# Éditeurs
|
||||
*.swp
|
||||
*~
|
||||
@@ -26,6 +26,8 @@ violet-dotfiles/
|
||||
├── README.md ← ce fichier
|
||||
├── hypr/ ← Hyprland : hyprland.conf, hyprlock, hyprpaper
|
||||
├── waybar/ ← barre du haut : config, style.css, icons/logo.png
|
||||
│ └── scripts/ ← modules média : media-cover, media-panel
|
||||
├── mako/ ← notifications (popups violets assortis à la barre)
|
||||
├── wofi/ ← menu d'applications (Super+R)
|
||||
├── kitty/ ← terminal
|
||||
├── btop/ ← moniteur système : themes/violet.theme
|
||||
@@ -76,8 +78,9 @@ Exemple complet :
|
||||
Ensuite :
|
||||
|
||||
```bash
|
||||
hyprctl reload # ou SUPER+SHIFT+C
|
||||
hyprctl reload # ou SUPER+SHIFT+C
|
||||
killall waybar; waybar & # recharge la barre
|
||||
makoctl reload # recharge le thème des notifications
|
||||
```
|
||||
|
||||
Redémarre pour voir GRUB et SDDM. 💜
|
||||
@@ -92,12 +95,16 @@ Paquets Arch (installés par `./install.sh --install-deps`) :
|
||||
hyprland hyprlock hyprpaper waybar wofi kitty btop
|
||||
mako grim slurp wl-clipboard playerctl pavucontrol
|
||||
noto-fonts ttf-nerd-fonts-symbols network-manager-applet
|
||||
blueman polkit-gnome dolphin
|
||||
blueman polkit-gnome dolphin python-gobject gtk4 curl
|
||||
```
|
||||
|
||||
> Les icônes de la barre ( …) viennent de **ttf-nerd-fonts-symbols**.
|
||||
> Sans ce paquet, Waybar affichera des carrés vides.
|
||||
|
||||
> `python-gobject` + `gtk4` : requis par le panneau multimédia (et par rien
|
||||
d'autre). `playerctl` lit et pilote la musique, `curl` télécharge les
|
||||
pochettes distantes.
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Personnalisation rapide
|
||||
@@ -109,27 +116,108 @@ blueman polkit-gnome dolphin
|
||||
| Changer le fond d'écran | remplace `wallpapers/Banner.png` puis relance `./install.sh` |
|
||||
| Dégradé des bordures de fenêtres | `hypr/hyprland.conf` → `col.active_border` |
|
||||
| Couleurs de la barre | `waybar/style.css` (palette en tête de fichier) |
|
||||
| Couleurs des notifications | `mako/config` (puis `makoctl reload`) |
|
||||
| Grandeur de la pochette dans la barre | `waybar/config` → module `image`, `size` |
|
||||
| Toujours vouloir le prompt bash | `./install.sh --bash` |
|
||||
|
||||
---
|
||||
|
||||
## 🎵 Lecture en cours (pochette + panneau)
|
||||
|
||||
La barre affiche la piste qui joue : **la pochette**, puis l'icône du lecteur,
|
||||
le titre, l'artiste et le temps (`0:42 / 3:18`). Rien n'est propre à un
|
||||
lecteur : tout passe par **MPRIS** (`playerctl`), donc Spotify, mpv, Firefox ou
|
||||
VLC fonctionnent de la même façon. Quand rien ne joue, la pochette et la piste
|
||||
disparaissent et seule l'image de repli reste.
|
||||
|
||||
| Action | Effet |
|
||||
|--------|-------|
|
||||
| Clic sur la pochette ou le titre | Ouvre le **panneau multimédia** |
|
||||
| Clic droit | Piste suivante |
|
||||
| Clic milieu | Piste précédente |
|
||||
| Molette | Avance / recule de 5 s |
|
||||
| `SUPER+M` | Ouvre le même panneau |
|
||||
|
||||
Le panneau (classe `fws.media`, déclarée flottante dans `hyprland.conf`) montre
|
||||
la pochette, le titre, l'artiste, l'album, une **barre de position déplaçable**
|
||||
(on peut sauter n'importe où dans la piste) et les commandes : piste
|
||||
précédente, **retour au début**, lecture/pause, piste suivante, fermeture.
|
||||
Il se ferme avec la **croix** en haut à droite, avec `Échap`, ou en cliquant une
|
||||
seconde fois sur la barre (le panneau bascule). `Espace`, `←` et `→`
|
||||
fonctionnent au clavier (lecture/pause et ±5 s).
|
||||
|
||||
> Le panneau **ne** se ferme pas tout seul quand il perd le focus : Hyprland est
|
||||
> configuré en focus glissant (`input.follow_mouse = 1`), donc ouvrir le panneau
|
||||
> depuis la barre laisse le curseur hors de la fenêtre — elle serait fermée
|
||||
> aussitôt, avant même d'avoir été vue.
|
||||
|
||||
Deux scripts, installés dans `~/.config/waybar/scripts/` :
|
||||
|
||||
- **`media-cover`** — donne à Waybar le **chemin local** de la pochette. Les
|
||||
lecteurs du web n'exposent qu'une URL `https` : l'image est téléchargée une
|
||||
seule fois dans `~/.cache/fws-media/` (vidé après 7 jours), sinon la barre la
|
||||
retéléchargerait à chaque rafraîchissement. Sans pochette, c'est le logo FWS
|
||||
qui s'affiche.
|
||||
- **`media-panel`** — le panneau lui-même (GTK4 + PyGObject, rien de plus à
|
||||
installer que `playerctl`).
|
||||
|
||||
```bash
|
||||
# Écouter un autre lecteur que celui que MPRIS désigne :
|
||||
playerctl -p mpv play-pause
|
||||
# Voir qui joue en ce moment :
|
||||
playerctl -l ; playerctl status
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔔 Notifications (mako)
|
||||
|
||||
Les popups reprennent la palette de la barre (fond `#29242e`, bordure lavande
|
||||
`#c3b6f6`, coins 12 px, police Noto Sans 11) pour ne pas avoir l'air d'un autre
|
||||
bureau. Réglages notables de `mako/config` :
|
||||
|
||||
| Réglage | Effet |
|
||||
|---------|-------|
|
||||
| `outer-margin=46,…` | La liste commence **sous la barre** au lieu de la recouvrir |
|
||||
| `group-by=app-name` | Les notifications d'une même application se regroupent |
|
||||
| `[urgency=critical]` | Bordure rose `#f569ca` et **pas de disparition automatique** |
|
||||
| `history=1` | Relire un message manqué : `makoctl history` |
|
||||
| `[mode=do-not-disturb]` | `invisible=1` : plus rien à l'écran en mode NIP |
|
||||
|
||||
```bash
|
||||
makoctl reload # après avoir modifié mako/config
|
||||
makoctl list # notifications affichées
|
||||
makoctl history # historique
|
||||
makoctl mode -t do-not-disturb # basculer le mode « ne pas déranger »
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🛠 Installation manuelle (sans le script)
|
||||
|
||||
1. **Hyprland** — copie `hypr/` vers `~/.config/hypr/`, puis dans
|
||||
`hyprpaper.conf` remplace `__WALLPAPER__` par le chemin absolu de
|
||||
`wallpapers/Banner.png` (ex. `/home/toi/Images/Banner.png`).
|
||||
2. **Waybar** — copie `waybar/` vers `~/.config/waybar/` et remplace
|
||||
`__WAYBAR_LOGO__` dans `style.css` par le chemin absolu
|
||||
`~/.config/waybar/icons/logo.png`.
|
||||
3. **wofi / kitty / btop / GTK** — copie chaque dossier vers
|
||||
2. **Waybar** — copie `waybar/` vers `~/.config/waybar/`, remplace les deux
|
||||
chemins absolus, puis rends les scripts média exécutables :
|
||||
```bash
|
||||
sed -i "s|__WAYBAR_SCRIPTS__|$HOME/.config/waybar/scripts|g" ~/.config/waybar/config
|
||||
sed -i "s|__WAYBAR_LOGO__|$HOME/.config/waybar/icons/logo.png|g" ~/.config/waybar/style.css
|
||||
chmod +x ~/.config/waybar/scripts/media-cover ~/.config/waybar/scripts/media-panel
|
||||
```
|
||||
3. **mako** — copie `mako/config` vers `~/.config/mako/`, puis recharge :
|
||||
```bash
|
||||
makoctl reload
|
||||
```
|
||||
4. **wofi / kitty / btop / GTK** — copie chaque dossier vers
|
||||
`~/.config/<nom>/`, puis choisis le thème btop : dans `~/.config/btop/btop.conf`,
|
||||
ligne `color_theme = "violet"`.
|
||||
4. **zsh** — copie `zsh/kali-violet.zshrc` vers `~/.config/zsh/` et ajoute
|
||||
5. **zsh** — copie `zsh/kali-violet.zshrc` vers `~/.config/zsh/` et ajoute
|
||||
dans `~/.zshrc` :
|
||||
```bash
|
||||
[[ -f "$HOME/.config/zsh/kali-violet.zshrc" ]] && source "$HOME/.config/zsh/kali-violet.zshrc"
|
||||
```
|
||||
5. **GRUB** :
|
||||
6. **GRUB** :
|
||||
```bash
|
||||
sudo rm -rf /boot/grub/themes/violet
|
||||
sudo cp -r grub/violet /boot/grub/themes/
|
||||
@@ -138,7 +226,7 @@ blueman polkit-gnome dolphin
|
||||
# GRUB_GFXMODE=1920x1080,auto
|
||||
sudo grub-mkconfig -o /boot/grub/grub.cfg
|
||||
```
|
||||
6. **SDDM** :
|
||||
7. **SDDM** :
|
||||
```bash
|
||||
sudo cp -r sddm/catppuccin-mocha-mauve /usr/share/sddm/themes/
|
||||
sudo cp sddm/10-fws.conf /etc/sddm.conf.d/10-fws.conf
|
||||
|
||||
+12
-1
@@ -70,6 +70,9 @@ misc {
|
||||
exec-once = hyprpaper
|
||||
exec-once = waybar
|
||||
exec-once = mako
|
||||
# playerctld suit le LECTEUR ACTIF : sans lui, les modules média de la barre
|
||||
# resteraient collés au premier lecteur ouvert (Spotify pendant que mpv joue).
|
||||
exec-once = playerctld daemon
|
||||
exec-once = nm-applet
|
||||
# Applet Bluetooth : seulement si un adaptateur existe (en VM il n'y en a
|
||||
# pas → blueman afficherait une erreur « Connection to BlueZ failed »).
|
||||
@@ -88,6 +91,9 @@ bindd = $mod, E, Gestionnaire de fichiers, exec, dolphin
|
||||
bindd = $mod, B, Ouvrir Firefox, exec, firefox
|
||||
bindd = $mod, K, Afficher les raccourcis clavier, exec, fws-keys
|
||||
bindd = $mod, X, Menu d'alimentation (arrêt/redémarrage…), exec, fws-powermenu
|
||||
# Panneau multimédia : pochette, position déplaçable, lecture/pause, pistes.
|
||||
# Même fenêtre que le clic sur la barre (script partagé avec Waybar).
|
||||
bindd = $mod, M, Panneau multimédia (lecture en cours), exec, $HOME/.config/waybar/scripts/media-panel
|
||||
|
||||
# --- Fenêtres ---------------------------------------------------------------
|
||||
bindd = $mod, Q, Fermer la fenêtre, killactive,
|
||||
@@ -181,4 +187,9 @@ windowrule = float on, match:class ^(.?[Bb]lueman-manager.*)$
|
||||
windowrule = float on, match:class ^([Ff]ws-hello)$
|
||||
windowrule = float on, match:class ^([Ff]ws-about)$
|
||||
windowrule = float on, match:class ^([Ff]ws-bugreport)$
|
||||
windowrule = float on, match:title ^(Picture-in-Picture)$
|
||||
windowrule = float on, match:title ^(Picture-in-Picture)$
|
||||
# Panneau multimédia (script media-panel) : flottant, à sa taille, au-dessus.
|
||||
# La classe vient de l'identifiant d'application « fws.media » du script ;
|
||||
# le point est écrit [.] pour rester valable quel que soit le moteur de regex.
|
||||
windowrule = float on, match:class ^(fws[.]media)$
|
||||
windowrule = size 460 214, match:class ^(fws[.]media)$
|
||||
+23
-7
@@ -4,8 +4,8 @@
|
||||
# ║ ║
|
||||
# ║ Usage : ║
|
||||
# ║ ./install.sh configs utilisateur (Hypr, ║
|
||||
# ║ Waybar, wofi, kitty, btop, ║
|
||||
# ║ GTK, zsh, fond d'écran) ║
|
||||
# ║ Waybar, mako, wofi, kitty, ║
|
||||
# ║ btop, GTK, zsh, fond d'écran)║
|
||||
# ║ ./install.sh --bash + prompt bash dans ~/.bashrc ║
|
||||
# ║ ./install.sh --grub + thème GRUB (demande sudo) ║
|
||||
# ║ ./install.sh --sddm + thème SDDM (demande sudo) ║
|
||||
@@ -125,16 +125,31 @@ say "config Hyprland → $HYPR_DST"
|
||||
# 3. Waybar
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
WAYBAR_DST="$HOME_DIR/.config/waybar"
|
||||
SCRIPTS_DST="$WAYBAR_DST/scripts"
|
||||
LOGO_DST="$WAYBAR_DST/icons/logo.png"
|
||||
backup "$WAYBAR_DST/config"
|
||||
backup "$WAYBAR_DST/style.css"
|
||||
backup "$WAYBAR_DST/icons/logo.png"
|
||||
mkdir -p "$WAYBAR_DST/icons"
|
||||
cp "$SRC_DIR/waybar/config" "$WAYBAR_DST/config"
|
||||
LOGO_DST="$WAYBAR_DST/icons/logo.png"
|
||||
mkdir -p "$WAYBAR_DST/icons" "$SCRIPTS_DST"
|
||||
# __WAYBAR_SCRIPTS__ = chemin ABSOLU : Waybar lance ses commandes sans passer
|
||||
# par un shell, donc ni « ~ » ni « $HOME » n'y sont développés.
|
||||
sed -e "s|__WAYBAR_SCRIPTS__|$SCRIPTS_DST|g" \
|
||||
"$SRC_DIR/waybar/config" > "$WAYBAR_DST/config"
|
||||
cp "$SRC_DIR/waybar/icons/logo.png" "$LOGO_DST"
|
||||
sed -e "s|__WAYBAR_LOGO__|$LOGO_DST|g" \
|
||||
"$SRC_DIR/waybar/style.css" > "$WAYBAR_DST/style.css"
|
||||
say "config Waybar → $WAYBAR_DST"
|
||||
# Panneau multimédia + pochette : appelés par la barre et par SUPER+M.
|
||||
install -m 755 "$SRC_DIR/waybar/scripts/media-cover" "$SCRIPTS_DST/media-cover"
|
||||
install -m 755 "$SRC_DIR/waybar/scripts/media-panel" "$SCRIPTS_DST/media-panel"
|
||||
say "config Waybar + scripts média → $WAYBAR_DST"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
# 3bis. Notifications (mako)
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
MAKO_DST="$HOME_DIR/.config/mako"
|
||||
backup "$MAKO_DST/config"
|
||||
install_dir "$SRC_DIR/mako" "$MAKO_DST"
|
||||
say "thème des notifications → $MAKO_DST/config"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
# 4. wofi, kitty, btop, GTK
|
||||
@@ -252,7 +267,7 @@ fi
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
DEPS=(hyprland hyprlock hyprpaper waybar wofi kitty btop mako grim slurp wl-clipboard \
|
||||
playerctl pavucontrol noto-fonts ttf-nerd-fonts-symbols network-manager-applet \
|
||||
blueman polkit-gnome dolphin)
|
||||
blueman polkit-gnome dolphin python-gobject gtk4 curl)
|
||||
if $DO_DEPS; then
|
||||
if command -v pacman >/dev/null 2>&1; then
|
||||
say "installation des dépendances (pacman)…"
|
||||
@@ -285,6 +300,7 @@ echo
|
||||
say "✔ Terminé !"
|
||||
say "Recharge Hyprland (SUPER+SHIFT+C ou hyprctl reload) et redémarre"
|
||||
say "waybar pour voir le thème : killall waybar ; waybar &"
|
||||
say "notifications (mako déjà lancé) : makoctl reload"
|
||||
if [[ -d "$BACKUP_DIR" ]]; then
|
||||
say "Anciennes configs : ~/.violet-backup-*/ (supprimables quand tout va bien)"
|
||||
fi
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
# FWS — notifications (mako), édition VIOLETTE 💜
|
||||
#
|
||||
# Mêmes valeurs que la barre Waybar pour que les popups ne semblent pas venir
|
||||
# d'un autre bureau : fond #29242e (opacité 0.88 comme la barre), bordure
|
||||
# lavande #c3b6f6 (opacité 0.35), texte #fafafa, coins 12px, police Noto Sans
|
||||
# 11. Le mauve #cba6f7 sert d'accent (barre de progression, urgence critique).
|
||||
#
|
||||
# Appliquer une modification sans redémarrer : makoctl reload
|
||||
# (mako doit tourner : exec-once = mako dans hyprland.conf).
|
||||
|
||||
font=Noto Sans 11
|
||||
background-color=#29242EE0
|
||||
text-color=#FAFAFA
|
||||
border-size=1
|
||||
border-color=#C3B6F659
|
||||
border-radius=12
|
||||
|
||||
# Marge externe = espace de la LISTE avec le bord de l'écran : 46px en haut
|
||||
# laissent passer la barre (36px de haut, 6px de marge) au lieu de la recouvrir.
|
||||
# margin = espace entre deux notifications.
|
||||
outer-margin=46,10,10,10
|
||||
margin=6
|
||||
padding=12,14
|
||||
|
||||
width=380
|
||||
height=140
|
||||
max-visible=4
|
||||
# Une teinte séparée par application : trois notifications de kitty se
|
||||
# regroupent, une notification de kitty et une de Spotify restent distinctes.
|
||||
group-by=app-name
|
||||
|
||||
anchor=top-right
|
||||
layer=overlay
|
||||
text-alignment=left
|
||||
markup=1
|
||||
icons=1
|
||||
max-icon-size=40
|
||||
progress-color=over #CBA6F7
|
||||
|
||||
default-timeout=6000
|
||||
# Historique consultable (makoctl history) : le thème de la barre n'a pas de
|
||||
# centre de notifications, c'est le seul moyen de relire un message manqué.
|
||||
history=1
|
||||
|
||||
[urgency=low]
|
||||
border-color=#9A8CD8AA
|
||||
default-timeout=4000
|
||||
|
||||
[urgency=critical]
|
||||
border-color=#F569CAFF
|
||||
background-color=#29242EF5
|
||||
# Une urgence critique reste affichée jusqu'à ce qu'on la ferme : les
|
||||
# batteries faibles ou les erreurs de disque ne doivent pas disparaître seules.
|
||||
default-timeout=0
|
||||
|
||||
[mode=do-not-disturb]
|
||||
invisible=1
|
||||
+28
-1
@@ -8,7 +8,34 @@
|
||||
"margin-right": 10,
|
||||
"modules-left": ["hyprland/workspaces", "hyprland/window"],
|
||||
"modules-center": ["clock"],
|
||||
"modules-right": ["custom/updates", "custom/keyhelp", "backlight", "pulseaudio", "bluetooth", "network", "cpu", "memory", "battery", "tray", "custom/power"],
|
||||
"modules-right": ["image", "mpris", "custom/updates", "custom/keyhelp", "backlight", "pulseaudio", "bluetooth", "network", "cpu", "memory", "battery", "tray", "custom/power"],
|
||||
|
||||
"image": {
|
||||
"exec": "__WAYBAR_SCRIPTS__/media-cover",
|
||||
"size": 22,
|
||||
"interval": 2,
|
||||
"tooltip": false,
|
||||
"on-click": "__WAYBAR_SCRIPTS__/media-panel"
|
||||
},
|
||||
|
||||
"mpris": {
|
||||
"player": "playerctld",
|
||||
"format": "{player_icon} {dynamic}",
|
||||
"format-paused": "{status_icon} {dynamic}",
|
||||
"dynamic-order": ["title", "artist", "position", "length"],
|
||||
"dynamic-separator": " — ",
|
||||
"title-len": 30,
|
||||
"artist-len": 22,
|
||||
"interval": 1,
|
||||
"player-icons": { "default": "", "spotify": "", "mpv": "", "firefox": "", "vlc": "", "chromium": "" },
|
||||
"status-icons": { "playing": "", "paused": "" },
|
||||
"tooltip-format": "{player} ({status})\n{artist} — {album}\n{dynamic}",
|
||||
"on-click": "__WAYBAR_SCRIPTS__/media-panel",
|
||||
"on-click-right": "playerctl next",
|
||||
"on-click-middle": "playerctl previous",
|
||||
"on-scroll-up": "playerctl position 5+",
|
||||
"on-scroll-down": "playerctl position 5-"
|
||||
},
|
||||
|
||||
"custom/power": {
|
||||
"format": " ",
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
# FWS — pochette de la piste en cours, pour le module « image » de Waybar.
|
||||
#
|
||||
# Waybar rappelle ce script (interval) et affiche l'image dont on lui donne le
|
||||
# chemin : on renvoie donc toujours un chemin LOCAL. Les lecteurs du web
|
||||
# (Spotify, Firefox…) n'exposent que des URL https, téléchargées une seule fois
|
||||
# puis gardées en cache — sans cache, la barre retéléchargerait la pochette à
|
||||
# chaque rafraîchissement.
|
||||
set -u
|
||||
|
||||
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/fws-media"
|
||||
# Repli quand rien ne joue ou que la piste n'a pas de pochette : le logo FWS,
|
||||
# déjà installé par le thème, évite un trou dans la barre.
|
||||
FALLBACK="$(cd "$(dirname "$0")/../icons" && pwd)/logo.png"
|
||||
|
||||
art=$(playerctl metadata mpris:artUrl 2>/dev/null) || art=""
|
||||
|
||||
if [ -z "$art" ]; then
|
||||
printf '%s\n' "$FALLBACK"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "$art" in
|
||||
file://*)
|
||||
printf '%s\n' "${art#file://}"
|
||||
;;
|
||||
http*)
|
||||
name=$(printf '%s' "$art" | md5sum | cut -d' ' -f1)
|
||||
file="$CACHE/$name"
|
||||
if [ ! -s "$file" ]; then
|
||||
mkdir -p "$CACHE"
|
||||
# Best-effort : une pochette indisponible ne doit pas retarder la
|
||||
# barre, on retombe simplement sur le logo. La limite de temps est
|
||||
# large : les CDN d'images sont lents, et une coupure donnerait une
|
||||
# pochette manquante pour toute la piste.
|
||||
if ! curl -fsSL --connect-timeout 4 --max-time 15 -o "$file.part" "$art"; then
|
||||
rm -f "$file.part"
|
||||
printf '%s\n' "$FALLBACK"
|
||||
exit 0
|
||||
fi
|
||||
mv "$file.part" "$file"
|
||||
# Une entrée par piste : le cache grossirait sans fin autrement.
|
||||
find "$CACHE" -type f -mtime +7 -delete 2>/dev/null
|
||||
fi
|
||||
printf '%s\n' "$file"
|
||||
;;
|
||||
*)
|
||||
printf '%s\n' "$FALLBACK"
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,481 @@
|
||||
#!/usr/bin/env python3
|
||||
"""FWS — panneau multimédia de la barre.
|
||||
|
||||
Ouvert en cliquant la pochette ou le titre dans Waybar (ou avec SUPER+M), il
|
||||
montre la pochette, la piste, le temps écoulé et une barre de position
|
||||
déplaçable, avec les commandes de lecture.
|
||||
|
||||
Tout passe par `playerctl` : n'importe quel lecteur MPRIS (Spotify, mpv,
|
||||
Firefox, VLC…) devient pilotable sans configuration, et l'interface ne sait
|
||||
rien d'autre des lecteurs que ce que MPRIS veut bien dire. Sans lecteur, le
|
||||
panneau reste ouvert et l'affiche au lieu de se fermer : on comprend que rien
|
||||
ne joue au lieu de croire à un bug.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "4.0")
|
||||
gi.require_version("Pango", "1.0")
|
||||
|
||||
from gi.repository import Gio, GLib, Gtk, Pango # noqa: E402 (après require_version)
|
||||
|
||||
# Poll interval: fast enough that the slider follows the track smoothly, slow
|
||||
# enough to keep three `playerctl` calls per tick cheap.
|
||||
POLL_MS = 500
|
||||
# Ignore the player position for a moment after a seek: the player reports the
|
||||
# old position for a few hundred milliseconds, which would make the slider jump
|
||||
# back under the cursor.
|
||||
SEEK_GRACE_S = 0.8
|
||||
SEEK_STEP_S = 5
|
||||
|
||||
CSS = """
|
||||
window {
|
||||
background: #29242e;
|
||||
border: 1px solid rgba(195, 182, 246, 0.35);
|
||||
border-radius: 14px;
|
||||
}
|
||||
.cover {
|
||||
border: 1px solid rgba(195, 182, 246, 0.35);
|
||||
border-radius: 12px;
|
||||
}
|
||||
.title { font-size: 15px; font-weight: bold; color: #fafafa; }
|
||||
.subtitle { font-size: 12px; color: #c3b6f6; }
|
||||
.album { font-size: 11px; color: #9a8cd8; }
|
||||
.time { font-size: 11px; color: #9a8cd8; }
|
||||
.hint { font-size: 10px; color: #6b6180; }
|
||||
.idle { font-size: 13px; color: #9a8cd8; }
|
||||
|
||||
scale trough {
|
||||
background: #1f1a2e;
|
||||
border-radius: 6px;
|
||||
min-height: 6px;
|
||||
}
|
||||
scale trough highlight {
|
||||
background: #cba6f7;
|
||||
border-radius: 6px;
|
||||
}
|
||||
scale slider {
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
min-width: 14px;
|
||||
min-height: 14px;
|
||||
margin: -5px 0;
|
||||
}
|
||||
scale:hover slider { background: #c3b6f6; }
|
||||
|
||||
button {
|
||||
background: #1f1a2e;
|
||||
color: #fafafa;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
padding: 6px 14px;
|
||||
font-size: 15px;
|
||||
}
|
||||
button:hover { background: #3a3350; }
|
||||
button:disabled { color: #6b6180; }
|
||||
button.accent { background: #cba6f7; color: #29242e; font-weight: bold; }
|
||||
button.accent:hover { background: #c3b6f6; }
|
||||
button.close { padding: 2px 10px; color: #c3b6f6; }
|
||||
button.close:hover { background: #f569ca; color: #29242e; }
|
||||
"""
|
||||
|
||||
|
||||
def playerctl(*args: str) -> str | None:
|
||||
"""Run a playerctl command, returning its output or None when it fails.
|
||||
|
||||
Any failure (no player, key absent, playerctl gone) is a normal state for
|
||||
this panel, so it is reported as None rather than raising: the caller
|
||||
decides what to show.
|
||||
"""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["playerctl", *args], capture_output=True, text=True, timeout=2
|
||||
)
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return None
|
||||
if result.returncode != 0:
|
||||
return None
|
||||
return result.stdout.strip()
|
||||
|
||||
|
||||
def metadata(key: str) -> str | None:
|
||||
value = playerctl("metadata", key)
|
||||
return value or None
|
||||
|
||||
|
||||
def position() -> float | None:
|
||||
value = playerctl("position")
|
||||
if value is None:
|
||||
return None
|
||||
try:
|
||||
return float(value)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def length() -> float | None:
|
||||
"""Track length in seconds (MPRIS exposes it in microseconds)."""
|
||||
value = metadata("mpris:length")
|
||||
if value is None:
|
||||
return None
|
||||
try:
|
||||
return int(value) / 1_000_000
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def format_time(seconds: float) -> str:
|
||||
seconds = max(0, int(seconds))
|
||||
minutes, secs = divmod(seconds, 60)
|
||||
hours, minutes = divmod(minutes, 60)
|
||||
if hours:
|
||||
return f"{hours}:{minutes:02d}:{secs:02d}"
|
||||
return f"{minutes}:{secs:02d}"
|
||||
|
||||
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
CACHE_DIR = os.path.join(
|
||||
os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache")), "fws-media"
|
||||
)
|
||||
# Repli quand la piste n'a pas de pochette : le logo FWS du thème, comme dans
|
||||
# la barre, plutôt qu'un carré vide.
|
||||
FALLBACK_ART = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, "icons", "logo.png"))
|
||||
|
||||
|
||||
def cache_path(url: str) -> str:
|
||||
"""Cache file the bar's helper uses for a remote artwork URL.
|
||||
|
||||
Same name on purpose (md5 of the URL): the panel only READS the cache the
|
||||
bar fills, so opening it never waits for a download.
|
||||
"""
|
||||
return os.path.join(CACHE_DIR, hashlib.md5(url.encode()).hexdigest())
|
||||
|
||||
|
||||
def cover_for(url: str | None) -> tuple[str | None, bool]:
|
||||
"""Local cover path for an artUrl, and whether it still has to be fetched.
|
||||
|
||||
Remote artwork is never downloaded here: the answer is "not ready yet" and
|
||||
the caller shows the logo until the file shows up in the cache.
|
||||
"""
|
||||
if not url:
|
||||
return FALLBACK_ART, False
|
||||
if url.startswith("file://"):
|
||||
return url[len("file://"):], False
|
||||
if url.startswith("http"):
|
||||
cached = cache_path(url)
|
||||
return (cached, False) if os.path.exists(cached) else (None, True)
|
||||
return FALLBACK_ART, False
|
||||
|
||||
|
||||
def start_download() -> None:
|
||||
"""Ask the bar's helper to fetch the artwork, in the background.
|
||||
|
||||
Waybar runs it every couple of seconds anyway; running it too keeps the
|
||||
panel usable when the bar is not up.
|
||||
"""
|
||||
try:
|
||||
subprocess.Popen(
|
||||
[os.path.join(SCRIPT_DIR, "media-cover")],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
start_new_session=True,
|
||||
)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
class MediaPanel(Gtk.Application):
|
||||
def __init__(self) -> None:
|
||||
# L'identifiant d'application devient la CLASSE de la fenêtre pour le
|
||||
# compositeur : c'est lui qui applique les règles « float » et « size »
|
||||
# de hyprland.conf. Il doit être un nom D-Bus valide, d'où le point.
|
||||
super().__init__(application_id="fws.media")
|
||||
self.window: Gtk.ApplicationWindow | None = None
|
||||
self.dragging = False
|
||||
self.last_seek = 0.0
|
||||
self.track_id: str | None = None
|
||||
self.pending_art: str | None = None
|
||||
self.css_loaded = False
|
||||
|
||||
# ---------------------------------------------------------------- fenêtre
|
||||
|
||||
def do_activate(self) -> None:
|
||||
# Une seule instance : recliquer sur la barre ferme le panneau déjà
|
||||
# ouvert au lieu d'en empiler un deuxième.
|
||||
if self.window is not None and self.window.get_visible():
|
||||
self.window.close()
|
||||
return
|
||||
self.build_window()
|
||||
self.window.present()
|
||||
GLib.timeout_add(POLL_MS, self.refresh)
|
||||
|
||||
def build_window(self) -> None:
|
||||
window = Gtk.ApplicationWindow(application=self)
|
||||
window.set_title("Lecture en cours")
|
||||
window.set_default_size(460, 214)
|
||||
window.set_decorated(False)
|
||||
window.set_resizable(False)
|
||||
|
||||
if not self.css_loaded:
|
||||
provider = Gtk.CssProvider()
|
||||
provider.load_from_string(CSS)
|
||||
Gtk.StyleContext.add_provider_for_display(
|
||||
window.get_display(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
||||
)
|
||||
self.css_loaded = True
|
||||
|
||||
outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
|
||||
outer.set_margin_top(10)
|
||||
outer.set_margin_bottom(12)
|
||||
outer.set_margin_start(16)
|
||||
outer.set_margin_end(16)
|
||||
window.set_child(outer)
|
||||
|
||||
# La croix est en haut à droite, comme sur n'importe quelle fenêtre :
|
||||
# c'est le premier réflexe pour fermer, et sans elle un panneau sans
|
||||
# bordure (donc sans bouton du compositeur) semble impossible à fermer.
|
||||
header = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
|
||||
outer.append(header)
|
||||
|
||||
close_button = Gtk.Button(label="\U000f0156")
|
||||
close_button.add_css_class("close")
|
||||
close_button.set_tooltip_text("Fermer (Échap)")
|
||||
close_button.set_halign(Gtk.Align.END)
|
||||
close_button.set_hexpand(True)
|
||||
close_button.connect("clicked", lambda _button: window.close())
|
||||
header.append(close_button)
|
||||
|
||||
top = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=14)
|
||||
outer.append(top)
|
||||
|
||||
self.cover = Gtk.Picture()
|
||||
self.cover.set_size_request(88, 88)
|
||||
self.cover.set_content_fit(Gtk.ContentFit.COVER)
|
||||
cover_frame = Gtk.Box()
|
||||
cover_frame.add_css_class("cover")
|
||||
# Le cadre arrondi doit rogner la pochette, sinon l'angle droit de
|
||||
# l'image déborde des coins de la bordure.
|
||||
cover_frame.set_overflow(Gtk.Overflow.HIDDEN)
|
||||
cover_frame.append(self.cover)
|
||||
top.append(cover_frame)
|
||||
|
||||
info = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=4)
|
||||
info.set_valign(Gtk.Align.CENTER)
|
||||
info.set_hexpand(True)
|
||||
top.append(info)
|
||||
|
||||
self.title_label = Gtk.Label(xalign=0)
|
||||
self.title_label.add_css_class("title")
|
||||
self.title_label.set_ellipsize(Pango.EllipsizeMode.END)
|
||||
self.title_label.set_max_width_chars(34)
|
||||
info.append(self.title_label)
|
||||
|
||||
self.artist_label = Gtk.Label(xalign=0)
|
||||
self.artist_label.add_css_class("subtitle")
|
||||
self.artist_label.set_ellipsize(Pango.EllipsizeMode.END)
|
||||
info.append(self.artist_label)
|
||||
|
||||
self.album_label = Gtk.Label(xalign=0)
|
||||
self.album_label.add_css_class("album")
|
||||
self.album_label.set_ellipsize(Pango.EllipsizeMode.END)
|
||||
info.append(self.album_label)
|
||||
|
||||
self.player_label = Gtk.Label(xalign=0)
|
||||
self.player_label.add_css_class("hint")
|
||||
self.player_label.set_ellipsize(Pango.EllipsizeMode.END)
|
||||
info.append(self.player_label)
|
||||
|
||||
progress = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
|
||||
outer.append(progress)
|
||||
|
||||
self.elapsed_label = Gtk.Label(label="0:00")
|
||||
self.elapsed_label.add_css_class("time")
|
||||
progress.append(self.elapsed_label)
|
||||
|
||||
self.scale = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 0, 1, 1)
|
||||
self.scale.set_draw_value(False)
|
||||
self.scale.set_hexpand(True)
|
||||
self.scale.set_sensitive(False)
|
||||
progress.append(self.scale)
|
||||
|
||||
self.total_label = Gtk.Label(label="0:00")
|
||||
self.total_label.add_css_class("time")
|
||||
progress.append(self.total_label)
|
||||
|
||||
# Le glissement est suivi par un geste et non par la valeur du widget :
|
||||
# `change-value` se déclencherait à chaque pixel de déplacement, ce qui
|
||||
# enverrait des dizaines de seeks au lecteur. On déplace donc la barre
|
||||
# librement et on ne cherche la position qu'au relâchement.
|
||||
drag = Gtk.GestureDrag()
|
||||
drag.connect("drag-begin", self.on_drag_begin)
|
||||
drag.connect("drag-end", self.on_drag_end)
|
||||
self.scale.add_controller(drag)
|
||||
|
||||
controls = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
|
||||
controls.set_halign(Gtk.Align.CENTER)
|
||||
outer.append(controls)
|
||||
|
||||
self.prev_button = self.control_button(controls, "", "Piste précédente", self.previous)
|
||||
self.restart_button = self.control_button(controls, "", "Revenir au début", self.restart)
|
||||
self.play_button = self.control_button(controls, "", "Lecture / pause", self.toggle, accent=True)
|
||||
self.next_button = self.control_button(controls, "", "Piste suivante", self.next)
|
||||
|
||||
keys = Gtk.EventControllerKey()
|
||||
keys.connect("key-pressed", self.on_key)
|
||||
window.add_controller(keys)
|
||||
|
||||
# Fermer automatiquement quand la fenêtre perd le focus serait tentant,
|
||||
# mais Hyprland est configuré ici en focus glissant (follow_mouse = 1) :
|
||||
# en ouvrant le panneau depuis la barre, le curseur reste hors de la
|
||||
# fenêtre, qui est dé-focalisée aussitôt et se fermerait avant d'avoir
|
||||
# été vue. On laisse donc fermer explicitement (croix, Échap, ou un
|
||||
# nouveau clic sur la barre, qui bascule).
|
||||
self.window = window
|
||||
|
||||
def control_button(self, box: Gtk.Box, icon: str, tooltip: str, callback, accent: bool = False) -> Gtk.Button:
|
||||
button = Gtk.Button(label=icon)
|
||||
button.set_tooltip_text(tooltip)
|
||||
if accent:
|
||||
button.add_css_class("accent")
|
||||
button.connect("clicked", lambda _button: callback())
|
||||
box.append(button)
|
||||
return button
|
||||
|
||||
# ------------------------------------------------------------------ état
|
||||
|
||||
def on_key(self, _controller, keyval, _code, _state) -> bool:
|
||||
if keyval == Gio.KEY_Escape:
|
||||
self.close()
|
||||
return True
|
||||
if keyval == Gio.KEY_space:
|
||||
self.toggle()
|
||||
return True
|
||||
if keyval == Gio.KEY_Left:
|
||||
playerctl("position", f"{SEEK_STEP_S}-")
|
||||
self.after_seek()
|
||||
return True
|
||||
if keyval == Gio.KEY_Right:
|
||||
playerctl("position", f"{SEEK_STEP_S}+")
|
||||
self.after_seek()
|
||||
return True
|
||||
return False
|
||||
|
||||
def on_drag_begin(self, _gesture, _x, _y) -> None:
|
||||
self.dragging = True
|
||||
|
||||
def on_drag_end(self, _gesture, _x, _y) -> None:
|
||||
self.dragging = False
|
||||
self.seek(self.scale.get_value())
|
||||
|
||||
def after_seek(self) -> None:
|
||||
self.last_seek = time.monotonic()
|
||||
|
||||
def seek(self, seconds: float) -> None:
|
||||
playerctl("position", f"{max(0, seconds):.0f}")
|
||||
self.after_seek()
|
||||
|
||||
def toggle(self) -> None:
|
||||
playerctl("play-pause")
|
||||
|
||||
def next(self) -> None:
|
||||
playerctl("next")
|
||||
|
||||
def previous(self) -> None:
|
||||
playerctl("previous")
|
||||
|
||||
def restart(self) -> None:
|
||||
self.seek(0)
|
||||
|
||||
def close(self) -> None:
|
||||
if self.window is not None:
|
||||
self.window.close()
|
||||
|
||||
# ------------------------------------------------------------- rafraîchir
|
||||
|
||||
def refresh(self) -> bool:
|
||||
status = playerctl("status")
|
||||
playing = status == "Playing"
|
||||
|
||||
title = metadata("xesam:title")
|
||||
if title is None:
|
||||
self.show_idle()
|
||||
return GLib.SOURCE_CONTINUE
|
||||
|
||||
self.title_label.set_text(title)
|
||||
self.artist_label.set_text(metadata("xesam:artist") or "Artiste inconnu")
|
||||
self.album_label.set_text(metadata("xesam:album") or "")
|
||||
self.player_label.set_text(status or "")
|
||||
self.play_button.set_label("" if playing else "")
|
||||
|
||||
for widget in (self.prev_button, self.restart_button, self.play_button,
|
||||
self.next_button, self.scale):
|
||||
widget.set_sensitive(True)
|
||||
self.total_label.set_text(format_time(length() or 0))
|
||||
self.scale.get_adjustment().set_upper(max(1.0, length() or 1.0))
|
||||
|
||||
track = metadata("mpris:trackid")
|
||||
if track != self.track_id:
|
||||
self.track_id = track
|
||||
self.update_cover()
|
||||
|
||||
# Pochette distante pas encore en cache : le helper la télécharge, on
|
||||
# la pose dès qu'elle apparaît au lieu de bloquer l'interface.
|
||||
if self.pending_art is not None and os.path.exists(cache_path(self.pending_art)):
|
||||
self.set_cover(cache_path(self.pending_art))
|
||||
self.pending_art = None
|
||||
|
||||
current = position()
|
||||
if current is not None and not self.dragging:
|
||||
# Après un seek, le lecteur annonce encore l'ancienne position :
|
||||
# on garde la valeur demandée le temps qu'il se recale.
|
||||
if time.monotonic() - self.last_seek > SEEK_GRACE_S:
|
||||
self.scale.set_value(current)
|
||||
self.elapsed_label.set_text(format_time(current))
|
||||
else:
|
||||
self.elapsed_label.set_text(format_time(self.scale.get_value()))
|
||||
return GLib.SOURCE_CONTINUE
|
||||
|
||||
def show_idle(self) -> None:
|
||||
self.title_label.set_text("Aucun lecteur")
|
||||
self.artist_label.set_text("Lance une musique pour la piloter ici")
|
||||
self.album_label.set_text("")
|
||||
self.player_label.set_text("")
|
||||
self.total_label.set_text("0:00")
|
||||
self.elapsed_label.set_text("0:00")
|
||||
self.scale.set_value(0)
|
||||
self.track_id = None
|
||||
self.pending_art = None
|
||||
self.update_cover()
|
||||
for widget in (self.prev_button, self.restart_button, self.play_button,
|
||||
self.next_button, self.scale):
|
||||
widget.set_sensitive(False)
|
||||
|
||||
def update_cover(self) -> None:
|
||||
url = metadata("mpris:artUrl")
|
||||
path, pending = cover_for(url)
|
||||
if not pending:
|
||||
self.pending_art = None
|
||||
elif url is not None and self.pending_art != url:
|
||||
self.pending_art = url
|
||||
start_download()
|
||||
self.set_cover(path)
|
||||
|
||||
def set_cover(self, path: str | None) -> None:
|
||||
if path is None or not os.path.exists(path):
|
||||
self.cover.set_paintable(None)
|
||||
return
|
||||
try:
|
||||
self.cover.set_filename(path)
|
||||
except GLib.Error:
|
||||
self.cover.set_paintable(None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(MediaPanel().run([]))
|
||||
+17
-1
@@ -76,6 +76,7 @@ tooltip label { color: #fafafa; }
|
||||
#cpu,
|
||||
#memory,
|
||||
#battery,
|
||||
#mpris,
|
||||
#tray {
|
||||
background: #1f1a2e;
|
||||
padding: 0 12px;
|
||||
@@ -116,4 +117,19 @@ tooltip label { color: #fafafa; }
|
||||
|
||||
#battery.warning { color: #c3b6f6; }
|
||||
#battery.critical { color: #f569ca; }
|
||||
#battery.charging { color: #8cebd4; }
|
||||
#battery.charging { color: #8cebd4; }
|
||||
|
||||
/* --- Lecture en cours : pochette + piste ------------------------------------ */
|
||||
/* La pochette vient du module « image » (script media-cover), le texte du
|
||||
module « mpris » ; les deux forment une seule pilule à l'écran. */
|
||||
#image {
|
||||
background: #1f1a2e;
|
||||
padding: 0 6px;
|
||||
margin: 5px 3px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
#mpris:hover,
|
||||
#image:hover { background: #3a3350; }
|
||||
|
||||
#mpris.paused { color: #9a8cd8; }
|
||||
Reference in new issue
Block a user