#!/bin/bash

# (c) Sean Parkin 13/12/10.  xp-proj-enabler
# This little enabler is intended to be called by an XP launching script. All it 
# does is to run an infinite print loop in a hidden dummy xterm. For some reason 
# this cures the choppy 'proj' rotation problem on the newest versions of X11 on 
# the Mac.  Inclusion of the delay (i.e. the 'sleep' line) prevents this process 
# from hogging massive amounts of CPU time. Without it, the dummy xterm in which 
# this script operates wastes roughly 100% of a single CPU's worth of resources, 
# which gets the processor very hot, causing CPU fans to run at full tilt.  With 
# the 'sleep' delay, CPU time for this process is typically less than ~1%, which 
# is unnoticeable in normal usage. This workaround is intended to be unobtrusive 
# and invisible. It is stopped automatically on exit from XP so long as you exit 
# properly, i.e. by typing 'exit' at the XP>> prompt. If you use XP on a Mac and 
# you have been frustrated by the poor 'proj' performance, you will be amazed at 
# how well this simple bit of nonsense works. For what it is worth, 'tput civis' 
# makes the cursor invisible. This version also writes out the number of seconds 
# (approximately) that XP has been running. 

# Note:  Much of this script is superfluous - it does not need to count anything 
# or time anything, or hide the cursor.  The only important task is to interrupt 
# the system periodically so that the xterm launched by XP doesn't suffer a race 
# condition.  I also have a version in (completely trivial) python.  Email me. 

tput civis
count=1
time=0
while true
do
   echo "  XP-proj-enabler: a fix for slow, choppy 'proj' rotation in OSX  "
   echo "  Don't believe it ?  See what happens if you close this window!  "
   echo "        XP-proj-enabler has been running for $time seconds        "
   wait
   sleep 0.04
   count=$(( count + 1 ))
   time=$(( count / 20 ))
done
