MacPerl's spin-cursor (was The Camel and his counfounded Ball)

[email protected] (Alan Fry) Thu, 13 Jun 2002 16:22:41 +0100
Newsgroups perl.macperl.porters,perl.macperl.toolbox
Message-ID <p05100300b92e63b9431d@[158.152.146.73]>
At 11:17 am +0100 12/06/02, I wrote to MacPerl-Toolbox:
>The following script demonstrates the phenomenon:
>
>	#!perl
>	# exit via Cmd+period
>
>	use Mac::Events;
>	use Mac::Events qw(@Event);
>
>	$Event[mouseDown] = sub { while (WaitMouseUp()) {} };
>
>	WaitNextEvent while 1;
>
>
>About two seconds after mouse-down MacPerl switches to the 
>spin-cursor and remains that way until mouse-up.
>
>IMO this behaviour is highly undesirable since it spoils any 
>application involving a 'WaitMouseUp' event, such as 
>button-tracking, auto-scrolling and similar regular GUI functions.

The attached patch appears to provide a solution. So far as I can 
determine the normal functions of MacPerl are unaffected by this 
change.

However I am a long long way from fully understanding the inner 
workings of MacPerl in relation to the spin cursor, so the proposal 
needs the scrutiny of wiser heads than mine -- to say the least.

Alan Fry

-----------

--- 
Millgate:Programming:BuildMacPerl:macperl_src:macperl:MPMain.c.orig 
	Mon Jan  7 14:36:34 2002
+++ Millgate:Programming:BuildMacPerl:macperl_src:macperl:MPMain.c 
	Tue Jun 11 16:54:12 2002
@@ -1182,6 +1182,7 @@
  	long		now;
  	EventRecord myEvent;
  	Point		mouse;
+	char		up;

  	if (!gSacrificialGoat)		/* Memory trouble */
  		if (gRunningPerl)			/* This 
script has gone too far */
@@ -1191,6 +1192,7 @@
  				exit(0);		/* Save our 
sorry ass. Shouldn't happen */

  	now = LMGetTicks();
+	up  = LMGetMouseButtonState();
  	if (spinning = busy) {
  		if (now - lastNonBusy < (gInBackground ? 
BACK_BUSY_WAIT : FRONT_BUSY_WAIT))
  			spinning = false;
@@ -1201,6 +1203,9 @@
  		events = activMask | updateMask | highLevelEventMask | osMask;
  		spinning = false;
  	}
+
+	if (!up)
+		spinning = false;

  	MaintainMenuBar();

-------------