Tap vs click on mac trackpad - objective-c

Is there any way to tell whether a pair of mouse up / down events were triggered by a tap on the trackpad, versus a trackpad depression resulting in a click?
Essentially, I'd like to replicate the behavior you see in toggle check boxes throughout macOS. They have four states:
Toggled off: no check
Toggled on: check mark
Activated off: no check / grey background
Activated on: check mark / grey background
If a tap is recognized on a checkbox, it'll go from 1 -> 2 or 2 -> 1 after a brief delay (~0.5s) without showing the grey background at all. However if you physically click the trackpad, you'll go from 1 -> 3 immediately on mouse-down, and then from 3 -> 2 if the mouse-up comes on the checkbox (otherwise it goes back to 1).
It seems that to replicate this behavior one needs to differentiate between a tap-like mouse-down and a click-like mouse down. As far as I can tell there is no way to do this by inspecting NSEvent in NSView.mouseDown.

Answering this myself: override pressureChange. This method fires on (and during) a physical trackpad click but not a tap-to-click. Anyway this question was also asked here: How to judge NSEvent from trackpad click, not tap to click.

Related

How to create a NSWindow like iTunes mini player (always on top but get no focus!)

I have a borderless window with a webview in it, which is always on top.
I want to create a NSWindow which is:
Always on top
Does not take the focus from the current foreground app
Does enable user mouse interaction (without forcing the user to switch focus to it - aka "click on it twice")
The problem I have atm is that to interact with the window (e.g. see hover effect, or click a link in the webview), the user has to click the window (which gives it focus) and only then the hover effect shows.
How can I make a window like iTunes mini player which doesn't take the focus from the current app - but also interacts with mouse? (see screenshots below)
Thanks!!
To receive mouseEntered:, mouseMoved: and mouseExited: events even when your app is not active, you must add a tracking area to some view in your window and set the tracking area's properties accordingly.
Take a look at NSTrackingArea.
You'll probably want to add a tracking area with the options NSTrackingActiveAlways and NSTrackingMouseEnteredAndExited.

Temporarily disable hot-corners and dock screen switching

I have a full screen borderless NSWindow that requires the user to move their mouse to the edges and the corners of the screen often. Unfortunately these movements can trigger the hot-corner actions as well as switching the dock to another screen.
Is there any way to temporarily disable this behaviour while the window is being shown?
It seems like the answer is 'not really' except if you capture all mouse events for the entire screen.
For a complete answer and possible solution, I leave you to Ken answer here : Disable (or filter) Hot Corners

Sending actions from a UIScrollView

I have a UIScrollView with 10 buttons, each button has its own method. My goal is to activate each button when the user scrolls and the UIButton is "entering" a specific area. What's a good way to accomplish that? (I don't want the UIButton to be pushed. Just hovering on it should activate it)
Example:
button 1
button 2
ooooooo
button 3 <--activated
ooooooo
button 4
Right now button 3 is activated. If the user will scroll down a bit button 2 will be activated.
I'm assuming by activated you mean uicontrolstate of the button being enabled or not. The most straight forward way I can think to do this is by doing something similar to BloonsTowerDefence and look at the uiscrollviews contentoffset and at various ranges you will examine the contentoffset and disable all the rest of the buttons and enable the button you would like to be enabled at that range.

UIButton events. What's the difference?

I've encountered a problem where my button should remain "pressed down" while it shows popover called from it. Popover is selector for some filter and filter is shown on button itself. When I tap on it and it shows popover it becomes deselected no matter what.
I think I have to redefine it's behavior on touch event and make it respond not to standart touch up inside. Then I wondered what are other events responsible for? But I couldn't find events list in iOS library and in StackOverflow are only questions about incorrect behavior of touch up inside or touch down.
So what's the difference betweeen touch events?
touch cancel - when you touch button but move your finger away and
it remains deselected?
touch down - right on tap.
touch down repeat ??
touch drag enter ??
touch drag exit ??
touch drag inside ??
touch drag outside ??
touch up inside - when you tap and release button remaining in it's
bounds . It changes UIButtons state to Normal.
touch up outside - when you tap and release button leaving it's
bounds ?
other IBActions are not sent by UIButton, right?
Also how those events change UIButton's appearance? Like highlighted or selected?
I'd appreciate a link on good article about IBActions, because I couldn't find it.
From Apple's doc for UIControlEvents:
UIControlEventTouchCancel
A system event canceling the current touches for the control.
UIControlEventTouchDown
A touch-down event in the control.
UIControlEventTouchDownRepeat
A repeated touch-down event in the control; for this event the value of the UITouch tapCount method is greater than one.
UIControlEventTouchDragEnter
An event where a finger is dragged into the bounds of the control.
UIControlEventTouchDragExit
An event where a finger is dragged from within a control to outside its bounds.
UIControlEventTouchDragInside
An event where a finger is dragged inside the bounds of the control.
UIControlEventTouchDragOutside
An event where a finger is dragged just outside the bounds of the control.
UIControlEventTouchUpInside
A touch-up event in the control where the finger is inside the bounds of the control.
UIControlEventTouchUpOutside
A touch-up event in the control where the finger is outside the bounds of the control.
Listed in, what I would consider, order of common use/likelihood of occurrence for a normal button:
UIControlEventTouchDown: The user tapped the button. This fires on the finger/stylus making contact.
UIControlEventTouchUpInside: The user tapped the button. This fires on the finger/stylus contact pulled back away from the screen.
Useful for sliders and drag events like moving a component around. The below are in order of occurrence:
UIControlEventTouchDragInside: Triggered as the finger drags into the button area.
UIControlEventTouchDragExit: Triggered during a drag motion. It is called only once, as the users finger/stylus leaves the bounds of the button.
UIControlEventTouchDragOutside: Triggered during a drag motion, after 'UIControlEventTouchDragExit', and is called continuously, as long as the original touch continues.
UIControlEventTouchUpOutside: This is simply the finger/stylus being lifted BUT only if the finger/stylus is no longer within the bounds of the button. The important thing (and probably obviously) to call out is that the touch had to have been within the button at some point to associate this event with the button.
Note: My understanding is that the above can be helpful for:
Sliders: as you might expect the touch may have been intentional but because of the quick swipe action, their finger movement may be sloppy and lift up outside of the slider area.
Moving components around, as when you push things around a screen you want the movement to happen when the finger/stylus touches the border of the component/object.
Other events:
UIControlEventTouchCancel: Something out of the user's control is cancelling their touch action. Think of this as something "going wrong" on the phone side of things.
UIControlEventTouchDownRepeat: Want to detect when your user is mad and tapping a button furiously? Want to detect if they're still in Windows mode and are trying to "double click"? Or maybe you designed a button to do something different if they tap twice. This event helps with all of those!
References:
SO 1: Dif between UIControlEventTouchDragOutside and UIControlEventTouchDragExit
SO 2: What is UIControlEventTouchCancel?

cocoa mousedown on a window and mouse up in another

I am developping a Cocoa application and I have a special need. In my main window, when I mouse down on a certain area, a new window (like a complex tooltip) appears. I want to be able to do:
- mouse down on the main window (mouse button stay pressed)
- user moves the mouse on the "tooltip" window and mouseup on it.
My issue is that the tooltip window does nto get any mousevent until the mouseup.
How can I fix this?
Thanks in advance for your help,
Regards,
And it won't since mouse is tracked by the main window. However, you can process mouseUp in the main window, transform click coordinates into the desktop space, get tooltip window frame and check whether the click occurred on the tooltip. After that, you can send a message to the tooltip window manually.
Or you can try to find another way to implement the final goal :) It is usually better to follow the rules, in this case - mouse tracking.