The Mystery of X Window

Source: Internet
Author: User
Tags console 8 gz file

Welcome to the big Data and AI technical articles released by the public number: Qing Research Academy, where you can learn the night white (author's pen name) carefully organized notes, let us make a little progress every day, so that excellent become a habit!

Read Catalogue

    • Know the X Window on your machine
    • Understanding display and Virtual consoles
    • Remote Connection X Server
    • Understanding the startup process of the LIGHTDM and X Window desktop environments
    • Fix Xauth.
    • Configuration of X Server
    • A nested X Server can be run in an existing graphical interface
    • Summarize:

The famous X Window is certainly not unfamiliar to everyone. All know it is unix/linux the window system below, also know it is based on server/clinet architecture. Search the Internet casually, you can also find a lot of X Window introduction. There are many articles in order to give users an intuitive impression, often first let the system into a plain text interface, and then use STARTX to start the graphical interface, or directly using X to start X Server, and then run a xterm to do the demonstration. I think the above articles have limited understanding of X Window, not deep enough, and not new enough. So, I'm here to write a "X Window Mystery", with the latest Ubuntu-14.04 Desktop example, showing how to learn X window.

Let's talk a little off-topic. After the previous article, "Create your own vim," a comment was made to share the configuration file. At that time I said: The configuration file is not long, I hit the picture by the code. As a result, I did my own work today with this "hit the code", but it didn't take much time, just a few minutes. The reason is because I toss the X Window today, the system to hang up, and then re-install the system, and then, I have to set again the Vim.

Go back to the top and learn about the X Window on your machine.

X window is actually a specification, it has many different implementations, the most popular in Linux system is the implementation of Xorg and XFREE86, Microsoft Windows System also has X window implementation, Apple's Mac is also a kind of X window. To find out which X Window is running on your machine, you can use the PS command that looks at the process, such as:

As you can see, the X Window used by Ubuntu 14.04 is Xorg. If you use the PS-EF command, you can also see the command-line arguments for the Xorg runtime.

To understand X Window, the following documents need to be read first:

The following is perhaps a well-known basic knowledge: X Window is a layered architecture that is divided into Serve and Client. X server is responsible for the display of the graphical interface (which is also responsible for user input), while the client program needs to connect to x server and then request X server to draw the graphical interface and accept the user's input from x server. On desktop systems, X Server and Client programs are often installed on the same machine, and the basic sense of everyday use is that it is layered. However, it is clear that X Server and Client can also run on separate machines, run programs on one machine, and display graphical interfaces on another machine.

The concept of Server and Client in X Window is just the opposite of the concept of "server/client" that we normally touch. Many people familiar with the principles of the Internet, the first contact with X Window of these two concepts will be mistaken. For example, I run Ubuntu 14.04 desktop on a local machine, and I run CentOS 5.10 on another remote machine (the pure Character interface), and when I connect to CentOS from Ubuntu using SSH, Ubuntu is the Client, and the CentOS is the Server. In X Window, the server is the UBUNTU,X server in front of me running on Ubuntu. I can run GVim in CentOS, but the window appears in Ubuntu, when GVim is a Client program that runs on a remote machine and its window is displayed locally.

Back to top understanding display and virtual consoles

As mentioned earlier, many of the articles on the Web introducing X Window are first to let the system enter the character interface and then manually start an X Server. This is completely unnecessary because you can run more than one X server on the same machine, just make each x server display different. So what exactly is display?

In X Window, you can specify a screen by Hostname:display_number.screen_number. You can understand this: a computer can have multiple displays, and a display can have multiple screens. So, display is equivalent to a computer equipped with a set of input, in general, a computer with only a set of keyboard and mouse and a monitor, in particular, can be equipped with multiple monitors.

Now the problem comes out, my computer has only a set of keyboard and mouse and a display, that is, only one display, then how can I run multiple X Server? That's because in Linux, there are advanced features such as virtual consoles. You can switch between different virtual consoles by pressing CTRL+ALT+F1, CTRL+ALT+F2 、...、 ctrl+alt+f7 at the same time. In Ubuntu 14.04, virtual consoles 1 to 6 run Getty, which is the character interface, and Virtual Console 7 runs Xorg. (unlike in Fedora, the Virtual Console 1 runs the graphical interface, and the other is the character interface.) )

We can run the X server program directly to start x server. Both/usr/bin/x and Xorg are X Server programs. In fact,/usr/bin/x is Xorg's symbolic link, which is the same.

You can specify display parameters when you start X Server, because you can omit hostname and screen_number, so you can specify display in a format such as: 0,:1. On my machine, there was an X Server running, display:0 is already occupied, so I use sudo x:1-retro to run an X Server on display:1, such as:

The-retro parameter is for the X server's background to appear as a twill, otherwise the background is pure black, it does not see whether the X server is started. The effect after starting X Server is as follows:

Press Ctrl+alt+f7 back to display:0, and then with the PS command to look at, you will find that the system has two Xorg in operation, one running in Virtual Console 7, one running in Virtual Console 8. Such as:

Run a GVim in the newly launched X Server to see the effect. When you run GVim, use the-display:1 parameter to specify that the window appears on the newly launched X Server, using the-geometry parameter to specify the size and position of the window. Then press CTRL+ALT+F8 to switch the Virtual Console to see the effect. command See, program operation effect SEE:

Back to top remote connection X Server

It would be interesting to have the GVim on the remote machine Display the window on the local machine screen. So, use SSH to connect to CentOS-5.10, and then use the Gvim-display ubuntu-14:1 command to display gvim to Ubuntu display:1. Because is the remote connection, therefore hostname cannot omit, must write ubuntu-14:1, also may use the IP address, writes 192.168.1.103:1. Such as:

Unfortunately, the connection failed.

The reason for the failure is that remote access X Server requires secure authentication. This can be understood, just like login mailbox need to enter the user name and password, if X Server do not authentication can be casually connected, it is not on the desktop garbage window flying? There are many ways to secure authentication, please refer to man xsecurity for details. Secure authentication can be done using both the Xhost and Xauth programs, which refer to their documentation in specific ways.

It's easier to use Xhost to authorize it first. In order to run xhost, you need to have a terminal on X Server, so run a xterm, such as:

Enter Sodu xhost +192.168.1.109 in xterm so that the GUI program running in CentOS-5.10 can connect to the newly opened X Server. Such as:

Run GVim in CentOS-5.10, such as:

Windows are displayed in Ubuntu, such as:

The new start of the X Server interface is ugly, we still want to let the remote machine GUI program directly display in Ubuntu desktop environment. Therefore, the specified display is: 0, such as:

Unfortunately, the display could not be opened. The connection is not up, why? Is the issue of security certification? No, it's LIGHTDM's problem, please keep looking down.

Back to the top understand the startup process of the LIGHTDM and X Window desktop environments

There are two ways to start X Server, one to start with a display manager, and another to start manually. In the previous example, I started an X Server by running/usr/bin/x directly: one. The way to start X Server directly is to run StartX or xinit. The disadvantage of manually starting X server is that the boot x server is not looking good. And the display manager started not only X Server, but also a large number of Client programs, constitute a complete desktop environment, of course, the interface is much more beautiful.

What is the display manager? In front of me, display is a computer with a set of keyboard and mouse and monitor, then the show manager is the manager of this set of devices. The display manager can manage these devices directly, so it can control the operation of X server, which is the right place to start X server. The system boot process is like this: Kernel load-->init program runs----display manager runs--X server runs--display manager connects to X server, displays the login interface--After the user logs on, the login interface closes, loading the desktop environment. As can be seen from the above process, the display manager is the parent process of x server, it is responsible for starting x server, when x server is started, it becomes a Client program of x server, connect to x server display welcome interface and login interface, finally, display tube Manager is the parent process for all desktop environments, and it is responsible for launching other Client programs required by the desktop environment.

In Ubuntu 14.04, LIGHTDM replaced the traditional XDm, GDM and other display managers. Simply put, the LIGHTDM is responsible for starting x Server and other X programs. I don't know why, LIGHTDM when I started X server, I added the-nolisten tcp parameter to x server, so there was no way for the remote computer to connect to Ubuntu desktop. (This parameter can be seen from the 1th picture.) )

The next goal is to change the configuration of the LIGHTDM, removing the-nolisten tcp parameter. But to achieve this goal is really difficult, ah, my system hangs and reload is here to toss out. Here I'm going to throw up the trough. freedesktop.org, in the software used by X Window, freedesktop.org contribute a lot, such as LIGHTDM, Xft, Fontconfig, FreeType are the contribution of this Organization, but, Can't you just write down the document in detail? Not only LIGHTDM documents, XFT, FreeType documents are also not.

LIGHTDM's man page is very brief, and using sudo dpkg-l LIGHTDM can not find anything valuable in the package. There is no way to go. When you use sudo dpkg-l lightdm to view the file for the package, find its log file under the/var/log/lightdm folder and look in the past:

Finally, the entire process of LIGHTDM startup is seen from the log file. First, see which directories it loads the configuration file from, and then see it start X Server. All parameters starting with X Server are visible from the line where the cursor is located, including the-nolisten TCP option.

Continue to look at the log file, the line below the cursor shows LIGHTDM how to start gnome-session:

At the same time, I found that there is no lightdm.conf file in the/etc/lightdm/directory, and/usr/share/doc/lightdm/directory has a lightdm.conf.gz file, the file as a document to look at, and found that it is indeed Explanation of the configuration of the LIGHTDM. Quickly copy the file to the/etc/lightdm/directory and unzip it, such as:

Then use Vim to edit the/etc/lightdm/lightdm.conf file, xserver-allow-tcp=false a line before the comment is removed, and changed to Xserver-allow-tcp=true. Such as:

Finally, restart the system. Then using PS to view the process, found that the-nolisten TCP option is no longer available.

Get back to the top and fix Xauth.

It's done. After-nolisten TCP, secure authentication is required to connect to Ubuntu desktops from remote computing. In the previous example, I used the xhost. Xhost is the simplest way to authenticate. Here I would like to try other authentication methods, such as mit-magic-cookie-1. For example, first use the Xauth List command to see the current authorization record, found only one, and display is ubuntu-14/unix:0, it is clear that this is a local authorization, so you need to use the Xauth Add command to add an authorization to use the IP address, the following Ke Y copy on the line. Finally, use the Xauth extract and Xauth merge pipeline and SSH to merge the authorization record into the CentOS-5.10.

Starting GVim in CentOS-5.10, specifying display as the 192.168.1.103:0,gvim window appears in Ubuntu. Such as:

Back to the top x Server configuration

The X Server can be configured using different methods, and the preceding example is specifying command-line arguments directly. In addition to specifying command-line arguments, you can also use environment variables and configuration files. The configuration file for X Server is generally a. conf file in the/etc/x11/xorg.conf or/etc/x11/xorg.conf.d/directory, and of course, the configuration file can also be placed in other directories, see Man xorg.conf for details.

If there is no configuration file, X Server automatically detects the hardware at startup and then generates a built-in configuration. There is no configuration file for the Ubuntu system. However, if you need to use a configuration file, you can generate a configuration file with the X Server's-configure parameter, which contains the currently detected configuration. If you need any personalized configuration, make changes to the file.

Back to the top of the existing graphical interface you can run a nested X Server

The x server we run above is a direct occupation of the computer's entire display and keyboard mouse, in fact, in the existing graphical interface, you can also run another X server in windowed mode, called nested x server. The most commonly used nested X Server is Xephyr, which can be installed in Ubuntu with the following command:

sudo aptitude install Xserver-xephyr

The use of Xephyr is simple and can be viewed through the man Xephyr command. If you enter the xephyr:1 command, you can open a window-mode X Server in an existing graphical interface, such as:

To start the GUI program later, you can use the program's-display option to let the program run in the nested X Server, such as:

What, isn't it fun? In addition to the fun, but also useful, such as Debugging window Manager Ah, connected to the Remote desktop and so on. Of course, I'm just going to show you how the X Window can play.

Back to the top of the summary:

1. There are multiple virtual consoles in a Linux system, so you can start multiple X servers;

2. There are two ways to start X Server, one is to start manually using/usr/bin/x, StartX, Xinit, and one is to start with the display manager;

The display manager used by 3.Ubuntu is LIGHTDM, which is a relatively new, lightweight display manager, but the documentation is not detailed enough;

4. The remote computer connects to the local x server, requires X server to open the TCP port, but also to take care of security authentication;

5.X Server configuration, can be through the command line parameters, can be through the environment variables, but also through the configuration file;

6. The nested X Server can be run in windowed mode under the existing graphical interface, the commonly used software is xephyr;

The Mystery of X Window

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.