diff --git a/render.c b/render.c index b3342fc..83d439a 100644 --- a/render.c +++ b/render.c @@ -681,6 +681,8 @@ static struct gl_bind_src* lookup_bind_src(const char* str) { struct renderer* rd_new(const char** paths, const char* entry, const char* force_mod, const char* force_backend) { + + xwin_wait_for_wm(); renderer* r = malloc(sizeof(struct renderer)); *r = (struct renderer) { diff --git a/xwin.c b/xwin.c index ce2193d..74d5eed 100644 --- a/xwin.c +++ b/xwin.c @@ -8,6 +8,8 @@ #include #include +#include + #include #include @@ -53,6 +55,33 @@ static Window find_desktop(struct renderer* r) { return desktop; } +void xwin_wait_for_wm(void) { + Display* d = XOpenDisplay(0); + + Atom check = None; + bool exists = false; + struct timespec tv = { .tv_sec = 0, .tv_nsec = 50 * 1000000 }; + + do { + if (check == None) { + check = XInternAtom(d, "_NET_SUPPORTING_WM_CHECK", true); + } + if (check) { + int num_prop, idx; + Atom* props = XListProperties(d, DefaultRootWindow(d), &num_prop); + for (idx = 0; idx < num_prop; ++idx) { + if (props[idx] == check) { + exists = true; + break; + } + } + } + if (!exists) nanosleep(&tv, NULL); + } while (!exists); + + XCloseDisplay(d); +} + bool xwin_should_render(struct renderer* rd) { bool ret = true, should_close = false; Display* d = rd_get_wcb(rd)->get_x11_display(); diff --git a/xwin.h b/xwin.h index 802b2b9..6e0049a 100644 --- a/xwin.h +++ b/xwin.h @@ -2,6 +2,7 @@ #define XWIN_ALL_DESKTOPS 0xFFFFFFFF bool xwin_should_render(struct renderer* rd); +void xwin_wait_for_wm(void); bool xwin_settype(struct gl_wcb* wcb, void* impl, const char* type); void xwin_setdesktop(struct gl_wcb* wcb, void* impl, unsigned long desktop); void xwin_addstate(struct gl_wcb* wcb, void* impl, const char* state);