Commit 9ed9eda6 by Scott Gilbertson Committed by Scott Gilbertson

natXAnyEvent.cc (loadNext): Added timeout.

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
parent 3eb54e5f
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> 2005-03-06 Roger Sayle <roger@eyesopen.com>
PR libgcj/20155 PR libgcj/20155
......
...@@ -349,7 +349,8 @@ public class XCanvasPeer implements CanvasPeer ...@@ -349,7 +349,8 @@ public class XCanvasPeer implements CanvasPeer
public void setBackground(Color color) 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) public void setBounds(int x, int y, int width, int height)
...@@ -405,13 +406,13 @@ public class XCanvasPeer implements CanvasPeer ...@@ -405,13 +406,13 @@ public class XCanvasPeer implements CanvasPeer
public void setFont(Font font) public void setFont(Font font)
{ {
/* default canvas peer does keep track of font, since it won't /* default canvas peer does not keep track of font, since it won't
write anything. */ paint anything. */
} }
public void setForeground(Color color) 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. */ paint anything. */
} }
......
...@@ -42,15 +42,20 @@ public class XEventLoop ...@@ -42,15 +42,20 @@ public class XEventLoop
anyEvent.interrupt(); 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); AWTEvent evt = getNextEvent(block);
if (evt != null) if (evt != null)
queue.postEvent(evt); 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) public AWTEvent getNextEvent(boolean block)
{ {
// ASSERT: // ASSERT:
...@@ -62,7 +67,7 @@ public class XEventLoop ...@@ -62,7 +67,7 @@ public class XEventLoop
{ {
event = createEvent(); event = createEvent();
event = lightweightRedirector.redirect(event); event = lightweightRedirector.redirect(event);
} }
return event; return event;
} }
...@@ -169,7 +174,7 @@ public class XEventLoop ...@@ -169,7 +174,7 @@ public class XEventLoop
return null; return null;
default: 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); throw new RuntimeException (msg);
} }
} }
......
...@@ -444,8 +444,6 @@ public class XToolkit extends ClasspathToolkit ...@@ -444,8 +444,6 @@ public class XToolkit extends ClasspathToolkit
throw new java.lang.UnsupportedOperationException (); throw new java.lang.UnsupportedOperationException ();
} }
boolean interrupted;
public boolean nativeQueueEmpty() public boolean nativeQueueEmpty()
{ {
return eventLoop.isIdle(); return eventLoop.isIdle();
...@@ -453,14 +451,19 @@ public class XToolkit extends ClasspathToolkit ...@@ -453,14 +451,19 @@ public class XToolkit extends ClasspathToolkit
public void wakeNativeQueue() public void wakeNativeQueue()
{ {
interrupted = true;
eventLoop.interrupt(); 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) public void iterateNativeQueue(java.awt.EventQueue locked, boolean block)
{ {
interrupted = false; eventLoop.postNextEvent(block);
while (!interrupted) }
eventLoop.postNextEvent(block);
};
} }
...@@ -69,11 +69,14 @@ jboolean gnu::gcj::xlib::XAnyEvent::loadNext(jboolean block) ...@@ -69,11 +69,14 @@ jboolean gnu::gcj::xlib::XAnyEvent::loadNext(jboolean block)
int xfd = XConnectionNumber(dpy); int xfd = XConnectionNumber(dpy);
int pipefd = pipe[0]; int pipefd = pipe[0];
int n = (xfd > pipefd ? xfd : pipefd) + 1; int n = (xfd > pipefd ? xfd : pipefd) + 1;
struct timeval timeout;
timeout.tv_usec = 100000; // 100ms timeout
timeout.tv_sec = 0;
fd_set rfds; fd_set rfds;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(xfd, &rfds); FD_SET(xfd, &rfds);
FD_SET(pipefd, &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 (sel > 0)
{ {
if (FD_ISSET(xfd, &rfds)) if (FD_ISSET(xfd, &rfds))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment