yourealwaysbe / forkyz

Forkyz Crosswords
GNU General Public License v3.0
39 stars 5 forks source link

Forkyz does not work with physical keyboard on Unihertz Titan #70

Closed Wren0 closed 1 year ago

Wren0 commented 1 year ago

Hello,

This is an outlier issue, but Forkyz does not work with the keyboard on my Unihertz Titan. The only keys that appear to do anything are spacebar and backspace. It would otherwise be the perfect device for a crossword app since it has a 1:1 aspect screen and physical keyboard.

I understand if you won't or can't add support for this device, but I thank you for your consideration.

yourealwaysbe commented 1 year ago

That's an odd one, and might be hard to fix without a device to play with.

Have you tried it with the native keyboard enabled (in settings > keyboard settings)?

Even if that works it would be good for it to work without the native keyboard. I have a thought we could try if you're happy installing versions i post here.

I'm away until next week, so won't do anything before then.

Also, have you tried Shortyz (also on FDroid). I forked that so it would help narrow it down if we know if it's something i broke.

yourealwaysbe commented 1 year ago

Oh, do the arrow keys work?

Wren0 commented 1 year ago

The physical keyboard doesn't have arrow keys.

When I enable native keyboard, all of the letter keys behave the same as backspace, that is they move the cursor back by one square (both horizontally or vertically), erasing any character that is behind it. Backspace and the spacebar still work and when I press enter, it cycles through each of the numbered rows in turn.

Interestingly, Shortyz does seem to work. It even somehow knows to suppress the native software mini keyboard that usually pops up when typing on the physical keyboard, which is used for entering special characters but which isn't needed for the crossword.

Of course, I am happy to try any test builds of Forkyz. Just let me know.

Thank you for taking a look at this.

yourealwaysbe commented 1 year ago

Ok, that's weird all around. Btw, are you happy using logcat and grepping the output? If not, I'll add some other way to get information.

When you say mini keyboard, do you mean something like an extra row of buttons to augment the hardware keyboard, or another full software keyboard? If you mean a full keyboard, does that show even when the native keyboard is not enabled in settings? And does it work?

In general, i think I'll need to add a lot of logging to find out exactly where it's sending its hardware keyboard events and how they're represented. Android input is a bit of a free-for-all and the developer documentation just says to experiment with as many different input methods as possible. This will at least be an original example :)

Fwiw, Forkyz supports special characters (and multiple characters) in crossword cells. They come up every now and then. But i don't think that's the reason the software keyboard doesn't show in Shortyz. I suspect that's because Shortyz never actually creates a software input connection and just treats everything as hardware instead. That said, i didn't think I'd disturbed the hardware input flow.

Wren0 commented 1 year ago

The mini keyboard is just an extra row of button to augment the hardware keyboard. It just allows entering characters not present on the hardware keyboard and, if enabled, word prediction.

In Forkyz, this mini keyboard doesn't appear if native keyboard is disabled, but it does appear if native keyboard is enabled.

In Shortyz no software keyboard appears when the option "keyboard style" is set to "small", "with arrows" or "native", but the Shortyz built-in keyboard does appear if "keyboard style" is set to either "small" or "with arrows" and the "force keyboard" option is selected. In all cases, the hardware keyboard continues to function properly.

I've never used logcat on an Android device but if you tell me what to do, I can do it. My phone is rooted (Magisk) and I have a terminal app (Termux). My computer is running Manjaro and I have adb installed.

yourealwaysbe commented 1 year ago

Great, that makes sense to me.

I found something in the docs that might explain the odd behaviour of the native keyboard in Forkyz. I'm not sure about the non native behaviour, but some logging will help.

I'll put together a test version next week.

Wren0 commented 1 year ago

Ok, I'll check back here then. Thanks for taking a look at this.

yourealwaysbe commented 1 year ago

Can you try this version this version?

You will need to uninstall the FDroid version before installing this one as they're signed with different keys.

Once installed, can you connect your phone to your computer with a usb cable. Make sure usb debugging is enabled in developer settings. Check that the command

$ adb logcat

produces (a whole load of) output.

Then, run

$ adb logcat | grep FORKYZ > keyboard.txt

and open Forkyz. Try to enter text in a few cells both with and without the non-native keyboard enabled.

Check that keyboard.txt contains a bunch of lines, all starting with FORKYZ and attach the file here. It'll only contain info on the characters you typed (and how that was reported to Forkyz).

Let me know if the native keyboard works properly now (i made some changes).

Thanks.

Wren0 commented 1 year ago

The Forkyz built-in keyboard works as usual, however pressing any key on the physical keyboard, whether "use native keyboard" is enabled or not, doesn't produce any letters and causes Forkyz to stop responding.

I have attached two files. keyboard_builtin.txt is the log when using the Forkyz built-in keyboard and keyboard_native.txt is with "use native keyboard" enabled and trying to use the physical keyboard.

keyboard_builtin.txt keyboard_native.txt

yourealwaysbe commented 1 year ago

Thanks, that's helpful. Can you try again with this one?

I think it stopped responding because an infinite loop was caused by it starting/ending an empty edit whilst being informed of an update. Since i was sending updates on ending an edit, it got the same update over and over. I clear the pending buffer before updating now, so it doesn't get resent when the empty edit comes.

I think this still happened when the non-native keyboard was used because the change of keyboard mode didn't proliferate fast enough for the system to know the native keyboard was no longer in use. This meant it was still creating a native connection even after changing back to non-native, then getting stuck in the same loop. I make sure that's up to date now every time the game activities are returned to (e.g. after viewing the settings), which looks like it stops the native being created when it shouldn't be, on my device at least.

It's still not clear to me where the hardware keyboard presses are going when the non-native keyboard is used. But hopefully the above fixes will allow the logs to show it. I did make one change that might help: i was returning a native input connection all the time when the system asked for one (using onCheckIsTextEditor to indicate that it shouldn't ask for one, but it turns out the system isn't obliged to use that). Now it doesn't return the input connection unless the native box is checked in settings. This might end up disabling the keyboard altogether. There's an alternative approach i can try if it does.

Wren0 commented 1 year ago

Sorry about the delay in getting back to you. This latest version is mostly working.

The Forkyz built-in software keyboard works as expected.

The physical keyboard works fine, but only if "use native keyboard" is disabled. This doesn't show the phone's mini software keyboard (I like that it doesn't) and I can force hide the built-in keyboard from "show/hide in-app keyboard". I would be happy to use Forkyz like this.

When "use native keyboard" is enabled, the first button I press on the physical keyboard doesn't enter a letter, but rather displays a hollow arrow shift symbol in my notification area which denotes lower case entry mode for the physical keyboard. All subsequent button presses on the physical keyboard enters lower case letters, which are flagged as erroneous entries by Forkyz. I can manually press the shift key to enter an upper case letter, but it reverts to lower case when the cursor moves to the next box. Additionally, the phone's mini software keyboard is being displayed, which isn't needed for English, letters-only puzzles and just takes up space.

I have attached 3 files this time. keyboard_builtin.txt is the Forkyz keyboard, keyboard_physical_nonative.txt is the hardware keyboard with "use native keyboard" disabled, and keyboard_physical_native.txt is the hardware keyboard with "use native keyboard" enabled.

keyboard_builtin.txt keyboard_physical_nonative.txt keyboard_physical_native.txt

yourealwaysbe commented 1 year ago

Ok, that's encouraging. Thanks!

I suspect "always hide" keyboard, and non-native is the right mode for you. It's how i imagined hardware keyboards working.

"Native" is probably the wrong word. It really means "Android IME", which basically means a system software keyboard. The physical keys plus the visible miniboard sounds like the Unihertz implementation of that, so in that sense it's behaving "correctly".

The capitalisation behaviour is irritating though. Forkyz specifies that the input type should be all caps, and the initial caps mode should be to capitalise all characters. It looks like the Unihertz keyboard drops directly out of caps and into lower case when you press the first key. I don't know if that's because i missed some other flag somewhere i need to set, or if it's a Unihertz bug. It would be good to track it down, but i don't have any inspiration for how to go about that.

Since the non-native mode works ok for you, perhaps i'll leave that last bug to a time when i've got a good emulator set up, someone cares about it enough to try a series of builds trying random guesses, or i have some brainwave as to what it might be.

Wren0 commented 1 year ago

Sounds good. I've completed a few crosswords now and haven't had any problems when I leave native keyboard disabled and hide the Forkyz keyboard. As far as I am concerned, this issue is resolved.

Thank you for taking the time to handle this. I know this was an issue that doesn't affect many (if any) other Forkyz users and you went above and beyond to fix it.

yourealwaysbe commented 1 year ago

No problem -- thanks for the new case. I find Android is a bit subtle and you can easily do something wrong in a way that's fine on your own device, but broken on others. It's helpful to know if any device goes wrong because it can be more universal.

I spotted the changes caused a bug on my own phone now, which required some fixing. Let me know if you have any issues with the fixed version. Also, test out the scratch entry on the notes page (i expect that will still be broken on the last version i posted).

Wren0 commented 1 year ago

Unfortunately, the latest version you linked in the last post doesn't work for me. When I try to type anything with the physical keyboard, the phone's mini software keyboard pops up and Forkyz stops responding. This is happening with native keyboard both disabled and enabled.

I have attached logs trying to use the physical keyboard with native keyboard disabled and enabled.

keyboard_physical_nonative.txt keyboard_physical_native.txt

yourealwaysbe commented 1 year ago

That's frustrating. Looking at the logs it might not be the right version -- the latest version had a bit more info on the end batch edit lines.

In the meantime i've changed things again, modelling it on some of the Android stock code.

I also had a thought about capitals. Can you also try the free-form notes box on the notes page. That's a standard Android text box set to all caps mode (in what looks like the same way as i'm doing it). If it works as expected (all caps), then there's one thing i can try to see if it fixes things.

This is the latest latest version.

Wren0 commented 1 year ago

The latest version (https://github.com/yourealwaysbe/forkyz/files/11337072/forkyz.apk.zip) works fine, both with and without native keyboard enabled and neither triggers the phone's mini software keyboard. I've completed several crosswords without issue.

I also tested the notes page and it seems to work. Text enters into the scratch fields as upper case and in the free-form area as lower case (unless I use shift). This appears to be expected behaviour.

I'm away from home right now, but I can post more logs later if they would be helpful.

yourealwaysbe commented 1 year ago

Great, thanks.

I guess this is with keyboard set to always hidden? Otherwise, in native mode, i'd expect the mini keyboard to show. In native mode with the keyboard set to show, i think the caps behaviour will still be wrong. However, i think that's a Unihertz issue: i'd set the free-form text box to also be caps in that last version (and there's nothing Forkyz-specific about that bit).

yourealwaysbe commented 1 year ago

I think we can call the issue closed now. Let me know if anything goes wrong once Version 42 is on FDroid.

Wren0 commented 1 year ago

Yes, I had keyboard set to hidden when I tested it. I tried resetting Forkyz to hide keyboard manually and you're right, the mini software keyboard showed up and it seems that the lower case input is being caused by that mini keyboard. On top of that, with the mini keyboard active, my physical backspace key is overly sensitive, tending to erase multiple characters each time I press it.

Despite that oddness, I agree that the issue can be closed. This last test version of Forkyz is working fine with the physical keyboard when native keyboard is disabled or when native keyboard is enabled with the keyboard set to always hidden.

I'll keep you posted if there are any future problems. Thank you again for handling this, I appreciate it.

yourealwaysbe commented 1 year ago

On top of that, with the mini keyboard active, my physical backspace key is overly sensitive, tending to erase multiple characters each time I press it.

Ah, that's odd. If you get around to it, can you send me a log? There might be a tweak i need to make somewhere depending on what it's sending to Forkyz.

Wren0 commented 1 year ago

I have attached a log from using the physical keyboard with native keyboard enabled and hide keyboard set to manual. I just typed in a few answers (which came out in lower case due to the mini keyboard) and then backspaced over them.

Let me know if you need anything else.

keyboard_physical_native_manualhide.txt

yourealwaysbe commented 1 year ago

Thanks, sorry for going quiet -- i've been travelling again.

The logs do show occasionally that a key press is reported both through the native input connection, and separately as a hardware key event. It's not clear to me when/why this happens, but it might be the cause of the eager backspace.

Looking at the docs i found some key event flags that might be relevant that i didn't know existed. In particular an "event cancelled" flag. It's possible the Titan is trying to tell Forkyz that the hardware delete should be ignored, but that's being misinterpreted. (Flags i've never heard of are often the cause of weird bugs on other devices.)

I've put together another version that hopefully handles cancellation properly, and also logs some more information about the flags. If you have time, could i ask for another log? Thanks.

Wren0 commented 1 year ago

No worries. I'm in the middle of moving, so I've been busy too. I will test and post a log as soon as I can.