87#elif __has_include(<X11/Xlib.h>)
88 void* x11 = dlopen(
"libX11.so.6", RTLD_LAZY | RTLD_LOCAL);
97 auto pool = msg(
id, cls(
"NSAutoreleasePool"),
"alloc");
98 msg(
void, pool,
"init");
100 msg(
id, cls(
"NSApplication"),
"sharedApplication");
105 void, NSApp,
"setActivationPolicy:", NSInteger,
110 id, msg(
id, cls(
"NSWindow"),
"alloc"),
111 "initWithContentRect:styleMask:backing:defer:", CGRect, CGRectMake(0, 0, 1, 1),
112 NSUInteger, 3, NSUInteger, 2, BOOL, NO);
116 msg1(
void, wnd,
"setOpaque:", NSInteger, NO);
117 id clearColor = msg(
id, cls(
"NSColor"),
"clearColor");
118 msg1(
void, wnd,
"setBackgroundColor:",
id, clearColor);
121 HINSTANCE hInstance = GetModuleHandle(NULL);
122 WNDCLASSEXA wc = {0};
123 wc.cbSize =
sizeof(WNDCLASSEX);
124 wc.style = CS_VREDRAW | CS_HREDRAW;
127 static LRESULT CALLBACK run(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
138 return DefWindowProc(hwnd, msg, wParam, lParam);
143 wc.lpfnWndProc = &WndProc::run;
144 wc.hInstance = hInstance;
145 wc.lpszClassName =
"window";
146 RegisterClassExA(&wc);
149 hwnd = CreateWindowExA(
150 WS_EX_TRANSPARENT,
"window",
"window", WS_POPUP, 0, 0, 0, 0,
nullptr,
nullptr,
156#elif __has_include(<X11/Xlib.h>)
160 if(
auto sym =
reinterpret_cast<int (*)()
>(dlsym(x11,
"XInitThreads")))
163 decltype(XOpenDisplay)* d_XOpenDisplay
164 = (
decltype(XOpenDisplay)*)dlsym(x11,
"XOpenDisplay");
165 decltype(XCreateWindow)* d_XCreateWindow
166 = (
decltype(XCreateWindow)*)dlsym(x11,
"XCreateWindow");
167 decltype(XCreateGC)* d_XCreateGC = (
decltype(XCreateGC)*)dlsym(x11,
"XCreateGC");
168 decltype(XSelectInput)* d_XSelectInput
169 = (
decltype(XSelectInput)*)dlsym(x11,
"XSelectInput");
170 decltype(XMapWindow)* d_XMapWindow = (
decltype(XMapWindow)*)dlsym(x11,
"XMapWindow");
171 decltype(XSync)* d_XSync = (
decltype(XSync)*)dlsym(x11,
"XSync");
172 decltype(XInternAtom)* d_XInternAtom
173 = (
decltype(XInternAtom)*)dlsym(x11,
"XInternAtom");
174 decltype(XChangeProperty)* d_XChangeProperty
175 = (
decltype(XChangeProperty)*)dlsym(x11,
"XChangeProperty");
177 dpy = d_XOpenDisplay(NULL);
181 XSetWindowAttributes attrs{};
182 attrs.override_redirect = True;
185 dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 1, 1, 0, CopyFromParent,
186 InputOutput, CopyFromParent, CWOverrideRedirect, &attrs);
188 gc = d_XCreateGC(dpy, w, 0, 0);
191 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask
192 | ButtonReleaseMask | PointerMotionMask);
193 d_XMapWindow(dpy, w);
199 unsigned long flags = 2;
200 unsigned long functions = 0;
201 unsigned long decorations = 0;
203 unsigned long status = 0;
205 auto property = d_XInternAtom(dpy,
"_MOTIF_WM_HINTS",
true);
207 dpy, w, property, property, 32, PropModeReplace, (
unsigned char*)&hints, 5);
208 d_XMapWindow(dpy, w);
214#if defined(__APPLE__)
215 msg1(
void, msg(
id, wnd,
"contentView"),
"setNeedsDisplay:", BOOL, YES);
217 id, NSApp,
"nextEventMatchingMask:untilDate:inMode:dequeue:", NSUInteger,
218 NSUIntegerMax,
id, NULL,
id, NSDefaultRunLoopMode, BOOL, YES);
221 msg1(
void, NSApp,
"sendEvent:",
id, ev);
225 while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
227 if(msg.message == WM_QUIT)
229 TranslateMessage(&msg);
230 DispatchMessage(&msg);
232 InvalidateRect(hwnd, NULL, TRUE);
234#elif __has_include(<X11/Xlib.h>)
237 if(
decltype(XFlush)* d_XFlush = (
decltype(XFlush)*)dlsym(x11,
"XFlush"))
246#if defined(__APPLE__)
247 msg(
void, wnd,
"close");
248 msg1(
void, NSApp,
"terminate:",
id, NSApp);
253#elif __has_include(<X11/Xlib.h>)
256 if(
decltype(XCloseDisplay)* d_XCloseDisplay
257 = (
decltype(XCloseDisplay)*)dlsym(x11,
"XCloseDisplay"))
258 d_XCloseDisplay(dpy);