> This is not a correct solution.  usleep() is hiding the problem further,
> not
> fixing it.
> 
> I do not have the time to help you though.
> 
> -- Thomas Adam

Thomas, all,

I disagree.

Increasing the usleep timer from 1 micro second to 10000 = 1/100th second
*is* the correct solution. Nobody who is right in his mind wants to query 
the mouse up to a million times per second.
The patch fixed the CPU hogging, which was about 80% of my problem. 

Attached is a new patch that 
1) changes the previous patch slightly
2) *adds* calls of WaitForButtonsUp() right after calls of
   is_function_allowed() when returning false:

    if (!is_function_allowed(F_MOVE, NULL, fw, RQORIG_PROGRAM_US, False))
    {
        WaitForButtonsUp(True); /* added! */
        return False;
    }

Part 2 fixes ALL of the remaining issues I had.
For example the issue that a mouse cursor (intended to move or resize) 
is marking text instead when entering a nearby terminal.

WaitForButtonsUp() *marks the mouse cursor busy* and
*discards superflous button events* that would cause
funny things! It just had a flaw.

> I do not have the time to help you though.

This is hardly the right attitude for a maintainer
of an open source project.

Regards,
   Axel

--- fvwm-2.6.5_orig/fvwm/events.c       2012-04-20 12:41:05.000000000 +0200
+++ fvwm-2.6.5/fvwm/events.c    2012-09-28 17:51:39.012361804 +0200
@@ -4665,10 +4665,15 @@
        return count;
 }
 
-/* Wait for all mouse buttons to be released
- * This can ease some confusion on the part of the user sometimes
+/* Wait for all mouse buttons to be released and
+ * activate the 'busy-cursor' to signalise a user
+ * "The action your're trying to perform won't work!"
  *
- * Discard superflous button events during this wait period. */
+ * It's an excellent idea to call this function if
+ * is_function_allowed() returns False. See also: move_resize.c
+ *
+ * Discard superflous button events during this wait period. 
+ */
 void WaitForButtonsUp(Bool do_handle_expose)
 {
        unsigned int mask;
@@ -4678,6 +4683,7 @@
        int count;
        int use_wait_cursor;
        XEvent e;
+    useconds_t uSeconds = 5;
 
        if (FQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, &JunkY,
                          &JunkX, &JunkY, &mask) == False)
@@ -4729,12 +4735,17 @@
                                 * okay here */
                        }
                        mask &= DEFAULT_ALL_BUTTONS_MASK;
-                       usleep(1);
+            usleep(uSeconds); /* was: usleep(1); */
                }
-               if (use_wait_cursor == 0 && count == 20)
+               if (use_wait_cursor == 0 && count == 4)
                {
                        GrabEm(CRS_WAIT, GRAB_NORMAL);
                        use_wait_cursor = 1;
+           /* Original code used usleep(1) above an thus called 
FQueryPointer() almost
+            * *a MILLION times per second* causing 100% CPU load and battery 
drain to boot!
+            * Axel Rohde (who neither owns a laptop nor a powerplant) August 
26 2012
+            */
+                       uSeconds = 10000;
                }
        }
        UngrabEm(GRAB_NORMAL);
--- fvwm-2.6.5_orig/fvwm/move_resize.c  2011-09-30 11:00:53.000000000 +0200
+++ fvwm-2.6.5/fvwm/move_resize.c       2012-09-26 22:06:26.657895084 +0200
@@ -1098,10 +1098,12 @@
 
        if (!is_function_allowed(F_MOVE, NULL, fw, RQORIG_PROGRAM_US, False))
        {
+           WaitForButtonsUp(True);
                return False;
        }
        if (!is_function_allowed(F_RESIZE, NULL, fw, RQORIG_PROGRAM_US, True))
        {
+           WaitForButtonsUp(True);
                return False;
        }
 
@@ -1755,6 +1757,7 @@
 
        if (!is_function_allowed(F_MOVE, NULL, fw, RQORIG_PROGRAM_US, False))
        {
+           WaitForButtonsUp(True);
                return;
        }
        /* gotta have a window */
@@ -3666,7 +3669,8 @@
 
        if (!is_function_allowed(F_RESIZE, NULL, fw, RQORIG_PROGRAM_US, True))
        {
-               XBell(dpy, 0);
+//             XBell(dpy, 0); // a non-resizable window is very common and NO 
cause for alarm!
+               WaitForButtonsUp(True);
                return False;
        }
 
@@ -4734,10 +4738,9 @@
        FvwmWindow *fw = exc->w.fw;
 
        if (
-               !is_function_allowed(
-                       F_MAXIMIZE, NULL, fw, RQORIG_PROGRAM_US, False))
+               !is_function_allowed(F_MAXIMIZE, NULL, fw, RQORIG_PROGRAM_US, 
False))
        {
-               XBell(dpy, 0);
+//             XBell(dpy, 0); // a non-maximizable window is pretty common and 
NO cause for alarm
                return;
        }
        /* Check for "global" flag ("absolute" is for compatibility with E) */


-------- Original-Nachricht --------
> Datum: Sun, 23 Sep 2012 14:31:53 +0100
> Von: Thomas Adam <[email protected]>
> An: Axel Rohde <[email protected]>
> CC: [email protected], [email protected]
> Betreff: Re: FIX for fvwm burning CPU on resize/move unresizable/unmovable 
> windows

> On Sun, Sep 23, 2012 at 03:28:30PM +0200, Axel Rohde wrote:
> > FIX for fvwm burning CPU on resize/move unresizable/unmovable windows
> > 
> > Hi Thomas, FVWM Workers,
> 
> Can you please send unified diffs, please?
> 
> > *** fvwm-2.6.5/fvwm/events.c_orig       2012-09-22 12:54:50.838388626
> +0200
> > --- fvwm-2.6.5/fvwm/events.c    2012-09-22 12:55:00.818388316 +0200
> > ***************
> > *** 4729,4736 ****
> >                                  * okay here */
> >                         }
> >                         mask &= DEFAULT_ALL_BUTTONS_MASK;
> > !                       usleep(1);
> > !               }
> >                 if (use_wait_cursor == 0 && count == 20)
> >                 {
> >                         GrabEm(CRS_WAIT, GRAB_NORMAL);
> > --- 4729,4738 ----
> >                                  * okay here */
> >                         }
> >                         mask &= DEFAULT_ALL_BUTTONS_MASK;
> > !                       usleep(10000); /* fixes 50% to 100% (P4) CPU
> load when trying */ 
> > !             /* to move/resize unmovable/unresizable windows. Tested on
> */
> > !             /* P4 3GHz/HT, ATi X550, and core i5-3550. Axel Rohde Sep.
> 22 2012 */
> > !               }                  
> 
> This is not a correct solution.  usleep() is hiding the problem further,
> not
> fixing it.
> 
> I do not have the time to help you though.
> 
> -- Thomas Adam

Attachment: unified.diff.gz
Description: application/gzip

Reply via email to