Integrate Pywal Colors into Selected-Window-Accent-Mode for Wallpaper Accent Matching in Emacs

I have updated my emacs package selected-window-accent-mode

The Selected Window Accent Mode is an Emacs package designed to visually distinguish the currently selected window by applying a unique accent color to its fringes, mode line, header line, and margins.

v0.9.0 <2024-08-10 Sat>

Added Pywal color integration to selected-window-accent-mode to allow the accent color to be consistent with the wallpaper of the operating system.

Pywal is a tool on linux that generates color schemes from images, allowing users to apply these colors to their desktop and application themes for a cohesive and dynamic look.

Note: will only work on linux.

Example use:

(setq selected-window-accent-use-pywal t)

When enabled, color1 is selected as the accent color, taken from the file : ~/.cache/wal/colors.json which is a generic color file typically generated by pywal.

This means that the accent color can be more tied in with the current wallpaper once pywal is connected to the wallpaper change mechanism of your operating system.

Note that this feature will require an external pywal generation step, triggered on wallpaper change, examples given below.

See below for an example colors.json file

Technically any tool that can write to a json file in a similar format will have a carry through affect on the accent color associated with this package. Here is an example :

{
    "wallpaper": "/home/jdyer/.last_wallpaper.jpg",
    "alpha": "100",

    "special": {
        "background": "#0d1a05",
        "foreground": "#c8cfdb",
        "cursor": "#c8cfdb"
    },
    "colors": {
        "color0": "#0d1a05",
        "color1": "#8FA944",
        "color2": "#165E97",
        "color3": "#5C7391",
        "color4": "#748AA6",
        "color5": "#7498C4",
        "color6": "#8D9BB1",
        "color7": "#c8cfdb",
        "color8": "#8c9099",
        "color9": "#8FA944",
        "color10": "#165E97",
        "color11": "#5C7391",
        "color12": "#748AA6",
        "color13": "#7498C4",
        "color14": "#8D9BB1",
        "color15": "#c8cfdb"
    }
}

On linux, install python-pywal using your package manager of choice.

At which point you can generate a colors.json with the following commands:

wal -c
wal -i ~/.last_wallpaper.jpg -q -n

Wallpaper Change Example

Changing a wallpaper and hooking pywal up accordingly, which technically should work for both Wayland and X11.

#!/bin/bash

wallpaper_path="$(find ~/wallpaper-dir -type f | shuf -n 1)"
echo $wallpaper_path > ~/.last_wallpaper_path
cp -f $wallpaper_path ~/.last_wallpaper.jpg

if [[ $XDG_SESSION_TYPE == "x11" ]]; then
   feh --bg-scale "$wallpaper_path"
fi

if [[ $XDG_SESSION_TYPE == "wayland" ]]; then
   swww img "$wallpaper_path" --transition-step 20 --transition-fps=20
fi

# lets run pywal for colour scheme generation
wal -c
wal -i ~/.last_wallpaper.jpg -q -n

Comments

comments powered by Disqus