Updated some stuff for linux

This commit is contained in:
WolverinDEV 2019-11-03 17:01:21 +01:00
parent 9f4470dacb
commit 81ad9bd9e8
5 changed files with 36 additions and 74 deletions

View File

@ -1,11 +1,12 @@
set(MODULE_NAME "teaclient_ppt")
set(SOURCE_FILES src/KeyboardHook.cpp)
if (MSVC)
set(SOURCE_FILES ${SOURCE_FILES} src/Win32KeyboardHook.cpp)
add_definitions(-DUSING_UV_SHARED)
else()
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()
add_nodejs_module(${MODULE_NAME} binding.cc ${SOURCE_FILES})

View 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);
}

View File

@ -15,21 +15,6 @@ KeyboardHook::~KeyboardHook() {
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() {
assert(!this->_attached);
this->active = true;

View File

@ -6,7 +6,7 @@
#include <iostream>
#include "KeyboardHook.h"
#define ClientMessageMask (1L<<24)
#define ClientMessageMask (1L << 24)
#define SelectMask (KeyPressMask | KeyReleaseMask | FocusChangeMask | ClientMessageMask)
using namespace std;
@ -63,15 +63,15 @@ bool KeyboardHook::attach() {
//XGrabKeyboard(this->display, this->window_focused, false, GrabModeAsync, GrabModeAsync, CurrentTime);
}
XSetErrorHandler([](Display* display, XErrorEvent* event) {
XSetErrorHandler([](Display* dp, XErrorEvent* event) {
if(event->type == BadWindow)
return 0;
/*
* X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 2 (X_ChangeWindowAttributes)
Resource id in failed request: 0x0
Serial number of failed request: 32
Current serial number in output stream: 32
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 2 (X_ChangeWindowAttributes)
Resource id in failed request: 0x0
Serial number of failed request: 32
Current serial number in output stream: 32
*/
cerr << "Caught X11 error: " << event->type << endl;
return 0;
@ -146,40 +146,9 @@ void KeyboardHook::poll_events() {
else
this->map_special[type] = key_sym;
if (this->callback_event) {
if(!typed) {
auto e = make_shared<KeyboardHook::KeyEvent>();
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);
}
}
if(!typed)
this->trigger_key_event(KeyEvent::PRESS, type == KeyType::KEY_NORMAL ? XKeysymToString(key_sym) : XKeysymToString(this->map_special[KeyType::KEY_NORMAL]));
this->trigger_key_event(KeyEvent::TYPE, type == KeyType::KEY_NORMAL ? XKeysymToString(key_sym) : XKeysymToString(this->map_special[KeyType::KEY_NORMAL]));
} else if(event.type == KeyRelease) {
auto key_sym = XLookupKeysym(&event.xkey, 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)
this->map_special[KeyType::KEY_NORMAL] = XK_VoidSymbol;
if (this->callback_event) {
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);
}
this->trigger_key_event(KeyEvent::RELEASE, type == KeyType::KEY_NORMAL ? XKeysymToString(key_sym) : XKeysymToString(this->map_special[KeyType::KEY_NORMAL]));
} else if(event.type == ClientMessage) {
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;
} else if(event.type == ButtonPress) {
cout << "Got button" << endl;
} else if(event.type == ButtonRelease) {
cout << "Got button" << endl;
} else {
cerr << "Got unknown event of type " << event.type << endl;
}

View File

@ -7,6 +7,7 @@
#include "config.h"
#include "util.h"
#include "file.h"
using namespace std;
using namespace log_helper;
@ -81,7 +82,7 @@ static bool daemonize() {
std::string log_file_path;
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";
//logger::info("Starting log at %s", log_file_path.c_str());