Skip to content
This repository was archived by the owner on Jan 3, 2020. It is now read-only.

Commit f14b77b

Browse files
committed
OSX black screen fix, java8 not work
1 parent 8f01ba4 commit f14b77b

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/main/java/org/devinprogress/YAIF/InputFieldWrapper.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import cpw.mods.fml.client.FMLClientHandler;
44
import cpw.mods.fml.common.FMLCommonHandler;
5+
import net.minecraft.util.Util;
56
import org.devinprogress.YAIF.Bridges.BaseActionBridge;
67
import org.lwjgl.opengl.AWTGLCanvas;
78
import org.lwjgl.opengl.Display;
89

910
import javax.swing.*;
1011
import java.awt.*;
12+
import java.awt.event.ComponentAdapter;
13+
import java.awt.event.ComponentEvent;
1114
import java.awt.event.WindowAdapter;
1215
import java.awt.event.WindowEvent;
1316

@@ -63,6 +66,23 @@ public InputFieldWrapper(int Width,int Height){ //Should be Called only once
6366
panel.add(textField, BorderLayout.PAGE_END);
6467
panel.setVisible(true);
6568
panel.validate();
69+
if(Util.getOSType()==Util.EnumOS.OSX&&false) { //OSX blacks-screen patch
70+
panel.addComponentListener(new ComponentAdapter() {
71+
@Override
72+
public void componentResized(ComponentEvent e) {
73+
YetAnotherInputFix.log("Panel Resizing...");
74+
SwingUtilities.invokeLater(new Runnable() {
75+
@Override
76+
public void run() {
77+
panel.requestFocusInWindow();
78+
canvas.requestFocusInWindow();
79+
canvas.requestFocus();
80+
YetAnotherInputFix.needCurrent = true;
81+
}
82+
});
83+
}
84+
});
85+
}
6686

6787
// Setup frame
6888
frame.setUndecorated(false);
@@ -71,8 +91,8 @@ public InputFieldWrapper(int Width,int Height){ //Should be Called only once
7191
frame.addWindowListener(new WindowAdapter() {
7292
@Override
7393
public void windowClosing(WindowEvent e) {
74-
FMLCommonHandler.instance().exitJava(0,false);
75-
//FMLClientHandler.instance().getClient().shutdown();
94+
//FMLCommonHandler.instance().exitJava(0,false);
95+
FMLClientHandler.instance().getClient().shutdown();
7696
}
7797
});
7898
frame.pack();

src/main/java/org/devinprogress/YAIF/YetAnotherInputFix.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
public class YetAnotherInputFix{
2121
private static GuiStateManager stateMachine=null;
2222
public static boolean ObfuscatedEnv=true;
23-
public static boolean needFocus=false;
2423

2524
public static void log(String msg,Object... args){
2625
LogManager.getLogger("YAIF").info(String.format(msg,args));
@@ -73,7 +72,12 @@ public void onGuiOpen(GuiOpenEvent e){
7372

7473
//Multi-threading is a problem
7574
//TODO: UGLY PATCH!!!
76-
//TODO: use ASM to reduce potential lag
75+
//TODO: Use better ways to deal with the problems addressed below
76+
public static boolean needFocus=false;
77+
public static boolean needCurrent=false;
78+
private static int downCounter=0;
79+
private static int logCounter=0;
80+
7781
@SubscribeEvent
7882
public void tryGetFocus(TickEvent.ClientTickEvent event){
7983
if(needFocus){
@@ -82,10 +86,23 @@ public void tryGetFocus(TickEvent.ClientTickEvent event){
8286
}catch(Exception e){
8387
e.printStackTrace();
8488
}
89+
++logCounter;
8590
if(Display.isActive()){
8691
FMLClientHandler.instance().getClient().setIngameFocus();
87-
92+
log("Focus Grabbed after %s tries",logCounter);
8893
needFocus=false;
94+
logCounter=0;
95+
}
96+
}
97+
if(needCurrent){
98+
downCounter=100;
99+
needCurrent=false;
100+
}
101+
if(--downCounter>0){
102+
try{
103+
Display.makeCurrent();
104+
}catch(Exception e){
105+
e.printStackTrace();
89106
}
90107
}
91108
}

0 commit comments

Comments
 (0)