Skip to content

Commit

Permalink
Add an option to use termux-app's additional key bar behaviour.
Browse files Browse the repository at this point in the history
Fixes #604
  • Loading branch information
twaik committed May 16, 2024
1 parent 2f26555 commit ebfac49
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class MainActivity extends AppCompatActivity implements View.OnApplyWindo
private boolean filterOutWinKey = false;
private boolean hideEKOnVolDown = false;
private boolean toggleIMEUsingBackKey = false;
private boolean useTermuxEKBarBehaviour = false;
private static final int KEY_BACK = 158;

private final BroadcastReceiver receiver = new BroadcastReceiver() {
Expand Down Expand Up @@ -173,6 +174,7 @@ public void swipeDown() {
}
}, new InputEventSender(lorieView));
mLorieKeyListener = (v, k, e) -> {
InputDevice dev = e.getDevice();
if (!captureVolumeKeys && (k == KEYCODE_VOLUME_DOWN || k == KEYCODE_VOLUME_UP))
return false;

Expand All @@ -199,6 +201,10 @@ public void swipeDown() {
}
}

// Do not steal dedicated buttons from a full external keyboard.
if (useTermuxEKBarBehaviour && mExtraKeys != null && (dev == null || dev.isVirtual()))
mExtraKeys.unsetSpecialKeys();

return mInputHandler.sendKeyEvent(v, e);
};

Expand Down Expand Up @@ -538,6 +544,7 @@ void onPreferencesChanged(String key) {
KeyInterceptor.shutdown();

hideEKOnVolDown = p.getBoolean("hideEKOnVolDown", false);
useTermuxEKBarBehaviour = p.getBoolean("useTermuxEKBarBehaviour", false);
toggleIMEUsingBackKey = p.getBoolean("toggleIMEUsingBackKey", true);

int requestedOrientation = p.getBoolean("forceLandscape", false) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ protected void onTerminalExtraKeyButtonClick(@SuppressWarnings("unused") View vi
}
}

public void unsetSpecialKeys() {
if (mExtraKeysView == null)
return;
mExtraKeysView.readSpecialButton(SpecialButton.CTRL, true);
mExtraKeysView.readSpecialButton(SpecialButton.ALT, true);
mExtraKeysView.readSpecialButton(SpecialButton.SHIFT, true);
mExtraKeysView.readSpecialButton(SpecialButton.META, true);
}

@Override
public boolean performExtraKeyButtonHapticFeedback(View view, ExtraKeyButton buttonInfo, Button button) {
MainActivity.handler.postDelayed(() -> {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
android:defaultValue="false"
android:key="hideEKOnVolDown" />

<SwitchPreferenceCompat
android:title="Deactivate special keys on additional key bar after each keypress"
android:summary="Use long-tap to lock special keys"
android:defaultValue="false"
android:key="useTermuxEKBarBehaviour" />

<SwitchPreferenceCompat
android:title="Show IME with external keyboard"
android:summary="Show software keyboard while hardware keyboard is connected. Requires WRITE_SECURE_SETTINGS permission."
Expand Down

0 comments on commit ebfac49

Please sign in to comment.