Skip to content

Commit

Permalink
Fix and update Wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
Cam authored Feb 15, 2024
1 parent 18aa458 commit 3a9d68f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Works for sure with :
`naga start` //Starts a daemon.
`naga edit ($EDITOR)` //Edits naga config, then restart service if edited.
(you can also specify editor : naga edit vim)
`naga debug` //Shows logs in realt time.
`naga debug` //Shows logs in realt time. (Add arg to override journalctl's args.)
`naga stop` //Stops the daemon.
`naga fix` //Restarts usb services.
`naga uninstall` //Uninstalls the daemon tool.
Expand Down
4 changes: 4 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ printf 'KERNEL=="event[0-9]*",SUBSYSTEM=="input",GROUP="razerInputGroup",MODE="6
LOGINTYPE=$(loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type)
if [ "$LOGINTYPE" = "Type=wayland" ]; then
sh ./src/_installWayland.sh
sed -i '/alias naga=/d' ~/.bash_aliases
grep 'alias naga=' ~/.bash_aliases || printf "alias naga='nagaWayland'" | tee -a ~/.bash_aliases > /dev/null
else
sh ./src/_installX11.sh
sudo sed -i '/alias naga=/d' ~/.bash_aliases
grep 'alias naga=' ~/.bash_aliases || printf "alias naga='nagaX11'" | tee -a ~/.bash_aliases > /dev/null
fi

if [ "$LOGINTYPE" = "Type=wayland" ]; then
Expand Down
16 changes: 8 additions & 8 deletions src/_installWayland.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

sudo apt install -y g++ nano pkexec procps wget gnome-shell-extension-prefs dbus-x11 curl libdbus-1-dev
sudo apt install -y g++ nano pkexec procps wget gnome-shell-extension-prefs dbus-x11 curl libdbus-1-dev libxkbcommon-dev

echo "Checking requirements..."

Expand All @@ -26,14 +26,16 @@ sudo chmod 755 /usr/local/bin/nagaWayland

echo "Installing dotool :"

wget https://git.sr.ht/~geb/dotool/archive/874650ad22dfb20ef24ab1f78666aa2e5178a0f0.tar.gz -O dotool.tar.gz
sleep 1
wget https://git.sr.ht/~geb/dotool/archive/b5812c001daeeaff1f259031661e47f3a612220c.tar.gz -O dotool.tar.gz
tar -xf dotool.tar.gz > /dev/null
mv -f dotool-874650ad22dfb20ef24ab1f78666aa2e5178a0f0 dotool > /dev/null
mv -fu dotool-b5812c001daeeaff1f259031661e47f3a612220c dotool > /dev/null
sleep 1
cd dotool
sudo sh install.sh > /dev/null
./build.sh
sudo ./build.sh install
cd ..
#rm -rdf dotool
rm -f dotool.tar.gz > /dev/null
rm -rf dotool* > /dev/null


cp -rf ./src/[email protected] ~/.local/share/gnome-shell/extensions
Expand All @@ -47,5 +49,3 @@ sudo chown -R "root:root" "$_dir"/keyMapWayland.txt
sudo groupadd -f razerInputGroup

printf 'KERNEL=="uinput", GROUP="razerInputGroup"' | sudo tee /etc/udev/rules.d/80-nagaWayland.rules >/dev/null

grep 'alias naga=' ~/.bash_aliases || printf "alias naga='nagaWayland'" | tee -a ~/.bash_aliases > /dev/null
5 changes: 1 addition & 4 deletions src/_installX11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,4 @@ sudo chmod 755 /usr/local/bin/nagaX11
_dir="/home/$USER/.naga"
mkdir -p "$_dir"
sudo cp -r -n -v "keyMap.txt" "$_dir"
sudo chown -R "root:root" "$_dir"/keyMap.txt


grep 'alias naga=' ~/.bash_aliases || printf "alias naga='nagaX11'" | tee -a ~/.bash_aliases > /dev/null
sudo chown -R "root:root" "$_dir"/keyMap.txt
2 changes: 1 addition & 1 deletion src/nagaServerCatcher.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
#Finds the visual server and starts the right one
if [ "$(loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type)" = "Type=wayland" ]; then
killall dotoold
killall dotoold > /dev/null 2>&1
setsid bash -c 'dotoold'&
if [ $# -eq 0 ]; then
nagaWayland serviceHelper
Expand Down
36 changes: 24 additions & 12 deletions src/nagaWayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ static const string getTitle()
DBusConnection *connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
if (dbus_error_is_set(&error))
{
std::cerr << "Error connecting to bus: " << error.message << std::endl;
cerr << "Error connecting to bus: " << error.message << endl;
dbus_error_free(&error);
return "";
}

DBusMessage *message = dbus_message_new_method_call(DB_DESTINATION, DB_PATH, DB_INTERFACE, DB_METHOD);
if (message == nullptr)
{
std::cerr << "Error creating message" << std::endl;
cerr << "Error creating message" << endl;
return "";
}

DBusMessage *reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error);
if (dbus_error_is_set(&error))
{
std::cerr << "Error calling method: " << error.message << std::endl;
cerr << "Error calling method: " << error.message << endl;
dbus_error_free(&error);
return "";
}

char *result;
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID))
{
std::cerr << "Error reading reply: " << error.message << std::endl;
cerr << "Error reading reply: " << error.message << endl;
dbus_error_free(&error);
return "";
}
Expand Down Expand Up @@ -143,6 +143,7 @@ class configSwitchScheduler
loadConf(true);
}
}

}
void remapRoutine()
{
Expand All @@ -161,6 +162,7 @@ class configSwitchScheduler
}
void scheduleReMap(const string *const reMapStr)
{
clog << "Remap Routine"<<endl;
lock_guard<mutex> guard(configSwitcherMutex);
if (winConfigActive)
{
Expand Down Expand Up @@ -197,12 +199,11 @@ class NagaDaemon
const int size = sizeof(ev1);
vector<pair<const char *const, const char *const>> devices;
bool areSideBtnEnabled = true, areExtraBtnEnabled = true;
map<int, std::map<bool, vector<MacroEvent *>>> *currentConfigPtr;

void initConf()
{
string commandContent;
map<int, std::map<bool, vector<MacroEvent *>>> *iteratedConfig;
map<int, map<bool, vector<MacroEvent *>>> *iteratedConfig;
bool isIteratingConfig = false;

ifstream in(conf_file.c_str(), ios::in);
Expand Down Expand Up @@ -255,13 +256,16 @@ class NagaDaemon
if (!configKeysMap[commandType]->Prefix()->empty())
commandContent = *configKeysMap[commandType]->Prefix() + commandContent;

if (!configKeysMap[commandType]->Suffix()->empty())
commandContent = commandContent + *configKeysMap[commandType]->Suffix();

(*iteratedButtonConfig)[configKeysMap[commandType]->IsOnKeyPressed()].emplace_back(new MacroEvent(configKeysMap[commandType], new string(commandContent)));
// Encode and store mapping v3
}
else if (commandType == "key")
{
string *commandContent2 = new string(*configKeysMap["keyreleaseonrelease"]->Prefix() + commandContent);
commandContent = *configKeysMap["keypressonpress"]->Prefix() + commandContent;
string *commandContent2 = new string(*configKeysMap["keyreleaseonrelease"]->Prefix() + commandContent + *configKeysMap["keyreleaseonrelease"]->Suffix());
commandContent = *configKeysMap["keypressonpress"]->Prefix() + commandContent + *configKeysMap["keypressonpress"]->Suffix();
(*iteratedButtonConfig)[true].emplace_back(new MacroEvent(configKeysMap["keypressonpress"], new string(commandContent)));
(*iteratedButtonConfig)[false].emplace_back(new MacroEvent(configKeysMap["keyreleaseonrelease"], new string(*commandContent2)));
}
Expand Down Expand Up @@ -321,7 +325,7 @@ class NagaDaemon
{
case 2 ... 13:
configSwitcher->checkForWindowConfig();
thread(runActions, &(*currentConfigPtr)[ev11->code][ev11->value == 1]).detach(); // real key number = ev11->code - 1
thread(runActions, &(*configSwitcher->currentConfigPtr)[ev11->code][ev11->value == 1]).detach(); // real key number = ev11->code - 1
break;
}
}
Expand All @@ -336,7 +340,7 @@ class NagaDaemon
{
case 275 ... 276:
configSwitcher->checkForWindowConfig();
thread(runActions, &(*currentConfigPtr)[ev11->code - 261][ev11->value == 1]).detach(); // real key number = ev11->code - OFFSET (#262)
thread(runActions, &(*configSwitcher->currentConfigPtr)[ev11->code - 261][ev11->value == 1]).detach(); // real key number = ev11->code - OFFSET (#262)
break;
}
}
Expand Down Expand Up @@ -388,6 +392,7 @@ class NagaDaemon
const static void executeThreadNow(const string *const macroContent)
{
thread(executeNow, macroContent).detach();
clog<<"EXECUTED : "<< macroContent->c_str() << endl;
}
// end of configKeys functions

Expand All @@ -399,7 +404,7 @@ class NagaDaemon
}
}

void emplaceConfigKey(const std::string &key, bool onKeyPressed, auto functionPtr, const std::string &prefix = "", const std::string &suffix = "")
void emplaceConfigKey(const string &key, bool onKeyPressed, auto functionPtr, const string &prefix = "", const string &suffix = "")
{
configKeysMap.emplace(key, new configKey(onKeyPressed, functionPtr, prefix, suffix));
}
Expand Down Expand Up @@ -522,7 +527,14 @@ int main(const int argc, const char *const argv[])
else if (strstr(argv[1], "debug") != NULL)
{
clog << "Starting naga debug, logs :" << endl;
(void)!(system("journalctl -fu naga"));
if (argc > 2)
{
(void)!(system(("journalctl " + string(argv[2]) + " naga").c_str()));
}
else
{
(void)!(system("journalctl -fu naga"));
}
}
else if (strstr(argv[1], "kill") != NULL || strstr(argv[1], "stop") != NULL)
{
Expand Down
9 changes: 8 additions & 1 deletion src/nagaX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,14 @@ int main(const int argc, const char *const argv[])
else if (strstr(argv[1], "debug") != NULL)
{
clog << "Starting naga debug, logs :" << endl;
(void)!(system("journalctl -fu naga"));
if (argc > 2)
{
(void)!(system(("journalctl " + string(argv[2]) + " naga").c_str()));
}
else
{
(void)!(system("journalctl -fu naga"));
}
}
else if (strstr(argv[1], "kill") != NULL || strstr(argv[1], "stop") != NULL)
{
Expand Down
4 changes: 2 additions & 2 deletions src/[email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

/* exported init */

const { Gio } = imports.gi;
import Gio from 'gi://Gio';

const MR_DBUS_IFACE = `
<node>
Expand All @@ -38,7 +38,7 @@ const MR_DBUS_IFACE = `
</interface>
</node>`;

class Extension {
export default class WCExtension {
enable() {
this._dbus = Gio.DBusExportedObject.wrapJSObject(MR_DBUS_IFACE, this);
this._dbus.export(Gio.DBus.session, '/org/gnome/Shell/Extensions/WindowsExt');
Expand Down

0 comments on commit 3a9d68f

Please sign in to comment.