Updated some stuff for linux
This commit is contained in:
		
							parent
							
								
									9f4470dacb
								
							
						
					
					
						commit
						81ad9bd9e8
					
				| @ -1,11 +1,12 @@ | |||||||
| set(MODULE_NAME "teaclient_ppt") | set(MODULE_NAME "teaclient_ppt") | ||||||
| 
 | 
 | ||||||
|  | set(SOURCE_FILES src/KeyboardHook.cpp) | ||||||
| if (MSVC) | if (MSVC) | ||||||
| 	set(SOURCE_FILES ${SOURCE_FILES} src/Win32KeyboardHook.cpp) | 	set(SOURCE_FILES ${SOURCE_FILES} src/Win32KeyboardHook.cpp) | ||||||
| 	add_definitions(-DUSING_UV_SHARED) | 	add_definitions(-DUSING_UV_SHARED) | ||||||
| else() | else() | ||||||
| 	add_definitions(-DHAVE_X11) | 	add_definitions(-DHAVE_X11) | ||||||
| 	set(SOURCE_FILES ${SOURCE_FILES} src/X11KeyboardHook.cpp ../updater/main.cpp ../updater/config.cpp ../updater/config.h) | 	set(SOURCE_FILES ${SOURCE_FILES} src/X11KeyboardHook.cpp) | ||||||
| endif() | endif() | ||||||
| 
 | 
 | ||||||
| add_nodejs_module(${MODULE_NAME} binding.cc ${SOURCE_FILES}) | add_nodejs_module(${MODULE_NAME} binding.cc ${SOURCE_FILES}) | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								native/ppt/src/KeyboardHook.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								native/ppt/src/KeyboardHook.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | |||||||
|  | #include "KeyboardHook.h" | ||||||
|  | 
 | ||||||
|  | using namespace std; | ||||||
|  | void KeyboardHook::trigger_key_event(const enum KeyEvent::type& type, const std::string &key) { | ||||||
|  | 	if(!this->callback_event) return; | ||||||
|  | 
 | ||||||
|  | 	auto event = make_shared<KeyboardHook::KeyEvent>(); | ||||||
|  | 	event->type = type; | ||||||
|  | 	event->code = key; | ||||||
|  | 
 | ||||||
|  | 	event->key_alt = this->map_special[KeyType::KEY_ALT] > 0; | ||||||
|  | 	event->key_ctrl = this->map_special[KeyType::KEY_CTRL] > 0; | ||||||
|  | 	event->key_windows = this->map_special[KeyType::KEY_WIN] > 0; | ||||||
|  | 	event->key_shift = this->map_special[KeyType::KEY_SHIFT] > 0; | ||||||
|  | 
 | ||||||
|  | 	this->callback_event(event); | ||||||
|  | } | ||||||
| @ -15,21 +15,6 @@ KeyboardHook::~KeyboardHook() { | |||||||
| 		this->detach(); | 		this->detach(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void KeyboardHook::trigger_key_event(const enum KeyEvent::type& type, const std::string &key) { |  | ||||||
|     if(!this->callback_event) return; |  | ||||||
|      |  | ||||||
|     auto event = make_shared<KeyboardHook::KeyEvent>(); |  | ||||||
|     event->type = type; |  | ||||||
|     event->code = key; |  | ||||||
| 
 |  | ||||||
|     event->key_alt = this->map_special[KeyType::KEY_ALT]; |  | ||||||
|     event->key_ctrl = this->map_special[KeyType::KEY_CTRL]; |  | ||||||
|     event->key_windows = this->map_special[KeyType::KEY_WIN]; |  | ||||||
|     event->key_shift = this->map_special[KeyType::KEY_SHIFT]; |  | ||||||
| 
 |  | ||||||
|     this->callback_event(event); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| bool KeyboardHook::attach() { | bool KeyboardHook::attach() { | ||||||
| 	assert(!this->_attached); | 	assert(!this->_attached); | ||||||
| 	this->active = true; | 	this->active = true; | ||||||
|  | |||||||
| @ -63,11 +63,11 @@ bool KeyboardHook::attach() { | |||||||
| 		//XGrabKeyboard(this->display, this->window_focused, false, GrabModeAsync, GrabModeAsync, CurrentTime);
 | 		//XGrabKeyboard(this->display, this->window_focused, false, GrabModeAsync, GrabModeAsync, CurrentTime);
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	XSetErrorHandler([](Display* display, XErrorEvent* event) { | 	XSetErrorHandler([](Display* dp, XErrorEvent* event) { | ||||||
| 		if(event->type == BadWindow) | 		if(event->type == BadWindow) | ||||||
| 			return 0; | 			return 0; | ||||||
| 		/*
 | 		/*
 | ||||||
| 		 * X Error of failed request:  BadWindow (invalid Window parameter) | 	      X Error of failed request:  BadWindow (invalid Window parameter) | ||||||
| 		  Major opcode of failed request:  2 (X_ChangeWindowAttributes) | 		  Major opcode of failed request:  2 (X_ChangeWindowAttributes) | ||||||
| 		  Resource id in failed request:  0x0 | 		  Resource id in failed request:  0x0 | ||||||
| 		  Serial number of failed request:  32 | 		  Serial number of failed request:  32 | ||||||
| @ -146,40 +146,9 @@ void KeyboardHook::poll_events() { | |||||||
| 			else | 			else | ||||||
| 				this->map_special[type] = key_sym; | 				this->map_special[type] = key_sym; | ||||||
| 
 | 
 | ||||||
| 			if (this->callback_event) { | 			if(!typed) | ||||||
| 				if(!typed) { | 				this->trigger_key_event(KeyEvent::PRESS, type == KeyType::KEY_NORMAL ? XKeysymToString(key_sym) : XKeysymToString(this->map_special[KeyType::KEY_NORMAL])); | ||||||
| 					auto e = make_shared<KeyboardHook::KeyEvent>(); | 			this->trigger_key_event(KeyEvent::TYPE, type == KeyType::KEY_NORMAL ? XKeysymToString(key_sym) : XKeysymToString(this->map_special[KeyType::KEY_NORMAL])); | ||||||
| 					e->type = KeyboardHook::KeyEvent::PRESS; |  | ||||||
| 					if(type == KeyType::KEY_NORMAL) { |  | ||||||
| 						e->code = XKeysymToString(key_sym); |  | ||||||
| 					} else { |  | ||||||
| 						e->code = XKeysymToString(this->map_special[KeyType::KEY_NORMAL]); |  | ||||||
| 					} |  | ||||||
| 
 |  | ||||||
| 					e->key_alt = this->map_special[KeyType::KEY_ALT] > 0; |  | ||||||
| 					e->key_ctrl = this->map_special[KeyType::KEY_CTRL] > 0; |  | ||||||
| 					e->key_windows = this->map_special[KeyType::KEY_WIN] > 0; |  | ||||||
| 					e->key_shift = this->map_special[KeyType::KEY_SHIFT] > 0; |  | ||||||
| 
 |  | ||||||
| 					this->callback_event(e); |  | ||||||
| 				} |  | ||||||
| 				{ |  | ||||||
| 					auto e = make_shared<KeyboardHook::KeyEvent>(); |  | ||||||
| 					e->type = KeyboardHook::KeyEvent::TYPE; |  | ||||||
| 					if(type == KeyType::KEY_NORMAL) { |  | ||||||
| 						e->code = XKeysymToString(key_sym); |  | ||||||
| 					} else { |  | ||||||
| 						e->code = XKeysymToString(this->map_special[KeyType::KEY_NORMAL]); |  | ||||||
| 					} |  | ||||||
| 
 |  | ||||||
| 					e->key_alt = this->map_special[KeyType::KEY_ALT] > 0; |  | ||||||
| 					e->key_ctrl = this->map_special[KeyType::KEY_CTRL] > 0; |  | ||||||
| 					e->key_windows = this->map_special[KeyType::KEY_WIN] > 0; |  | ||||||
| 					e->key_shift = this->map_special[KeyType::KEY_SHIFT] > 0; |  | ||||||
| 
 |  | ||||||
| 					this->callback_event(e); |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} else if(event.type == KeyRelease) { | 		} else if(event.type == KeyRelease) { | ||||||
| 			auto key_sym = XLookupKeysym(&event.xkey, 0); | 			auto key_sym = XLookupKeysym(&event.xkey, 0); | ||||||
| 			if(XEventsQueued(this->display, 0) > 0) { | 			if(XEventsQueued(this->display, 0) > 0) { | ||||||
| @ -203,25 +172,14 @@ void KeyboardHook::poll_events() { | |||||||
| 			else if(this->map_special[KeyType::KEY_NORMAL] == key_sym) | 			else if(this->map_special[KeyType::KEY_NORMAL] == key_sym) | ||||||
| 				this->map_special[KeyType::KEY_NORMAL] = XK_VoidSymbol; | 				this->map_special[KeyType::KEY_NORMAL] = XK_VoidSymbol; | ||||||
| 
 | 
 | ||||||
| 			if (this->callback_event) { | 			this->trigger_key_event(KeyEvent::RELEASE, type == KeyType::KEY_NORMAL ? XKeysymToString(key_sym) : XKeysymToString(this->map_special[KeyType::KEY_NORMAL])); | ||||||
| 				auto e = make_shared<KeyboardHook::KeyEvent>(); |  | ||||||
| 				e->type = KeyboardHook::KeyEvent::RELEASE; |  | ||||||
| 				if(type == KeyType::KEY_NORMAL) { |  | ||||||
| 					e->code = XKeysymToString(key_sym); |  | ||||||
| 				} else { |  | ||||||
| 					e->code = XKeysymToString(this->map_special[KeyType::KEY_NORMAL]); |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 				e->key_alt = this->map_special[KeyType::KEY_ALT] > 0; |  | ||||||
| 				e->key_ctrl = this->map_special[KeyType::KEY_CTRL] > 0; |  | ||||||
| 				e->key_windows = this->map_special[KeyType::KEY_WIN] > 0; |  | ||||||
| 				e->key_shift = this->map_special[KeyType::KEY_SHIFT] > 0; |  | ||||||
| 
 |  | ||||||
| 				this->callback_event(e); |  | ||||||
| 			} |  | ||||||
| 		} else if(event.type == ClientMessage) { | 		} else if(event.type == ClientMessage) { | ||||||
| 			cout << "Got client message. End ID: " << event.xclient.data.l[0] << " <=> " << this->end_id << endl; | 			cout << "Got client message. End ID: " << event.xclient.data.l[0] << " <=> " << this->end_id << endl; | ||||||
| 			if(event.xclient.data.l[0] == this->end_id) break; | 			if(event.xclient.data.l[0] == this->end_id) break; | ||||||
|  | 		} else if(event.type == ButtonPress) { | ||||||
|  | 			cout << "Got button" << endl; | ||||||
|  | 		} else if(event.type == ButtonRelease) { | ||||||
|  | 			cout << "Got button" << endl; | ||||||
| 		} else { | 		} else { | ||||||
| 			cerr << "Got unknown event of type " << event.type << endl; | 			cerr << "Got unknown event of type " << event.type << endl; | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ | |||||||
| #include "config.h" | #include "config.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
| #include "file.h" | #include "file.h" | ||||||
|  | 
 | ||||||
| using namespace std; | using namespace std; | ||||||
| using namespace log_helper; | using namespace log_helper; | ||||||
| 
 | 
 | ||||||
| @ -81,7 +82,7 @@ static bool daemonize() { | |||||||
| 
 | 
 | ||||||
| std::string log_file_path; | std::string log_file_path; | ||||||
| int main(int argc, char** argv) { | int main(int argc, char** argv) { | ||||||
|     srand((unsigned int) floor<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count()); |     srand((unsigned int) chrono::floor<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count()); | ||||||
| 
 | 
 | ||||||
|     log_file_path = argc > 2 ? argv[1] : "update_installer.log"; |     log_file_path = argc > 2 ? argv[1] : "update_installer.log"; | ||||||
|     //logger::info("Starting log at %s", log_file_path.c_str());
 |     //logger::info("Starting log at %s", log_file_path.c_str());
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user