|
|
@ -2,13 +2,52 @@
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
#include <memory>
|
|
|
|
#include <functional>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include "shared_x11.h"
|
|
|
|
#include "shared_x11.h"
|
|
|
|
#include "loaders/loader_x11.h"
|
|
|
|
#include "loaders/loader_x11.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
|
|
|
|
static std::unique_ptr<Display, std::function<void(Display*)>> display;
|
|
|
|
static std::unique_ptr<Display, std::function<void(Display*)>> display;
|
|
|
|
|
|
|
|
char keys_return[32]{};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class x11_poller
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::thread thread;
|
|
|
|
|
|
|
|
bool quit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void poll()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
while (!quit)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
libx11->XQueryKeymap(get_xdisplay(), keys_return);
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
std::shared_ptr<libx11_loader> libx11;
|
|
|
|
|
|
|
|
x11_poller(std::shared_ptr<libx11_loader> x) : libx11(x) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void start()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
quit = false;
|
|
|
|
|
|
|
|
thread = std::thread(&x11_poller::poll, this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void stop()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
quit = true;
|
|
|
|
|
|
|
|
if (thread.joinable())
|
|
|
|
|
|
|
|
thread.join();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool init_x11() {
|
|
|
|
bool init_x11() {
|
|
|
|
|
|
|
|
std::shared_ptr<x11_poller> poller;
|
|
|
|
static bool failed = false;
|
|
|
|
static bool failed = false;
|
|
|
|
if (failed)
|
|
|
|
if (failed)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -24,13 +63,17 @@ bool init_x11() {
|
|
|
|
|
|
|
|
|
|
|
|
const char *displayid = getenv("DISPLAY");
|
|
|
|
const char *displayid = getenv("DISPLAY");
|
|
|
|
if (displayid) {
|
|
|
|
if (displayid) {
|
|
|
|
auto local_x11 = g_x11;
|
|
|
|
poller = std::make_shared<x11_poller>( g_x11 );
|
|
|
|
display = { g_x11->XOpenDisplay(displayid),
|
|
|
|
display = { g_x11->XOpenDisplay(displayid),
|
|
|
|
[local_x11](Display* dpy) {
|
|
|
|
[poller](Display* dpy) {
|
|
|
|
|
|
|
|
poller->stop();
|
|
|
|
if (dpy)
|
|
|
|
if (dpy)
|
|
|
|
local_x11->XCloseDisplay(dpy);
|
|
|
|
poller->libx11->XCloseDisplay(dpy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (display)
|
|
|
|
|
|
|
|
poller->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
failed = !display;
|
|
|
|
failed = !display;
|
|
|
|