Re: Screensaver can capture mouse events under Catalina
Re: Screensaver can capture mouse events under Catalina
- Subject: Re: Screensaver can capture mouse events under Catalina
- From: Michael Diehr via Cocoa-dev <email@hidden>
- Date: Mon, 25 May 2020 08:09:08 -0700
Great question - I'm the author of iScreensaver. Although our editor app is
primarily built using Xojo, the actual .saver file is now a proper Swift .saver
file built using Xcode, which internally runs a JavaScript/HTML rendering
engine in a WKWebView. I mention this detail in case it's important (e.g.
does having a WKWebView matter?)
My experience has been that Catalina tried really hard to break many features
of screensavers.
In any case, here's the code we use for capturing mouse events. Basically you
set up a global handler, and then have to figure out how to route the event
back to the correct screen (on a multi monitor system) and view...
if isCatalinaOrHigher && mainScreen {
func mouseEventMonitor (event:NSEvent) -> NSEvent? {
log("##### [\(screenNumber)] mouseDownEventMonitor
event=\(event.description)")
// this is a global handler for the App - so the event may
be from any screen.
// figure out which screen this is and route it
appropriately
for i in 0..<parentSaverView.count {
let w = parentSaverView[i]?.window
let m = parentSaverView[i]?.mView
if event.window == w {
switch event.type {
case .leftMouseDown:
m?.doMouseDown(event: event)
return nil // CatalinaFix: important to return
nil here, otherwise saver exits on 1st or 2nd click
case .leftMouseUp:
m?.doMouseUp(event: event)
return event
case .leftMouseDragged:
m?.doMouseDragged(event: event)
return event
default:
return event
}
}
}
logWarning("##### [\(screenNumber)] mouseDownEventMonitor
event did not belong to any window. event=\(event.description)")
return event
}
log("##### [\(screenNumber)] NSEvent.addLocalMonitorForEvents
.leftMouseDown .leftMouseUp .leftMouseDragged")
mEventMonitor = NSEvent.addLocalMonitorForEvents(matching:
[.leftMouseDown, .leftMouseUp, .leftMouseDragged], handler:mouseEventMonitor)
Also, I'm adding a NSTrackingArea (but not when the screensaver is in preview
mode). I think this is critical to making it work, but can't say for certain.
if (!previewMode) {
log ("### screen=[\(screenNumber)] addTrackingArea " +
String(reflecting:bounds))
trackingArea = NSTrackingArea(rect:bounds,
options:[NSTrackingArea.Options.activeAlways,
NSTrackingArea.Options.mouseEnteredAndExited,
NSTrackingArea.Options.mouseMoved], owner:self)
self.addTrackingArea(trackingArea!)
}
> On May 25, 2020, at 6:17 AM, Gabriel Zachmann via Cocoa-dev
> <email@hidden> wrote:
>
>>>
>>> https://iscreensaver.com
>>>
>>
>> Looks like a macOS application with screen saver functionality. You could
>> download it and try it
>
> It's a "screensaver builder":
> you add a bunch of picture, "build" a screensaver, and that sits then in your
> System Preferences' Desktop & Screensavers pane.
> And it runs as a screensaver (well, actually, it gets run by macOS saver
> engine).
>
>> there other pieces installed. Open up the app package and see what is
>> inside. That might give
>
> It contains lots of frameworks (dylibs), most of which look like they're
> copied from the macOS.
> And two apps.
> Nothing else of interest, AFAICS.
> No source code available.
>
> After you build the screensaver, there is an actual plugin in
> ~/Library/Screen Savers,
> which is just a regular screen saver.
>
> When the saver runs and you move the mouse, you get an overlay , just like
> with the video player, with icons like "forward", "pause"; you can click the
> icons (e.g., pause the slide show).
>
> So I am wondering very much how they do that.
>
>
> Best regards, Gabriel
>
>
> _______________________________________________
>
> 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
_______________________________________________
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