Restart by shortcut

This commit is contained in:
Alex Kotov 2021-11-21 09:47:59 +05:00
parent 6b8d87d1ae
commit 01610d88d7
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 40 additions and 3 deletions

View file

@ -34,6 +34,7 @@ static const Layout layouts[] = {
static Key keys[] = {
// WM
{ MODKEY|ControlMask|ShiftMask, XK_q, quit, {0} },
{ MODKEY|ControlMask|ShiftMask, XK_r, dorestart, {0} },
// Monitor
{ MODKEY, XK_bracketleft, focusmon, {.i = -1 } },
{ MODKEY, XK_bracketright, focusmon, {.i = +1 } },

View file

@ -164,6 +164,7 @@ static Monitor *createmon();
static void detach(Client *c);
static void detachstack(Client *c);
static Monitor *dirtomon(int dir);
static void dorestart(const Arg *arg);
static void focus(Client *c);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
@ -650,6 +651,11 @@ Monitor *dirtomon(int dir)
return m;
}
void dorestart(__attribute__((unused)) const Arg *const arg)
{
restart();
}
void focus(Client *c)
{
if (!c || !ISVISIBLE(c))

View file

@ -10,9 +10,12 @@
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#define PROGRAM_NAME "polytreewm"
static char *program_exe = NULL;
static void signal_callback(int signo);
static void logger(const char *level, const char *fmt, ...);
@ -30,6 +33,10 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
if (!(program_exe = argv[0])) {
fatal("no program executable name");
}
if (!setlocale(LC_CTYPE, "") || !dwm_has_locale_support()) {
warning("no locale support");
}
@ -44,6 +51,7 @@ int main(int argc, char *argv[])
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler = signal_callback;
if (sigaction(SIGCHLD, &action, NULL) != 0) {
fatal_perror("can't install SIGCHLD handler");
}
@ -54,10 +62,20 @@ int main(int argc, char *argv[])
void signal_callback(const int signo)
{
if (signo != SIGCHLD) return;
switch (signo) {
case SIGCHLD:
// Clean up any zombies immediately.
while (waitpid(-1, NULL, WNOHANG) > 0);
break;
}
}
// Clean up any zombies immediately.
while (waitpid(-1, NULL, WNOHANG) > 0);
void restart()
{
info("restarting");
char *args[] = { program_exe, NULL };
execvp(program_exe, args);
fatal_perror("restart with `execvp' failed");
}
void logger(const char *const level, const char *const fmt, ...)
@ -136,3 +154,11 @@ void warning_perror(const char *const fmt, ...)
logger_perror("WARN", fmt, ap);
va_end(ap);
}
void info(const char *const fmt, ...)
{
va_list ap;
va_start(ap, fmt);
logger("INFO", fmt, ap);
va_end(ap);
}

View file

@ -9,5 +9,9 @@ void fatal_nodie(const char *fmt, ...);
void fatal_perror_nodie(const char *fmt, ...);
void warning(const char *fmt, ...);
void warning_perror(const char *fmt, ...);
void info(const char *fmt, ...);
__attribute__((noreturn))
void restart();
#endif // _MAIN_H