Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Cam authored Mar 19, 2023
1 parent 0c455d3 commit 20edc0f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,9 @@ Now with app auto profiles !

Run sh install.sh from the directory to install.


## COMMANDS :

`naga start <optional:configName>` //Starts a daemon with the optional config name.
`naga edit <optional:configName>` //Edits naga config, then starts with optional config name.
`naga stop` //stops the daemon.
`naga fix` //Restarts usb services.
`naga uninstall` //Uninstalls the daemon tool.
`naga` //Gives help.


If there is an error about config files just copy it to your /home/.naga/

Run in root if there is an error accessing the device.
Run in root if there is an error accessing the device, also look up naga debug it'll give all the info you need most of the time.

Map razer naga devices keys with the config file : `keyMap.txt` under `$HOME/.naga/`

Expand Down Expand Up @@ -66,21 +55,18 @@ The configuration file `keyMap.txt` has the following syntax:
The possible choices are :
-chmap : Changes the keymap for another config inside `keymap.txt` in ~/.naga .
-champRelease : Changes the keymap on key release.
-keyPress : Runs <command> in xdotool so the possible keys are on google ( i didn't find a list of all the keys ) .
The <command> is run in : **xdotool keydown** or/and **keyup --window getactivewindow <command>** so it's already 'framed' by the program.
By example to play/pause music you can put **key=XF86AudioPlay**.
-sleep and sleepRelease :
Sleeps
-string and stringRelease :
Writes a string, doesn't use xdotool so xdotool keys won't work
-key : does keyPress at press and keyRelease at release
-specialKey : does speical keyPress at press and special keyRelease at release.
-keyPressOnPress :
The xdotool key is pressed when the key is pressed.
-keyReleaseOnRelease :
The xdotool key is released when the key is released.
-keyPressOnRelease :
The xdotool key is pressed when the key is released.
-keyReleaseOnPress :
The xdotool key is released when the key is pressed.
-keyPress :
-keyRelease :
The xdotool key is released when the key is released.
There seems to be a list of keys on https://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h but you need to remove **XK_** and they're not all there so google them if you want to be sure.
-run : Runs the command <command> on key press with setsid before the command.
-run2 : Runs the command without setsid.
Expand All @@ -101,7 +87,7 @@ The configuration file `keyMap.txt` has the following syntax:

To test any <command> run it in the command cited above.

"configEnd" Marks the end of a config.
"configEnd" Marks the end of <configName>.
For a mouseclick run xdotool click <command>) (Can put numbers from 1 to 9 and options such as *--window etc).

Expand Down Expand Up @@ -163,6 +149,18 @@ Since autorun is a bit complicated for all the distros you can simply add nagast

If you ever were to login as root then unlog and log as another user the daemon might ask you for your password to kill the rooted daemon. If the device still doesn't work after root access, unplugging and replugging the device then starting the daemon will surely work.

## Debugging

The commands are :

`naga stop` or `naga kill` //stops the daemon.
`naga start <optional:selectedMapping>` //restart the daemon if there is one running and starts a hidden daemon with the optional key mapping passed as the default config.
`naga debug <optional:selectedMapping>` //restart the daemon if there is one running and starts one in the console for debugging with the optional key mapping passed as the default config.
`naga uninstall` //uninstall the daemon tool
`naga killroot` //kill root daemon if launched as root
`naga` //gives help

For all the double dashed ocd people the commands also works with 2 dashes.

#### In depth

Expand Down
46 changes: 23 additions & 23 deletions src/nagaX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class configKey
const void (*const internalFunction)(const string *const c);

public:
const bool &IsOnKeyPressed() const { return onKeyPressed; }
const bool IsOnKeyPressed() const { return onKeyPressed; }
const void runInternal(const string *const content) const { internalFunction(content); }
const string *const Prefix() const { return prefix; }

configKey(const bool tonKeyPressed, const void (*const tinternalF)(const string *cc) = NULL, const string tcontent = "") : prefix(new string(tcontent)), onKeyPressed(tonKeyPressed), internalFunction(tinternalF)
configKey(const bool tonKeyPressed, const void (*const tinternalF)(const string *const cc), const string tcontent = "") : prefix(new string(tcontent)), onKeyPressed(tonKeyPressed), internalFunction(tinternalF)
{
}
};
Expand All @@ -49,8 +49,8 @@ class MacroEvent
const string *const content;

public:
const configKey *KeyType() const { return keyType; }
const string *Content() const { return content; }
const configKey *const KeyType() const { return keyType; }
const string *const Content() const { return content; }

MacroEvent(const configKey *tkeyType, const string *tcontent) : keyType(tkeyType), content(new string(*tcontent))
{
Expand All @@ -68,23 +68,23 @@ class configSwitchScheduler
public:
vector<string *> configWindowsNamesVector;

const string &RemapString() const
const string *RemapString() const
{
return scheduledReMapString;
return &scheduledReMapString;
}
const string &temporaryWindowName() const
const string *temporaryWindowName() const
{
return temporaryWindowConfigName;
return &temporaryWindowConfigName;
}
const string &getBackupConfigName() const
const string *getBackupConfigName() const
{
return backupConfigName;
return &backupConfigName;
}
const bool &isAWindowConfigActive() const
const bool isAWindowConfigActive() const
{
return aWindowConfigActive;
}
const bool &isRemapScheduled() const
const bool isRemapScheduled() const
{
return scheduledReMap;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ class NagaDaemon

if (isIteratingConfig)
{
if (commandContent.substr(0,10) == "configEnd") // finding configEnd
if (commandContent.substr(0, 10) == "configEnd") // finding configEnd
{
isIteratingConfig = false;
}
Expand Down Expand Up @@ -209,14 +209,14 @@ class NagaDaemon
}
}
}
else if (commandContent.substr(0,13) == "configWindow=")
else if (commandContent.substr(0, 13) == "configWindow=")
{
isIteratingConfig = true;
commandContent.erase(0, 13);
iteratedConfig = &macroEventsKeyMaps[commandContent];
configSwitcher->configWindowsNamesVector.emplace_back(new string(commandContent));
}
else if (commandContent.substr(0,7) == "config=")
else if (commandContent.substr(0, 7) == "config=")
{
isIteratingConfig = true;
commandContent.erase(0, 7);
Expand All @@ -226,20 +226,20 @@ class NagaDaemon
in.close();
}

void loadConf(const string configName, const bool silent = false)
void loadConf(const string *const configName, const bool silent = false)
{
if (!macroEventsKeyMaps.contains(configName))
if (!macroEventsKeyMaps.contains(*configName))
{
clog << "Undefined profile : " << configName << endl;
return;
}
configSwitcher->unScheduleReMap();

currentConfigName = configName;
currentConfigName = *configName;
currentConfigPtr = &macroEventsKeyMaps[currentConfigName];
if (!silent)
{
(void)!(system(("notify-send -t 200 'New config :' '" + configName + "'").c_str()));
(void)!(system(("notify-send -t 200 'New config :' '" + *configName + "'").c_str()));
}
}

Expand All @@ -257,8 +257,8 @@ class NagaDaemon
void checkForWindowConfig()
{
char *c = getActiveWindow();
clog << "CurrentWindowNameLog : " << c << endl;
if (configSwitcher->temporaryWindowName() == "" || strcmp(c, configSwitcher->temporaryWindowName().c_str()) != 0)
clog << "WindowNameLog : " << c << endl;
if (*configSwitcher->temporaryWindowName() == "" || strcmp(c, configSwitcher->temporaryWindowName()->c_str()) != 0)
{
bool found = false;
for (string *configWindowName : (*configSwitcher).configWindowsNamesVector)
Expand All @@ -274,7 +274,7 @@ class NagaDaemon
if (!found && configSwitcher->isAWindowConfigActive())
{
lock_guard<mutex> guard(configSwitcherMutex);
configSwitcher->scheduleReMap(&configSwitcher->getBackupConfigName());
configSwitcher->scheduleReMap(configSwitcher->getBackupConfigName());
loadConf(configSwitcher->RemapString(), true); // change config for macroEvents[ii]->Content()
}
}
Expand Down Expand Up @@ -508,7 +508,7 @@ class NagaDaemon
initConf();

configSwitcher->scheduleReMap(&mapConfig);
loadConf(mapConfig); // Initialize config
loadConf(&mapConfig); // Initialize config
run();
}
};
Expand Down

0 comments on commit 20edc0f

Please sign in to comment.