Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra keys conversion to agnosticism #2237

Conversation

agnostic-apollo
Copy link
Member

@agnostic-apollo agnostic-apollo commented Aug 23, 2021

  • The termux extra-keys have been moved to termux-shared library so that they can be imported and used by other apps for their own needs as long as they comply with GPLv3 license.
  • You can now long hold on CTRL, ALT, SHIFT and FN to lock those control keys. They will not be released when you press another key and will only be released by pressing the respective control key again.
  • Add shift key support in extra keys and terminal with SHIFT or SHFT.
  • Ensured FN extra key is read by the terminal.

@suhan-paradkar let me know if some design change needs to be made for https://github.com/suhan-paradkar/termux-wayland. Check commits and javadocs for more details, there should be enough info to get it working. implementation 'com.github.agnostic-apollo:termux-app:extra-keys-conversion-to-agnosticism-SNAPSHOT'

Someone on debug builds should "ideally" also test this before I merge, I have tested and seems to be working fine on my Android 7 device.

The termux `extra-keys` have been moved to `termux-shared` library so that they can be imported and used by other apps for their own needs as long as they comply with GPLv3 license.

Almost everything is customizable and has no dependency on termux specific logic. Check the javadocs of files of `com.termux.shared.terminal.io.extrakeys` package for more info, specially, `ExtraKeysView`, `ExtraKeysInfo`, `ExtraKeyButton`, `TerminalExtraKeys` and  `TermuxTerminalExtraKeys`.

Moreover, you can now long hold on `CTRL`, `ALT`, `SHIFT` and `FN` to lock those control keys. They will not be released when you press another key and will only be released by pressing the respective control key again.

Closes termux#2049, Closes termux#1861
Can't find info on why it wasn't being read before
@creepy-pasta101
Copy link

Thanks for that @agnostic-apollo I will be working on it soon and will let you know about that👍👍

@creepy-pasta101
Copy link

Well.. for your information.. I will be working on it here

This reverts commit 296ee60

We do not need to bump to compileSdkVersion 31 currently, since I have decided not to bump `androidx.window` to `1.0.0-alpha10` or higher currently, since it has changed APIs and ViewUtils will break.

https://developer.android.com/jetpack/androidx/releases/window

Moreover, bumping compileSdkVersion to 31 requires openjdk 11 in build environment, which will break Jitpack library build and possibly still F-Droid as well, unless changes are made.

https://gitlab.com/fdroid/fdroiddata/-/issues/2441

jitpack/jitpack.io#4474

https://jitpack.io/docs/BUILDING/#java-version

Also in android studio stub files are loaded when opening class sources since android 12 sources aren't available.
@agnostic-apollo
Copy link
Member Author

agnostic-apollo commented Aug 23, 2021

You are welcome.

Jitpack build was failing, which failed yours. Is fixed now.

@creepy-pasta101
Copy link

Thanks 👍 lemme rerun the CI

@creepy-pasta101
Copy link

Well.. is there any way an app can read termux-app's Sharedpreferences set in ./termux/termux.properties ?

@RalfWerner
Copy link

RalfWerner commented Aug 23, 2021

I've extend my Extra-Keys (EK) with ALT,SHIFT,FN, and checked on different AVD and my Android 9 device. The long-tap/hold of the first four Keys has worked as described (helpful in mc). Here is a shot of the complete *properties:
grafik
The 11th Key is KEYBOARD and still working sometimes and sometimes not! The 11th popup is DRAWER but termux chrashes here allways on all checked devices (not draw from left). Could you repeat that?
With draw on EK from right to left the EK will removed and replaced by OS-KB-Settings (gboard) and word input mode
That is nice (floating/non-floating toggle is possible) but no more EK, Should that be so?

If you are currently working on EK, could you also check the behavior of the auto-repeat function (sixth Key LEFT/BACKSPACE) and whether the actions started (12th keymc/F10) could be canceled by move finger outside?

@ghost
Copy link

ghost commented Aug 23, 2021

What program do you use to test or work with keys FN and SHIFT?

@ghost
Copy link

ghost commented Aug 23, 2021

Used vtshowkeys from vtutils package.

I can be wrong, but it appears that FN simply not working in Termux. Here is what output vtshowkeys procuces on PC for combination FN + left arrow:

0033  27 0x1B Escape '^[' or '\e'
0133  91 0x5B ASCII '['
0110  72 0x48 ASCII 'H'

In Termux it produces nothing.

SHIFT appears to be working correctly.

@RalfWerner
Copy link

RalfWerner commented Aug 23, 2021

What program do you use to test or work with keys FN

@xeffyr Whether Key FN is really needed I know either. But it is included on many real keyboards and also does something.
Here is a video in which my BT-KB is coupled with different devices (also with FN) and the effects in Termux are confusing. For example, FN+Right/Left at AVD corresponds to the startscreen function (Home) but not with Hard-KB and scrcpy or direct coupling.
If it is possible to merge the two EK from Termux and T:X11, new possibilities of the X protocol result. Currently with T:Wayland only small sentence (eight keys) without config possible. If I use BT-KB so the keys above are HOME/END but also other buttons with FN like Num_Log, Screenshot, Search are recognized correctly. However, these buttons are not offered in most OS-KB (Hackers KB only).

My goal is to minimize the finger work and if FN is useful for this I do not know yet. I wish @suhan-paradkar a lot of skill and success in the merge try. Incidentally, the PASTE Key is also implemented correctly in @agnostic-apollo artifact.
grafik

In between I've also checked on my SM-P610 device (shot) and get DRAWERchrash also without popup - Could you repeat that?

@ghost
Copy link

ghost commented Aug 23, 2021

Here is a video in which my BT-KB is coupled with different devices (also with FN) and the effects in Termux are confusing. For example, FN+Right/Left at AVD corresponds to the startscreen function (Home)

Video appears to be about older Termux version.

I'm asking specifically about this pull request and only about behavior of software keyboard and extra keys row. FN + Left/Right arrows either does not produce expected input or actually does something else (in this case, what exactly?). Hardware keyboard is another story. I have tried a USB keyboard for PC as well as bluetooth keyboard made for Nexus 7 - both produced different behavior on FN + Left/Right combination, but neither was one that I expect (when FN is pressed, left/right send home/end respectively). Related issue #731 (closed 3 years ago). @agnostic-apollo

@RalfWerner
Copy link

Video appears to be about older Termux version

Right - the PR was closed yesterday and treated KEYBOARD Extra Key and BT/USB-KB together with OS-KB. I have no differences between BT/USB but discovered some between AVD and real device and the behavior of the latest version (below) is not different.

Since no one suffers from the confusing behavior or has not such a tablet device, it is still unchanged and probably remains so until other users suffer from it too.

@agnostic-apollo
Copy link
Member Author

agnostic-apollo commented Aug 23, 2021

is there any way an app can read termux-app's Sharedpreferences set in ./termux/termux.properties ?

@suhan-paradkar That file stores SharedProperties, not SharedPreferences. If you are going to declare sharedUserId=com.termux in Termux:Wayland, then you will have direct access. If not, then you can get the file content in two ways. Either via SAF by letting user select file/directory and storing Uri permanently, but of course this will need UI interaction. Or possibly better background way would be to use RUN_COMMAND intent background mode. Use PendingIndent mechanism to read the file via cat, then store in your own data directory with a call to FileUtils.writeStringToFile(), then pass to SharedProperties. This way you can read any termux file if needed, even outside $HOME.

https://github.com/termux/termux-app/wiki/RUN_COMMAND-Intent

@creepy-pasta101
Copy link

Ah.. thanks...

@RalfWerner
Copy link

RalfWerner commented Aug 25, 2021

Someone on debug builds should "ideally" also test this before I merge

@agnostic-apollo again - Do you also get Termux crash when tapping on DRAWER Extra Key (PASTE,SHFT missing here)?

…pening

Also fixed NullPointerException due to changes in 2a74d43
The user can add `disable-hardware-keyboard-shortcuts=true` entry to `termux.properties` file to disable hardware keyboard shortcuts. The default value is `false`. Running `termux-reload-settings` command will also update the behaviour instantaneously if changed. Note that for `ctrl+alt+p` to work, you need to unset `shortcut.rename-session = ctrl + n`. https://wiki.termux.com/wiki/Terminal_Settings

Closes termux#1825
The `terminal-margin-horizontal` key can be used to adjust the terminal left/right margin and the `terminal-margin-vertical` can be used to adjust the terminal top/bottom margin. This will also affect drawer. The user can set an integer value between `0` and `100` as `dp` units. The default value is still `3` for horizontal and `0` for vertical margin. So adding an entry like `terminal-margin-horizontal=10` to `termux.properties` file will allow users to set a horizontal margin of `10dp`. After updating the value, either restart termux or run `termux-reload-settings` for changes to take effect.

This was added since for some users text on edges would not be shown on the screen or they had screen protectors/cases that covered screen edges (Of course, that would require fixing every single app and android system UI itself, so kinda stupid to use). Moreover, horizontal margin of like `10dp` may be helpful with peek-and-slide for people having gesture navigation enabled on android `10+` since they won't be to touch at exactly the edge of the screen to trigger peek (termux#1325).

Closes termux#2210
…yboards and added docs for keyboard key characters mapping
@agnostic-apollo
Copy link
Member Author

agnostic-apollo commented Aug 26, 2021

@RalfWerner

Do you also get Termux crash when tapping on DRAWER

Yes, that has been fixed in 16c56a9

Should that be so?

Should what be so? EK don't float...

could you also check the behavior of the auto-repeat function (sixth Key LEFT/BACKSPACE) and whether the actions started (12th keymc/F10) could be canceled be move finger outside?

I didn't get you. Once a macro has started, it can't be stopped by pressing another key. Auto-repeat will automatically cancel once you lift the finger.

@xeffyr

I have added docs with the details for behaviour in 994df1c.

SHIFT will work since /system/usr/keychars/Virtual.kcm has definition for shift modifier for the english letters. But that would only apply when using Gboard, for other keyboards like Hacker's Keyboard, OpenBoard, etc, the onKeyDown() is not called, so I added behaviour to manually uppercase in commitText() via Character.toUpperCase() for those keyboards and this way is better since would handle non-english too. Although, String.toUpperCase() would likely be even better. Adding this logic in onKeyDown() after getUnicodeChar() returns a valid code point (result != 0) might be problematic since kcm file may have lower case letter by default with shift and uppercasing it after that would break it.

FN will also work for unicode characters that don't need to be converted to escape sequences by KeyHandler.getCode() if the fn modifier entries exist in Virtual.kcm for soft keyboards and Generic.kcm or vendor specific kcm for hardware keyboards. The fallback key codes won't work. The default Virtual.kcm in AOSP and likely your device doesn't have fn modifier definitions so wouldn't work.

I have added a proof of concept for custom key mapping for software and hardware keyboards in d9c7c8b that also supports escape sequences but currently requires root to modify /system/usr/keychars/Virtual.kcm, since porting KeyCharacterMap.cpp from AOSP needs to be looked into, which if done would work for non-root. With the below in Virtual.kcm pressing DPAD_LEFT will trigger left movement (KEYCODE_DPAD_LEFT) and pressing fn+DPAD_LEFT will trigger move to home (KEYCODE_MOVE_HOME). However, pressing shift+DPAD_LEFT will just input code point 19 into terminal which is equivalent to End of Medium (EM) in ascii. The other two work because TerminalEmuator.handleKeyCode() via KeyHandler.getCode() converts them to a valid escape sequence that terminal uses to perform the action. As for how useful this or fn support would be, I can't say. There are some issues opened with wrong layout or character issues for hardware keyboard like #250 but some may also be solved externally by defining a kcm file and building an app that publishes the layout, like done in https://github.com/ris58h/custom-keyboard-layout or https://github.com/abbeyanke/se_sv_dvorak via ACTION_QUERY_KEYBOARD_LAYOUTS.

#'\u0015' 21 KEYCODE_DPAD_LEFT
#'\u0016' 22 KEYCODE_DPAD_RIGHT
#'\u0018' 24 KEYCODE_VOLUME_UP
#'\u0019' 25 KEYCODE_VOLUME_DOWN
#'\u007a' 122 KEYCODE_MOVE_HOME
#'\u007b' 123 KEYCODE_MOVE_END

key DPAD_LEFT {
    base: '\u0015'
    shift: '\u0019'
    fn: '\u007a'
}

key DPAD_RIGHT {
    base: '\u0016'
    shift: '\u0018'
    fn: '\u007b'
}

For more info on kcm files, check https://source.android.com/devices/input/key-character-map-files

I have tried a USB keyboard for PC as well as bluetooth keyboard made for Nexus 7 - both produced different behavior on FN + Left/Right combination

They are likely using different kcm files, check dumpsys input. Also for the 1 usb keyboard that I had lying around Apple A1243 which had an fn key, the fn key was sent to android and received as an event and then mapped by Generic.kcm after modification. Some keyboards might not send it and do the mapping in the microcontroller and send the keyboard specific alternate key code. The AOSP Generic.kcm does not have any fn mappings and your move home/end one would require escape sequence conversion anyways to work, either via fallback so that onKeyDown is called again to run handleKeyCode() or with d9c7c8b patch (kcm-files-mapping.patch.txt) for escape sequences.

@RalfWerner
Copy link

Should What Be? Ek do not float ... i did not get you. Once a Macro Has started ...

Was related to the shot above - 1:41 in video. I have created it with two devices. Maybe you understand better, what I mean, the EK line disappears several times in the first 17 seconds and can not be used! 17Mb is a bit too big for Github - so video is here.

@agnostic-apollo
Copy link
Member Author

, the EK line disappears several times in the first 17 seconds and can not be used!

There is no internal logic for keyboard button that would cause switching of extra key to text input mode. My guess is that when you press the button or swipe up, you also have some right to left movement in your fingers that triggers a fling, which then causes the switch. The ViewPager that is used by termux to switch pages between extra keys and text input does not have any API to set fling sensitivity, and it decides it automatically based on 25dp x display density. It might get triggered more easily in pip in a smaller window for your case. Reflection could possibly be used to set sensitivity but that won't be done currently since will take time to experiment, will look into it in future, assuming that is indeed the real issue.

@agnostic-apollo
Copy link
Member Author

I am merging this since no other issue has been raised.

@agnostic-apollo agnostic-apollo merged commit e7d06ae into termux:master Aug 27, 2021
@RalfWerner
Copy link

My guess is that when you press the button or swipe up, you also have some right to left movement in your fingers that triggers a fling, which then causes the switch.

Exactly that I mean! The movement can also be done from left to right. The main thing is less than 50% of the length remains at the end. After the popup has been selected (up) this is no longer possible and the decision for one of the two alternatives can no longer be revised.
The fling can also be done without OS-KB. Then EK is only missing. With back-fling EK appears again, but this time with OS-KB or not or half OS-KB - do you like shots of this? Meanwhile, the same EK is also in X11. OS-KB is never turned on here.

@agnostic-apollo
Copy link
Member Author

The termux-app sets a FocusChangeListerner for the TerminalView to automatically open keyboard when it is selected. The LorieView does not.

@RalfWerner
Copy link

RalfWerner commented Sep 2, 2021

Thanks for the hint. @suhan-paradkar had already noticed that and I hope he find a solution - done in between!
Commit above was about the fling behave here. Without OS-KB, there is no use - why not direct open OS-KB after first EK remove? Thereafter, with the first tab/press clearly in which mode I am. Depending on the OS-KB, the button can be here corrected before release or canceled when the finger is moved out of the OS-KB (typical behavior).

For some of my EK buttons, this is easily possible by switching in fling after press, even if it is not completed (<50%). Back then does not work and after popup no more. two Examples with nano check.c:

  • {macro:END,popup:HOME} After press on END (with CTRL/^ fixed), this can be broken with a small left/right finger movement. HOME does not work anymore but it could be redevised on END. If I'm at position 79 in a table with 125 lines (will be displayed with END) and does not want to start the beginning (HOME show line 1) I can cancel this but only before popup.
  • {key:LEFT,popup:BKSP} LEFT has autorepeat so the finger movement has quickly to executed. In the case up I can only dodge to release on LEFT. This is usually no problem or you use autorepeat LEFT and move finger up at the desired position.

Most Extra-Keys could be common in Termux and X11 except X11/TUX-Toggle and this is not needet in Split/floating mode.
Open topic is harmonized EK in the two Apps. In X11 currently only exit/restart is possible, which also applies to other Preferences.

AdamMickiewich pushed a commit to VolyaTeam/dzida-app that referenced this pull request Aug 8, 2022
…sion-to-agnosticism

Extra keys conversion to agnosticism and disabling hardware keyboard shortcuts and terminal margin customization support
shrihankp pushed a commit to reisxd/termux-app that referenced this pull request Oct 20, 2022
…sion-to-agnosticism

Extra keys conversion to agnosticism and disabling hardware keyboard shortcuts and terminal margin customization support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants