Implement PowerAssertions for X11 displays

This commit is contained in:
Lubos Dolezel 2020-02-15 16:22:55 +01:00
parent a102eaf152
commit 06d3e5898f
4 changed files with 30 additions and 4 deletions

View File

@ -48,7 +48,7 @@ set(iokitd_sources
)
add_darling_executable(iokitd ${iokitd_sources})
target_link_libraries(iokitd cxx CoreFoundation Foundation X11 XRandR)
target_link_libraries(iokitd cxx CoreFoundation Foundation X11 XRandR Xext)
install(TARGETS iokitd DESTINATION libexec/darling/usr/sbin)
install(FILES org.darlinghq.iokitd.plist DESTINATION libexec/darling/System/Library/LaunchDaemons)

View File

@ -11,10 +11,14 @@ class IODisplayConnectX11 : IODisplayConnect
{
private:
IODisplayConnectX11(int index, NSDictionary* props);
public:
~IODisplayConnectX11();
static void discoverDevices(ServiceRegistry* targetRegistry);
NSDictionary* getProperties() override;
// TODO: Make the whole display server abstraction nicer?
static Display* getDisplay() { return m_display; }
private:
static Display* m_display;
// Index of the corresponding XrandR output

View File

@ -165,7 +165,7 @@ kern_return_t _io_pm_assertion_create
pid_t callerPid;
audit_token_to_au32(token, nullptr, nullptr, nullptr, nullptr, nullptr, &callerPid, nullptr, nullptr);
std::cout << "Creating assertion for PID " << callerPid << std::endl;
// std::cout << "Creating assertion for PID " << callerPid << std::endl;
*assertion_id = AppAssertions::get(callerPid)->createAssertion(pa);
*return_code = 0;

View File

@ -1,12 +1,34 @@
#include "PowerAssertionsX11.h"
#include "IODisplayConnectX11.h"
#include <iostream>
#include <X11/Xlib.h>
#define BOOL BOOL_THOU_SHALT_NOT_TYPEDEF_BOOL_IN_UNIMPORTANT_HEADERS
#include <X11/extensions/dpms.h>
#undef BOOL
void PowerAssertionPreventDisplaySleep::activate()
{
std::cout << "STUB: PowerAssertionPreventDisplaySleep::activate()\n";
Display* display = IODisplayConnectX11::getDisplay();
if (!display)
return;
int eventBase, errorBase;
if (DPMSQueryExtension(display, &eventBase, &errorBase))
{
DPMSDisable(display);
}
}
void PowerAssertionPreventDisplaySleep::deactivate()
{
std::cout << "STUB: PowerAssertionPreventDisplaySleep::deactivate()\n";
Display* display = IODisplayConnectX11::getDisplay();
if (!display)
return;
int eventBase, errorBase;
if (DPMSQueryExtension(display, &eventBase, &errorBase))
{
DPMSEnable(display);
}
}