OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [gcj/] [xlib/] [natDisplay.cc] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
/* Copyright (C) 1999, 2000  Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
This software is copyrighted work licensed under the terms of the
6
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
details.  */
8
 
9
#include <X11/Xproto.h>
10
#include <X11/Xlib.h>
11
#include <stdio.h>
12
 
13
#include <java/lang/System.h>
14
#include <java/lang/RuntimeException.h>
15
#include <java/io/PrintStream.h>
16
#include <gcj/cni.h>
17
 
18
#include <gnu/gcj/xlib/Display.h>
19
#include <gnu/gcj/xlib/XConnectException.h>
20
#include <gnu/gcj/xlib/XException.h>
21
 
22
void gnu::gcj::xlib::Display::init()
23
{
24
  ::Display* openedDisplay = XOpenDisplay(0); // default display
25
 
26
  if (openedDisplay == 0) {
27
    jstring msg = JvNewStringLatin1("Unable to open display");
28
    throw new gnu::gcj::xlib::XConnectException(msg);
29
  }
30
 
31
  display = reinterpret_cast<gnu::gcj::RawData*>(openedDisplay);
32
}
33
 
34
void gnu::gcj::xlib::Display::finalize()
35
{
36
  if (display == 0) return;
37
  ::Display* dpy = (::Display*) display;
38
  XCloseDisplay(dpy);
39
}
40
 
41
jint gnu::gcj::xlib::Display::getDefaultScreenNumber()
42
{
43
  ::Display* dpy = (::Display*) display;
44
  return DefaultScreen(dpy);
45
}
46
 
47
jint gnu::gcj::xlib::Display::getDefaultRootWindowXID()
48
{
49
  ::Display* dpy = (::Display*) display;
50
  return DefaultRootWindow(dpy);
51
}
52
 
53
jint gnu::gcj::xlib::Display::internAtom(jstring name)
54
{
55
  ::Display* dpy = (::Display*) display;
56
  int len = JvGetStringUTFLength(name);
57
  char cName[len+1];
58
  JvGetStringUTFRegion(name, 0, name->length(), cName);
59
  cName[len] = '\0';
60
  bool onlyIfExists = false;
61
  return XInternAtom(dpy, cName, onlyIfExists);
62
}
63
 
64
jstring gnu::gcj::xlib::Display::getAtomName(jint atom)
65
{
66
  ::Display* dpy = (::Display*) display;
67
  char* cName = XGetAtomName(dpy, atom);
68
  jstring name = JvNewStringLatin1(cName);
69
  XFree(cName);
70
  return name;
71
}
72
 
73
static int handleXError(Display* dpy, XErrorEvent* xee)
74
{
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;
79
 
80
  if (requestCode == X_GetImage)
81
    {
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. */
86
      return 0;
87
    }
88
 
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);
95
 
96
  if (requestCode < 128)
97
    {
98
      char number[8];
99
      snprintf(number, 8, "%d", requestCode);
100
      number[7] = '\0';
101
 
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(")"));
107
    }
108
 
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);
113
 
114
  return 0;
115
}
116
 
117
void gnu::gcj::xlib::Display::staticInit()
118
{
119
  if (XInitThreads() == 0)
120
    {
121
      char msg[] = "threads are not supported on this platform";
122
      throw new ::java::lang::RuntimeException(JvNewStringLatin1(msg));
123
    }
124
 
125
  XSetErrorHandler(&handleXError);
126
}
127
 
128
void gnu::gcj::xlib::Display::flush()
129
{
130
  ::Display* dpy = (::Display*) display;
131
  XFlush(dpy);
132
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.