Skip to content

Instantly share code, notes, and snippets.

@numpad0
Created July 7, 2020 13:50
Show Gist options
  • Save numpad0/5e70ab13cfb1322aa7ae5004fd3a5e13 to your computer and use it in GitHub Desktop.
Save numpad0/5e70ab13cfb1322aa7ae5004fd3a5e13 to your computer and use it in GitHub Desktop.

Revisions

  1. numpad0 created this gist Jul 7, 2020.
    105 changes: 105 additions & 0 deletions WSL2 + X410 + PulseAudio備忘録.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    # WSL2 + X410 + PulseAudio備忘録

    ## 目的
    Windows 10上のWSL2でFirefox開いてYouTube見られるくらいまで持ってく。

    ## 免責
    早くも記憶が薄れているので……

    ## 既知の問題点
    - Windowsを起動するごとに言語設定に`US`キーボードが勝手に入る
    - X410が英語ロケールでビルドされてるとか何かそんなん
    - XプロトコルとPulseAudioの着信全部受けるのでIPが届くと軽くヤバい
    - X410: localhostからの接続に限定する(オン・オフ)しか選べない
    - PulseAudio: 172.24.0.0/12とかに絞れると思う

    ## ネタ元ハイパーリンク

    - https://x410.dev/cookbook/wsl/enabling-sound-in-wsl-ubuntu-let-it-sing/
    - https://discourse.ubuntu.com/t/getting-sound-to-work-on-wsl2/11869
    - https://gist.github.com/ThYpHo0n/349f1f6473e207b866f65aca4728da3e
    - https://kazblog.hateblo.jp/entry/2018/05/28/221242
    - https://superuser.com/questions/198525/how-can-i-execute-a-windows-command-line-in-background

    ## prereq
    1. X410: Microsoft Storeで買う。常態的に二重価格販売されている。フリーのVcXsrvでも変わらない気もする……
    1. PulseAudio: https://www.freedesktop.org/wiki/Software/PulseAudio/Ports/Windows/Support/

    ## X410
    1. Storeから入れる
    1. スタートアップにショートカットを作成
    1. Win+Rを押して `shell:AppsFolder` [OK]
    1. Win+Rを押して `shell:startup` [OK]
    1. Applications から Startup へ右ドラッグ
    1. X410を設定
    1. トレイアイコン → ✔ Allow Public Access
    1. (任意) トレイアイコン → ✔ Windowed Apps
    1. ファイアウォール警告が出たら許可する

    1. WSL側作業
    - ~/.bashrc に以下を追加
    ```
    # Windows XSrv config
    export $(dbus-launch)
    export LIBGL_ALWAYS_INDIRECT=1
    export WSL_VERSION=$(wsl.exe -l -v | grep -a '[*]' | sed 's/[^0-9]*//g')
    export WSL_HOST=$(tail -1 /etc/resolv.conf | cut -d' ' -f2)
    export DISPLAY=$WSL_HOST:0
    # fcitx
    export GTK_IM_MODULE=fcitx
    export QT_IM_MODULE=fcitx
    export XMODIFIERS=@im=fcitx
    # pulseaudio
    export PULSE_SERVER=tcp:$WSL_HOST;
    ```
    ## PulseAudio
    1. PulseAudio: `C:\PULSE~1`とか適当に展開する
    1. `PULSE~1\etc\pulse\default.pa` をに追記
    - 行41: `load-module module-waveout sink_name=output source_name=input`
    - 行61: `load-module module-native-protocol-tcp auth-anonymous=1`
    - \* 録音無効にしなくても大丈夫ぽい
    1. `PULSE~1\etc\pulse\daemon.conf` に追記
    - 末尾: `exit-idle-time = -1`
    - \* 接続待ちタイムアウトの無効化
    1. `PULSE~1\pulseaudio.vbs` を以下で新規作成
    ```
    Dim WinScriptHost
    Set WinScriptHost = CreateObject("WScript.Shell")
    WinScriptHost.Run Chr(34) & "C:\PULSE~1\bin\pulseaudio.exe" & Chr(34), 0
    Set WinScriptHost = Nothing
    ```
    VBSからWSH経由で叩くとウィンドウが出ない理由は謎。
    1. `PULSE~1\pulseaudio.vbs`へのショートカットをStartupフォルダに投げ込む
    1. WSL側作業
    - `$ apt install pulseaudio`
    - ~/.bashrc に以下を追記 (*X410の項で追記済)
    ```
    # export WSL_HOST=$(tail -1 /etc/resolv.conf | cut -d' ' -f2)
    export PULSE_SERVER=tcp:$WSL_HOST;
    ```
    ## fcitx
    あかん忘れてもうた。
    1. $ sudo apt install fcitx fcitx-mozc
    1. $ fcitx-configtool
    - Global Config - Trigger Input Method - Ctrl+Space を確認
    1. ~/.bashrc に以下を追記 (*X410の項で追記済)
    ```
    export GTK_IM_MODULE=fcitx
    export QT_IM_MODULE=fcitx
    export XMODIFIERS=@im=fcitx
    ```
    1. 使用時に必要に応じて: `$ fcitx-autostart`
    1. 使用時に必要に応じて: Ctrl+Space
    ## firefox
    1. `$ sudo apt install firefox `
    1. `$ firefox youtube.com`