1. 程式人生 > >thinkpad,dell等 ubuntu18.04下 設定搖桿中鍵滾動方法

thinkpad,dell等 ubuntu18.04下 設定搖桿中鍵滾動方法

之前用的筆記本thinkpadt200安裝ubuntu後搖桿中鍵滾動就用不了,在網上找了寫資料,可以解決。後來新的筆記本是dell的precision3530安裝了ubuntu18.04 , 發現原來的設定方式不行了, 主要是ubuntu最新版使用了libinput 代替了evdev,其實也比較簡單,擔心以後忘記,就記錄下來。

主要用到的命令就2個, xinput 和libinput

1.先檢視一下搖桿的裝置名,執行: xinput list, 我的電腦是這樣的:

xinput list
⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                  id=4    [slave  pointer  (2)]
⎜   ↳ DELL0820:00 044E:121F Mouse                 id=12    [slave  pointer  (2)]
⎜   ↳ DELL0820:00 044E:121F Touchpad              id=13    [slave  pointer  (2)]
⎣ Virtual core keyboard                       id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard                 id=5    [slave  keyboard (3)]
    ↳ Power Button                                id=6    [slave  keyboard (3)]
    ↳ Video Bus                                   id=7    [slave  keyboard (3)]
    ↳ Video Bus                                   id=8    [slave  keyboard (3)]
    ↳ Power Button                                id=9    [slave  keyboard (3)]
    ↳ Sleep Button                                id=10    [slave  keyboard (3)]
    ↳ Integrated_Webcam_HD: Integrate             id=11    [slave  keyboard (3)]
    ↳ DELL0820:00 044E:121F UNKNOWN               id=14    [slave  keyboard (3)]
    ↳ DELL0820:00 044E:121F UNKNOWN               id=15    [slave  keyboard (3)]
    ↳ Intel HID events                            id=16    [slave  keyboard (3)]
    ↳ Intel HID 5 button array                    id=17    [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                            id=18    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard                id=19    [slave  keyboard (3)]
其中 Virtual core pointer 就是列出的指標裝置, 其中 DELL0820:00 044E:121F Mouse 就是搖桿, 不同的筆記本這個裝置命令一般不一樣,想要知道是那個通過禁用和啟用它來判斷,命令是 :

    xinput disable <device>
    xinput enable <device>

其中<device> 部分就是裝置名,通過先禁用它,然後操控一下搖桿,看是不是不管用了,來判斷。這裡可能有人會擔心禁用了沒法操作電腦了,這個大可不必擔心,實在不行重啟電腦就可以了, 這個禁用不是永久的。

2.既然確認了裝置名, 那麼就可以查詢裝置具有的屬性,還是以我的電腦為例,執行下面命令, 其中裝置名記得替換成自己的:

xinput list-props "DELL0820:00 044E:121F Mouse" 

輸出內容如下:

    Device Enabled (142):    1
    Coordinate Transformation Matrix (144):    1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    libinput Natural Scrolling Enabled (279):    0
    libinput Natural Scrolling Enabled Default (280):    0
    libinput Scroll Methods Available (281):    0, 0, 1
    libinput Scroll Method Enabled (282):    0, 0, 1
    libinput Scroll Method Enabled Default (283):    0, 0, 0
    libinput Button Scrolling Button (284):    2
    libinput Button Scrolling Button Default (285):    2
    libinput Middle Emulation Enabled (286):    0
    libinput Middle Emulation Enabled Default (287):    0
    libinput Accel Speed (288):    0.000000
    libinput Accel Speed Default (289):    0.000000
    libinput Accel Profiles Available (290):    1, 1
    libinput Accel Profile Enabled (291):    1, 0
    libinput Accel Profile Enabled Default (292):    1, 0
    libinput Left Handed Enabled (293):    0
    libinput Left Handed Enabled Default (294):    0
    libinput Send Events Modes Available (264):    1, 0
    libinput Send Events Mode Enabled (265):    0, 0
    libinput Send Events Mode Enabled Default (266):    0, 0
    Device Node (267):    "/dev/input/event11"
    Device Product ID (268):    1102, 4639
    libinput Drag Lock Buttons (295):    <no items>
    libinput Horizontal Scroll Enabled (296):    1
這個列出的內容每一行為一個屬性值,冒號分割屬性名和屬性的值, 具體到每個屬性名所代表的含義可以根據libinput的文件查詢的到。 終端中輸入:

man libinput

會輸出libinput的所有屬性的詳細介紹,這裡我就不多解釋了, 結合文件幫助,比較容易找到一些可能的修改選項, 經過嘗試,我的電腦通過修改 “libinput Scroll Method Enabled” 屬性的值可以啟動搖桿, libinput文件是這樣說明的:

libinput Middle Emulation Enabled
              1 boolean value (8 bit, 0 or 1). Indicates if middle emulation is enabled or disabled.

那麼通過命令修改屬性:

xinput set-prop "DELL0820:00 044E:121F Mouse" "libinput Middle Emulation Enabled" 0
這裡要注意一下,屬性名不要包含後面那個括號和裡面的數字。

執行命令後按住中鍵通過搖桿就可以上下左右滾動螢幕了。

為了每次開機都自動啟用,可以吧這個命令加到 /etc/profile 中當然需要root許可權訪問。也可以加到 ~/.profile,只是無法作用到其他使用者。