1 /* gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
45 #include <X11/extensions/Xrandr.h>
48 #include "gdkdisplay.h"
50 #include "gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.h"
52 struct state_table *cp_gtk_native_screen_state_table;
54 jclass gdkScreenGraphicsDevice_class;
56 JNIEXPORT void JNICALL
57 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_initIDs
58 (JNIEnv *env, jclass klazz __attribute__((unused)))
60 gtkpeer_init_screen_IDs(env);
63 JNIEXPORT jobject JNICALL
64 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetFixedDisplayMode
65 (JNIEnv *env, jobject obj, jobject gdkGraphicsEnv __attribute__((unused)))
67 jclass displayMode_class;
68 jmethodID displayMode_ctor;
70 jobject fixedDisplayMode = NULL;
75 display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
79 if (!XRRQueryExtension(GDK_DISPLAY_XDISPLAY(display), &temp1, &temp2))
81 displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode");
82 displayMode_ctor = (*env)->GetMethodID(env,
87 screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
89 fixedDisplayMode = (*env)->NewObject(env,
92 gdk_screen_get_width(screen),
93 gdk_screen_get_height(screen),
102 displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode");
103 displayMode_ctor = (*env)->GetMethodID(env,
108 screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
110 fixedDisplayMode = (*env)->NewObject(env,
113 gdk_screen_get_width(screen),
114 gdk_screen_get_height(screen),
119 return fixedDisplayMode;
122 JNIEXPORT jstring JNICALL
123 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetIDString
124 (JNIEnv *env, jobject obj)
130 screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
134 displayName = gdk_screen_make_display_name(screen);
138 string = (*env)->NewStringUTF(env, displayName);
145 JNIEXPORT jint JNICALL
146 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeRate
147 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
152 XRRScreenConfiguration *config;
155 display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
159 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
161 rate = (int) XRRConfigCurrentRate (config);
163 XRRFreeScreenConfigInfo (config);
169 JCL_ThrowException(env,
170 "java/lang/InternalError",
171 "Method should not have been invoked.");
177 JNIEXPORT jint JNICALL
178 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeIndex
179 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
184 XRRScreenConfiguration *config;
188 display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
192 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
194 index = XRRConfigCurrentConfiguration (config, &rotation);
196 XRRFreeScreenConfigInfo (config);
204 JCL_ThrowException(env,
205 "java/lang/InternalError",
206 "Method should not have been invoked.");
213 JNIEXPORT jobjectArray JNICALL
214 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModes
215 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
219 XRRScreenConfiguration *config;
220 XRRScreenSize *screenSizes;
221 int nsizes = 0, nrates = 0, i = 0;
222 jclass x11DisplayMode_class;
223 jmethodID x11DisplayMode_ctor;
227 jshortArray shortArray;
229 display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
233 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
235 screenSizes = XRRConfigSizes(config, &nsizes);
237 x11DisplayMode_class = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice$X11DisplayMode");
239 x11DisplayMode_ctor = (*env)->GetMethodID(env, x11DisplayMode_class, "<init>", "(II[S)V");
241 array = (*env)->NewObjectArray(env, nsizes, x11DisplayMode_class, NULL);
243 for (; i < nsizes ; i++)
245 /* Retrieves refresh rate information. */
246 rates = XRRConfigRates(config, i, &nrates);
248 /* Create a Java short array and put them in. */
249 shortArray = (*env)->NewShortArray(env, nrates);
250 (*env)->SetShortArrayRegion(env, shortArray, 0, nrates, (jshort *) rates);
252 /* Create a GdkScreenGraphicsDevice.X11DisplayMode instance. */
253 instance = (*env)->NewObject(env,
254 x11DisplayMode_class,
256 screenSizes[i].width,
257 screenSizes[i].height,
260 /* Put it into the result array. */
261 (*env)->SetObjectArrayElement(env, array, i, instance);
264 /* Free everything acquired by xlib. */
265 XRRFreeScreenConfigInfo (config);
271 JCL_ThrowException(env,
272 "java/lang/InternalError",
273 "Method should not have been invoked.");
280 JNIEXPORT void JNICALL
281 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeSetDisplayMode
282 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)), jint index __attribute__((unused)), jshort rate __attribute__((unused)))
286 XRRScreenConfiguration *config;
289 display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
293 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
295 /* The rotation is not exposed to the Java API. So we retrieve its current
296 * value and set it to the same when switching resolution.
298 XRRConfigCurrentConfiguration (config, &rotation);
300 XRRSetScreenConfigAndRate (GDK_DISPLAY_XDISPLAY(display),
308 XRRFreeScreenConfigInfo(config);
313 JCL_ThrowException(env,
314 "java/lang/InternalError",
315 "Method should not have been invoked.");
319 JNIEXPORT jobject JNICALL
320 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetBounds
321 (JNIEnv *env, jobject obj)
323 jclass rectangle_class;
324 jmethodID rectangle_ctor;
330 rectangle_class = (*env)->FindClass(env, "java/awt/Rectangle");
332 rectangle_ctor = (*env)->GetMethodID
333 (env, rectangle_class, "<init>", "(IIII)V");
335 screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
339 window = gdk_screen_get_root_window(screen);
341 gdk_window_get_geometry(window, &x, &y, &w, &h, NULL);
345 instance = (*env)->NewObject(env,