6

Aggressively Hiding the Cursor

 2 years ago
source link: https://soffes.blog/aggressively-hiding-the-cursor
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Aggressively Hiding the Cursor — Hi, I’m Sam

Aggressively Hiding the Cursor — Hi, I’m Sam

Hi, I’m Sam

This is my blog. I also have a website thing.

Aggressively Hiding the Cursor

Posted on July 5, 2017

I’m working on a Mac app that has a color picker in it. Here’s a screenshot:

Loupe

For this to work, I hide the cursor and have a custom view track your mouse movements. (When I say cursor I mean the pointer on screen you control with your mouse, and when I say mouse I mean your physical input device.) I use a full screen, borderless window and NSTrackingArea to do this. Nothing too crazy there. I do this to avoid dealing with custom a NSCursor since that was a lot more work.

When I show this fullscreen window, I simply call NSCursor.hide() and call NSCursor.unhide() when the window gets dismissed or loses focus. Easy enough.

Here’s the catch. If you violently move your mouse the cursor would come back. This took me awhile to figure out. If the system makes your cursor giant then it comes back. You never actually see it get giant though. This kinda seems like a bug. I know using NSCursor hide and unhide isn’t super reliable unless you control everything. I though having a full screen window was enough control. Oh well.

There was a simple solution though:

override func mouseMoved(with event: NSEvent) {
    // Whatever work I would normally do here

    // Workaround macOS making the cursor huge and unhiding it when you wiggle it violently
    NSCursor.hide()
}

Easy enough. Maybe I should use a custom cursor instead of this craziness?

Automating Simple Things

Posted on June 29, 2017

Most of my projects contain a Rakefile with some common tasks. rake is Ruby’s tool for running tasks. It’s my tool of choice for little scripts, but you could of course do whatever you want. My friend Ayaka even did a talk on scripting with Swift!

Usually my scripts are for something tedious that can be easily automated. Here’s a few examples in my own projects:

Some of the most elaborate scripts I’ve written in projects have been to automate gathering dependencies. This can be complicated depending on your setup. My goal is always for someone that isn’t a developer to clone, run the command, open Xcode, and build. That may seem like overkill, but if you make it that easy, you make it that easy for yourself and teammates which saves a ton of time.

Continue reading →

© 2006-2022 Sam Soffes


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK