JohnCoates / Aerial

Apple TV Aerial Screensaver for Mac
MIT License
20.77k stars 1.05k forks source link

Since 1.4.8+ keyboard input no longer stops the screensaver #768

Closed luckman212 closed 5 years ago

luckman212 commented 5 years ago

Description of issue

Since ver 1.4.8 or so (maybe 1.4.9?) when I tap the keyboard to end the screensaver and get to the lockscreen, the mac just plays a beep/alert sound, but the video keeps playing. Only moving the mouse causes the video to stop playing.

I'm now on 1.4.10beta2 but the issue remains. I've been using Aerial for years, since 1.1 and never had this issue before.

Can't really think of anything that would cause this, but browsing through recent commits, https://github.com/JohnCoates/Aerial/commit/7786dc683bd3f2a5a7827a3c8e46400781ad2251 seems like the only thing even close to being related.

I've just enabled debug logging, so next time this happens I'll be sure to post a log.

glouel commented 5 years ago

Hi @luckman212

Does no key work, not even the space bar ? Can you try unchecking the "Right arrow skips video" option in main panel to see if it helps ? Thanks

luckman212 commented 5 years ago

Correct - when this bug occurs, no keys work. I have unchecked the "Allow Right arrow key to skip" box for now and will report back if that makes any difference.

luckman212 commented 5 years ago

Ok, so this just happened again, even with the Allow skip option enabled. I'm attaching the debug log here. I noticed this time that the "CTRL" key (that's how I usually wake up the display) has no effect, and does not cause the error/beep sound to play. However other standard keys such as spacebar, any letter keys, arrow keys etc do cause a beep sound. Moving the mouse also had no effect - the only way to stop the video playback and get back to the lockscreen was to CLICK the mouse.

DebugLog: AerialLog.txt

Screenshot of my main settings screen

glouel commented 5 years ago

Ok thanks for the report, I'll have a look and let you know. Can you tell me which keyboard you have on your mac mini ? Are you by any chance using multiple keyboards (even if not at the same time ?) ?

luckman212 commented 5 years ago

Currently I'm using a Logitech G413 keyboard. I don't have multiple keyboards but I do have Karabiner-Elements installed, to disable the CapsLock key.

glouel commented 5 years ago

So according to your log, Aerial doesn't receive the keydown events (there should be a "keyDown" somewhere), which is consistant with you hearing beeps when pressing non modifier keys (just like typing when you don't have focus). Karabiner-Elements probably intercepts events and that throws the logic.

I may have missed an event forwarding, trying some stuff and will get back to you.

luckman212 commented 5 years ago

Thank you - anything else I can do to help debug just let me know

glouel commented 5 years ago

Well, I just put up beta3 if you can give it a shot, there's a tentative fix for both your issues, although I'm very unsure about this one to be honest ! Let me know how it goes and we'll try to figure out what's next.

luckman212 commented 5 years ago

Great, happy to test - I will give this a go and report back

luckman212 commented 5 years ago

Just reporting in. Been running beta3 for a few days now and it hasn't fixed this for me (sadly). I also removed Karabiner-Elements temporarily for testing (did not help). I don't know what else to do to debug. Sometimes the keyboard works to bring up the login prompt and sometimes it doesn't. Mouse clicks always work!

I think this is related to the /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow process having focus and thus eating keypresses. The reason I suspect this is: I've noticed that sometimes when the screen unlocks, the frontmost app does not have focus even though it appears from the menu bar that it should.

E.g. when I walk away, the frontmost app was Sublime Text and I was in the middle of editing a file. When I come back and unlock, even though Sublime is still the frontmost app, all keypresses result in a beep sound until I click the mouse in the Sublime window—this mimics the original bug I am seeing from within Aerial / ScreenSaverEngine sometimes. I can tell that this is happening because Karabiner includes a helpful app called EventViewer that displays the frontmost app in a floating window (see screenshot below).

image

In case it's at all helpful, I'm attaching a fresh log here. AerialLog.txt

glouel commented 5 years ago

I was going to suggest maybe disabling Karabiner-elements, as I strongly suspected it could be linked to your issue. You mentioned removing it, though (fully ? it runs a kext I think right ?).

There may be something else specific to your setup that's causing this (I can't reproduce and nobody else complained about it yet so there's probably something pretty specific). The fact that you also have the issue with Sublime not getting focus back certainly isn't right either. Here I systematically get focus back on the previous window when coming out of screensaver. Are you using some third party login addon maybe ? Do you have some sort of extra "keyboard driver" installed ? I'll try to grab that EventViewer to give it a shot here and see what I get.

In general, we don't control much as a screensaver, we are just a plugin for ScreenSaverEngine and don't control our lifecycle. Our view gets initialized by ScreenSaverEngine, and ScreenSaverEngine kills us when he wants to.

I do see many keyDown events that we intercept now (since 1.4.8) in your log, can you confirm that you kept enabled the right arrow key thing ? Our interception seems to work since the right arrow thing works for you, but it looks like when we forward the key event now (after intercepting), on your machine it goes to loginwindow and not ScreenSaverEngine.

By not intercepting in previous versions, it looks like you didn't have the issue. A quick fix would have been to conditionally override the keyDown event but that's not possible.

I'll keep investigating this, and try to see what EventViewer says here and report back to you. May I suggest you give a shot to ElectricSheep ? It also overrides the right arrow key (I haven't looked at their source code though to see how they do it) so maybe you'll get to see if you have the same issue or not ? Could be a good data point.

https://electricsheep.org/mac/

luckman212 commented 5 years ago

Sure I will give ElectricSheep a try and see if the results are the same, and if they are I will work backwards on any 3rd party things that might be conflicting. I did remove Karabiner but then re-installed it after I continued having the issue. So I will try some more thorough testing.

luckman212 commented 5 years ago

Ok, I believe I've uncovered more info!

Please verify yourself if you have time, by saving this script and running it from a Terminal: https://gist.github.com/luckman212/91cdd9a08e98a9f01214bdfde3057e85

Then enable the screen lock preference and activate your screensaver. See if when you exit, you have output similar to the below (and any keypresses result in beep sounds...) image

glouel commented 5 years ago

Hi @luckman212

Ok, I believe I've uncovered more info!

  • I tried ElectricSheep as well as some other screensavers and observed that they triggered this bug too. So, good news - it does NOT seem to be an Aerial bug at all 🎉

Good news in a sense indeed, although I hope we can fix your issue.

  • I completely uninstalled Karabiner-Elements, rebooted, double checked that the kext was not present via kextstat | grep -v com.apple, and then re-tested. The problem was still present - so does not seem to be related to KbE either

Ok good to clear that one up too!

  • I do think I've traced the source of this problem to the "screen lock" feature in System Preferences > Security & Privacy. I had mine enabled/set like this (which is not the default): image
  • As a test, I created a brand new user account, downloaded Aerial 1.4.10b3 and tested on that (no modifications whatsoever) and was UNABLE to reproduce the issue
  • I then enabled the auto-lock feature (no other changes made) and re-tested. I was then able to reproduce the bug. So it seems very likely to be related
  • When the screensaver exits and the auto-lock feature is enabled (at least on my system) - the active aka focused app will be NULL (it actually wasn't loginwindow as I previously thought—it's just that KbE's EventViewer app doesn't seem to report NULL values, whereas the Python script below does).

Please verify yourself if you have time, by saving this script and running it from a Terminal: https://gist.github.com/luckman212/91cdd9a08e98a9f01214bdfde3057e85

Then enable the screen lock preference and activate your screensaver. See if when you exit, you have output similar to the below (and any keypresses result in beep sounds...) image

First, thanks for digging into this so deeply, hopefully we can get to the bottom of this.

Soooooo...

FYI I had it at 5 minutes here (probably default ?) AND I have Apple Watch unlock enabled. So, first with my original setup:

Capture d’écran 2019-05-10 à 12 48 28

No loginwindow.app (makes sense, below 5 mins), no no active app either.

With insta-lock AND Apple Watch unlock:

Capture d’écran 2019-05-10 à 12 48 44

As you can see I also have the no active app thing. And I can confirm that on exiting screensaver, iTerm2 (or any other app) didn't have focus. I switched to another app to be sure in subsequent test and every time, no focus. That's not particularly good and look like a (new?) system bug indeed.

Yet, every single time, as I used space key, the login screen instantly popped and I was relogged (with no keyboard focus, but still relogged). I also did try disabling Apple Watch unlock but same result on 5 tries.

As a side note, I do use Mojave's latest beta 10.14.5 (18F131a) which may (or may not) make a difference. But with that said, I tried on my painfully old 2011 Macbook Air under High Sierra and...

Capture d’écran 2019-05-10 à 13 11 29

iTerm (or whatever) keeps focus, tried a few times, after loginwindow I always get focus back. So the no active app looks like a new Mojave bug, which is definitely worth a radar !

There's a tiny chance that this mayyyyy be a 10.14.4 bug that happens to be fixed in 10.14.5 beta, that could explain why I can't replicate but if so, I'm pretty sure someone else would have complained ? Or maybe it only happens with insta lock which noone else uses ? People make issues about way less usually and that's a pretty major one.

This doesn't clear it all up sadly, sorry. Side question, do you have any logitech software installed by the way ?

luckman212 commented 5 years ago

Thanks for the detailed reply and for taking more time out to test on this! (No I don't have any Logitech software installed).

Glad you were able to reproduce my results, at least the NIL app focus on screensaver exit. I'll file a rdar for that and reference back here.

I'm going to try installing 10.14.5 beta just to see if by chance the original issue is just a 10.14.4 bug.

luckman212 commented 5 years ago

I installed 10.14.5beta5 (18F131a) and re-ran my tests. Interestingly, the VERY FIRST time I invoked Aerial (via hot-corner), upon trying to wake up the screen, I hit the original bug again 😞 (keypresses were just resulting in a "beep" but not causing the login prompt to appear).

So, I clicked the mouse and unlocked the screen. Then, I triggered the screensaver a second time, and this time the keypresses worked fine. I repeated a few more times, and it also worked. So I guess it's back to being inconsistent, or somewhat improved. I'll keep investigating.

Sadly, the "no active app" bug still seems present to me. It is always triggered when the screen is woken up AFTER the "require password after" timer has elapsed.

E.g. if you have it set to 1 minute, and then you trigger the screensaver and wait only 15 seconds, and then wake up the screen, your app will regain focus correctly.

However, if you instead wait e.g. 65 seconds, when you wake up the screen (after unlocking it) you will have the NIL focused app.

glouel commented 5 years ago

@luckman212 hmm, well at least it's a tiny bit better now, it looks like this is really some new Mojave bug then. Hopefully the frequency will be pretty low now. I never managed in maybe 30 tries here. Maybe it now only happens once upon reboot (hoping).

Definitely file a radar for both issues I think !

luckman212 commented 5 years ago

For now I filed bug 50661344 for the issue that leaves NULL focusedapp after resume (since that's the one I can reliably reproduce).

I'll keep testing on the other one to try to get better repro steps.

luckman212 commented 5 years ago

Just FYI- I am now running 1.4.99beta1

glouel commented 5 years ago

Great, let me know if you have any issues with the new multi monitor stuff! Some pretty radical changes I've been working on all week ;)

luckman212 commented 5 years ago

So far no issues! 🙌

The new multi monitor modes are very cool, I really like the "spanned" mode - great effect.

glouel commented 5 years ago

Thanks ! Took me a while to figure out how to properly detect the screens but got it in the end :)

gregarios commented 5 years ago

Here is the problem I was having with the keyboard not switching scenes (with the arrow key) and my screensaver not stopping with any keystrokes, and the solution that fixed both: https://apple.stackexchange.com/questions/332448/how-to-stop-screensaver-with-a-keyboard-button-press-rather-than-a-mouse-button

Subsequent Note: I see how this affects the experience of using the macOS now too, however, and I find it incompatible with my workflow. I guess I will change it back and just deal with not having the arrow skip capability.

Note: Ok upon even further experimentation, I discovered that the arrow and the keyboard screensaver-off both work also if I have the "Displays have separate spaces" turned on or off and the "When switching to an application, switch to a space with open windows for the application" enabled as well.

So, either of these settings will allow it to work correctly under MacOS Mojave: Screen-Shot-2019-05-10-at-9 44 57-PM Screen-Shot-2019-05-10-at-9 45 03-PM

glouel commented 5 years ago

Note: Ok upon even further experimentation, I discovered that the arrow and the keyboard screensaver-off both work also if I have the "Displays have separate spaces" turned on or off and the "When switching to an application, switch to a space with open windows for the application" enabled as well.

So, either of these settings will allow it to work correctly under MacOS Mojave:

@gregarios many many thanks for following up on this ! This is super useful feedback !

luckman212 commented 5 years ago

Just wanted to post an update since I've been banging away at this for a while. Some things I've learned:

  1. This is not an Aerial bug. It affects all screensavers, including the ones shipped with macOS.
  2. The bug lies in macOS, and seems to have started with High Sierra (10.13).
  3. Does not affect all systems, and even on the systems that are affected, it does not occur 100% of the time ScreenSaverEngine is invoked, making it very difficult to troubleshoot.
  4. The bug does not seem to be in /System/Library/CoreServices/ScreenSaverEngine.app itself: I extracted a copy of this app from 10.12 and code-signed it so it would run on 10.14, and tried to invoke it manually—the same bug manifested itself (keypresses are eaten, do not stop the saver).
  5. In this thread on AskDifferent, one user reported that changing these Mission Control settings was a workaround. However, I tested all of the combinations that were supposed to work, and in my case, they did NOT fix the issue. So I reverted back to my preferred settings (Displays have separate spaces: unchecked).

In light of the above, feel free to close this and I'll post back with any updates I receive from Apple via the BugReporter, or if any future macOS releases fix the bug.

glouel commented 5 years ago

hey @luckman212

Thanks a lot for the followup, gregarios posted two combinations that work for him above just in case you want to give this a shot.

I'll be closing this then, pretty sad that it's a macos bug, bit disheartening to see so many little things starting to fail over time :(