diff --git a/install.sh b/install.sh index 705288e..a1795cf 100755 --- a/install.sh +++ b/install.sh @@ -16,8 +16,8 @@ command -v g++ >/dev/null 2>&1 || { tput setaf 1; echo >&2 "I require g++ but it reset echo "Compiling code..." -cd src -g++ naga.cpp -o naga -pthread -Ofast --std=c++2a -lX11 -lXtst -lXmu +cd src || exit +g++ nagaX11.cpp -o naga -pthread -Ofast --std=c++2b -lX11 -lXtst -lXmu if [ ! -f ./naga ]; then tput setaf 1; echo "Error at compile! Ensure you have g++ installed. !!!Aborting!!!" @@ -47,11 +47,11 @@ for u in $(sudo awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/pa do sudo gpasswd -a "$u" razer _dir="/home/${u}/.naga" - sudo mkdir -p $_dir + sudo mkdir -p "$_dir" if [ -d "$_dir" ] then sudo cp -r -n -v "keyMap.txt" "$_dir" - sudo chown -R $(id -un $u):users "$_dir" + sudo chown -R "$(id -un "$u"):users" "$_dir" fi done if [ -d "/root" ]; @@ -67,5 +67,5 @@ sudo mv /tmp/80-naga.rules /etc/udev/rules.d/80-naga.rules naga start -tput setaf 2; echo "Please add (naga.desktop or a script with naga start) to be executed\nwhen your window manager starts." +tput setaf 2; printf "Please add (naga.desktop or a script with naga start) to be executed\nwhen your window manager starts." tput sgr0; diff --git a/keyMap.txt b/keyMap.txt index 530d0a8..9c22c4e 100644 --- a/keyMap.txt +++ b/keyMap.txt @@ -54,6 +54,8 @@ configWindow=Gnome-terminal 3 - string=gnome@terminal.com 4 - run2=if [ $(pgrep -c spotify) -eq 0 ]; then setsid spotify; fi 5 - run=gnome-terminal +6 - specialPressOnPress=È +6 - specialReleaseOnRelease=È 7 - key=XF86AudioLowerVolume 8 - key=XF86AudioPlay 9 - key=XF86AudioRaiseVolume diff --git a/src/fakeKeys.hpp b/src/fakeKeysX11.hpp similarity index 99% rename from src/fakeKeys.hpp rename to src/fakeKeysX11.hpp index a330a09..df7beb9 100644 --- a/src/fakeKeys.hpp +++ b/src/fakeKeysX11.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #define N_MODIFIER_INDEXES (Mod5MapIndex + 1) diff --git a/src/getactivewindow.hpp b/src/getactivewindowX11.hpp similarity index 100% rename from src/getactivewindow.hpp rename to src/getactivewindowX11.hpp diff --git a/src/naga.cpp b/src/nagaX11.cpp similarity index 94% rename from src/naga.cpp rename to src/nagaX11.cpp index 774b323..50ead44 100644 --- a/src/naga.cpp +++ b/src/nagaX11.cpp @@ -2,8 +2,8 @@ // RaulPPelaez, et. al wrote the original file. As long as you retain this notice you // can do whatever you want with this stuff. -#include "fakeKeys.hpp" -#include "getactivewindow.hpp" +#include "fakeKeysX11.hpp" +#include "getactivewindowX11.hpp" #include #include #include @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -232,9 +231,8 @@ class NagaDaemon } const string *const commandContent2 = new string(*configKeysMap["keyreleaseonrelease"]->Prefix() + commandContent); commandContent = *configKeysMap["keypressonpress"]->Prefix() + commandContent; - map *const mEKMCB = ¯oEventsKeyMaps[configName][stoiNumber(buttonNumber)]; - (*mEKMCB)[true].emplace_back(new MacroEvent(configKeysMap["keypressonpress"], &commandContent)); - (*mEKMCB)[false].emplace_back(new MacroEvent(configKeysMap["keyreleaseonrelease"], commandContent2)); + macroEventsKeyMaps[configName][stoiNumber(buttonNumber)][true].emplace_back(new MacroEvent(configKeysMap["keypressonpress"], &commandContent)); + macroEventsKeyMaps[configName][stoiNumber(buttonNumber)][false].emplace_back(new MacroEvent(configKeysMap["keyreleaseonrelease"], commandContent2)); } } } @@ -258,21 +256,13 @@ class NagaDaemon input_event *ev11; fd_set readset; - void checkForWindowConfig() + bool checkForWindowConfig() { - char *c; - try - { - c = getActiveWindow(); - } - catch (...) - { - return; - } + char *c = getActiveWindow(); clog << "CurrentWindowNameLog : " << c << endl; - bool found = false; if (configSwitcher->temporaryWindowName() == "" || strcmp(c, configSwitcher->temporaryWindowName().c_str()) != 0) { + bool found = false; for (string *configWindowName : (*configSwitcher).configWindowsNamesVector) { if (strcmp(c, configWindowName->c_str()) == 0) @@ -281,7 +271,7 @@ class NagaDaemon configSwitcher->scheduleWindowReMap(configWindowName); loadConf(configSwitcher->RemapString(), true); // change config for macroEvents[ii]->Content() found = true; - break; + return true; } } if (!found && configSwitcher->isAWindowConfigActive()) @@ -289,12 +279,16 @@ class NagaDaemon lock_guard guard(configSwitcherMutex); configSwitcher->scheduleReMap(&configSwitcher->getBackupConfigName()); loadConf(configSwitcher->RemapString(), true); // change config for macroEvents[ii]->Content() - } + return true; + } } + return false; } void run() { + map> currenConfigPtr = macroEventsKeyMaps[currentConfigName]; + if (areSideBtnEnabled) ioctl(side_btn_fd, EVIOCGRAB, 1); // Give application exclusive control over side buttons. ev11 = &ev1[1]; @@ -304,6 +298,7 @@ class NagaDaemon { lock_guard guard(configSwitcherMutex); // remap loadConf(configSwitcher->RemapString()); // change config for macroEvents[ii]->Content() + currenConfigPtr = macroEventsKeyMaps[currentConfigName]; } FD_ZERO(&readset); @@ -333,8 +328,9 @@ class NagaDaemon case 11: case 12: case 13: - checkForWindowConfig(); - thread(runActions, ¯oEventsKeyMaps[currentConfigName][ev11->code - 1][ev11->value == 1]).detach(); // real key number = ev11->code - 1 + if (checkForWindowConfig()) + currenConfigPtr = macroEventsKeyMaps[currentConfigName]; + thread(runActions, ¤ConfigPtr[ev11->code - 1][ev11->value == 1]).detach(); // real key number = ev11->code - 1 break; } } @@ -349,10 +345,9 @@ class NagaDaemon { case 275: case 276: - case 277: - case 278: - checkForWindowConfig(); - thread(runActions, ¯oEventsKeyMaps[currentConfigName][ev11->code - 262][ev11->value == 1]).detach(); // real key number = ev11->code - OFFSET (#262) + if (checkForWindowConfig()) + currenConfigPtr = macroEventsKeyMaps[currentConfigName]; + thread(runActions, ¤ConfigPtr[ev11->code - 262][ev11->value == 1]).detach(); // real key number = ev11->code - OFFSET (#262) break; } } diff --git a/src/nagaXinputStart.sh b/src/nagaXinputStart.sh index 2b7cc37..132ddf9 100644 --- a/src/nagaXinputStart.sh +++ b/src/nagaXinputStart.sh @@ -1,11 +1,11 @@ -#!/bin/bash +#!/bin/sh NAGAID2=$(xinput | grep Naga | grep pointer | cut -d= -f2 | cut -f1) -if [[ `echo $NAGAID2 | wc -w` -eq 2 ]]; then - if [[ `xinput get-button-map $(echo $NAGAID2 | awk '{print $1}') | grep 10 | wc -l` -eq 1 ]]; then - xinput set-button-map $(echo $NAGAID2 | awk '{print $1}') 1 2 3 4 5 6 7 11 10 8 9 13 14 15 275 276 +if [ "$(echo "$NAGAID2" | wc -w)" -eq "2" ]; then + if [ "$(xinput get-button-map "$(echo "$NAGAID2" | head -n 1)" | grep -c 10)" -eq 1 ]; then + xinput set-button-map "$(echo "$NAGAID2" | head -n 1)" 1 2 3 4 5 6 7 11 10 8 9 13 14 15 275 276 else - xinput set-button-map $(echo $NAGAID2 | awk '{print $2}') 1 2 3 4 5 6 7 11 10 8 9 13 14 15 275 276 + xinput set-button-map "$(echo "$NAGAID2" | tail -n 1)" 1 2 3 4 5 6 7 11 10 8 9 13 14 15 275 276 fi else - xinput set-button-map $NAGAID2 1 2 3 4 5 6 7 11 10 8 9 13 14 15 275 276 + xinput set-button-map "$NAGAID2" 1 2 3 4 5 6 7 11 10 8 9 13 14 15 275 276 fi