summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java37
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java272
-rw-r--r--src/newt/classes/com/jogamp/newt/Screen.java13
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java22
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/ScreenMode.java5
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java25
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java36
-rw-r--r--src/newt/native/X11Window.c106
8 files changed, 484 insertions, 32 deletions
diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
index acbcc6e17..5dbc56c7d 100644
--- a/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
@@ -28,29 +28,27 @@
package com.jogamp.test.junit.newt;
-import java.lang.reflect.*;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.io.IOException;
+import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.NativeWindowFactory;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Test;
-import javax.media.nativewindow.*;
-
-import com.jogamp.newt.*;
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
import com.jogamp.newt.impl.ScreenMode;
-
-import java.io.IOException;
-
import com.jogamp.test.junit.util.UITestCase;
public class TestScreenMode01NEWT extends UITestCase {
static int width, height;
+
+ static int waitTimeShort = 1000; //1 sec
+ static int waitTimeLong = 6000; //6 sec
+
@BeforeClass
public static void initClass() {
@@ -73,9 +71,6 @@ public class TestScreenMode01NEWT extends UITestCase {
window.setVisible(true);
Assert.assertEquals(true,window.isVisible());
Assert.assertEquals(true,window.isNativeValid());
- // Assert.assertEquals(width,window.getWidth());
- // Assert.assertEquals(height,window.getHeight());
- // System.out.println("Created: "+window);
//
// Create native OpenGL resources .. XGL/WGL/CGL ..
@@ -118,7 +113,7 @@ public class TestScreenMode01NEWT extends UITestCase {
Assert.assertEquals(true, window.isFullscreen());
- Thread.sleep(1000); // 1 sec
+ Thread.sleep(waitTimeShort);
window.setFullscreen(false);
Assert.assertEquals(false, window.isFullscreen());
@@ -157,7 +152,7 @@ public class TestScreenMode01NEWT extends UITestCase {
Assert.assertEquals(modeIndex, screen.getDesktopScreenModeIndex());
Assert.assertEquals(modeRate, screen.getCurrentScreenRate());
- Thread.sleep(6000); // 6 sec
+ Thread.sleep(waitTimeLong);
screen.setScreenMode(-1, (short)-1);
Assert.assertEquals(originalScreenMode, screen.getDesktopScreenModeIndex());
@@ -200,7 +195,7 @@ public class TestScreenMode01NEWT extends UITestCase {
window.setFullscreen(true);
Assert.assertEquals(true, window.isFullscreen());
- Thread.sleep(6000); // 6 sec
+ Thread.sleep(waitTimeLong);
window.setFullscreen(false);
Assert.assertEquals(false, window.isFullscreen());
@@ -246,7 +241,7 @@ public class TestScreenMode01NEWT extends UITestCase {
window.setFullscreen(true);
Assert.assertEquals(true, window.isFullscreen());
- Thread.sleep(6000); // 6 sec
+ Thread.sleep(waitTimeLong);
screen.setScreenMode(-1, (short)-1);
Assert.assertEquals(originalScreenMode, screen.getDesktopScreenModeIndex());
@@ -257,7 +252,7 @@ public class TestScreenMode01NEWT extends UITestCase {
destroyWindow(display, screen, window);
}
-
+
public static void main(String args[]) throws IOException {
String tstname = TestScreenMode01NEWT.class.getName();
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java
new file mode 100644
index 000000000..713e1f2ef
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java
@@ -0,0 +1,272 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.test.junit.newt;
+
+
+import java.io.IOException;
+
+import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.NativeWindowFactory;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.impl.ScreenMode;
+import com.jogamp.test.junit.util.UITestCase;
+
+public class TestScreenMode02NEWT extends UITestCase {
+ static int width, height;
+
+ static int waitTimeShort = 1000; //1 sec
+ static int waitTimeLong = 4000; //4 sec
+
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(onscreen && undecorated);
+ window.setSize(width, height);
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isVisible());
+ Assert.assertEquals(true,window.isNativeValid());
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ caps = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(caps);
+ Assert.assertTrue(caps.getGreenBits()>5);
+ Assert.assertTrue(caps.getBlueBits()>5);
+ Assert.assertTrue(caps.getRedBits()>5);
+ Assert.assertEquals(caps.isOnscreen(),onscreen);
+
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testScreenRotationChange01() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+ System.out.println("Original Rotation: " + originalScreenRotation);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_90);
+ Assert.assertEquals(ScreenMode.ROTATE_90, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testScreenRotationChange02() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+ System.out.println("Original Rotation: " + originalScreenRotation);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_180);
+ Assert.assertEquals(ScreenMode.ROTATE_180, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testScreenRotationChange03() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_270);
+ Assert.assertEquals(ScreenMode.ROTATE_270, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testScreenModeChangeWithRotate01() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+
+ int modeIndex = 1;
+
+ ScreenMode screenMode = screenModes[modeIndex];
+ Assert.assertNotNull(screenMode);
+
+ short modeRate = screenMode.getRates()[0];
+ screen.setScreenMode(modeIndex, modeRate);
+
+ Assert.assertEquals(modeIndex, screen.getDesktopScreenModeIndex());
+ Assert.assertEquals(modeRate, screen.getCurrentScreenRate());
+
+ Thread.sleep(waitTimeLong);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_180);
+ Assert.assertEquals(ScreenMode.ROTATE_180, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenMode(-1, (short)-1);
+ Assert.assertEquals(originalScreenMode, screen.getDesktopScreenModeIndex());
+ Assert.assertEquals(originalScreenRate, screen.getCurrentScreenRate());
+
+ destroyWindow(display, screen, window);
+ }
+
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode02NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java
index 14de2f0da..ab4b9f0b4 100644
--- a/src/newt/classes/com/jogamp/newt/Screen.java
+++ b/src/newt/classes/com/jogamp/newt/Screen.java
@@ -30,8 +30,6 @@ package com.jogamp.newt;
import com.jogamp.newt.impl.Debug;
import com.jogamp.newt.impl.ScreenMode;
-import com.jogamp.newt.impl.ScreensModeState;
-
import javax.media.nativewindow.AbstractGraphicsScreen;
public interface Screen {
@@ -101,4 +99,15 @@ public interface Screen {
* @param rate the desired rate should be one of the available rates.
*/
void setScreenMode(int modeIndex, short rate);
+
+ /** Change the Screen Rotation to
+ * one of the rotations defined in ScreenMode
+ * @param rot rotation id, example ScreenMode.ROTATE_0
+ */
+ public void setScreenRotation(int rot);
+
+ /** Get the Current screen rotation
+ * returns -1 if not implemented natively
+ */
+ public int getCurrentScreenRotation();
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java
index 793c278a1..4535213da 100644
--- a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java
+++ b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java
@@ -122,7 +122,7 @@ public abstract class ScreenImpl implements Screen {
String screenFQN = display.getFQName()+idx;
setScreenFQN(screenFQN);
ScreenModeStatus screenModeStatus = new ScreenModeStatus(screenFQN ,
- getDesktopScreenModeIndex(), getCurrentScreenRate());
+ getDesktopScreenModeIndex(), getCurrentScreenRate(),getCurrentScreenRotation());
screenModeStatus.setScreenModes(screenModes);
screensModeState.setScreenModeController(screenModeStatus);
@@ -130,6 +130,7 @@ public abstract class ScreenImpl implements Screen {
private void resetScreenMode() {
ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN());
+
/**Revert the screen mode and rate
* to original state of creation
*/
@@ -137,6 +138,12 @@ public abstract class ScreenImpl implements Screen {
setScreenMode(sms.getOriginalScreenMode(),
sms.getOriginalScreenRate());
}
+ /**Revert Screen Rotation
+ * to original value
+ */
+ if(!sms.isOriginalRotation()) {
+ setScreenRotation(sms.getOriginalScreenRotation());
+ }
}
public synchronized final void destroy() {
@@ -219,6 +226,19 @@ public abstract class ScreenImpl implements Screen {
return -1;
}
+
+ public void setScreenRotation(int rot) {
+
+ }
+
+ public int getCurrentScreenRotation() {
+ ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN());
+ if(sms != null) {
+ return sms.getCurrentScreenRotation();
+ }
+ return -1;
+ }
+
/** get the screens mode state handler
* which contain the screen mode controller of each screen
* @return the ScreensModeState static object
diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java b/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java
index 22ed07250..74dd8ebcd 100644
--- a/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java
+++ b/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java
@@ -1,6 +1,11 @@
package com.jogamp.newt.impl;
public class ScreenMode {
+ public static final int ROTATE_0 = 0;
+ public static final int ROTATE_90 = 90;
+ public static final int ROTATE_180 = 180;
+ public static final int ROTATE_270 = 270;
+
private int index;
private int width;
private int height;
diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java b/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java
index b5b95da6a..2ea77c33e 100644
--- a/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java
+++ b/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java
@@ -6,18 +6,34 @@ public class ScreenModeStatus {
private int currentScreenMode = -1;
private short currentScreenRate = -1;
-
+ private int currentScreenRotation = -1;
+
private int originalScreenMode = -1;
private short originalScreenRate = -1;
+ private int originalScreenRotation = -1;
public ScreenModeStatus(String screenFQN, int originalScreenMode,
- short originalScreenRate) {
+ short originalScreenRate, int originalScreenRotation) {
this.screenFQN = screenFQN;
this.originalScreenMode = originalScreenMode;
this.originalScreenRate = originalScreenRate;
+ this.originalScreenRotation = originalScreenRotation;
this.currentScreenMode = originalScreenMode;
this.currentScreenRate = originalScreenRate;
+ this.currentScreenRotation = originalScreenRotation;
+ }
+
+ public void setCurrentScreenRotation(int currentScreenRotation) {
+ this.currentScreenRotation = currentScreenRotation;
+ }
+
+ public int getCurrentScreenRotation() {
+ return currentScreenRotation;
+ }
+
+ public int getOriginalScreenRotation() {
+ return originalScreenRotation;
}
public int getCurrentScreenMode() {
@@ -57,6 +73,11 @@ public class ScreenModeStatus {
return true;
return false;
}
+ public boolean isOriginalRotation(){
+ if(currentScreenRotation == originalScreenRotation)
+ return true;
+ return false;
+ }
public int getOriginalScreenMode() {
return originalScreenMode;
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
index 79ccf5a7d..f01ffdea4 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
@@ -98,7 +98,7 @@ public class X11Screen extends ScreenImpl {
}
- setScreenMode0(display.getHandle(), idx, selectedMode, selectedRate);
+ setScreenMode0(display.getHandle(), idx, selectedMode, selectedRate, getCurrentScreenRotation());
sms.setCurrentScreenMode(selectedMode);
sms.setCurrentScreenRate(selectedRate);
}
@@ -145,6 +145,35 @@ public class X11Screen extends ScreenImpl {
return screenMode;
}
+ public void setScreenRotation(int rot) {
+ if(!isRotationValid(rot)){
+ return;
+ }
+ ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN());
+ setScreenRotation0(display.getHandle(), idx, rot);
+ sms.setCurrentScreenRotation(rot);
+ }
+
+ /** Check if this rotation is valid for platform
+ * @param rot user requested rotation angle
+ * @return true if is valid
+ */
+ private boolean isRotationValid(int rot){
+ if((rot == ScreenMode.ROTATE_0) || (rot == ScreenMode.ROTATE_90) ||
+ (rot == ScreenMode.ROTATE_180) || (rot == ScreenMode.ROTATE_270)) {
+ return true;
+ }
+ return false;
+ }
+
+ public int getCurrentScreenRotation() {
+ int rotation = super.getCurrentScreenRotation();
+ if(rotation == -1){
+ rotation = getCurrentScreenRotation0(display.getHandle(), idx);
+ }
+ return rotation;
+ }
+
//----------------------------------------------------------------------
// Internals only
//
@@ -156,7 +185,10 @@ public class X11Screen extends ScreenImpl {
private native int getDesktopScreenModeIndex0(long display, int screen_index);
private native short getCurrentScreenRate0(long display, int screen_index);
- private native void setScreenMode0(long display, int screen_index, int mode_index, short freq);
+ private native int getCurrentScreenRotation0(long display, int screen_index);
+ private native void setScreenRotation0(long display, int screen_index, int rot);
+
+ private native void setScreenMode0(long display, int screen_index, int mode_index, short freq, int rot);
private native int[] getScreenMode0(long display, int screen_index, int mode_index);
private native int getNumScreenModes0(long display, int screen_index);
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index 26bce0c63..7fcbd83da 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -756,16 +756,30 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getDesktopScreenM
return (jint)original_size_id;
}
-static void X11Screen_changeScreenMode(Display* dpy, Window root, int screen_indx, XRRScreenSize *xrrs, int screenModeIndex, short freq)
+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, RR_Rotate_0, freq, CurrentTime);
+ XRRSetScreenConfigAndRate(dpy, conf, root, screenModeIndex, rot, freq, CurrentTime);
//free
XRRFreeScreenConfigInfo(conf);
@@ -777,7 +791,7 @@ static void X11Screen_changeScreenMode(Display* dpy, Window root, int screen_ind
* 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)
+ (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);
@@ -792,7 +806,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_setScreenMode0
return;
}
- X11Screen_changeScreenMode(dpy, root, (int)scrn_indx, xrrs, screenModeIndex, (short)freq);
+ X11Screen_changeScreenMode(dpy, root, (int)scrn_indx, xrrs, screenModeIndex, (short)freq, (int)rotation);
}
#define NUM_SCREEN_MODE_PROPERTIES 3
@@ -885,6 +899,90 @@ JNIEXPORT jshort JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScree
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, &current_rotation);
+ short current_rate = XRRConfigCurrentRate(conf);
+
+ XRRSetScreenConfigAndRate(dpy, conf, root, current_mode_id, rot, current_rate, CurrentTime);
+
+ //free
+ XRRFreeScreenConfigInfo(conf);
+}
+
/**
* Window
*/