LibGDX Multiple Fullscreen Windows

506 views Asked by At

I am writing a program to display text on two monitors.

Right now my method is to launch a LibGDX window on both monitors, then control each separately. However, when both are in fullscreen, only one window can have focus. The out-of-focus window gets hidden. How do I solve this?

Specs:

  • Windows 10

  • Java 1.8

  • LibGDX 1.9.3, using LWJGL 3 backend

Code:

  • In the ApplicationListener:

    @Override
    public void show() throws RuntimeException {
       // Throws exception if it is set to go to monitor 1 and it does not exist
    
       if (external && Gdx.graphics.getMonitors().length < 2)
            throw new RuntimeException("Cannot extend to secondary monitor.");
    
        Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode(Gdx.graphics.getMonitors()[external ? 1 : 0]));
    }
    
  • Then, to open the window:

    @Override
    public void openWindow(ApplicationListener a) {
       Lwjgl3WindowConfiguration config = new Lwjgl3WindowConfiguration();
    
       config.setTitle(title);
    
       config.setWindowListener(new Lwjgl3WindowListener() {
    
           @Override
           public void iconified() {}
    
           @Override
           public void focusLost() {}
    
           @Override
           public void focusGained() {}
    
           @Override
           public void filesDropped(String[] files) {}
    
           @Override
           public void deiconified() {}
    
           @Override
           public boolean closeRequested() { 
               return true;
           }
       });
    
       Lwjgl3Application app = (Lwjgl3Application) Gdx.app;
       window = app.newWindow(a, config);
       DesktopLauncher.openWindows.add(window);  // Used to close all windows later
    }
    

Am I looking at this the wrong way? Thanks!

0

There are 0 answers