rocksdanister / lively

Free and open-source software that allows users to set animated desktop wallpapers and screensavers powered by WinUI 3.
https://rocksdanister.com/lively
GNU General Public License v3.0
14.97k stars 1.06k forks source link

Inconsistent Window Focus when using Godot as Wallpaper #666

Open PhantomARC opened 3 years ago

PhantomARC commented 3 years ago

Describe the bug Window focus isn't captured when loading Godot applications.

To Reproduce Steps to reproduce the behavior:

  1. Open up Lively Wallpaper
  2. Select a Godot application (which contains mouse tracking)
  3. See that the object in question is not reacting/moving to cursor.

Expected behavior I expected the mouse position to update (as well as the window to come into focus) when I clicked on the desktop, which would allow the object to move to my cursor.

Screenshots/Video

https://user-images.githubusercontent.com/51982416/128814570-f6c4d95e-f5a2-4764-b2b6-67571dcd7c5a.mp4

Desktop:

Additional context I believe what's happening is that Lively is unable to grab focus of the project, which prevents my wallpaper (Godot app) from being able to collect mouse position data. Not sure if this is a Godot-side problem, and the error occasionally disappears after reloading Lively Wallpapers a couple times. However, most of the time, the issue persists and I can't grab focus of the application.

Log file 20210809_222442.txt

PhantomARC commented 3 years ago

Strange bugfix solution As I've just discovered, if I start up Lively and drag a tab around while it boots, I can then grab focus of my background Godot application.

I'm not sure what causes this to happen, as my default settings on Godot don't try to enter full screen and are resizeable.

https://user-images.githubusercontent.com/51982416/128816250-f854c1f3-5d01-4e3d-b553-5cc901426edb.mp4

Edit: Holding any non-maximized tab while starting Lively will allow it to capture the Godot wallpaper's focus. However, switching wallpapers won't...

rocksdanister commented 3 years ago

Desktop does not forward input to child windows, so I am manually doing it from my end (along with other calculation like span, per-screen): https://github.com/rocksdanister/lively/blob/cbc35c570ed39ba1d33b487fdfd3c98c1d8ed7bb/src/livelywpf/livelywpf/Core/InputForwarding/RawInputDX.xaml.cs#L280-L285

Its a bit hacky since I am simulating input to non-focused window; works reliably for unity, web and most application wallpapers. Godot I have only tested games with keyboard support so this issue might be mouse only, can you test keyboard also to verify?

I don't have much experience working with Godot project... if you share your mouse sample project I can also take a look.

PhantomARC commented 3 years ago

Lively Wallpaper's keyboard support for Godot works great; with/without the bug, keyboard inputs are registered.

As for sharing, I'm quite new to GitHub, so please forgive me if I'm doing this wrong. I've shared my Godot project as both the source code and a release here: https://github.com/PhantomARC/godot-lively-focustest

Hope this helps! Edit, One thing I should note: Click events on objects are registered (likely because the click grabs focus for just an instant). The only issues are mouse movement and passing through objects which can't be detected by the focusing bug.

rocksdanister commented 3 years ago

So I tried.. it looks like godot apps need focus for mouse movement unless I am missing some editor settings. One alternative would be to make mouse hooks on the godot project side.

Unity does not have this issue.

PhantomARC commented 3 years ago

Thanks for the information. I do happen to have a couple more questions/suggestions revolving around this issue.

Would it be possible to enable window focusing as a toggleable option in settings?

Also, I was wondering if this bug could be solved through this method I found, but "automated"...

Holding any non-maximized tab while starting Lively will allow it to capture the Godot wallpaper's focus. However, switching wallpapers won't...

It appears to me that something happens when I hold a tab while starting up Lively Wallpapers which allows Godot to grab window focus and work properly, but I'm not sure what that exact method is. If possible, could that "method" be a toggleable function to grab focus for programs which require it (e.g. Godot)?

Here's another log report file, if it helps. I didn't see any errors, but changing applications to the focusTest program didn't work (as usual). 20210812_201313.txt

Many thanks for looking into this!

Edit: I spoke with a Godot developer about this issue, and he noted that any mouse events from Godot API are only usable while the window is focused. Since click events work (it's just mouse movement that doesn't), I'm guessing that clicking grabs event focus for just a fraction of a second, then releases focus (possibly to remove echo events?)...

rocksdanister commented 3 years ago

One alternative would be to make mouse hooks on the godot project side.

This is a guaranteed soln, by mouse hook I mean global mousehook: https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-setwindowshookexa?redirectedfrom=MSDN

I will try lookin for other alternatives including the focusing tricks, speaking of which:

Holding any non-maximized tab while starting Lively will allow it to capture the Godot wallpaper's focus. However, switching wallpapers won't...

I didn't quite get this, what's "tab"? can you show a video of this method?

PhantomARC commented 3 years ago

Sorry, I meant to say title bar. In the video above ( regarding the "Strange bugfix solution", video in the 2nd comment), I held down on an application title bar and dragged it around on screen until the Godot application finished loading. Afterwards, I clicked on the desktop and the Godot program became fully functional. image_2021-08-12_221338