Skip to content

Latest commit

 

History

History
441 lines (258 loc) · 9.35 KB

x11.md

File metadata and controls

441 lines (258 loc) · 9.35 KB

X11

Real name: X Window System.

X11 is a window system:

It is by far the most commonly used on Linux.

Alternatives: http://unix.stackexchange.com/questions/9608/lightweight-x11-alternative-available

X11 is only an interface.

There can be different implementations:

  • X.org implementation currently dominates
  • XFree86 was the dominant prior to 2004, when it adopted BSD license leaving GPL, and fell into oblivion.

X is an abstraction layer for things like:

  • windows
  • key presses
  • mouse position / presses
  • screen backlight

X does not:

  • relegates certain jobs to x display managers and X window managers.

  • panel

  • a desktop that shows files contained in some predefined folder. TODO who does that?

  • sound management

    This has been taken up by other projects:

    • PulseAudio
    • Advanced Linux Sound Architecture (ALSA)

Usually graphic accelerated. This is why messing with GPU settings may break your desktop.

X11 uses a server/client mode

Client and server can be on different machines

Client:

  • typically programs with a window
  • clients give commands to the X server and tell it to draw on screen
  • clients respond to input events via callback functions

Server:

  • creates the image

  • sends inputs events to clients who responds to it via callbacks

  • a server has many displays

  • a display has many screens, one mouse and one keyboard

  • to set the display to use use the DISPLAY var:

    env DISPLAY=localhost:0.1 firefox & #single commena
    

    Display notation: 0.1 means: display 0, screen 1

A good way to see some basic and useful application implemented in pure X as demos is to do ls /etc/X11/app-defaults

xorg

Dominant implementation of the X server.

Configuration file:

man xorg.conf

First of:

  • /etc/X11/<cmdline>
  • /tmp/Xorg-KEM/etc/X11/<cmdline>
  • /etc/X11/$XORGCONFIG
  • /tmp/Xorg-KEM/etc/X11/$XORGCONFIG
  • /etc/X11/xorg.conf-4
  • /etc/X11/xorg.conf
  • /etc/xorg.conf

where <cmdline> is specified on the command line at startup

Log file:

less /var/log/Xorg.0.log

where 0 is the display number.

X

Get X server version

sudo X -version

xhost

View and edit on which users may connect to an X server.

When you start with most desktop environments, they start the host as you.

If you su another-user, by default he cannot connect.

View current status:

xhost

Let any user connect:

xhost +

Let a single user connect:

xhost + another-user

xlsclients

List x clients.

This allows you to see all open windows.

xlsclients

More detailed info:

xlsclients -l

xmodmap

Modify key maps.

For example, to exchange ESC and Caps Lock:

f=~/.Xmodmap
echo "! Swap caps lock and escape
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock
" >> "$f"
xmodmap "$f"

To make this happen every time at startup TODO broken?:

echo "xmodmap \"$f\"
" >> ~/.xinitrc
chmod +x ~/.xinitrc

The ~/.xsession file could also be used depending on system

xsessionrc

TODO vs xinitrc?

xdotool

Send clicks and manage window properties from sh.

select window

Before you try to do things to a window, you must say which window you want to act on.

If you don't give any indication, actions occur on the current window.

Every window has a window id.

Act on windows with given id:

id=
xdotool search --window "$id" key ctrl+c

Act on windows with given name:

n=
xdotool search --name "$n" key ctrl+c

Name is exactly what is shown on window title bar.

keystrokes

Keystroke types:

  • key: up and down
  • keydown: only down
  • keyup: only up

Send an a keystroke to the current window:

xdotool key a

Send an a keystroke and then a b keystroke to the current window:

xdotool key a b

F2:

xdotool key F2

á:

xdotool key Aacute

ctrl+l:

xdotool key ctrl+l

Sends a, b, space, c and d:

xdotool type 'ab cd'

a, waits 1 ms, b:

xdotool type --delay 1 'ab'

sync

Wait for application to start before sending a command to it:

google-chrome &
xdotool search --sync --onlyvisible --class "google-chrome"x-terminal-emulator

In this way, you can launch an app and send commands, making sure they will be received!

keyboard and mouse automation

AutoKey

High level, GUI interface X11 automation.

xbacklight

Control screen brightness

Get current lightning level on a scale of 0 to 100:

xbacklight -get

Set lightning to 80%:

xbacklight -set 80

xrandr

Acronym for X Resize, rotate AND Reflect

Gets and sets screen properties such as screen resolution.

xrandr

Sample output:

Screen 0: minimum 320 x 200, current 1600 x 900, maximum 32767 x 32767
LVDS1 connected primary 1600x900+0+0 (normal left inverted right x axis y axis) 309mm x 174mm
   1600x900       60.0*+   40.0
   1440x900       59.9
   1360x768       59.8     60.0
   1152x864       60.0
   1024x768       60.0
   800x600        60.3     56.2
   640x480        59.9
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
LVDS-2 disconnected (normal left inverted right x axis y axis)
VGA-2 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)

TODO understand everything on this output.

This output lists the possible resolutions. Mine are: 1600x900 (current because of the *, default because of the +).

Change resolution:

xrandr -s 1360x769

the new resolution must be on the list.

Now:

xrandr

Outputs:

1600x900       60.0 +   40.0
1440x900       59.9
1360x768       59.8*    60.0
1152x864       60.0
1024x768       60.0
800x600        60.3     56.2
640x480        59.9

So the asterisk * gives the new resolution.

Change to default resolution (the one with the plus sign +):

xrandr -s 0

PRIMARY selection

CLIPBOARD

selection

X support an arbitrary number of selections.

The most important ones are widely implemented by default by most GUI systems:

  • PRIMARY: automatically updated to the last selected text.

    It can be pasted with a middle click.

  • CLIPBOARD: Ctrl + C, Ctrl + V mechanism.

Each selection contains data completely separate from the others.

Those concepts touched by freedesktop.org: http://freedesktop.org/wiki/Specifications/ClipboardsWiki/

xclip

Alternative tool to xsel.

xmodmap

View and modify key mappings.

Get a list of current keymapping state:

xmodmap -pke > ~/.Xmodmap

Sample output line:

keycode  24 = q Q q Q adiaeresis Adiaeresis
              ^ ^ ^ ^ ^^^^^^^^^^ ^^^^^^^^^^
              1 2 3 4 5          6
  1. no modifiers
  2. shift
  3. mode_switch no shift
  4. mode_switch + shift
  5. ?
  6. ?
  7. ?
  8. ?
  9. ?

AltGru is the mode_switch key.

Up to 8 keysyms bay be attached to each keycode.

However, only the first 4 are commonly used.

setxkblayout

TODO

setxkbmap

Swap ESC and CapsLock:

setxkbmap -option caps:escape

Put this in your ~/.xinitrc.

Simple GUI apps

Either for testing or useful utilities.

  • xcalc: simple scientific calculator
  • xedit: text editor
  • xeyes: fun X11 test program
  • xfontsel: point and click and view how a font looks like
  • xgc: X Graphics Demo. A GUI.
  • xlogo: a window with an X11 logo
  • xmag: magnifying lens
  • xmessage: zenity's grandfather
  • xmore: more for X
  • xtime: pointer clock
  • xterm: terminal

xev

Open a test window and prints X events description to stdout:

xterm
xev

Try clicking on the windows, or using your keyboard to see the outputs.

How to write a minimal window system

GUI without X

xinit

https://en.wikipedia.org/wiki/Xinit backend of startx

xinitrc

Sourced in Ubuntu 12.04, but not 14.04.

startx

http://askubuntu.com/questions/518454/what-does-startx-command-do/817747#817747

Script to start an graphical session.

Don't ever run sudo startx on an Ubuntu TTY!!! It will break your UI. Fix:

sudo apt-get install --reinstall ubuntu-desktop gdm unity
sudo mv /etc/X11/xorg.conf "/etc/X11/xorg.conf.$(date '+%Y-%m-%d-%H-%M-%S').bak"