Skip to content

Commit

Permalink
fix: cursor randomly invisible
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Oct 5, 2024
1 parent f4670d8 commit cdb7abe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/xtr/keymapper/server/InputService.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public void showCursor() {
throw new RuntimeException(e);
}
}

}

public void reloadKeymap() {
Expand Down
71 changes: 39 additions & 32 deletions app/src/main/java/xtr/keymapper/server/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,30 @@ public void destroy() {
}

private void addCursorView() {
if (cursorView != null) mHandler.post(() -> {
if(cursorView.isAttachedToWindow()) {
cursorView.setVisibility(View.VISIBLE);
} else {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
TYPE_SECURE_SYSTEM_OVERLAY,
// Don't let the cursor grab the input focus
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
// Make the underlying application window visible
// through the cursor
PixelFormat.TRANSLUCENT);
try {
windowManager.addView(cursorView, params);
} catch (IllegalStateException e) { // A14 QPR3 https://gist.github.com/RikkaW/be3fe4178903702c54ec73b2fc1187fe
Log.e(TAG, e.getMessage(), e);
cursorView = null;
}
if (cursorView == null) return;

if(cursorView.isAttachedToWindow()) {
cursorView.setVisibility(View.VISIBLE);
} else {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
TYPE_SECURE_SYSTEM_OVERLAY,
// Don't let the cursor grab the input focus
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
// Make the underlying application window visible
// through the cursor
PixelFormat.TRANSLUCENT);
try {
windowManager.addView(cursorView, params);
} catch (IllegalStateException e) { // A14 QPR3 issue https://gist.github.com/RikkaW/be3fe4178903702c54ec73b2fc1187fe
cursorView = null;
Log.e(TAG, e.getMessage(), e);
}
});
}
}

public void prepareCursorOverlayWindow() throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException {
Expand Down Expand Up @@ -214,17 +214,24 @@ private boolean addNewDevices(String[] data) {
*/
@Override
public void startServer(KeymapProfile profile, KeymapConfig keymapConfig, IRemoteServiceCallback cb, int screenWidth, int screenHeight) throws RemoteException {

if (inputService != null) stopServer();
if (cb != null) cb.asBinder().linkToDeath(this::stopServer, 0);
if (keymapConfig.pointerMode != KeymapConfig.POINTER_SYSTEM) {
addCursorView();
}
inputService = new InputService(profile, keymapConfig, cb, screenWidth, screenHeight, cursorView, isWaylandClient);
if (!isWaylandClient) {
inputService.setMouseLock(true);
inputService.openDevice(currentDevice);
}
mHandler.post(() -> {
if (keymapConfig.pointerMode != KeymapConfig.POINTER_SYSTEM) {
addCursorView();
} else {
cursorView = null;
}
try {
inputService = new InputService(profile, keymapConfig, cb, screenWidth, screenHeight, cursorView, isWaylandClient);
if (!isWaylandClient) {
inputService.setMouseLock(true);
inputService.openDevice(currentDevice);
}
} catch (RemoteException e) {
throw new RuntimeException(e);
}
});
}

@Override
Expand Down

0 comments on commit cdb7abe

Please sign in to comment.