1 /* Copyright (C) 1999, 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
9 #include <X11/Xproto.h>
13 #include <java/lang/System.h>
14 #include <java/lang/RuntimeException.h>
15 #include <java/io/PrintStream.h>
18 #include <gnu/gcj/xlib/Display.h>
19 #include <gnu/gcj/xlib/XConnectException.h>
20 #include <gnu/gcj/xlib/XException.h>
22 void gnu::gcj::xlib::Display::init()
24 ::Display
* openedDisplay
= XOpenDisplay(0); // default display
26 if (openedDisplay
== 0) {
27 jstring msg
= JvNewStringLatin1("Unable to open display");
28 throw new gnu::gcj::xlib::XConnectException(msg
);
31 display
= reinterpret_cast<gnu::gcj::RawData
*>(openedDisplay
);
34 void gnu::gcj::xlib::Display::finalize()
36 if (display
== 0) return;
37 ::Display
* dpy
= (::Display
*) display
;
41 jint
gnu::gcj::xlib::Display::getDefaultScreenNumber()
43 ::Display
* dpy
= (::Display
*) display
;
44 return DefaultScreen(dpy
);
47 jint
gnu::gcj::xlib::Display::getDefaultRootWindowXID()
49 ::Display
* dpy
= (::Display
*) display
;
50 return DefaultRootWindow(dpy
);
53 jint
gnu::gcj::xlib::Display::internAtom(jstring name
)
55 ::Display
* dpy
= (::Display
*) display
;
56 int len
= JvGetStringUTFLength(name
);
58 JvGetStringUTFRegion(name
, 0, name
->length(), cName
);
60 bool onlyIfExists
= false;
61 return XInternAtom(dpy
, cName
, onlyIfExists
);
64 jstring
gnu::gcj::xlib::Display::getAtomName(jint atom
)
66 ::Display
* dpy
= (::Display
*) display
;
67 char* cName
= XGetAtomName(dpy
, atom
);
68 jstring name
= JvNewStringLatin1(cName
);
73 static int handleXError(Display
* dpy
, XErrorEvent
* xee
)
75 const int ERROR_TEXT_LENGTH
= 256;
76 char errorText
[ERROR_TEXT_LENGTH
];
77 XGetErrorText(dpy
, xee
->error_code
, errorText
, ERROR_TEXT_LENGTH
);
78 int requestCode
= xee
->request_code
;
80 if (requestCode
== X_GetImage
)
82 /* The current implementation of Drawable.copyIntoXImage()
83 will generate harmless X_GetImage errors if the initially
84 requested area is not completly within the drawable. Until
85 we find a better solution, simply ignore these errors. */
89 java::lang::System::err
->print(JvNewStringLatin1("X error: "));
90 java::lang::System::err
->print(JvNewStringLatin1(errorText
));
91 java::lang::System::err
->print(JvNewStringLatin1(", serial="));
92 java::lang::System::err
->print((jlong
) xee
->serial
);
93 java::lang::System::err
->print(JvNewStringLatin1(", requestCode="));
94 java::lang::System::err
->print((jint
) requestCode
);
96 if (requestCode
< 128)
99 snprintf(number
, 8, "%d", requestCode
);
102 XGetErrorDatabaseText(dpy
, "XRequest", number
,
103 "", errorText
, ERROR_TEXT_LENGTH
);
104 java::lang::System::err
->print(JvNewStringLatin1(" ("));
105 java::lang::System::err
->print(JvNewStringLatin1(errorText
));
106 java::lang::System::err
->print(JvNewStringLatin1(")"));
109 java::lang::System::err
->print(JvNewStringLatin1(", minorCode="));
110 java::lang::System::err
->print((jint
) xee
->minor_code
);
111 java::lang::System::err
->print(JvNewStringLatin1(", XID="));
112 java::lang::System::err
->println((jlong
) xee
->resourceid
);
117 void gnu::gcj::xlib::Display::staticInit()
119 if (XInitThreads() == 0)
121 char msg
[] = "threads are not supported on this platform";
122 throw new ::java::lang::RuntimeException(JvNewStringLatin1(msg
));
125 XSetErrorHandler(&handleXError
);
128 void gnu::gcj::xlib::Display::flush()
130 ::Display
* dpy
= (::Display
*) display
;