diff options
Diffstat (limited to 'src/newt/native')
-rw-r--r-- | src/newt/native/WindowsWindow.c | 258 | ||||
-rw-r--r-- | src/newt/native/X11Window.c | 258 |
2 files changed, 516 insertions, 0 deletions
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 44f90bc0e..9aac8720c 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -90,6 +90,8 @@ #define MONITOR_DEFAULTTONEAREST 2 #endif +#include "com_jogamp_newt_impl_windows_WindowsDisplay.h" +#include "com_jogamp_newt_impl_windows_WindowsScreen.h" #include "com_jogamp_newt_impl_windows_WindowsWindow.h" #include "MouseEvent.h" @@ -1145,6 +1147,220 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getHeight } /* + * Class: com_jogamp_newt_impl_windows_WindowsScreen + * Method: getCurrentScreenRate0 + * Signature: (I)S + */ +JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getCurrentScreenRate0 + (JNIEnv *env, jobject object, jint scrn_idx) +{ + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + int rate = -1; + if (0 != EnumDisplaySettings(NULL /*current display device*/, ENUM_CURRENT_SETTINGS, &dm)) + { + rate = dm.dmDisplayFrequency; + } + + return rate; +} + +/* + * Class: com_jogamp_newt_impl_windows_WindowsScreen + * Method: getScreenMode0 + * Signature: (II)[I + */ +JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getScreenMode0 + (JNIEnv *env, jobject obj, jint scrn_idx, jint mode_idx) +{ + int propIndex = 0; + int prop_size = 4; //wxhxbxf + + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + int devModeID = (int)mode_idx; + + if(devModeID == -1) + { + devModeID = ENUM_CURRENT_SETTINGS; + } + + jintArray properties = (*env)->NewIntArray(env, prop_size); + + //Fill the properties in temp jint array + jint prop[prop_size]; + if (0 == EnumDisplaySettings(NULL /*current display device*/, devModeID, &dm)) + { + return NULL; + } + prop[propIndex++] = dm.dmPelsWidth; + prop[propIndex++] = dm.dmPelsHeight; + prop[propIndex++] = dm.dmBitsPerPel; + prop[propIndex++] = dm.dmDisplayFrequency; + + (*env)->SetIntArrayRegion(env, properties, 0, prop_size, prop); + + return properties; +} + +#define SCREEN_MODE_NOERROR 0 +#define SCREEN_MODE_ERROR 1 +/* + * Class: com_jogamp_newt_impl_windows_WindowsScreen + * Method: setScreenMode0 + * Signature: (IIIIS)I + */ +JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_setScreenMode0 + (JNIEnv *env, jobject object, jint scrn_idx, jint width, jint height, jint bits, jshort rate) +{ + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + if (0 == EnumDisplaySettings(NULL /*current display device*/, ENUM_CURRENT_SETTINGS, &dm)) + { + return SCREEN_MODE_ERROR; + } + + dm.dmPelsWidth = (int)width; + dm.dmPelsHeight = (int)height; + dm.dmBitsPerPel = (int)bits; + dm.dmDisplayFrequency = (int)rate; + dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; + + long result = ChangeDisplaySettings(&dm, 0); + if(result == DISP_CHANGE_SUCCESSFUL) + { + return SCREEN_MODE_NOERROR; + } + return SCREEN_MODE_ERROR; +} + +#define SCREEN_ROT_ERROR -1 +/* + * Class: com_jogamp_newt_impl_windows_WindowsScreen + * Method: getCurrentScreenRotation0 + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getCurrentScreenRotation0 + (JNIEnv *env, jobject object, jint scrn_idx) +{ + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + if (0 == EnumDisplaySettings(NULL /*current display device*/, ENUM_CURRENT_SETTINGS, &dm)) + { + return SCREEN_ROT_ERROR; + } + + int currentRotation = -1; + switch (dm.dmDisplayOrientation) + { + case DMDO_DEFAULT: + currentRotation = 0; + break; + case DMDO_270: + currentRotation = 270; + break; + case DMDO_180: + currentRotation = 180; + break; + case DMDO_90: + currentRotation = 90; + break; + default: + break; + } + return currentRotation; +} +/* + * Class: com_jogamp_newt_impl_windows_WindowsScreen + * Method: setScreenRotation0 + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_setScreenRotation0 + (JNIEnv *env, jobject object, jint scrn_idx, jint rot) +{ + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + if (0 == EnumDisplaySettings(NULL /*current display device*/, ENUM_CURRENT_SETTINGS, &dm)) + { + return SCREEN_MODE_ERROR; + } + int requestedRotation = dm.dmDisplayOrientation; + int currentRotation = dm.dmDisplayOrientation; + + int shouldFlipDims = 0; + + int rotation = (int)rot; + switch (rotation) + { + case 0: + requestedRotation = DMDO_DEFAULT; + if (currentRotation == DMDO_90 || currentRotation == DMDO_270) + { + shouldFlipDims = 1; + } + break; + case 270: + requestedRotation = DMDO_270; + if (currentRotation == DMDO_DEFAULT || currentRotation == DMDO_180) + { + shouldFlipDims = 1; + } + break; + case 180: + requestedRotation = DMDO_180; + if (currentRotation == DMDO_90 || currentRotation == DMDO_270) + { + shouldFlipDims = 1; + } + break; + case 90: + requestedRotation = DMDO_90; + if (currentRotation == DMDO_DEFAULT || currentRotation == DMDO_180) + { + shouldFlipDims = 1; + } + break; + default: + //requested rotation not available + return SCREEN_MODE_ERROR; + break; + } + /** swap width and height if changing from vertical to horizantal + * or horizantal to vertical + */ + if (shouldFlipDims) + { + int tempWidth = dm.dmPelsWidth; + dm.dmPelsWidth = dm.dmPelsHeight; + dm.dmPelsHeight = tempWidth; + } + dm.dmDisplayOrientation = requestedRotation; + dm.dmFields = DM_DISPLAYORIENTATION | DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; + + long result = ChangeDisplaySettings(&dm, 0); + if(result == DISP_CHANGE_SUCCESSFUL) + { + return SCREEN_MODE_NOERROR; + } + return SCREEN_MODE_ERROR; +} + +/* * Class: com_jogamp_newt_impl_windows_WindowsWindow * Method: initIDs0 * Signature: ()Z @@ -1407,6 +1623,38 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setVisibl } } +#define FULLSCREEN_NOERROR 0 +#define FULLSCREEN_ERROR 1 + +static int NewtWindows_setFullScreen(jboolean fullscreen) +{ + int flags = 0; + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + if (0 == EnumDisplaySettings(NULL /*current display device*/, ENUM_CURRENT_SETTINGS, &dm)) + { + return FULLSCREEN_ERROR; + } + + if(fullscreen == JNI_TRUE) + { + flags = CDS_FULLSCREEN; //set fullscreen temporary + } + else + { + flags = CDS_RESET; // reset to registery values + } + long result = ChangeDisplaySettings(&dm, flags); + if(result == DISP_CHANGE_SUCCESSFUL) + { + return FULLSCREEN_NOERROR; + } + return FULLSCREEN_ERROR; +} + /* * Class: com_jogamp_newt_impl_windows_WindowsWindow * Method: reconfigureWindow0 @@ -1439,6 +1687,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reconfigu if(JNI_TRUE == visible) { windowStyle |= WS_VISIBLE ; } + + if(fullScreenChange < 0) + { + NewtWindows_setFullScreen(JNI_FALSE); + } // order of call sequence: (MS documentation) // TOP: SetParent(.., NULL); Clear WS_CHILD [, Set WS_POPUP] @@ -1447,6 +1700,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reconfigu if ( JNI_TRUE == parentChange && NULL == hwndP ) { SetParent(hwnd, NULL); } + + if(fullScreenChange > 0) + { + NewtWindows_setFullScreen(JNI_TRUE); + } if ( styleChange ) { if(NULL!=hwndP) { diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 0cdf6ae57..6c6aff478 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -48,6 +48,10 @@ #include <X11/keysym.h> #include <X11/Xatom.h> +#include<X11/extensions/Xrandr.h> + +#include "com_jogamp_newt_impl_x11_X11Screen.h" +#include "com_jogamp_newt_impl_x11_X11Display.h" #include "com_jogamp_newt_impl_x11_X11Window.h" #include "MouseEvent.h" @@ -476,6 +480,8 @@ static void NewtWindows_setDecorations (Display *dpy, Window w, Bool decorated) #define _NET_WM_STATE_REMOVE 0 #define _NET_WM_STATE_ADD 1 + + static void NewtWindows_setFullscreen (Display *dpy, Window root, Window w, Bool fullscreen) { Atom _NET_WM_STATE = XInternAtom( dpy, "_NET_WM_STATE", False ); Atom _NET_WM_STATE_ABOVE = XInternAtom( dpy, "_NET_WM_STATE_ABOVE", False ); @@ -506,6 +512,7 @@ static void NewtWindows_setFullscreen (Display *dpy, Window root, Window w, Bool xev.xclient.data.l[2] = _NET_WM_STATE_ABOVE; xev.xclient.data.l[3] = 1; //source indication for normal applications } + XChangeProperty( dpy, w, _NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *)&types, ntypes); XSync(dpy, False); XSendEvent (dpy, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev ); @@ -837,6 +844,256 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getHeight0 return (jint) XDisplayHeight( dpy, scrn_idx); } +/* + * Class: com_jogamp_newt_impl_x11_X11Screen + * Method: getDesktopScreenModeIndex0 + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getDesktopScreenModeIndex0 + (JNIEnv *env, jobject object, jlong display, jint scrn_indx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_indx); + + // get current resolutions and frequency configuration + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + short original_rate = XRRConfigCurrentRate(conf); + + Rotation original_rotation; + SizeID original_size_id = XRRConfigCurrentConfiguration(conf, &original_rotation); + + //free + XRRFreeScreenConfigInfo(conf); + + return (jint)original_size_id; +} + +static void X11Screen_changeScreenMode(Display* dpy, Window root, int screen_indx, XRRScreenSize *xrrs, int screenModeIndex, short freq, int rotation) +{ + int num_rates; //number of available rates for selected mode index + short *rates = XRRRates(dpy, screen_indx, screenModeIndex, &num_rates); + + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + + int rot = RR_Rotate_0; + + if(rotation == 90) + { + rot = RR_Rotate_90; + } + else if(rotation == 180) + { + rot = RR_Rotate_180; + } + else if(rotation == 270) + { + rot = RR_Rotate_270; + } + // Change the resolution + DBG_PRINT("\nCHANGED TO %i x %i PIXELS, %i Hz\n\n", xrrs[screenModeIndex].width, xrrs[screenModeIndex].height, selectedFreq); + XRRSetScreenConfigAndRate(dpy, conf, root, screenModeIndex, rot, freq, CurrentTime); + + //free + XRRFreeScreenConfigInfo(conf); +} + +/* + * Class: com_jogamp_newt_impl_x11_X11Screen + * Method: setScreenMode0 + * Signature: (JIIS)V + */ +JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_setScreenMode0 + (JNIEnv *env, jobject object, jlong display, jint scrn_indx, jint mode_indx, jshort freq, jint rotation) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_indx); + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)scrn_indx, &num_sizes); //get possible screen resolutions + int screenModeIndex = (int)mode_indx; + + if((screenModeIndex > num_sizes) || (screenModeIndex < 0)) + { + DBG_PRINT("\nSelected mode index not available for selected screen, index: %i\n", screenModeIndex); + return; + } + + X11Screen_changeScreenMode(dpy, root, (int)scrn_indx, xrrs, screenModeIndex, (short)freq, (int)rotation); +} + +#define NUM_SCREEN_MODE_PROPERTIES 3 + +/* + * Class: com_jogamp_newt_impl_x11_X11Screen + * Method: getScreenMode0 + * Signature: (JII)[I + */ +JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getScreenMode0 + (JNIEnv *env, jobject object, jlong display, jint scrn_indx, jint mode_indx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_indx); + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)scrn_indx, &num_sizes); //get possible screen resolutions + + int num_rates; + short *rates = XRRRates(dpy, (int)scrn_indx, (int)mode_indx, &num_rates); + + int prop_size = NUM_SCREEN_MODE_PROPERTIES +num_rates; + + jintArray properties = (*env)->NewIntArray(env, prop_size); + if (properties == NULL) + { + return NULL; /* out of memory error thrown */ + } + + //Fill the properties in temp jint array + int propIndex = 0; + jint prop[prop_size]; + + prop[propIndex++] = (int)mode_indx; + prop[propIndex++] = xrrs[(int)mode_indx].width; + prop[propIndex++] = xrrs[(int)mode_indx].height; + + //loop through all possible resolutions + //with the selectable display frequencies + int i= 0; + while(i < num_rates) + { + prop[propIndex++] = rates[i]; + i++; + } + + + // move from the temp structure to the java structure + (*env)->SetIntArrayRegion(env, properties, 0, prop_size, prop); + + return properties; +} + +/* + * Class: com_jogamp_newt_impl_x11_X11Screen + * Method: getNumScreenModes0 + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getNumScreenModes0 + (JNIEnv *env, jobject object, jlong display, jint scrn_indx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_indx); + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)scrn_indx, &num_sizes); //get possible screen resolutions + + return num_sizes; +} + + +/* + * Class: com_jogamp_newt_impl_x11_X11Screen + * Method: getCurrentScreenRate0 + * Signature: (JI)S + */ +JNIEXPORT jshort JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenRate0 + (JNIEnv *env, jobject object, jlong display, jint scrn_indx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_indx); + + // get current resolutions and frequencies + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + short original_rate = XRRConfigCurrentRate(conf); + + //free + XRRFreeScreenConfigInfo(conf); + + return original_rate; +} + +/* + * Class: com_jogamp_newt_impl_x11_X11Screen + * Method: getCurrentScreenRotation0 + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenRotation0 + (JNIEnv *env, jobject object, jlong display, jint scrn_indx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_indx); + + //get current resolutions and frequencies + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + + Rotation rotation; + XRRConfigCurrentConfiguration(conf, &rotation); + + //free + XRRFreeScreenConfigInfo(conf); + + int rot = -1; + + if(rotation == RR_Rotate_0) { + rot = 0; + } + else if(rotation == RR_Rotate_90) { + rot = 90; + } + else if(rotation == RR_Rotate_180) { + rot = 180; + } + else if(rotation == RR_Rotate_270) { + rot = 270; + } + + return rot; +} + +/* + * Class: com_jogamp_newt_impl_x11_X11Screen + * Method: setScreenRotation0 + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_setScreenRotation0 + (JNIEnv *env, jobject object, jlong display, jint scrn_indx, jint rotation) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_indx); + + int rot = -1; + + if(rotation == 0) + { + rot = RR_Rotate_0; + } + else if(rotation == 90) + { + rot = RR_Rotate_90; + } + else if(rotation == 180) + { + rot = RR_Rotate_180; + } + else if(rotation == 270) + { + rot = RR_Rotate_270; + } + else + { + return; + } + + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + + Rotation current_rotation; + SizeID current_mode_id = XRRConfigCurrentConfiguration(conf, ¤t_rotation); + short current_rate = XRRConfigCurrentRate(conf); + + XRRSetScreenConfigAndRate(dpy, conf, root, current_mode_id, rot, current_rate, CurrentTime); + + //free + XRRFreeScreenConfigInfo(conf); +} /** * Window @@ -1159,6 +1416,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_reconfigureWindow NewtWindows_setPosSize(dpy, w, x, y, width, height); + if(0 < fullscreenChange ) { // FS on NewtWindows_setFullscreen(dpy, root, w, True ); XSync(dpy, False); |