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
12 #include <gcj/javaprims.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>
34 void gnu::gcj::xlib::XAnyEvent::init()
36 ::XEvent
* event
= new ::XEvent
;
37 int *pipes
= new int[2];
39 structure
= reinterpret_cast<gnu::gcj::RawData
*>(event
);
40 pipefds
= reinterpret_cast<gnu::gcj::RawData
*>(pipes
);
43 void gnu::gcj::xlib::XAnyEvent::finalize()
46 int *pipe
= reinterpret_cast<int *>(pipefds
);
54 jboolean
gnu::gcj::xlib::XAnyEvent::loadNext(jboolean block
)
56 ::Display
* dpy
= (::Display
*) display
->display
;
57 ::XEvent
* evt
= (::XEvent
*) structure
;
68 int *pipe
= reinterpret_cast<int *>(pipefds
);
69 int xfd
= XConnectionNumber(dpy
);
71 int n
= (xfd
> pipefd
? xfd
: pipefd
) + 1;
75 FD_SET(pipefd
, &rfds
);
76 int sel
= _Jv_select (n
, &rfds
, NULL
, NULL
, NULL
);
79 if (FD_ISSET(xfd
, &rfds
))
84 if (FD_ISSET(pipefd
, &rfds
))
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
;
105 void gnu::gcj::xlib::XAnyEvent::setType(jint type
)
107 ::XEvent
* event
= (::XEvent
*) structure
;
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
;
136 XSendEvent(dpy
, destination
->getXID(), propagate
? True
: False
,
142 throw new XException(JvNewStringLatin1("conversion to wire "
146 throw new XException(display
, status
);
149 /* All other return values indicate success. Ie. (status ==
150 1) indicates success, not BadRequest. */