garbear / xbmc

XBMC Main Repository
http://xbmc.org
Other
132 stars 53 forks source link

[Enhancement] xbmc.joystickSuspend() #105

Closed zach-morris closed 4 years ago

zach-morris commented 5 years ago

Title says most of it. Similar to Kodi's python module functions xbmc.audioSuspend() and xbmc. audioResume()

Rationale: I can think of a lot of reasons an addon would want to temporarily suspend joystick input (or prevent it all together), but one of the main reasons is to avoid input to Kodi when it's not in focus on the screen (i.e user temporarily brings another application in focus and uses the joystick)

Bonus points if the function can specify by controller type

garbear commented 5 years ago

Interesting idea. Already Kodi should ignore input when it's not in focus. Kodi doesn't know the controller type, only the name of the controller according to the driver.

zach-morris commented 5 years ago

Thats good to know it should. There have been issues, specifically with Linux, where users state that is not the case. I haven't looked at it in a while, maybe those issues have been resolved.

garbear commented 5 years ago

With so many platforms and windowing libraries, I'm not surprised there's some errors. I'm not against this feature but expanding API surface area isn't a scalable strategy for handling bugs. Any other use cases for this?

zach-morris commented 5 years ago

If it's not as easy as adding an if statement into your codebase, then probably not worth the effort. I just happened to close the issue page for IARL, but here's some background on the focus issue.

garbear commented 5 years ago

Is this still wanted? Adding the feature would be relatively nonintrusive if it's worth the added complexity.

zach-morris commented 5 years ago

I'd probably poll people in the forums or other, to see if this is really a common issue, or if it's just the fringe setups. I personally am not able to recreate the issue Maybe @Wintermute0110 or @maloep have more experience with it

Wintermute0110 commented 5 years ago

@zach-morris Thanks for including me on this.

Yeah, having the ability to suspend/resume the joystick subsystem in Kodi would be very useful to launch external apps. For some reason, some users (particularly Windows users) report that Kodi gets the input from the joystick even when the launched app is on top and focused. I guess the cause may be some buggy joystick driver. Unfortunately I don't know if this problem happens for a specific brand/model of joysticks or for a particular version of Windows. For some reason many users do not provide much information when reporting problems.

I tried to implemented an option in AEL/AML so users can disable Kodi from using the joystick but for some reason in Krypton the setting input.enablejoystick was not available any more. Ideally, I would like to see a couple of functions like xbmc.joystickSuspend() and xbmc.joystickResume().

I have some documentation of these problems in AEL source. There you can find some links to the forum to post reporting the issue. I will not say it's a common issue but neither unheard off.

zach-morris commented 5 years ago

Just some additional documentation - I think it depends on the users setup, but there seem to be instances where focus does not ignore control: https://www.reddit.com/r/kodi/comments/ajkiil/anyone_know_how_to_disable_the_xbox_controller/

zach-morris commented 4 years ago

More info, seems the issue is potentially caused by setups without a window manager.

garbear commented 4 years ago

If there's no window manager, then input won't be suspended. Is there another form of global state that can be monitored, instead of introducing a new state in the API?

zach-morris commented 4 years ago

My google-fu didn't find anything. Previously the attempt on the addon side was to disable by toggling the setting input.enablejoystick, but that crashes Kodi. Since the method is already present, that may be the quickest/easiest way to create a workaround (again, if this isn't simple, then it can be listed as a limitation for windowless users - they can use shell scripts to workaround the issue).

garbear commented 4 years ago

If we have a setting named input.enablejoystick, then we already have an API to enable/disable joysticks. Looks to me like the solution is to fix the crash. I'm hunkered down this weekend so I'll take a look at it.

garbear commented 4 years ago

So, it doesn't actually crash because input.enablejoystick was removed in v17 :) It was effectively replaced by the command to enable/disable peripheral.joystick. I've re-introduced the input.enablejoystick setting in https://github.com/xbmc/xbmc/pull/17529.

In v17 and v18, a workaround could be to enable/disable the peripheral.joystick add-on.

zach-morris commented 4 years ago

OK, thanks. I'll give that try

garbear commented 4 years ago

I uploaded test builds here: https://github.com/garbear/xbmc/releases/tag/retroplayer-18.6-20200320

If a game is fullscreen, it may ignore input.enablejoystick still receive input. Should this be fixed too?

garbear commented 4 years ago

Anything to report on this? I noticed that the setting only affects the GUI, not gameplay, so I'll update the PR to disable joysticks when a fullscreen game is open too.

garbear commented 4 years ago

I fixed the setting only working in GUI, now it works in gameplay too. Test builds uploaded to: https://github.com/garbear/xbmc/releases/tag/retroplayer-18.6-20200516

garbear commented 4 years ago

I merged https://github.com/xbmc/xbmc/pull/17529, which automatically closed this PR. Please re-open or comment if desired.