Dead
[official-gcc.git] / gomp-20050608-branch / libjava / gnu / gcj / xlib / natXAnyEvent.cc
blob0bef563ed2d999262d1c87e6fee1bca0c6cd3f7f
1 /* Copyright (C) 2000 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 #include <config.h>
10 #include <platform.h>
12 #include <gcj/javaprims.h>
13 #include <jvm.h>
15 #include <X11/Xlib.h>
17 #include <gcj/cni.h>
18 #include <gnu/gcj/RawData.h>
20 #include <java/lang/RuntimeException.h>
22 #include <java/lang/System.h>
23 #include <java/io/PrintStream.h>
25 #include <gnu/gcj/xlib/Display.h>
26 #include <gnu/gcj/xlib/Window.h>
27 #include <gnu/gcj/xlib/XAnyEvent.h>
28 #include <gnu/gcj/xlib/XExposeEvent.h>
29 #include <gnu/gcj/xlib/XException.h>
31 #include <unistd.h>
32 #include <posix.h>
34 void gnu::gcj::xlib::XAnyEvent::init()
36 ::XEvent* event = new ::XEvent;
37 int *pipes = new int[2];
38 pipe(pipes);
39 structure = reinterpret_cast<gnu::gcj::RawData*>(event);
40 pipefds = reinterpret_cast<gnu::gcj::RawData*>(pipes);
43 void gnu::gcj::xlib::XAnyEvent::finalize()
45 delete structure;
46 int *pipe = reinterpret_cast<int *>(pipefds);
47 close(pipe[0]);
48 close(pipe[1]);
49 delete [] pipefds;
50 pipefds = 0;
51 structure = 0;
54 jboolean gnu::gcj::xlib::XAnyEvent::loadNext(jboolean block)
56 ::Display* dpy = (::Display*) display->display;
57 ::XEvent* evt = (::XEvent*) structure;
59 if (XPending(dpy))
61 XNextEvent(dpy, evt);
62 return true;
65 if (!block)
66 return false;
68 int *pipe = reinterpret_cast<int *>(pipefds);
69 int xfd = XConnectionNumber(dpy);
70 int pipefd = pipe[0];
71 int n = (xfd > pipefd ? xfd : pipefd) + 1;
72 fd_set rfds;
73 FD_ZERO(&rfds);
74 FD_SET(xfd, &rfds);
75 FD_SET(pipefd, &rfds);
76 int sel = _Jv_select (n, &rfds, NULL, NULL, NULL);
77 if (sel > 0)
79 if (FD_ISSET(xfd, &rfds))
81 XNextEvent(dpy, evt);
82 return true;
84 if (FD_ISSET(pipefd, &rfds))
86 char c;
87 read(pipefd, &c, 1);
90 return false;
93 void gnu::gcj::xlib::XAnyEvent::interrupt()
95 int *pipe = reinterpret_cast<int *>(pipefds);
96 write(pipe[1], "W", 1);
99 jint gnu::gcj::xlib::XAnyEvent::getType()
101 ::XEvent* event = (::XEvent*) structure;
102 return event->type;
105 void gnu::gcj::xlib::XAnyEvent::setType(jint type)
107 ::XEvent* event = (::XEvent*) structure;
108 event->type = type;
111 gnu::gcj::xlib::Window* gnu::gcj::xlib::XAnyEvent::getWindow()
113 ::XEvent* event = (::XEvent*) structure;
114 return display->getWindow(event->xany.window);
117 void gnu::gcj::xlib::XAnyEvent::setWindow(gnu::gcj::xlib::Window* window)
119 ::XEvent* event = (::XEvent*) structure;
120 event->xany.window = window->getXID();
123 jlong gnu::gcj::xlib::XAnyEvent::getSerial()
125 ::XEvent* event = (::XEvent*) structure;
126 return event->xany.serial;
129 void gnu::gcj::xlib::XAnyEvent::send(gnu::gcj::xlib::Window* destination,
130 jboolean propagate, jlong mask)
132 ::Display* dpy = (::Display*) display->display;
133 ::XEvent* event = (::XEvent*) structure;
135 Status status =
136 XSendEvent(dpy, destination->getXID(), propagate ? True : False,
137 mask, event);
139 switch (status)
141 case 0:
142 throw new XException(JvNewStringLatin1("conversion to wire "
143 "protocol failed"));
144 case BadWindow:
145 case BadValue:
146 throw new XException(display, status);
148 default:
149 /* All other return values indicate success. Ie. (status ==
150 1) indicates success, not BadRequest. */
151 ; // NOP