Linux graphical interface start principle __linux

Source: Internet
Author: User
Tags sessions domain name server
Graphical interface directory [hide]
1 Introduction
2 Architecture and principles
2.1 Xserver
2.2 Xclient
2.3 Xprotocol
3 window Manager
4 START process
4.1 startx
4.2 GDM Session
5 Configuration Files
5.1 x Server
5.2 x Client
6 fonts
6.1 FreeType Rendering Engine
6.2 x Core Font
6.3 Xft Fonts

Edit
Brief introduction
Xwindow is the industrial standard for workstation graphics systems, it has many different implementations, and most Linux systems use Xorg

Of course, Xwindow has a long history and tradition, but that is beyond the scope of our discussion. There are two points to emphasize:
The meaning of "X" in Xwindow and Xbox is different, x is just a letter after W, it should be understood that Xwindow is the successor of window (note, not Windows)
Also, do not say Xwindow as xwindows, it is a sacrilege. All great creations deserve to be understood and respected.
Edit
Architecture and principles

Xwindow uses the server-client architecture.

Both the local graphical interface and the remote graphical interface work the same way.

This does not require separate design and maintenance
Local x client ┐┌ keyboard
Remote x Client ┼X protocol ─x Server-driver ┼ mouse
Remote x Client ┘└ Monitor
Edit
Xserver

Xwindow system server side, through the driver (Hardware specification) to manage hardware resources.

For example: When we move the mouse, through the driver (most of the mouse does not need a special driver, they conform to a hardware specification, such as: have four move direction and three keys), send the message to the Xserver:
"Move 200 points to the right, move up 100 points" (move to the right), "press left" ...


Xserver made the following response:
The last time the mouse stopped coordinates were 600,500
200 to the right, up to 100. Now the mouse is at coordinates 800,600
At coordinates 800,600, the "Close" button for the window Firefox
According to the preset action, the "click on Firefox window Close button" translates to "close the window Firefox"
Send an "exit" message to the X client Firefox
Xserver displays the mouse position and movement through the display subsystem (video card, monitor)
In fact, sending an "exit" signal to a program is usually done by the window manager. In order to describe the convenience, there is no distinction. Later, we'll introduce you to some other details of the window manager.
Edit
Xclient

The Xwindow system client, through the X protocol, realizes the interaction with the xserver. For example:
Xclient (assuming Firefox) receives Xserver message: input focus in the range of the address bar, "linuxtoy.org", carriage return
Firefox identifies these messages as "open link linuxtoy.org" according to preset actions
Firefox requests a link "linuxtoy.org" to the domain name server. The domain name server converts this request to "http://linuxtoy.org/" and IP address 211.148.131.7, which is sent back to Firefox
Firefox displays "http://linuxtoy.org/" in the address bar (sending requests to xserver, displaying this address in the Address bar location)
Firefox to address 211.148.131.7 for instructions to display the page
Firefox Displays the page that the server sends back to the main window
Edit
Xprotocol

Xwindow system protocols, rules for communication between Xserver and Xclient
Edit
Window Manager

Window Manager is a special kind of xclient.

When using the window manager, Xserver does not communicate directly with other xclient, but through the WM relay, when some messages are defined as WM directives, they are intercepted. For example, Alt+f4 closes the window, drags the title bar ...

The message "Open link linuxtoy.org" is as follows:


Enter focus in the range of the address bar, "linuxtoy.org", carriage return

Xserver can not directly judge the focus, but this:
Xserver sends location and click Information to the WM, the WM determines the active (topmost) window as Firefox according to the current focus policy
Xserver Firefox on top, highlighting its title bar
Click on the Address bar in the window Firefox or ctrl+l,xserver send the location information to WM,WM and send it to Firefox
After Firefox determines the current focus, a flashing text input cursor is displayed
Firefox sends the input cursor through the WM to Xserver,xserver to display at the appropriate location on the screen


So what can the window manager do?

In fact, there is only one thing it does--the management window. For example:
The topmost window will block the other windows.
It is usually an "activated window", depending on the focus policy, the window manager determines which windows are activated.
Activates the window title bar highlighting, receiving most of the keyboard messages and mouse click messages inside the window.
For beauty and easy resolution, most windows have a title bar and a border.
For convenience, there are also buttons on the title bar, such as minimizing, maximizing, and closing (these buttons are small windows requested by the window manager).
A window can be displayed next to another window, not necessarily completely obscured. To do this, you need to control where the window is displayed
In order to control the display of the window, you need to describe the entire screen with a coordinate, the best way is to draw a fill the entire screen of the window, that is, the root window.
Because the root window is the largest, it can block any window tightly, in order to avoid this, the root window is always at the bottom. This is a vivid illustration of why it is called the "root window" ... root
The root window is not necessarily one, and most window managers can use the workspace to toggle the display of multiple root windows
The root window is usually placed in a fixed position with some other xclient windows, such as the bottom panel, the top panel, the side panel, the program launch icon
The panel can also put some other xclient windows, such as task bar, launch bar, menu ...
The taskbar can display the running tasks as icons, as well as other miscellaneous chores, such as automatic mounting of USB devices ...
Edit
Start process

We know that Init is the root process of Linux and the parent process of all processes. Similarly, Xinit is the root process for all Xwindow processes
Edit
StartX

StartX can start the graphical interface at the command line. When you execute the STARTX command, you actually execute this command:
XINIT/ETC/X11/XINIT/XINITRC--/ETC/X11/XINIT/XSERVERRC

Start the Xserver according to the script/ETC/X11/XINIT/XSERVERRC, and start the specified xclient process based on the script/etc/x11/xinit/xinitrc, such as the window manager

/ETC/X11/XINIT/XSERVERRC run the program with a preset parameter/usr/bin/x11/x

The/etc/x11/xinit/xinitrc script points to/etc/x11/xsession and starts the script in the/ETC/X11/XSESSION.D directory in turn
You can ~/the user profile. The WM used in the xsession is defined as having a higher precedence than the global configuration file (for GDM sessions)
STARTX is not authenticated when it is started. Because it starts with a/etc/x11/xsession.d/gnome-session, not a GDM session.


Edit
GDM session

Many Linux systems automatically enter the graphical interface when booting, without the need to run the STARTX command

In some boot levels, GDM's startup script is included, for example:/ETC/RC2.D/S13GDM
Point to/etc/gdm/gdm-cdd.conf file, load preset visual theme, start/usr/lib/gdm/gdmgreeter (login screen)
After user authentication is complete, start/etc/x11/default-display-manager the default window manager set in this file/USR/SBIN/GDM

When GDM starts, it asks for a username and password, which is the login screen we see (gdmgreeter)
Scripts for all available logon sessions under the/usr/share/xsessions directory
Edit
Configuration file
Edit
X Server

X server's primary profile is/etc/x11/xorg.conf

(The most recent xserver already supports Plug and Play and does not need this profile)
section "Serverlayout" #布局
Identifier "Xorg configured" #布局标识
Screen 0 "Default screen" 0 0 #屏幕标识
InputDevice "Generic Keyboard" #键盘标识
InputDevice "Configured Mouse" #鼠标标识
Endsection

section "Module" #模块
Load "DDC"
Load "DBE"
Load "DRI"
Load "Extmod"
Load "GLX"
Load "Bitmap"
Load "Type1"
Load "FreeType"
Load "Record"
Endsection

section "Files" #X核心字体路径
Fontpath "/USR/SHARE/X11/FONTS/75DPI"
Fontpath "/USR/SHARE/X11/FONTS/100DPI"
Fontpath "/usr/share/x11/fonts/misc"
Fontpath "/usr/share/x11/fonts/cyrillic"
Fontpath "/usr/share/x11/fonts/100dpi/:unscaled"
Fontpath "/usr/share/x11/fonts/75dpi/:unscaled"
Fontpath "/usr/share/x11/fonts/type1"
Fontpath "/usr/share/fonts/chinese/wqy-bitmapfont"
Endsection

Section ' Screen ' #屏幕
Identifier "Default Screen"
Device "Card0" #指定显卡
Monitor "Monitor0" #指定显示器
Defaultdepth #默认色深为24
Subsection "Display" #可用分辨率
Depth #24位色深下可用分辨率
Modes "1280x1024" ① "1152x864" "1024x768" "800x600" "720x400" "640x480"
..................
Endsubsection
Endsection

section "Device" #显卡
Identifier "Card0"
Driver "VESA" #驱动
VendorName "All"
Boardname "All"
Endsection
① default resolution is the first resolution under the default color depth


Configuration file Internal structure
/
├/"Serverlayout" layout
│ "InputDevice" keyboard keyboard
│ "InputDevice" Mouse Mouse
││
│└/"Screen" display subsystem
│ "Monitor" monitor
│ "Device" videocard video card


├ "Files" font
└ "Module" modules
Edit
X client

The following contents can be found in the/etc/x11/xsession file
Optionfile=/etc/x11/xsession.options # Sets the start parameters for the X process. For example, allow user process allow-user-xsession
# x resource file. Many programs retain the X interface, allowing the X server to manage some visual options, such as the fonts in the window, color matching, etc.
Sysresources=/etc/x11/xresources
usrresources= $HOME/. Xresources
# x process. You can set up programs that run automatically at startup, or you can use to set your own Window Manager (Window Manager and desktop environment or login manager is irrelevant)
Syssessiondir=/etc/x11/xsession.d
userxsession= $HOME/.xsession
altuserxsession= $HOME/. Xsession
errfile= $HOME/.xsession-errors
Edit
Font
Edit
FreeType Rendering Engine

As a module of the Xorg server, FreeType's features include reading Truetype font information, such as size, resolution, encoding, and so on, and rendering fonts based on them-freetype2.x has added anti-aliasing to freetype1.x (/etc/x1 1/xorg.conf the module field, you can select the font rendering modules)

FreeType is only responsible for rendering fonts. To find the font, it can be done by an X server, an X client, or a font server. After the font is found, use the FreeType engine for rendering

X Core Font
The X server looks for and renders the font according to the X client's request (character encoding) and then displays

xft fonts
X The client finds the font itself and renders it, and the X server is only responsible for displaying it. Because the rendering of the Xft font is done on the client, it can be loaded dynamically without having to be started with the X server

Font server
When the client requests a font, the X server forwards the request to the font server, the font server looks up the font, uses the FreeType engine rendering, returns the result back to the X server, and the X server displays
Edit
X Core Font

/etc/x11/xorg.conf can be configured in the X core font search path
section "Files"
Fontpath "/usr/x11r6/lib/x11/fonts/misc/"
Fontpath "/usr/x11r6/lib/x11/fonts/type1/"
Fontpath "/usr/x11r6/lib/x11/fonts/speedo/"
Fontpath "/usr/x11r6/lib/x11/fonts/100dpi/"
Fontpath "/usr/x11r6/lib/x11/fonts/75dpi/"
Endsection
When the X client requests the text to be displayed to the X server, the x server looks for the font in the order listed above. When displaying Chinese, if the font in the first path does not contain Chinese, find the path below until you find the Chinese font
Please put your preferred font in the front position

To make the installed font available as an X core font, add the installation path of the font to the list above, use the fonts in the Mkfontscale, Mkfontdir Scan folder, and generate an index (Ttmkfdir build Fonts.scale is recommended). Copy it to Fonts.dir)

Font selection and display style, you can modify the GTK1 configuration file, or in the Xresources file to define the program separately

In fact, in our daily applications, x core font environment is not common, using the GTK1 graphics library program, some types of terminals ...
Edit
xft fonts

Xft font-related options are configured in the/etc/fonts/fonts.conf file
<dir>/usr/share/X11/fonts</dir>
<dir>/usr/share/fonts</dir>
<dir>/usr/local/share/fonts</dir>
<dir>~/.fonts</dir>

You can use the Fc-cache command to recursively scan the fonts in the above directory (including the fonts in subfolders) and create a font cache

Most x clients that support GTK2 or Qt graphics libraries can use xft font rendering techniques

Install fonts, just copy the font to any of the above directories, FC-CACHE-FV refresh the font cache (option:-F forced refresh; -V Display Procedure)

Use the command fc-list to list all available fonts.


Font selection and display style, you can modify the GTK2 or Qt configuration file,

It is recommended that you use a graphical interface configuration, such as Gnome-font-properties

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.