natXAnyEvent.cc (loadNext): Added timeout.
authorScott Gilbertson <scottg@mantatest.com>
Mon, 7 Mar 2005 16:49:37 +0000 (16:49 +0000)
committerScott Gilbertson <sgilbertson@gcc.gnu.org>
Mon, 7 Mar 2005 16:49:37 +0000 (16:49 +0000)
2005-04-07  Scott Gilbertson  <scottg@mantatest.com>

* gnu/gcj/xlib/natXAnyEvent.cc (loadNext): Added timeout.
* gnu/awt/xlib/XCanvasPeer.java (setBackground): Removed
    throw UnsupportedOperationException, fixed comments.
    (setFont, setForeground): Fixed comments.
* gnu/awt/xlib/XEventLoop.java (postNextEvent): Changed
    return type to boolean.
    (getNextEvent): Fixed javadocs.
* gnu/awt/xlib/XToolkit.java (interrupted): Removed field.
    (nativeQueueEmpty): Removed unused code.
    (iterateNativeQueue): Removed outer loop.

From-SVN: r96029

libjava/ChangeLog
libjava/gnu/awt/xlib/XCanvasPeer.java
libjava/gnu/awt/xlib/XEventLoop.java
libjava/gnu/awt/xlib/XToolkit.java
libjava/gnu/gcj/xlib/natXAnyEvent.cc

index dd315eccf61001b6069ff25f63c680b5a0ef7a49..9645824ba1a34a8d8b21973e7a88504921d304e3 100644 (file)
@@ -1,3 +1,15 @@
+2005-04-07  Scott Gilbertson  <scottg@mantatest.com>
+       * gnu/gcj/xlib/natXAnyEvent.cc (loadNext): Added timeout.
+       * gnu/awt/xlib/XCanvasPeer.java (setBackground): Removed
+       throw UnsupportedOperationException, fixed comments.
+       (setFont, setForeground): Fixed comments.
+       * gnu/awt/xlib/XEventLoop.java (postNextEvent): Changed
+       return type to boolean.
+       (getNextEvent): Fixed javadocs.
+       * gnu/awt/xlib/XToolkit.java (interrupted): Removed field.
+       (nativeQueueEmpty): Removed unused code.
+       (iterateNativeQueue): Removed outer loop.
+
 2005-03-06  Roger Sayle  <roger@eyesopen.com>
 
        PR libgcj/20155
index 5daee59dcd711f08815454a3d8515195099bb972..83646b1f3385d58ce0a1336ff3faf2e77d7e4065 100644 (file)
@@ -349,7 +349,8 @@ public class XCanvasPeer implements CanvasPeer
 
   public void setBackground(Color color)
   {
-    throw new UnsupportedOperationException("not implemented");
+    /* default canvas peer does not keep track of background, since it won't
+     * paint anything. */
   }
 
   public void setBounds(int x, int y, int width, int height)
@@ -405,13 +406,13 @@ public class XCanvasPeer implements CanvasPeer
 
   public void setFont(Font font)
   {
-    /* default canvas peer does keep track of font, since it won't
-       write anything. */
+    /* default canvas peer does not keep track of font, since it won't
+       paint anything. */
   }
 
   public void setForeground(Color color)
   {
-    /* default canvas peer does keep track of foreground, since it won't
+    /* default canvas peer does not keep track of foreground, since it won't
        paint anything. */
   }
        
index 8f7828770e85341b99aa0f12b8fabbfb57f6d8b2..149ee736d7c1918f9afc663f1f327475630fa440 100644 (file)
@@ -42,15 +42,20 @@ public class XEventLoop
     anyEvent.interrupt();
   }
 
-  void postNextEvent(boolean block)
+  /** If there's an event available, post it.
+   * @return true if an event was posted
+   */
+  boolean postNextEvent(boolean block)
   {
     AWTEvent evt = getNextEvent(block);
     if (evt != null)
       queue.postEvent(evt);
+    return evt != null;
   }
     
-  /** get next event. Will block until events become available. */
+  /** Get the next event.
+   * @param block If true, block until an event becomes available
+   */
   public AWTEvent getNextEvent(boolean block)
   {
     // ASSERT:
@@ -62,7 +67,7 @@ public class XEventLoop
       {
         event = createEvent();        
         event = lightweightRedirector.redirect(event);
-      }    
+      }
     return event;
   }
 
@@ -169,7 +174,7 @@ public class XEventLoop
         return null;
         
       default:
-        String msg = "Do no know how to handle event (" + anyEvent + ")";
+        String msg = "Do not know how to handle event (" + anyEvent + ")";
         throw new RuntimeException (msg);
     }
   }
index 1e937c2386700ae57424c590b6f3f752cc8adf0d..c6e140eb3e1619f99b1f8d2168165d6af7343feb 100644 (file)
@@ -444,8 +444,6 @@ public class XToolkit extends ClasspathToolkit
     throw new java.lang.UnsupportedOperationException ();
   }
 
-  boolean interrupted;
-
   public boolean nativeQueueEmpty() 
   { 
     return eventLoop.isIdle(); 
@@ -453,14 +451,19 @@ public class XToolkit extends ClasspathToolkit
 
   public void wakeNativeQueue() 
   {
-    interrupted = true;
     eventLoop.interrupt();
   }
 
+  /** Checks the native event queue for events.  If blocking, waits until an
+   * event is available before returning, unless interrupted by
+   * wakeNativeQueue.  If non-blocking, returns immediately even if no
+   * event is available.
+   *
+   * @param locked The calling EventQueue
+   * @param block If true, waits for a native event before returning
+   */
   public void iterateNativeQueue(java.awt.EventQueue locked, boolean block) 
   {
-    interrupted = false;
-    while (!interrupted)
-      eventLoop.postNextEvent(block);
-  }; 
+    eventLoop.postNextEvent(block);
+  }
 }
index 0bef563ed2d999262d1c87e6fee1bca0c6cd3f7f..26d3b604b04fdc8338316c068e524fcb21b216a3 100644 (file)
@@ -69,11 +69,14 @@ jboolean gnu::gcj::xlib::XAnyEvent::loadNext(jboolean block)
   int xfd = XConnectionNumber(dpy);
   int pipefd = pipe[0];
   int n = (xfd > pipefd ? xfd : pipefd) + 1;
+  struct timeval timeout;
+  timeout.tv_usec = 100000;  // 100ms timeout
+  timeout.tv_sec = 0;
   fd_set rfds;
   FD_ZERO(&rfds);
   FD_SET(xfd, &rfds);
   FD_SET(pipefd, &rfds);  
-  int sel = _Jv_select (n, &rfds, NULL, NULL, NULL);
+  int sel = _Jv_select (n, &rfds, NULL, NULL, &timeout);
   if (sel > 0)
     {
       if (FD_ISSET(xfd, &rfds))