+
hack
linux
+
+
pip
+
//
rs
backbone
+
+
+
+
+
+
+
+
rails
+
istio
+
jest
+
fedora
+
zorin
ractive
*
+
quarkus
influxdb
+
+
+
+
+
pytest
+
===
clj
+
+
smtp
git
+
+
xgboost
+
prometheus
bsd
r
choo
+
+
+
scipy
mint
+
+
vercel
vb
+
eslint
hugging
+
+
go
+
+
remix
+
+
html
+
cosmos
chef
rest
+
+
centos
+
apex
+
+
=
nvim
gulp
+
Back to Blog
🪟 Configuring Herbstluftwm Window Manager on Alpine Linux: Tiling Excellence
Alpine Linux Herbstluftwm Window Manager

🪟 Configuring Herbstluftwm Window Manager on Alpine Linux: Tiling Excellence

Published Jun 18, 2025

Comprehensive tutorial for advanced users to install and configure Herbstluftwm manual tiling window manager on Alpine Linux. Perfect for productivity-focused environments requiring flexible window management!

18 min read
0 views
Table of Contents

🪟 Configuring Herbstluftwm Window Manager on Alpine Linux: Tiling Excellence

Let’s master Herbstluftwm, the powerful manual tiling window manager on Alpine Linux! 🚀 This comprehensive tutorial shows you how to install, configure, and customize Herbstluftwm for maximum productivity and window management efficiency. Perfect for power users who want complete control over their desktop workspace! 😊

🤔 What is Herbstluftwm?

Herbstluftwm is a manual tiling window manager for X11 that organizes windows into non-overlapping frames using a binary tree layout, where each frame can be split again or filled with windows, providing complete keyboard-driven control over window placement and size!

Herbstluftwm is like:

  • 🧩 Puzzle master that perfectly arranges every piece of your workspace
  • 🎛️ Control tower giving you precise command over every window and layout
  • 🌳 Digital tree where windows grow in organized, predictable patterns

🎯 What You Need

Before we start, you need:

  • ✅ Alpine Linux system with X11 and basic desktop environment
  • ✅ Understanding of tiling window managers and keyboard shortcuts
  • ✅ Familiarity with shell scripting and configuration files
  • ✅ Desire for keyboard-driven workflow and maximum productivity

📋 Step 1: Install X11 and Herbstluftwm

Install X.Org Server and Dependencies

Let’s set up the complete desktop foundation! 😊

What we’re doing: Installing X11 display server and all necessary components for running Herbstluftwm window manager.

# Update package list
apk update

# Install X.Org server and essential components
apk add xorg-server xorg-server-xvfb xinit xauth

# Install display drivers (choose based on your hardware)
apk add xf86-video-vesa        # Generic VESA driver
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 essential fonts
apk add font-noto font-noto-cjk font-awesome
apk add font-dejavu font-liberation

# Install Herbstluftwm window manager
apk add herbstluftwm

# Install essential applications
apk add xterm dmenu

# Install additional desktop utilities
apk add xrandr xset xmodmap xprop
apk add feh imagemagick  # For wallpaper support

# Check Herbstluftwm version
herbstluftwm --version

echo "Herbstluftwm and X11 installed! 🌿"

What this does: 📖 Installs complete desktop environment with Herbstluftwm window manager.

Example output:

herbstluftwm 0.9.5 compiled on Nov 15 2023

What this means: Herbstluftwm is ready for configuration! ✅

Configure X11 Display Settings

Let’s optimize X11 for Herbstluftwm performance! 🎯

What we’re doing: Setting up X11 configuration files for optimal tiling window manager performance.

# Create X11 configuration directory
mkdir -p /etc/X11/xorg.conf.d

# Create keyboard configuration
cat > /etc/X11/xorg.conf.d/00-keyboard.conf << 'EOF'
# Keyboard Configuration for Herbstluftwm
Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbLayout" "us"
    Option "XkbModel" "pc105"
    Option "XkbOptions" "terminate:ctrl_alt_bksp,caps:escape"
EndSection
EOF

# Create mouse configuration
cat > /etc/X11/xorg.conf.d/10-mouse.conf << 'EOF'
# Mouse Configuration
Section "InputClass"
    Identifier "system-mouse"
    MatchIsPointer "on"
    Driver "libinput"
    Option "AccelProfile" "flat"
    Option "AccelSpeed" "0.3"
    Option "ClickMethod" "clickfinger"
EndSection
EOF

# Create touchpad configuration (for laptops)
cat > /etc/X11/xorg.conf.d/30-touchpad.conf << 'EOF'
# Touchpad Configuration
Section "InputClass"
    Identifier "touchpad"
    MatchIsTouchpad "on"
    Driver "libinput"
    Option "Tapping" "on"
    Option "TappingDrag" "on"
    Option "DisableWhileTyping" "on"
    Option "NaturalScrolling" "true"
    Option "ScrollMethod" "twofinger"
EndSection
EOF

# Create display configuration
cat > /etc/X11/xorg.conf.d/20-display.conf << 'EOF'
# Display Configuration for Herbstluftwm
Section "Monitor"
    Identifier "Monitor0"
    Option "DPMS" "true"
EndSection

Section "Device"
    Identifier "Card0"
    Driver "vesa"  # Change to your specific driver
    Option "AccelMethod" "glamor"
    Option "DRI" "3"
EndSection

Section "Screen"
    Identifier "Screen0"
    Device "Card0"
    Monitor "Monitor0"
    DefaultDepth 24
    SubSection "Display"
        Depth 24
        Modes "1920x1080" "1680x1050" "1280x1024" "1024x768"
    EndSubSection
EndSection
EOF

echo "X11 configuration optimized for Herbstluftwm! ⚙️"

What this creates: Optimized X11 environment for dynamic tiling window management! ✅

🔧 Step 2: Configure Herbstluftwm

Create Basic Herbstluftwm Configuration

Let’s build a comprehensive Herbstluftwm configuration! 🌿

What we’re doing: Creating a feature-rich Herbstluftwm configuration with smart layouts, keybindings, and automation.

# Create configuration directory
mkdir -p ~/.config/herbstluftwm

# Create main configuration file
cat > ~/.config/herbstluftwm/autostart << 'EOF'
#!/usr/bin/env bash
# Herbstluftwm Configuration for Alpine Linux
# Advanced tiling window manager setup

# Remove all existing keybindings and settings
herbstclient keyunbind --all
herbstclient mouseunbind --all
herbstclient unrule -F

# Define modifier keys
Mod=Mod4    # Super/Windows key
Alt=Mod1    # Alt key

# Basic settings
herbstclient set default_frame_layout grid
herbstclient set_layout grid
herbstclient set window_gap 8
herbstclient set frame_padding 4
herbstclient set smart_window_surroundings off
herbstclient set smart_frame_surroundings on
herbstclient set mouse_recenter_gap 0
herbstclient set focus_follows_mouse true
herbstclient set swap_monitors_to_get_tag false

# Frame appearance
herbstclient set frame_border_active_color '#88c0d0'
herbstclient set frame_border_normal_color '#434c5e'
herbstclient set frame_bg_normal_color '#2e3440'
herbstclient set frame_bg_active_color '#3b4252'
herbstclient set frame_border_width 2
herbstclient set frame_bg_transparent on

# Window appearance (Nord theme)
herbstclient set window_border_width 2
herbstclient set window_border_inner_width 0
herbstclient set window_border_normal_color '#434c5e'
herbstclient set window_border_active_color '#88c0d0'
herbstclient set window_border_urgent_color '#bf616a'

# Application launching keybindings
herbstclient keybind $Mod-Return spawn xterm
herbstclient keybind $Mod-d spawn dmenu_run -fn 'Noto Sans-12' -nb '#2e3440' -nf '#d8dee9' -sb '#88c0d0' -sf '#2e3440'
herbstclient keybind $Mod-f spawn firefox
herbstclient keybind $Mod-e spawn thunar

# Window management
herbstclient keybind $Mod-Shift-q close_or_remove
herbstclient keybind $Mod-q close_and_remove
herbstclient keybind $Mod-Shift-r reload
herbstclient keybind $Mod-Shift-c close

# Frame management and splitting
herbstclient keybind $Mod-s split bottom 0.5
herbstclient keybind $Mod-v split right 0.5
herbstclient keybind $Mod-Shift-s split top 0.5
herbstclient keybind $Mod-Shift-v split left 0.5
herbstclient keybind $Mod-r remove
herbstclient keybind $Mod-Ctrl-space split explode

# Focus movement
herbstclient keybind $Mod-h focus left
herbstclient keybind $Mod-j focus down
herbstclient keybind $Mod-k focus up
herbstclient keybind $Mod-l focus right
herbstclient keybind $Mod-Tab cycle_all +1
herbstclient keybind $Mod-Shift-Tab cycle_all -1
herbstclient keybind $Mod-c cycle
herbstclient keybind $Mod-i jumpto urgent

# Window movement
herbstclient keybind $Mod-Shift-h shift left
herbstclient keybind $Mod-Shift-j shift down
herbstclient keybind $Mod-Shift-k shift up
herbstclient keybind $Mod-Shift-l shift right
herbstclient keybind $Mod-Shift-Return shift_to_monitor +1

# Resizing frames
resizestep=0.05
herbstclient keybind $Mod-Ctrl-h resize left +$resizestep
herbstclient keybind $Mod-Ctrl-j resize down +$resizestep
herbstclient keybind $Mod-Ctrl-k resize up +$resizestep
herbstclient keybind $Mod-Ctrl-l resize right +$resizestep

# Layout controls
herbstclient keybind $Mod-space cycle_layout +1 grid vertical horizontal max
herbstclient keybind $Mod-Shift-space cycle_layout -1
herbstclient keybind $Mod-u split vertical 0.5 ; split horizontal 0.5
herbstclient keybind $Mod-o split horizontal 0.5 ; split vertical 0.5

# Floating window controls
herbstclient keybind $Mod-Shift-f floating toggle
herbstclient keybind $Mod-p pseudotile toggle
herbstclient keybind $Mod-Ctrl-f fullscreen toggle

# Tag (workspace) setup
tag_names=( "1:term" "2:web" "3:code" "4:files" "5:media" "6:comm" "7:sys" "8:misc" "9:tmp" )
tag_keys=( {1..9} 0 )

for i in "${!tag_names[@]}" ; do
    herbstclient add "${tag_names[$i]}"
    key="${tag_keys[$i]}"
    if [ -n "$key" ] ; then
        herbstclient keybind "$Mod-$key" use_index "$i"
        herbstclient keybind "$Mod-Shift-$key" move_index "$i"
    fi
done

# Monitor management
herbstclient keybind $Mod-period focus_monitor +1
herbstclient keybind $Mod-comma focus_monitor -1
herbstclient keybind $Mod-Shift-period shift_to_monitor +1
herbstclient keybind $Mod-Shift-comma shift_to_monitor -1

# Mouse bindings
herbstclient mouseunbind --all
herbstclient mousebind $Mod-Button1 move
herbstclient mousebind $Mod-Button2 zoom
herbstclient mousebind $Mod-Button3 resize
herbstclient mousebind $Mod-Shift-Button1 resize

# Application rules
herbstclient unrule -F
herbstclient rule focus=on
herbstclient rule floatplacement=smart
herbstclient rule windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' floating=on
herbstclient rule windowtype='_NET_WM_WINDOW_TYPE_DIALOG' focus=on
herbstclient rule windowtype~'_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK|DESKTOP)' manage=off
herbstclient rule class=Firefox tag=2:web
herbstclient rule class=Thunar tag=4:files
herbstclient rule class=discord tag=6:comm
herbstclient rule class=VLC tag=5:media
herbstclient rule instance=pinentry floating=on

# Advanced layout rules
herbstclient rule class=Gimp tag=5:media pseudotile=on
herbstclient rule class=Steam tag=5:media
herbstclient rule title='Developer Tools' floating=on
herbstclient rule title='DevTools' floating=on

# Multi-monitor setup
herbstclient detect_monitors

# Theme and panel settings
panel=~/.config/herbstluftwm/panel.sh
[ -x "$panel" ] && "$panel" &

# Startup applications
pgrep -x compton || compton -b &  # Compositor
pgrep -x dunst || dunst &         # Notifications
feh --bg-scale ~/.config/herbstluftwm/wallpaper.jpg 2>/dev/null &

# Set wallpaper color if image not found
xsetroot -solid '#2e3440'

# Lock screen setup
herbstclient keybind $Mod-Ctrl-l spawn slock

# Volume controls (if available)
herbstclient keybind XF86AudioRaiseVolume spawn amixer set Master 5%+
herbstclient keybind XF86AudioLowerVolume spawn amixer set Master 5%-
herbstclient keybind XF86AudioMute spawn amixer set Master toggle

# Brightness controls (if available)
herbstclient keybind XF86MonBrightnessUp spawn xbacklight -inc 10
herbstclient keybind XF86MonBrightnessDown spawn xbacklight -dec 10

# Screenshot functionality
herbstclient keybind Print spawn scrot ~/screenshot-%Y%m%d-%H%M%S.png
herbstclient keybind $Mod-Print spawn scrot -s ~/screenshot-selection-%Y%m%d-%H%M%S.png

# Herbstluftwm client focusing chain
herbstclient chain , lock , add temporary , focus temporary , spawn xterm , unlock

echo "Herbstluftwm configuration loaded successfully"
EOF

chmod +x ~/.config/herbstluftwm/autostart

echo "Herbstluftwm configuration created! 🌿"

What this creates: Comprehensive Herbstluftwm configuration with advanced features! 🌟

Create Status Panel and Theming

Let’s build a beautiful status panel and theming system! 📊

What we’re doing: Creating a custom status panel with system information and consistent visual theming.

# Create panel script
cat > ~/.config/herbstluftwm/panel.sh << 'EOF'
#!/bin/bash
# Herbstluftwm Panel Script for Alpine Linux
# Advanced status bar with system monitoring

# Configuration
monitor=${1:-0}
geometry=( $(herbstclient monitor_rect "$monitor") )
if [ -z "$geometry" ] ;then
    echo "Invalid monitor $monitor"
    exit 1
fi

# Panel dimensions
x=${geometry[0]}
y=${geometry[1]}
panel_width=${geometry[2]}
panel_height=24

# Colors (Nord theme)
bg_normal='#2e3440'
bg_focus='#3b4252'
fg_normal='#d8dee9'
fg_focus='#88c0d0'
fg_urgent='#bf616a'
fg_warning='#ebcb8b'
fg_success='#a3be8c'

# Fonts
font='-*-noto sans-medium-r-*-*-12-*-*-*-*-*-*-*'
icon_font='-*-font awesome 5 free-medium-r-*-*-11-*-*-*-*-*-*-*'

# Create FIFO for panel updates
fifo="/tmp/herbstluftwm-panel.$monitor"
[ -p "$fifo" ] && rm "$fifo"
mkfifo "$fifo"

# Function to get system information
get_system_info() {
    # CPU usage
    cpu_usage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
    
    # Memory usage
    mem_info=$(free | grep Mem)
    mem_total=$(echo $mem_info | awk '{print $2}')
    mem_used=$(echo $mem_info | awk '{print $3}')
    mem_percent=$(echo "scale=1; $mem_used * 100 / $mem_total" | bc -l)
    
    # Battery status (if available)
    if [ -f /sys/class/power_supply/BAT0/capacity ]; then
        battery=$(cat /sys/class/power_supply/BAT0/capacity)
        battery_status=$(cat /sys/class/power_supply/BAT0/status)
    else
        battery=""
        battery_status=""
    fi
    
    # Network status
    if ip route | grep -q "default"; then
        network_status="󰖩"
        network_color="$fg_success"
    else
        network_status="󰖪"
        network_color="$fg_urgent"
    fi
    
    # Volume level (if available)
    if command -v amixer >/dev/null; then
        volume=$(amixer get Master | grep -o '[0-9]*%' | head -1 | tr -d '%')
        if amixer get Master | grep -q '\[off\]'; then
            volume_icon="󰖁"
        elif [ "$volume" -gt 70 ]; then
            volume_icon="󰕾"
        elif [ "$volume" -gt 30 ]; then
            volume_icon="󰖀"
        else
            volume_icon="󰕿"
        fi
    else
        volume=""
        volume_icon=""
    fi
    
    # Date and time
    datetime=$(date '+%a %d/%m %H:%M')
    
    # Format system info
    cpu_info="󰻠 ${cpu_usage%.*}%"
    mem_info="󰍛 ${mem_percent%.*}%"
    
    if [ -n "$battery" ]; then
        if [ "$battery_status" = "Charging" ]; then
            battery_icon="󰂄"
        elif [ "$battery" -gt 80 ]; then
            battery_icon="󰁹"
        elif [ "$battery" -gt 60 ]; then
            battery_icon="󰂀"
        elif [ "$battery" -gt 40 ]; then
            battery_icon="󰁾"
        elif [ "$battery" -gt 20 ]; then
            battery_icon="󰁻"
        else
            battery_icon="󰁺"
        fi
        battery_info="$battery_icon $battery%"
    else
        battery_info=""
    fi
    
    volume_info=""
    if [ -n "$volume" ]; then
        volume_info="$volume_icon $volume%"
    fi
    
    # Output formatted system info
    echo "sys_info|$cpu_info  $mem_info  $network_status  $volume_info  $battery_info  󰃰 $datetime"
}

# Update system info every 5 seconds
{
    while true; do
        get_system_info
        sleep 5
    done
} > "$fifo" &

# Update workspace info when changes occur
herbstclient --idle > "$fifo" &

# Panel content generation
{
    # Initialize variables
    tags=""
    layout=""
    title=""
    sys_info=""
    
    while true; do
        # Read from FIFO
        read line || break
        cmd=( $line )
        
        case "${cmd[0]}" in
            tag*)
                # Update workspace/tag information
                tags=""
                IFS=$'\t' read -ra tag_statuses <<< "$(herbstclient tag_status $monitor)"
                for tag in "${tag_statuses[@]}" ; do
                    case ${tag:0:1} in
                        '#')  # Current tag
                            tags+="%{B$bg_focus}%{F$fg_focus} ${tag:1} %{B-}%{F-}"
                            ;;
                        '+')  # Active on other monitor
                            tags+="%{B$bg_normal}%{F$fg_warning} ${tag:1} %{B-}%{F-}"
                            ;;
                        ':')  # Not empty
                            tags+="%{B$bg_normal}%{F$fg_normal} ${tag:1} %{B-}%{F-}"
                            ;;
                        '!')  # Urgent
                            tags+="%{B$fg_urgent}%{F$bg_normal} ${tag:1} %{B-}%{F-}"
                            ;;
                        '-')  # Empty
                            tags+="%{B$bg_normal}%{F#4c566a} ${tag:1} %{B-}%{F-}"
                            ;;
                        *)
                            tags+="%{B$bg_normal}%{F$fg_normal} ${tag:1} %{B-}%{F-}"
                            ;;
                    esac
                done
                ;;
            title_changed)
                # Update window title
                title=$(herbstclient get_attr clients.focus.title)
                if [ ${#title} -gt 60 ]; then
                    title="${title:0:57}..."
                fi
                ;;
            sys_info)
                # Update system information
                sys_info="${line#sys_info|}"
                ;;
        esac
        
        # Generate panel content
        left="$tags"
        center="%{c}$title"
        right="%{r}$sys_info  "
        
        # Output formatted panel line
        echo "%{l}$left$center$right"
        
    done
} < "$fifo" | lemonbar \
    -g "${panel_width}x${panel_height}+${x}+${y}" \
    -f "$font" \
    -f "$icon_font" \
    -B "$bg_normal" \
    -F "$fg_normal" \
    -U "$fg_focus" \
    -u 2 \
    | while read line; do
        eval "$line"
    done &

# Clean up when panel exits
trap "kill 0" EXIT

# Wait for panel to exit
wait
EOF

chmod +x ~/.config/herbstluftwm/panel.sh

# Create theme script
cat > ~/.config/herbstluftwm/themes.sh << 'EOF'
#!/bin/bash
# Herbstluftwm Theme Manager

# Theme definitions
declare -A themes

# Nord theme
themes[nord]="
window_border_normal_color='#434c5e'
window_border_active_color='#88c0d0'
window_border_urgent_color='#bf616a'
frame_border_normal_color='#434c5e'
frame_border_active_color='#88c0d0'
frame_bg_normal_color='#2e3440'
frame_bg_active_color='#3b4252'
"

# Gruvbox theme
themes[gruvbox]="
window_border_normal_color='#3c3836'
window_border_active_color='#fe8019'
window_border_urgent_color='#fb4934'
frame_border_normal_color='#3c3836'
frame_border_active_color='#fe8019'
frame_bg_normal_color='#282828'
frame_bg_active_color='#3c3836'
"

# Dracula theme
themes[dracula]="
window_border_normal_color='#44475a'
window_border_active_color='#bd93f9'
window_border_urgent_color='#ff5555'
frame_border_normal_color='#44475a'
frame_border_active_color='#bd93f9'
frame_bg_normal_color='#282a36'
frame_bg_active_color='#44475a'
"

# Apply theme function
apply_theme() {
    local theme_name="$1"
    
    if [[ -z "${themes[$theme_name]}" ]]; then
        echo "Theme '$theme_name' not found!"
        echo "Available themes: ${!themes[@]}"
        return 1
    fi
    
    echo "Applying theme: $theme_name"
    
    # Parse and apply theme colors
    while IFS='=' read -r key value; do
        if [[ -n "$key" && -n "$value" ]]; then
            # Remove quotes from value
            value=${value//\'/}
            herbstclient set "$key" "$value"
        fi
    done <<< "${themes[$theme_name]}"
    
    # Save current theme
    echo "$theme_name" > ~/.config/herbstluftwm/current_theme
    
    echo "Theme '$theme_name' applied successfully!"
}

# Main function
case "$1" in
    list)
        echo "Available themes:"
        printf ' - %s\n' "${!themes[@]}"
        ;;
    apply)
        apply_theme "$2"
        ;;
    current)
        if [ -f ~/.config/herbstluftwm/current_theme ]; then
            cat ~/.config/herbstluftwm/current_theme
        else
            echo "No theme set"
        fi
        ;;
    *)
        echo "Usage: $0 {list|apply <theme>|current}"
        echo "Example: $0 apply nord"
        ;;
esac
EOF

chmod +x ~/.config/herbstluftwm/themes.sh

# Download a sample wallpaper or create a solid color background
mkdir -p ~/.config/herbstluftwm/wallpapers
convert -size 1920x1080 xc:'#2e3440' ~/.config/herbstluftwm/wallpaper.jpg 2>/dev/null || {
    echo "Install 'imagemagick' for wallpaper support"
    touch ~/.config/herbstluftwm/wallpaper.jpg
}

echo "Panel and theming system created! 📊"

What this creates: Beautiful status panel with system monitoring and theme management! ✅

🖥️ Step 3: Configure Desktop Session

Create Desktop Session and Startup

Let’s set up Herbstluftwm as a complete desktop session! 🖥️

What we’re doing: Creating desktop session files and startup scripts for seamless Herbstluftwm experience.

# Create desktop session file
sudo mkdir -p /usr/share/xsessions
sudo cat > /usr/share/xsessions/herbstluftwm.desktop << 'EOF'
[Desktop Entry]
Name=herbstluftwm
Comment=Dynamic tiling window manager
Exec=herbstluftwm
Type=Application
Keywords=wm;tiling;dynamic
EOF

# Create xinitrc for startx
cat > ~/.xinitrc << 'EOF'
#!/bin/sh
# xinitrc for Herbstluftwm 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)

# Configure display
xrandr --auto

# Set keyboard repeat rate
xset r rate 300 50

# Disable bell
xset -b

# Enable zapping (Ctrl+Alt+Backspace)
setxkbmap -option terminate:ctrl_alt_bksp

# Start compositor (if available)
command -v picom >/dev/null && picom -b &

# Start notification daemon
command -v dunst >/dev/null && dunst &

# Start network manager applet
command -v nm-applet >/dev/null && nm-applet &

# Start volume control
command -v volumeicon >/dev/null && volumeicon &

# Set wallpaper
feh --bg-scale ~/.config/herbstluftwm/wallpaper.jpg 2>/dev/null || xsetroot -solid '#2e3440'

# Apply saved theme
if [ -f ~/.config/herbstluftwm/current_theme ]; then
    theme=$(cat ~/.config/herbstluftwm/current_theme)
    ~/.config/herbstluftwm/themes.sh apply "$theme"
fi

# Start herbstluftwm
exec herbstluftwm
EOF

chmod +x ~/.xinitrc

# Create Xresources for consistent theming
cat > ~/.Xresources << 'EOF'
! Xresources for Herbstluftwm
! Nord color scheme

! Fonts
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=11
XTerm*geometry: 80x24
XTerm*saveLines: 2000
XTerm*scrollBar: false
XTerm*bellIsUrgent: true

! dmenu colors
dmenu.background: #2e3440
dmenu.foreground: #d8dee9
dmenu.selbackground: #88c0d0
dmenu.selforeground: #2e3440
EOF

# Apply Xresources
xrdb -merge ~/.Xresources

echo "Desktop session configured! 🖥️"

What this creates: Complete desktop session setup for Herbstluftwm! 🌟

Create Workflow Management Scripts

Let’s build productivity-focused workflow management tools! 🛠️

What we’re doing: Creating scripts for layout management, workspace automation, and productivity enhancement.

# Create scripts directory
mkdir -p ~/.config/herbstluftwm/scripts

# Create layout management script
cat > ~/.config/herbstluftwm/scripts/layout-manager.sh << 'EOF'
#!/bin/bash
# Herbstluftwm Layout Manager
# Preset layouts for different workflows

# Configuration
config_dir="$HOME/.config/herbstluftwm"
layouts_dir="$config_dir/layouts"

# Create layouts directory
mkdir -p "$layouts_dir"

# Function to save current layout
save_layout() {
    local name="$1"
    if [ -z "$name" ]; then
        echo "Usage: save_layout <name>"
        return 1
    fi
    
    local layout_file="$layouts_dir/$name.layout"
    
    # Save tag information and frame layouts
    {
        echo "# Herbstluftwm layout: $name"
        echo "# Created: $(date)"
        echo ""
        
        # Save each tag's layout
        for tag in $(herbstclient tag_status | cut -d$'\t' -f1 | sed 's/^.//' ); do
            echo "# Tag: $tag"
            herbstclient use "$tag"
            echo "herbstclient use \"$tag\""
            herbstclient dump
            echo ""
        done
    } > "$layout_file"
    
    echo "Layout '$name' saved to: $layout_file"
}

# Function to load layout
load_layout() {
    local name="$1"
    if [ -z "$name" ]; then
        echo "Usage: load_layout <name>"
        return 1
    fi
    
    local layout_file="$layouts_dir/$name.layout"
    
    if [ ! -f "$layout_file" ]; then
        echo "Layout '$name' not found!"
        return 1
    fi
    
    echo "Loading layout: $name"
    
    # Execute layout commands
    while IFS= read -r line; do
        if [[ "$line" =~ ^herbstclient ]]; then
            eval "$line"
        fi
    done < "$layout_file"
    
    echo "Layout '$name' loaded successfully!"
}

# Function to list layouts
list_layouts() {
    echo "Available layouts:"
    if [ -d "$layouts_dir" ]; then
        for layout in "$layouts_dir"/*.layout; do
            if [ -f "$layout" ]; then
                basename "$layout" .layout
            fi
        done
    else
        echo "No layouts found"
    fi
}

# Predefined layouts
create_development_layout() {
    echo "Creating development layout..."
    
    # Switch to code tag
    herbstclient use "3:code"
    
    # Create development layout: editor on left, terminal on right
    herbstclient split right 0.7
    herbstclient focus right
    herbstclient split bottom 0.5
    
    # Focus back to main editor area
    herbstclient focus left
    
    echo "Development layout created on tag '3:code'"
}

create_monitoring_layout() {
    echo "Creating monitoring layout..."
    
    # Switch to sys tag
    herbstclient use "7:sys"
    
    # Create 2x2 grid for monitoring
    herbstclient split right 0.5
    herbstclient focus left
    herbstclient split bottom 0.5
    herbstclient focus right
    herbstclient split bottom 0.5
    
    echo "Monitoring layout created on tag '7:sys'"
}

create_communication_layout() {
    echo "Creating communication layout..."
    
    # Switch to comm tag
    herbstclient use "6:comm"
    
    # Vertical split for communication apps
    herbstclient split bottom 0.6
    
    echo "Communication layout created on tag '6:comm'"
}

# Main function
case "$1" in
    save)
        save_layout "$2"
        ;;
    load)
        load_layout "$2"
        ;;
    list)
        list_layouts
        ;;
    dev)
        create_development_layout
        ;;
    monitor)
        create_monitoring_layout
        ;;
    comm)
        create_communication_layout
        ;;
    *)
        echo "Herbstluftwm Layout Manager"
        echo "Usage: $0 {save|load|list|dev|monitor|comm} [name]"
        echo ""
        echo "Commands:"
        echo "  save <name>  - Save current layout"
        echo "  load <name>  - Load saved layout"
        echo "  list         - List available layouts"
        echo "  dev          - Create development layout"
        echo "  monitor      - Create monitoring layout"
        echo "  comm         - Create communication layout"
        ;;
esac
EOF

chmod +x ~/.config/herbstluftwm/scripts/layout-manager.sh

# Create workspace automation script
cat > ~/.config/herbstluftwm/scripts/workspace-automation.sh << 'EOF'
#!/bin/bash
# Herbstluftwm Workspace Automation
# Automated workspace setup for different scenarios

# Function to setup development workspace
setup_development() {
    echo "Setting up development workspace..."
    
    # Terminal workspace
    herbstclient use "1:term"
    herbstclient spawn xterm
    
    # Web browser for documentation
    herbstclient use "2:web"
    herbstclient spawn firefox
    
    # Code editor workspace
    herbstclient use "3:code"
    ~/.config/herbstluftwm/scripts/layout-manager.sh dev
    
    # File manager
    herbstclient use "4:files"
    herbstclient spawn thunar
    
    # Switch back to terminal
    herbstclient use "1:term"
    
    echo "Development workspace ready!"
}

# Function to setup media workspace
setup_media() {
    echo "Setting up media workspace..."
    
    # Media tag with optimized layout
    herbstclient use "5:media"
    herbstclient spawn xterm -e "echo 'Media workspace - launch your media applications'; bash"
    
    echo "Media workspace ready!"
}

# Function to setup system administration
setup_sysadmin() {
    echo "Setting up system administration workspace..."
    
    # System monitoring
    herbstclient use "7:sys"
    ~/.config/herbstluftwm/scripts/layout-manager.sh monitor
    
    # Launch monitoring tools
    herbstclient spawn xterm -e htop
    herbstclient focus right
    herbstclient spawn xterm -e "watch -n 1 'df -h; echo; free -h'"
    herbstclient focus down
    herbstclient spawn xterm -e "watch -n 2 'netstat -tuln | head -20'"
    herbstclient focus left
    herbstclient spawn xterm -e "tail -f /var/log/messages"
    
    echo "System administration workspace ready!"
}

# Function to setup communication workspace
setup_communication() {
    echo "Setting up communication workspace..."
    
    herbstclient use "6:comm"
    ~/.config/herbstluftwm/scripts/layout-manager.sh comm
    
    echo "Communication workspace ready!"
}

# Function to restore default workspace
restore_default() {
    echo "Restoring default workspace layout..."
    
    # Close all windows and reset layouts
    for tag in "1:term" "2:web" "3:code" "4:files" "5:media" "6:comm" "7:sys" "8:misc" "9:tmp"; do
        herbstclient use "$tag"
        herbstclient close_and_remove
    done
    
    # Return to first tag
    herbstclient use "1:term"
    
    echo "Default workspace restored!"
}

# Main function
case "$1" in
    dev|development)
        setup_development
        ;;
    media)
        setup_media
        ;;
    sysadmin|admin)
        setup_sysadmin
        ;;
    comm|communication)
        setup_communication
        ;;
    reset|default)
        restore_default
        ;;
    *)
        echo "Herbstluftwm Workspace Automation"
        echo "Usage: $0 {dev|media|sysadmin|comm|reset}"
        echo ""
        echo "Workspace setups:"
        echo "  dev        - Development environment"
        echo "  media      - Media consumption workspace"
        echo "  sysadmin   - System administration tools"
        echo "  comm       - Communication applications"
        echo "  reset      - Restore default workspace"
        ;;
esac
EOF

chmod +x ~/.config/herbstluftwm/scripts/workspace-automation.sh

# Create keybinding for workspace automation
echo '# Add to autostart for workspace automation keybindings' >> ~/.config/herbstluftwm/autostart
echo 'herbstclient keybind $Mod-w spawn ~/.config/herbstluftwm/scripts/workspace-automation.sh' >> ~/.config/herbstluftwm/autostart
echo 'herbstclient keybind $Mod-Shift-w spawn ~/.config/herbstluftwm/scripts/layout-manager.sh' >> ~/.config/herbstluftwm/autostart

echo "Workflow management scripts created! 🛠️"

What this creates: Powerful workflow management tools for productivity enhancement! ✅

📊 Quick Herbstluftwm Commands Table

CommandPurposeResult
🔧 Super + ReturnOpen terminal✅ New terminal window
🔍 Super + dApplication launcher✅ dmenu for app selection
🚀 Super + s/vSplit frame✅ Create new frame splits
📋 Super + h/j/k/lNavigate frames✅ Move focus between frames

🎮 Practice Time!

Let’s practice what you learned! Try these Herbstluftwm scenarios:

Example 1: Custom Development Environment 🟢

What we’re doing: Creating a specialized development environment with custom layouts, automated project setup, and productivity enhancements.

# Create development environment setup
mkdir -p ~/.config/herbstluftwm/dev-setup

# Create project workspace manager
cat > ~/.config/herbstluftwm/dev-setup/project-manager.sh << 'EOF'
#!/bin/bash
# Project Workspace Manager for Herbstluftwm

PROJECTS_DIR="$HOME/projects"
CONFIG_DIR="$HOME/.config/herbstluftwm/dev-setup"

# Function to create new project workspace
create_project() {
    local project_name="$1"
    local project_type="${2:-general}"
    
    if [ -z "$project_name" ]; then
        echo "Usage: create_project <name> [type]"
        echo "Types: web, python, go, alpine, general"
        return 1
    fi
    
    local project_path="$PROJECTS_DIR/$project_name"
    
    echo "🚀 Creating project workspace: $project_name"
    
    # Create project directory structure
    mkdir -p "$project_path"/{src,docs,tests,scripts,config}
    
    # Create project-specific configuration
    cat > "$project_path/.herbstluftwm-project.conf" << PROJEOF
# Herbstluftwm Project Configuration
PROJECT_NAME="$project_name"
PROJECT_TYPE="$project_type"
PROJECT_PATH="$project_path"
MAIN_TAG="3:code"
TERM_TAG="1:term"
WEB_TAG="2:web"
FILES_TAG="4:files"
PROJEOF
    
    # Create project README
    cat > "$project_path/README.md" << READMEEOF
# $project_name

A $project_type project created with Herbstluftwm project manager.

## Structure
- \`src/\` - Source code
- \`docs/\` - Documentation
- \`tests/\` - Test files
- \`scripts/\` - Build and utility scripts
- \`config/\` - Configuration files

## Herbstluftwm Integration
This project is integrated with Herbstluftwm for optimal development workflow.

Use \`load-project.sh $project_name\` to set up the workspace.
READMEEOF
    
    # Create project-specific scripts based on type
    case "$project_type" in
        web)
            cat > "$project_path/scripts/dev-server.sh" << 'WEBEOF'
#!/bin/bash
# Development server for web project
echo "Starting development server..."
cd "$(dirname "$0")/.."
if [ -f "package.json" ]; then
    npm run dev
elif [ -f "index.html" ]; then
    python3 -m http.server 8080
else
    echo "No suitable development server found"
fi
WEBEOF
            chmod +x "$project_path/scripts/dev-server.sh"
            
            # Create basic web structure
            touch "$project_path/src/index.html"
            touch "$project_path/src/style.css"
            touch "$project_path/src/script.js"
            ;;
            
        python)
            cat > "$project_path/scripts/setup-venv.sh" << 'PYTHONEOF'
#!/bin/bash
# Python virtual environment setup
cd "$(dirname "$0")/.."
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
echo "Virtual environment created and activated"
PYTHONEOF
            chmod +x "$project_path/scripts/setup-venv.sh"
            
            # Create basic Python structure
            touch "$project_path/src/__init__.py"
            touch "$project_path/src/main.py"
            touch "$project_path/requirements.txt"
            ;;
            
        alpine)
            cat > "$project_path/scripts/build-package.sh" << 'ALPINEEOF'
#!/bin/bash
# Alpine package build script
cd "$(dirname "$0")/.."
if [ -f "APKBUILD" ]; then
    abuild -r
else
    echo "No APKBUILD found"
fi
ALPINEEOF
            chmod +x "$project_path/scripts/build-package.sh"
            
            # Create Alpine package structure
            touch "$project_path/APKBUILD"
            mkdir -p "$project_path/src"
            ;;
    esac
    
    echo "✅ Project '$project_name' created at: $project_path"
    echo "📂 Project type: $project_type"
    echo "🔧 Use: load-project.sh $project_name"
}

# Function to load project workspace
load_project() {
    local project_name="$1"
    
    if [ -z "$project_name" ]; then
        echo "Usage: load_project <name>"
        return 1
    fi
    
    local project_path="$PROJECTS_DIR/$project_name"
    local config_file="$project_path/.herbstluftwm-project.conf"
    
    if [ ! -f "$config_file" ]; then
        echo "Project '$project_name' not found or not a Herbstluftwm project"
        return 1
    fi
    
    # Load project configuration
    source "$config_file"
    
    echo "📂 Loading project: $PROJECT_NAME"
    
    # Set up development layout
    herbstclient use "$MAIN_TAG"
    ~/.config/herbstluftwm/scripts/layout-manager.sh dev
    
    # Open project in editor/IDE
    herbstclient focus left
    cd "$project_path"
    
    # Try to open with available editors
    if command -v code >/dev/null; then
        herbstclient spawn code "$project_path"
    elif command -v vim >/dev/null; then
        herbstclient spawn xterm -e "cd '$project_path' && vim ."
    else
        herbstclient spawn xterm -e "cd '$project_path' && ls -la"
    fi
    
    # Open terminal in project directory
    herbstclient focus right
    herbstclient focus up
    herbstclient spawn xterm -e "cd '$project_path' && bash"
    
    # Open file manager
    herbstclient use "$FILES_TAG"
    herbstclient spawn thunar "$project_path"
    
    # Return to main development tag
    herbstclient use "$MAIN_TAG"
    
    echo "✅ Project workspace loaded: $PROJECT_NAME"
}

# Function to list projects
list_projects() {
    echo "📂 Available projects:"
    if [ -d "$PROJECTS_DIR" ]; then
        for project in "$PROJECTS_DIR"/*/; do
            if [ -f "$project/.herbstluftwm-project.conf" ]; then
                project_name=$(basename "$project")
                source "$project/.herbstluftwm-project.conf"
                echo "  $project_name ($PROJECT_TYPE)"
            fi
        done
    else
        echo "No projects found"
    fi
}

# Main function
case "$1" in
    create)
        create_project "$2" "$3"
        ;;
    load)
        load_project "$2"
        ;;
    list)
        list_projects
        ;;
    *)
        echo "Herbstluftwm Project Manager"
        echo "Usage: $0 {create|load|list} [options]"
        echo ""
        echo "Commands:"
        echo "  create <name> [type]  - Create new project"
        echo "  load <name>           - Load project workspace"
        echo "  list                  - List available projects"
        echo ""
        echo "Project types: web, python, go, alpine, general"
        ;;
esac
EOF

chmod +x ~/.config/herbstluftwm/dev-setup/project-manager.sh

# Create quick project loader
cat > ~/.config/herbstluftwm/dev-setup/quick-load.sh << 'EOF'
#!/bin/bash
# Quick project loader with dmenu

projects_list=$(~/.config/herbstluftwm/dev-setup/project-manager.sh list | grep "  " | awk '{print $1}')

if [ -z "$projects_list" ]; then
    echo "No projects found"
    exit 1
fi

selected_project=$(echo "$projects_list" | dmenu -p "Load project:" -fn 'Noto Sans-12' -nb '#2e3440' -nf '#d8dee9' -sb '#88c0d0' -sf '#2e3440')

if [ -n "$selected_project" ]; then
    ~/.config/herbstluftwm/dev-setup/project-manager.sh load "$selected_project"
fi
EOF

chmod +x ~/.config/herbstluftwm/dev-setup/quick-load.sh

# Add keybindings for project management
echo 'herbstclient keybind $Mod-p spawn ~/.config/herbstluftwm/dev-setup/quick-load.sh' >> ~/.config/herbstluftwm/autostart

echo "Development environment setup created! 💻"
echo "Commands:"
echo "  Super + p - Quick project loader"
echo "  project-manager.sh create <name> [type] - Create project"
echo "  project-manager.sh load <name> - Load project"

What this does: Shows you how to create a complete integrated development environment with Herbstluftwm! 💻

Example 2: System Monitoring Dashboard 🟡

What we’re doing: Creating a comprehensive system monitoring dashboard using Herbstluftwm’s frame system for organized monitoring layout.

# Create monitoring dashboard system
mkdir -p ~/.config/herbstluftwm/monitoring

# Create monitoring dashboard script
cat > ~/.config/herbstluftwm/monitoring/dashboard.sh << 'EOF'
#!/bin/bash
# System Monitoring Dashboard for Herbstluftwm

# Configuration
MONITOR_TAG="7:sys"
REFRESH_INTERVAL=5

# Function to setup monitoring layout
setup_monitoring_layout() {
    echo "🖥️  Setting up monitoring dashboard..."
    
    # Switch to monitoring tag
    herbstclient use "$MONITOR_TAG"
    
    # Close any existing windows
    herbstclient close_and_remove
    
    # Create 2x2 grid layout
    herbstclient split right 0.5
    herbstclient focus left
    herbstclient split bottom 0.5
    herbstclient focus right
    herbstclient split bottom 0.5
    
    # Label frames for identification
    herbstclient set_attr clients.focus.title "System Overview"
}

# Function to launch monitoring tools
launch_monitoring_tools() {
    echo "🚀 Launching monitoring tools..."
    
    # Ensure we're on the monitoring tag
    herbstclient use "$MONITOR_TAG"
    
    # Top-left: System overview (htop)
    herbstclient focus left
    herbstclient focus up
    herbstclient spawn xterm -title "System Processes" -e htop
    
    # Top-right: Memory and disk usage
    herbstclient focus right
    herbstclient spawn xterm -title "Memory & Disk" -e 'watch -n 2 "echo \"=== MEMORY USAGE ===\"; free -h; echo; echo \"=== DISK USAGE ===\"; df -h; echo; echo \"=== SYSTEM LOAD ===\"; uptime"'
    
    # Bottom-left: Network monitoring
    herbstclient focus left
    herbstclient focus down
    herbstclient spawn xterm -title "Network Monitor" -e 'watch -n 3 "echo \"=== NETWORK CONNECTIONS ===\"; netstat -tuln | head -15; echo; echo \"=== NETWORK INTERFACES ===\"; ip addr show | grep -E \"(inet|UP|DOWN)\""'
    
    # Bottom-right: System logs
    herbstclient focus right
    herbstclient spawn xterm -title "System Logs" -e 'tail -f /var/log/messages'
    
    echo "✅ Monitoring dashboard launched!"
}

# Function to create advanced monitoring terminal
create_advanced_monitor() {
    local monitor_type="$1"
    
    case "$monitor_type" in
        "performance")
            herbstclient spawn xterm -title "Performance Monitor" -e '
                echo "🚀 Advanced Performance Monitor"
                echo "============================="
                while true; do
                    clear
                    echo "📊 System Performance - $(date)"
                    echo "=============================="
                    echo
                    echo "💾 Memory Usage:"
                    free -h
                    echo
                    echo "🖥️  CPU Usage:"
                    top -bn1 | grep "Cpu(s)" | awk "{print \"CPU: \" \$2 \" \" \$4}"
                    echo
                    echo "💿 Disk I/O:"
                    iostat -d 1 1 2>/dev/null | tail -n +4 || echo "iostat not available"
                    echo
                    echo "🌐 Network:"
                    cat /proc/net/dev | awk "NR>2 {print \$1 \" RX: \" \$2/1024/1024 \"MB TX: \" \$10/1024/1024 \"MB\"}" | head -5
                    echo
                    echo "Press Ctrl+C to exit"
                    sleep '$REFRESH_INTERVAL'
                done
            '
            ;;
        "security")
            herbstclient spawn xterm -title "Security Monitor" -e '
                echo "🔒 Security Monitoring Dashboard"
                echo "==============================="
                while true; do
                    clear
                    echo "🛡️  Security Status - $(date)"
                    echo "============================="
                    echo
                    echo "📊 Login Attempts:"
                    grep "authentication failure" /var/log/auth.log 2>/dev/null | tail -5 || echo "No recent authentication failures"
                    echo
                    echo "🔑 SSH Connections:"
                    ss -tuln | grep :22 || echo "SSH not listening"
                    echo
                    echo "🚪 Open Ports:"
                    netstat -tuln | head -10
                    echo
                    echo "🔥 Firewall Status:"
                    iptables -L | head -10 2>/dev/null || echo "iptables not accessible"
                    echo
                    echo "Press Ctrl+C to exit"
                    sleep '$REFRESH_INTERVAL'
                done
            '
            ;;
        "custom")
            # Create custom monitoring script
            cat > /tmp/custom-monitor.sh << 'CUSTOMEOF'
#!/bin/bash
echo "📊 Custom System Monitor"
echo "======================="
while true; do
    clear
    echo "🖥️  Custom Monitor - $(date)"
    echo "========================="
    echo
    echo "⚡ System Uptime:"
    uptime
    echo
    echo "🌡️  Temperature (if available):"
    if [ -f /sys/class/thermal/thermal_zone0/temp ]; then
        temp=$(cat /sys/class/thermal/thermal_zone0/temp)
        echo "CPU: $((temp / 1000))°C"
    else
        echo "Temperature monitoring not available"
    fi
    echo
    echo "📦 Package Count:"
    apk info | wc -l | awk '{print "Installed packages: " $1}'
    echo
    echo "🔄 Active Services:"
    rc-status | grep started | head -5
    echo
    echo "💡 System Info:"
    echo "Kernel: $(uname -r)"
    echo "Alpine: $(cat /etc/alpine-release 2>/dev/null || echo 'Unknown')"
    echo
    sleep 5
done
CUSTOMEOF
            chmod +x /tmp/custom-monitor.sh
            herbstclient spawn xterm -title "Custom Monitor" -e /tmp/custom-monitor.sh
            ;;
    esac
}

# Function to create monitoring menu
show_monitoring_menu() {
    local choice=$(echo -e "System Overview\nPerformance Monitor\nSecurity Monitor\nCustom Monitor\nNetwork Tools\nLog Viewer" | dmenu -p "Monitoring:" -fn 'Noto Sans-12' -nb '#2e3440' -nf '#d8dee9' -sb '#88c0d0' -sf '#2e3440')
    
    case "$choice" in
        "System Overview")
            launch_monitoring_tools
            ;;
        "Performance Monitor")
            create_advanced_monitor "performance"
            ;;
        "Security Monitor")
            create_advanced_monitor "security"
            ;;
        "Custom Monitor")
            create_advanced_monitor "custom"
            ;;
        "Network Tools")
            herbstclient spawn xterm -title "Network Tools" -e 'echo "🌐 Network Tools Menu"; echo "=================="; echo "Available commands:"; echo "- ping <host>"; echo "- traceroute <host>"; echo "- nslookup <domain>"; echo "- netstat -tuln"; echo "- ss -tuln"; bash'
            ;;
        "Log Viewer")
            herbstclient spawn xterm -title "Log Viewer" -e 'echo "📋 Log Viewer"; echo "==========="; echo "Available logs:"; echo "- /var/log/messages (system)"; echo "- /var/log/auth.log (authentication)"; echo "- dmesg (kernel)"; echo; echo "Example: tail -f /var/log/messages"; bash'
            ;;
    esac
}

# Main function
case "$1" in
    setup)
        setup_monitoring_layout
        ;;
    launch)
        launch_monitoring_tools
        ;;
    menu)
        show_monitoring_menu
        ;;
    performance)
        create_advanced_monitor "performance"
        ;;
    security)
        create_advanced_monitor "security"
        ;;
    custom)
        create_advanced_monitor "custom"
        ;;
    *)
        echo "Herbstluftwm Monitoring Dashboard"
        echo "Usage: $0 {setup|launch|menu|performance|security|custom}"
        echo ""
        echo "Commands:"
        echo "  setup       - Create monitoring layout"
        echo "  launch      - Launch basic monitoring tools"
        echo "  menu        - Show monitoring menu"
        echo "  performance - Advanced performance monitor"
        echo "  security    - Security monitoring"
        echo "  custom      - Custom system monitor"
        ;;
esac
EOF

chmod +x ~/.config/herbstluftwm/monitoring/dashboard.sh

# Add keybinding for monitoring dashboard
echo 'herbstclient keybind $Mod-m spawn ~/.config/herbstluftwm/monitoring/dashboard.sh menu' >> ~/.config/herbstluftwm/autostart

echo "System monitoring dashboard created! 📊"
echo "Commands:"
echo "  Super + m - Monitoring dashboard menu"
echo "  dashboard.sh setup - Create layout"
echo "  dashboard.sh launch - Launch tools"

What this does: Demonstrates comprehensive system monitoring with organized frame layouts! 📊

🚨 Fix Common Problems

Problem 1: Herbstluftwm won’t start ❌

What happened: Window manager fails to start or crashes immediately. How to fix it: Check configuration syntax and dependencies.

# Check Herbstluftwm configuration syntax
herbstluftwm --autostart ~/.config/herbstluftwm/autostart --check

# Test configuration with minimal setup
herbstluftwm --replace &

# Check X11 logs for errors
tail -f /var/log/Xorg.0.log

# Reset to minimal configuration
mv ~/.config/herbstluftwm/autostart ~/.config/herbstluftwm/autostart.backup
echo 'herbstclient set default_frame_layout grid' > ~/.config/herbstluftwm/autostart

Problem 2: Panel not displaying properly ❌

What happened: Status panel missing or showing incorrect information. How to fix it: Check panel dependencies and configuration.

# Check if lemonbar is available
command -v lemonbar || apk add lemonbar

# Check panel script
bash -x ~/.config/herbstluftwm/panel.sh

# Kill existing panel and restart
pkill lemonbar
~/.config/herbstluftwm/panel.sh &

# Check for missing fonts
fc-list | grep -i noto

Don’t worry! Herbstluftwm is highly configurable - debugging configurations is part of the learning process! 💪

💡 Simple Tips

  1. Start with basic layouts 📅 - Master simple splits before complex arrangements
  2. Use descriptive frame titles 🌱 - Label frames for better workspace organization
  3. Save useful layouts 🤝 - Store frequently used arrangements for quick access
  4. Master keyboard shortcuts 💪 - Efficiency comes from muscle memory

✅ Check Everything Works

Let’s verify your Herbstluftwm installation is working perfectly:

# Complete Herbstluftwm system verification
cat > /usr/local/bin/herbstluftwm-system-check.sh << 'EOF'
#!/bin/sh
echo "=== Herbstluftwm 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. Herbstluftwm Installation:"
if command -v herbstluftwm >/dev/null; then
    echo "✅ Herbstluftwm installed"
    herbstluftwm --version
else
    echo "❌ Herbstluftwm not found"
fi

echo -e "\n3. Configuration Files:"
if [ -f ~/.config/herbstluftwm/autostart ]; then
    echo "✅ Autostart configuration exists"
    echo "Configuration file: ~/.config/herbstluftwm/autostart"
else
    echo "❌ Autostart configuration missing"
fi

if [ -f ~/.config/herbstluftwm/panel.sh ]; then
    echo "✅ Panel script exists"
else
    echo "❌ Panel script missing"
fi

echo -e "\n4. Essential Applications:"
apps="xterm dmenu"
for app in $apps; do
    if command -v $app >/dev/null; then
        echo "✅ $app available"
    else
        echo "❌ $app not found"
    fi
done

echo -e "\n5. Desktop Session:"
if [ -f /usr/share/xsessions/herbstluftwm.desktop ]; then
    echo "✅ Desktop session configured"
else
    echo "❌ Desktop session not configured"
fi

echo -e "\n6. Startup Configuration:"
if [ -f ~/.xinitrc ]; then
    echo "✅ xinitrc configured for startx"
else
    echo "⚠️  xinitrc not found"
fi

echo -e "\n7. Theme Support:"
if [ -f ~/.config/herbstluftwm/themes.sh ]; then
    echo "✅ Theme system available"
    current_theme=$(~/.config/herbstluftwm/themes.sh current)
    echo "Current theme: $current_theme"
else
    echo "❌ Theme system not configured"
fi

echo -e "\n8. Workflow Scripts:"
if [ -f ~/.config/herbstluftwm/scripts/layout-manager.sh ]; then
    echo "✅ Layout manager available"
else
    echo "❌ Layout manager missing"
fi

if [ -f ~/.config/herbstluftwm/scripts/workspace-automation.sh ]; then
    echo "✅ Workspace automation available"
else
    echo "❌ Workspace automation missing"
fi

echo -e "\n9. Configuration Test:"
if herbstluftwm --autostart ~/.config/herbstluftwm/autostart --check >/dev/null 2>&1; then
    echo "✅ Configuration syntax valid"
else
    echo "❌ Configuration has syntax errors"
fi

echo -e "\n10. Getting Started:"
echo "🚀 To start Herbstluftwm:"
echo "   • From console: startx"
echo "   • From display manager: select 'herbstluftwm' session"
echo ""
echo "📋 Essential keybindings:"
echo "   • Super + Return: Terminal"
echo "   • Super + d: Application launcher"
echo "   • Super + s/v: Split frames"
echo "   • Super + h/j/k/l: Navigate frames"
echo "   • Super + 1-9: Switch workspaces"

echo -e "\nHerbstluftwm system check completed! ✅"
EOF

chmod +x /usr/local/bin/herbstluftwm-system-check.sh
/usr/local/bin/herbstluftwm-system-check.sh

Good output shows:

=== Herbstluftwm System Check ===
1. X11 Server:
✅ X.Org server installed
X.Org X Server 1.21.1

2. Herbstluftwm Installation:
✅ Herbstluftwm installed
herbstluftwm 0.9.5

3. Configuration Files:
✅ Autostart configuration exists
✅ Panel script exists

Herbstluftwm system check completed! ✅

🏆 What You Learned

Great job! Now you can:

  • ✅ Install and configure complete Herbstluftwm desktop environment
  • ✅ Create sophisticated frame-based layouts with dynamic splitting
  • ✅ Build custom status panels with system monitoring
  • ✅ Implement theme management and visual customization
  • ✅ Set up desktop sessions and startup automation
  • ✅ Create workflow management tools and project integration
  • ✅ Build system monitoring dashboards with organized layouts
  • ✅ Troubleshoot common Herbstluftwm configuration issues
  • ✅ Master advanced keyboard-driven window management

🎯 What’s Next?

Now you can try:

  • 📚 Exploring advanced Herbstluftwm scripting and automation
  • 🛠️ Creating custom panel widgets and system integrations
  • 🤝 Setting up multi-monitor configurations and workspace routing
  • 🌟 Building specialized workflows for different development environments!

Remember: Herbstluftwm’s frame-based approach offers unlimited flexibility! You’re now building highly efficient, customizable desktop environments on Alpine Linux! 🎉

Keep tiling and you’ll master dynamic window management! 💫