mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 23:24:32 +00:00
Working Indicators
This commit is contained in:
parent
79eb1311bf
commit
1a45d4e7f4
16 changed files with 629 additions and 17 deletions
44
DynamicIsland/managers/SystemKeyObserver.swift
Normal file
44
DynamicIsland/managers/SystemKeyObserver.swift
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// SystemKeyObserver.swift
|
||||
// DynamicIsland
|
||||
//
|
||||
// Adapted from TheBoringWorker-HUD KeyPressObserver.swift
|
||||
// Created by GitHub Copilot on 06/09/25.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class SystemKeyObserver: NSApplication {
|
||||
static let volumeChanged = Notification.Name("DynamicIsland.volumeChanged")
|
||||
static let brightnessChanged = Notification.Name("DynamicIsland.brightnessChanged")
|
||||
static let keyboardIlluminationChanged = Notification.Name("DynamicIsland.keyboardIlluminationChanged")
|
||||
|
||||
override func sendEvent(_ event: NSEvent) {
|
||||
if event.type == .systemDefined && event.subtype.rawValue == 8 {
|
||||
let keyCode = ((event.data1 & 0xFFFF0000) >> 16)
|
||||
let keyFlags = (event.data1 & 0x0000FFFF)
|
||||
// Get the key state. 0xA is KeyDown, OxB is KeyUp
|
||||
let keyState = ((keyFlags & 0xFF00) >> 8) == 0xA
|
||||
let keyRepeat = keyFlags & 0x1
|
||||
mediaKeyEvent(key: Int32(keyCode), state: keyState, keyRepeat: Bool(truncating: keyRepeat as NSNumber))
|
||||
}
|
||||
|
||||
super.sendEvent(event)
|
||||
}
|
||||
|
||||
func mediaKeyEvent(key: Int32, state: Bool, keyRepeat: Bool) {
|
||||
// Only send events on KeyDown. Without this check, these events will happen twice
|
||||
if state {
|
||||
switch key {
|
||||
case NX_KEYTYPE_SOUND_DOWN, NX_KEYTYPE_SOUND_UP, NX_KEYTYPE_MUTE:
|
||||
NotificationCenter.default.post(name: SystemKeyObserver.volumeChanged, object: self)
|
||||
case NX_KEYTYPE_BRIGHTNESS_UP, NX_KEYTYPE_BRIGHTNESS_DOWN:
|
||||
NotificationCenter.default.post(name: SystemKeyObserver.brightnessChanged, object: self)
|
||||
case NX_KEYTYPE_ILLUMINATION_DOWN, NX_KEYTYPE_ILLUMINATION_UP:
|
||||
NotificationCenter.default.post(name: SystemKeyObserver.keyboardIlluminationChanged, object: self)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue