summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-06-16 00:05:28 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-06-16 00:05:28 +1200
commit5f54adae7bc4edaf2c18383efe13ded233255509 (patch)
treeda3736531e9be6ea57057f7178bfb2baf5a061f9
parent0b539b0b0278f2d7c2b7629e6d28d8463cba2688 (diff)
downloadYATwm-5f54adae7bc4edaf2c18383efe13ded233255509.tar.gz
YATwm-5f54adae7bc4edaf2c18383efe13ded233255509.zip
feat: Uses a backup config file and respects XDG
Uses config files in the order of `$XDG_CONFIG_HOME/YATwm/config`, `$HOME/.config/YATwm/config`, then `/etc/YATwm/config`
-rw-r--r--config5
-rw-r--r--config.cpp12
-rw-r--r--keybinds.cpp3
-rw-r--r--main.cpp55
-rw-r--r--makefile4
-rw-r--r--util.h4
6 files changed, 55 insertions, 28 deletions
diff --git a/config b/config
index b046b67..8ccdc1e 100644
--- a/config
+++ b/config
@@ -4,10 +4,13 @@
swapmods
bind mod+e exit
-bind mod+Return spawn kitty
+bind mod+Return spawn alacritty
+bind mod+k spawn kitty
gaps 10
outergaps 10
+bind mod+r reload
+
# Tiling
bind mod+t toggle
diff --git a/config.cpp b/config.cpp
index b17f0e2..5200a4b 100644
--- a/config.cpp
+++ b/config.cpp
@@ -74,20 +74,28 @@ std::vector<Err> Config::reloadFile()
std::vector<Err> Config::loadFromFile(std::string path)
{
std::vector<Err> errs;
-
+
file = path;
+
+ std::ifstream config(path);
+ if(!config.good())
+ {
+ config = std::ifstream("/etc/YATwm/config");
+ errs.push_back({CFG_ERR_FATAL, "Using default config: /etc/YATwm/config"});
+ }
+
//Set defaults
gaps = 3;
outerGaps = 3;
logFile = "/tmp/yatlog.txt";
numWS = 0;
swapSuperAlt = false;
+ workspaces = std::vector<Workspace>();
//Probably need something for workspaces and binds too...
string cmd;
int line = 0;
- std::ifstream config(path);
while(getline(config, cmd))
{
if(cmd.size() == 0)
diff --git a/keybinds.cpp b/keybinds.cpp
index 6e4abfd..3a431f0 100644
--- a/keybinds.cpp
+++ b/keybinds.cpp
@@ -33,7 +33,7 @@ const void KeybindsModule::handleKeypress(XKeyEvent e)
const unsigned int masks = ShiftMask | ControlMask | Mod1Mask | Mod4Mask;
for(Keybind bind : binds)
{
- if(bind.modifiers == (e.state & masks) && bind.key == XKeycodeToKeysym(globals.dpy, e.keycode, 0))
+ if(bind.modifiers == (e.state & masks) && bind.key == XLookupKeysym(&e, 0))
{
commandsModule.runCommand(bind.command);
}
@@ -89,4 +89,5 @@ const void KeybindsModule::bind(const CommandArg* argv)
const void KeybindsModule::clearKeybinds()
{
XUngrabButton(globals.dpy, AnyKey, AnyModifier, globals.root);
+ binds = std::vector<Keybind>();
}
diff --git a/main.cpp b/main.cpp
index 2e1f0ad..14e43b7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -44,10 +44,10 @@ std::ofstream yatlog;
#define log(x) yatlog << x << std::endl
-Globals globals;
+Display* dpy;
+Window root;
-Display*& dpy = globals.dpy;
-Window &root = globals.root;
+Globals globals = {dpy, root};
void updateMousePos();
@@ -532,13 +532,14 @@ const void reload(const CommandArg* argv)
//Clear keybinds
keybindsModule.clearKeybinds();
-
+
//Load config again
vector<Err> cfgErr = cfg.reloadFile();
//Error check
handleConfigErrs(cfgErr);
//Re tile
+ untileRoots();
tileRoots();
}
const void wsDump(const CommandArg* argv)
@@ -577,7 +578,10 @@ void configureRequest(XConfigureRequestEvent e)
changes.border_width = e.border_width;
changes.sibling = e.above;
changes.stack_mode = e.detail;
- XConfigureWindow(dpy, e.window, e.value_mask, &changes);
+ XConfigureWindow(dpy, e.window, (unsigned int) e.value_mask, &changes);
+ log("Configure request: " << e.window);
+ //XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime);
+ //tileRoots();
}
void mapRequest(XMapRequestEvent e)
@@ -656,7 +660,7 @@ void mapRequest(XMapRequestEvent e)
- XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime);
+
XSelectInput(dpy, e.window, EnterWindowMask);
//Make client
@@ -680,7 +684,7 @@ void mapRequest(XMapRequestEvent e)
status = getProp(e.window, "_NET_WM_STATE", &type, &data);
if(status == Success && type!=None && (((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_STATE_MODAL", false) || ((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_STATE_ABOVE", false)))
{
- log("\tWindow floating");
+ cout << "Floating" << endl;
clients.find(c.ID)->second.floating = true;
frames.find(pID)->second.floatingFrameIDs.push_back(f.ID);
frames.insert(pair<int, Frame>(f.ID, f));
@@ -736,6 +740,7 @@ void mapRequest(XMapRequestEvent e)
updateClientList(clients);
//tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH);
+ XSetInputFocus(dpy, e.window, RevertToNone, CurrentTime);
tileRoots();
}
@@ -790,10 +795,10 @@ void destroyNotify(XDestroyWindowEvent e)
void enterNotify(XEnterWindowEvent e)
{
//log(e.xcrossing.x);
- /* Cancel if crossing into root
- if(e.xcrossing.window == root)
- break;
- */
+ //Cancel if crossing into root
+ if(e.window == root)
+ return;
+
XWindowAttributes attr;
XGetWindowAttributes(dpy, e.window, &attr);
int monitor = 0;
@@ -839,7 +844,10 @@ void clientMessage(XClientMessageEvent e)
static int OnXError(Display* display, XErrorEvent* e)
{
- log("XError " << e->type);
+ char* error = new char[50];
+ XGetErrorText(dpy, e->type, error, 50);
+ log("XError " << error);
+ delete[] error;
return 0;
}
@@ -935,8 +943,8 @@ int main(int argc, char** argv)
}
//Important init stuff
mX = mY = 0;
- globals.dpy = XOpenDisplay(nullptr);
- globals.root = Window(DefaultRootWindow(dpy));
+ dpy = XOpenDisplay(nullptr);
+ root = Window(DefaultRootWindow(dpy));
// Adding commands
commandsModule.addCommand("exit", exit, 0, {});
@@ -953,11 +961,18 @@ int main(int argc, char** argv)
commandsModule.addCommand("nextMonitor", nextMonitor, 0, {});
//Config
- std::string home = getenv("HOME");
- std::string pathAfterHome = "/.config/YATwm/config.toml";
- std::string file = home + pathAfterHome;
- // Err cfgErr = cfg.loadFromFile(file);
- std::vector<Err> cfgErr = cfg.loadFromFile("config");
+ std::vector<Err> cfgErr;
+
+ char* confDir = getenv("XDG_CONFIG_HOME");
+ if(confDir != NULL)
+ {
+ cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config");
+ }
+ else
+ {
+ string home = getenv("HOME");
+ cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config");
+ }
//Log
yatlog.open(cfg.logFile, std::ios_base::app);
@@ -981,7 +996,7 @@ int main(int argc, char** argv)
sW = DisplayWidth(dpy, screenNum);
sH = DisplayHeight(dpy, screenNum);
- XSetErrorHandler(OnXError);
+ //XSetErrorHandler(OnXError);
XSelectInput(dpy, root, SubstructureRedirectMask | SubstructureNotifyMask | KeyPressMask | EnterWindowMask);
XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow));
diff --git a/makefile b/makefile
index 01e6b5d..df4304a 100644
--- a/makefile
+++ b/makefile
@@ -18,9 +18,9 @@ $(OBJS_DIR)/%.o : $(SOURCE_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
i: $(EXEC)
- sudo install -D $(EXEC) $(INSTALL_DIR)usr/bin/$(EXEC)
+ sudo install -D -m 755 $(EXEC) $(INSTALL_DIR)usr/bin/$(EXEC)
sudo install -D -m 644 yat.desktop $(INSTALL_DIR)usr/share/xsessions/yat.desktop
- sudo install -D -m 644 config.toml $(INSTALL_DIR)etc/YATwm/config.toml
+ sudo install -D -m 644 config $(INSTALL_DIR)etc/YATwm/config
install: i
r:
sudo rm $(INSTALL_DIR)usr/bin/$(EXEC)
diff --git a/util.h b/util.h
index bc3cc6a..bdc45d8 100644
--- a/util.h
+++ b/util.h
@@ -11,6 +11,6 @@ std::vector<std::string> split (const std::string &s, char delim);
struct Globals {
- Display* dpy;
- Window root;
+ Display*& dpy;
+ Window& root;
};