Multiple displays and focus/first responder problems

I just experienced a problem in my app where I could not completely make it the key window and process first responder status. I first noticed there was a problem because I click on my app's notification icon and the app did not activate. If I manually switched to it, it acted like it as an inactive window and I could not activate it. There was one window that I couldn't activate at all. This is somehow related to multiple displays. When I plugged in my external display, I was able to get it working. I have seen this same problem before in other apps. Messages in particular was doing this for a long time. But after connecting and disconnect my external display, Messages is working now too.


Does anyone know the cause of this problem and how to fix it? Thanks.