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

@ -9,13 +9,20 @@ 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");
if (displayid) {
auto local_x11 = g_x11; auto local_x11 = g_x11;
display = { g_x11->XOpenDisplay(displayid), display = { g_x11->XOpenDisplay(displayid),
[local_x11](Display* dpy) { [local_x11](Display* dpy) {
@ -23,9 +30,13 @@ bool init_x11() {
local_x11->XCloseDisplay(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