dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/Xsharp Application.cs,1.2,1.3 Displa


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/Xsharp Application.cs,1.2,1.3 Display.cs,1.5,1.6 Timer.cs,1.1,1.2
Date: Sat, 21 Jun 2003 07:16:21 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv20918/Xsharp

Modified Files:
        Application.cs Display.cs Timer.cs 
Log Message:


Split the event loop into "ProcessPendingEvents()" and
"WaitForEvent()" so that it is possible to return back to the
application between events.


Index: Application.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Application.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Application.cs      6 Jun 2003 07:47:06 -0000       1.2
--- Application.cs      21 Jun 2003 11:16:18 -0000      1.3
***************
*** 315,318 ****
--- 315,358 ----
  
        /// <summary>
+       /// <para>Process pending events, and return immediately.</para>
+       /// </summary>
+       ///
+       /// <returns>
+       /// <para>Returns <see langword="true"/> if events were processed,
+       /// or <see langword="false"/> if there are no pending events.</para>
+       /// </returns>
+       public bool ProcessPendingEvents()
+                       {
+                               if(display != null)
+                               {
+                                       return display.ProcessPendingEvents();
+                               }
+                               else
+                               {
+                                       return false;
+                               }
+                       }
+ 
+       /// <summary>
+       /// <para>Wait for the next event, process it, and then return.</para>
+       /// </summary>
+       ///
+       /// <returns>
+       /// <para>Returns <see langword="true"/> if an event was processed,
+       /// or <see langword="false"/> if <c>Quit</c> was detected.</para>
+       /// </returns>
+       public bool WaitForEvent()
+                       {
+                               if(display != null)
+                               {
+                                       return display.WaitForEvent();
+                               }
+                               else
+                               {
+                                       return false;
+                               }
+                       }
+ 
+       /// <summary>
        /// <para>Get the name of this program (i.e. the argv[0] value).</para>
        /// </summary>

Index: Display.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Display.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** Display.cs  7 Jun 2003 07:40:16 -0000       1.5
--- Display.cs  21 Jun 2003 11:16:18 -0000      1.6
***************
*** 466,478 ****
                        }
  
!       /// <summary>
!       /// <para>Run the main event loop on this display.</para>
!       /// </summary>
!       ///
!       /// <remarks>
!       /// <para>The main event loop will run until the <c>Quit</c>
!       /// method is called.</para>
!       /// </remarks>
!       public void Run()
                        {
                                try
--- 466,481 ----
                        }
  
!       // Event types for "HandleNextEvent".
!       private enum AppEvent
!       {
!               NoEvent,
!               Regular,
!               Timer,
!               Quit,
! 
!       }; // enum AppEvent
! 
!       // Handle the next event and return what kind of event it was.
!       private AppEvent HandleNextEvent(bool wait)
                        {
                                try
***************
*** 482,536 ****
                                        int timeout;
  
!                                       Xlib.XFlush(dpy);
                                        inMainLoop = true;
-                                       while(!quit)
-                                       {
-                                               // Flush any requests that are 
in the outgoing queue.
-                                               Xlib.XFlush(dpy);
- 
-                                               // Process timers that need to 
be activated.
-                                               Timer.ActivateTimers(this);
  
!                                               // Do we have pending expose 
events to process?
!                                               if(pendingExposes)
                                                {
!                                                       // If there are still 
events in the queue,
!                                                       // then process them 
before the exposes.
!                                                       if(Xlib.XEventsQueued
!                                                                       (dpy, 2 
/* QueuedAfterFlush */) != 0)
!                                                       {
!                                                               // Read the 
next event and dispatch it.
!                                                               
Xlib.XNextEvent(dpy, out xevent);
!                                                               
DispatchEvent(ref xevent);
!                                                       }
!                                                       else
                                                        {
!                                                               // Process the 
pending expose events.
!                                                               
InputOutputWidget widget;
!                                                               
while(exposeList != null)
!                                                               {
!                                                                       widget 
= exposeList;
!                                                                       
exposeList = exposeList.nextExpose;
!                                                                       
widget.Expose();
!                                                               }
!                                                               pendingExposes 
= false;
                                                        }
                                                }
!                                               else
                                                {
-                                                       // Wait for the next 
event.
                                                        timeout = 
Timer.GetNextTimeout(this);
!                                                       if(timeout < 0)
                                                        {
-                                                               
Xlib.XNextEvent(dpy, out xevent);
                                                                
DispatchEvent(ref xevent);
!                                                       }
!                                                       else
!                                                       {
!                                                               
if(Xlib.XNextEventWithTimeout
!                                                                       (dpy, 
out xevent, timeout) > 0)
!                                                               {
!                                                                       
DispatchEvent(ref xevent);
!                                                               }
                                                        }
                                                }
--- 485,556 ----
                                        int timeout;
  
!                                       // We are now in the main loop 
processing events.
                                        inMainLoop = true;
  
!                                       // Flush any requests that are in the 
outgoing queue.
!                                       Xlib.XFlush(dpy);
!       
!                                       // Process "Quit".
!                                       if(quit)
!                                       {
!                                               return AppEvent.Quit;
!                                       }
!       
!                                       // Process timers that need to be 
activated.
!                                       if(Timer.ActivateTimers(this))
!                                       {
!                                               return AppEvent.Timer;
!                                       }
!       
!                                       // Do we have pending expose events to 
process?
!                                       if(pendingExposes)
!                                       {
!                                               // If there are still events in 
the queue,
!                                               // then process them before the 
exposes.
!                                               if(Xlib.XEventsQueued
!                                                               (dpy, 2 /* 
QueuedAfterFlush */) != 0)
                                                {
!                                                       // Read the next event 
and dispatch it.
!                                                       Xlib.XNextEvent(dpy, 
out xevent);
!                                                       DispatchEvent(ref 
xevent);
!                                               }
!                                               else
!                                               {
!                                                       // Process the pending 
expose events.
!                                                       InputOutputWidget 
widget;
!                                                       while(exposeList != 
null)
                                                        {
!                                                               widget = 
exposeList;
!                                                               exposeList = 
exposeList.nextExpose;
!                                                               widget.Expose();
                                                        }
+                                                       pendingExposes = false;
                                                }
!                                               return AppEvent.Regular;
!                                       }
!                                       else
!                                       {
!                                               // Wait for the next event.
!                                               if(wait)
                                                {
                                                        timeout = 
Timer.GetNextTimeout(this);
!                                               }
!                                               else
!                                               {
!                                                       timeout = 0;
!                                               }
!                                               if(timeout < 0)
!                                               {
!                                                       Xlib.XNextEvent(dpy, 
out xevent);
!                                                       DispatchEvent(ref 
xevent);
!                                                       return AppEvent.Regular;
!                                               }
!                                               else
!                                               {
!                                                       
if(Xlib.XNextEventWithTimeout
!                                                               (dpy, out 
xevent, timeout) > 0)
                                                        {
                                                                
DispatchEvent(ref xevent);
!                                                               return 
AppEvent.Regular;
                                                        }
                                                }
***************
*** 541,544 ****
--- 561,610 ----
                                        inMainLoop = false;
                                        Unlock();
+                               }
+ 
+                               // If we get here, then there were no events 
processed.
+                               return AppEvent.NoEvent;
+                       }
+ 
+       /// <summary>
+       /// <para>Process pending events, and return immediately.</para>
+       /// </summary>
+       ///
+       /// <returns>
+       /// <para>Returns <see langword="true"/> if events were processed,
+       /// or <see langword="false"/> if there are no pending events.</para>
+       /// </returns>
+       public bool ProcessPendingEvents()
+                       {
+                               AppEvent ev = HandleNextEvent(false);
+                               return (ev != AppEvent.NoEvent && ev != 
AppEvent.Quit);
+                       }
+ 
+       /// <summary>
+       /// <para>Wait for the next event, process it, and then return.</para>
+       /// </summary>
+       ///
+       /// <returns>
+       /// <para>Returns <see langword="true"/> if an event was processed,
+       /// or <see langword="false"/> if <c>Quit</c> was detected.</para>
+       /// </returns>
+       public bool WaitForEvent()
+                       {
+                               return (HandleNextEvent(true) != AppEvent.Quit);
+                       }
+ 
+       /// <summary>
+       /// <para>Run the main event loop on this display.</para>
+       /// </summary>
+       ///
+       /// <remarks>
+       /// <para>The main event loop will run until the <c>Quit</c>
+       /// method is called.</para>
+       /// </remarks>
+       public void Run()
+                       {
+                               while(HandleNextEvent(true) != AppEvent.Quit)
+                               {
+                                       // Nothing to do here - just wait for 
the quit.
                                }
                        }

Index: Timer.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Timer.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Timer.cs    7 Jun 2003 02:18:39 -0000       1.1
--- Timer.cs    21 Jun 2003 11:16:18 -0000      1.2
***************
*** 344,348 ****
  
        // Activate timers that have fired on a particular display.
!       internal static void ActivateTimers(Display dpy)
                        {
                                // Bail out early if there are no timers, to 
avoid
--- 344,348 ----
  
        // Activate timers that have fired on a particular display.
!       internal static bool ActivateTimers(Display dpy)
                        {
                                // Bail out early if there are no timers, to 
avoid
***************
*** 352,356 ****
                                        if(dpy.timerQueue == null)
                                        {
!                                               return;
                                        }
                                }
--- 352,356 ----
                                        if(dpy.timerQueue == null)
                                        {
!                                               return false;
                                        }
                                }
***************
*** 358,361 ****
--- 358,362 ----
                                Timer timer;
                                DateTime next;
+                               bool activated = false;
                                for(;;)
                                {
***************
*** 380,383 ****
--- 381,385 ----
  
                                        // Invoke the timer's callback delegate.
+                                       activated = true;
                                        timer.callback(timer.state);
  
***************
*** 405,408 ****
--- 407,411 ----
                                        }
                                }
+                               return activated;
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]