Skip to content

Refactor OSD for screenpad backlight #1

Description

@Qonfused

There is currently no OSD indicator for brightness when controlling backlight for screenpad devices. This may limit the practicality of ACPI patches that implement more than a handful of brightness steps. Refer to SSDT-SPLC.dsl#L42-L63 for an implementation example.

There is already a function for extracting and calling the same OSD method in AsusSMC (AsusSMCDaemon/OSD.h), though perhaps a clearer reference comes from ExternalDisplayBrightness for handling multiple displays:

// @fnesveda/ExternalDisplayBrightness/src/ExternalDisplayBrightness/BrightnessManager.swift#L330-L349
330 | // shows the brightness HUD with the correct brightness indicator on the correct display
331 | // unfortunately Apple doesn't provide a public API for this, so we have to manually extract the function from the OSD framework
332 | private static var showBrightnessHUD: ((CGDirectDisplayID, Int, Int) -> Void)? {
333 | 	if let osdLoaded = Bundle(path: "/System/Library/PrivateFrameworks/OSD.framework")?.load(), osdLoaded {
334 | 		if let sharedOSDManager = NSClassFromString("OSDManager")?.value(forKeyPath: "sharedManager") as AnyObject? {
335 | 			let showImageSelector = Selector(("showImage:onDisplayID:priority:msecUntilFade:filledChiclets:totalChiclets:locked:"))
336 | 			if sharedOSDManager.responds(to: showImageSelector) {
337 | 				let showImageImplementation = sharedOSDManager.method(for: showImageSelector)
338 | 				
339 | 				typealias ShowImageFunctionType = @convention(c) (AnyObject, Selector, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, Bool) -> Void
340 | 				let showImage = unsafeBitCast(showImageImplementation, to: ShowImageFunctionType.self)
341 | 				
342 | 				return {(onDisplayID: CGDirectDisplayID, filledChiclets: Int, totalChiclets: Int) -> Void in
343 | 					showImage(sharedOSDManager, showImageSelector, 1, onDisplayID, 0x1f3, 1000, UInt32(filledChiclets), UInt32(totalChiclets), false)
344 | 				}
345 | 			}
346 | 		}
347 | 	}
348 | 	return nil
349 | }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions