🏗️ Installing xmonad Window Manager on Alpine Linux: Tiling Mastery Guide
Let’s install and configure xmonad, the powerful tiling window manager on Alpine Linux! 🚀 This comprehensive tutorial shows you how to set up an efficient, keyboard-driven desktop environment that maximizes productivity. Perfect for developers and power users who love minimalist, functional interfaces! 😊
🤔 What is xmonad?
xmonad is a minimalist, dynamically tiling window manager written in Haskell that automatically organizes windows without overlapping, maximizing screen real estate and productivity!
xmonad is like:
- 🧩 Smart puzzle solver that perfectly arranges all your windows
- ⌨️ Keyboard virtuoso that responds to every shortcut instantly
- 🏗️ Efficient architect that builds the perfect workspace layout
🎯 What You Need
Before we start, you need:
- ✅ Alpine Linux system with X11 support
- ✅ Basic understanding of tiling window managers
- ✅ Familiarity with keyboard shortcuts and terminal usage
- ✅ Root access for package installation
📋 Step 1: Install X11 and Display Components
Install X.Org Server and Dependencies
Let’s set up the X11 display server foundation! 😊
What we’re doing: Installing X.Org server and essential display components for running xmonad window manager.
# Update package list
apk update
# Install X.Org server and essential components
apk add xorg-server xorg-server-xvfb xorg-server-xnest
# Install X11 applications and utilities
apk add xinit xauth xrandr xset
# Install display drivers (choose based on your hardware)
apk add xf86-video-vesa # Generic VESA driver (works everywhere)
apk add xf86-video-intel # Intel graphics
apk add xf86-video-amdgpu # AMD graphics
apk add xf86-video-nouveau # NVIDIA open source
# Install input drivers
apk add xf86-input-evdev xf86-input-libinput
apk add xf86-input-keyboard xf86-input-mouse
# Install fonts for better display
apk add font-noto font-noto-cjk font-noto-emoji
apk add font-awesome font-dejavu
# Check X11 installation
Xorg -version
echo "X11 display server installed! 🖥️"
What this does: 📖 Installs complete X11 display system required for graphical applications.
Example output:
X.Org X Server 1.21.1
X Protocol Version 11, Revision 0
What this means: X11 display server is ready for window manager installation! ✅
Configure X11 Display Settings
Let’s configure X11 for optimal xmonad performance! 🎯
What we’re doing: Setting up X11 configuration files and display settings for smooth xmonad operation.
# Create X11 configuration directory
mkdir -p /etc/X11/xorg.conf.d
# Create basic X11 configuration
cat > /etc/X11/xorg.conf.d/20-keyboard.conf << 'EOF'
# Keyboard Configuration
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "us"
Option "XkbModel" "pc105"
Option "XkbOptions" "terminate:ctrl_alt_bksp"
EndSection
EOF
# Create mouse configuration
cat > /etc/X11/xorg.conf.d/30-mouse.conf << 'EOF'
# Mouse Configuration
Section "InputClass"
Identifier "system-mouse"
MatchIsPointer "on"
Driver "libinput"
Option "AccelProfile" "flat"
Option "AccelSpeed" "0"
EndSection
EOF
# Create touchpad configuration (for laptops)
cat > /etc/X11/xorg.conf.d/40-touchpad.conf << 'EOF'
# Touchpad Configuration
Section "InputClass"
Identifier "system-touchpad"
MatchIsTouchpad "on"
Driver "libinput"
Option "Tapping" "on"
Option "TappingDrag" "on"
Option "DisableWhileTyping" "on"
Option "NaturalScrolling" "true"
EndSection
EOF
# Create display configuration
cat > /etc/X11/xorg.conf.d/50-display.conf << 'EOF'
# Display Configuration
Section "Monitor"
Identifier "Monitor0"
Option "DPMS" "true"
EndSection
Section "Device"
Identifier "Card0"
Driver "vesa" # Change to your specific driver if needed
Option "AccelMethod" "glamor"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1920x1080" "1680x1050" "1280x1024" "1024x768"
EndSubSection
EndSection
EOF
# Test X11 configuration
Xorg -configure -retro
echo "X11 configured for xmonad! ⚙️"
What this creates: Optimal X11 configuration for tiling window manager performance! ✅
🔧 Step 2: Install xmonad and Haskell Environment
Install Haskell and xmonad
Let’s install xmonad and its Haskell dependencies! 🏗️
What we’re doing: Installing xmonad window manager with complete Haskell toolchain for customization.
# Install Haskell and development tools
apk add ghc cabal stack
# Install xmonad and related packages
apk add xmonad xmonad-contrib
# Install additional window manager utilities
apk add dmenu xmobar trayer
# Install terminal emulator (essential for xmonad)
apk add xterm st
# Install essential applications
apk add firefox-esr thunar
# Install text editor for configuration
apk add vim nano
# Check xmonad installation
xmonad --version
# Check Haskell compiler
ghc --version
echo "xmonad and Haskell environment installed! 🎉"
What this does: Installs complete xmonad environment with development tools! ✅
Example output:
xmonad 0.17.0
The Glorious Glasgow Haskell Compilation System, version 9.2.7
What this means: xmonad is ready for configuration and customization! 🌟
Create Basic xmonad Configuration
Let’s create a functional xmonad configuration! 🎮
What we’re doing: Creating comprehensive xmonad configuration with productivity-focused keybindings and layouts.
# Create user configuration directory
mkdir -p ~/.xmonad
# Create basic xmonad configuration
cat > ~/.xmonad/xmonad.hs << 'EOF'
-- xmonad Configuration for Alpine Linux
-- Productivity-focused tiling window manager setup
import XMonad
import XMonad.Config.Desktop
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.SetWMName
import XMonad.Layout.Spacing
import XMonad.Layout.Gaps
import XMonad.Layout.NoBorders
import XMonad.Layout.Fullscreen
import XMonad.Layout.Circle
import XMonad.Layout.Grid
import XMonad.Layout.Spiral
import XMonad.Layout.ThreeColumns
import XMonad.Layout.Mosaic
import XMonad.Layout.Cross
import XMonad.Util.Run
import XMonad.Util.SpawnOnce
import XMonad.Actions.CycleWS
import XMonad.Actions.GridSelect
import XMonad.Actions.UpdatePointer
import Data.Monoid
import System.Exit
import qualified XMonad.StackSet as W
import qualified Data.Map as M
-- Define terminal and modMask
myTerminal = "xterm"
myModMask = mod4Mask -- Use Super/Windows key
-- Workspaces configuration
myWorkspaces = ["1:term","2:web","3:code","4:files","5:media","6:comm","7:sys","8:misc","9:tmp"]
-- Border configuration
myBorderWidth = 2
myNormalBorderColor = "#2e3440"
myFocusedBorderColor = "#88c0d0"
-- Key bindings configuration
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
-- Launch applications
[ ((modm, xK_Return), spawn $ XMonad.terminal conf)
, ((modm, xK_d ), spawn "dmenu_run -fn 'Noto Sans-10'")
, ((modm, xK_f ), spawn "firefox")
, ((modm, xK_e ), spawn "thunar")
-- Close windows
, ((modm .|. shiftMask, xK_c ), kill)
-- Layout management
, ((modm, xK_space ), sendMessage NextLayout)
, ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
, ((modm, xK_n ), refresh)
-- Window focus
, ((modm, xK_Tab ), windows W.focusDown)
, ((modm, xK_j ), windows W.focusDown)
, ((modm, xK_k ), windows W.focusUp)
, ((modm, xK_m ), windows W.focusMaster)
-- Window swapping
, ((modm .|. shiftMask, xK_Return), windows W.swapMaster)
, ((modm .|. shiftMask, xK_j ), windows W.swapDown)
, ((modm .|. shiftMask, xK_k ), windows W.swapUp)
-- Window resizing
, ((modm, xK_h ), sendMessage Shrink)
, ((modm, xK_l ), sendMessage Expand)
, ((modm, xK_t ), withFocused $ windows . W.sink)
-- Master area management
, ((modm , xK_comma ), sendMessage (IncMasterN 1))
, ((modm , xK_period), sendMessage (IncMasterN (-1)))
-- Workspace navigation
, ((modm, xK_Right ), nextWS)
, ((modm, xK_Left ), prevWS)
, ((modm .|. shiftMask, xK_Right ), shiftToNext >> nextWS)
, ((modm .|. shiftMask, xK_Left ), shiftToPrev >> prevWS)
-- Grid select
, ((modm, xK_g ), goToSelected defaultGSConfig)
-- System controls
, ((modm .|. shiftMask, xK_q ), io (exitWith ExitSuccess))
, ((modm , xK_q ), spawn "xmonad --recompile; xmonad --restart")
-- Volume controls (if available)
, ((0, 0x1008ff11), spawn "amixer -q sset Master 5%-")
, ((0, 0x1008ff13), spawn "amixer -q sset Master 5%+")
, ((0, 0x1008ff12), spawn "amixer -q sset Master toggle")
-- Brightness controls (if available)
, ((0, 0x1008ff02), spawn "xrandr --output eDP-1 --brightness $(echo \"$(xrandr --verbose | grep -i brightness | head -1 | cut -d' ' -f2) + 0.1\" | bc -l)")
, ((0, 0x1008ff03), spawn "xrandr --output eDP-1 --brightness $(echo \"$(xrandr --verbose | grep -i brightness | head -1 | cut -d' ' -f2) - 0.1\" | bc -l)")
]
++
-- Workspace switching and moving windows
[((m .|. modm, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
-- Mouse bindings
myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
[ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
>> windows W.shiftMaster))
, ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
, ((modm, button3), (\w -> focus w >> mouseResizeWindow w
>> windows W.shiftMaster))
]
-- Layout configuration
myLayout = avoidStruts $ smartBorders $
spacing 5 $ gaps [(U,5), (D,5), (R,5), (L,5)] $
tiled ||| Mirror tiled ||| Full ||| Grid ||| spiral (6/7) ||| ThreeColMid 1 (3/100) (1/2)
where
tiled = Tall nmaster delta ratio
nmaster = 1
ratio = 1/2
delta = 3/100
-- Window management rules
myManageHook = composeAll
[ className =? "Firefox" --> doShift "2:web"
, className =? "Thunar" --> doShift "4:files"
, className =? "VLC" --> doShift "5:media"
, className =? "Discord" --> doShift "6:comm"
, className =? "Steam" --> doShift "5:media"
, resource =? "desktop_window" --> doIgnore
, resource =? "kdesktop" --> doIgnore
, className =? "Dmenu" --> doFloat
, isFullscreen --> doFullFloat
] <+> manageDocks
-- Event handling
myEventHook = ewmhDesktopsEventHook <+> fullscreenEventHook
-- Log hook for status bar
myLogHook = updatePointer (0.5, 0.5) (0, 0)
-- Startup hook
myStartupHook = do
spawnOnce "trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --width 10 --transparent true --alpha 0 --tint 0x000000 --height 22 &"
spawnOnce "feh --bg-scale ~/.xmonad/wallpaper.jpg"
setWMName "LG3D"
-- Main configuration
main = do
xmproc <- spawnPipe "xmobar ~/.xmonad/xmobarrc"
xmonad $ ewmh $ docks $ desktopConfig
{ terminal = myTerminal
, focusFollowsMouse = True
, clickJustFocuses = False
, borderWidth = myBorderWidth
, modMask = myModMask
, workspaces = myWorkspaces
, normalBorderColor = myNormalBorderColor
, focusedBorderColor = myFocusedBorderColor
, keys = myKeys
, mouseBindings = myMouseBindings
, layoutHook = myLayout
, manageHook = myManageHook
, handleEventHook = myEventHook
, logHook = myLogHook <+> dynamicLogWithPP xmobarPP
{ ppOutput = hPutStrLn xmproc
, ppTitle = xmobarColor "green" "" . shorten 50
, ppCurrent = xmobarColor "yellow" "" . wrap "[" "]"
, ppSep = " : "
}
, startupHook = myStartupHook
}
EOF
echo "xmonad configuration created! 🔧"
What this creates: Comprehensive xmonad configuration with productivity features! 🌟
Create xmobar Status Bar Configuration
Let’s create a beautiful status bar for xmonad! 📊
What we’re doing: Configuring xmobar status bar with system information and workspace indicators.
# Create xmobar configuration
cat > ~/.xmonad/xmobarrc << 'EOF'
-- xmobar Configuration for Alpine Linux
Config {
font = "xft:Noto Sans:size=10:bold:antialias=true"
, additionalFonts =
[ "xft:Font Awesome 5 Free Solid:size=10"
, "xft:Noto Sans CJK JP:size=10"
]
-- Appearance
, bgColor = "#2e3440"
, fgColor = "#d8dee9"
, alpha = 255
, position = TopW L 90
-- Layout
, sepChar = "%"
, alignSep = "}{"
, template = " %StdinReader% }{ %multicpu% | %memory% | %dynnetwork% | %battery% | %date% | %uname% "
-- Plugins
, commands =
[ Run StdinReader
-- CPU monitor
, Run MultiCpu
[ "--template" , "<fn=1>\xf2db</fn> <total0>%|<total1>%"
, "--Low" , "50"
, "--High" , "85"
, "--low" , "#a3be8c"
, "--normal" , "#ebcb8b"
, "--high" , "#bf616a"
] 10
-- Memory monitor
, Run Memory
[ "--template" , "<fn=1>\xf538</fn> <usedratio>%"
, "--Low" , "20"
, "--High" , "90"
, "--low" , "#a3be8c"
, "--normal" , "#ebcb8b"
, "--high" , "#bf616a"
] 10
-- Network monitor
, Run DynNetwork
[ "--template" , "<fn=1>\xf0aa</fn> <tx>kB/s|<rx>kB/s"
, "--Low" , "1000"
, "--High" , "5000"
, "--low" , "#a3be8c"
, "--normal" , "#ebcb8b"
, "--high" , "#bf616a"
] 10
-- Battery monitor
, Run Battery
[ "--template" , "<fn=1>\xf241</fn> <acstatus>"
, "--Low" , "10"
, "--High" , "80"
, "--low" , "#bf616a"
, "--normal" , "#ebcb8b"
, "--high" , "#a3be8c"
, "--"
, "-o" , "<left>% (<timeleft>)"
, "-O" , "<fc=#ebcb8b>Charging</fc>"
, "-i" , "<fc=#a3be8c>Charged</fc>"
] 50
-- Date and time
, Run Date "<fn=1>\xf017</fn> %H:%M:%S - %a %d/%m/%Y" "date" 10
-- System information
, Run Com "uname" ["-r"] "" 3600
]
}
EOF
# Create wallpaper directory and download a sample wallpaper
mkdir -p ~/.xmonad/wallpapers
# Create simple wallpaper (solid color) if none available
convert -size 1920x1080 xc:'#2e3440' ~/.xmonad/wallpaper.jpg 2>/dev/null || {
# If ImageMagick is not available, create a simple text file
echo "Install 'imagemagick' package and add your wallpaper to ~/.xmonad/wallpaper.jpg" > ~/.xmonad/wallpaper.txt
}
echo "xmobar status bar configured! 📊"
What this creates: Functional status bar with system monitoring capabilities! ✅
🎮 Step 3: Configure Desktop Environment
Create Desktop Session Configuration
Let’s set up xmonad as a desktop session! 🖥️
What we’re doing: Creating desktop session files and startup scripts for seamless xmonad experience.
# Create desktop session file
sudo mkdir -p /usr/share/xsessions
sudo cat > /usr/share/xsessions/xmonad.desktop << 'EOF'
[Desktop Entry]
Name=xmonad
Comment=Lightweight tiling window manager
Exec=xmonad
Type=Application
Keywords=wm;tiling
EOF
# Create xinitrc for startx
cat > ~/.xinitrc << 'EOF'
#!/bin/sh
# xinitrc for xmonad on Alpine Linux
# Set up X11 environment
userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap
# Merge in defaults and keymaps
if [ -f $sysresources ]; then
xrdb -merge $sysresources
fi
if [ -f $sysmodmap ]; then
xmodmap $sysmodmap
fi
if [ -f "$userresources" ]; then
xrdb -merge "$userresources"
fi
if [ -f "$usermodmap" ]; then
xmodmap "$usermodmap"
fi
# Start essential services
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
[ -x "$f" ] && . "$f"
done
unset f
fi
# Set up dbus
eval $(dbus-launch --sh-syntax --exit-with-session)
# Start compositor for transparency effects (optional)
# picom &
# Set wallpaper
feh --bg-scale ~/.xmonad/wallpaper.jpg 2>/dev/null &
# Start system tray
trayer --edge top --align right --SetDockType true --SetPartialStrut true \
--expand true --width 10 --transparent true --alpha 0 \
--tint 0x000000 --height 22 &
# Start network manager applet (if available)
nm-applet &
# Start volume control applet (if available)
volumeicon &
# Compile and start xmonad
cd ~/.xmonad
ghc --make xmonad.hs -i -ilib -fforce-recomp -main-is main -v0 -o xmonad-alpine-linux
exec ./xmonad-alpine-linux
EOF
chmod +x ~/.xinitrc
# Create Xresources for terminal and application theming
cat > ~/.Xresources << 'EOF'
! X Resources Configuration for xmonad
! Provides consistent theming across X11 applications
! Font configuration
Xft.dpi: 96
Xft.antialias: true
Xft.rgba: rgb
Xft.hinting: true
Xft.hintstyle: hintfull
Xft.lcdfilter: lcddefault
! Terminal colors (Nord theme)
*.foreground: #d8dee9
*.background: #2e3440
*.cursorColor: #d8dee9
! Black
*.color0: #3b4252
*.color8: #4c566a
! Red
*.color1: #bf616a
*.color9: #bf616a
! Green
*.color2: #a3be8c
*.color10: #a3be8c
! Yellow
*.color3: #ebcb8b
*.color11: #ebcb8b
! Blue
*.color4: #81a1c1
*.color12: #81a1c1
! Magenta
*.color5: #b48ead
*.color13: #b48ead
! Cyan
*.color6: #88c0d0
*.color14: #8fbcbb
! White
*.color7: #e5e9f0
*.color15: #eceff4
! XTerm configuration
XTerm*background: #2e3440
XTerm*foreground: #d8dee9
XTerm*faceName: Noto Sans Mono:size=10
XTerm*boldFont: Noto Sans Mono:size=10:bold
XTerm*geometry: 80x24
XTerm*saveLines: 2000
XTerm*scrollBar: false
XTerm*bellIsUrgent: true
! URxvt configuration (if using rxvt-unicode)
URxvt.font: xft:Noto Sans Mono:size=10
URxvt.scrollBar: false
URxvt.background: #2e3440
URxvt.foreground: #d8dee9
EOF
# Apply Xresources
xrdb -merge ~/.Xresources
echo "Desktop session configured! 🖥️"
What this creates: Complete desktop session setup for xmonad! 🌟
Create Essential Application Launcher Script
Let’s create helpful scripts for common tasks! 🛠️
What we’re doing: Creating application launchers and productivity scripts for xmonad workflow.
# Create scripts directory
mkdir -p ~/.local/bin
# Create application launcher script
cat > ~/.local/bin/xmonad-launcher << 'EOF'
#!/bin/sh
# xmonad Application Launcher Script
# Provides quick access to common applications
case "$1" in
"browser")
firefox &
;;
"terminal")
xterm &
;;
"files")
thunar &
;;
"editor")
if command -v code >/dev/null; then
code &
elif command -v vim >/dev/null; then
xterm -e vim &
else
xterm -e nano &
fi
;;
"calculator")
if command -v galculator >/dev/null; then
galculator &
else
xterm -e bc -l &
fi
;;
"screenshot")
if command -v scrot >/dev/null; then
scrot ~/screenshot-$(date +%Y%m%d-%H%M%S).png
else
echo "Install scrot for screenshots"
fi
;;
"system-monitor")
xterm -e htop &
;;
"logout")
echo "logout" > ~/.xmonad/session-command
;;
"restart")
echo "restart" > ~/.xmonad/session-command
;;
"shutdown")
echo "shutdown" > ~/.xmonad/session-command
;;
*)
echo "xmonad Application Launcher"
echo "Usage: $0 {browser|terminal|files|editor|calculator|screenshot|system-monitor|logout|restart|shutdown}"
echo ""
echo "Available applications:"
echo " browser - Launch web browser"
echo " terminal - Launch terminal"
echo " files - Launch file manager"
echo " editor - Launch text editor"
echo " calculator - Launch calculator"
echo " screenshot - Take screenshot"
echo " system-monitor - Launch system monitor"
echo " logout - Logout from session"
echo " restart - Restart xmonad"
echo " shutdown - Shutdown system"
;;
esac
EOF
chmod +x ~/.local/bin/xmonad-launcher
# Create workspace management script
cat > ~/.local/bin/xmonad-workspace << 'EOF'
#!/bin/sh
# xmonad Workspace Management Script
case "$1" in
"layout")
echo "Available layouts:"
echo " Super + Space - Next layout"
echo " Super + Shift + Space - Reset to default layout"
echo ""
echo "Current layouts:"
echo " 1. Tall (master + stack)"
echo " 2. Mirror Tall (horizontal)"
echo " 3. Full (maximized)"
echo " 4. Grid (equal sized)"
echo " 5. Spiral (fibonacci-like)"
echo " 6. Three Column"
;;
"shortcuts")
echo "xmonad Keyboard Shortcuts:"
echo ""
echo "Window Management:"
echo " Super + Return - Open terminal"
echo " Super + d - Application launcher (dmenu)"
echo " Super + f - Firefox browser"
echo " Super + e - File manager"
echo " Super + Shift + c - Close window"
echo ""
echo "Focus and Movement:"
echo " Super + Tab - Next window"
echo " Super + j/k - Focus down/up"
echo " Super + Shift + j/k - Swap down/up"
echo " Super + Return - Move to master"
echo ""
echo "Layout Control:"
echo " Super + h/l - Shrink/expand master"
echo " Super + ,/. - Inc/dec master count"
echo " Super + t - Sink floating window"
echo ""
echo "Workspace Navigation:"
echo " Super + 1-9 - Switch to workspace"
echo " Super + Shift + 1-9 - Move window to workspace"
echo " Super + Left/Right - Previous/next workspace"
echo ""
echo "System Control:"
echo " Super + q - Restart xmonad"
echo " Super + Shift + q - Quit xmonad"
;;
"status")
echo "xmonad System Status:"
echo "===================="
echo "Date: $(date)"
echo "Uptime: $(uptime -p)"
echo "Load: $(uptime | awk -F'load average:' '{print $2}')"
echo "Memory: $(free -h | awk '/^Mem:/ {print $3 "/" $2}')"
echo "Disk: $(df -h / | awk 'NR==2 {print $3 "/" $2 " (" $5 " used)"}')"
echo ""
echo "xmonad Process:"
pgrep -fl xmonad | head -5
;;
*)
echo "xmonad Workspace Management"
echo "Usage: $0 {layout|shortcuts|status}"
echo ""
echo "Commands:"
echo " layout - Show available layouts"
echo " shortcuts - Display keyboard shortcuts"
echo " status - Show system status"
;;
esac
EOF
chmod +x ~/.local/bin/xmonad-workspace
# Add local bin to PATH
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.profile
echo "xmonad scripts created! 🛠️"
What this creates: Helpful utility scripts for xmonad productivity! ✅
📊 Quick xmonad Commands Table
Command | Purpose | Result |
---|---|---|
🔧 Super + Return | Open terminal | ✅ New terminal window |
🔍 Super + d | Application launcher | ✅ dmenu for app selection |
🚀 Super + Space | Next layout | ✅ Switch tiling layout |
📋 Super + 1-9 | Switch workspace | ✅ Navigate workspaces |
🎮 Practice Time!
Let’s practice what you learned! Try these xmonad scenarios:
Example 1: Development Workspace Setup 🟢
What we’re doing: Setting up a complete development environment with xmonad workspaces optimized for coding productivity.
# Create development workspace configuration
mkdir -p ~/.xmonad/scripts
# Create development environment launcher
cat > ~/.xmonad/scripts/dev-setup.sh << 'EOF'
#!/bin/sh
# Development Environment Setup for xmonad
echo "Setting up development workspace..."
# Workspace 1: Terminal with development tools
xterm -e "cd ~/projects && bash" &
sleep 1
# Workspace 2: Browser for documentation
firefox https://docs.alpinelinux.org &
sleep 2
# Workspace 3: Code editor
if command -v code >/dev/null; then
code ~/projects &
elif command -v vim >/dev/null; then
xterm -e "cd ~/projects && vim" &
else
xterm -e "cd ~/projects && nano" &
fi
sleep 1
# Workspace 4: File manager for project files
thunar ~/projects &
sleep 1
# Create sample project structure
mkdir -p ~/projects/sample-alpine-project/{src,docs,tests,config}
cat > ~/projects/sample-alpine-project/README.md << 'DEVEOF'
# Sample Alpine Linux Project
This is a sample project structure for development on Alpine Linux with xmonad.
## Project Structure
sample-alpine-project/ ├── src/ # Source code ├── docs/ # Documentation ├── tests/ # Test files ├── config/ # Configuration files └── README.md # This file
## Development Workflow
1. Use workspace 1 for terminal operations
2. Use workspace 2 for documentation and research
3. Use workspace 3 for code editing
4. Use workspace 4 for file management
## xmonad Tips
- Super + 1-4: Switch between development workspaces
- Super + Shift + 1-4: Move windows between workspaces
- Super + Space: Cycle through layouts for optimal view
- Super + h/l: Adjust window sizes for comfort
DEVEOF
cat > ~/projects/sample-alpine-project/src/hello.sh << 'DEVEOF'
#!/bin/sh
# Sample Alpine Linux script
echo "Hello from Alpine Linux with xmonad!"
echo "System Information:"
echo "==================="
echo "OS: $(cat /etc/os-release | grep PRETTY_NAME | cut -d'"' -f2)"
echo "Kernel: $(uname -r)"
echo "Architecture: $(uname -m)"
echo "Window Manager: xmonad"
echo "Desktop Environment: Minimal Tiling Setup"
echo ""
echo "Development Environment Ready! 🚀"
DEVEOF
chmod +x ~/projects/sample-alpine-project/src/hello.sh
echo "Development workspace configured!"
echo "Projects directory: ~/projects"
echo "Run: ~/.xmonad/scripts/dev-setup.sh to launch dev environment"
EOF
chmod +x ~/.xmonad/scripts/dev-setup.sh
# Create keybinding for development setup
cat >> ~/.xmonad/xmonad.hs << 'EOF'
-- Development environment launcher
, ((modm .|. shiftMask, xK_d ), spawn "~/.xmonad/scripts/dev-setup.sh")
EOF
echo "Development workspace setup created! 💻"
What this does: Shows you how to create productive development environments with xmonad! 💻
Example 2: System Monitoring and Management 🟡
What we’re doing: Creating comprehensive system monitoring and management tools integrated with xmonad.
# Create system monitoring setup
mkdir -p ~/.xmonad/monitoring
# Create system monitor dashboard script
cat > ~/.xmonad/monitoring/system-dashboard.sh << 'EOF'
#!/bin/sh
# System Monitoring Dashboard for xmonad
# Function to display system information
show_system_info() {
clear
echo "🖥️ xmonad System Monitor Dashboard"
echo "====================================="
echo ""
# System information
echo "📊 System Information:"
echo " OS: $(cat /etc/os-release | grep PRETTY_NAME | cut -d'"' -f2)"
echo " Kernel: $(uname -r)"
echo " Uptime: $(uptime -p)"
echo " Load: $(uptime | awk -F'load average:' '{print $2}')"
echo ""
# CPU information
echo "⚡ CPU Usage:"
top -bn1 | grep "Cpu(s)" | awk '{print " " $2}' | sed 's/%us,/% user,/'
echo ""
# Memory information
echo "🧠 Memory Usage:"
free -h | awk '/^Mem:/ {printf " Used: %s / %s (%.1f%%)\n", $3, $2, $3/$2*100}'
echo ""
# Disk usage
echo "💾 Disk Usage:"
df -h / | awk 'NR==2 {printf " Root: %s / %s (%s)\n", $3, $2, $5}'
echo ""
# Network information
echo "🌐 Network Interfaces:"
ip addr show | grep -E "^[0-9]+:" | awk '{print " " $2}' | sed 's/://'
echo ""
# xmonad processes
echo "🏗️ xmonad Processes:"
pgrep -fl xmonad | awk '{print " PID " $1 ": " substr($0, index($0,$2))}'
echo ""
# Active workspaces
echo "🖱️ Active X11 Sessions:"
who | awk '$2 ~ /:[0-9]+/ {print " " $1 " on " $2}'
echo ""
}
# Function to show process monitor
show_processes() {
echo "Press 'q' to return to dashboard"
htop 2>/dev/null || top
}
# Function to show network monitor
show_network() {
echo "🌐 Network Monitor (Press Ctrl+C to return)"
echo "========================================="
if command -v nethogs >/dev/null; then
sudo nethogs
elif command -v iftop >/dev/null; then
sudo iftop
else
echo "Network monitoring tools not available."
echo "Install: apk add nethogs iftop"
echo ""
echo "Current network statistics:"
cat /proc/net/dev | awk '
NR>2 {
printf "%-8s RX: %10d bytes TX: %10d bytes\n",
substr($1,1,length($1)-1), $2, $10
}'
fi
}
# Function to show logs
show_logs() {
echo "📋 System Logs (Press 'q' to exit)"
echo "================================="
echo ""
echo "Recent system messages:"
dmesg | tail -20
echo ""
echo "X11 logs:"
tail -10 /var/log/Xorg.0.log 2>/dev/null || echo "No X11 logs found"
}
# Function to system control
system_control() {
echo "🔧 System Control Panel"
echo "======================"
echo ""
echo "1) Restart xmonad"
echo "2) Reload xmonad config"
echo "3) View xmonad log"
echo "4) Restart X11"
echo "5) System information"
echo "6) Return to dashboard"
echo ""
printf "Select option (1-6): "
read option
case $option in
1) xmonad --restart ;;
2) xmonad --recompile && xmonad --restart ;;
3) cat ~/.xmonad/xmonad.log 2>/dev/null || echo "No xmonad log found" ;;
4) echo "Restarting X11 will close all applications. Continue? (y/N)"
read confirm
if [ "$confirm" = "y" ]; then
sudo rc-service xdm restart
fi ;;
5) show_system_info ;;
6) return ;;
*) echo "Invalid option" ;;
esac
echo ""
echo "Press Enter to continue..."
read
}
# Main menu loop
while true; do
clear
show_system_info
echo "📱 Dashboard Menu:"
echo " [r] Refresh [p] Processes [n] Network [l] Logs [c] Control [q] Quit"
echo ""
printf "Select option: "
read -n1 option
echo ""
case $option in
r|R) continue ;;
p|P) show_processes ;;
n|N) show_network ;;
l|L) show_logs ;;
c|C) system_control ;;
q|Q) break ;;
*) echo "Invalid option. Press Enter to continue..."
read ;;
esac
done
echo "Exiting system dashboard..."
EOF
chmod +x ~/.xmonad/monitoring/system-dashboard.sh
# Create resource monitor widget for xmobar
cat > ~/.xmonad/monitoring/resource-widget.sh << 'EOF'
#!/bin/sh
# Resource monitoring widget for xmobar
# CPU usage
cpu_usage() {
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {printf "%.1f", usage}'
}
# Memory usage
mem_usage() {
awk '/MemTotal/ {total=$2} /MemAvailable/ {available=$2} END {printf "%.1f", (total-available)/total*100}' /proc/meminfo
}
# Disk usage
disk_usage() {
df / | awk 'NR==2 {printf "%.1f", $3/$2*100}'
}
# Network traffic
network_traffic() {
interface=$(ip route | awk '/default/ {print $5; exit}')
if [ -n "$interface" ]; then
rx_bytes=$(cat /sys/class/net/$interface/statistics/rx_bytes)
tx_bytes=$(cat /sys/class/net/$interface/statistics/tx_bytes)
echo "↓$(echo $rx_bytes | awk '{printf "%.1fM", $1/1024/1024}') ↑$(echo $tx_bytes | awk '{printf "%.1fM", $1/1024/1024}')"
else
echo "No network"
fi
}
# Temperature (if available)
temperature() {
if [ -r /sys/class/thermal/thermal_zone0/temp ]; then
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
echo "$(echo $temp | awk '{printf "%.1f°C", $1/1000}')"
else
echo "N/A"
fi
}
# Output format for xmobar
case "$1" in
cpu) cpu_usage ;;
mem) mem_usage ;;
disk) disk_usage ;;
net) network_traffic ;;
temp) temperature ;;
all)
echo "CPU:$(cpu_usage)% MEM:$(mem_usage)% DISK:$(disk_usage)% $(network_traffic) $(temperature)"
;;
*)
echo "Usage: $0 {cpu|mem|disk|net|temp|all}"
;;
esac
EOF
chmod +x ~/.xmonad/monitoring/resource-widget.sh
# Add keybinding for system dashboard
echo "System monitoring dashboard created! 📊"
echo "Launch with: ~/.xmonad/monitoring/system-dashboard.sh"
echo "Add to xmonad config: Super + Shift + m for quick access"
What this does: Creates comprehensive system monitoring tools integrated with xmonad! 📊
🚨 Fix Common Problems
Problem 1: xmonad won’t start or compile ❌
What happened: xmonad configuration has syntax errors or missing dependencies. How to fix it: Check configuration and install missing Haskell packages.
# Check xmonad configuration syntax
cd ~/.xmonad
ghc --make xmonad.hs -i -ilib -fforce-recomp -main-is main -v0 -o xmonad-test
# If compilation fails, check for missing packages
cabal update
cabal install xmonad xmonad-contrib
# Reset to minimal configuration if needed
cp ~/.xmonad/xmonad.hs ~/.xmonad/xmonad.hs.backup
cat > ~/.xmonad/xmonad.hs << 'EOF'
import XMonad
main = xmonad def
EOF
# Test minimal configuration
xmonad --recompile
Problem 2: Status bar not displaying properly ❌
What happened: xmobar configuration issues or missing fonts. How to fix it: Install required fonts and check xmobar config.
# Install missing fonts
apk add font-awesome font-noto font-dejavu
# Test xmobar configuration
xmobar ~/.xmonad/xmobarrc &
# Check if xmobar is running
pgrep -f xmobar
# Kill and restart xmobar
pkill xmobar
xmobar ~/.xmonad/xmobarrc &
Don’t worry! xmonad configuration is iterative - start simple and gradually add features! 💪
💡 Simple Tips
- Start with basic config 📅 - Begin with minimal setup and add features gradually
- Learn keybindings 🌱 - Master essential shortcuts for efficient workflow
- Customize workspaces 🤝 - Set up workspaces for different activities
- Use status bar 💪 - Monitor system resources and workspace status
✅ Check Everything Works
Let’s verify your xmonad installation is working perfectly:
# Complete xmonad system verification
cat > /usr/local/bin/xmonad-system-check.sh << 'EOF'
#!/bin/sh
echo "=== xmonad System Check ==="
echo "1. X11 Server:"
if command -v Xorg >/dev/null; then
echo "✅ X.Org server installed"
Xorg -version 2>&1 | head -1
else
echo "❌ X.Org server not found"
fi
echo -e "\n2. xmonad Installation:"
if command -v xmonad >/dev/null; then
echo "✅ xmonad installed"
xmonad --version
else
echo "❌ xmonad not found"
fi
echo -e "\n3. Haskell Environment:"
if command -v ghc >/dev/null; then
echo "✅ GHC compiler available"
ghc --version
else
echo "❌ GHC compiler not found"
fi
echo -e "\n4. Configuration Files:"
if [ -f ~/.xmonad/xmonad.hs ]; then
echo "✅ xmonad configuration exists"
echo "Configuration file: ~/.xmonad/xmonad.hs"
else
echo "❌ xmonad configuration missing"
fi
if [ -f ~/.xmonad/xmobarrc ]; then
echo "✅ xmobar configuration exists"
else
echo "❌ xmobar configuration missing"
fi
echo -e "\n5. Essential Applications:"
apps="xterm dmenu firefox thunar"
for app in $apps; do
if command -v $app >/dev/null; then
echo "✅ $app available"
else
echo "⚠️ $app not found (optional)"
fi
done
echo -e "\n6. Desktop Session:"
if [ -f /usr/share/xsessions/xmonad.desktop ]; then
echo "✅ xmonad desktop session configured"
else
echo "❌ Desktop session not configured"
fi
echo -e "\n7. Startup Configuration:"
if [ -f ~/.xinitrc ]; then
echo "✅ xinitrc configured for startx"
else
echo "⚠️ xinitrc not found (use display manager instead)"
fi
echo -e "\n8. Font Support:"
fc-list | grep -i noto >/dev/null && echo "✅ Noto fonts available" || echo "⚠️ Consider installing font-noto"
fc-list | grep -i awesome >/dev/null && echo "✅ Font Awesome available" || echo "⚠️ Consider installing font-awesome"
echo -e "\n9. Configuration Test:"
if [ -f ~/.xmonad/xmonad.hs ]; then
cd ~/.xmonad
if ghc --make xmonad.hs -i -ilib -fforce-recomp -main-is main -v0 -o xmonad-test 2>/dev/null; then
echo "✅ xmonad configuration compiles successfully"
rm -f xmonad-test
else
echo "❌ xmonad configuration has syntax errors"
fi
fi
echo -e "\n10. Getting Started:"
echo "🚀 To start xmonad:"
echo " • From console: startx"
echo " • From display manager: select 'xmonad' session"
echo ""
echo "📋 Essential keybindings:"
echo " • Super + Return: Terminal"
echo " • Super + d: Application launcher"
echo " • Super + Space: Next layout"
echo " • Super + 1-9: Switch workspaces"
echo -e "\nxmonad system check completed! ✅"
EOF
chmod +x /usr/local/bin/xmonad-system-check.sh
/usr/local/bin/xmonad-system-check.sh
Good output shows:
=== xmonad System Check ===
1. X11 Server:
✅ X.Org server installed
X.Org X Server 1.21.1
2. xmonad Installation:
✅ xmonad installed
xmonad 0.17.0
3. Haskell Environment:
✅ GHC compiler available
The Glorious Glasgow Haskell Compilation System, version 9.2.7
xmonad system check completed! ✅
🏆 What You Learned
Great job! Now you can:
- ✅ Install and configure X11 display server for graphical applications
- ✅ Set up xmonad tiling window manager with Haskell environment
- ✅ Create comprehensive xmonad configuration with productivity features
- ✅ Configure xmobar status bar with system monitoring
- ✅ Set up desktop sessions and startup scripts
- ✅ Create application launchers and workspace management tools
- ✅ Build development and monitoring environments with xmonad
- ✅ Customize keybindings and layouts for optimal workflow
- ✅ Troubleshoot common xmonad configuration issues
🎯 What’s Next?
Now you can try:
- 📚 Exploring advanced xmonad layouts and window management features
- 🛠️ Creating custom Haskell functions for xmonad automation
- 🤝 Setting up multi-monitor configurations and workspace routing
- 🌟 Integrating with desktop applications and system services!
Remember: xmonad excels at keyboard-driven productivity! You’re now building an efficient, minimalist desktop environment on Alpine Linux! 🎉
Keep tiling and you’ll master productive window management! 💫