Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make OSX application respond to first mouse click when not focused

Normal OSX applications eat the first mouse click when not focused to first focus the application. Then future clicks are processed by the application. iTunes play/pause button and Finder behave differently, the first click is acted on even when not focused. I am looking for a way to force an existing application (Remote Desktop Connection.app) to act on the first click and not just focus.

like image 537
user21737 Avatar asked Sep 24 '08 15:09

user21737


2 Answers

Check NSView's acceptsFirstMouse, it may be what you're looking for.

acceptsFirstMouse: Overridden by subclasses to return YES if the receiver should be sent a mouseDown: message for an initial mouse-down event, NO if not.

  • (BOOL)acceptsFirstMouse:(NSEvent *)theEvent

Parameters theEvent The initial mouse-down event, which must be over the receiver in its window.

Discussion The receiver can either return a value unconditionally or use the location of theEvent to determine whether or not it wants the event. The default implementation ignores theEvent and returns NO.

Override this method in a subclass to allow instances to respond to click-through. This allows the user to click on a view in an inactive window, activating the view with one click, instead of clicking first to make the window active and then clicking the view. Most view objects refuse a click-through attempt, so the event simply activates the window. Many control objects, however, such as instances of NSButton and NSSlider, do accept them, so the user can immediately manipulate the control without having to release the mouse button.

like image 93
Casey Fleser Avatar answered Sep 19 '22 13:09

Casey Fleser


Responding to the first mouse click when not focused is called 'click through'. And its worth is debated heatedly, for instance here and here.

like image 31
Hans Sjunnesson Avatar answered Sep 17 '22 13:09

Hans Sjunnesson