Skip to content

Commit c0412f2

Browse files
committed
fix wrong case shift of typed characters for Linux customers
fixes ##28 (cherry picked from commit 3a23f54)
1 parent 3a7f080 commit c0412f2

2 files changed

Lines changed: 46 additions & 67 deletions

File tree

Core/src/main/java/de/openindex/support/core/AppUtils.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,6 @@ public static void initTruststore(File defaultTruststore, String defaultPassword
261261
System.getProperty(TRUSTSTORE_PASSWORD), defaultPassword));
262262
}
263263

264-
public static boolean isAsciiCharacter(char character) {
265-
return character == ' ' || // is space
266-
(character >= 48 && character <= 57) || // is number
267-
(character >= 65 && character <= 90) || // is upper case letter
268-
(character >= 97 && character <= 122); // is lower case letter
269-
}
270-
271264
public static URL resource(String file) {
272265
return AppUtils.class.getResource("resources/" + file);
273266
}

Customer/src/main/java/de/openindex/support/customer/utils/LinuxUtils.java

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.sun.jna.NativeLong;
2020
import com.sun.jna.platform.unix.X11;
2121
import com.sun.jna.ptr.IntByReference;
22-
import de.openindex.support.core.AppUtils;
2322
import org.apache.commons.lang3.StringUtils;
2423
import org.slf4j.Logger;
2524
import org.slf4j.LoggerFactory;
@@ -138,72 +137,59 @@ private static void sendTextViaX11(String text) throws LinuxException {
138137
X11.XFlush(display);
139138

140139
for (int i = 0; i < text.length(); i++) {
141-
char c = text.charAt(i);
142-
//LOGGER.debug("printing " + c);
143-
144-
145-
//int value = StandardCharsets.UTF_8.encode(String.valueOf(c)).getInt();
146-
//LOGGER.debug("> value " + value);
147-
String unicode = String.format("U%04x", (int) c);
148-
//LOGGER.debug("> code " + unicode);
149-
150-
//X11.KeySym sym = X11.XStringToKeysym(String.valueOf(c));
151-
X11.KeySym sym = X11.XStringToKeysym(unicode);
152-
153-
//int code = (sym != null) ? X11.XKeysymToKeycode(display, sym) : 0x00D1;
154-
int code = X11.XKeysymToKeycode(display, sym);
155-
156-
X11.KeySym[] resetKeySym = null;
157-
if (!AppUtils.isAsciiCharacter(c)) {
158-
//LOGGER.debug("> use scratch");
159-
//LOGGER.debug("> " + X11.XKeysymToString(sym));
160-
161-
resetKeySym = new X11.KeySym[keysymsPerKeycode.getValue()];
162-
for (int j = 0; j < resetKeySym.length; j++) {
163-
resetKeySym[j] = X11.XKeycodeToKeysym(display, (byte) scratch_keycode, j);
164-
}
165-
166-
X11.XChangeKeyboardMapping(
167-
display,
168-
scratch_keycode,
169-
2,
170-
new X11.KeySym[]{sym, sym},
171-
1);
172-
code = scratch_keycode;
173-
}
174-
175-
//LOGGER.debug("> " + code);
176-
177-
if (code > 0) {
178-
//XTEST.XTestFakeKeyEvent(display, code, false, new NativeLong(0));
179-
//X11.XFlush(display);
140+
final char character = text.charAt(i);
141+
//LOGGER.debug("printing {}", character);
180142

181-
XTEST.XTestFakeKeyEvent(display, code, true, new NativeLong(0));
182-
//X11.XFlush(display);
183-
X11.XSync(display, false);
143+
// get unicode formatted string
144+
final String unicode = String.format("U%04x", (int) character);
145+
//LOGGER.debug("> code {}", unicode);
184146

185-
XTEST.XTestFakeKeyEvent(display, code, false, new NativeLong(0));
186-
//X11.XFlush(display);
187-
X11.XSync(display, false);
147+
// get keysym for the unicode string
148+
final X11.KeySym sym = X11.XStringToKeysym(unicode);
188149

189-
//noinspection CatchMayIgnoreException
190-
try {
191-
Thread.sleep(100);
192-
} catch (Exception ex) {
193-
}
150+
// remember the old value before the keysym is overwritten
151+
final X11.KeySym[] resetKeySym = new X11.KeySym[keysymsPerKeycode.getValue()];
152+
for (int j = 0; j < resetKeySym.length; j++) {
153+
resetKeySym[j] = X11.XKeycodeToKeysym(display, (byte) scratch_keycode, j);
194154
}
195155

196-
if (resetKeySym != null) {
197-
X11.XChangeKeyboardMapping(
198-
display,
199-
scratch_keycode,
200-
resetKeySym.length,
201-
resetKeySym,
202-
1);
203-
}
156+
// register keysym for the unicode string
157+
X11.XChangeKeyboardMapping(
158+
display,
159+
scratch_keycode,
160+
2,
161+
new X11.KeySym[]{sym, sym},
162+
1);
163+
164+
//XTEST.XTestFakeKeyEvent(display, code, false, new NativeLong(0));
165+
//X11.XFlush(display);
166+
167+
// post event for key press
168+
XTEST.XTestFakeKeyEvent(display, scratch_keycode, true, new NativeLong(0));
169+
//X11.XFlush(display);
170+
X11.XSync(display, false);
171+
172+
// post event for key release
173+
XTEST.XTestFakeKeyEvent(display, scratch_keycode, false, new NativeLong(0));
174+
//X11.XFlush(display);
175+
X11.XSync(display, false);
176+
177+
//noinspection CatchMayIgnoreException
178+
//try {
179+
// Thread.sleep(50);
180+
//} catch (Exception ex) {
181+
//}
182+
183+
// reset the keysym to the old value before it was overwritten
184+
X11.XChangeKeyboardMapping(
185+
display,
186+
scratch_keycode,
187+
resetKeySym.length,
188+
resetKeySym,
189+
1);
204190
}
205191

206-
//X11.XFlush(display);
192+
X11.XFlush(display);
207193
//X11.XSync(display, false);
208194
X11.XCloseDisplay(display);
209195
}

0 commit comments

Comments
 (0)