Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get resolution change event in swift?

Tags:

macos

swift

cocoa

I try to make an app, and now i shoud make some changes when screen resolution will change, but i coudn't find how to intercept this event.

Do you have any ideea how can i take that event?

like image 285
C-Viorel Avatar asked Dec 19 '22 03:12

C-Viorel


1 Answers

The NSApplicationDidChangeScreenParametersNotification is posted when the configuration of the displays attached to the computer is changed, so you can register for that notification, e.g. with

NSNotificationCenter.defaultCenter().addObserverForName(NSApplicationDidChangeScreenParametersNotification,
    object: NSApplication.sharedApplication(),
    queue: NSOperationQueue.mainQueue()) {
        notification -> Void in
        println("screen parameters changed")
}

Note that there can be various reasons why this notification is fired, e.g. a change in the dock size (as observed in Cocoa Dock fires NSApplicationDidChangeScreenParametersNotification), so you have to "remember" the old resolution and compare it with the new resolution.

like image 198
Martin R Avatar answered Jan 19 '23 10:01

Martin R