# Setting Up a Desktop Environment on Android Using VNC and Termux-X11

This guide will walk you through setting up a desktop environment on your Android device using either VNC or Termux-X11. By running a Linux distribution (such as Debian or Ubuntu) in a chroot environment within Termux, you can display a full desktop interface on your phone or tablet.

## Prerequisites
Before you begin, ensure you have the following:
- **Termux App**: Download it from [F-Droid](https://f-droid.org/packages/com.termux/) or [GitHub](https://github.com/termux/termux-app/releases).
- **chroot-distro Setup**: Install `chroot-distro` and set up a Linux chroot environment (e.g., Debian or Ubuntu). Follow the [official guide](https://github.com/Magisk-Modules-Alt-Repo/chroot-distro) if you need help with this step.

---

## Part 1: Using VNC for the Desktop Environment

### 1. Install a VNC Viewer App
To view the desktop, install a VNC viewer app on your Android device. Here are some recommended options:
- [RealVNC Viewer](https://play.google.com/store/apps/details?id=com.realvnc.viewer.android)
- bVNC Pro
- MultiVNC

### 2. Install Required Packages
In your chroot environment (e.g., Debian or Ubuntu), open a terminal and run these commands:
```bash
apt update -y && apt upgrade -y 
apt install tightvncserver sudo dbus-x11 xfce4 xfce4-goodies xfce4-terminal -y 
```

### 3. Configure the Desktop Environment
Set up the desktop with these steps:
```bash
# Set the default terminal emulator
update-alternatives --config x-terminal-emulator
# A menu will appear. Type the number for `xfce4-terminal` and press Enter.

# Start the VNC server to generate configuration files
vncserver

# Stop the server after the files are created
vncserver -kill :1

# Edit the VNC startup file to launch XFCE4
echo 'startxfce4 &' >> ~/.vnc/xstartup
```

### 4. Launch the Desktop
Start the VNC server and connect to it:
```bash
# Start the VNC server
vncserver
# Note the address it provides, e.g., `localhost:1`.

# Connect using your VNC viewer app
# Enter the address (e.g., `localhost:1`) and tap "Connect."

# To stop the server later
vncserver -kill :1
```

#### Example Screenshots
- **Debian via VNC**:  
  ![Debian GUI](https://github.com/Magisk-Modules-Alt-Repo/chroot-distro/raw/main/screenshot/debian_vnc.png)
- **Ubuntu via VNC**:  
  ![Ubuntu GUI](https://github.com/Magisk-Modules-Alt-Repo/chroot-distro/raw/main/screenshot/ubuntu.png)

---

## Part 2: Using Termux-X11 for the Desktop Environment
- **Parrot Security via Termux-X11**:  
![Parrot GUI](https://github.com/Magisk-Modules-Alt-Repo/chroot-distro/raw/main/images/parrot_termux_x11.jpg) 
### 1. Install Termux-X11
Download and install Termux-X11 from the [official repository](https://github.com/termux/termux-x11/releases).

### 2. Install Required Packages in Termux
Open the Termux app and run these commands:
```bash
pkg update -y && pkg upgrade -y 
pkg install x11-repo root-repo -y
pkg install tsu ncurses-utils termux-x11-nightly pulseaudio virglrenderer-android -y
```

### 3. Install the Desktop Environment in the Chroot
Inside your chroot environment, install XFCE4:
```bash
apt install sudo dbus-x11 xfce4 xfce4-goodies xfce4terminal -y
# Installs the XFCE4 desktop and tools

# Optional: Install an audio server
apt install mpd
# Edit `mpd.conf` if audio setup is needed (e.g., for music playback).
```

### 4. Launch the Desktop
Use a script to simplify the process:
1. Download the script `chroot-xfce.sh` from [here](https://github.com/Magisk-Modules-Alt-Repo/chroot-distro/blob/main/scripts/chroot-xfce.sh).
2. Make it executable:
   ```bash
   chmod +x chroot-xfce.sh
   ```
3. Run it from Termux:
   ```bash
   ./chroot-xfce.sh
   ```
   or
   ```bash
   bash chroot-xfce.sh
   ```

**Note**: The script includes a menu to launch XFCE4 with audio support via Termux-X11.  
**Screenshot of Script**:  
![chroot-xfce.sh](https://github.com/user-attachments/assets/3f5db05f-fdde-40da-aab1-bb754ca98e35)

---

## Additional Tips
- Run `apt` commands inside the chroot environment, not Termux directly.
- If audio doesn’t work, check the `mpd.conf` file for configuration issues.
- For more help, see the [chroot-distro documentation](https://github.com/Magisk-Modules-Alt-Repo/chroot-distro).

---

This guide is designed to be clear and easy to follow, whether you're a beginner or an advanced user. Enjoy your Android desktop experience!
