POV-Ray : Newsgroups : povray.programming : [patch] Patching unix.cpp Server Time
3 Jul 2024 05:47:19 EDT (-0400)
  [patch] Patching unix.cpp (Message 1 to 4 of 4)  
From: Wolfgang Wieser
Subject: [patch] Patching unix.cpp
Date: 29 Nov 2003 06:31:21
Message: <3fc88388@news.povray.org>
Here we go...

POVRay/X11 has code to handle window close and abort rendering 
when the window is closed. Unfortunately, the code does not work, 
at least not for me. 

This patch fixes that. Please apply. Read on below. 

----------------------------------------------------------------
--- povray-3.50c/src/unix.cpp   2003-01-07 02:08:30.000000000 +0100
+++ povray-3.50c-ww/src/unix.cpp        2003-11-29 12:09:14.000000000 +0100
@@ -382,7 +386,7 @@
 static XColor  *GetBestColor PARAMS((long r, long g, long b));
 static void     SelectVisual PARAMS((Visual **theVisual, unsigned int
*theDepth));
 static void     BuildColormap PARAMS((Visual *theVisual));
-static Bool     HandleXEvents PARAMS((XEvent *theEvent, Bool finished));
+static Bool     HandleXEvents PARAMS((Bool finished));
 static int      HandleXError PARAMS((Display *ErrorDisplay,
                                      XErrorEvent *ErrorEvent));
 static int      HandleXIOError PARAMS((Display *ErrorDisplay));
@@ -3187,10 +3200,7 @@
     /* Sit and handle events until we quit, but don't busy wait */
     while (!finished)
     {
-      XEvent theEvent;
-
-      XNextEvent(theDisplay, &theEvent);
-      finished = HandleXEvents(&theEvent, True);
+      finished = HandleXEvents(True);
     }
   }
 }
@@ -3220,12 +3230,9 @@
 
 int XWIN_Test_Abort()
 {
-  XEvent theEvent;
-
-  if (theDisplay && 
-      XCheckWindowEvent(theDisplay, theWindow, theEVENTMASK, &theEvent))
+  if(theDisplay)
   {
-    return (HandleXEvents(&theEvent, False) ? true : false);
+    return(HandleXEvents(False) ? true : false);
   }
 
   return false;
@@ -3327,7 +3334,7 @@
 *
 ******************************************************************************/
 
-int HandleXEvents(XEvent *theEvent, Bool finished)
+int HandleXEvents(Bool finished)
 {
   Bool   refresh = False;
   Bool   abortRender = False;
@@ -3335,9 +3342,20 @@
   int    refresh_x_max = 0;
   int    refresh_y_min = theImage->height - 1;
   int    refresh_y_max = 0;
+  int    npending=0;
+  XEvent _theEvent,*theEvent=&_theEvent;  // <-- (**)
 
   do
   {
+    if(!finished)
+    {
+      /* Process available events; return if no events available. */
+      if(!npending)  npending=XPending(theDisplay);
+      if(!npending)  break;
+      --npending;
+    }
+    XNextEvent(theDisplay,theEvent);
+    
     KeySym theKeySym;
 
 #if (X11_DEBUG > 0)
@@ -3465,7 +3510,7 @@
 #endif
     }
   }
-  while (XCheckWindowEvent(theDisplay, theWindow, theEVENTMASK, theEvent));
+  while(!finished);
 
   if (refresh && !abortRender)
   {
----------------------------------------------------------------

Basically, all I do is replacing XCheckWindowEvent() by XPending() and 
XNextEvent(). Furthermore, all event handling is now done in 
HandleXEvents() which results in cleaner design. (Previously, the first 
event was quieried outside while successive events were queried by 
HandleXEvents()). 

I tested this patch and it works (linux/X11R6). Should not make trouble 
on other OS/releases. 
Fixes: 
- Closing the window while tracing will now abort the render. 
- No events will stay and accumulate in the event queue until end of 
  rendering. 

In case something is unclear or it does not work, feel free to ask me. 

Wolfgang


Post a reply to this message

From: Christoph Hormann
Subject: Re: [patch] Patching unix.cpp
Date: 29 Nov 2003 07:02:04
Message: <6vdm91-baj.ln1@triton.imagico.de>
Wolfgang Wieser wrote:
> Here we go...
> 
> POVRay/X11 has code to handle window close and abort rendering 
> when the window is closed. Unfortunately, the code does not work, 
> at least not for me. 
> 
> This patch fixes that. Please apply. Read on below. 
> 
> [...]

It would be useful if you could simply post the changed functions as a 
whole instead of a diff so i don't need to dig out the 3.5 code to test 
the patch.

I did not completely understand your description, does this also fix the 
problem that when you close the render window with a mouse click after 
completition (with the +p option) the mouse event is passed to whatever 
is behind the window?

> Fixes: 
> - Closing the window while tracing will now abort the render. 

I always considered this as a feature rather than a bug...

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 25 Oct. 2003 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Wolfgang Wieser
Subject: Re: [patch] Patching unix.cpp
Date: 29 Nov 2003 07:16:45
Message: <3fc88e2c@news.povray.org>
Christoph Hormann wrote:
> Wolfgang Wieser wrote:
>> Here we go...
>> 
>> POVRay/X11 has code to handle window close and abort rendering
>> when the window is closed. Unfortunately, the code does not work,
>> at least not for me.
>> 
>> This patch fixes that. Please apply. Read on below.
>> 
>> [...]
> 
> It would be useful if you could simply post the changed functions as a
> whole instead of a diff so i don't need to dig out the 3.5 code to test
> the patch.
> 
Okay. I changed the following functions:

-----------------------------------------------------------------------
void XWIN_display_finished()
{
  if (theDisplay && opts.Options & PROMPTEXIT)
  {
    Bool   finished = False;

    Status_Info("\nClick on window to exit...");

#ifdef USE_CURSOR
    /* Get rid of the watch cursor now that we don't need it anymore */
    XUndefineCursor(theDisplay, theWindow);
    XFreeCursor(theDisplay, theCursor);
#endif

    /* Sit and handle events until we quit, but don't busy wait */
    while (!finished)
    {
      finished = HandleXEvents(True);
    }
  }
}
-----------------------------------------------------------------------
int XWIN_Test_Abort()
{
  if(theDisplay)
  {
    return(HandleXEvents(False) ? true : false);
  }

  return false;
}
-----------------------------------------------------------------------
int HandleXEvents(Bool finished)
{
  Bool   refresh = False;
  Bool   abortRender = False;
  int    refresh_x_min = theImage->width - 1;
  int    refresh_x_max = 0;
  int    refresh_y_min = theImage->height - 1;
  int    refresh_y_max = 0;
  int    npending=0;
  XEvent _theEvent,*theEvent=&_theEvent;  // (**)

  do
  {
    if(!finished)
    {
      /* Process available events; return if no events available. */
      if(!npending)  npending=XPending(theDisplay);
      if(!npending)  break;
      --npending;
    }
    XNextEvent(theDisplay,theEvent);
    
    KeySym theKeySym;

#if (X11_DEBUG > 0)
  Debug_Info("\nGot event %ld - ", theEvent->type);
#endif

    switch (theEvent->type)
    {

<<SNIPPED UNCHANGED CODE>>

    }
  }
  while(!finished);

  if (refresh && !abortRender)
  {
#if (X11_DEBUG > 0)
    Debug_Info("Refresh %dx%d+%d+%d\n", refresh_x_min, refresh_y_min,
              refresh_x_max - refresh_x_min, refresh_y_max - refresh_y_min);
#endif
    XPutImage(theDisplay,theWindow,theGC,theImage,
              refresh_x_min, refresh_y_min, refresh_x_min, refresh_y_min,
              (unsigned int)(refresh_x_max - refresh_x_min),
              (unsigned int)(refresh_y_max - refresh_y_min));
    XFlush(theDisplay);
  }

  return (abortRender);
}
-----------------------------------------------------------------------

Please note the (**) above. Once the patch is applied, one should 
remove it and use "theEvent." instead of "theEvent->"; just did that 
to make the patch more readable. 

> I did not completely understand your description, does this also fix the
> problem that when you close the render window with a mouse click after
> completition (with the +p option) the mouse event is passed to whatever
> is behind the window?
> 
Since we leave when the button is pressed, the below window will get 
an enter notify with button pressed and the button release event 
(unless you move the mouse away before). Applications may treat that 
as complete button press and release. I'll write a separate patch for 
that in some minutes. 

>> Fixes:
>> - Closing the window while tracing will now abort the render.
> 
> I always considered this as a feature rather than a bug...
> 
It is easier to disable this feature once it is working than make it 
work at all...


Post a reply to this message

From: Nicolas Calimet
Subject: Re: [patch] Patching unix.cpp
Date: 1 Dec 2003 08:03:13
Message: <3FCB3C11.7040103@free.fr>
Thanks for this finding and patch.  It's been basically applied
to the current development version.  Waiting for more  ;-p

	- NC


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.