mayfrost-guides/X.md

17 KiB

X

Set X and a desktop environment fast.

  1. INSTALLING X
  2. CONFIGURING X
    2.1. SCREEN RESOLUTION
    2.2. SCREEN TEARING
  3. FONTS
    3.1. CORE FONTS
    3.2. FONTCONFIG
  4. THEME
  5. NO DE
    5.1. XINITRC CONFIGURATION FILE
    5.2. LAUNCH X
    5.3. LAUNCH X AT LOGIN
  6. KEY BINDINGS
    6.1. GETTING KEYS INFORMATION
    6.2. XBINDKEYSRC CONFIGURATION FILE
  7. CLIPBOARD
    7.1. CLIPBOARD BINDINGS
  8. WINDOW MANAGER
    8.1. BASIC SHORTCUTS
    8.2. RATPOISONRC CONFIGURATION FILE

INSTALLING X

Generally it can be installed from the live CD or DVD or afterwards with the package manager. For example on CRUX:

  • Installing a minimal set of xorg and xorg dependent tools one by one (you must know which "DRIVER" you use)
    prtget depinst xorg-server xorg-xf86-video-<DRIVER> xorg-font-util xkeyboard-config xorg-xinit
  • Alternatively just install the metapackage "xorg"

CONFIGURING X

X can be configured for several things.

OPTION 1
You can generate a general configuration file containing all sorts of options and that will appear on your home directory and later move it to "/etc/X11/xorg.conf". You need to stop the X server and have root privileges for creating it.

  • Create a new configuration file "xorg.conf.new"
    Xorg -configure
  • change it to "/etc/X11/xorg.conf"
    mv /path/to/xorg.conf.new /etc/X11/xorg.conf
  • on other X versions the commands are
    XFree86 -configure
    XFree86 -xf86config /etc/X11/XF86Config.new

OPTION 2
Or you can create specific configuration files under the "/etc/X11/xorg.conf.d/" directory for particular cases.

SCREEN RESOLUTION

To make changes you generally don't need to know supported resolutions but it helps using defaults.

  • List currently supported resolutions (optional):
    xrandr
  • Generate a modeline:
    cvt <WIDTH> <HEIGHT> <REFRESH_RATE>
  • Use that ouput to add changes on the configuration file "/etc/X11/xorg.conf":
Section "Device"
        Identifier   "<DEVICE_NAME>"
        Driver       "<DRIVER_NAME>"
EndSection

Section "Monitor"
        Identifier	"<MONITOR_NAME>"
        Modeline        "<CVT_OUTPUT>
        Option    	"PreferredMode" "<THE_RESOLUTION_YOU_WANT>"
        Option          "Enable" "True"
EndSection

Section "Screen"
        Identifier	"<DEFAULT_SCREEN>"
        Monitor   	"<MONITOR_NAME>"
        Device          "<DEVICE_NAME>"
   SubSection "Display"
      Modes	  "<RESOLUTION_YOU_WANT>"
   EndSubSection
EndSection

In "Modes" the resolution you want can contain a framerate appended but needs to be exactly the same from the modeline. A full example configuration follows:

Section "Device"
    Identifier    "Device0"
    Driver        "Intel"
EndSection

Section "Monitor"
    Identifier    "HDMI1"
    Modeline "1280x720_60.00"   74.50  1280 1344 1472 1664  720 723 728 748 -hsync +vsync
    Option "PreferredMode" "1280x720"
    Option "Enable" "True"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Monitor        "HDMI1"
    Device         "Device0"
    SubSection "Display"
        Modes       "1280x720_60.00"
    EndSubSection
EndSection

Notice the framerate appended with an underscore in "Mode", this comes from "Modeline".

SCREEN TEARING

To solve screen tearing you can use any of these config files in its appropriate directory.

  • If you have Intel add these changes to "/etc/X11/xorg.conf" or in the separate file "/etc/X11/xorg.conf.d/20-intel.conf":
Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "TearFree"  "true"
EndSection
  • If you still have issues with Intel add a line with the option UXA:
Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "AccelMethod"  "uxa"
   Option      "TearFree" "true"
EndSection
  • If you have AMD add these changes to "/etc/X11/xorg.conf" or in the separate file "/etc/X11/xorg.conf.d/20-amdgpu.conf":
Section "Device"
   Identifier  "AMD Graphics"
   Driver      "amdgpu"
   Option      "TearFree"  "true"
EndSection

FONTS

There are two ways of adding fonts, with Fontconfig or with X core fonts. Make sure the fonts and the directory (and all of its parents) are world-readable:

  • The directory needs appropriate permissions.
    chmod 755 /path/to/fonts/
  • The fonts need appropriate permissions.
    chmod 644 /path/to/fonts/*
  • If the fonts are global they need to be owned by root.
    chown root:root /path/to/fonts/*

CORE FONTS

The next deals with core fonts.

  • Fonts can be added to the database on "/etc/X11/xorg.conf" or in the separate file "/etc/X11/xorg.conf.d/fonts.conf".
  • Supported font formats are BDF, binary PCF, and SNF.
  • Scalable fonts must appear in the font path before the bitmap fonts when possible.
  • You can query the current font paths (along with other information) by using xset:
    xset q
  • To see the list of installed fonts:
    xlsfonts
  • All this works for cursors too.

STEP 1: Create a font directory with font files and index files.

  • First you might need to correctly name scalable fonts by creating a fonts.scale file in the directory:
    mkfontscale /path/to/fonts/
  • Next create a proper font index file fonts.dir to list available fonts in this directory:
    mkfontdir /path/to/fonts/
  • The fonts.alias provides aliases you can use and is manually created.

STEP 2: Inform X where to look for font directories.

  • Edit "/etc/X11/xorg.conf" or in the separate file "/etc/X11/xorg.conf.d/fonts.conf":
Section "Files"
        FontPath     "/path/to/fonts/"
        FontPath     "/path/to/other/fonts/"
EndSection

Where "/path/to/fonts/" can be the default /usr/local/share/fonts/, a directory under /usr/local/share/fonts/, or any directory of your choosing.

STEP 3: Re-scan the font directories to apply new fonts.

  • Either restart X or reload using xset to apply changes:
    xset fp rehash

TEMPORARY CHANGES (OPTIONAL)
You can add fonts temporarily.

  • Temporarily add fonts first on the list:
    xset +fp /path/to/fonts
  • Temporarily add fonts last on the list:
    xset fp+ /path/to/fonts

TRUETYPE FONTS

  • To enable TrueType® fonts enable Freetype by adding the following line either to "/etc/X11/xorg.conf" or in the separate file "/etc/X11/xorg.conf.d/fonts.conf":
Section "Module"
	Load  "freetype"
EndSection

FONTCONFIG

The next deals with Fontconfig.

ADDING FONTS

  • Fonts added under:
    /usr/share/fonts/
  • or:
    /usr/local/share/fonts/
  • or locally under:
    ~/.fonts/
  • are automatically added after updating Fontconfig.

COMMANDS

  • To list fonts:
    fc-list
  • To show an ordered list of fonts matching a certain name or pattern:
    fc-match -s <NAME>
  • To update the list of fonts:
    fc-cache -fv
  • To update an specific directory:
    fc-cache /path/to/fonts/

GLOBAL CONFIGURATION

  • User generated system-wide changes are in:
    /etc/fonts/local.conf
  • or by replacing files under the directory:
    /etc/fonts/conf.d/
  • with symbolic links to files from:
    /etc/fonts/conf.avail/

The system-wide configuration file /etc/fonts/fonts.conf is generally not touched by the user.

LOCAL CONFIGURATION

  • User-specific configuration file (can be overridden with the "FONTCONFIG_FILE" environment variable):
    ~/.fonts.conf
  • or:
    ~/.config/fontconfig/fonts.conf
  • or making symbolic links of files from:
    /etc/fonts/conf.avail/
  • to:
    ~/.config/fontconfig/conf.d/

BITMAP FONTS The bitmap fonts may not be enabled by default on FONTCONFIG.

  • Remove current configuration:
    rm /etc/fonts/conf.d/70-no-bitmaps.conf
  • Create symbolic link to configuration enabling it:
    ln -s /etc/fonts/conf.avail/70-yes-bitmaps.conf /etc/fonts/conf.d/70-yes-bitmaps.conf

THEME

To tweak the theme of your terminal emulator you need to tweak the ".Xresources" file.

Next is an example ".Xresources" file which goes under your home directory:

xterm*maximized:	true
xterm*background:	black
xterm*foreground:	grey
xterm*cursorColor:	green
xterm*cursorBlink:	false
xterm*faceName:	Fixedsys Excelsior 3.01:size=11:antialias=true
xterm*faceNameDoublesize:	WenQuanYi Zen Hei
xterm*termName:	xterm-256color
xterm*locale:	true
xterm*utf8Title:	true
xterm*dynamicColors: true
xterm*borderWidth: 0
xterm*eightBitInput:   false
xterm*metaSendsEscape: true
xterm*decTerminalID:	vt340


urxvt*maximized:	true
urxvt*background:	black
urxvt*foreground:	white
urxvt*cursorColor:	green
urxvt*cursorBlink:	false
urxvt*faceName:	GNU Unifont:size=12:antialias=true
urxvt*faceNameDoublesize:	WenQuanYi Zen Hei
urxvt*termName:	urxvt-256color
urxvt*locale:	true
urxvt*utf8Title:	true
urxvt*font: fixed
urxvt*boldFont: fixed
urxvt*dynamicColors: true
urxvt*borderWidth: 0

To load changes run:
xrdb -merge ~/.Xresources

NO DE

To use a window manager without any desktop environment, or even a login manager, you can just install the applications mentioned here and edit the ".xinitrc" file with the appropriate changes and start "X" from the command line. The required applications are:

  • Ratpoison (or your preferred window manager in the ".xinitrc" file)
  • Xbindkeys
  • hsetroot or imagemagick (or replace with your preferred wallpaper changer in the ".xinitrc" file)
  • ImageMagick (or replace with your preferred screenshot program in the ".xinitrc" file)
  • FFmpeg or libav-tools (or replace with your preferred screencasting program in the ".xinitrc" file)
  • UXTerm or urxvt (in the case you want to set the terminal emulator theme with the ".Xresources" file)
  • dmenu

XINITRC CONFIGURATION FILE

Next is an example ".xinitrc" file which goes under your home directory:

# load your preferred terminal settings
xrdb -merge -I$HOME ~/.Xresources

# load your preferred keybindings
xbindkeys

# set the wallpaper (requires hsetroot to be installed)
hsetroot -fill ~/.wallpaper.jpg

# alternative way to set the wallpaper using imagemagick (DISABLED)
#display -size 1280x800 -window root ~/.wallpaper.png

# launch the window manager (needs to be done at the end)
exec dbus-launch --sh-syntax --exit-with-session ratpoison

LAUNCH X

After the configuration file is properly set, you login and type on the terminal:
startx
whenever you want to start X.

LAUNCH X AT LOGIN

To launch X at login, place the following at either your ".bash_profile" or ".bashrc" file:

if [ $(tty) = "/dev/tty1" ]
then
    startx > /dev/null 2>&1
fi

This will automatically launch "X" at the first "tty" ("virtual terminal"). If you are confused, to switch between ttys press "Ctrl-Alt-F<X>" (where "<X>" is a number). So to change to the tty with xorg you'll press "Ctrl-Alt-F1".

KEY BINDINGS

Custom keys can be added with the Xbindkeys program.

GETTING KEYS INFORMATION

With the help of the default xev program you can check the keys you want:

  • Start the program and type the key you want to see its information
    xev > keys.txt
  • Look for the line that says
    keycode KEY_NUMBER (keysym INGORE_THIS, KEY_NAME)
  • Now on ".xbindkeysrc" add the information for each bind:
"WHAT_YOU_WANT_HERE_GOES_HERE"
  m:0x0 + c:KEY_NUMBER
  KEY_NAME

XBINDKEYSRC CONFIGURATION FILE

In the example below we'll have the modified keys:

  • The "windows" key switch windows using dmenu pre-installed.
  • The "menu" key brings an application launcher you type names into using dmenu.
  • The "print screen" key takes a screenshot using imagemagick.
  • The "scroll lock" key records the desktop using either libav-tools or ffmpeg.
  • The "mute" button if available will mute/unmute volume.
  • The "lower volume" button if available will lower volume.
  • The "raise volume" button if available will raise volume.

Now the example ".xbindkeysrc" file which goes under your home directory:

# Enable "Scroll_Lock" for the next keybinding
keystate_scrolllock= enable

# Switch windows using the "windows key" (needs dmenu)
"ratpoison -c "select $(ratpoison -c "windows "%t"" | dmenu -nf gray -nb black -sf black -sb gray -b -l 20)""
  Super_L

# Launch application using the "menu key" (needs dmenu)
"dmenu_run -nf gray -nb black -sf black -sb gray -b"
  m:0x0 + c:135
  Menu

# Take screenshot using the "print screen key" (needs imagemagick)
"import -window root png:$HOME/x_$(date "+%Y-%m-%d-%H:%M:%S").png"
  m:0x0 + c:107
  Print

# Record desktop with avconv (libav-tools) or install ffmpeg and replace avconv
"killall -INT avconv 2>/dev/null || avconv -f x11grab -r 10 -s $(xrandr | grep '*' |  tr -s ' ' | cut -d ' ' -f2) -i :0.0 $HOME/x_$(date "+%Y-%m-%d-%H:%M:%S").mp4 &"
  m:0x0 + c:78
  Scroll_Lock

# Mute/unmute volume
"amixer set Master toggle"
  m:0x0 + c:121
  XF86AudioMute

# Lower volume
"amixer set PCM 5%-"
  m:0x0 + c:122
  XF86AudioLowerVolume

# Raise volume
"amixer set PCM 5%+"
  m:0x0 + c:123
  XF86AudioRaiseVolume

CLIPBOARD

"Xsel" with the help of "GNU Screen" will be used as intermediary between the terminal and "X". The following commands are examples we will replace by more simple bindings:

  • To paste from "X" clipboard
    xsel -ob
  • To copy to "X" clipboard from inside "GNU Screen"
    cat | xsel -ib
    Then hit "Ctrl-a + ]", then "Enter", then "Ctrl-d".

CLIPBOARD BINDINGS

For ease of use we will use "GNU Screen's" configuration file ".screenrc" to save shortcuts for clipboard exchange instead of the above commands. Save these in your ".screenrc" file:

# Copy from "GNU Screen" to "X" clipboard automatically when using "GNU Screen's" copy selection
bindkey -m ' ' eval 'stuff \040' 'writebuf' 'exec sh -c "xsel -ib < /tmp/screen-exchange"'

# Copy from "X" to "GNU Screen" clipboard by pressing "Ctr-a + b" + "Ctrl-a + ]" on "GNU Screen's" normal mode
bind b eval 'exec sh -c "xsel -ob > /tmp/screen-exchange && screen -X readbuf"'

WINDOW MANAGER

Productive, automated, scriptable, and minimal, Ratpoison is a strict tiling window manager using bindings similar to GNU Screen. A few of its benefits are.

  • No mouse used, all done by commands called by typing "control" and "t" at the same time, plus another key.
  • You can set your own bindings in the file ".ratpoisonrc" which is extremely friendly.
  • Extensible by scripts. The "rpws" script for example adds multiple workspaces (comes by default with Ratpoison), another script ("expose.pl") gives a mozaic of current windows.
  • Can temporarily switch to another window manager with the "tmpwm" command for your comfort.
  • Full manual available from the terminal:
    info ratpoison

BASIC SHORTCUTS

  • Show the help cheatsheet:
    Ctrl-t + ?

  • Bring an application menu:
    Ctrl-t + .

  • Get time and date:
    Ctrl-t + a

  • Clear screen from help cheatsheet or menu:
    Esc

  • Show open windows:
    Ctrl-t + w

  • Close a window:
    Ctrl-t + k

  • Swith back between windows:
    Ctrl-t + Ctrl-t

  • Go to next window:
    Ctrl-t + n
    Ctrl-t + Space

  • Go to previous window:
    Ctrl-t + p

  • Split screen vertically:
    Ctrl-t + s

  • Split screen horizontally:
    Ctrl-t + S

  • Go to next frame:
    Ctrl-t + Tab

  • Go to previous frame:
    Ctrl-t + Alt-Tab

  • Make a window the only one visible:
    Ctrl-t + Q

RATPOISONRC CONFIGURATION FILE

The next custom ".ratpoisonrc" file goes under your home directory and can be customized to your needs. It adds several goodies through scripts like an expose-like effect showing all windows on the screen arranged in a mozaic which you can choose by pressing the number from its tag:

# text editor
bind e exec gjots2
bind E exec xterm -e elvis

# web browser
bind y exec icecat
# highlight an url in a window and the url is opened in a new tab
bind Y exec icecat -new-tab `$RATPOISON -c getsel`

# MOC as a music player, alsamixer as volume control
bind o exec xterm -e mocp
bind O exec xterm -e alsamixer

# file manager
bind d exec spacefm
bind D exec xterm -e vifm

# mail
bind g exec xterm -e mutt

# IRC
bind h exec xterm -e irssi

# RSS
bind j exec liferea
bind J exec xterm -e newsbeuter

# password manager
bind z exec xterm -e kpcli

# looks for the JDownloader program under the designated path
bind Z exec ~/jd2/JDownloader2

# expose-like switch window by using "Ctrl-t + ,"
bind comma exec ~/bin/expose.pl

# as colon invoke ratpoison commands, semicolon invoke shell commands ("Ctrl-t + ;")
bind semicolon exec

# no startup message announcing what the prefix keys are
startup_message off

# change font, color and position for messages
set font "Fixed-11"
set fgcolor gray
set bgcolor black
set bargravity c

# normal cursor
exec xsetroot -cursor_name left_ptr

# fix java swing, needs wmname from suckless
exec wmname LG3D

# multiple workspaces by using "Alt + FX" (where "FX" is from F1 to F4), needs rpws script
exec rpws init 4 -k

# get rid of the one pixel border around windows
set border 0