Skip to content

Commit

Permalink
Add support for wayland client #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Aug 29, 2023
1 parent 2468af5 commit db34a1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/xtr/keymapper/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ private void writeScript(ApplicationInfo ai) throws IOException, InterruptedExce
linesToWrite.append("exec env ");
linesToWrite.append("LD_LIBRARY_PATH=\"").append(ai.nativeLibraryDir) //path containing lib*.so
.append("\" CLASSPATH=\"").append(ai.publicSourceDir) // Absolute path to apk in /data/app
.append("\" /system/bin/app_process /system/bin ")
.append(className).append("\n");
.append("\" /system/bin/app_process / ")
.append(className).append(" \"$@\" \n");

linesToWrite.flush();
linesToWrite.close();
Expand Down
31 changes: 24 additions & 7 deletions app/src/main/java/xtr/keymapper/server/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.util.Log;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import xtr.keymapper.IRemoteService;
import xtr.keymapper.IRemoteServiceCallback;
Expand All @@ -20,19 +21,26 @@ public class RemoteService extends Service {
private String currentDevice = "";
private InputService inputService;
private OnKeyEventListener mOnKeyEventListener;
private boolean isWaylandClient = false;

public static void main(String[] args) {
Looper.prepare();
new RemoteService();
new RemoteService(args);
Looper.loop();
}

public RemoteService() {
public RemoteService(String[] args) {
super();
Log.i("XtMapper", "starting server...");
try {
ServiceManager.addService("xtmapper", binder);
System.out.println("Waiting for overlay...");
for (String arg: args) {
if (arg.equals("--wayland-client")) {
isWaylandClient = true;
System.out.println("using wayland client");
}
}
start_getevent();
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -42,13 +50,18 @@ public RemoteService() {
private void start_getevent() {
new Thread(() -> {
try {
BufferedReader getevent = Utils.geteventStream();
final BufferedReader getevent;
if (isWaylandClient) {
getevent = new BufferedReader(new InputStreamReader(System.in));
} else {
getevent = Utils.geteventStream();
}
String line;
boolean stopEvents = false;
while ((line = getevent.readLine()) != null) {
addNewDevices(line);
if (!stopEvents) {
if (inputService != null) inputService.getKeyEventHandler().handleEvent(line);
if (addNewDevices(line)) if (!stopEvents) {
if (inputService != null)
inputService.getKeyEventHandler().handleEvent(line);
if (mOnKeyEventListener != null) mOnKeyEventListener.onKeyEvent(line);
}
}
Expand All @@ -58,18 +71,22 @@ private void start_getevent() {
}).start();
}

private void addNewDevices(String line) {
private boolean addNewDevices(String line) {
String[] input_event, data;
String evdev;
data = line.split(":"); // split a string like "/dev/input/event2: EV_REL REL_X ffffffff"
if (data.length != 2) return false;
evdev = data[0];

input_event = data[1].split("\\s+");
if (input_event.length != 3) return false;

if( !currentDevice.equals(evdev) )
if (input_event[1].equals("EV_REL")) {
System.out.println("add device: " + evdev);
currentDevice = evdev;
}
return true;
}

@Override
Expand Down

0 comments on commit db34a1b

Please sign in to comment.