Re: Inactive Window Receives Mouse Events
Re: Inactive Window Receives Mouse Events
- Subject: Re: Inactive Window Receives Mouse Events
- From: Quincey Morris <email@hidden>
- Date: Sat, 11 Sep 2010 00:06:39 -0700
On Sep 10, 2010, at 22:50, Richard Somers wrote:
> I just noticed that when you hold down the command key over an inactive window and click and drag the mouse, the window will receive mouse events. You can move the window, use the tool bar, select text, interact with views, etc. Almost what ever you can do when the window is active with a mouse, you can also do when the window is inactive using the command key and the mouse. (Mac OS 10.5.8) If you have never done this you should try it. It works in Mail, Safari, Pages, etc.
I think you're slightly mis-describing the behavior. What you're seeing is actually (AFAIK) the interaction of 2 separate behaviors. First, any mouse-down event on an inactive window doesn't bring it to the front if the Command key is down too. Second, most standard controls return YES from 'acceptsFirstMouse:', which means that they respond to mouse-down events when their window is not frontmost. Put those 2 things together and you get the behavior you describe.
> The only reference in the documentation to this functionality that I can find is in the Apple Human Interface Guidelines which says "Pressing the Command key while dragging an inactive window moves the window but does not make it active." It mentions nothing about the entire window and all of its contents also receiving mouse events.
IIRC, there's a historical evolution here. Originally (in classic Mac OS), controls typically didn't respond in non-frontmost windows, and I believe the Command-drag-title-bar thing started life as a non-sanctioned behavior made popular by 3rd-party apps. It rapidly became a standard behavior and in Mac OS X the ability to click-through on many controls eventually became standard too, as a kind of evolution of the Command-drag metaphor. Around the same time, (again IIRC) the visual appearance of standard controls was codified to properly distinguish between inactive (non-frontmost but enabled) and disabled controls, a distinction that wasn't clearly maintained in the old days.
If my memory has let me down on the history here, I'm sure others will remember more clearly.
> I have a custom view where this behavior is undesirable. How can I disable this view from receiving mouse events when the window is inactive and the user uses the command key with the mouse?
Are you talking about the view itself, or standard controls (subviews) within your view? I would have expected that returning NO from 'acceptsFirstMouse:' (which is the default for NSView) would have disabled the behavior for the view outside of its subviews. For standard controls that return YES, you can simply disable the control when its window is non-main (including when the application is inactive). It's also possible to subclass the control to return NO from 'acceptsFirstMouse:', but in order to keep the user experience as consistent as possible I wouldn't recommend doing that without a really compelling reason.
Note that the behavior can vary on a case by case basis. In Mail, for example, the "Junk" toolbar button is disabled when inactive, but the "New Message" button is left enabled. The idea seems to be to allow click-through when it's not potentially harmful. (But that's not specifically about the Command key.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden