Skip to content

Commit

Permalink
feat: add setting for switching pointer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Feb 25, 2024
1 parent 605d4a3 commit a842d8d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 28 deletions.
1 change: 0 additions & 1 deletion app/src/main/aidl/xtr/keymapper/IRemoteService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import xtr.keymapper.keymap.KeymapProfile;
interface IRemoteService {
void destroy() = 16777114; // Destroy method defined by Shizuku server

boolean isRoot() = 1;

void startServer(in KeymapProfile profile, in KeymapConfig keymapConfig, IRemoteServiceCallback cb, int screenWidth, int screenHeight) = 2;
void stopServer() = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
});
mouseAimActions();
loadTouchpadInputSettings();

binding.pointerMode.setText(keymapConfig.pointerMode);
final String[] pointerModes = {KeymapConfig.POINTER_COMBINED, KeymapConfig.POINTER_OVERLAY, KeymapConfig.POINTER_SYSTEM};
((MaterialAutoCompleteTextView)binding.pointerMode).setSimpleItems(pointerModes);

setDefaultVisibilty();
binding.sliders.setVisibility(View.VISIBLE);
}
Expand Down Expand Up @@ -187,6 +192,7 @@ public void onDestroyView() {
saveKeyboardShortcuts();
keymapConfig.mouseAimToggle = binding.mouseAimAction.getText().toString().equals(KeymapConfig.TOGGLE);
keymapConfig.touchpadInputMode = binding.touchpadInputMode.getText().toString();
keymapConfig.pointerMode = binding.pointerMode.getText().toString();

keymapConfig.mouseSensitivity = binding.sliderMouse.getValue();
keymapConfig.scrollSpeed = binding.sliderScrollSpeed.getValue();
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/xtr/keymapper/keymap/KeymapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ public class KeymapConfig implements Parcelable {
public int pauseResumeShortcutKey, launchEditorShortcutKey, switchProfileShortcutKey;
public int swipeDelayMs;
public String pauseResumeShortcutKeyModifier, launchEditorShortcutKeyModifier, switchProfileShortcutKeyModifier;
public String pointerMode;

public static final String KEY_CTRL = "Ctrl", KEY_ALT = "Alt";
public static final String TOGGLE = "Toggle", HOLD = "Hold";
public static final String TOUCHPAD_DIRECT = "Direct";
public static final String TOUCHPAD_RELATIVE = "Relative";
public static final String TOUCHPAD_DISABLED = "Disabled";

public static final String POINTER_SYSTEM = "System";
public static final String POINTER_OVERLAY = "Overlay";
public static final String POINTER_COMBINED = "Combined";

public int mouseAimShortcutKey;
public boolean mouseAimToggle;
public String touchpadInputMode;
Expand Down Expand Up @@ -66,6 +72,7 @@ protected KeymapConfig(Parcel in) {
disableAutoProfiling = in.readByte() != 0;
touchpadInputMode = in.readString();
useShizuku = in.readByte() != 0;
pointerMode = in.readString();
}

public static final Creator<KeymapConfig> CREATOR = new Creator<>() {
Expand Down Expand Up @@ -105,6 +112,7 @@ private void loadSharedPrefs() {
dpadRadiusMultiplier = sharedPref.getFloat("dpad_radius", 1f);

touchpadInputMode = sharedPref.getString("touchpad_input_mode", TOUCHPAD_DISABLED);
pointerMode = sharedPref.getString("pointer_mode", POINTER_COMBINED);
}

public void applySharedPrefs() {
Expand All @@ -127,6 +135,7 @@ public void applySharedPrefs() {
.putString("switch_profile_shortcut_modifier", switchProfileShortcutKeyModifier)
.putString("touchpad_input_mode", touchpadInputMode)
.putInt("swipe_delay_ms", swipeDelayMs)
.putString("pointer_mode", pointerMode)
.apply();
}

Expand Down Expand Up @@ -171,5 +180,6 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeByte((byte) (disableAutoProfiling ? 1 : 0));
dest.writeString(touchpadInputMode);
dest.writeByte((byte) (useShizuku ? 1 : 0));
dest.writeString(pointerMode);
}
}
15 changes: 10 additions & 5 deletions app/src/main/java/xtr/keymapper/server/InputService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class InputService implements IInputInterface {
private final Input input = new Input();
public static final int UP = 0, DOWN = 1, MOVE = 2;
private final IRemoteServiceCallback mCallback;
int supportsUinput;
boolean stopEvents = false;
boolean pointerUp = false;
private final boolean isWaylandClient;
Expand All @@ -41,7 +40,13 @@ public InputService(KeymapProfile profile, KeymapConfig keymapConfig, IRemoteSer
this.mCallback = mCallback;
this.isWaylandClient = isWaylandClient;
this.cursorView = cursorView;
supportsUinput = initMouseCursor(screenWidth, screenHeight);

if (cursorView == null || !keymapConfig.pointerMode.equals(KeymapConfig.POINTER_OVERLAY)) {
initMouseCursor(screenWidth, screenHeight);
// Reduce visibility of system pointer
cursorSetX(0);
cursorSetY(0);
}

this.touchpadInputMode = keymapConfig.touchpadInputMode;
if (touchpadInputMode.equals(KeymapConfig.TOUCHPAD_DIRECT))
Expand Down Expand Up @@ -143,12 +148,12 @@ else if (touchpadInputMode.equals(KeymapConfig.TOUCHPAD_RELATIVE))
stopTouchpadRelative();
}

public native void cursorSetX(int x);
public native void cursorSetY(int y);
public native int openDevice(String device);
public native void stopMouse();

// mouse cursor created with uinput in mouse_cursor.cpp
public native void cursorSetX(int x);
public native void cursorSetY(int y);
private native int initMouseCursor(int width, int height);
public native void destroyUinputDev();

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/xtr/keymapper/server/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ private boolean addNewDevices(String[] data) {
return true;
}

public boolean isRoot() {
return inputService.supportsUinput > 0;
}

@Override
public void startServer(KeymapProfile profile, KeymapConfig keymapConfig, IRemoteServiceCallback cb, int screenWidth, int screenHeight) throws RemoteException {
if (inputService != null) stopServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ private boolean transactRemote(int code, ParcelableByteArray data) {
return true;
}

@Override public boolean isRoot()
{
ParcelableByteArray _data = new ParcelableByteArray(5);
boolean _status = transactRemote(TRANSACTION_isRoot, _data);

boolean _result = (0!=readInt());

return _result;
}

@Override public void startServer(KeymapProfile profile, KeymapConfig keymapConfig, IRemoteServiceCallback cb, int screenWidth, int screenHeight) {
ParcelableByteArray _data = new ParcelableByteArray(5);
_data.writeTypedObject(profile);
Expand Down Expand Up @@ -146,7 +136,6 @@ private boolean transactRemote(int code, ParcelableByteArray data) {
ParcelableByteArray _data = new ParcelableByteArray(5);
boolean _status = transactRemote(TRANSACTION_reloadKeymap, _data);
}
static final int TRANSACTION_isRoot = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);

static final int TRANSACTION_startServer = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
static final int TRANSACTION_stopServer = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ public RemoteServiceSocketServer(RemoteService mService) {
public void onTransact(int code) throws RemoteException {
switch (code)
{
case TRANSACTION_isRoot:
{
boolean _result = mService.isRoot();
writeNoException();
writeInt(((_result)?(1):(0)));
break;
}
case TRANSACTION_startServer:
{
xtr.keymapper.keymap.KeymapProfile _arg0;
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/fragment_settings_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,27 @@

</com.google.android.material.textfield.TextInputLayout>

<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:gravity="end"
android:text="@string/pointer" />


<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<AutoCompleteTextView
android:id="@+id/pointer_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none" />

</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>

<com.google.android.material.materialswitch.MaterialSwitch
Expand All @@ -354,6 +375,7 @@
android:checked="false"
android:text="@string/use_shizuku" />


</LinearLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
<string name="touchpad_input">Touchpad Input</string>
<string name="launch_app">Launch App</string>
<string name="use_shizuku">Use Shizuku</string>
<string name="pointer">Pointer Mode</string>

</resources>

0 comments on commit a842d8d

Please sign in to comment.