Fix `init_x11` return value and X11/XNVCtrl logic checks

pull/131/head
jackun 4 years ago
parent 88188ee1da
commit 723c6bedeb
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -16,15 +16,17 @@ bool nvctrlSuccess = false;
bool checkXNVCtrl() bool checkXNVCtrl()
{ {
if (init_x11() && nvctrl.IsLoaded()) { if (init_x11()) {
nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(get_xdisplay(), 0); if (nvctrl.IsLoaded()) {
if (!nvctrlSuccess) nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(get_xdisplay(), 0);
std::cerr << "MANGOHUD: XNVCtrl didn't find the correct display" << std::endl; if (!nvctrlSuccess)
return nvctrlSuccess; std::cerr << "MANGOHUD: XNVCtrl didn't find the correct display" << std::endl;
return nvctrlSuccess;
} else {
std::cerr << "MANGOHUD: XNVCtrl failed to load\n";
}
} }
std::cerr << "MANGOHUD: XNVCtrl failed to load\n";
return false; return false;
} }

@ -9,23 +9,34 @@ static std::unique_ptr<Display, std::function<void(Display*)>> display;
bool init_x11() { bool init_x11() {
static bool failed = false; static bool failed = false;
if (failed || !g_x11->IsLoaded()) if (failed)
return false; return false;
if (display) if (display)
return true; return true;
if (!g_x11->IsLoaded()) {
std::cerr << "MANGOHUD: X11 loader failed to load\n";
failed = true;
return false;
}
const char *displayid = getenv("DISPLAY"); const char *displayid = getenv("DISPLAY");
auto local_x11 = g_x11; if (displayid) {
display = { g_x11->XOpenDisplay(displayid), auto local_x11 = g_x11;
[local_x11](Display* dpy) { display = { g_x11->XOpenDisplay(displayid),
if (dpy) [local_x11](Display* dpy) {
local_x11->XCloseDisplay(dpy); if (dpy)
} local_x11->XCloseDisplay(dpy);
}; }
};
}
failed = !display; failed = !display;
return failed; if (failed)
std::cerr << "MANGOHUD: XOpenDisplay failed to open display '" << displayid << "'\n";
return !!display;
} }
Display* get_xdisplay() Display* get_xdisplay()

Loading…
Cancel
Save