»
S
I
D
E
B
A
R
«
The good old xorg.conf and the new xorg.conf.d
Apr 8th, 2010 by kanru

自從 Xorg xserver 宣佈要放棄使用 hal 的自動設定機制後,Xorg 開發者們就開始討論與實做各種可能的 config backend。最後定案的是在 Linux 上直接使用 udev 來偵測 input device,在這個後端實做的早期也想把設定的工作一起做在 udev rules 裡,但顯然這樣的做法是有其侷限的。很多人說這只是把 hal 的 .fdi 換個寫法放到 udev rules 裡罷了,同樣是對 user 極不友善的做法,而且使用 udev 在非 Linux 的平台就不能用了。

最後一個很聰明的辦法是把 auto probe 與 config 這兩個行為分開,讓 udev 只管找到新的裝置,config 則集中放在 xorg.conf.d 中。xorg.conf.d 中設定檔的格式和 xorg.conf 是一樣的,因此不但 code 可以重用,使用者也不用學新的語法,其他平台則可以用不同的 backend。

因為 udev backend 是以 Debian Developer – Julien Cristau 為主開發的, Debian 很早就可以使用 udev backend 了,最近 Debian 更從 xorg-xserver 1.8 backport 了 xorg.conf.d 的修改,所以設定方式又不太一樣了。(大概只有 Debian 是這樣一改再改吧,其他 distro 應是無痛升級)

參考 xorg.conf(5),X 在啟動時會去找

           /etc/X11/<cmdline>
           /usr/etc/X11/<cmdline>
           /etc/X11/$XORGCONFIG
           /usr/etc/X11/$XORGCONFIG
           /etc/X11/xorg.conf-4
           /etc/X11/xorg.conf
           /etc/xorg.conf
           /usr/etc/X11/xorg.conf.<hostname>
           /usr/etc/X11/xorg.conf-4
           /usr/etc/X11/xorg.conf
           /usr/lib/X11/xorg.conf.<hostname>
           /usr/lib/X11/xorg.conf-4
           /usr/lib/X11/xorg.conf

這些地方的設定檔,因此設定不用全放在一個檔案裡了。這也是近來很多 daemon 要支援多重設定檔常用的方法,可以讓 vendor 或 distro 的設定與 user 的設定可以各自獨立出來。

接下來我們有興趣的地方是 InputClass 這個新的 Section,就是它讓我們可以設定隨插即用裝置。

           Section "InputClass"
               Identifier  "name"
               entries
               ...
               options
               ...
           EndSection

就像 xorg.conf 內其他 Section 一樣,Identifier 是必需的,我們可以用各種 Match rule 去比對裝置的特性並用 Option 加以設定。所有的 InputClass 都可以被其之後的 InputClass 取代,因此使用者可以用新設定檔取代系統的設定。

現在可以用的 Match rule 有

MatchProduct        "matchproduct"
MatchVendor         "matchvendor"
MatchDevicePath     "matchdevice"
MatchTag            "matchtag"
MatchIsKeyboard     "bool"
MatchIsPointer      "bool"
MatchIsJoystick     "bool"
MatchIsTablet       "bool"
MatchIsTouchpad     "bool"
MatchIsTouchscreen  "bool"

前四個可以用來 match 特定的裝置名稱、路徑,其他的則可以用來 match 一般的裝置特性如滑鼠、鍵盤等。如我要設定 touchpad 的話,可以用

# /etc/X11/xorg.conf.d/10-synaptics.conf
Section "InputClass"
    Identifier "Synaptics"
    MatchIsTouchpad "true"

    Option "TapButton1" "1"
    Option "HorizEdgeScroll" "true"
EndSection

來設定。再加上 X 會自己找到可以用的 driver,和以前方法比起來,是不是簡單很多呢? :)

Xorg 1.5 XInput Hotplug
Oct 4th, 2008 by kanru

之前寫過 Xorg 1.4 XInput Hotplug,提到 xorg, evdev 可以利用 hal 自動偵測硬體載入 driver 與設定參數,而即將 release 的 Xorg 1.5 又新增了一些可以在 hal policy 裡設定的參數:

  • input.x11_driver 可以設定這個 device 要使用的 driver,對應到 xorg.conf 的 Driver 選項
  • input.x11_options.

如今我的 /etc/hal/fdi/policy/10-x11-input.fdi 長這樣:

< ?xml version="1.0" encoding="ISO-8859-1"?>

  
      
          mouse
          
              evdev
          
      

<match key="info.capabilities" contains="input.keys">
    <merge key="input.x11_options.XkbRules" type="string">base</merge>
    <!-- If we're using Linux, we use evdev by default (falling back to
    keyboard otherwise). -->
    <merge key="input.x11_driver" type="string">keyboard</merge>
    <merge key="input.x11_options.XkbModel" type="string">pc105</merge>
    <match key="/org/freedesktop/Hal/devices/computer:system.kernel.name"
        string="Linux">
        <merge key="input.x11_driver" type="string">evdev</merge>
        <merge key="input.x11_options.XkbModel" type="string">evdev</merge>
    </match>
    <merge key="input.x11_options.XkbVariant" type="string" />
    <merge key="input.x11_options.XkbLayout" type="string">dvorak</merge>
    <merge key="input.x11_options.XkbOptions" type="string">ctrl:nocaps</merge>
</match>
<match key="info.capabilities" contains="input.touchpad">
    <merge key="input.x11_driver" type="string">synaptics</merge>
    <merge key="input.x11_options.Protocol" type="string">auto-dev</merge>
    <merge key="input.x11_options.SHMConfig" type="string">on</merge>
    <merge key="input.x11_options.LeftEdge" type="string">1100</merge>
    <merge key="input.x11_options.RightEdge" type="string">5800</merge>
    <merge key="input.x11_options.TopEdge" type="string">1600</merge>
    <merge key="input.x11_options.BottomEdge" type="string">4200</merge>
    <merge key="input.x11_options.HorizEdgeScroll" type="string">on</merge>
</match>

我的 /etc/X11/xorg.conf 只剩下必要的:

Section "Device"
    Identifier  "i915gm"
    Driver      "intel"
EndSection

Section "Screen" Identifier "Default Screen" Device "i915gm" DefaultDepth 24 SubSection "Display" Modes "1280x768" Virtual 1280 1792 EndSubSection EndSection

X 啟動的 log 如下:

(II) config/hal: Adding input device SynPS/2 Synaptics TouchPad
(II) LoadModule: "synaptics"

(II) Loading /usr/lib/xorg/modules/input//synaptics_drv.so (II) Module synaptics: vendor="X.Org Foundation" compiled for 1.4.99.906, module version = 0.15.0 Module class: X.Org XInput Driver ABI class: X.Org XInput driver, version 2.1 (II) Synaptics touchpad driver version 0.15.0 () Option "Device" "/dev/input/event8" () Option "SHMConfig" "on" () Option "LeftEdge" "1100" () Option "RightEdge" "5800" () Option "TopEdge" "1600" () Option "BottomEdge" "4200" () Option "HorizEdgeScroll" "on" (--) SynPS/2 Synaptics TouchPad touchpad found () SynPS/2 Synaptics TouchPad: always reports core events (II) XINPUT: Adding extended input device "SynPS/2 Synaptics TouchPad" (type: MOUSE) (--) SynPS/2 Synaptics TouchPad touchpad found

未來各 distro 可以提供預設的 fdi 檔,常見的 input device 都可以隨插即用 :)

X-Server 1.5.0 very sluggish
Sep 18th, 2008 by kanru

最近升到 xorg 1.5.0,某些操作 (terminal 快速更新) 會使 xserver 佔用非常多 cpu,看來是這個問題

Working on it … right now it looks like:

  • XShm pixmaps got accidentally reenabled in the course of Adam’s changes

  • Someone (maybe GTK, having tracked it down yet) is taking advantage
    of that by creating a shared pixmap and using it as the source for a composite operation.

  • That is not handled well in EXA and triggers migration of the destination back to system memory. (*)

– Owen

(*) One of the many cases where we’d be better off creating temporaries in video memory to avoid migration.

測測..

Xorg 1.4 XInput Hotplug
Nov 16th, 2007 by kanru

Xorg 1.4 開始支援 hal based 的 xinput hotplug,也就是說滑鼠跟鍵盤這些設備可以拔來拔去而不用在 xorg.conf 裡面設定,再加上越來越多 driver 可以 auto-configuration,xorg.conf 裡面的東西越來越少了。

xorg 的 evdev driver 是利用 linux kernel 的 evdev 支援,來使用滑鼠、鍵盤等多種設備,我的 Logitech V450 就一定要用 evdev 才能支援所有的按鍵。

無奈 Debian Sid 中的 Xorg 以及 evdev 都非常的新,但是一些升級的配套措施跟文件跟不上,導致最近發生許多問題,相關的 bug report 有 #443292#442316

今天終於把滑鼠鍵盤都設定好了,關鍵在於 hal 的設定跟 gnome 的設定。

首先是設定 hal,因為 hal 預設只設定了使用 evdev,但是沒有顧慮到非使用 us layout 的人,導致升級之後鍵盤 layout 大亂,目前暫時取消了這項設定,我們可以從 /usr/share/doc/hal/examples/10-x11-input.fdi 把設定撿回 /etc/hal/fdi/policy/,內容如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <!-- FIXME: Support tablets too. -->
    <match key="info.capabilities" contains="input.mouse">
      <merge key="input.x11_driver" type="string">mouse</merge>
      <match key="/org/freedesktop/Hal/devices/computer:system.kernel.name"
             string="Linux">
        <merge key="input.x11_driver" type="string">evdev</merge>
      </match>
    </match>

&lt;match key="info.capabilities" contains="input.keys"&gt;
  &lt;!-- If we're using Linux, we use evdev by default (falling back to
       keyboard otherwise). --&gt;
  &lt;merge key="input.x11_driver" type="string"&gt;keyboard&lt;/merge&gt;
  &lt;match key="/org/freedesktop/Hal/devices/computer:system.kernel.name"
         string="Linux"&gt;
    &lt;merge key="input.x11_driver" type="string"&gt;evdev&lt;/merge&gt;
    &lt;merge key="input.xkb.rules" type="string"&gt;xorg&lt;/merge&gt;
    &lt;merge key="input.xkb.model" type="string"&gt;evdev&lt;/merge&gt;
    &lt;merge key="input.xkb.layout" type="string"&gt;dvorak&lt;/merge&gt;
  &lt;/match&gt;
&lt;/match&gt;

</device> </deviceinfo>

其中關於鍵盤 layout、model、rules 的設定是我加上去的。滑鼠不需更動即可 hotplug 使用。

接下來關鍵的地方是,如果你使用 gnome 的話,記得把 keyboard model 改成 evdev,如圖:

gnome keyboard setting

最後,xorg.conf 就可以清乾淨了:

Section "Device"
        Identifier      "intel"
        Driver          "intel"
        Option          "AccelMethod"     "XAA"
        Option          "XAANoOffScreenPixmaps" "True"
EndSection

Section "InputDevice" Identifier "Synaptics Touchpad" Driver "synaptics" Option "CorePointer" Option "Device" "/dev/input/event9" Option "Protocol" "auto-dev" Option "SHMConfig" "on" Option "LeftEdge" "1100" Option "RightEdge" "5800" Option "TopEdge" "1600" Option "BottomEdge" "4200" Option "HorizEdgeScroll" "on" EndSection

Section "Monitor" Identifier "Configured Monitor" Option "DPMS" DisplaySize 330 200 EndSection

Section "Screen" Identifier "Default Screen" Monitor "Configured Monitor" DefaultDepth 24 SubSection "Display" Modes "1280x768" "1024x768" EndSubSection EndSection

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2004-2009 Kan-Ru Chen