]> git.sur5r.net Git - i3/i3/commitdiff
Implements a reload command
authorbapt <baptiste.daroussin@gmail.com>
Thu, 23 Jul 2009 16:14:24 +0000 (16:14 +0000)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 23 Jul 2009 16:46:21 +0000 (18:46 +0200)
include/config.h
include/i3.h
src/commands.c
src/config.c
src/mainx.c

index 140db5ab2a44d5c886bfa2ecbe68189311e6de33..80fa2f0247551838a5a3a1ebb0403a909bef1732 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef _CONFIG_H
 #define _CONFIG_H
 
+#include <stdbool.h>
 #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
index a489b42f4556fd262115a934426d711040208de7..2a31b93b47e1b80cc487e3793c1bebccd4386431 100644 (file)
@@ -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
index 0322a51da7a4d121f5d09d4cb4b9f9b26b5e4c08..d1b77635437fd5e41e12b86e9c1baeab96cae28a 100644 (file)
@@ -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 <reload */
+        if (STARTS_WITH(command, "reload")) {
+            load_configuration(conn,NULL,true);
+            return;
+        }
+
         /* Is it <restart>? Then restart in place. */
         if (STARTS_WITH(command, "restart")) {
                 LOG("restarting \"%s\"...\n", start_argv[0]);
index 3fe6d0679d24a8d642ae29c91580eb891e8e8a62..1530622f68f3387fd1f73bf8fb3e9876df6ab5e4 100644 (file)
@@ -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);
index 6061fd8d325bb5aa0f176c15aa9a2370646d3f28..56b864e3550853e8bfc620ec1c0eedb7745f131d 100644 (file)
@@ -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;