# KDE Plasma Installation and Revert Guide for reTerminal DM4

## Device Information
- **Model**: Raspberry Pi Compute Module 4 (CM4)
- **CPU**: Cortex-A72 (4 cores)
- **RAM**: 8GB
- **Current Desktop**: LXDE with Openbox
- **Display**: 10-inch, 1280x800

## Pre-Installation State

### Current Desktop Packages
- libobrender32v5
- libobt2v5:arm64
- lxsession
- lxsession-data
- lxsession-logout
- openbox
- pcmanfm

### Current Session Manager
- Default: `/usr/bin/startx-rpd` (priority 90)
- Available: `/usr/bin/lxsession` (priority 49)
- Available: `/usr/bin/openbox-session` (priority 40)
- Current mode: auto (points to startx-rpd)

### Available Desktop Sessions
- lightdm-xsession.desktop
- openbox.desktop
- rpd-x.desktop

### Installation Date
- Date: 2026-01-09

---

## Installation Steps

### Step 1: Update System
```bash
sudo apt-get update
sudo apt-get upgrade -y
```

### Step 2: Install KDE Plasma
```bash
# Install KDE Plasma desktop (lightweight version)
sudo apt-get install -y kde-plasma-desktop

# Install on-screen keyboard for touchscreen
sudo apt-get install -y maliit-keyboard

# Install additional KDE utilities
sudo apt-get install -y kde-standard
```

### Step 3: Configure Default Desktop

**Option A: Switch at Login (Recommended - Safest)**
1. Log out of current session
2. At login screen, click on the session/desktop selector (usually in top-right corner)
3. Select "Plasma (X11)" or "plasmax11"
4. Log in

**Option B: Set as Default**
```bash
# Set KDE as default desktop session
sudo update-alternatives --config x-session-manager
# Select: /usr/bin/startplasma-x11 (priority 40)
```

**Note**: KDE Plasma X11 session is available at `/usr/share/xsessions/plasmax11.desktop`

### Step 4: Configure Touchscreen Settings

After logging into KDE:

1. **Enable On-Screen Keyboard:**
   - System Settings > Input Devices > Virtual Keyboard
   - Enable "Show on-screen keyboard when needed"

2. **Adjust Touch Settings:**
   - System Settings > Input Devices > Touchpad/Touchscreen
   - Adjust touch sensitivity
   - Enable tap-to-click

3. **UI Scaling for Touch:**
   - System Settings > Display and Monitor
   - Set scale to 125% or 150% for better touch targets

4. **Disable Heavy Effects (for better performance):**
   - System Settings > Workspace Behavior > Desktop Effects
   - Disable resource-intensive effects
   - Keep basic animations enabled

### Step 5: Reboot
```bash
sudo reboot
```

---

## Post-Installation Verification

After reboot, verify KDE is working:
```bash
echo $XDG_CURRENT_DESKTOP
# Should show: KDE or plasma

ps aux | grep -i plasma
# Should show KDE processes running
```

---

## Cloud-Init (Automated Install)

For EMMC provisioning you can install KDE, set it as the default session, and enable touch options automatically using cloud-init. Use the example that includes KDE and touch:

- **File:** `emmc-provisioning/cloud-init/user-data-kiosk-username-ssh.example`

It installs `kde-plasma-desktop`, `maliit-keyboard`, and `xinput-calibrator`; sets LightDM default session to Plasma (X11); writes KDE config for touch-friendly scaling and touch-point feedback; and autostarts the on-screen keyboard. Chromium kiosk and SSH are configured in the same example. Replace the password hash and use it as your cloud-init `user-data` when building the image.

---

## Reverting to LXDE

### Method 1: Switch at Login Screen (Easiest)

1. Log out of current session
2. At the login screen, click on the session/desktop selector (usually top-right)
3. Select "Openbox" or "RPD-X" session
4. Log in

### Method 1b: Use Revert Script

A revert script is provided: `revert-to-lxde.sh`
```bash
# Copy script to device and run
./revert-to-lxde.sh
```

### Method 2: Change Default Session

```bash
# Set LXDE as default
sudo update-alternatives --config x-session-manager
# Select LXDE option (usually /usr/bin/startlxde or similar)
```

### Method 3: Remove KDE (Complete Revert)

If you want to completely remove KDE:

```bash
# Remove KDE packages
sudo apt-get remove --purge kde-plasma-desktop kde-standard
sudo apt-get autoremove -y
sudo apt-get autoclean

# Restore LXDE as default
sudo update-alternatives --config x-session-manager
# Select LXDE

# Reboot
sudo reboot
```

### Method 4: Reinstall LXDE (if removed)

If LXDE was accidentally removed:

```bash
sudo apt-get update
sudo apt-get install --reinstall lxde
sudo update-alternatives --config x-session-manager
```

---

## Troubleshooting

### KDE Won't Start
```bash
# Check if KDE is installed
dpkg -l | grep kde-plasma

# Check available sessions
ls /usr/share/xsessions/

# Try starting KDE manually
startplasma-wayland
# or
startplasma-x11
```

### Performance Issues
- Disable desktop effects in System Settings
- Reduce animation duration
- Use X11 instead of Wayland (if Wayland is causing issues)

### Touchscreen Not Working
```bash
# Check touchscreen device
xinput list

# Calibrate touchscreen
sudo apt-get install xinput-calibrator
xinput_calibrator
```

### Chromium Autostart Issues
Your existing Chromium autostart configuration should work with KDE.
If it doesn't, check:
```bash
cat ~/.config/autostart/chromium-kiosk.desktop
```

---

## Performance Notes

- **Expected RAM Usage**: 400-800MB for KDE Plasma
- **Expected CPU Usage**: Low to moderate (Cortex-A72 handles it well)
- **Boot Time**: Slightly longer than LXDE (~10-15 seconds more)

---

## Files Modified/Created

- `/usr/share/xsessions/` - Desktop session files
- `~/.config/plasma-org.kde.plasma.desktop-appletsrc` - KDE panel configuration
- `~/.config/kwinrc` - Window manager settings
- `~/.config/plasmarc` - Plasma settings

---

## Backup Before Installation

To create a backup of current desktop settings:
```bash
# Backup current desktop configuration
mkdir -p ~/desktop-backup
cp -r ~/.config/lx* ~/desktop-backup/ 2>/dev/null
cp -r ~/.config/openbox ~/desktop-backup/ 2>/dev/null
```

---

## Rollback Checklist

If you need to revert:
- [ ] Switch session at login screen (easiest)
- [ ] Change default session via update-alternatives
- [ ] Remove KDE packages if needed
- [ ] Verify LXDE is working
- [ ] Check Chromium autostart still works
- [ ] Verify touchscreen calibration

---

## Support

If you encounter issues:
1. Check system logs: `journalctl -xe`
2. Check X/Wayland logs: `~/.xsession-errors`
3. Verify packages: `dpkg -l | grep kde`
4. Check available sessions: `ls /usr/share/xsessions/`
