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_initStaticState
58 (JNIEnv *env, jclass klazz)
60 gdkScreenGraphicsDevice_class = (*env)->NewGlobalRef
63 NSA_SCREEN_INIT(env, gdkScreenGraphicsDevice_class);
66 JNIEXPORT jobject JNICALL
67 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetFixedDisplayMode
68 (JNIEnv *env, jobject obj, jobject gdkGraphicsEnv __attribute__((unused)))
70 jclass displayMode_class;
71 jmethodID displayMode_ctor;
73 jobject fixedDisplayMode = NULL;
78 display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
82 if (!XRRQueryExtension(GDK_DISPLAY_XDISPLAY(display), &temp1, &temp2))
84 displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode");
85 displayMode_ctor = (*env)->GetMethodID(env,
90 screen = (GdkScreen *) NSA_GET_SCREEN_PTR(env, obj);
92 fixedDisplayMode = (*env)->NewObject(env,
95 gdk_screen_get_width(screen),
96 gdk_screen_get_height(screen),
105 displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode");
106 displayMode_ctor = (*env)->GetMethodID(env,
111 screen = (GdkScreen *) NSA_GET_SCREEN_PTR(env, obj);
113 fixedDisplayMode = (*env)->NewObject(env,
116 gdk_screen_get_width(screen),
117 gdk_screen_get_height(screen),
122 return fixedDisplayMode;
125 JNIEXPORT jstring JNICALL
126 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetIDString
127 (JNIEnv *env, jobject obj)
133 screen = (GdkScreen *) NSA_GET_SCREEN_PTR(env, obj);
137 displayName = gdk_screen_make_display_name(screen);
141 string = (*env)->NewStringUTF(env, displayName);
148 JNIEXPORT jint JNICALL
149 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeRate
150 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
155 XRRScreenConfiguration *config;
158 display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
162 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
164 rate = (int) XRRConfigCurrentRate (config);
166 XRRFreeScreenConfigInfo (config);
172 JCL_ThrowException(env,
173 "java/lang/InternalError",
174 "Method should not have been invoked.");
180 JNIEXPORT jint JNICALL
181 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeIndex
182 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
187 XRRScreenConfiguration *config;
191 display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
195 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
197 index = XRRConfigCurrentConfiguration (config, &rotation);
199 XRRFreeScreenConfigInfo (config);
207 JCL_ThrowException(env,
208 "java/lang/InternalError",
209 "Method should not have been invoked.");
216 JNIEXPORT jobjectArray JNICALL
217 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModes
218 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
222 XRRScreenConfiguration *config;
223 XRRScreenSize *screenSizes;
224 int nsizes = 0, nrates = 0, i = 0;
225 jclass x11DisplayMode_class;
226 jmethodID x11DisplayMode_ctor;
230 jshortArray shortArray;
232 display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
236 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
238 screenSizes = XRRConfigSizes(config, &nsizes);
240 x11DisplayMode_class = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice$X11DisplayMode");
242 x11DisplayMode_ctor = (*env)->GetMethodID(env, x11DisplayMode_class, "<init>", "(II[S)V");
244 array = (*env)->NewObjectArray(env, nsizes, x11DisplayMode_class, NULL);
246 for (; i < nsizes ; i++)
248 /* Retrieves refresh rate information. */
249 rates = XRRConfigRates(config, i, &nrates);
251 /* Create a Java int array and put them in. */
252 shortArray = (*env)->NewIntArray(env, nrates);
253 (*env)->SetShortArrayRegion(env, shortArray, 0, nrates, (jshort *) rates);
255 /* Create a GdkScreenGraphicsDevice.X11DisplayMode instance. */
256 instance = (*env)->NewObject(env,
257 x11DisplayMode_class,
259 screenSizes[i].width,
260 screenSizes[i].height,
263 /* Put it into the result array. */
264 (*env)->SetObjectArrayElement(env, array, i, instance);
267 /* Free everything acquired by xlib. */
268 XRRFreeScreenConfigInfo (config);
274 JCL_ThrowException(env,
275 "java/lang/InternalError",
276 "Method should not have been invoked.");
283 JNIEXPORT void JNICALL
284 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeSetDisplayMode
285 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)), jint index __attribute__((unused)), jshort rate __attribute__((unused)))
289 XRRScreenConfiguration *config;
292 display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv);
296 config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
298 /* The rotation is not exposed to the Java API. So we retrieve its current
299 * value and set it to the same when switching resolution.
301 XRRConfigCurrentConfiguration (config, &rotation);
303 XRRSetScreenConfigAndRate (GDK_DISPLAY_XDISPLAY(display),
311 XRRFreeScreenConfigInfo(config);
316 JCL_ThrowException(env,
317 "java/lang/InternalError",
318 "Method should not have been invoked.");
322 JNIEXPORT jobject JNICALL
323 Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetBounds
324 (JNIEnv *env, jobject obj)
326 jclass rectangle_class;
327 jmethodID rectangle_ctor;
333 rectangle_class = (*env)->FindClass(env, "java/awt/Rectangle");
335 rectangle_ctor = (*env)->GetMethodID
336 (env, rectangle_class, "<init>", "(IIII)V");
338 screen = (GdkScreen *) NSA_GET_SCREEN_PTR(env, obj);
342 window = gdk_screen_get_root_window(screen);
344 gdk_window_get_geometry(window, &x, &y, &w, &h, NULL);
348 instance = (*env)->NewObject(env,