Skip to content

Commit

Permalink
refactor: final splitting into files, bit more renaming before release
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-clarke committed Nov 10, 2024
1 parent e20f9ac commit 12b5764
Show file tree
Hide file tree
Showing 15 changed files with 860 additions and 868 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include config.mk

SRC = draw.c atlas.c util.c layouts.c configurer.c ipc.c windows.c events.c dashboard.c ewmh.c
SRC = draw.c atlas.c util.c layouts.c configurer.c ipc.c windows.c events.c dashboard.c ewmh.c input.c focus.c monitor.c client.c actions.c
OBJ = ${SRC:.c=.o}

all: atlaswm
Expand Down
199 changes: 199 additions & 0 deletions actions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
#include "atlas.h"
#include "configurer.h"
#include "util.h"
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

static void reload(const Arg *arg) { reload_config(); }

void executeKeybinding(Keybinding *kb) {
Arg arg = {0};
Arg direction = {0};

switch (kb->action) {
case ACTION_SPAWN:
if (kb->value[0]) {
char **argv = parse_command_string(kb->value);
if (argv) {
arg.v = argv;
spawn(&arg);
free_command_args(argv);
} else {
LOG_ERROR("Failed to parse command: %s", kb->value);
}
}
break;

case ACTION_KILLCLIENT:
killclient(&arg);
break;

case ACTION_TOGGLEDASH:
toggleDash(&arg);
break;

case ACTION_RELOAD:
reload(&arg);
break;

case ACTION_CYCLEFOCUS:
focusstack(&arg);
break;

case ACTION_FOCUSMONITOR:
if (!kb->value[0]) {
LOG_ERROR("No direction specified for focusmonitor keybinding");
return;
}
// New empty variable to hold the direction
if (strcasecmp(kb->value, "next") == 0) {
direction.i = +1;
} else if (strcasecmp(kb->value, "prev") == 0) {
direction.i = -1;
} else {
LOG_ERROR("Invalid direction specified for focusmonitor keybinding, ",
kb->value);
}
focusMonitor(&direction);
break;

case ACTION_MOVETOMONITOR:
if (!kb->value[0]) {
LOG_ERROR("No direction specified for focusmonitor keybinding");
return;
}
// New empty variable to hold the direction
if (strcasecmp(kb->value, "next") == 0) {
direction.i = +1;
} else if (strcasecmp(kb->value, "prev") == 0) {
direction.i = -1;
} else {
LOG_ERROR("Invalid direction specified for focusmonitor keybinding, ",
kb->value);
}
directWindowToMonitor(&direction);
break;

case ACTION_TOGGLEFLOATING:
toggleWindowFloating(&arg);
break;

case ACTION_QUIT:
quit(&arg);
break;

default:
LOG_WARN("Unknown action for keybinding");
break;
}
}

void killclient(const Arg *arg) {
if (!selectedMonitor->active)
return;
if (!sendevent(selectedMonitor->active, wmatom[WMDelete])) {
XGrabServer(dpy);
XSetErrorHandler(xerrordummy);
XSetCloseDownMode(dpy, DestroyAll);
XKillClient(dpy, selectedMonitor->active->win);
XSync(dpy, False);
XSetErrorHandler(xerror);
XUngrabServer(dpy);
}
}

void quit(const Arg *arg) { running = 0; }

void spawn(const Arg *arg) {
struct sigaction sa;

if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
setsid();

sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &sa, NULL);

execvp(((char **)arg->v)[0], (char **)arg->v);
LOG_ERROR("Failed to execute '%s'", ((char **)arg->v)[0]);
}
}

void tag(const Arg *arg) {
if (selectedMonitor->active && arg->ui & WORKSPACEMASK) {
selectedMonitor->active->workspaces = arg->ui & WORKSPACEMASK;
focus(NULL);
arrange(selectedMonitor);
}
}

void toggletag(const Arg *arg) {
unsigned int newtags;

if (!selectedMonitor->active)
return;
newtags = selectedMonitor->active->workspaces ^ (arg->ui & WORKSPACEMASK);
if (newtags) {
selectedMonitor->active->workspaces = newtags;
focus(NULL);
arrange(selectedMonitor);
}
}

void toggleview(const Arg *arg) {
unsigned int newtagset =
selectedMonitor->workspaceset[selectedMonitor->selectedWorkspaces] ^
(arg->ui & WORKSPACEMASK);

if (newtagset) {
selectedMonitor->workspaceset[selectedMonitor->selectedWorkspaces] =
newtagset;
focus(NULL);
arrange(selectedMonitor);
}
}

void view(const Arg *arg) {
if ((arg->ui & WORKSPACEMASK) ==
selectedMonitor->workspaceset[selectedMonitor->selectedWorkspaces])
return;
selectedMonitor->selectedWorkspaces ^= 1; /* toggle sel tagset */
if (arg->ui & WORKSPACEMASK)
selectedMonitor->workspaceset[selectedMonitor->selectedWorkspaces] =
arg->ui & WORKSPACEMASK;
focus(NULL);
arrange(selectedMonitor);
}

void zoom(const Arg *arg) {
Client *c = selectedMonitor->active;

if (!selectedMonitor->layouts[selectedMonitor->selectedLayout]->arrange ||
!c || c->isFloating)
return;
if (c == getNextTiledWindow(selectedMonitor->clients) &&
!(c = getNextTiledWindow(c->next)))
return;
pop(c);
}

void pop(Client *c) {
detach(c);
attach(c);
focus(c);
arrange(c->monitor);
}

void directWindowToMonitor(const Arg *arg) {
if (!selectedMonitor->active || !monitors->next)
return;
sendWindowToMonitor(selectedMonitor->active, findMonitorInDirection(arg->i));
focusMonitor(arg);
moveCursorToClientCenter(selectedMonitor->active);
}
Loading

0 comments on commit 12b5764

Please sign in to comment.