Skip to content

Commit

Permalink
Fixed: Ensure FN extra key is read by the terminal
Browse files Browse the repository at this point in the history
Can't find info on why it wasn't being read before
  • Loading branch information
agnostic-apollo committed Aug 23, 2021
1 parent 9117240 commit d1478fb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ public boolean readShiftKey() {
return readExtraKeysSpecialButton(SpecialButton.SHIFT);
}

@Override
public boolean readFnKey() {
return readExtraKeysSpecialButton(SpecialButton.FN);
}

public boolean readExtraKeysSpecialButton(SpecialButton specialButton) {
if (mActivity.getExtraKeysView() == null) return false;
Boolean state = mActivity.getExtraKeysView().readSpecialButton(specialButton, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,16 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
final boolean controlDown = event.isCtrlPressed() || mClient.readControlKey();
final boolean leftAltDown = (metaState & KeyEvent.META_ALT_LEFT_ON) != 0 || mClient.readAltKey();
final boolean shiftDown = event.isShiftPressed() || mClient.readShiftKey();
final boolean fnDown = event.isFunctionPressed() || mClient.readFnKey();
final boolean rightAltDownFromEvent = (metaState & KeyEvent.META_ALT_RIGHT_ON) != 0;

int keyMod = 0;
if (controlDown) keyMod |= KeyHandler.KEYMOD_CTRL;
if (event.isAltPressed() || leftAltDown) keyMod |= KeyHandler.KEYMOD_ALT;
if (shiftDown) keyMod |= KeyHandler.KEYMOD_SHIFT;
if (event.isNumLockOn()) keyMod |= KeyHandler.KEYMOD_NUM_LOCK;
if (!event.isFunctionPressed() && handleKeyCode(keyCode, keyMod)) {
// https://github.com/termux/termux-app/issues/731
if (!fnDown && handleKeyCode(keyCode, keyMod)) {
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED) mClient.logInfo(LOG_TAG, "handleKeyCode() took key event");
return true;
}
Expand All @@ -622,6 +624,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
int effectiveMetaState = event.getMetaState() & ~bitsToClear;

if (shiftDown) effectiveMetaState |= KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON;
if (fnDown) effectiveMetaState |= KeyEvent.META_FUNCTION_ON;

int result = event.getUnicodeChar(effectiveMetaState);
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public interface TerminalViewClient {

boolean readShiftKey();

boolean readFnKey();



boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ public boolean readAltKey() {
return false;
}

@Override
public boolean readShiftKey() {
return false;
}

@Override
public boolean readFnKey() {
return false;
}



@Override
Expand Down

0 comments on commit d1478fb

Please sign in to comment.