mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-30 22:46:07 +00:00
Implement pause-on-active for Linux
This commit is contained in:
parent
69590f9777
commit
062f3f6d2d
2 changed files with 60 additions and 1 deletions
|
@ -166,6 +166,13 @@ else()
|
||||||
)
|
)
|
||||||
|
|
||||||
set(EXTRA_LIBS pthread rt dl)
|
set(EXTRA_LIBS pthread rt dl)
|
||||||
|
|
||||||
|
find_package(X11)
|
||||||
|
|
||||||
|
if(X11_FOUND)
|
||||||
|
include_directories(${X11_INCLUDE_DIR})
|
||||||
|
add_definitions(-DXMRIG_X11_FOUND)
|
||||||
|
endif()
|
||||||
elseif (XMRIG_OS_FREEBSD)
|
elseif (XMRIG_OS_FREEBSD)
|
||||||
set(EXTRA_LIBS kvm pthread)
|
set(EXTRA_LIBS kvm pthread)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
|
||||||
#include "base/kernel/Platform.h"
|
#include "base/kernel/Platform.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
@ -160,8 +159,61 @@ bool xmrig::Platform::isOnBatteryPower()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(XMRIG_OS_LINUX) && defined(XMRIG_X11_FOUND)
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <X11/extensions/scrnsaver.h>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void bind_symbol(T& var, void *library, const char* name) {
|
||||||
|
var = reinterpret_cast<T>(::dlsym(library, name));
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t xmrig::Platform::idleTime()
|
uint64_t xmrig::Platform::idleTime()
|
||||||
{
|
{
|
||||||
|
// libX11
|
||||||
|
static Display* (*XOpenDisplay)(const char *name) = {};
|
||||||
|
|
||||||
|
// libXss
|
||||||
|
static XScreenSaverInfo* (*XScreenSaverAllocInfo)() = {};
|
||||||
|
static Status (*XScreenSaverQueryInfo)(Display *dpy, Drawable drawable,
|
||||||
|
XScreenSaverInfo *saver_info) = {};
|
||||||
|
|
||||||
|
static bool initialized = false;
|
||||||
|
static Display *dpy = {};
|
||||||
|
static XScreenSaverInfo *info = {};
|
||||||
|
|
||||||
|
if(!initialized) {
|
||||||
|
static void *libx11 = dlopen("/usr/lib/libX11.so", RTLD_LAZY);
|
||||||
|
static void *libxss = dlopen("/usr/lib/libXss.so", RTLD_LAZY);
|
||||||
|
|
||||||
|
if(!libxss || !libx11) {
|
||||||
|
initialized = true;
|
||||||
|
return std::numeric_limits<uint64_t>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
bind_symbol(XOpenDisplay, libx11, "XOpenDisplay");
|
||||||
|
bind_symbol(XScreenSaverAllocInfo, libxss, "XScreenSaverAllocInfo");
|
||||||
|
bind_symbol(XScreenSaverQueryInfo, libxss, "XScreenSaverQueryInfo");
|
||||||
|
|
||||||
|
dpy = XOpenDisplay(nullptr);
|
||||||
|
info = XScreenSaverAllocInfo();
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dpy) {
|
||||||
|
return std::numeric_limits<uint64_t>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
|
||||||
|
|
||||||
|
return info->idle;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
uint64_t xmrig::Platform::idleTime() {
|
||||||
return std::numeric_limits<uint64_t>::max();
|
return std::numeric_limits<uint64_t>::max();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue