PojavLauncher icon indicating copy to clipboard operation
PojavLauncher copied to clipboard

[BUG] Pause on Lost Focus setting is ignored

Open ItsJustSomeDude opened this issue 1 year ago • 3 comments
trafficstars

Describe the bug

The vanilla "pause on lost focus" setting is ignored when the app is backgrounded. This means things like AFK farms that require a button to be held down (such as Tree farms or AFK Fish farms, or walking while AFK) cannot be done in the background. A key can be held in the background either with a toggleable button, or with the F3+T trick. However, the actions stop as soon as the activity is in the background.

The log file and images/videos

latest.log

Steps To Reproduce

1. Launch a 1.21.1 instance
2. Enter a singleplayer world
3. Disable Pause on Lost Focus (F3+P)
4. Background the app (without pausing or opening your inventory)
5. Return to the app, see that it is now paused.
6. You can also place down, say, a Noteblock and Button, toggle Right-click, and hear that the dinging stops in the background.

Expected Behavior

The app should be able to enter the background without an Escape key event being sent to the game.

Platform

- Device model: moto G(7)
- CPU architecture: arm64
- Android version: 13
- PojavLauncher version: foxglove-20240922-a6a6a29-v3_openjdk

Anything else?

No response

ItsJustSomeDude avatar Oct 24 '24 17:10 ItsJustSomeDude

not all versions of the game pause on focus loss, so it is simply easier to send the escape event so that it works uniformly across everything that pojav can run

and i dont feel like making a button to turn that off yet

artdeell avatar Oct 24 '24 17:10 artdeell

Apologies for immediately adding a comment.

It seems the Escape key is being sent during onPause() lifecycle hook right here: https://github.com/PojavLauncherTeam/PojavLauncher/blob/v3_openjdk/app_pojavlauncher%2Fsrc%2Fmain%2Fjava%2Fnet%2Fkdt%2Fpojavlaunch%2FMainActivity.java#L271

It seems to me that instead of sending ESC, the game window can simply be informed that it is in the background (like it looks like is being done onStop several lines below that), and will thus let Pause on Lost Focus pause the game, if the user hasn't disabled that.

I'll try building a version with this line removed to see if there are any unforseen consequences. (Perhaps a "cursor release" has to be sent instead?) If everything still works I'll be happy to PR this!

ItsJustSomeDude avatar Oct 24 '24 17:10 ItsJustSomeDude

The problem is that (iirc) older versions dont care about window focus, which is why this was initially implemented as an esc keypress.

artdeell avatar Oct 24 '24 18:10 artdeell