Skip to content

Commit

Permalink
Merge pull request #27 from lostallmymoney/lostallmymoney-patch-1
Browse files Browse the repository at this point in the history
Lostallmymoney patch 1
  • Loading branch information
Cam authored Mar 18, 2023
2 parents 218f1b9 + d94273d commit 1e4509e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 37 deletions.
10 changes: 5 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!"
Expand Down Expand Up @@ -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" ];
Expand All @@ -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;
2 changes: 2 additions & 0 deletions keyMap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ configWindow=Gnome-terminal
3 - [email protected]
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
Expand Down
2 changes: 1 addition & 1 deletion src/fakeKeys.hpp → src/fakeKeysX11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <X11/XKBlib.h>
#include <X11/extensions/XTest.h>

#include <cstring>
#include <string.h>
#include <stdlib.h>

#define N_MODIFIER_INDEXES (Mod5MapIndex + 1)
Expand Down
File renamed without changes.
45 changes: 20 additions & 25 deletions src/naga.cpp → src/nagaX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// 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 <algorithm>
#include <iostream>
#include <vector>
#include <fstream>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
#include <cstring>
#include <thread>
#include <mutex>
#include <map>
Expand Down Expand Up @@ -232,9 +231,8 @@ class NagaDaemon
}
const string *const commandContent2 = new string(*configKeysMap["keyreleaseonrelease"]->Prefix() + commandContent);
commandContent = *configKeysMap["keypressonpress"]->Prefix() + commandContent;
map<bool, MacroEventVector> *const mEKMCB = &macroEventsKeyMaps[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));
}
}
}
Expand All @@ -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)
Expand All @@ -281,20 +271,24 @@ class NagaDaemon
configSwitcher->scheduleWindowReMap(configWindowName);
loadConf(configSwitcher->RemapString(), true); // change config for macroEvents[ii]->Content()
found = true;
break;
return true;
}
}
if (!found && configSwitcher->isAWindowConfigActive())
{
lock_guard<mutex> guard(configSwitcherMutex);
configSwitcher->scheduleReMap(&configSwitcher->getBackupConfigName());
loadConf(configSwitcher->RemapString(), true); // change config for macroEvents[ii]->Content()
}
return true;
}
}
return false;
}

void run()
{
map<int, std::map<bool, MacroEventVector>> currenConfigPtr = macroEventsKeyMaps[currentConfigName];

if (areSideBtnEnabled)
ioctl(side_btn_fd, EVIOCGRAB, 1); // Give application exclusive control over side buttons.
ev11 = &ev1[1];
Expand All @@ -304,6 +298,7 @@ class NagaDaemon
{
lock_guard<mutex> guard(configSwitcherMutex); // remap
loadConf(configSwitcher->RemapString()); // change config for macroEvents[ii]->Content()
currenConfigPtr = macroEventsKeyMaps[currentConfigName];
}

FD_ZERO(&readset);
Expand Down Expand Up @@ -333,8 +328,9 @@ class NagaDaemon
case 11:
case 12:
case 13:
checkForWindowConfig();
thread(runActions, &macroEventsKeyMaps[currentConfigName][ev11->code - 1][ev11->value == 1]).detach(); // real key number = ev11->code - 1
if (checkForWindowConfig())
currenConfigPtr = macroEventsKeyMaps[currentConfigName];
thread(runActions, &currenConfigPtr[ev11->code - 1][ev11->value == 1]).detach(); // real key number = ev11->code - 1
break;
}
}
Expand All @@ -349,10 +345,9 @@ class NagaDaemon
{
case 275:
case 276:
case 277:
case 278:
checkForWindowConfig();
thread(runActions, &macroEventsKeyMaps[currentConfigName][ev11->code - 262][ev11->value == 1]).detach(); // real key number = ev11->code - OFFSET (#262)
if (checkForWindowConfig())
currenConfigPtr = macroEventsKeyMaps[currentConfigName];
thread(runActions, &currenConfigPtr[ev11->code - 262][ev11->value == 1]).detach(); // real key number = ev11->code - OFFSET (#262)
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/nagaXinputStart.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1e4509e

Please sign in to comment.