2020-04-01 19:17:24 +00:00
|
|
|
#include "shared_x11.h"
|
|
|
|
#include "loaders/loader_x11.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
static std::unique_ptr<Display, std::function<void(Display*)>> display;
|
|
|
|
|
|
|
|
bool init_x11() {
|
|
|
|
static bool failed = false;
|
2020-04-13 21:25:27 +00:00
|
|
|
if (failed)
|
2020-04-01 19:17:24 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (display)
|
|
|
|
return true;
|
|
|
|
|
2020-04-13 21:25:27 +00:00
|
|
|
if (!g_x11->IsLoaded()) {
|
|
|
|
std::cerr << "MANGOHUD: X11 loader failed to load\n";
|
|
|
|
failed = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-01 19:17:24 +00:00
|
|
|
const char *displayid = getenv("DISPLAY");
|
2020-04-13 21:25:27 +00:00
|
|
|
if (displayid) {
|
|
|
|
auto local_x11 = g_x11;
|
|
|
|
display = { g_x11->XOpenDisplay(displayid),
|
|
|
|
[local_x11](Display* dpy) {
|
|
|
|
if (dpy)
|
|
|
|
local_x11->XCloseDisplay(dpy);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2020-04-01 19:17:24 +00:00
|
|
|
|
|
|
|
failed = !display;
|
2020-04-13 21:25:27 +00:00
|
|
|
if (failed)
|
|
|
|
std::cerr << "MANGOHUD: XOpenDisplay failed to open display '" << displayid << "'\n";
|
|
|
|
|
|
|
|
return !!display;
|
2020-04-01 19:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Display* get_xdisplay()
|
|
|
|
{
|
|
|
|
return display.get();
|
|
|
|
}
|