Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
Fixed fullscreen issue.
  • Loading branch information
Yesterday17 committed Dec 28, 2019
1 parent 90cbfe5 commit d360ce5
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ libkokoa/*.cmake
libkokoa/*.so
libkokoa/Makefile
libkokoa/*Cache*
libkokoa/*.cbp
7 changes: 3 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ It tweaks lwjgl when game starts. So it's much easier to install.

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

## Known issue
- 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**.
- 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).
- 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.
## Known issues
- 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).
- 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).

## Debug and Build
### Debug
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: "com.wynprice.cursemaven"

version = "1.1.0"
version = "1.1.1"
group = "cn.yesterday17"
archivesBaseName = "kokoalinux"

Expand Down
69 changes: 26 additions & 43 deletions libkokoa/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ void preeditDraw(XIC xic, XPointer clientData, XIMPreeditDrawCallbackStruct *str
XFree(attr);
}

void statusStart(XIC xic, XPointer clientData, XPointer data) {
printf("start\n");
fflush(stdout);
}

void statusDone(XIC xic, XPointer clientData, XPointer data) {
printf("done\n");
fflush(stdout);
}

void statusDraw(XIC xic, XPointer clientData, XPointer data, XIMStatusDrawCallbackStruct *structure) {
printf("draw\n");
fflush(stdout);
}

XICCallback calet, start, done, draw;

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

calet.client_data = NULL;
calet.callback = preeditCalet;
return XVaCreateNestedList(0,
return XVaCreateNestedList(0, // DUMMY
XNPreeditStartCallback,
&start,
XNPreeditDoneCallback,
&done,
XNPreeditDrawCallback,
&draw,
XNPreeditCaretCallback,
&calet, NULL);
}


XICCallback s_start, s_done, s_draw;

XVaNestedList statusCallbacksList() {
s_start.client_data = NULL;
s_done.client_data = NULL;
s_draw.client_data = NULL;
s_start.callback = statusStart;
s_done.callback = statusDone;
s_draw.callback = statusDraw;
return XVaCreateNestedList(0,
XNStatusStartCallback,
&s_start,
XNStatusDoneCallback,
&s_done,
XNStatusDrawCallback,
&s_draw, NULL);
&calet,
NULL); // FINAL
}

long createInactiveIC(long xim, long window) {
Expand Down Expand Up @@ -162,8 +130,6 @@ long createActiveIC(long xim, long window) {
XIMPreeditCallbacks | XIMStatusNothing,
XNPreeditAttributes,
preeditCallbacksList(),
XNStatusAttributes,
statusCallbacksList(),
NULL);
return (long) ic;
}
Expand All @@ -172,24 +138,41 @@ void setLocale() {
setlocale(LC_CTYPE, "");
}


// X11
//////////////////////// X11 ////////////////////////
/**
* Clear Locale Modifier
*/
void setEmptyLocaleModifier() {
XSetLocaleModifiers("");
}

/**
* Destroy specified XIC
* This function assumes xic is valid, and protects deleting NULL pointer.
* @param xic Long form of XIC pointer
*/
void destroyIC(long xic) {
if (xic != 0) {
XDestroyIC((XIC) xic);
}
}

/**
* Open IM for specified Display
* @param display
* @return Long form of opened XIM pointer.
*/
long openIM(long display) {
return (long) XOpenIM((Display *) display, NULL, NULL, NULL);
}

/**
* Close specified XIM
* This function assumes xim is valid, and protects deleting NULL pointer.
* @param xim Long form of XIM pointer
*/
void closeIM(long xim) {
if (xim != 0) {
XCloseIM((XIM) xim);
}
}

long openIM(long display) {
return (long) XOpenIM((Display *) display, NULL, NULL, NULL);
}
12 changes: 10 additions & 2 deletions src/main/java/cn/yesterday17/kokoalinux/Focus.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
class Focus {
private static LinuxIMEOperator focused = null;

static void focus(LinuxIMEOperator op) {
private static void focus(LinuxIMEOperator op) {
focused = op;
}

static void release() {
focused = null;
}

static void release(LinuxIMEOperator op) {
private static void release(LinuxIMEOperator op) {
if (op == focused) {
release();
}
}

static void operate(LinuxIMEOperator op, boolean isFocused) {
if (isFocused) {
focus(op);
} else {
release(op);
}
}

static boolean isFocused() {
return focused != null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/yesterday17/kokoalinux/LinuxController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class LinuxController implements Controller {

InputHelper.prepareLocale();
InputHelper.openIM();
InputHelper.createInactiveIC();
InputHelper.createIC(false);

MinecraftForge.EVENT_BUS.register(this);
}
Expand All @@ -65,7 +65,7 @@ public void didChangeGui(GuiOpenEvent event) {
if (!currentGuiIsIMEReceiver) {
KokoaLinux.logger.debug("GUI");
InputHelper.destroyIC();
InputHelper.createInactiveIC();
InputHelper.createIC(false);
Focus.release();
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/cn/yesterday17/kokoalinux/LinuxIMEOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ public void setFocused(boolean focused) {
KokoaLinux.logger.debug("FOCUS");
InputHelper.destroyIC();

if (focused) {
Focus.focus(this);
InputHelper.createActivateIC();
} else {
Focus.release(this);
InputHelper.createInactiveIC();
}
Focus.operate(this, focused);
InputHelper.createIC(focused);
}
}
44 changes: 32 additions & 12 deletions src/main/java/cn/yesterday17/kokoalinux/input/InputHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,38 @@
import org.apache.logging.log4j.Level;

public class InputHelper {
public static void createActivateIC() {
long xim = DisplayHelper.getXIM(),
public static void createIC(boolean toActivate) {
long xic,
xim = DisplayHelper.getXIM(),
window = DisplayHelper.getCurrentWindow();
long xic = InputNative.instance.createActiveIC(xim, window);
KokoaLinux.logger.printf(Level.DEBUG, "Activate XIC: %d", xic);
if (toActivate) {
xic = InputNative.instance.createActiveIC(xim, window);

if (xic == 0) {
// Current XIM is not available, so NULL is returned
// Sp close current XIM and open a new one
// Also, Locale is reset, So we MUST prepareLocale again
DisplayHelper.closeLWJGLIM();
InputHelper.prepareLocale();
xim = InputHelper.openIM();
xic = InputNative.instance.createActiveIC(xim, window);
}

KokoaLinux.logger.printf(Level.DEBUG, "Activate XIC: %d", xic);
} else {
xic = InputNative.instance.createInactiveIC(xim, window);
KokoaLinux.logger.printf(Level.DEBUG, "Inactivate XIC: %d", xic);
}
DisplayHelper.setXIC(xic);

// Unexpected situation
if (xic == 0) {
KokoaLinux.logger.printf(Level.DEBUG, "xim: %d, window: %d", xim, window);
KokoaLinux.logger.error("Unexpected zero XIC when creating IC");
KokoaLinux.logger.printf(Level.ERROR, "XIM: %d", xim);
KokoaLinux.logger.printf(Level.ERROR, "Window: %d", window);
}
}

public static void createInactiveIC() {
long xic = InputNative.instance.createInactiveIC(DisplayHelper.getXIM(), DisplayHelper.getCurrentWindow());
KokoaLinux.logger.printf(Level.DEBUG, "Inactivate XIC: %d", xic);
DisplayHelper.setXIC(xic);
}

public static void prepareLocale() {
InputNative.instance.setEmptyLocaleModifier();
InputNative.instance.setLocale();
Expand All @@ -34,8 +48,14 @@ public static void destroyIC() {
InputNative.instance.destroyIC(xic);
}

public static void openIM() {
public static long openIM() {
long xim = InputNative.instance.openIM(DisplayHelper.getDisplay());
DisplayHelper.setXIM(xim);
return xim;
}

public static void closeIM() {
InputNative.instance.closeIM(DisplayHelper.getXIM());
DisplayHelper.setXIM(0);
}
}

0 comments on commit d360ce5

Please sign in to comment.