Skip to content

Commit d360ce5

Browse files
committed
v1.1.1
Fixed fullscreen issue.
1 parent 90cbfe5 commit d360ce5

8 files changed

Lines changed: 77 additions & 71 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ libkokoa/*.cmake
3030
libkokoa/*.so
3131
libkokoa/Makefile
3232
libkokoa/*Cache*
33+
libkokoa/*.cbp

Readme.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ It tweaks lwjgl when game starts. So it's much easier to install.
77

88
This Mod is licensed under [MMPL](LICENSE), the same as CocoaInput.
99

10-
## Known issue
11-
- Switching between **fullscreen** will make IME unavailable(It doesn't crash the game now). If you want to use IME, **don't enter fullscreen mode**.
12-
- Type shortly. Don't type a whole sentence with your IME and input to Minecraft all at once, or it will **crash your game**(Tested with Mozc).
13-
- If somewhere you input has length limit (for example, world name) and you continue typing with IME, what displays on the screen may be strange.
10+
## Known issues
11+
- Type shortly. Don't type a whole sentence with your IME and input to Minecraft all at once, or it will **crash your game**(Tested with Mozc, maybe a CocoaInput bug).
12+
- If somewhere you input has length limit (for example, world name) and you continue typing with IME, what displays on the screen may be strange (seems caused by the implementation of CocoaInput to show underscore).
1413

1514
## Debug and Build
1615
### Debug

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515
apply plugin: 'net.minecraftforge.gradle.forge'
1616
apply plugin: "com.wynprice.cursemaven"
1717

18-
version = "1.1.0"
18+
version = "1.1.1"
1919
group = "cn.yesterday17"
2020
archivesBaseName = "kokoalinux"
2121

libkokoa/library.c

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,6 @@ void preeditDraw(XIC xic, XPointer clientData, XIMPreeditDrawCallbackStruct *str
7878
XFree(attr);
7979
}
8080

81-
void statusStart(XIC xic, XPointer clientData, XPointer data) {
82-
printf("start\n");
83-
fflush(stdout);
84-
}
85-
86-
void statusDone(XIC xic, XPointer clientData, XPointer data) {
87-
printf("done\n");
88-
fflush(stdout);
89-
}
90-
91-
void statusDraw(XIC xic, XPointer clientData, XPointer data, XIMStatusDrawCallbackStruct *structure) {
92-
printf("draw\n");
93-
fflush(stdout);
94-
}
9581

9682
XICCallback calet, start, done, draw;
9783

@@ -107,34 +93,16 @@ XVaNestedList preeditCallbacksList() {
10793

10894
calet.client_data = NULL;
10995
calet.callback = preeditCalet;
110-
return XVaCreateNestedList(0,
96+
return XVaCreateNestedList(0, // DUMMY
11197
XNPreeditStartCallback,
11298
&start,
11399
XNPreeditDoneCallback,
114100
&done,
115101
XNPreeditDrawCallback,
116102
&draw,
117103
XNPreeditCaretCallback,
118-
&calet, NULL);
119-
}
120-
121-
122-
XICCallback s_start, s_done, s_draw;
123-
124-
XVaNestedList statusCallbacksList() {
125-
s_start.client_data = NULL;
126-
s_done.client_data = NULL;
127-
s_draw.client_data = NULL;
128-
s_start.callback = statusStart;
129-
s_done.callback = statusDone;
130-
s_draw.callback = statusDraw;
131-
return XVaCreateNestedList(0,
132-
XNStatusStartCallback,
133-
&s_start,
134-
XNStatusDoneCallback,
135-
&s_done,
136-
XNStatusDrawCallback,
137-
&s_draw, NULL);
104+
&calet,
105+
NULL); // FINAL
138106
}
139107

140108
long createInactiveIC(long xim, long window) {
@@ -162,8 +130,6 @@ long createActiveIC(long xim, long window) {
162130
XIMPreeditCallbacks | XIMStatusNothing,
163131
XNPreeditAttributes,
164132
preeditCallbacksList(),
165-
XNStatusAttributes,
166-
statusCallbacksList(),
167133
NULL);
168134
return (long) ic;
169135
}
@@ -172,24 +138,41 @@ void setLocale() {
172138
setlocale(LC_CTYPE, "");
173139
}
174140

175-
176-
// X11
141+
//////////////////////// X11 ////////////////////////
142+
/**
143+
* Clear Locale Modifier
144+
*/
177145
void setEmptyLocaleModifier() {
178146
XSetLocaleModifiers("");
179147
}
180148

149+
/**
150+
* Destroy specified XIC
151+
* This function assumes xic is valid, and protects deleting NULL pointer.
152+
* @param xic Long form of XIC pointer
153+
*/
181154
void destroyIC(long xic) {
182155
if (xic != 0) {
183156
XDestroyIC((XIC) xic);
184157
}
185158
}
186159

160+
/**
161+
* Open IM for specified Display
162+
* @param display
163+
* @return Long form of opened XIM pointer.
164+
*/
165+
long openIM(long display) {
166+
return (long) XOpenIM((Display *) display, NULL, NULL, NULL);
167+
}
168+
169+
/**
170+
* Close specified XIM
171+
* This function assumes xim is valid, and protects deleting NULL pointer.
172+
* @param xim Long form of XIM pointer
173+
*/
187174
void closeIM(long xim) {
188175
if (xim != 0) {
189176
XCloseIM((XIM) xim);
190177
}
191178
}
192-
193-
long openIM(long display) {
194-
return (long) XOpenIM((Display *) display, NULL, NULL, NULL);
195-
}

src/main/java/cn/yesterday17/kokoalinux/Focus.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@
33
class Focus {
44
private static LinuxIMEOperator focused = null;
55

6-
static void focus(LinuxIMEOperator op) {
6+
private static void focus(LinuxIMEOperator op) {
77
focused = op;
88
}
99

1010
static void release() {
1111
focused = null;
1212
}
1313

14-
static void release(LinuxIMEOperator op) {
14+
private static void release(LinuxIMEOperator op) {
1515
if (op == focused) {
1616
release();
1717
}
1818
}
1919

20+
static void operate(LinuxIMEOperator op, boolean isFocused) {
21+
if (isFocused) {
22+
focus(op);
23+
} else {
24+
release(op);
25+
}
26+
}
27+
2028
static boolean isFocused() {
2129
return focused != null;
2230
}

src/main/java/cn/yesterday17/kokoalinux/LinuxController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class LinuxController implements Controller {
5050

5151
InputHelper.prepareLocale();
5252
InputHelper.openIM();
53-
InputHelper.createInactiveIC();
53+
InputHelper.createIC(false);
5454

5555
MinecraftForge.EVENT_BUS.register(this);
5656
}
@@ -65,7 +65,7 @@ public void didChangeGui(GuiOpenEvent event) {
6565
if (!currentGuiIsIMEReceiver) {
6666
KokoaLinux.logger.debug("GUI");
6767
InputHelper.destroyIC();
68-
InputHelper.createInactiveIC();
68+
InputHelper.createIC(false);
6969
Focus.release();
7070
}
7171
}

src/main/java/cn/yesterday17/kokoalinux/LinuxIMEOperator.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ public void setFocused(boolean focused) {
2121
KokoaLinux.logger.debug("FOCUS");
2222
InputHelper.destroyIC();
2323

24-
if (focused) {
25-
Focus.focus(this);
26-
InputHelper.createActivateIC();
27-
} else {
28-
Focus.release(this);
29-
InputHelper.createInactiveIC();
30-
}
24+
Focus.operate(this, focused);
25+
InputHelper.createIC(focused);
3126
}
3227
}

src/main/java/cn/yesterday17/kokoalinux/input/InputHelper.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,38 @@
55
import org.apache.logging.log4j.Level;
66

77
public class InputHelper {
8-
public static void createActivateIC() {
9-
long xim = DisplayHelper.getXIM(),
8+
public static void createIC(boolean toActivate) {
9+
long xic,
10+
xim = DisplayHelper.getXIM(),
1011
window = DisplayHelper.getCurrentWindow();
11-
long xic = InputNative.instance.createActiveIC(xim, window);
12-
KokoaLinux.logger.printf(Level.DEBUG, "Activate XIC: %d", xic);
12+
if (toActivate) {
13+
xic = InputNative.instance.createActiveIC(xim, window);
14+
15+
if (xic == 0) {
16+
// Current XIM is not available, so NULL is returned
17+
// Sp close current XIM and open a new one
18+
// Also, Locale is reset, So we MUST prepareLocale again
19+
DisplayHelper.closeLWJGLIM();
20+
InputHelper.prepareLocale();
21+
xim = InputHelper.openIM();
22+
xic = InputNative.instance.createActiveIC(xim, window);
23+
}
24+
25+
KokoaLinux.logger.printf(Level.DEBUG, "Activate XIC: %d", xic);
26+
} else {
27+
xic = InputNative.instance.createInactiveIC(xim, window);
28+
KokoaLinux.logger.printf(Level.DEBUG, "Inactivate XIC: %d", xic);
29+
}
1330
DisplayHelper.setXIC(xic);
1431

32+
// Unexpected situation
1533
if (xic == 0) {
16-
KokoaLinux.logger.printf(Level.DEBUG, "xim: %d, window: %d", xim, window);
34+
KokoaLinux.logger.error("Unexpected zero XIC when creating IC");
35+
KokoaLinux.logger.printf(Level.ERROR, "XIM: %d", xim);
36+
KokoaLinux.logger.printf(Level.ERROR, "Window: %d", window);
1737
}
1838
}
1939

20-
public static void createInactiveIC() {
21-
long xic = InputNative.instance.createInactiveIC(DisplayHelper.getXIM(), DisplayHelper.getCurrentWindow());
22-
KokoaLinux.logger.printf(Level.DEBUG, "Inactivate XIC: %d", xic);
23-
DisplayHelper.setXIC(xic);
24-
}
25-
2640
public static void prepareLocale() {
2741
InputNative.instance.setEmptyLocaleModifier();
2842
InputNative.instance.setLocale();
@@ -34,8 +48,14 @@ public static void destroyIC() {
3448
InputNative.instance.destroyIC(xic);
3549
}
3650

37-
public static void openIM() {
51+
public static long openIM() {
3852
long xim = InputNative.instance.openIM(DisplayHelper.getDisplay());
3953
DisplayHelper.setXIM(xim);
54+
return xim;
55+
}
56+
57+
public static void closeIM() {
58+
InputNative.instance.closeIM(DisplayHelper.getXIM());
59+
DisplayHelper.setXIM(0);
4060
}
4161
}

0 commit comments

Comments
 (0)