#!/bin/bash# Fix PyCharm's translucent-overlay rendering on WSL2 by forcing X11.# This script disables problematic graphics backends (Metal and Compose rendering)# and forces X11 rendering, which is more stable on WSL2.set-euopipefail# Color outputRED='\033[0;31m'GREEN='\033[0;32m'YELLOW='\033[1;33m'NC='\033[0m'# No Color# Fixes to applydeclare-aFIXES=("-Dsun.java2d.metal=false""-Dcompose.swing.render.on.graphics=false""-Dawt.toolkit.name=xlib")fix_vmoptions_file(){localfile=$1if[[!-f"$file"]];thenecho-e"${YELLOW}File not found: $file${NC}"return1fiecho"Processing: $file"localmodified=falseforfixin"${FIXES[@]}";doifgrep-q"^${fix}$""$file";thenecho-e"${GREEN} ✓ Already present: $fix${NC}"elseecho"$fix">>"$file"echo-e"${GREEN} ✓ Added: $fix${NC}"modified=truefidoneif[["$modified"==true]];thenecho-e"${GREEN} Modified: $file${NC}"fireturn0}main(){echo"PyCharm WSL2 Dimmed Overlay Fix"echo"================================"echo""# Find PyCharm config directorieslocalconfig_dir="$HOME/.config/JetBrains"if[[!-d"$config_dir"]];thenecho-e"${RED}Error: PyCharm config directory not found at $config_dir${NC}"exit1fiecho"Found PyCharm config directory: $config_dir"echo""# Process all PyCharm versionslocalfound_any=falseforpycharm_version_dirin"$config_dir"/PyCharm*/;doif[[-d"$pycharm_version_dir"]];thenlocalversion_nameversion_name=$(basename"$pycharm_version_dir")localvmoptions_file="$pycharm_version_dir/pycharm64.vmoptions"echo"Version: $version_name"if[[!-f"$vmoptions_file"]];thenecho-e"${YELLOW} vmoptions file not found, creating it${NC}"touch"$vmoptions_file"fiiffix_vmoptions_file"$vmoptions_file";thenfound_any=truefiecho""fidoneif[["$found_any"==false]];thenecho-e"${YELLOW}No PyCharm installations were modified${NC}"exit1fiecho-e"${GREEN}Fix applied successfully!${NC}"echo""echo"Please restart PyCharm for changes to take effect."echo""echo"What this fix does:"echo" • Disables Metal rendering (macOS only, incompatible with WSL2)"echo" • Disables Compose graphics rendering (unstable on WSL2)"echo" • Forces X11 rendering (stable on WSL2)"echo""}main"$@"