Use a "get" function to initialize X11 loader...

...so static init doesn't spam log before we got that set up properly.
pull/1028/head
jackun 11 months ago
parent ea3ba7e30d
commit 5fde8749af
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -22,10 +22,11 @@ static inline bool keys_are_pressed(const std::vector<KeySym>& keys) {
char keys_return[32];
size_t pressed = 0;
g_x11->XQueryKeymap(get_xdisplay(), keys_return);
auto libx11 = get_libx11();
libx11->XQueryKeymap(get_xdisplay(), keys_return);
for (KeySym ks : keys) {
KeyCode kc2 = g_x11->XKeysymToKeycode(get_xdisplay(), ks);
KeyCode kc2 = libx11->XKeysymToKeycode(get_xdisplay(), ks);
bool isPressed = !!(keys_return[kc2 >> 3] & (1 << (kc2 & 7)));

@ -89,4 +89,10 @@ void libx11_loader::CleanUp(bool unload) {
}
std::shared_ptr<libx11_loader> g_x11(new libx11_loader("libX11.so.6"));
static std::shared_ptr<libx11_loader> loader;
std::shared_ptr<libx11_loader> get_libx11()
{
if (!loader)
loader = std::make_shared<libx11_loader>("libX11.so.6");
return loader;
}

@ -33,4 +33,4 @@ class libx11_loader {
void operator=(const libx11_loader&);
};
extern std::shared_ptr<libx11_loader> g_x11;
std::shared_ptr<libx11_loader> get_libx11();

@ -20,16 +20,17 @@ bool nvctrlSuccess = false;
static bool find_nv_x11(libnvctrl_loader& nvctrl, Display*& dpy)
{
char buf[8] {};
auto libx11 = get_libx11();
for (int i = 0; i < 16; i++) {
snprintf(buf, sizeof(buf), ":%d", i);
Display *d = g_x11->XOpenDisplay(buf);
Display *d = libx11->XOpenDisplay(buf);
if (d) {
if (nvctrl.XNVCTRLIsNvScreen(d, i)) {
dpy = d;
SPDLOG_DEBUG("XNVCtrl is using display {}", buf);
return true;
}
g_x11->XCloseDisplay(d);
libx11->XCloseDisplay(d);
}
}
return false;
@ -37,7 +38,7 @@ static bool find_nv_x11(libnvctrl_loader& nvctrl, Display*& dpy)
bool checkXNVCtrl()
{
if (!g_x11->IsLoaded())
if (!get_libx11()->IsLoaded())
return false;
auto& nvctrl = get_libnvctrl_loader();
@ -54,7 +55,7 @@ bool checkXNVCtrl()
return false;
}
auto local_x11 = g_x11;
auto local_x11 = get_libx11();
display = { dpy,
[local_x11](Display *dpy) {
local_x11->XCloseDisplay(dpy);

@ -129,12 +129,12 @@ static std::vector<KeySym>
parse_string_to_keysym_vec(const char *str)
{
std::vector<KeySym> keys;
if(g_x11->IsLoaded())
if(get_libx11()->IsLoaded())
{
auto keyStrings = str_tokenize(str);
for (auto& ks : keyStrings) {
trim(ks);
KeySym xk = g_x11->XStringToKeysym(ks.c_str());
KeySym xk = get_libx11()->XStringToKeysym(ks.c_str());
if (xk)
keys.push_back(xk);
else

@ -16,7 +16,9 @@ bool init_x11() {
if (display)
return true;
if (!g_x11->IsLoaded()) {
auto libx11 = get_libx11();
if (!libx11->IsLoaded()) {
SPDLOG_ERROR("X11 loader failed to load");
failed = true;
return false;
@ -24,11 +26,10 @@ bool init_x11() {
const char *displayid = getenv("DISPLAY");
if (displayid) {
auto local_x11 = g_x11;
display = { g_x11->XOpenDisplay(displayid),
[local_x11](Display* dpy) {
display = { libx11->XOpenDisplay(displayid),
[libx11](Display* dpy) {
if (dpy)
local_x11->XCloseDisplay(dpy);
libx11->XCloseDisplay(dpy);
}
};
}

Loading…
Cancel
Save