summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2024-12-19 15:00:45 +1300
committerBossCode45 <human.cyborg42@gmail.com>2024-12-24 15:56:39 +1300
commitd1d4a63d4473cd4910b678cf5b385f622186fbd3 (patch)
treee6a4a478ad63e29ab12479d88a700238b970ec26
parentc3791254bfb127d64b329098bc792acaa9c30832 (diff)
downloadYATwm-d1d4a63d4473cd4910b678cf5b385f622186fbd3.tar.gz
YATwm-d1d4a63d4473cd4910b678cf5b385f622186fbd3.zip
feat: Added IPC client side to main binary
Updated command line arguments to use `getopt_long' Made it so both -v and --version work Made it so that if you give it non recognised arguments they are sent through the socket to the running window manager if possible.
-rw-r--r--.clang-format3
-rw-r--r--YATmsg/YATmsgbin16680 -> 0 bytes
-rw-r--r--YATmsg/YATmsg.cpp75
-rw-r--r--YATmsg/makefile32
-rw-r--r--YATwm.nix30
-rw-r--r--flake.lock46
-rw-r--r--flake.nix38
-rw-r--r--nix/hm-module.nix20
-rw-r--r--nix/module.nix26
-rw-r--r--shell.nix13
-rw-r--r--src/IPC.cpp79
-rw-r--r--src/IPC.h25
-rw-r--r--src/main.cpp204
13 files changed, 346 insertions, 245 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..51f7195
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,3 @@
+{
+"DisableFormat": true
+} \ No newline at end of file
diff --git a/YATmsg/YATmsg b/YATmsg/YATmsg
deleted file mode 100644
index ee34c4f..0000000
--- a/YATmsg/YATmsg
+++ /dev/null
Binary files differ
diff --git a/YATmsg/YATmsg.cpp b/YATmsg/YATmsg.cpp
deleted file mode 100644
index 7013861..0000000
--- a/YATmsg/YATmsg.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-#include <X11/X.h>
-#include <X11/Xlib.h>
-
-#include <cstring>
-#include <iostream>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-using std::cout, std::endl;
-
-int main(int argc, const char** argv)
-{
- if(argc < 2)
- {
- cout << "Not enough args" << endl;
- return 1;
- }
- Display* dpy = XOpenDisplay(nullptr);
- Window root = Window(DefaultRootWindow(dpy));
- Atom propName = XInternAtom(dpy, "YATWM_SOCKET_PATH", false);
- Atom propType = XInternAtom(dpy, "STRING", false);
- int format;
- unsigned long length;
- unsigned long after;
- Atom type;
- unsigned char* sockPath;
-
- if(XGetWindowProperty(dpy, root, propName, 0L, 32L, False, propType, &type, &format, &length, &after, &sockPath) != Success)
- {
- cout << "Failed to get path" << endl;
- XFree(sockPath);
- return 1;
- }
-
- int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
- if(sockfd == -1)
- {
- cout << "Failed to create socket" << endl;
- XFree(sockPath);
- return 1;
- }
- sockaddr_un address;
- address.sun_family = AF_UNIX;
- strcpy(address.sun_path, (const char*)sockPath);
- if(connect(sockfd, (sockaddr*) &address, sizeof(address)) == -1)
- {
- cout << "Failed connect" << endl;
- XFree(sockPath);
- return 1;
- }
-
- std::string message;
- for(int i = 1; i < argc; i++)
- {
- message += argv[i];
- if(i != argc - 1)
- message += " ";
- }
- cout << "Sending: " << message << endl;
- if(write(sockfd, message.c_str(), message.length()) == -1)
- {
- cout << "Failed write" << endl;
- XFree(sockPath);
- return 1;
- }
-
- char recv[128];
- read(sockfd, recv, 128);
- cout << recv << endl;
-
- close(sockfd);
- XFree(sockPath);
- return 0;
-}
diff --git a/YATmsg/makefile b/YATmsg/makefile
deleted file mode 100644
index 6aeee67..0000000
--- a/YATmsg/makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-.PHONY: clean
-CXX := g++
-CXXFLAGS := -std=c++17 # -g -fsanitize=address -fno-omit-frame-pointer
-LINKFLAGS := -lX11
-OBJS_DIR := ../build
-OUT_DIR := ../out/
-SOURCE_DIR := ./
-EXEC := YATmsg
-SOURCE_FILES := $(wildcard $(SOURCE_DIR)/*.cpp)
-SOURCE_HEADERS := $(wildcard $(SOURCE_DIR)/*.h)
-OBJS := $(subst $(SOURCE_DIR),$(OBJS_DIR), $(patsubst %.cpp,%.o,$(SOURCE_FILES)))
-INSTALL_DIR = /
-
-$(EXEC): $(OBJS)
- $(CXX) $(OBJS) $(CXXFLAGS) $(LINKFLAGS) -o $(EXEC)
-
-$(OBJS_DIR)/%.o : $(SOURCE_DIR)/%.cpp
- $(CXX) $(CXXFLAGS) -c $< -o $@
-
-i: $(EXEC)
- sudo install -D -m 755 $(EXEC) $(INSTALL_DIR)usr/bin/$(EXEC)
-install: i
-r:
- sudo rm $(INSTALL_DIR)usr/bin/$(EXEC)
-remove: r
-
-#Files to be compiled
-$(OBJS_DIR)/YATmsg.o: $(SOURCE_FILES) $(SOURCE_HEADERS)
-
-clean:
- rm $(OBJS_DIR)/*.o
- rm $(EXEC)
diff --git a/YATwm.nix b/YATwm.nix
new file mode 100644
index 0000000..3c583af
--- /dev/null
+++ b/YATwm.nix
@@ -0,0 +1,30 @@
+{
+ stdenv,
+ fetchgit,
+ xorg,
+ libnotify,
+ pkg-config
+}:
+
+
+stdenv.mkDerivation {
+ pname = "YATwm";
+ version = "0.0.1";
+
+ src = fetchgit {
+ url = "https://git.tehbox.org/cgit/boss/YATwm.git/";
+ rev = "v0.0.1";
+ hash = "sha256-c0GIwZFZoaYsq6cK1cPzjxwPZzNg7tyDh44vLFsdMAI=";
+ };
+
+ installPhase = ''
+runHook preInstall
+mkdir -p $out/bin
+install -D -m 755 YATwm $out/bin/YATwm
+install -D -m 644 yat.desktop $out/usr/share/xsessions/yat.desktop
+install -D -m 644 config $out/etc/YATwm/config
+runHook postInstall
+ '';
+
+ buildInputs = [ xorg.libX11 xorg.libXrandr libnotify pkg-config ];
+}
diff --git a/flake.lock b/flake.lock
index fcf75f0..d22a24f 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,57 +1,25 @@
{
"nodes": {
- "flake-utils": {
- "inputs": {
- "systems": "systems"
- },
- "locked": {
- "lastModified": 1710146030,
- "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
- "owner": "numtide",
- "repo": "flake-utils",
- "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
- "type": "github"
- },
- "original": {
- "owner": "numtide",
- "repo": "flake-utils",
- "type": "github"
- }
- },
"nixpkgs": {
"locked": {
- "lastModified": 1710252211,
- "narHash": "sha256-hQChQpB4LDBaSrNlD6DPLhU9T+R6oyxMCg2V+S7Y1jg=",
+ "lastModified": 1734323986,
+ "narHash": "sha256-m/lh6hYMIWDYHCAsn81CDAiXoT3gmxXI9J987W5tZrE=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "7eeacecff44e05a9fd61b9e03836b66ecde8a525",
+ "rev": "394571358ce82dff7411395829aa6a3aad45b907",
"type": "github"
},
"original": {
- "id": "nixpkgs",
- "type": "indirect"
+ "owner": "NixOS",
+ "ref": "nixos-24.11",
+ "repo": "nixpkgs",
+ "type": "github"
}
},
"root": {
"inputs": {
- "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
- },
- "systems": {
- "locked": {
- "lastModified": 1681028828,
- "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
- "owner": "nix-systems",
- "repo": "default",
- "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
- "type": "github"
- },
- "original": {
- "owner": "nix-systems",
- "repo": "default",
- "type": "github"
- }
}
},
"root": "root",
diff --git a/flake.nix b/flake.nix
index d56f11d..3cea84d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,14 +1,28 @@
{
- description = "YATwm";
-
- inputs.flake-utils.url = "github:numtide/flake-utils";
-
- outputs = { self, nixpkgs, flake-utils }:
- flake-utils.lib.eachDefaultSystem
- (system:
- let pkgs = nixpkgs.legacyPackages.${system}; in
- {
- devShells.default = import ./shell.nix { inherit pkgs; };
- }
- );
+ description = "YATwm";
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
+ };
+ outputs = { self, nixpkgs, ... }@inputs:
+ let pkgs = nixpkgs.legacyPackages.x86_64-linux;
+ in
+ {
+ devShells.x86_64-linux.default = pkgs.mkShell {
+ buildInputs = with pkgs; [
+ gcc
+ gnumake
+ xorg.libX11
+ xorg.libXrandr
+ libnotify
+ pkg-config
+ clang-tools
+ ];
+ };
+ packages.x86_64-linux.YATwm = (pkgs.callPackage ./YATwm.nix {});
+ packages.x86_64-linux.default = self.packages.x86_64-linux.YATwm;
+ nixosModules.YATwm = import ./nix/module.nix;
+ nixosModules.default = self.nixosModules.YATwm;
+ homeManagerModules.YATwm = import ./nix/hm-module.nix;
+ homeManagerModules.default = self.homeManagerModules.YATwm;
+ };
}
diff --git a/nix/hm-module.nix b/nix/hm-module.nix
new file mode 100644
index 0000000..87b47f2
--- /dev/null
+++ b/nix/hm-module.nix
@@ -0,0 +1,20 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.xsession.windowManager.YATwm;
+in
+
+{
+ options.xsession.windowManager.YATwm = {
+ enable = mkEnableOption "YATwm";
+ package = mkPackageOption pkgs null { };
+ };
+
+ config = mkIf cfg.enable {
+ home.packages = [ cfg.package ];
+ xsession.windowManager.command = "${cfg.package}/bin/YATwm";
+ xsession.enable = true;
+ };
+}
diff --git a/nix/module.nix b/nix/module.nix
new file mode 100644
index 0000000..829c26d
--- /dev/null
+++ b/nix/module.nix
@@ -0,0 +1,26 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.services.xserver.windowManager.YATwm;
+in
+
+{
+ options.services.xserver.windowManager.YATwm = {
+ enable = mkEnableOption "YATwm";
+
+ package = mkPackageOption pkgs null { };
+ };
+
+ config = mkIf cfg.enable {
+ services.xserver.windowManager.session = [{
+ name = "YATwm";
+ start = ''
+ ${cfg.package}/bin/YATwm &
+ waitPID=$!
+ '';
+ }];
+ environment.systemPackages = [ cfg.package ];
+ };
+}
diff --git a/shell.nix b/shell.nix
deleted file mode 100644
index 46c8894..0000000
--- a/shell.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ pkgs ? import <nixpkgs> {} }:
-with pkgs;
-mkShell {
- buildInputs = [
- gcc
- gnumake
- xorg.libX11
- xorg.libXrandr
- libnotify
- pkg-config
- clang-tools
- ];
-}
diff --git a/src/IPC.cpp b/src/IPC.cpp
index 709cc5c..3ed1bb6 100644
--- a/src/IPC.cpp
+++ b/src/IPC.cpp
@@ -1,6 +1,7 @@
#include "IPC.h"
#include "ewmh.h"
+#include <X11/Xlib.h>
#include <cstring>
#include <string>
#include <sys/socket.h>
@@ -11,14 +12,14 @@ using std::cout, std::endl;
static const char* path = "/tmp/YATwm.sock";
-IPCModule::IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globals)
+IPCServerModule::IPCServerModule(CommandsModule& commandsModule, Config& cfg, Globals& globals)
:commandsModule(commandsModule),
cfg(cfg),
globals(globals)
{
}
-void IPCModule::init()
+void IPCServerModule::init()
{
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
address.sun_family = AF_UNIX;
@@ -35,7 +36,7 @@ void IPCModule::init()
ready = true;
}
-void IPCModule::doListen()
+void IPCServerModule::doListen()
{
if(!ready)
return;
@@ -73,7 +74,7 @@ void IPCModule::doListen()
close(newsock);
}
-void IPCModule::quitIPC()
+void IPCServerModule::quitIPC()
{
if(!ready)
return;
@@ -81,7 +82,7 @@ void IPCModule::quitIPC()
ready = false;
}
-int IPCModule::getFD()
+int IPCServerModule::getFD()
{
if(!ready)
return -1;
@@ -89,3 +90,71 @@ int IPCModule::getFD()
return sockfd;
return -1;
}
+
+IPCClientModule::IPCClientModule()
+{
+ ready = false;
+}
+
+int IPCClientModule::init()
+{
+ Display* dpy = XOpenDisplay(nullptr);
+ Window root = Window(DefaultRootWindow(dpy));
+ Atom propName = XInternAtom(dpy, "YATWM_SOCKET_PATH", false);
+ Atom propType = XInternAtom(dpy, "STRING", false);
+ int format;
+ unsigned long length;
+ unsigned long after;
+ Atom type;
+ unsigned char* sockPath;
+
+ if(XGetWindowProperty(dpy, root, propName, 0L, 32L, False, propType, &type, &format, &length, &after, &sockPath) != Success || type == None)
+ {
+ cout << "Failed to get path" << endl;
+ XFree(sockPath);
+ return 1;
+ }
+
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if(sockfd == -1)
+ {
+ cout << "Failed to create socket" << endl;
+ XFree(sockPath);
+ return -1;
+ }
+ sockaddr_un address;
+ address.sun_family = AF_UNIX;
+ strcpy(address.sun_path, (const char*)sockPath);
+ if(connect(sockfd, (sockaddr*) &address, sizeof(address)) == -1)
+ {
+ cout << "Failed connect" << endl;
+ XFree(sockPath);
+ return -1;
+ }
+ XFree(sockPath);
+ XCloseDisplay(dpy);
+
+ ready = true;
+ return 0;
+}
+
+int IPCClientModule::sendMessage(const char* message, int length)
+{
+ if(!ready)
+ return 1;
+ return write(sockfd, message, length);
+}
+
+int IPCClientModule::getMessage(char* buff, int buffsize)
+{
+ if(!ready)
+ return 1;
+ return read(sockfd, buff, buffsize);
+}
+
+void IPCClientModule::quit()
+{
+ if(!ready)
+ return;
+ close(sockfd);
+}
diff --git a/src/IPC.h b/src/IPC.h
index 97716bb..e0bbcee 100644
--- a/src/IPC.h
+++ b/src/IPC.h
@@ -7,10 +7,10 @@
#include "config.h"
#include "util.h"
-class IPCModule
+class IPCServerModule
{
public:
- IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globals);
+ IPCServerModule(CommandsModule& commandsModule, Config& cfg, Globals& globals);
void init();
void doListen();
void quitIPC();
@@ -25,3 +25,24 @@ private:
bool ready = false;
sockaddr_un address;
};
+
+class IPCClientModule
+{
+public:
+ IPCClientModule();
+
+ // Returns 0 for success, 1 for X error, -1 for socket error
+ int init();
+
+ // Returns 0 for success, 1 for not ready, -1 for socket error
+ int sendMessage(const char* message, int length);
+
+ // Returns 0 for success, 1 for not ready, -1 for socket error
+ int getMessage(char* buff, int buffsize);
+
+
+ void quit();
+private:
+ bool ready;
+ int sockfd;
+};
diff --git a/src/main.cpp b/src/main.cpp
index a11b203..da1ae9b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,6 +5,7 @@
#include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h>
+#include <bits/getopt_core.h>
#include <libnotify/notification.h>
#include <libnotify/notify.h>
@@ -26,6 +27,7 @@
#include <algorithm>
#include <fcntl.h>
#include <poll.h>
+#include <getopt.h>
#include "IPC.h"
#include "commands.h"
@@ -48,8 +50,8 @@ std::time_t timeNow;
std::tm *now;
char nowString[80];
-#define log(x) \
- updateTime(); \
+#define log(x) \
+ updateTime(); \
yatlog << nowString << x << std::endl
Display* dpy;
@@ -62,7 +64,7 @@ void updateMousePos();
CommandsModule commandsModule;
Config cfg(commandsModule);
KeybindsModule keybindsModule(commandsModule, cfg, globals, &updateMousePos);
-IPCModule ipc(commandsModule, cfg, globals);
+IPCServerModule ipc(commandsModule, cfg, globals);
int sW, sH;
int bH;
@@ -193,8 +195,8 @@ void handleConfigErrs(vector<Err> cfgErrs)
std::string title = "YATwm fatal config error (Code " + std::to_string(cfgErr.code) + ")";
std::string body = cfgErr.message;
NotifyNotification* n = notify_notification_new(title.c_str(),
- body.c_str(),
- 0);
+ body.c_str(),
+ 0);
notify_notification_set_timeout(n, 10000);
if(!notify_notification_show(n, 0))
{
@@ -207,8 +209,8 @@ void handleConfigErrs(vector<Err> cfgErrs)
std::string title = "YATwm non fatal config error (Code " + std::to_string(cfgErr.code) + ")";
std::string body = "Check logs for more information";
NotifyNotification* n = notify_notification_new(title.c_str(),
- body.c_str(),
- 0);
+ body.c_str(),
+ 0);
notify_notification_set_timeout(n, 10000);
if(!notify_notification_show(n, 0))
{
@@ -317,30 +319,30 @@ const void kill(const CommandArg* argv)
int revertToReturn;
XGetInputFocus(dpy, &w, &revertToReturn);
Atom* supported_protocols;
- int num_supported_protocols;
- if (XGetWMProtocols(dpy,
- w,
- &supported_protocols,
- &num_supported_protocols) &&
- (std::find(supported_protocols,
- supported_protocols + num_supported_protocols,
- XInternAtom(dpy, "WM_DELETE_WINDOW", false)) !=
- supported_protocols + num_supported_protocols)) {
- // 1. Construct message.
- XEvent msg;
- memset(&msg, 0, sizeof(msg));
- msg.xclient.type = ClientMessage;
- msg.xclient.message_type = XInternAtom(dpy, "WM_PROTOCOLS", false);
- msg.xclient.window = w;
- msg.xclient.format = 32;
- msg.xclient.data.l[0] = XInternAtom(dpy, "WM_DELETE_WINDOW", false);
- // 2. Send message to window to be closed.
- cout << "Nice kill\n";
- XSendEvent(dpy, w, false, 0, &msg);
- } else {
- cout << "Mean kill\n";
- XKillClient(dpy, w);
- }
+ int num_supported_protocols;
+ if (XGetWMProtocols(dpy,
+ w,
+ &supported_protocols,
+ &num_supported_protocols) &&
+ (std::find(supported_protocols,
+ supported_protocols + num_supported_protocols,
+ XInternAtom(dpy, "WM_DELETE_WINDOW", false)) !=
+ supported_protocols + num_supported_protocols)) {
+ // 1. Construct message.
+ XEvent msg;
+ memset(&msg, 0, sizeof(msg));
+ msg.xclient.type = ClientMessage;
+ msg.xclient.message_type = XInternAtom(dpy, "WM_PROTOCOLS", false);
+ msg.xclient.window = w;
+ msg.xclient.format = 32;
+ msg.xclient.data.l[0] = XInternAtom(dpy, "WM_DELETE_WINDOW", false);
+ // 2. Send message to window to be closed.
+ cout << "Nice kill\n";
+ XSendEvent(dpy, w, false, 0, &msg);
+ } else {
+ cout << "Mean kill\n";
+ XKillClient(dpy, w);
+ }
}
const void changeWS(const CommandArg* argv)
{
@@ -418,20 +420,20 @@ int dirFind(int fID, MoveDir dir)
{
switch(dir)
{
- case UP: i--; break;
- case DOWN: i++; break;
- 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;
+ case UP: i--; break;
+ case DOWN: i++; break;
+ 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)
{
switch(dir)
{
- case LEFT: i--; break;
- case RIGHT: i++; break;
- 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;
+ case LEFT: i--; break;
+ case RIGHT: i++; break;
+ 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)
@@ -677,19 +679,19 @@ void mapRequest(XMapRequestEvent e)
pID = focusedWorkspaces[monitor];
focusedScreen = monitor;
/*
- if(mX == rX && mY == rY)
- {
- //Use focused screen
- log("\tFocused screen is: " << focusedScreen);
- }
- else
- {
- //Use mouse
- //TODO: Make this find the monitor
- log("\tMouse is at x: " << rX << ", y: " << rY);
- mX = rX;
- mY = rY;
- }
+ if(mX == rX && mY == rY)
+ {
+ //Use focused screen
+ log("\tFocused screen is: " << focusedScreen);
+ }
+ else
+ {
+ //Use mouse
+ //TODO: Make this find the monitor
+ log("\tMouse is at x: " << rX << ", y: " << rY);
+ mX = rX;
+ mY = rY;
+ }
*/
}
@@ -876,7 +878,7 @@ void clientMessage(XClientMessageEvent e)
currWS = nextWS;
if(prevWS == currWS)
- return;
+ return;
untile(prevWS);
tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH);
@@ -928,9 +930,9 @@ void tileRoots()
Client c = getClient(fullscreenClientID);
XMapWindow(dpy, c.w);
XMoveWindow(dpy, c.w,
- screens[i].x, screens[i].y);
+ screens[i].x, screens[i].y);
XResizeWindow(dpy, c.w,
- screens[i].w, screens[i].h);
+ screens[i].w, screens[i].h);
}
}
}
@@ -983,9 +985,9 @@ int tile(int frameID, int x, int y, int w, int h)
wH -= cfg.gaps * 2;
XMapWindow(dpy, c.w);
XMoveWindow(dpy, c.w,
- wX, wY);
+ wX, wY);
XResizeWindow(dpy, c.w,
- wW, wH);
+ wW, wH);
}
return noID;
}
@@ -1015,24 +1017,92 @@ void untile(int frameID)
}
}
+void printVersion()
+{
+ const char* version =
+ "YATwm for X\n"
+ "version 0.0.1";
+ cout << version << endl;
+}
+
int main(int argc, char** argv)
{
- if(argc > 1)
+ int versionFlag = 0;
+ bool immediateExit = false;
+ while(1)
{
- if(strcmp(argv[1], "--version") == 0)
+ static option long_options[] = {{"version", no_argument, &versionFlag, 1},
+ {0, 0, 0, 0}};
+
+ int optionIndex;
+ char c = getopt_long(argc, argv, "v", long_options, &optionIndex);
+
+ if(c == -1)
+ break;
+
+ switch(c)
{
- const char* version =
- "YATwm for X\n"
- "version 0.1.0";
- cout << version << endl;
- return 0;
+ case 0:
+ if(long_options[optionIndex].flag != 0)
+ break;
+ //Option had arg
+ break;
+ case 'v':
+ versionFlag = 1;
+ case '?':
+ //Error??
+ break;
+ default:
+ //Big error???
+ cout << "BIG ERROR WITH OPTIONS" << endl;
}
}
-
+
+ if(versionFlag == 1)
+ {
+ printVersion();
+ immediateExit = true;
+ }
+
+ if(optind < argc)
+ {
+ //Extra options - probably meant to be a command sent on IPC
+ std::string message;
+ while(optind < argc)
+ {
+ message += argv[optind++];
+ if(optind != argc)
+ message += " ";
+ }
+
+ cout << message << endl;
+
+ IPCClientModule IPCClient;
+ switch(IPCClient.init())
+ {
+ case 1:
+ cout << "X error: is YATwm running?" << endl;
+ exit(1);
+ case -1:
+ cout << "Socket error" << endl;
+ exit(1);
+ }
+ IPCClient.sendMessage(message.c_str(), message.length());
+ char buff[256];
+ IPCClient.getMessage(buff, 256);
+ cout << buff << endl;
+ IPCClient.quit();
+
+ immediateExit = true;
+ }
+
+ if(immediateExit)
+ exit(0);
+
//Important init stuff
mX = mY = 0;
- dpy = XOpenDisplay(nullptr);
- root = Window(DefaultRootWindow(dpy));
+ dpy = XOpenDisplay(nullptr);
+ root = Window(DefaultRootWindow(dpy));
// Adding commands
commandsModule.addCommand("exit", exit, 0, {});
commandsModule.addCommand("spawn", spawn, 1, {STR_REST});