Subject: CursorMove fix

From: Austin Donnelly <[email-masked]>
Date: Tue, 9 Dec 1997 00:01:28 +0000 (GMT)

CursorMove uses the standard "GetTwoArguments" function to read the two
integer args it needs.  The GetTwoArguments() function make some attempt
to process the 'p' convention, where something like:

  CursorMove 10 10

means move 10 percent of the screen, while

  CursorMove 10p 10p

means move 10 pixels.

Unfortunately, it doesn't quite do its job right: it won't let you mix
pixels and percentages.

Because it does two sscanf()s, if the first succeeds then it never
gets to look at the second, which has support for the 'p' stuff.  This
happens if you say something like:

  CursorMove 0 10p

since sscanf("0 10p", "%d %d", &a, &b) is quite happy to parse this.

I've patched this to only do a single sscanf(), and interpret the
return code to see how much was correctly parsed.

I've also updated the manpage to include the 'p' syntax in its
description of the CursorMove command, and added some checking of
GetTwoArguments()'s return code to movecursor().

I notice that GetOneArgument() uses two sscanf()s as well, but I
havn't thought too hard about when that might fail, so I've left it
alone.

Hope this helps,
Austin
------------------------------------------------------------
--- builtins.c~	Wed Aug 20 00:41:27 1997
+++ builtins.c	Mon Dec  8 23:28:54 1997
@@ -617,6 +617,11 @@
   int val1, val2, val1_unit,val2_unit,n;
 
   n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit);
+  if (n != 2)
+  {
+    fvwm_msg(ERR, "movecursor", "CursorMove needs 2 arguments");
+    return;
+  }
 
   XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild,
                  &x,&y,&JunkX, &JunkY, &JunkMask);
--- fvwm2.man~	Sun Aug 24 19:11:40 1997
+++ fvwm2.man	Mon Dec  8 23:40:49 1997
@@ -864,9 +864,12 @@
 Moves the mouse pointer by \fIhorizontal\fP pages in the X direction
 and \fIvertical\fP pages in the Y direction.  Either or both entries
 may be negative.  Both horizontal and vertical values are expressed in
-percent of pages, so "CursorMove 100 100" means to move down and left
-by one full page.  "CursorMove 50 25" means to move left half a page
-and down a quarter of a page.  The CursorMove function should not be
+percent of pages, so "CursorMove 100 100" means to move down and right
+by one full page.  "CursorMove 50 25" means to move right half a page
+and down a quarter of a page.  Alternatively, the distance can be
+specified in pixels by appending a 'p' to the horizontal and/or vertical
+specification.  For example "CursorMove -10p -10p" means move ten
+pixels up and ten pixels left.  The CursorMove function should not be
 called from pop-up menus.
 
 .IP "CursorStyle \fIcontext cursornum\fP"
--- misc.c~	Tue Jun 24 15:01:39 1997
+++ misc.c	Mon Dec  8 23:32:58 1997
@@ -392,21 +392,18 @@
   *val1_unit = Scr.MyDisplayWidth;
   *val2_unit = Scr.MyDisplayHeight;
 
-  n = sscanf(action,"%d %d", val1, val2);
-  if(n == 2)
-    return 2;
-
   c1 = 's';
   c2 = 's';
   n = sscanf(action,"%d%c %d%c", val1, &c1, val2, &c2);
 
-  if(n != 4)
-    return 0;
-  
+  if(n<3)
+    return 0;  /* didn't get the second number */
+
   if((c1 == 'p')||(c1 == 'P'))
     *val1_unit = 100;
 
-  if((c2 == 'p')||(c2 == 'P'))
+  /* if n==4 then c2 is valid, so take account of it */
+  if((n==4) && ((c2 == 'p')||(c2 == 'P')))
     *val2_unit = 100;
 
   return 2;
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].