Implements a reload command
This commit is contained in:
parent
9db8535b4c
commit
40750e227d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]);
|
||||
|
|
56
src/config.c
56
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);
|
||||
|
|
20
src/mainx.c
20
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;
|
||||
|
|
Loading…
Reference in New Issue