\chapter{Basic X-Windows} \label{cha:x} {\mns \subsection{Objectives} \label{sec:x-objectives} \begin{itemize} \item On completion, you should be able to: \begin{itemize} \item Understand the basic concepts behind networked X windowing \item start and stop X \item run shells and user applications under X \item set preferences for X \item change window managers and desktops \item use X over a network \end{itemize} \end{itemize} \section{What X-Windows Is} \label{sec:what-x-is} X is a windowing system \begin{itemize} \item Provides the basic graphic functions for Linux \item Designed to provide windowing to any workstation across a network, regardless of OS \item Operates on a client-server model \item Is an {\em application}, i.e. not a part of the OS \item The standard Linux X server is {\pgn Xfree86}, commercial alternatives include: \begin{itemize} \item Metro-X \item Accelerated-X \end{itemize} \end{itemize} \section{X Needs Window Managers} \label{sec:needs-window-managers} \begin{itemize} \item Window managers provide the controls which allow you manipulate all graphic apps, e.g. \begin{itemize} \item move, size and stick \item open and close \item maximize, minimize, iconize \item title bars \end{itemize} \item Determine the `look and feel' of X, e.g. \begin{itemize} \item Win95 \item Motif \item Next Step \end{itemize} \item Can provide `virtual desktops' \end{itemize} \includegraphics[width=130pt]{../images/fvwmshot} \includegraphics[width=130pt]{../images/gnomeshot} \includegraphics[width=130pt]{../images/kdeshot} \section{Window Managers Are Applications} \label{sec:wm-are-apps} \begin{itemize} \item Linux distributions contain many window managers, e.g. \vspace{14pt} {\myss \begin{tabular}[b]{|p{120pt}|>{\PBS\rr}p{213pt}|} \hline Manager & Description \\ \hline \hline {\pgn sawfish} & Used with Gnome, lightweight, programmable\\ \hline {\pgn fvwm2} & Motif-like look \\ \hline {\pgn fvwm2} & Win95-like configuration for {\pgn fvwm2}, Red Hat default \\ \hline {\pgn twm} & Bare-bones Tab WM \\ \hline {\pgn olwm} & Open Look (Sun) \\ \hline {\pgn olvwm} & Virtual Screen Open Look \\ \hline {\pgn WindowMaker} & Next Step look, fast and lean \\ \hline {\pgn enlightenment} & Gnome-compatible WM, powerful, rich, heavy weight \\ \hline {\pgn wm2} & Ultra-lean \\ \hline \end{tabular} } \item Window managers are X applications, thus: \begin{itemize} \item change manager without re-starting X \item change X behaviour without re-start \end{itemize} \end{itemize} \section{Desktop Environments} \label{sec:desktops} \begin{itemize} \item X + WM alone don't provide everything expected of modern desktops, e.g. \begin{itemize} \item completely integrated drag and drop \item universal access to a clip board \end{itemize} \item Desktop Environments bring these facilities to Linux, bundling: \begin{itemize} \item desktop-capable window manager \item URL-based file manager \item facilities to share clipboard and other data between optimized apps (inc. object linking) \end{itemize} \item Linux currently has 3 main desktop environments: \begin{itemize} \item CDE \ldots the original commercial UNIX standard \item KDE \item GNOME --- now adopted by Sun Microsystems as the window desktop for Solaris. Helix Gnome is excelent and is available from \url{http://www.helixcode.com}. \end{itemize} \end{itemize} \section{Starting X} \label{sec:start-x} \begin{itemize} \item Many possibilities \begin{itemize} \item You may be using the graphical {\cmdn xdm} tool which does it for you \item or login to command prompt then type {\cmdn \$ startx} if {\fn .xinitrc} is not setup: \begin{quote} {\cmdn \$ xinit} {\cmdn \$ {\usb window manager filename}} \end{quote} \end{itemize} \end{itemize} \section{Stopping X} \label{sec:stop-x} \begin{itemize} \item Stopping: {\kbk }+{\kbk }+{\kbk } \item Use the window manager's menus \item If you started via {\pgn xinit}, type the following in the startup xterm: {\cmdn \$ exit} \item If all these fail, switch to another virtual terminal using the following keys, then kill X from the command prompt: {\kbk ++ ... } \end{itemize} \section{Running Shells (Xterms) Under X} \label{sec:run-shells-under-x} \begin{itemize} \item Even under X, the most productive way to work is often via the command line (i.e. a shell) \item The standard way to access a shell prompt under X is via a terminal emulator called an {\pgn xterm}\footnote{Linux provides other terminal emulators for specialised hosts, but they are rarely necessary. There is also another category of emulators that provide advanced features such as transparent terminals etc.} % Nick: Err, what's a ``transparent terminal''? \item An {\pgn xterm} shell behaves like a non-X shell, except that you can cut and paste between it and X applications \item Any number of xterms can be open at the same time \item Using {\pgn ssh} (or if you are desperate, {\pgn telnet}) the {\pgn xterms} can provide shells to any number of other hosts \item To start an {\pgn xterm}: \begin{itemize} \item From an already open xterm: {\cmdn \$ xterm \&} \item From a window manager menu (invariably top-level) \end{itemize} \end{itemize} \section{Running Applications from an {\pgn xterm}} \label{se:run-apps-from-xterms} \begin{itemize} \item Character-based apps: \begin{itemize} \item Run exactly as they would outside X, unless the xterm itself has been misconfigured \end{itemize} \item X applications: \begin{itemize} \item Type the program's file name at the prompt:~\footnote{The ampersand allows the application to run independently of the shell} \end{itemize} {\cmdn \$ {\usb filename} \&} \end{itemize} \section{Running Applications from a window manager} \label{sec:running-apps-from-wm} \begin{itemize} \item Every window manager provides simple menu- based access to applications \item Application Menus are usually accessible by clicking {\kbk Mouse Button 1} on: \begin{itemize} \item Buttons set into a task bar \item The desktop background (root window) \end{itemize} \end{itemize} \section{Configuring X} \label{sec:configuring-x} \begin{itemize} \item Default installations of Linux provide a fully functional setup for using graphic X apps \item 2 different types of X configuration that system administrators or users may need to change: \item Basic configuration of screen, mouse, keyboard behaviour, fonts \begin{itemize} \item Could be a course in itself (classic O'Reilly manual fills a bookshelf) \item Configuration files best edited via config tools (see next Section~\ref{sec:basic-x-hardware-config}) \end{itemize} \item Behaviour of desktop objects (windows, icons, taskbars, {\pgn xterms}) \begin{itemize} \item Window manager dependent \item Best configured via window manager preferences \end{itemize} \end{itemize} \section{Basic X Hardware Configuration} \label{sec:basic-x-hardware-config} \begin{itemize} \item Basic configuration for hardware is defined in the {\fn XF86Config} file, located in {\fn /etc/X11}~\footnote{On some older systems you may find the X configuration in {\fn /usr/lib/X11},{\fn /usr/X11R6/lib/X11} or {\fn /var/X11R6/lib/}} \item {\fn XF86Config} is easier to edit using the following tools: {\myss \begin{itemize} \item {\pgn Xconfigurator} \ldots Red Hat tool sets monitor, card, screen mode, colour depth and resolution with probing \item {\pgn XF86Setup} \ldots an X application which edits most basic hardware preferences (Mouse, Keyboard, Card, Monitor, Graphic Modes) \item {\pgn xf86config} a character-based application which prompts for the same settings \item {\pgn mouseconfig} \ldots Red Hat tool sets the mouse type with probing. Useful for setting 2-button mice to emulate 3-button types by simultaneous clicking on both buttons \end{itemize}} \end{itemize} \section{Basic X Software Configuration} \label{basic-x-software-configuration} \begin{itemize} \item Under X, the user can configure every conceivable aspect of graphic display \item Users may need to change: \begin{itemize} \item Screen font sizes, styles, familes \item Pointer behaviour \item Screen colours \item Window manager \end{itemize} \item All desktop environments and many window managers provide graphic tools for changing these configurations \item They can be set, on a system-wide or per-user basis, in the following two files: \item {\fn .xinitrc} \begin{itemize} \item to set the default window manager and style to be used by the {\pgn startx} command \end{itemize} \item {\fn $\sim$/.Xresources} or {\fn $\sim$/.Xdefaults} \begin{itemize} \item for fonts, pointers, colours, etc \item Read this file after changing it with {\cmdn xrdb $\sim$/.Xresources} \end{itemize} \end{itemize} \section{Networked X --- The Client-Server Relationship} \label{sec:networked-x-client-server} \begin{itemize} \item X works in a client-server relationship \item The client is a user application (e.g. {netscape}) which needs X services to display itself on a given screen \item The server is the application which provides these services, e.g. {\pgn Xfree86} \item On a single-user Linux system, both apps reside on the same system \item On a networked Linux system the user can run an X application which is installed on a remote system but see it displayed on the local monitor, i.e. \begin{itemize} \item The client application (e.g. {\pgn netscape}) is remote and the X server (e.g. {\pgn Xfree86}) is local \end{itemize} \end{itemize} \section{Principles of Running Remote X Apps} \label{sec:principles-of-running-remote-x-apps} \begin{itemize} \item The most common use for networked X is to run client apps which are installed on remote hosts \item Reasons for running X apps on remote hosts: \begin{itemize} \item Using graphical tools to administer a remote machine \item No local installation of the app \item Local processing or memory are insufficient \item No local access to data \end{itemize} \end{itemize} \section{How to Run Remote X Apps} \label{sec:how-to-run-remote-x-apps} The right way (and simplest way) to do this is to use {\pgn openssh} \begin{itemize} \item Simply type: \begin{alltt} $ slogin {\usb remotehost} \end{alltt}%$ \item \ldots then type any commands to start a graphical epplication in the terminal window; it just works. \end{itemize} The wrong way: \begin{itemize} \item Start the local x server: {\cmdn \$ startx} \item Enable (dangerous) lack of authentication {\cmdn \$ xhost +{\usb remote-hostname}} \item Open a telnet connection to the remote host: {\cmdn \$ telnet {\usb remote-hostname}} \item Set the your {\var \${}DISPLAY} {\kwd environment variable} on the remote host so that applications re-direct their graphic output to your local monitor: {\cmdn \$ export DISPLAY=oakleigh:0} \end{itemize} \section{Authentication} \label{sec:auth-x} \begin{itemize} \item Xservers only allow authenticated hosts to connect \item The right way to connect to a remote host is to use {\pgn openssh}. All the other methods described here are difficult, insecure, troublesome\ldots\ So don't use them. \item On a trusted LAN you might use {\pgn xhost} in an xterm \\ {\cmdn \$ xhost +beehive} \item Or edit {\fn /etc/X0.hosts} (0 refers to display 0): {\cmdn \begin{verbatim} $ cat /etc/X0.hosts landlord kebab samosa \end{verbatim}}%$ \item This is dangerous \begin{itemize} \item Allows hosts to grab your mouse and keyboard \end{itemize} \item {\em Only use in a trusted environment} \end{itemize} \section{Better Authentication} \label{sec:auth-x-better} \begin{itemize} \item Can use cookie-based authentication \item Done for you if using {\cmdn xdm} or {\cmdn ssh} \item Clients look in {\fn $\sim$/.Xauthority} for cookies to feed to server \item Server must be started with appropriate argument \begin{itemize} \item Reads {\em its} {\fn $\sim$/.Xauthority} file \end{itemize} \item Server only looks when started \begin{itemize} \item Too late to change once running \end{itemize} \item Both server and clients must use the same cookies \begin{itemize} \item Involves merging {\fn $\sim$/.Xauthority} files using {\pgn xauth} \end{itemize} \item Hard to manage --- most resort to {\cmdn xdm} for local access or {\cmdn ssh} for remote access. \item Documentation is not very penetrable; {\cmdn ssh} is much simpler to use, and is secure. \end{itemize} \section{Basic X Exercises} \label{sec:basic-x-exs} {\normalsize \begin{enumerate} \item Figure out how to get an X session running \item In an xterm window type {\cmdn 'xterm'} --- what happens? \item In an xterm window type \begin{quote} {\cmdn export DISPLAY=xyz xterm} \end{quote} what happens? \item Start up another xterm. \begin{enumerate} \item Type: \begin{quote} {\cmdn echo hello} \end{quote} You should get `hello' echoed. \item Select the {\cmdn echo hello} text so that it highlights --- do this by clicking the first mouse button and dragging. \item Move the mouse to another xterm window; click into it to make it active if necessary. \item You should be able to paste the selected text by clicking the middle mouse button (3 button mouse) or simultaneously clicking both buttons on a 2 button mouse. Try it and see. \end{enumerate} \item Find another machine on the same network. Use {\cmdn xhost} to tell it to accept connections from your machine. Start an xterm on your machine but tell it (using the {\cmdn DISPLAY} variable) to display on the remote machine. \pagebreak \item Go to the {\fn /usr/X11R6/bin} directory. Try these commands: {\cmdn \begin{verbatim} xeyes xsnow xfishtank xbill xdemineur xclock \end{verbatim}} and any others that you like the idea of. \end{enumerate} \label{endofchapter-basic-x} } % end {\normalsize} from exercises start } % end {\mns from chapter start %%% Local Variables: %%% mode: latex %%% TeX-master: "planet_basic_course_masterfile" %%% End: