X.md (17609B)
1 # X 2 Set __X__ and a desktop environment fast. 3 4 1. [INSTALLING X](#installing-x) 5 2. [CONFIGURING X](#configuring-x) 6 2.1. [SCREEN RESOLUTION](#screen-resolution) 7 2.2. [SCREEN TEARING](#screen-tearing) 8 3. [FONTS](#fonts) 9 3.1. [CORE FONTS](#core-fonts) 10 3.2. [FONTCONFIG](#fontconfig) 11 4. [THEME](theme) 12 5. [NO DE](#no-de) 13 5.1. [XINITRC CONFIGURATION FILE](#xinitrc-configuration-file) 14 5.2. [LAUNCH X](#launch-x) 15 5.3. [LAUNCH X AT LOGIN](#launch-x-at-login) 16 6. [KEY BINDINGS](#key-bindings) 17 6.1. [GETTING KEYS INFORMATION](#getting-keys-information) 18 6.2. [XBINDKEYSRC CONFIGURATION FILE](#xbindkeysrc-configuration-file) 19 7. [CLIPBOARD](#clipboard) 20 7.1. [CLIPBOARD BINDINGS](#clipboard-bindings) 21 8. [WINDOW MANAGER](#window-manager) 22 8.1. [BASIC SHORTCUTS](#basic-shortcuts) 23 8.2. [RATPOISONRC CONFIGURATION FILE](#ratpoisonrc-configuration-file) 24 25 ## INSTALLING X 26 Generally it can be installed from the live _CD or DVD_ or afterwards with the package manager. For example on __CRUX__: 27 * Installing a minimal set of xorg and xorg dependent tools one by one (you must know which _"DRIVER"_ you use) 28 `prtget depinst xorg-server xorg-xf86-video-<DRIVER> xorg-font-util xkeyboard-config xorg-xinit` 29 * Alternatively just install the metapackage _"xorg"_ 30 31 ## CONFIGURING X 32 __X__ can be configured for several things. 33 34 __OPTION 1__ 35 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. 36 * Create a new configuration file "xorg.conf.new" 37 `Xorg -configure` 38 * change it to _"/etc/X11/xorg.conf"_ 39 `mv /path/to/xorg.conf.new /etc/X11/xorg.conf` 40 * on other X versions the commands are 41 `XFree86 -configure` 42 `XFree86 -xf86config /etc/X11/XF86Config.new` 43 44 __OPTION 2__ 45 Or you can create specific configuration files under the _"/etc/X11/xorg.conf.d/"_ directory for particular cases. 46 47 ### SCREEN RESOLUTION 48 To make changes you generally don't need to know supported resolutions but it helps using defaults. 49 * List currently supported resolutions (optional): 50 `xrandr` 51 * Generate a modeline: 52 `cvt <WIDTH> <HEIGHT> <REFRESH_RATE>` 53 * Use that ouput to add changes on the configuration file _"/etc/X11/xorg.conf"_: 54 ``` 55 Section "Device" 56 Identifier "<DEVICE_NAME>" 57 Driver "<DRIVER_NAME>" 58 EndSection 59 60 Section "Monitor" 61 Identifier "<MONITOR_NAME>" 62 Modeline "<CVT_OUTPUT> 63 Option "PreferredMode" "<THE_RESOLUTION_YOU_WANT>" 64 Option "Enable" "True" 65 EndSection 66 67 Section "Screen" 68 Identifier "<DEFAULT_SCREEN>" 69 Monitor "<MONITOR_NAME>" 70 Device "<DEVICE_NAME>" 71 SubSection "Display" 72 Modes "<RESOLUTION_YOU_WANT>" 73 EndSubSection 74 EndSection 75 ``` 76 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: 77 ``` 78 Section "Device" 79 Identifier "Device0" 80 Driver "Intel" 81 EndSection 82 83 Section "Monitor" 84 Identifier "HDMI1" 85 Modeline "1280x720_60.00" 74.50 1280 1344 1472 1664 720 723 728 748 -hsync +vsync 86 Option "PreferredMode" "1280x720" 87 Option "Enable" "True" 88 EndSection 89 90 Section "Screen" 91 Identifier "Screen0" 92 Monitor "HDMI1" 93 Device "Device0" 94 SubSection "Display" 95 Modes "1280x720_60.00" 96 EndSubSection 97 EndSection 98 99 ``` 100 Notice the framerate appended with an underscore in _"Mode"_, this comes from _"Modeline"_. 101 102 ### SCREEN TEARING 103 To solve screen tearing you can use any of these config files in its appropriate directory. 104 105 * 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"_: 106 ``` 107 Section "Device" 108 Identifier "Intel Graphics" 109 Driver "intel" 110 Option "TearFree" "true" 111 EndSection 112 ``` 113 114 * If you still have issues with Intel add a line with the option _UXA_: 115 ``` 116 Section "Device" 117 Identifier "Intel Graphics" 118 Driver "intel" 119 Option "AccelMethod" "uxa" 120 Option "TearFree" "true" 121 EndSection 122 ``` 123 124 * 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_": 125 ``` 126 Section "Device" 127 Identifier "AMD Graphics" 128 Driver "amdgpu" 129 Option "TearFree" "true" 130 EndSection 131 ``` 132 133 ## FONTS 134 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: 135 * The directory needs appropriate permissions. 136 `chmod 755 /path/to/fonts/` 137 * The fonts need appropriate permissions. 138 `chmod 644 /path/to/fonts/*` 139 * If the fonts are global they need to be owned by root. 140 `chown root:root /path/to/fonts/*` 141 142 ### CORE FONTS 143 The next deals with core fonts. 144 * Fonts can be added to the database on _"/etc/X11/xorg.conf"_ or in the separate file _"/etc/X11/xorg.conf.d/fonts.conf_". 145 * Supported font formats are _BDF_, binary _PCF_, and _SNF_. 146 * Scalable fonts must appear in the font path before the bitmap fonts when possible. 147 * You can query the current _font paths_ (along with other information) by using __xset__: 148 `xset q` 149 * To see the list of installed fonts: 150 `xlsfonts` 151 * All this works for cursors too. 152 153 __STEP 1__: Create a font directory with font files and index files. 154 * First you might need to correctly name scalable fonts by creating a _fonts.scale_ file in the directory: 155 `mkfontscale /path/to/fonts/` 156 * Next create a proper font index file _fonts.dir_ to list available fonts in this directory: 157 `mkfontdir /path/to/fonts/` 158 * The _fonts.alias_ provides aliases you can use and is manually created. 159 160 __STEP 2__: Inform __X__ where to look for font directories. 161 * Edit _"/etc/X11/xorg.conf"_ or in the separate file _"/etc/X11/xorg.conf.d/fonts.conf"_: 162 ``` 163 Section "Files" 164 FontPath "/path/to/fonts/" 165 FontPath "/path/to/other/fonts/" 166 EndSection 167 ``` 168 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. 169 170 __STEP 3__: Re-scan the font directories to apply new fonts. 171 * Either restart __X__ or reload using _xset_ to apply changes: 172 `xset fp rehash` 173 174 __TEMPORARY CHANGES (OPTIONAL)__ 175 You can add fonts temporarily. 176 * Temporarily add fonts first on the list: 177 `xset +fp /path/to/fonts` 178 * Temporarily add fonts last on the list: 179 `xset fp+ /path/to/fonts` 180 181 __TRUETYPE FONTS__ 182 * 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"_: 183 ``` 184 Section "Module" 185 Load "freetype" 186 EndSection 187 ``` 188 189 ### FONTCONFIG 190 The next deals with __Fontconfig__. 191 192 __ADDING FONTS__ 193 * Fonts added under: 194 `/usr/share/fonts/` 195 * or: 196 `/usr/local/share/fonts/` 197 * or locally under: 198 `~/.fonts/` 199 * are automatically added after updating __Fontconfig__. 200 201 __COMMANDS__ 202 * To list fonts: 203 `fc-list` 204 * To show an ordered list of fonts matching a certain name or pattern: 205 `fc-match -s <NAME>` 206 * To update the list of fonts: 207 `fc-cache -fv` 208 * To update an specific directory: 209 `fc-cache /path/to/fonts/` 210 211 __GLOBAL CONFIGURATION__ 212 * User generated system-wide changes are in: 213 `/etc/fonts/local.conf` 214 * or by replacing files under the directory: 215 `/etc/fonts/conf.d/` 216 * with symbolic links to files from: 217 `/etc/fonts/conf.avail/` 218 219 The system-wide configuration file _/etc/fonts/fonts.conf_ is generally not touched by the user. 220 221 __LOCAL CONFIGURATION__ 222 * User-specific configuration file (can be overridden with the "FONTCONFIG_FILE" environment variable): 223 `~/.fonts.conf` 224 * or: 225 `~/.config/fontconfig/fonts.conf` 226 * or making symbolic links of files from: 227 `/etc/fonts/conf.avail/` 228 * to: 229 `~/.config/fontconfig/conf.d/` 230 231 __BITMAP FONTS__ 232 The bitmap fonts may not be enabled by default on __FONTCONFIG__. 233 * Remove current configuration: 234 `rm /etc/fonts/conf.d/70-no-bitmaps.conf` 235 * Create symbolic link to configuration enabling it: 236 `ln -s /etc/fonts/conf.avail/70-yes-bitmaps.conf /etc/fonts/conf.d/70-yes-bitmaps.conf` 237 238 ## THEME 239 To tweak the theme of your terminal emulator you need to tweak the _".Xresources"_ file. 240 241 Next is an example _".Xresources"_ file which goes under your home directory: 242 ``` 243 xterm*maximized: true 244 xterm*background: black 245 xterm*foreground: grey 246 xterm*cursorColor: green 247 xterm*cursorBlink: false 248 xterm*faceName: Fixedsys Excelsior 3.01:size=11:antialias=true 249 xterm*faceNameDoublesize: WenQuanYi Zen Hei 250 xterm*termName: xterm-256color 251 xterm*locale: true 252 xterm*utf8Title: true 253 xterm*dynamicColors: true 254 xterm*borderWidth: 0 255 xterm*eightBitInput: false 256 xterm*metaSendsEscape: true 257 xterm*decTerminalID: vt340 258 259 260 urxvt*maximized: true 261 urxvt*background: black 262 urxvt*foreground: white 263 urxvt*cursorColor: green 264 urxvt*cursorBlink: false 265 urxvt*faceName: GNU Unifont:size=12:antialias=true 266 urxvt*faceNameDoublesize: WenQuanYi Zen Hei 267 urxvt*termName: urxvt-256color 268 urxvt*locale: true 269 urxvt*utf8Title: true 270 urxvt*font: fixed 271 urxvt*boldFont: fixed 272 urxvt*dynamicColors: true 273 urxvt*borderWidth: 0 274 ``` 275 276 To load changes run: 277 `xrdb -merge ~/.Xresources` 278 279 ## NO DE 280 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: 281 * Ratpoison (or your preferred window manager in the _".xinitrc"_ file) 282 * Xbindkeys 283 * hsetroot or imagemagick (or replace with your preferred wallpaper changer in the _".xinitrc"_ file) 284 * ImageMagick (or replace with your preferred screenshot program in the _".xinitrc"_ file) 285 * FFmpeg or libav-tools (or replace with your preferred screencasting program in the _".xinitrc"_ file) 286 * UXTerm or urxvt (in the case you want to set the terminal emulator theme with the _".Xresources"_ file) 287 * dmenu 288 289 ### XINITRC CONFIGURATION FILE 290 Next is an example _".xinitrc"_ file which goes under your home directory: 291 ``` 292 # load your preferred terminal settings 293 xrdb -merge -I$HOME ~/.Xresources 294 295 # load your preferred keybindings 296 xbindkeys 297 298 # set the wallpaper (requires hsetroot to be installed) 299 hsetroot -fill ~/.wallpaper.jpg 300 301 # alternative way to set the wallpaper using imagemagick (DISABLED) 302 #display -size 1280x800 -window root ~/.wallpaper.png 303 304 # launch the window manager (needs to be done at the end) 305 exec dbus-launch --sh-syntax --exit-with-session ratpoison 306 ``` 307 ### LAUNCH X 308 After the configuration file is properly set, you login and type on the terminal: 309 `startx` 310 whenever you want to start X. 311 312 ### LAUNCH X AT LOGIN 313 To launch X at login, place the following at either your _".bash_profile"_ or _".bashrc"_ file: 314 ``` 315 if [ $(tty) = "/dev/tty1" ] 316 then 317 startx > /dev/null 2>&1 318 fi 319 ``` 320 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"_. 321 322 ## KEY BINDINGS 323 Custom keys can be added with the __Xbindkeys__ program. 324 325 ### GETTING KEYS INFORMATION 326 With the help of the default xev program you can check the keys you want: 327 * Start the program and type the key you want to see its information 328 `xev > keys.txt` 329 * Look for the line that says 330 `keycode KEY_NUMBER (keysym INGORE_THIS, KEY_NAME)` 331 * Now on _".xbindkeysrc"_ add the information for each bind: 332 ``` 333 "WHAT_YOU_WANT_HERE_GOES_HERE" 334 m:0x0 + c:KEY_NUMBER 335 KEY_NAME 336 ``` 337 338 ### XBINDKEYSRC CONFIGURATION FILE 339 In the example below we'll have the modified keys: 340 * The "windows" key switch windows using dmenu pre-installed. 341 * The "menu" key brings an application launcher you type names into using dmenu. 342 * The "print screen" key takes a screenshot using imagemagick. 343 * The "scroll lock" key records the desktop using either libav-tools or ffmpeg. 344 * The "mute" button if available will mute/unmute volume. 345 * The "lower volume" button if available will lower volume. 346 * The "raise volume" button if available will raise volume. 347 348 Now the example _".xbindkeysrc"_ file which goes under your home directory: 349 ``` 350 # Enable "Scroll_Lock" for the next keybinding 351 keystate_scrolllock= enable 352 353 # Switch windows using the "windows key" (needs dmenu) 354 "ratpoison -c "select $(ratpoison -c "windows "%t"" | dmenu -nf gray -nb black -sf black -sb gray -b -l 20)"" 355 Super_L 356 357 # Launch application using the "menu key" (needs dmenu) 358 "dmenu_run -nf gray -nb black -sf black -sb gray -b" 359 m:0x0 + c:135 360 Menu 361 362 # Take screenshot using the "print screen key" (needs imagemagick) 363 "import -window root png:$HOME/x_$(date "+%Y-%m-%d-%H:%M:%S").png" 364 m:0x0 + c:107 365 Print 366 367 # Record desktop with avconv (libav-tools) or install ffmpeg and replace avconv 368 "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 &" 369 m:0x0 + c:78 370 Scroll_Lock 371 372 # Mute/unmute volume 373 "amixer set Master toggle" 374 m:0x0 + c:121 375 XF86AudioMute 376 377 # Lower volume 378 "amixer set PCM 5%-" 379 m:0x0 + c:122 380 XF86AudioLowerVolume 381 382 # Raise volume 383 "amixer set PCM 5%+" 384 m:0x0 + c:123 385 XF86AudioRaiseVolume 386 ``` 387 388 ## CLIPBOARD 389 _"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: 390 * To paste from _"X"_ clipboard 391 `xsel -ob` 392 * To copy to _"X"_ clipboard from inside _"GNU Screen"_ 393 `cat | xsel -ib` 394 Then hit _"Ctrl-a + ]"_, then _"Enter"_, then _"Ctrl-d"_. 395 396 ### CLIPBOARD BINDINGS 397 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: 398 ``` 399 # Copy from "GNU Screen" to "X" clipboard automatically when using "GNU Screen's" copy selection 400 bindkey -m ' ' eval 'stuff \040' 'writebuf' 'exec sh -c "xsel -ib < /tmp/screen-exchange"' 401 402 # Copy from "X" to "GNU Screen" clipboard by pressing "Ctr-a + b" + "Ctrl-a + ]" on "GNU Screen's" normal mode 403 bind b eval 'exec sh -c "xsel -ob > /tmp/screen-exchange && screen -X readbuf"' 404 ``` 405 406 ## WINDOW MANAGER 407 Productive, automated, scriptable, and minimal, __Ratpoison__ is a strict tiling window manager using bindings similar to GNU Screen. A few of its benefits are. 408 * No mouse used, all done by commands called by typing _"control"_ and _"t"_ at the same time, plus another key. 409 * You can set your own bindings in the file _".ratpoisonrc"_ which is extremely friendly. 410 * Extensible by [scripts](http://ratpoison.wxcvbn.org/cgi-bin/wiki.pl/Scripts). The _"rpws"_ script for example adds multiple workspaces (comes by default with Ratpoison), another script (_"[expose.pl](http://ratpoison.wxcvbn.org/cgi-bin/wiki.pl/expose.pl)"_) gives a mozaic of current windows. 411 * Can temporarily switch to another window manager with the _"tmpwm"_ command for your comfort. 412 * Full manual available from the terminal: 413 `info ratpoison` 414 415 ### BASIC SHORTCUTS 416 * Show the help cheatsheet: 417 `Ctrl-t + ?` 418 * Bring an application menu: 419 `Ctrl-t + .` 420 * Get time and date: 421 `Ctrl-t + a` 422 * Clear screen from help cheatsheet or menu: 423 `Esc` 424 425 * Show open windows: 426 `Ctrl-t + w` 427 * Close a window: 428 `Ctrl-t + k` 429 * Swith back between windows: 430 `Ctrl-t + Ctrl-t` 431 * Go to next window: 432 `Ctrl-t + n` 433 `Ctrl-t + Space` 434 * Go to previous window: 435 `Ctrl-t + p` 436 437 438 * Split screen vertically: 439 `Ctrl-t + s` 440 * Split screen horizontally: 441 `Ctrl-t + S` 442 * Go to next frame: 443 `Ctrl-t + Tab` 444 * Go to previous frame: 445 `Ctrl-t + Alt-Tab` 446 * Make a window the only one visible: 447 `Ctrl-t + Q` 448 449 ### RATPOISONRC CONFIGURATION FILE 450 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: 451 ``` 452 # text editor 453 bind e exec gjots2 454 bind E exec xterm -e elvis 455 456 # web browser 457 bind y exec icecat 458 # highlight an url in a window and the url is opened in a new tab 459 bind Y exec icecat -new-tab `$RATPOISON -c getsel` 460 461 # MOC as a music player, alsamixer as volume control 462 bind o exec xterm -e mocp 463 bind O exec xterm -e alsamixer 464 465 # file manager 466 bind d exec spacefm 467 bind D exec xterm -e vifm 468 469 # mail 470 bind g exec xterm -e mutt 471 472 # IRC 473 bind h exec xterm -e irssi 474 475 # RSS 476 bind j exec liferea 477 bind J exec xterm -e newsbeuter 478 479 # password manager 480 bind z exec xterm -e kpcli 481 482 # looks for the JDownloader program under the designated path 483 bind Z exec ~/jd2/JDownloader2 484 485 # expose-like switch window by using "Ctrl-t + ," 486 bind comma exec ~/bin/expose.pl 487 488 # as colon invoke ratpoison commands, semicolon invoke shell commands ("Ctrl-t + ;") 489 bind semicolon exec 490 491 # no startup message announcing what the prefix keys are 492 startup_message off 493 494 # change font, color and position for messages 495 set font "Fixed-11" 496 set fgcolor gray 497 set bgcolor black 498 set bargravity c 499 500 # normal cursor 501 exec xsetroot -cursor_name left_ptr 502 503 # fix java swing, needs wmname from suckless 504 exec wmname LG3D 505 506 # multiple workspaces by using "Alt + FX" (where "FX" is from F1 to F4), needs rpws script 507 exec rpws init 4 -k 508 509 # get rid of the one pixel border around windows 510 set border 0 511 ```