diff --git a/src/nvctrl.cpp b/src/nvctrl.cpp index 3123a689..a16fda29 100644 --- a/src/nvctrl.cpp +++ b/src/nvctrl.cpp @@ -16,15 +16,17 @@ bool nvctrlSuccess = false; bool checkXNVCtrl() { - if (init_x11() && nvctrl.IsLoaded()) { - nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(get_xdisplay(), 0); - if (!nvctrlSuccess) - std::cerr << "MANGOHUD: XNVCtrl didn't find the correct display" << std::endl; - return nvctrlSuccess; + if (init_x11()) { + if (nvctrl.IsLoaded()) { + nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(get_xdisplay(), 0); + if (!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; } diff --git a/src/shared_x11.cpp b/src/shared_x11.cpp index eec9275d..88eb1bf4 100644 --- a/src/shared_x11.cpp +++ b/src/shared_x11.cpp @@ -9,23 +9,34 @@ static std::unique_ptr> display; bool init_x11() { static bool failed = false; - if (failed || !g_x11->IsLoaded()) + if (failed) return false; if (display) return true; + if (!g_x11->IsLoaded()) { + std::cerr << "MANGOHUD: X11 loader failed to load\n"; + failed = true; + return false; + } + const char *displayid = getenv("DISPLAY"); - auto local_x11 = g_x11; - display = { g_x11->XOpenDisplay(displayid), - [local_x11](Display* dpy) { - if (dpy) - local_x11->XCloseDisplay(dpy); - } - }; + if (displayid) { + auto local_x11 = g_x11; + display = { g_x11->XOpenDisplay(displayid), + [local_x11](Display* dpy) { + if (dpy) + local_x11->XCloseDisplay(dpy); + } + }; + } failed = !display; - return failed; + if (failed) + std::cerr << "MANGOHUD: XOpenDisplay failed to open display '" << displayid << "'\n"; + + return !!display; } Display* get_xdisplay()