Skip to content

Commit

Permalink
receive mouse events from wayland client #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Aug 30, 2023
1 parent 903d9e4 commit f26f83e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
23 changes: 23 additions & 0 deletions app/src/main/java/xtr/keymapper/server/InputService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xtr.keymapper.server;

import static xtr.keymapper.InputEventCodes.*;

import android.os.RemoteException;
import android.view.MotionEvent;

Expand Down Expand Up @@ -115,6 +117,27 @@ public void stop() {

public native void setMouseLock(boolean lock);

public void sendWaylandMouseEvent(String line) {
String[] input_event = line.split("\\s+");
int value = Integer.parseInt(input_event[3]);
switch (input_event[2]) {
case "ABS_X":
mouseEventHandler.evAbsX(value);
break;
case "ABS_Y":
mouseEventHandler.evAbsY(value);
break;
case "REL_WHEEL":
mouseEventHandler.handleEvent(REL_WHEEL, value);
break;
case "BTN_LEFT":
mouseEventHandler.handleEvent(BTN_MOUSE, value);
break;
case "BTN_RIGHT":
mouseEventHandler.handleEvent(BTN_RIGHT, value);
break;
}
}
/*
* Called from native code to send mouse event to client
*/
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/java/xtr/keymapper/server/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ private void start_getevent() {
String line;
boolean stopEvents = false;
while ((line = getevent.readLine()) != null) {
if (addNewDevices(line)) if (!stopEvents) {
if (inputService != null)
inputService.getKeyEventHandler().handleEvent(line);
String[] data = line.split(":"); // split a string like "/dev/input/event2: EV_REL REL_X ffffffff"
if (addNewDevices(data)) if (!stopEvents) {
if (inputService != null) {
inputService.getKeyEventHandler().handleEvent(data[1]);
if (isWaylandClient && data[0].contains("wl_pointer"))
inputService.sendWaylandMouseEvent(data[1]);
}
if (mOnKeyEventListener != null) mOnKeyEventListener.onKeyEvent(line);
}
}
Expand All @@ -71,12 +75,10 @@ private void start_getevent() {
}).start();
}

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"
private boolean addNewDevices(String[] data) {
String[] input_event;
if (data.length != 2) return false;
evdev = data[0];
String evdev = data[0];

input_event = data[1].split("\\s+");
if (isWaylandClient) return true;
Expand All @@ -101,8 +103,10 @@ public boolean isRoot() {
@Override
public void startServer(KeymapProfile profile, KeymapConfig keymapConfig, IRemoteServiceCallback cb, int screenWidth, int screenHeight) {
inputService = new InputService(profile, keymapConfig, cb, screenWidth, screenHeight);
inputService.setMouseLock(true);
inputService.openDevice(currentDevice);
if (!isWaylandClient) {
inputService.setMouseLock(true);
inputService.openDevice(currentDevice);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ public static class KeyEvent {
}

public void handleEvent(String line) throws RemoteException {
// line: /dev/input/event3: EV_KEY KEY_X DOWN
// line: EV_KEY KEY_X DOWN
String[] input_event = line.split("\\s+");
if (!input_event[1].equals("EV_KEY")) return;
if (!input_event[0].equals("EV_KEY")) return;

KeyEvent event = new KeyEvent();
event.code = input_event[2];
event.code = input_event[1];
if (!event.code.contains("KEY_")) return;

KeymapConfig keymapConfig = mInput.getKeymapConfig();

switch (input_event[3]) {
switch (input_event[2]) {
case "UP":
event.action = UP;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ public void handleEvent(int code, int value) {
if (code == REL_X || code == REL_Y) movePointer();
}

public void evAbsY(int y) {
this.y1 = y;
if (pointer_down) mInput.injectEvent(x1, y1, MOVE, pointerId1);
movePointer();
}

public void evAbsX(int x) {
this.x1 = x;
if (pointer_down) mInput.injectEvent(x1, y1, MOVE, pointerId1);
movePointer();
}

public void stop() {
mouseAimHandler = null;
scrollZoomHandler = null;
Expand Down

0 comments on commit f26f83e

Please sign in to comment.