summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.cpp59
-rw-r--r--main.cpp93
-rw-r--r--makefile3
-rw-r--r--util.cpp17
-rw-r--r--util.h10
5 files changed, 106 insertions, 76 deletions
diff --git a/config.cpp b/config.cpp
index 097287c..5934f21 100644
--- a/config.cpp
+++ b/config.cpp
@@ -1,5 +1,7 @@
#include "config.h"
+#include "util.h"
+
#include <X11/Xlib.h>
#include <string>
@@ -15,38 +17,19 @@ using std::map, std::string;
// For testing
using std::cout, std::endl, std::cerr;
-void exit(const KeyArg arg)
-{
- cout << "exit called" << endl;
-}
-void spawn(const KeyArg arg)
-{
- cout << "spawn called " << arg.str << endl;
-}
-void changeWS(const KeyArg arg)
-{
- cout << "changeWS called" << endl;
-}
-void wToWS(const KeyArg arg)
-{
- cout << "wToWS called" << endl;
-}
-void focChange(const KeyArg arg)
-{
- cout << "focChange called" << endl;
-}
-void reload(const KeyArg arg)
-{
- cout << "reload called" << endl;
-}
-
map<string, void(*) (const KeyArg arg)> funcNameMap = {
{"exit", exit},
{"spawn", spawn},
+ {"toggle", toggle},
+ {"kill", kill},
{"changeWS", changeWS},
{"wToWS", wToWS},
{"focChange", focChange},
- {"reload", reload}
+ {"wMove", wMove},
+ {"bashSpawn", bashSpawn},
+ {"reload", reload},
+ {"wsDump", wsDump},
+ {"nextMonitor", nextMonitor},
};
@@ -54,18 +37,6 @@ Config::Config()
{
}
-std::vector<string> split (const string &s, char delim) {
- std::vector<string> result;
- std::stringstream ss (s);
- string item;
-
- while (getline (ss, item, delim)) {
- result.push_back (item);
- }
-
- return result;
-}
-
void Config::loadFromFile(string path)
{
//free();
@@ -144,22 +115,30 @@ void Config::loadFromFile(string path)
}
//Keybinds
+ bool swapSuperAlt = tbl["Keybinds"]["swapSuperAlt"].value_or<bool>(false);
bindsc = tbl["Keybinds"]["key"].as_array()->size();
binds = new KeyBind[bindsc];
for(int i = 0; i < bindsc; i++)
{
KeyBind bind;
+ bind.modifiers = 0;
const string bindString = *tbl["Keybinds"]["key"][i]["bind"].value<string>();
std::vector<string> keys = split(bindString, '+');
for(string key : keys)
{
if(key == "mod")
{
- bind.modifiers |= Mod4Mask;
+ if(!swapSuperAlt)
+ bind.modifiers |= Mod4Mask;
+ else
+ bind.modifiers |= Mod1Mask;
}
else if(key == "alt")
{
- bind.modifiers |= Mod1Mask;
+ if(swapSuperAlt)
+ bind.modifiers |= Mod4Mask;
+ else
+ bind.modifiers |= Mod1Mask;
}
else if(key == "shift")
{
diff --git a/main.cpp b/main.cpp
index ebec3f2..ff49223 100644
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,8 @@
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
+#include <toml++/toml.hpp>
+
#include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
#include <chrono>
@@ -22,11 +24,10 @@
#include <fcntl.h>
#include "structs.h"
+#include "config.h"
#include "util.h"
#include "ewmh.h"
-#include "config.h"
-
using std::cout;
using std::map;
using std::pair;
@@ -36,6 +37,8 @@ std::ofstream yatlog;
#define log(x) yatlog << x << std::endl
+Config cfg;
+
Display* dpy;
Window root;
int sW, sH;
@@ -110,9 +113,9 @@ void detectScreens()
log("\t\tw: " << screens[i].w << ", h: " << screens[i].h);
XFree(name);
}
- for(int i = 0; i < numWS; i++)
+ for(int i = 0; i < cfg.numWS; i++)
{
- if(screenPreferences[i][0] < nscreens && focusedWorkspaces[screenPreferences[i][0]] == 0)
+ if(cfg.screenPreferences[i][0] < nscreens && focusedWorkspaces[cfg.screenPreferences[i][0]] == 0)
{
//focusedWorkspaces[screenPreferences[i][0]] = i+1;
}
@@ -162,7 +165,14 @@ void spawn(const KeyArg arg)
int null = open("/dev/null", O_WRONLY);
dup2(null, 1);
dup2(null, 2);
- execvp((char*)arg.str[0], (char**)arg.str);
+ const std::string argsStr = arg.str;
+ vector<std::string> args = split(argsStr, ' ');
+ char** execvpArgs = new char*[args.size()];
+ for(int i = 0; i < args.size(); i++)
+ {
+ execvpArgs[i] = strdup(args[i].c_str());
+ }
+ execvp(execvpArgs[0], execvpArgs);
exit(0);
}
}
@@ -212,19 +222,19 @@ void changeWS(const KeyArg arg)
//log("Changing WS with keybind");
- for(int i = 0; i < maxMonitors; i++)
+ for(int i = 0; i < cfg.maxMonitors; i++)
{
- if(nscreens > screenPreferences[arg.num - 1][i])
+ if(nscreens > cfg.screenPreferences[arg.num - 1][i])
{
- int screen = screenPreferences[arg.num - 1][i];
+ int screen = cfg.screenPreferences[arg.num - 1][i];
//log("Found screen (screen " << screenPreferences[arg.num - 1][i] << ")");
- prevWS = focusedWorkspaces[screenPreferences[arg.num - 1][i]];
+ prevWS = focusedWorkspaces[cfg.screenPreferences[arg.num - 1][i]];
//log("Changed prevWS");
- focusedWorkspaces[screenPreferences[arg.num - 1][i]] = arg.num;
+ focusedWorkspaces[cfg.screenPreferences[arg.num - 1][i]] = arg.num;
//log("Changed focusedWorkspaces");
- if(focusedScreen != screenPreferences[arg.num - 1][i])
+ if(focusedScreen != cfg.screenPreferences[arg.num - 1][i])
{
- focusedScreen = screenPreferences[arg.num - 1][i];
+ focusedScreen = cfg.screenPreferences[arg.num - 1][i];
XWarpPointer(dpy, root, root, 0, 0, 0, 0, screens[screen].x + screens[screen].w/2, screens[screen].y + screens[screen].h/2);
}
//log("Changed focusedScreen");
@@ -235,7 +245,7 @@ void changeWS(const KeyArg arg)
//log("Finished changes");
//log(prevWS);
- if(prevWS < 1 || prevWS > numWS)
+ if(prevWS < 1 || prevWS > cfg.numWS)
{
//untile(prevWS);
}
@@ -322,8 +332,8 @@ int dirFind(int fID, MoveDir dir)
{
case Up: i--; break;
case Down: i++; break;
- case Left: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
- case Right: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
+ case Left: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
+ case Right: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
}
}
else if(pDir == horizontal)
@@ -332,8 +342,8 @@ int dirFind(int fID, MoveDir dir)
{
case Left: i--; break;
case Right: i++; break;
- case Up: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
- case Down: return (frames.find(fID)->second.pID > numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
+ case Up: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
+ case Down: return (frames.find(fID)->second.pID > cfg.numWS)? dirFind(frames.find(fID)->second.pID, dir) : fID;
}
}
if(i < 0)
@@ -449,7 +459,7 @@ void bashSpawn(const KeyArg arg)
int null = open("/dev/null", O_WRONLY);
dup2(null, 1);
dup2(null, 2);
- system(arg.str[0]);
+ system(arg.str);
exit(0);
}
@@ -488,12 +498,14 @@ void keyPress(XKeyEvent e)
{
if(e.same_screen!=1) return;
updateMousePos();
+ cout << "Keypress recieved\n";
KeySym keysym = XLookupKeysym(&e, 0);
- for(int i = 0; i < sizeof(keyBinds)/sizeof(keyBinds[0]); i++)
+ cout << "\t" << XKeysymToString(keysym) << " super: " << ((e.state & Mod4Mask) == Mod4Mask) << " alt: " << ((e.state & Mod1Mask) == Mod1Mask) << " shift: " << ((e.state & ShiftMask) == ShiftMask) << std::endl;
+ for(int i = 0; i < cfg.bindsc; i++)
{
- if(keyBinds[i].keysym == keysym && e.state == keyBinds[i].modifiers)
+ if(cfg.binds[i].keysym == keysym)// && e.state == cfg.binds[i].modifiers)
{
- keyBinds[i].function(keyBinds[i].arg);
+ cfg.binds[i].func(cfg.binds[i].args);
}
}
}
@@ -775,7 +787,7 @@ void tileRoots()
{
for(int i = 0; i < nscreens; i++)
{
- tile(focusedWorkspaces[i], screens[i].x + outerGaps, screens[i].y + outerGaps, screens[i].w - outerGaps*2, screens[i].h - outerGaps*2 - bH);
+ tile(focusedWorkspaces[i], screens[i].x + cfg.outerGaps, screens[i].y + cfg.outerGaps, screens[i].w - cfg.outerGaps*2, screens[i].h - cfg.outerGaps*2 - bH);
}
}
void untileRoots()
@@ -813,10 +825,10 @@ void tile(int frameID, int x, int y, int w, int h)
tile(fID, wX, wY, wW, wH);
continue;
}
- wX += gaps;
- wY += gaps;
- wW -= gaps * 2;
- wH -= gaps * 2;
+ wX += cfg.gaps;
+ wY += cfg.gaps;
+ wW -= cfg.gaps * 2;
+ wH -= cfg.gaps * 2;
Client c = clients.find(f.cID)->second;
XMapWindow(dpy, c.w);
XMoveWindow(dpy, c.w,
@@ -850,11 +862,24 @@ void untile(int frameID)
int main(int argc, char** argv)
{
+ std::string home = getenv("HOME");
+ std::string pathAfterHome = "/.config/YATwm/config.toml";
+ std::string file = home + pathAfterHome;
+ try
+ {
+ cfg.loadFromFile(file);
+ }
+ catch (const toml::parse_error& err)
+ {
+ std::cerr << "Parsing failed:\n" << err << "\n";
+ return 1;
+ }
+
mX = mY = 0;
dpy = XOpenDisplay(nullptr);
root = Window(DefaultRootWindow(dpy));
- yatlog.open(logFile, std::ios_base::app);
+ yatlog.open(cfg.logFile, std::ios_base::app);
auto timeUnformatted = std::chrono::system_clock::now();
std::time_t time = std::chrono::system_clock::to_time_t(timeUnformatted);
@@ -871,28 +896,28 @@ int main(int argc, char** argv)
XSetErrorHandler(OnXError);
XSelectInput(dpy, root, SubstructureRedirectMask | SubstructureNotifyMask | KeyPressMask | EnterWindowMask);
- for(int i = 0; i < sizeof(keyBinds)/sizeof(keyBinds[0]); i++)
+ for(int i = 0; i < cfg.bindsc; i++)
{
- XGrabKey(dpy, XKeysymToKeycode(dpy, keyBinds[i].keysym), keyBinds[i].modifiers, root, false, GrabModeAsync, GrabModeAsync);
- //log("Grabbing " << XKeysymToString(keyBinds[i].keysym));
+ XGrabKey(dpy, XKeysymToKeycode(dpy, cfg.binds[i].keysym), cfg.binds[i].modifiers, root, false, GrabModeAsync, GrabModeAsync);
+ //log("Grabbing " << XKeysymToString(cfg.binds[i].keysym));
}
XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow));
//EWMH
- initEWMH(&dpy, &root, numWS, workspaceNames);
+ initEWMH(&dpy, &root, cfg.numWS,cfg. workspaceNames);
setCurrentDesktop(1);
- for(int i = 1; i < numWS + 1; i++)
+ for(int i = 1; i < cfg.numWS + 1; i++)
{
vector<int> v;
Frame rootFrame = {i, noID, false, noID, horizontal, v, true};
frames.insert(pair<int, Frame>(i, rootFrame));
currFrameID++;
}
- for(int i = 0; i < sizeof(startup)/sizeof(startup[0]); i++)
+ for(int i = 0; i < cfg.startupBashc; i++)
{
if(fork() == 0)
{
- system((startup[i] + " > /dev/null 2> /dev/null").c_str());
+ system((cfg.startupBash[i] + " > /dev/null 2> /dev/null").c_str());
exit(0);
}
}
diff --git a/makefile b/makefile
index f77b48b..2788185 100644
--- a/makefile
+++ b/makefile
@@ -28,7 +28,8 @@ remove: r
#Files to be compiled
$(OBJS_DIR)/main.o: $(SOURCE_FILES) $(SOURCE_HEADERS)
$(OBJS_DIR)/ewmh.o: $(SOURCE_DIR)/ewmh.cpp $(SOURCE_DIR)/ewmh.h
-$(OBJS_DIR)/config.o: $(SOURCE_DIR)/config.cpp $(SOURCE_DIR)/config.h
+$(OBJS_DIR)/util.o: $(SOURCE_DIR)/util.cpp $(SOURCE_DIR)/util.h
+$(OBJS_DIR)/config.o: $(SOURCE_DIR)/config.cpp $(SOURCE_DIR)/config.h $(OBJS_DIR)/util.o
clean:
rm $(OBJS_DIR)/*.o
diff --git a/util.cpp b/util.cpp
new file mode 100644
index 0000000..dff3428
--- /dev/null
+++ b/util.cpp
@@ -0,0 +1,17 @@
+#include "util.h"
+
+#include <sstream>
+
+using std::string;
+
+std::vector<string> split (const string &s, char delim) {
+ std::vector<string> result;
+ std::stringstream ss (s);
+ string item;
+
+ while (getline (ss, item, delim)) {
+ result.push_back (item);
+ }
+
+ return result;
+}
diff --git a/util.h b/util.h
index 2268432..666fb40 100644
--- a/util.h
+++ b/util.h
@@ -1 +1,9 @@
-const char* evNames[37] = {0, 0, "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose", "NoExpose", "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify", "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear", "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify", "GenericEvent", "LASTEvent"};
+#pragma once
+
+#include <vector>
+#include <string>
+
+#define evNames {0, 0, "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose", "NoExpose", "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify", "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear", "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify", "GenericEvent", "LASTEvent"};
+
+
+std::vector<std::string> split (const std::string &s, char delim);