This source file includes following definitions.
- Sleep
- set
- display
- main
- __lsan_is_turned_off
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <X11/Xlib.h>
#if defined(USE_AURA)
#include <X11/extensions/XInput2.h>
#endif
void Sleep(int duration_ms) {
struct timespec sleep_time, remaining;
sleep_time.tv_sec = duration_ms / 1000;
duration_ms -= sleep_time.tv_sec * 1000;
sleep_time.tv_nsec = duration_ms * 1000 * 1000;
while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR)
sleep_time = remaining;
}
class XScopedDisplay {
public:
XScopedDisplay() : display_(NULL) {}
~XScopedDisplay() {
if (display_) XCloseDisplay(display_);
}
void set(Display* display) { display_ = display; }
Display* display() { return display_; }
private:
Display* display_;
};
int main(int argc, char* argv[]) {
XScopedDisplay scoped_display;
if (argv[1] && strcmp(argv[1], "--noserver") == 0) {
scoped_display.set(XOpenDisplay(NULL));
if (scoped_display.display()) {
fprintf(stderr, "Found unexpected connectable display %s\n",
XDisplayName(NULL));
}
return !scoped_display.display();
}
int kNumTries = 78;
int tries;
for (tries = 0; tries < kNumTries; ++tries) {
scoped_display.set(XOpenDisplay(NULL));
if (scoped_display.display())
break;
Sleep(10 * tries);
}
if (!scoped_display.display()) {
fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL));
return -1;
}
fprintf(stderr, "Connected after %d retries\n", tries);
#if defined(USE_AURA)
int opcode, event, err;
if (!XQueryExtension(scoped_display.display(), "XInputExtension", &opcode,
&event, &err)) {
fprintf(stderr,
"Failed to get XInputExtension on %s.\n", XDisplayName(NULL));
return -1;
}
int major = 2, minor = 0;
if (XIQueryVersion(scoped_display.display(), &major, &minor) == BadRequest) {
fprintf(stderr,
"Server does not have XInput2 on %s.\n", XDisplayName(NULL));
return -1;
}
int count = 0;
XIDeviceInfo* devices =
XIQueryDevice(scoped_display.display(), XIAllDevices, &count);
if (devices)
XIFreeDeviceInfo(devices);
fprintf(stderr,
"XInput2 verified initially sane on %s.\n", XDisplayName(NULL));
#endif
return 0;
}
#if defined(LEAK_SANITIZER)
__attribute__((used))
__attribute__((visibility("default")))
extern "C" int __lsan_is_turned_off() { return 1; }
#endif