From cc0b060628f66df2fba38ecddeb01869cb28a04f Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 14 Mar 2009 21:31:22 +0100 Subject: [PATCH] Implement exit command, document it in manpage, add it to defaultconfig (Mod1+Shift+e) --- CMDMODE | 2 +- i3.config | 3 +++ include/util.h | 1 + man/i3.man | 11 ++++++++++- src/commands.c | 12 ++++++++---- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CMDMODE b/CMDMODE index c7881e1f..5e8ebbfa 100644 --- a/CMDMODE +++ b/CMDMODE @@ -17,7 +17,7 @@ with := { [ ] }+ oder -exec := exec +special := [ exec | exit | restart ] an jeder Stelle kann mit escape abgebrochen werden diff --git a/i3.config b/i3.config index 70e3c318..a40f13ad 100644 --- a/i3.config +++ b/i3.config @@ -76,5 +76,8 @@ bind Mod1+36 exec /usr/bin/urxvt # for now, we don’t have an own launcher bind Mod1+55 exec /usr/bin/dmenu_run +# Mod1+Shift+e exits i3 +bind Mod1+Shift+26 exit + # Mod1+Shift+r restarts i3 inplace bind Mod1+Shift+27 restart diff --git a/include/util.h b/include/util.h index 12cd852c..827ae6d1 100644 --- a/include/util.h +++ b/include/util.h @@ -16,6 +16,7 @@ #define _UTIL_H #define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); } +#define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0) #define CIRCLEQ_NEXT_OR_NULL(head, elm, field) (CIRCLEQ_NEXT(elm, field) != CIRCLEQ_END(head) ? \ CIRCLEQ_NEXT(elm, field) : NULL) #define CIRCLEQ_PREV_OR_NULL(head, elm, field) (CIRCLEQ_PREV(elm, field) != CIRCLEQ_END(head) ? \ diff --git a/man/i3.man b/man/i3.man index bdabf41e..c5386c5c 100644 --- a/man/i3.man +++ b/man/i3.man @@ -108,6 +108,12 @@ Enable stacking layout for the current container. Mod1+d:: Enable default layout for the current container. +Mod1+Shift+r:: +Restarts i3 in place (without losing any windows, but the layout). + +Mod1+Shift+e:: +Exits i3. + == FILES === ~/.i3/config @@ -136,9 +142,12 @@ bind Mod1+73 exec /home/michael/toggle_beamer.sh # Screen locking bind Mod1+68 exec /usr/bin/i3lock -# Restart i3 inplace +# Restart i3 inplace (Mod1+Shift+r) bind Mod1+Shift+27 restart +# Exit i3 (Mod1+Shift+e) +bind Mod1+Shift+26 exit + # Brightness bind Mod1+97 exec sudo sh -c "echo up > /proc/acpi/ibm/brightness" bind Mod1+103 exec sudo sh -c "echo down > /proc/acpi/ibm/brightness" diff --git a/src/commands.c b/src/commands.c index 4e9f304a..3afd6c5e 100644 --- a/src/commands.c +++ b/src/commands.c @@ -552,15 +552,19 @@ void parse_command(xcb_connection_t *conn, const char *command) { if (command[0] == '\0') return; - /* Is it an ? */ - if (strncmp(command, "exec ", strlen("exec ")) == 0) { + /* Is it an ? Then execute the given command. */ + if (STARTS_WITH(command, "exec ")) { LOG("starting \"%s\"\n", command + strlen("exec ")); start_application(command+strlen("exec ")); return; } - /* Is it ? */ - if (strncmp(command, "restart", strlen("restart")) == 0) { + /* Is it an ? */ + if (STARTS_WITH(command, "exit")) + exit(0); + + /* Is it ? Then restart in place. */ + if (STARTS_WITH(command, "restart")) { LOG("restarting \"%s\"...\n", application_path); execl(application_path, application_path, NULL); /* not reached */