Skip to content

Instantly share code, notes, and snippets.

@riccardobl riccardobl/FixAltTab.patch Secret
Created Aug 2, 2019

Embed
What would you like to do?
From 4c9aca61ee963c8352e49da176216fdd89bc5b40 Mon Sep 17 00:00:00 2001
From: Riccardo Balbo <riccardo@forkforge.net>
Date: Fri, 14 Jun 2019 23:43:21 +0200
Subject: [PATCH] Fix alt tab
---
.../com/jme3/input/lwjgl/JInputJoyInput.java | 10 +++
.../com/jme3/input/lwjgl/LwjglKeyInput.java | 11 ++++
.../com/jme3/input/lwjgl/LwjglMouseInput.java | 10 +++
.../java/com/jme3/system/NullRenderer.java | 5 ++
.../system/lwjgl/LwjglAbstractDisplay.java | 11 ++++
.../com/jme3/system/lwjgl/LwjglDisplay.java | 63 +++++++++++++++++++
6 files changed, 110 insertions(+)
diff --git a/commons/src/main/java/com/jme3/input/lwjgl/JInputJoyInput.java b/commons/src/main/java/com/jme3/input/lwjgl/JInputJoyInput.java
index d89a07a..13cc36b 100644
--- a/commons/src/main/java/com/jme3/input/lwjgl/JInputJoyInput.java
+++ b/commons/src/main/java/com/jme3/input/lwjgl/JInputJoyInput.java
@@ -117,7 +117,17 @@ public class JInputJoyInput implements JoyInput {
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();
diff --git a/commons/src/main/java/com/jme3/input/lwjgl/LwjglKeyInput.java b/commons/src/main/java/com/jme3/input/lwjgl/LwjglKeyInput.java
index e7b9f92..ca26d8a 100644
--- a/commons/src/main/java/com/jme3/input/lwjgl/LwjglKeyInput.java
+++ b/commons/src/main/java/com/jme3/input/lwjgl/LwjglKeyInput.java
@@ -72,7 +72,18 @@ public class LwjglKeyInput implements KeyInput {
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;
diff --git a/commons/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java b/commons/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java
index b53d936..2185220 100644
--- a/commons/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java
+++ b/commons/src/main/java/com/jme3/input/lwjgl/LwjglMouseInput.java
@@ -99,7 +99,17 @@ public class LwjglMouseInput implements MouseInput {
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;
diff --git a/commons/src/main/java/com/jme3/system/NullRenderer.java b/commons/src/main/java/com/jme3/system/NullRenderer.java
index 4c67c61..416ff40 100644
--- a/commons/src/main/java/com/jme3/system/NullRenderer.java
+++ b/commons/src/main/java/com/jme3/system/NullRenderer.java
@@ -279,4 +279,9 @@ public class NullRenderer implements Renderer {
public void endConditionalRendering() {
}
+
+ @Override
+ public ColorRGBA getBackgroundColor() {
+ return null;
+ }
}
diff --git a/commons/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java b/commons/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java
index f241fc3..eb62692 100644
--- a/commons/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java
+++ b/commons/src/main/java/com/jme3/system/lwjgl/LwjglAbstractDisplay.java
@@ -224,9 +224,11 @@ public abstract class LwjglAbstractDisplay extends LwjglContext implements Runna
listener.gainFocus();
timer.reset();
wasActive = true;
+ onFocusGained();
} else {
listener.loseFocus();
wasActive = false;
+ onFocusLost();
}
}
}
@@ -239,6 +241,15 @@ public abstract class LwjglAbstractDisplay extends LwjglContext implements Runna
deinitInThread();
}
+
+ protected void onFocusGained(){
+
+ }
+
+ protected void onFocusLost(){
+
+ }
+
public JoyInput getJoyInput() {
if (joyInput == null){
joyInput = new JInputJoyInput();
diff --git a/commons/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java b/commons/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java
index 459c56a..9ca0166 100644
--- a/commons/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java
+++ b/commons/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java
@@ -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.concurrent.atomic.AtomicBoolean;
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,65 @@ public class LwjglDisplay extends LwjglAbstractDisplay {
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;
+ }
+ 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();
+ }
+ }
+ }
+
}
--
2.17.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.