Menu

NSApp.activate raised every window of my Mac app, so scroll capture scrolled the wrong one
📰

NSApp.activate raised every window of my Mac app, so scroll capture scrolled the wrong one

DEV Community: swift·Apps by Mo·3 days ago
#gJ42hFuz
#devtoswift#devto#dev#signup#level
Reading 0:00
15s threshold

I make Scry, a screenshot app for the Mac. One of its tools is scroll capture: you draw a box around part of a page, and Scry scrolls that page and stitches one long image.

For a while it had a bug that looked random. You drew the box over a web page, and Scry scrolled its own Library window instead. Sometimes it scrolled the Settings window. Never the page you asked for.

The cause was one line I had added on purpose.

The line that raised everything

The capture overlay is a borderless, full-screen, transparent window. To take key and receive keystrokes, the app has to be active, so the overlay called:

NSApp . activate ( ignoringOtherApps : true )

Enter fullscreen mode

Exit fullscreen mode

That does make the overlay key. It also orders every ordinary window of the app above every other app. With a transparent overlay covering the whole screen, nobody sees it happen.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.