This is an archive of past FreeBSD releases; it's part of the FreeBSD Documentation Archive.
第一次接觸 X 的人,大概都會有些震撼,尤其是熟悉其他 GUI 介面(像是 Microsoft® Windows® 或 Mac OS®)的使用者。
雖然 X 各元件的所有細節及運作方式,並不是必須要知道的。 但對它們有些基本概念會更容易上手。
X 並非 UNIX® 上第一套視窗系統,但它卻是最廣為流傳運用。 原本的 X 研發團隊在研發 X 之前有開發另一套視窗系統。 那套系統叫做 “W”(取 “Window” 的第一個字)。 而 X 則是 W 之後的下一個羅馬字母。
X 亦被稱之為 “X”、“X Window System”、 “X11”,以及其他一些詞彙。 使用 “X Windows” 這字眼來稱呼 X11,可能會讓有些人不爽;這部分細節可參閱 X(7) 說明。
X 一開始是設計為網路架構環境,並採用 “client-server” 架構。
在 X 架構下, “X server” 是在有鍵盤、螢幕、滑鼠的電腦上運作。 而 server 部份則是負責像是顯示部份的管理、 處理來自鍵盤、滑鼠方面的輸入等等, 每個 X 程式(像是 XTerm,或 Netscape®)都是 “client”。 client 會傳訊息到 server 上,比如:“Please draw a window at these coordinates”,接著 server 會傳回訊息,比如: “The user just clicked on the OK button”。
在家庭或小辦公室環境,通常 X server 跟 X client 都是在同一台電腦上執行的。 然而,也可以在比較爛的桌機上執行 X server, 並在比較強、比較貴的電腦上跑 X 程式(client)來做事情。 在這種場景,X client 與 server 之間的溝通就需透過網路來進行。
這點可能會讓有些人產生困惑,因為 X 術語與他們原本的認知剛好相反。 他們原本以為 “X server” 是要在最強悍的機器上跑才行,而 “X client” 則是在他們桌機上面跑。
有點相當重要,請記住 X server 是在有接螢幕、鍵盤的機器上運作, 而 X client 則是顯示這些視窗的程式。
協定(protocol)內並無強制規定 client 以及 server 兩邊機器都得是同一作業系統,或者得是同型機器才可以。 換句話說,也可以在 Microsoft Windows 或蘋果電腦(Apple)的 Mac OS 上跑 X server,而且可以透過許多免費或商業軟體完成這些安裝、設定。
X 設計哲學與 UNIX 設計哲學相當類似,都是 “tools, not policy”。 也就是說,X 不會試圖強制規定某任務應該要如何完成,而是只提供使用者一些工具, 至於如何運用這些工具,則是使用者本身的事了。
X 延續這哲學,它並不規定:螢幕上的視窗該長什麼樣、要如何移動滑鼠指標、 該用什麼組合鍵來切換各視窗(比如:在 Microsoft Windows 的 Alt+Tab鍵)、各視窗的標題列長相,以及是否該有關閉鈕等等。
事實上,X 把這部分交給所謂的 “Window Manager” 來管理。 有一堆 window manager 程式,像是: AfterStep 、Blackbox、ctwm 、Enlightenment、 fvwm、Sawfish、 twm、 Window Maker 等等。每一種 window manager 都提供不同的使用經驗; 有些還可使用 “virtual desktops(虛擬桌面) ”;有些則可自訂組合鍵來管理桌面;有些會有 “Start(開始) ”鈕或其他類似設計;有些則是 “可更換佈景主題”, 可自行安裝新的佈景主題以更換外觀。 這些跟其他的 window manager 在 Ports Collection 內的 x11-wm 目錄內都有。
此外,KDE 及 GNOME 桌面環境則有其自屬並整合完整的 window manager。
每個 window manager 也各有其不同的設定機制;有些需手動寫設定檔, 而有的則可透過 GUI 工具來完成大部分的設定。舉個例子: Sawfish 就有以 Lisp 語言寫的設定檔。
Focus Policy: Another feature the window manager is responsible for is the mouse “focus policy”. Every windowing system needs some means of choosing a window to be actively receiving keystrokes, and should visibly indicate which window is active as well.
A familiar focus policy is called “click-to-focus”. This is the model utilized by Microsoft Windows, in which a window becomes active upon receiving a mouse click.
X does not support any particular focus policy. Instead, the window manager controls which window has the focus at any one time. Different window managers will support different focus methods. All of them support click to focus, and the majority of them support several others.
The most popular focus policies are:
- focus-follows-mouse
The window that is under the mouse pointer is the window that has the focus. This may not necessarily be the window that is on top of all the other windows. The focus is changed by pointing at another window, there is no need to click in it as well.
- sloppy-focus
This policy is a small extension to focus-follows-mouse. With focus-follows-mouse, if the mouse is moved over the root window (or background) then no window has the focus, and keystrokes are simply lost. With sloppy-focus, focus is only changed when the cursor enters a new window, and not when exiting the current window.
- click-to-focus
The active window is selected by mouse click. The window may then be “raised”, and appear in front of all other windows. All keystrokes will now be directed to this window, even if the cursor is moved to another window.
Many window managers support other policies, as well as variations on these. Be sure to consult the documentation for the window manager itself.
The X approach of providing tools and not policy extends to the widgets seen on screen in each application.
“Widget” is a term for all the items in the user interface that can be clicked or manipulated in some way; buttons, check boxes, radio buttons, icons, lists, and so on. Microsoft Windows calls these “controls”.
Microsoft Windows and Apple's Mac OS both have a very rigid widget policy. Application developers are supposed to ensure that their applications share a common look and feel. With X, it was not considered sensible to mandate a particular graphical style, or set of widgets to adhere to.
As a result, do not expect X applications to have a common look and feel. There are several popular widget sets and variations, including the original Athena widget set from MIT, Motif® (on which the widget set in Microsoft Windows was modeled, all bevelled edges and three shades of grey), OpenLook, and others.
Most newer X applications today will use a modern-looking widget set, either Qt, used by KDE, or GTK+, used by the GNOME project. In this respect, there is some convergence in look-and-feel of the UNIX desktop, which certainly makes things easier for the novice user.
本文及其他文件,可由此下載:ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。
若有 FreeBSD 方面疑問,請先閱讀 FreeBSD 相關文件,如不能解決的話,再洽詢
<questions@FreeBSD.org>。
關於本文件的問題,請洽詢 <doc@FreeBSD.org>。