Skip to content

Commit

Permalink
feat: Update when display reconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
douo committed Jun 26, 2020
1 parent 7c6982b commit 54c0a11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 1 addition & 9 deletions ScreenJumper/ScreenFocusHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ let SFHelper = ScreenFocusHelper()

class ScreenFocusHelper: NSObject {
override init() {
CGDisplayRegisterReconfigurationCallback({ (id, flags, pointer) in
print("wtf:\(id) \(flags)")
if ((flags.rawValue & CGDisplayChangeSummaryFlags.addFlag.rawValue) != 0) {
print("display has been added:\(id)")
}
else if ((flags.rawValue & CGDisplayChangeSummaryFlags.removeFlag.rawValue) != 0) {
print(" display has been removed:\(id)")
}
}, nil)

}
private func screens() -> [NSScreen]{
return NSScreen.screens
Expand Down
10 changes: 10 additions & 0 deletions ScreenJumper/ShortcutHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ class ShortcutRepository: ObservableObject {
let size = ShortcutRepository.restoreSize()
assigns = []
assignSize = size

CGDisplayRegisterReconfigurationCallback({ (id, flags, pointer) in
print("wtf:\(id) \(flags)")
//TODO 只监听显示器增减还不能覆盖所有情况,比如镜像显示器。暂不继续深入
// if ((flags.rawValue & (CGDisplayChangeSummaryFlags.addFlag.rawValue | CGDisplayChangeSummaryFlags.removeFlag.rawValue)) != 0) {
let size = ShortcutRepository.restoreSize()
ShortcutRepository.shared.assigns = []
ShortcutRepository.shared.assignSize = size
// }
}, nil)
}

func register() {
Expand Down

0 comments on commit 54c0a11

Please sign in to comment.