summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/IPC.cpp16
-rw-r--r--src/IPC.h1
-rw-r--r--src/commands.cpp2
-rw-r--r--src/config.cpp8
-rw-r--r--src/keybinds.cpp2
-rw-r--r--src/main.cpp8
6 files changed, 23 insertions, 14 deletions
diff --git a/src/IPC.cpp b/src/IPC.cpp
index 0aed97e..09bf78e 100644
--- a/src/IPC.cpp
+++ b/src/IPC.cpp
@@ -16,6 +16,10 @@ IPCModule::IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globa
cfg(cfg),
globals(globals)
{
+}
+
+void IPCModule::init()
+{
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
address.sun_family = AF_UNIX;
strcpy(address.sun_path, path);
@@ -27,15 +31,14 @@ IPCModule::IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globa
cout << "ERROR " << errno << endl;
}
cout << "SOCKETED" << endl;
-}
-
-void IPCModule::init()
-{
setIPCPath((unsigned char*)path, strlen(path));
+ ready = true;
}
void IPCModule::doListen()
{
+ if(!ready)
+ return;
if(listen(sockfd, 1) != 0)
{
cout << "ERROR 2" << endl;
@@ -75,11 +78,16 @@ void IPCModule::doListen()
void IPCModule::quitIPC()
{
+ if(!ready)
+ return;
close(sockfd);
+ ready = false;
}
int IPCModule::getFD()
{
+ if(!ready)
+ return -1;
if(sockfd > 0)
return sockfd;
return -1;
diff --git a/src/IPC.h b/src/IPC.h
index 89e67e5..97716bb 100644
--- a/src/IPC.h
+++ b/src/IPC.h
@@ -22,5 +22,6 @@ private:
int sockfd;
int len;
bool first = true;
+ bool ready = false;
sockaddr_un address;
};
diff --git a/src/commands.cpp b/src/commands.cpp
index 57cfd0b..5688da4 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -185,7 +185,7 @@ CommandArg* CommandsModule::getCommandArgs(vector<string>& split, const CommandA
rest += " ";
}
args[i-1].str = new char[rest.size()];
- strcpy(args[i-1].str, rest.c_str());
+ strncpy(args[i-1].str, rest.c_str(), rest.size());
return args;
}
case NUM_ARR_REST:
diff --git a/src/config.cpp b/src/config.cpp
index 3af2491..925e6ea 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -4,13 +4,10 @@
#include <X11/Xlib.h>
-#include <cstdio>
-#include <cstring>
#include <fstream>
-#include <ios>
+#include <ostream>
#include <string>
#include <vector>
-#include <sstream>
#include <unistd.h>
#include <fcntl.h>
@@ -94,9 +91,8 @@ std::vector<Err> Config::loadFromFile(std::string path)
//Probably need something for workspaces and binds too...
- string cmd;
int line = 0;
- while(getline(config, cmd))
+ for(string cmd; std::getline(config, cmd);)
{
line++;
if(cmd.size() == 0)
diff --git a/src/keybinds.cpp b/src/keybinds.cpp
index c41452f..235f8c1 100644
--- a/src/keybinds.cpp
+++ b/src/keybinds.cpp
@@ -12,7 +12,7 @@
#include "keybinds.h"
#include "util.h"
-using std::string;
+using std::string, std::cout, std::endl;
bool Keybind::operator<(const Keybind &o) const {
if(key != o.key)
diff --git a/src/main.cpp b/src/main.cpp
index 77f4dbc..a11b203 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1028,11 +1028,11 @@ int main(int argc, char** argv)
return 0;
}
}
+
//Important init stuff
mX = mY = 0;
dpy = XOpenDisplay(nullptr);
root = Window(DefaultRootWindow(dpy));
-
// Adding commands
commandsModule.addCommand("exit", exit, 0, {});
commandsModule.addCommand("spawn", spawn, 1, {STR_REST});
@@ -1051,6 +1051,8 @@ int main(int argc, char** argv)
//Config
std::vector<Err> cfgErr;
+
+ cout << "Registered commands" << endl;
char* confDir = getenv("XDG_CONFIG_HOME");
if(confDir != NULL)
@@ -1063,6 +1065,8 @@ int main(int argc, char** argv)
cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config");
}
+ cout << "Done config" << endl;
+
//Log
yatlog.open(cfg.logFile, std::ios_base::app);
yatlog << "\n" << endl;
@@ -1119,7 +1123,7 @@ int main(int argc, char** argv)
FD_ZERO(&fdset);
FD_SET(x11fd, &fdset);
FD_SET(ipc.getFD(), &fdset);
- int ready = select(x11fd + 1, &fdset, NULL, NULL, NULL);
+ int ready = select(std::max(x11fd, ipc.getFD()) + 1, &fdset, NULL, NULL, NULL);
if(FD_ISSET(ipc.getFD(), &fdset))
{
ipc.doListen();