summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-06-05 11:46:17 +0530
committersinanmohd <sinan@sinanmohd.com>2024-06-05 12:51:26 +0530
commit1368cff428c3eb2112afeb53f4756bfdddaff363 (patch)
tree85e1a933e8c7750348e8f31448c25155ae41777a /home
parente038eb08741a003dde903ffc5c12fa40cfcf1bf4 (diff)
home/wayland/sway: add support for wallpapers
Diffstat (limited to 'home')
-rw-r--r--home/wayland/modules/sway/home.nix9
-rw-r--r--home/wayland/modules/sway/swaylock.nix5
-rw-r--r--home/wayland/pkgs/wayland-scripts/default.nix46
-rwxr-xr-xhome/wayland/pkgs/wayland-scripts/src/bin/cwall106
4 files changed, 165 insertions, 1 deletions
diff --git a/home/wayland/modules/sway/home.nix b/home/wayland/modules/sway/home.nix
index 3565cf8..dd0a275 100644
--- a/home/wayland/modules/sway/home.nix
+++ b/home/wayland/modules/sway/home.nix
@@ -5,6 +5,10 @@
down = "j";
up = "k";
+ background = "${config.xdg.dataHome}/wayland/desktop";
+ wayland-scripts = pkgs.callPackage ../../pkgs/wayland-scripts {};
+ cwall = "${wayland-scripts}/bin/cwall";
+
menu = "${pkgs.bemenu}/bin/bemenu-run --prompt ' '";
foot = lib.getExe config.programs.foot.package;
i3status = lib.getExe config.programs.i3status.package;
@@ -29,11 +33,14 @@ in {
pkgs.bemenu
pkgs.swayidle
pkgs.brightnessctl
+ wayland-scripts
];
wayland.windowManager.sway = {
enable = true;
config = null;
+ # checkConfig fails if ${background} doesn't exist
+ checkConfig = false;
settings = {
bar = {
@@ -51,6 +58,7 @@ in {
"swipe:left" = "workspace next";
"swipe:right" = "workspace prev";
"swipe:down" = "exec ${swaylock}";
+ "swipe:up" = "exec ${cwall}";
};
input = {
"type:touchpad" = {
@@ -142,6 +150,7 @@ in {
default_border.pixel = 2;
floating_modifier = "${mod} normal";
"client.focused" = "#4c7899 #285577 #ffffff #285577";
+ output."*".background = "${background} fill";
};
};
}
diff --git a/home/wayland/modules/sway/swaylock.nix b/home/wayland/modules/sway/swaylock.nix
index dbac0db..1d5a58f 100644
--- a/home/wayland/modules/sway/swaylock.nix
+++ b/home/wayland/modules/sway/swaylock.nix
@@ -1,4 +1,6 @@
-{ pkgs, ... }: {
+{ config, pkgs, ... }: let
+ background = "${config.xdg.dataHome}/wayland/lockscreen";
+in {
programs.swaylock = {
enable = true;
package = pkgs.swaylock-effects;
@@ -9,6 +11,7 @@
color = "404040";
timestr = "%H:%M";
datestr = "%a,%e %b";
+ image = background;
indicator-idle-visible = true;
};
};
diff --git a/home/wayland/pkgs/wayland-scripts/default.nix b/home/wayland/pkgs/wayland-scripts/default.nix
new file mode 100644
index 0000000..bded5e7
--- /dev/null
+++ b/home/wayland/pkgs/wayland-scripts/default.nix
@@ -0,0 +1,46 @@
+{
+ stdenvNoCC,
+ lib,
+ makeWrapper,
+
+ bash,
+ sway,
+ ffmpeg,
+ libnotify,
+}:
+
+stdenvNoCC.mkDerivation {
+ pname = "wayland-scipts";
+ version = "1717572072";
+ src = ./src;
+
+ strictDeps = true;
+ outputs = [ "out" ];
+ buildInputs = [ bash ];
+ nativeBuildInputs = [ makeWrapper ];
+
+ postPatch = ''
+ for sh in bin/*; do
+ patchShebangs --host "$sh"
+ done
+ '';
+
+ installPhase = ''
+ runHook preInstall
+ cp -r ./ $out
+ runHook postInstall
+ '';
+
+ postInstall = ''
+ wrapProgram $out/bin/cwall \
+ --prefix PATH : ${lib.makeBinPath [ ffmpeg libnotify sway ]}
+ '';
+
+ meta = {
+ description = "Wayland scripts for sway";
+ homepage = "https://www.sinanmohd.com";
+ license = lib.licenses.gpl3;
+ platforms = lib.platforms.unix;
+ maintainers = with lib.maintainers; [ sinanmohd ];
+ };
+}
diff --git a/home/wayland/pkgs/wayland-scripts/src/bin/cwall b/home/wayland/pkgs/wayland-scripts/src/bin/cwall
new file mode 100755
index 0000000..6268390
--- /dev/null
+++ b/home/wayland/pkgs/wayland-scripts/src/bin/cwall
@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+
+bgroot="$XDG_DATA_HOME/wayland"
+bgdesk="$bgroot/desktop"
+bglock="$bgroot/lockscreen"
+walldir="$HOME/pix/wall"
+
+die()
+{
+ command -v notify-send > /dev/null &&
+ notify-send " cwall" "$1"
+
+ printf "\033[31;1merr: %b\033[0m\n" "$1" 1>&2
+ exit "${2:-1}"
+}
+
+usage()
+{
+ echo 'Usage: cwall [wallpaper.img|directory]'
+}
+
+mimetype()
+{
+ file --brief --dereference --mime-type "$1"
+}
+
+randimg()
+{
+ # usage: randbg dir
+ : "${1:?}"
+ maxattempts=10
+ attempt=0
+
+ img=
+ while :; do
+ img="$(find "$1" \
+ -iname "*.avif" \
+ -o -iname "*.heic" \
+ -o -iname "*.heif" \
+ -o -iname "*.jpeg" \
+ -o -iname "*.jpg" \
+ -o -iname "*.jxl" \
+ -o -iname "*.png" \
+ -o -iname "*.webp" | shuf -n1)"
+
+ [ -z "$img" ] &&
+ return 1
+
+ # make sure the file is an actual image
+ case "$(mimetype "$img")" in
+ "image/"*)
+ echo "$img"
+ break
+ ;;
+ *)
+ attempt=$((attempt + 1))
+ [ "$attempt" -gt "$maxattempts" ] &&
+ return 1
+ esac
+ done
+}
+
+updatewall()
+{
+ : "${1:?}"
+
+ rm -f "$bgdesk" "$bglock"
+ cp "$1" "$bgdesk"
+ swaymsg "output * background '${bgdesk}' fill"
+ ffmpeg -loglevel quiet -i "$bgdesk" -vf "boxblur=50" -f mjpeg "$bglock"
+}
+
+########
+# MAIN #
+########
+
+if [ "$#" -eq 0 ]; then
+ input="$walldir"
+elif [ "$1" = "-h" ]; then
+ usage && exit 0
+else
+ input="$1"
+fi
+
+if [ ! -r "$input" ]; then
+ die "can't read $input"
+fi
+if [ ! -d "$bgroot" ]; then
+ mkdir -p "$bgroot"
+fi
+
+case "$(mimetype "$input")" in
+"image/"*)
+ updatewall "$input"
+ ;;
+"inode/directory")
+ if ! img=$(randimg "$input"); then
+ die "no image file in $input"
+ fi
+
+ updatewall "$img"
+ ;;
+*)
+ die "invalid input $input"
+ ;;
+esac