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;
125 wc.lpfnWndProc = [](HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -> LRESULT {
135 return DefWindowProc(hwnd, msg, wParam, lParam);
139 wc.hInstance = hInstance;
140 wc.lpszClassName =
"window";
141 RegisterClassExA(&wc);
144 hwnd = CreateWindowExA(
145 WS_EX_TRANSPARENT,
"window",
"window", WS_POPUP, 0, 0, 0, 0,
nullptr,
nullptr,
151#elif __has_include(<X11/Xlib.h>)
155 if(
auto sym =
reinterpret_cast<int (*)()
>(dlsym(x11,
"XInitThreads")))
158 decltype(XOpenDisplay)* d_XOpenDisplay
159 = (
decltype(XOpenDisplay)*)dlsym(x11,
"XOpenDisplay");
160 decltype(XCreateWindow)* d_XCreateWindow
161 = (
decltype(XCreateWindow)*)dlsym(x11,
"XCreateWindow");
162 decltype(XCreateGC)* d_XCreateGC = (
decltype(XCreateGC)*)dlsym(x11,
"XCreateGC");
163 decltype(XSelectInput)* d_XSelectInput
164 = (
decltype(XSelectInput)*)dlsym(x11,
"XSelectInput");
165 decltype(XMapWindow)* d_XMapWindow = (
decltype(XMapWindow)*)dlsym(x11,
"XMapWindow");
166 decltype(XSync)* d_XSync = (
decltype(XSync)*)dlsym(x11,
"XSync");
167 decltype(XInternAtom)* d_XInternAtom
168 = (
decltype(XInternAtom)*)dlsym(x11,
"XInternAtom");
169 decltype(XChangeProperty)* d_XChangeProperty
170 = (
decltype(XChangeProperty)*)dlsym(x11,
"XChangeProperty");
172 dpy = d_XOpenDisplay(NULL);
176 XSetWindowAttributes attrs{};
177 attrs.override_redirect = True;
180 dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 1, 1, 0, CopyFromParent,
181 InputOutput, CopyFromParent, CWOverrideRedirect, &attrs);
183 gc = d_XCreateGC(dpy, w, 0, 0);
186 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask
187 | ButtonReleaseMask | PointerMotionMask);
188 d_XMapWindow(dpy, w);
194 unsigned long flags = 2;
195 unsigned long functions = 0;
196 unsigned long decorations = 0;
198 unsigned long status = 0;
200 auto property = d_XInternAtom(dpy,
"_MOTIF_WM_HINTS",
true);
202 dpy, w, property, property, 32, PropModeReplace, (
unsigned char*)&hints, 5);
203 d_XMapWindow(dpy, w);
209#if defined(__APPLE__)
210 msg1(
void, msg(
id, wnd,
"contentView"),
"setNeedsDisplay:", BOOL, YES);
212 id, NSApp,
"nextEventMatchingMask:untilDate:inMode:dequeue:", NSUInteger,
213 NSUIntegerMax,
id, NULL,
id, NSDefaultRunLoopMode, BOOL, YES);
216 msg1(
void, NSApp,
"sendEvent:",
id, ev);
220 while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
222 if(msg.message == WM_QUIT)
224 TranslateMessage(&msg);
225 DispatchMessage(&msg);
227 InvalidateRect(hwnd, NULL, TRUE);
229#elif __has_include(<X11/Xlib.h>)
232 if(
decltype(XFlush)* d_XFlush = (
decltype(XFlush)*)dlsym(x11,
"XFlush"))
241#if defined(__APPLE__)
242 msg(
void, wnd,
"close");
243 msg1(
void, NSApp,
"terminate:",
id, NSApp);
248#elif __has_include(<X11/Xlib.h>)
251 if(
decltype(XCloseDisplay)* d_XCloseDisplay
252 = (
decltype(XCloseDisplay)*)dlsym(x11,
"XCloseDisplay"))
253 d_XCloseDisplay(dpy);