Skip to content

swayidleからresumeする際にewwを復元させる

Posted on:June 11, 2023 at 05:20 PM

Sway環境でメニューバーをwaybarからewwに乗り換えてみたんだけど、スリープから復帰する際にバーが表示されなくなることがしばしば。

exec_always --no-startup-id eww -c ~/.config/eww/bar open bar &

exec swayidle -w \
  timeout 600  'env LANG=en.US_UTF-8 swaylock -f' \
  timeout 1200 'swaymsg "output * dpms off"' \
  resume       'swaymsg "output * dpms on"' \
  before-sleep 'env LANG=en.US_UTF-8 swaylock -f'

Swayの設定はこんな感じにしていて、無操作時間が10分超えたらロック、20分超えたらディスプレイがオフになるようにswayidleを実行していた。

どうもこのresumeで復帰する際にはバーが消失していそうだったので調べてみたところ同じようなことで躓いている人がいて、このIssueでワークアラウンドが提示されていた。

Given that eww windows are basically just regular windows that set some specific properties, I don’t think this is actually an issue with eww itself, as I couldn’t see how eww would even know about the monitor sleeping. the only thing I could imagine would be that the monitor just disappears completely, and thus ewws window gets moved somewhere else by your compositor, and then obviously not moved back properly — which too would be a compositor issue

なるほど、たしかにそれはそうだなーという感じ。

早速Issueのワークアラウンドを参考に設定してみた。

exec_always --no-startup-id eww -c ~/.config/eww/bar open bar &

exec swayidle -w \
  timeout 600  'env LANG=en.US_UTF-8 swaylock -f' \
  timeout 1200 'swaymsg "output * dpms off"' \
  resume       'swaymsg "output * dpms on" && sleep 5 && eww -c ~/.config/eww/bar --restart open bar' \
  before-sleep 'env LANG=en.US_UTF-8 swaylock -f'

でもこれでもバーが復帰しなかったので、次のような設定でewwをあらかじめデーモンで起動するようにしたところ、無事にresumeでバーが復帰するようになった。

bar {
 swaybar_command eww -c ~/.config/eww/bar daemon
}

exec_always --no-startup-id eww -c ~/.config/eww/bar open bar &

exec swayidle -w \
  timeout 600  'env LANG=en.US_UTF-8 swaylock -f' \
  timeout 1200 'swaymsg "output * dpms off"' \
  resume       'swaymsg "output * dpms on" && sleep 5 && eww -c ~/.config/eww/bar --restart open bar' \
  before-sleep 'env LANG=en.US_UTF-8 swaylock -f'

これで復帰後にバーを手動起動する必要がなくなった。