mirror of
https://github.com/MonitorControl/MonitorControl.git
synced 2026-05-15 14:15:55 -06:00
Update menu when diplays are added/removed
This commit is contained in:
parent
b072626dad
commit
a6422c017a
1 changed files with 21 additions and 2 deletions
|
|
@ -15,6 +15,8 @@ struct Display {
|
|||
var serial: String
|
||||
}
|
||||
|
||||
var app : AppDelegate! = nil
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
|
|
@ -27,6 +29,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
|
||||
let keycode = UInt16(0x07)
|
||||
|
||||
var monitorItems : [NSMenuItem] = []
|
||||
var displays : [Display] = []
|
||||
|
||||
@IBAction func quitClicked(_ sender: AnyObject) {
|
||||
|
|
@ -70,9 +73,26 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
app = self
|
||||
|
||||
statusItem.title = "♨"
|
||||
statusItem.menu = statusMenu
|
||||
|
||||
acquirePrivileges();
|
||||
|
||||
CGDisplayRegisterReconfigurationCallback({_,_,_ in app.updateDisplays()}, nil)
|
||||
updateDisplays()
|
||||
}
|
||||
|
||||
func updateDisplays() {
|
||||
for m in monitorItems {
|
||||
statusMenu.removeItem(m)
|
||||
}
|
||||
monitorItems = []
|
||||
displays = []
|
||||
|
||||
sleep(1)
|
||||
|
||||
var firstDisplay : Display? = nil
|
||||
|
||||
for s in NSScreen.screens()! {
|
||||
|
|
@ -209,6 +229,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
monitorMenuItem.title = "\(name)";
|
||||
monitorMenuItem.submenu = monitorSubMenu;
|
||||
|
||||
monitorItems.append(monitorMenuItem)
|
||||
statusMenu.insertItem(monitorMenuItem, at: i)
|
||||
|
||||
if firstDisplay == nil {
|
||||
|
|
@ -216,8 +237,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
acquirePrivileges();
|
||||
|
||||
if firstDisplay == nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue