#!/bin/bash
# Configure IceWM and LightDM for privacy
set -euo pipefail

echo "Configuring desktop environment..."

# Create IceWM configuration directory
mkdir -p /etc/icewm

# Create minimal IceWM configuration
cat >/etc/icewm/preferences <<'EOF'
# IceWM Configuration for KNEL-Football
Theme="Default/default.theme"
TitleBarHeight=20
TitleBarCentered=1
ShowTaskBar=1
TaskBarShowAllWindows=1
TaskBarShowCPU=0
TaskBarShowNet=0
TaskBarShowClock=1
TaskBarClockLeds=0
WinMenuItems=256
InputFocusSloppy=1
UseMouseWheel=1
QuickSwitch=1
QuickSwitchAllWorkspaces=1
AutoReloadMenus=0
ShowPopupsWhileGrabbed=0
EOF

# Create IceWM theme
cat >/etc/icewm/theme <<'EOF'
Theme="Flat/default.theme"
TitleBarBkColor="rgb:40/40/40"
TitleBarTextColor="rgb:FF/FF/FF"
MenuBkColor="rgb:30/30/30"
MenuTextColor="rgb:FF/FF/FF"
ActiveTaskBarBkColor="rgb:50/50/50"
NormalTaskBarBkColor="rgb:40/40/40"
NormalButtonBkColor="rgb:40/40/40"
ActiveButtonBkColor="rgb:60/60/60"
NormalForeground="rgb:FF/FF/FF"
ActiveForeground="rgb:FF/FF/FF"
EOF

# Configure LightDM for privacy (hide usernames)
mkdir -p /etc/lightdm/lightdm.conf.d

cat >/etc/lightdm/lightdm.conf.d/99-privacy.conf <<'EOF'
[Seat:*]
greeter-hide-users=true
greeter-show-manual-login=true
greeter-allow-guest=false
allow-guest=false
autologin-user=
autologin-user-timeout=0
autologin-session=lightdm-xsession
EOF

# Create autostart directory for IceWM
mkdir -p /etc/skel/.config/autostart

# Remmina autostart
cat >/etc/skel/.config/autostart/remmina.desktop <<'EOF'
[Desktop Entry]
Name=Remmina
Comment=Remote Desktop Client
Exec=remmina
Terminal=false
Type=Application
Categories=Network;
EOF

# Create simple IceWM startup script
mkdir -p /etc/X11/Xsession.d
cat >/etc/X11/Xsession.d/99icewm <<'EOF'
# Start IceWM window manager
exec icewm-session
EOF

# Set IceWM as default session
update-alternatives --install /usr/bin/x-window-manager x-window-manager /usr/bin/icewm 50

echo "Desktop environment configured successfully."
