v2.5.0: added better multi-monitor fullscreen support

This commit is contained in:
Evan Debenham
2024-08-18 15:06:25 -04:00
parent ac31ef1faa
commit 41422a9147
2 changed files with 34 additions and 2 deletions

View File

@@ -433,6 +433,7 @@ public class SPDSettings extends GameSettings {
public static final String KEY_WINDOW_WIDTH = "window_width"; public static final String KEY_WINDOW_WIDTH = "window_width";
public static final String KEY_WINDOW_HEIGHT = "window_height"; public static final String KEY_WINDOW_HEIGHT = "window_height";
public static final String KEY_WINDOW_MAXIMIZED = "window_maximized"; public static final String KEY_WINDOW_MAXIMIZED = "window_maximized";
public static final String KEY_FULLSCREEN_MONITOR = "fullscreen_monitor";
public static void windowResolution( Point p ){ public static void windowResolution( Point p ){
put(KEY_WINDOW_WIDTH, p.x); put(KEY_WINDOW_WIDTH, p.x);
@@ -453,4 +454,12 @@ public class SPDSettings extends GameSettings {
public static boolean windowMaximized(){ public static boolean windowMaximized(){
return getBoolean( KEY_WINDOW_MAXIMIZED, false ); return getBoolean( KEY_WINDOW_MAXIMIZED, false );
} }
public static void fulLScreenMonitor( int value ){
put( KEY_FULLSCREEN_MONITOR, value);
}
public static int fulLScreenMonitor(){
return getInt( KEY_FULLSCREEN_MONITOR, 0 );
}
} }

View File

@@ -22,6 +22,8 @@
package com.shatteredpixel.shatteredpixeldungeon.desktop; package com.shatteredpixel.shatteredpixeldungeon.desktop;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.PixmapPacker; import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
@@ -55,17 +57,38 @@ public class DesktopPlatformSupport extends PlatformSupport {
} }
} }
private static boolean first = false;
@Override @Override
public void updateSystemUI() { public void updateSystemUI() {
Gdx.app.postRunnable( new Runnable() { Gdx.app.postRunnable( new Runnable() {
@Override @Override
public void run () { public void run () {
if (SPDSettings.fullscreen()){ if (SPDSettings.fullscreen()){
Gdx.graphics.setFullscreenMode( Gdx.graphics.getDisplayMode() ); int monitorNum = 0;
if (!first){
Graphics.Monitor[] monitors = Gdx.graphics.getMonitors();
for (int i = 0; i < monitors.length; i++){
if (((Lwjgl3Graphics.Lwjgl3Monitor)Gdx.graphics.getMonitor()).getMonitorHandle()
== ((Lwjgl3Graphics.Lwjgl3Monitor)monitors[i]).getMonitorHandle()) {
monitorNum = i;
}
}
} else {
monitorNum = SPDSettings.fulLScreenMonitor();
}
Graphics.Monitor[] monitors = Gdx.graphics.getMonitors();
if (monitors.length <= monitorNum) {
monitorNum = 0;
}
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode(monitors[monitorNum]));
SPDSettings.fulLScreenMonitor(monitorNum);
} else { } else {
Point p = SPDSettings.windowResolution(); Point p = SPDSettings.windowResolution();
Gdx.graphics.setWindowedMode( p.x, p.y ); Gdx.graphics.setWindowedMode( p.x, p.y );
} }
first = false;
} }
} ); } );
} }