src/X11Handler.h
branchv_0
changeset 8 6f5616572273
parent 7 93d9c4fce585
child 9 08c913c9662f
equal deleted inserted replaced
7:93d9c4fce585 8:6f5616572273
    20 #include <string>
    20 #include <string>
    21 #include <vector>
    21 #include <vector>
    22 #include <iostream>
    22 #include <iostream>
    23 #include <sstream>
    23 #include <sstream>
    24 #include <locale>
    24 #include <locale>
    25 #include <codecvt>
       
    26 #include <stdexcept>
    25 #include <stdexcept>
    27 
    26 
    28 #include <X11/extensions/XTest.h>
    27 #include <X11/extensions/XTest.h>
    29 
    28 
    30 #include <relpipe/common/type/typedefs.h>
    29 #include <relpipe/common/type/typedefs.h>
    77 		int y = -1;
    76 		int y = -1;
    78 	} currentEvent;
    77 	} currentEvent;
    79 
    78 
    80 	Display display;
    79 	Display display;
    81 	Configuration& configuration;
    80 	Configuration& configuration;
    82 	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: probably not needed
       
    83 	std::vector<relpipe::reader::handlers::AttributeMetadata> attributes;
    81 	std::vector<relpipe::reader::handlers::AttributeMetadata> attributes;
    84 	relpipe::common::type::Integer attributeIndex = 0;
    82 	relpipe::common::type::Integer attributeIndex = 0;
    85 public:
    83 public:
    86 
    84 
    87 	X11Handler(Configuration& configuration) : configuration(configuration) {
    85 	X11Handler(Configuration& configuration) : configuration(configuration) {
    88 		display.display = XOpenDisplay(nullptr);
    86 		display.display = XOpenDisplay(nullptr);
    89 	}
    87 	}
    90 
    88 
    91 	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
    89 	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
       
    90 		// TODO: check relation name, print waring if it does not match
    92 		if (display.display) {
    91 		if (display.display) {
    93 			if (this->attributes.empty()) {
    92 			if (this->attributes.empty()) {
    94 				this->attributes = attributes;
    93 				this->attributes = attributes;
    95 			} else {
    94 			} else {
    96 				throw std::logic_error("Only a single relation can be converted to the X11 format.");
    95 				throw std::logic_error("Only a single relation can be converted to the X11 format.");
   100 		}
    99 		}
   101 
   100 
   102 	}
   101 	}
   103 
   102 
   104 	void attribute(const relpipe::common::type::StringX& value) override {
   103 	void attribute(const relpipe::common::type::StringX& value) override {
       
   104 		// TODO: strictly expect correct data types (integers)?
       
   105 		// TODO: shorter codes (k/b/m, p/r) instead of names or both?
   105 		if (attributes[attributeIndex].getAttributeName() == L"device") {
   106 		if (attributes[attributeIndex].getAttributeName() == L"device") {
   106 			// TODO: maybe add some filtering based on device ID
   107 			// TODO: maybe add some filtering based on device ID
   107 		} else if (attributes[attributeIndex].getAttributeName() == L"type") {
   108 		} else if (attributes[attributeIndex].getAttributeName() == L"type") {
   108 			if (value == L"key") currentEvent.type = Event::Type::KEY;
   109 			if (value == L"key") currentEvent.type = Event::Type::KEY;
   109 			else if (value == L"button") currentEvent.type = Event::Type::BUTTON;
   110 			else if (value == L"button") currentEvent.type = Event::Type::BUTTON;
   153 			currentEvent = Event();
   154 			currentEvent = Event();
   154 		}
   155 		}
   155 	}
   156 	}
   156 
   157 
   157 	void endOfPipe() {
   158 	void endOfPipe() {
   158 		// XTestDiscard(display.display); // TODO: wait before discard?
       
   159 	}
   159 	}
   160 
   160 
   161 };
   161 };
   162 
   162 
   163 }
   163 }