From 40750e227dc15116c8af0a8723eafa0469b019dc Mon Sep 17 00:00:00 2001 From: bapt Date: Thu, 23 Jul 2009 16:14:24 +0000 Subject: [PATCH] Implements a reload command --- include/config.h | 4 +++- include/i3.h | 1 + src/commands.c | 7 ++++++ src/config.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++- src/mainx.c | 20 +++-------------- 5 files changed, 69 insertions(+), 19 deletions(-) diff --git a/include/config.h b/include/config.h index 140db5ab..80fa2f02 100644 --- a/include/config.h +++ b/include/config.h @@ -15,6 +15,7 @@ #ifndef _CONFIG_H #define _CONFIG_H +#include #include "queue.h" typedef struct Config Config; @@ -75,6 +76,7 @@ struct Config { * configuration file. * */ -void load_configuration(xcb_connection_t *conn, const char *override_configfile); +void load_configuration(xcb_connection_t *conn, const char *override_configfile, bool reload); +void grab_all_keys(xcb_connection_t *conn); #endif diff --git a/include/i3.h b/include/i3.h index a489b42f..2a31b93b 100644 --- a/include/i3.h +++ b/include/i3.h @@ -32,5 +32,6 @@ extern xcb_event_handlers_t evenths; extern int num_screens; extern uint8_t root_depth; extern xcb_atom_t atoms[NUM_ATOMS]; +extern xcb_window_t root; #endif diff --git a/src/commands.c b/src/commands.c index 0322a51d..d1b77635 100644 --- a/src/commands.c +++ b/src/commands.c @@ -26,6 +26,7 @@ #include "client.h" #include "floating.h" #include "xcb.h" +#include "config.h" bool focus_window_in_container(xcb_connection_t *conn, Container *container, direction_t direction) { /* If this container is empty, we’re done */ @@ -907,6 +908,12 @@ void parse_command(xcb_connection_t *conn, const char *command) { exit(EXIT_SUCCESS); } + /* Is it ? Then restart in place. */ if (STARTS_WITH(command, "restart")) { LOG("restarting \"%s\"...\n", start_argv[0]); diff --git a/src/config.c b/src/config.c index 3fe6d067..1530622f 100644 --- a/src/config.c +++ b/src/config.c @@ -57,6 +57,36 @@ static void replace_variable(char *buffer, const char *key, const char *value) { } } +/* UnGrab the bound keys */ + +void ungrab_all_keys(xcb_connection_t *conn) { + Binding *bind; + TAILQ_FOREACH(bind, &bindings, bindings) { + LOG("UnGrabbing %d\n", bind->keycode); + #define UNGRAB_KEY(modifier) xcb_ungrab_key(conn,bind->keycode,root,modifier); + UNGRAB_KEY(bind->keycode); + } +} + +/* Grab the bound keys */ +void grab_all_keys(xcb_connection_t *conn) { + Binding *bind; + TAILQ_FOREACH(bind, &bindings, bindings) { + LOG("Grabbing %d\n", bind->keycode); + if ( bind->mods & BIND_MODE_SWITCH ) + xcb_grab_key(conn, 0, root, 0, bind->keycode, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC); + else { + /* Grab the key in all combinations */ + #define GRAB_KEY(modifier) xcb_grab_key(conn, 0, root, modifier, bind->keycode, \ + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC) + GRAB_KEY(bind->mods); + GRAB_KEY(bind->mods | xcb_numlock_mask); + GRAB_KEY(bind->mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK); + } + } +} + /* * Reads the configuration from ~/.i3/config or /etc/i3/config if not found. * @@ -64,7 +94,28 @@ static void replace_variable(char *buffer, const char *key, const char *value) { * configuration file. * */ -void load_configuration(xcb_connection_t *conn, const char *override_configpath) { +void load_configuration(xcb_connection_t *conn, const char *override_configpath,bool reload) { + + if(reload) { + /* First ungrab the keys */ + ungrab_all_keys(conn); + /* clean up lists */ + Binding *bind; + TAILQ_FOREACH(bind,&bindings,bindings) { + TAILQ_REMOVE(&bindings,bind,bindings); + free(bind->command); + free(bind); + } + + struct Assignment *assign; + TAILQ_FOREACH(assign,&assignments,assignments) { + TAILQ_REMOVE(&assignments,assign,assignments); + free(assign->windowclass_title); + free(assign) + } + } + + SLIST_HEAD(variables_head, Variable) variables; #define OPTION_STRING(name) \ @@ -321,6 +372,9 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath) die("Unknown configfile option: %s\n", key); } + /* now grab all keys again */ + if(reload) + grab_all_keys(conn); fclose(handle); REQUIRED_OPTION(terminal); diff --git a/src/mainx.c b/src/mainx.c index 6061fd8d..56b864e3 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -69,6 +69,7 @@ struct stack_wins_head stack_wins = SLIST_HEAD_INITIALIZER(stack_wins); xcb_event_handlers_t evenths; xcb_atom_t atoms[NUM_ATOMS]; +xcb_window_t root; int num_screens = 0; /* The depth of the root screen (used e.g. for creating new pixmaps later) */ @@ -111,7 +112,6 @@ int main(int argc, char *argv[], char *env[]) { bool autostart = true; xcb_connection_t *conn; xcb_property_handlers_t prophs; - xcb_window_t root; xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS]; setlocale(LC_ALL, ""); @@ -153,7 +153,7 @@ int main(int argc, char *argv[], char *env[]) { if (xcb_connection_has_error(conn)) die("Cannot open display\n"); - load_configuration(conn, override_configpath); + load_configuration(conn, override_configpath,false); /* Place requests for the atoms we need as soon as possible */ #define REQUEST_ATOM(name) atom_cookies[name] = xcb_intern_atom(conn, 0, strlen(#name), #name); @@ -330,21 +330,7 @@ int main(int argc, char *argv[], char *env[]) { xcb_get_numlock_mask(conn); - /* Grab the bound keys */ - Binding *bind; - TAILQ_FOREACH(bind, &bindings, bindings) { - LOG("Grabbing %d\n", bind->keycode); - if (bind->mods & BIND_MODE_SWITCH) - xcb_grab_key(conn, 0, root, 0, bind->keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC); - else { - /* Grab the key in all combinations */ - #define GRAB_KEY(modifier) xcb_grab_key(conn, 0, root, modifier, bind->keycode, \ - XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC) - GRAB_KEY(bind->mods); - GRAB_KEY(bind->mods | xcb_numlock_mask); - GRAB_KEY(bind->mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK); - } - } + grab_all_keys(conn); /* Autostarting exec-lines */ struct Autostart *exec; -- 2.39.5