我們知道unix/linux剛開始的時候是沒有圖形界面的,隨着時代的發展,排版、制圖、多媒體應用越來越普遍了,這些需求都需要用到圖形界面(Graphical User Interface)。為此,MIT在1984年開發出了X window system,X在字母表中是W(indows)的下一個字母,寓意“下一代GUI”的意思。目前為止,unix/linux上幾乎所有的發行版都采用X window system來作為自己的圖形界面,它已經成為事實上的unix/linux圖形界面標准。
X window system,又名X,X11(現在主要的X window system大都基於其第11個版本),是一個能夠跨網絡和操作系統平台的圖形界面。開發者在開發x時就希望,這個窗口界面不要與硬件有強烈的相關性,這是因為如果與硬件的相關性高,那就等於開發一個操作系統了,如此一來其應用性就要受到限制。故此,x是一套軟件體系,而不是操作系統中的組成部分,就像瀏覽器不是操作系統的組成部分一樣(當然微軟在與網景干仗時可不管這些)。
X的軟件架構
如上圖所示,X使用服務器-客戶端模型:每個需要顯示圖形界面的主機都要運行一個x server,它負責主機中各個與圖形界面有關硬件設備的管理,如在顯示器中顯示輸出,從鼠標、鍵盤接受輸入等。同時與不同的客戶端程序(x client)通信,x client指那些需要圖形界面的應用程序,如瀏覽器、終端、視頻播放器等。這里需要解釋一下,這里的server,client術語是從應用的角度而不是以用戶的角度來說的:X server利用自己對硬件的掌控為應用提供顯示界面以及處理輸入輸出等服務,所以說它是服務器端,而各種應用需要使用x server提供的這些服務,他們就是客戶端了。
x server和x client之間所使用的通信協議對網絡來說是透明的,所以client和server可以運行在相同機器上,也可以運行在不同機器上,甚至機器本身的硬件架構和操作系統也可以不一樣(如windows上的xmanager就是一個x server,它可以遠程連接linux上的主機為linux上的x client提供服務,有興趣的童鞋可以試下)。
說完了x的軟件架構,下面我們就來說說x中其他幾個概念。
1. X Display Manager(XDM)
display manager,又稱login manager,是linux在boot進程完成之后啟動的一個用於用戶身份認證的圖形界面,相當於文本模式下啟動時讓我們輸入用戶名和密碼的shell。比較常見的有GNOME的gdm,KDE的kdm等。
display manager可以在本地也可以在遠程主機上啟動。如果在本地啟動,display manager接下來會把x server也啟動起來,這樣就可以在開機時顯示如上圖所示的圖形界面了。
如果display manager已經在遠程啟動了,我們在本地需要連接到遠程的display manager上去,這時x server就用使用XDMCP(X Display Manager Control Protocol)協議連接到遠程的display manager,請求開啟一個會話,這樣在本地也就出現了如上圖所示畫面,如果身份認證通過,display manager就退居二線,剩下的就是本地的x server與遠程的x client之間互相交流了:我們通過x server(鍵盤、鼠標等輸入設備)把我們的要求發給x client(x client與display manager 運行在同一台機器上),x client運行得到結果並將結果返回給x server,x server再通過自己管理的輸出設備如顯示屏等把結果顯示出來,如此種種可以參看下圖。
2. GNOME,KDE......
3. GNOME與X的區別與聯系
關於GNOME與X之間的關系,這里有一篇文章介紹的非常清楚,現摘抄一部分如下,我就不畫蛇添足了:
X11 is the window system. Gnome is a desktop environment. The difference is that Gnome works through X11. Gnome and X11 run on Linux, though, not Windows.
Basically, X11 is what displays everything. It's the graphical shell that connects you to the operating system. None of the applications you run ever send anything directly to the screen - they need to tell X11 what they want to display and let it do the work for them.
X11 draws and moves windows and responds to input from the keyboard and mouse. That's pretty much it. Everything else is taken care of by the desktop environment. What that means is that the look and feel of the windows and the way those windows behave are all decided by which desktop environment you're using (Gnome, KDE, XFCE, etc.).
The desktop environments all have their own graphics libraries (reusable chunks of code) that they use, along with APIs (Application Programming Interfaces) which allow programmers to use those libraries when they create GUI applications. This way programmers don't have to recreate commonly used functions and elements from scratch, and the whole operating system has a more standardized look.
參考鏈接:http://en.wikipedia.org/wiki/X_Window_System
http://en.wikipedia.org/wiki/X_display_manager_(program_type)
https://wiki.archlinux.org/index.php/Display_Manager
https://wiki.debian.org/DisplayManager
http://en.wikipedia.org/wiki/GNOME
http://stackoverflow.com/questions/17251293/what-is-the-relationship-between-x11-and-gnome