Last active
June 14, 2019 19:41
-
-
Save riccardobl/c75b1d017370559ccd088b06eb1ad23b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- <unnamed> | |
+++ <unnamed> | |
@@ -117,7 +117,17 @@ | |
inited = true; | |
} | |
+ private boolean enabled=true; | |
+ public void setEnabled(boolean v){ | |
+ enabled=v; | |
+ } | |
+ | |
+ public boolean isEnabled(){ | |
+ return enabled; | |
+ } | |
+ | |
public void update() { | |
+ if(!enabled) return; | |
ControllerEnvironment ce = | |
ControllerEnvironment.getDefaultEnvironment(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- <unnamed> | |
+++ <unnamed> | |
@@ -224,9 +224,11 @@ | |
listener.gainFocus(); | |
timer.reset(); | |
wasActive = true; | |
+ onFocusGained(); | |
} else { | |
listener.loseFocus(); | |
wasActive = false; | |
+ onFocusLost(); | |
} | |
} | |
} | |
@@ -237,6 +239,15 @@ | |
break; | |
} | |
deinitInThread(); | |
+ } | |
+ | |
+ | |
+ protected void onFocusGained(){ | |
+ | |
+ } | |
+ | |
+ protected void onFocusLost(){ | |
+ | |
} | |
public JoyInput getJoyInput() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- <unnamed> | |
+++ <unnamed> | |
@@ -32,6 +32,7 @@ | |
package com.jme3.system.lwjgl; | |
+import com.jme3.EngineHacks; | |
import com.jme3.system.AppSettings; | |
import com.jme3.system.JmeContext.Type; | |
import java.awt.Graphics2D; | |
@@ -41,6 +42,7 @@ | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import org.lwjgl.LWJGLException; | |
+import org.lwjgl.input.Mouse; | |
import org.lwjgl.opengl.*; | |
public class LwjglDisplay extends LwjglAbstractDisplay { | |
@@ -261,4 +263,68 @@ | |
return ByteBuffer.wrap(imageBuffer); | |
} | |
+ private boolean skipNextGrab=false; | |
+ private boolean skipNextLoss=false; | |
+ private boolean wasMouseGrabbed; | |
+ | |
+ protected void onFocusGained() { | |
+ if(!EngineHacks.windowedOnAltTab)return; | |
+ if(settings.isFullscreen() && Display.isVisible() ){ | |
+ | |
+ if(skipNextGrab){ | |
+ skipNextGrab=false; | |
+ return; | |
+ } | |
+ | |
+ System.out.println("Focus gained"); | |
+ try{ | |
+ if(!Display.isFullscreen()){ | |
+ Display.setFullscreen(true); | |
+ skipNextLoss=true; | |
+ } | |
+ if(keyInput != null) keyInput.setEnabled(true); | |
+ if(joyInput != null) joyInput.setEnabled(true); | |
+ if(mouseInput != null){ | |
+ mouseInput.setEnabled(true); | |
+ Mouse.setGrabbed(wasMouseGrabbed); | |
+ Mouse.setClipMouseCoordinatesToWindow(true); | |
+ Mouse.setGrabbed(true); | |
+ } | |
+ | |
+ Display.update(); | |
+ | |
+ }catch(LWJGLException e){ | |
+ e.printStackTrace(); | |
+ } | |
+ } | |
+ } | |
+ | |
+ | |
+ protected void onFocusLost() { | |
+ if(!EngineHacks.windowedOnAltTab)return; | |
+ | |
+ if(settings.isFullscreen()){ | |
+ if(skipNextLoss){ | |
+ skipNextLoss=false; | |
+ return; | |
+ } | |
+ try{ | |
+ if(Display.isFullscreen()){ | |
+ Display.setFullscreen(false); | |
+ skipNextGrab=true; | |
+ } | |
+ if(keyInput!=null) keyInput.setEnabled(false); | |
+ if(joyInput!=null) joyInput.setEnabled(false); | |
+ if(mouseInput!=null){ | |
+ mouseInput.setEnabled(false); | |
+ wasMouseGrabbed=Mouse.isGrabbed(); | |
+ Mouse.setGrabbed(false); | |
+ Mouse.setClipMouseCoordinatesToWindow(false); | |
+ } | |
+ }catch(LWJGLException e){ | |
+ e.printStackTrace(); | |
+ } | |
+ } | |
+ } | |
+ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- <unnamed> | |
+++ <unnamed> | |
@@ -72,7 +72,18 @@ | |
return Keyboard.KEYBOARD_SIZE; | |
} | |
+ private boolean enabled=true; | |
+ public void setEnabled(boolean v){ | |
+ enabled=v; | |
+ } | |
+ | |
+ public boolean isEnabled(){ | |
+ return enabled; | |
+ } | |
+ | |
public void update() { | |
+ if(!enabled) return; | |
+ | |
if (!context.isRenderable()) | |
return; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- <unnamed> | |
+++ <unnamed> | |
@@ -99,7 +99,17 @@ | |
return Mouse.getButtonCount(); | |
} | |
+ private boolean enabled=true; | |
+ public void setEnabled(boolean v){ | |
+ enabled=v; | |
+ } | |
+ | |
+ public boolean isEnabled(){ | |
+ return enabled; | |
+ } | |
+ | |
public void update() { | |
+ if(!enabled) return; | |
if (!context.isRenderable()) | |
return; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment