Wacomグラフィックタブレットが(USB経由で)接続されたらすぐに構成スクリプトを実行するにはどうすればよいですか?

AFoeee

Ubuntu 18.04(カーネル :)でWacomグラフィックタブレットを使用してい4.15.0-72-genericます。

残念ながら、正しく認識されないため、システム設定を使用して構成することはできません。

経由の構成はxsetwacom機能しますが、永続的ではありません。コンピュータを再起動するか、デバイスを再接続するとすぐに、デフォルト設定がロードされます。


最も簡単な解決策は、タブレットがUSBデバイスとして認識されたらすぐに構成スクリプトを実行することだと思いました。

私の理解によれば、これを達成するには2つのステップが必要です。

  1. udevルールを作成する

    /etc/udev/rules.d/99-config_wacom_intuos.rulesの内容のファイル作成しました

    # "idVendor" and "idProduct" were derived from the output of the lsusb command.
    ACTION=="add" \
    , SUBSYSTEM=="input" \
    , KERNEL=="mouse*" \
    , ATTRS{idVendor}=="1234" \
    , ATTRS{idProduct}=="5678" \
    , RUN+="/bin/sh -c '/usr/local/bin/config_wacom_intuos.sh >> /var/log/custom_logs/config_wacom_intuos.log 2>&1'"
    

    このファイルには次の権限があります。

    -rw-r--r-- 1 root root    ...
    

    (辞書/var/log/custom_logsも私が作成しました。)

  2. 構成スクリプトを作成する

    /usr/local/bin/config_wacom_intuos.shの内容のファイル作成しました

    #!/bin/bash
    #coding:utf8
    
    # These were the missing statements as suggested by the answer.
    #export DISPLAY=:1
    #export XAUTHORITY=/run/user/1000/gdm/Xauthority
    
    echo "`date '+%Y-%m-%dT%H:%M:%S'`, ShellPID $$, start"
    
    sleep 1
    
    if xsetwacom --list devices | grep -q "Wacom Intuos BT"
    then
        main_screen="HEAD-0"
        bezier_args="0 20 80 100"
        positioning_mode="Absolute"
        raw_sample_lvl="9"
        suppress_lvl="10"
    
        # Maps the graphics tablet to the area of a specified screen (for multiple-screen environments).
        xsetwacom set "Wacom Intuos BT S Pen stylus" MapToOutput "$main_screen"
        xsetwacom set "Wacom Intuos BT S Pen eraser" MapToOutput "$main_screen"
        xsetwacom set "Wacom Intuos BT S Pen cursor" MapToOutput "$main_screen"
    
        # Changes the pressure sensitivity.
        xsetwacom set "Wacom Intuos BT S Pen stylus" PressureCurve "$bezier_args"
        xsetwacom set "Wacom Intuos BT S Pen eraser" PressureCurve "$bezier_args"
    
        # Smoothes drawn lines by reducing any quivering.
        xsetwacom set "Wacom Intuos BT S Pen stylus" RawSample "$raw_sample_lvl"
        xsetwacom set "Wacom Intuos BT S Pen stylus" Suppress "$suppress_lvl"
        xsetwacom set "Wacom Intuos BT S Pen eraser" RawSample "$raw_sample_lvl"
        xsetwacom set "Wacom Intuos BT S Pen eraser" Suppress "$suppress_lvl"
        xsetwacom set "Wacom Intuos BT S Pen cursor" RawSample "$raw_sample_lvl"
        xsetwacom set "Wacom Intuos BT S Pen cursor" Suppress "$suppress_lvl"
    
        # Specifies the positioning mode ("Absolute" / "Relative")
        xsetwacom set "Wacom Intuos BT S Pen stylus" Mode "$positioning_mode"
        xsetwacom set "Wacom Intuos BT S Pen eraser" Mode "$positioning_mode"
        xsetwacom set "Wacom Intuos BT S Pen cursor" Mode "$positioning_mode"
    
        # Assigns actions to the tablet buttons.
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 1 "key +ctrl z -ctrl"
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 2 "key +ctrl +shift z -ctrl -shift"
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 3 "key 0xffab"
        xsetwacom set "Wacom Intuos BT S Pad pad" Button 8 "key 0xffad"
    
    else
        echo "NO 'WACOM INTUOS BT' DEVICES FOUND."
    fi
    
    echo "`date '+%Y-%m-%dT%H:%M:%S'`, ShellPID $$, end"
    echo -e "---\n"
    
    exit 0
    

    このファイルには次の権限があります。

    -rwxr-xr-x 1 root root    ...
    

ターミナルから手動で実行した場合、スクリプトは問題なく機能します。

デバイスを接続したときにも実行されます。残念ながら、これは効果がないようです。

また、デバイスを接続した後、スクリプトが連続して数回実行されます。
この動作は、十分に制限されていないudevルールが原因で発生すると思います。

誰かが私に何を間違っているのか教えてもらえますか?

ティムシューマッハ

Xサーバーツールは通常、現在のセッションにのみ影響します(そのため、毎回設定する必要があります)。

Xセッションに接続されていないシェルでそのスクリプトを実行しているため、ツールは、これらの設定をどのXセッションに変更する必要があるかを認識していません(より正確には、Xセッションを認識していません)。セッションも存在します)。

シェルを現在のXセッションに手動で接続できますが、解決策が少し壊れやすい場合があります。

あなたのスクリプトには2つの変数の輸出、のための1つを追加する必要がありますDISPLAYXAUTHORITYこれらは、正しいXセッションを識別してアクセスするために使用されます。env通常のユーザーとしてログインしているときに実行すると、適切な値を取得できます。

私の場合、出力は次のようになります(でマークされた部分[...]は省略されています)。

$ env
[...]
XAUTHORITY=/home/tim/.Xauthority
[...]
DISPLAY=:0.0
[...]

これらの値については、次の行でスクリプトを拡張する必要があります。

export DISPLAY=:0.0
export XAUTHORITY=/home/tim/.Xauthority

これで、rootユーザーでもスクリプトが機能するはずです。

udev構成自体は問題ないようです。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ