# HG changeset patch # User František Kučera # Date 1616951384 -7200 # Node ID 6851c08c62606b8d79f6d1fdebd163ab4ed31d63 # Parent 043a3e2e5f0c206d7f16048d57247cd76fed7ec0 open X display diff -r 043a3e2e5f0c -r 6851c08c6260 src/X11Handler.h --- a/src/X11Handler.h Sun Mar 28 18:57:10 2021 +0200 +++ b/src/X11Handler.h Sun Mar 28 19:09:44 2021 +0200 @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -38,24 +40,42 @@ class X11Handler : public relpipe::reader::handlers::RelationalReaderStringHandler { private: - std::ostream& output; + + class Display { + public: + ::Display* display = nullptr; + // TODO: more OOP + + virtual ~Display() { + if (display) XCloseDisplay(display); + } + }; + + Display display; + std::ostream& output; // TODO: remove Configuration& configuration; - const char QUOTE = '"'; + const char QUOTE = '"'; // TODO: remove std::wstring_convert> convertor; // TODO: probably not needed std::vector firstAttributes; relpipe::common::type::Integer valueCount = 0; public: X11Handler(std::ostream& output, Configuration& configuration) : output(output), configuration(configuration) { + display.display = XOpenDisplay(nullptr); } void startRelation(relpipe::common::type::StringX name, std::vector attributes) override { - if (firstAttributes.empty()) { - firstAttributes = attributes; - if (configuration.writeHeader) for (auto attr : attributes) attribute(attr.getAttributeName()); + if (display.display) { + if (firstAttributes.empty()) { + firstAttributes = attributes; + if (configuration.writeHeader) for (auto attr : attributes) attribute(attr.getAttributeName()); + } else { + throw std::logic_error("Only a single relation can be converted to the X11 format."); + } } else { - throw std::logic_error("Only a single relation can be converted to the X11 format."); + throw std::invalid_argument("Unable to open display. Please check the $DISPLAY variable."); } + } void attribute(const relpipe::common::type::StringX& value) override { @@ -75,6 +95,8 @@ } else { output << "\r\n"; valueCount = 0; + // XTestFakeKeyEvent(display.display, 38, true, 0); + // XTestFakeKeyEvent(display.display, 38, false, 0); } }