LoginSignup
4
1

More than 5 years have passed since last update.

タイル型 wm で背景を n 秒ごとに変えてみた⁽⁽٩( ˘ω˘)۶⁾⁾

Posted at

こういう方へ

  • i3, xmonad 等のタイル型ウィンドウマネージャを使ってる方
  • 背景を周期的に変更したい方

どうやるの?

feh を使いますので, これをインストールしてください.

  • ArchLinux : sudo pacman -S feh
  • GentooLinux : sudo emerge --ask media-gfx/feh
  • Ubuntu, Debian 等の他の LinuxDistro, CentOS : ソースからビルドしてください.

つづいて, 以下のシェルスクリプトを適当なディレクトリに配置してください.

update-wallpaper.sh
#!/bin/sh
if [ $$ != $(pgrep -fo $(basename $0)) ]; then
    exit 0
fi

interval=30 # ここに描画周期
imgPath=/usr/share/backgrounds/ # ここに背景画像のディレクトリ名
imgs=(`find $imgPath -type f -regextype sed -regex ".*\.\(png\|jpg\)"`)
len=${#imgs[@]}

while true
do
    rand=$(($RANDOM % $len))
    feh --bg-fill ${imgs[$rand]}
    sleep $interval
done

あとは, このファイルの実行を許可して, スタートアッププログラム(wm 起動時に呼ばれるスクリプト)に登録するだけです.

$ sudo chmod +x /path/to/update-wallpaper.sh

i3 の場合

exec_always /path/to/update-wallpaper.sh を ~/.config/i3/config 等のコンフィグファイルに追加してください.

# some other configs
exec_always /path/to/update-wallpaper.sh

xmonad の場合

xmonad.hs 等の xmonad コンフィグファイルで用いる XConfig のコンストラクタの startupHook に, spawn "/bin/sh /path/to/update-wallpaper.sh" を追加してください. 以下は一例です.

xmonad.hs
myConfig = desktopConfig {
   -- some other constructors
   startupHook = do
     -- some other startup hooks
     spawn "/bin/sh /path/to/update-wallpaper.sh"
}

その他のタイル型ウィンドウマネージャ

ごめんなさい, きりがないので省略させてください(´・ω・`)
大抵ウィンドウマネージャのホームページに書いてあったりするので, そちらを参照してください.

注意

あまり無いとは思いますが, 複数の X Server を起動して作業を行う際には, 片方でしか動作しません.

また雑に実装した結果, 連続で同じ背景が描画されることがあるコードになってしまいました. 私はあまり気にならないんですが, これが嫌だという方は, それほど難しくはないと思うのでご自分で実装してみるのもいいと思います.

背景の画像を大量に用意しておけば, かぶる確率も下がるんじゃないでしょうかね(適当)

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1