From ce501c9de9954da29a7afa3c11f53d5bdf98c0df Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 23 Jul 2009 20:36:48 +0200 Subject: [PATCH] =?utf8?q?Some=20fixes/reformatting=20for=20bapt=E2=80=99s?= =?utf8?q?=20patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/commands.c | 6 ++-- src/config.c | 75 ++++++++++++++++++++++++++------------------------ src/mainx.c | 2 +- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/commands.c b/src/commands.c index d1b77635..74f8f2a6 100644 --- a/src/commands.c +++ b/src/commands.c @@ -908,10 +908,10 @@ void parse_command(xcb_connection_t *conn, const char *command) { exit(EXIT_SUCCESS); } - /* Is it ? */ if (STARTS_WITH(command, "reload")) { - load_configuration(conn,NULL,true); - return; + load_configuration(conn, NULL, true); + return; } /* Is it ? Then restart in place. */ diff --git a/src/config.c b/src/config.c index 1530622f..ee188537 100644 --- a/src/config.c +++ b/src/config.c @@ -57,24 +57,28 @@ static void replace_variable(char *buffer, const char *key, const char *value) { } } -/* UnGrab the bound keys */ - +/* + * 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); + LOG("Ungrabbing %d\n", bind->keycode); + xcb_ungrab_key(conn, bind->keycode, root, bind->keycode); } } -/* Grab the bound keys */ +/* + * Grab the bound keys (tell X to send us keypress events for those keycodes) + * + */ 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, + if ((bind->mods & BIND_MODE_SWITCH) != 0) + xcb_grab_key(conn, 0, root, 0, bind->keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC); else { /* Grab the key in all combinations */ @@ -94,28 +98,29 @@ void grab_all_keys(xcb_connection_t *conn) { * configuration file. * */ -void load_configuration(xcb_connection_t *conn, const char *override_configpath,bool reload) { - - if(reload) { +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 */ + + /* Clear the old binding and assignment lists */ Binding *bind; - TAILQ_FOREACH(bind,&bindings,bindings) { - TAILQ_REMOVE(&bindings,bind,bindings); - free(bind->command); - free(bind); + while (!TAILQ_EMPTY(&bindings)) { + bind = TAILQ_FIRST(&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) + while (!TAILQ_EMPTY(&assignments)) { + assign = TAILQ_FIRST(&assignments); + FREE(assign->windowclass_title); + TAILQ_REMOVE(&assignments, assign, assignments); + FREE(assign); } } - SLIST_HEAD(variables_head, Variable) variables; #define OPTION_STRING(name) \ @@ -293,23 +298,22 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath, /* assign window class[/window title] → workspace */ if (strcasecmp(key, "assign") == 0) { LOG("assign: \"%s\"\n", value); - char *class_title = sstrdup(value); + char *class_title; char *target; + char *end; /* If the window class/title is quoted we skip quotes */ - if (class_title[0] == '"') { - class_title++; - char *end = strchr(class_title, '"'); - if (end == NULL) - die("Malformed assignment, couldn't find terminating quote\n"); - *end = '\0'; + if (value[0] == '"') { + class_title = sstrdup(value+1); + end = strchr(class_title, '"'); } else { + class_title = sstrdup(value); /* If it is not quoted, we terminate it at the first space */ - char *end = strchr(class_title, ' '); - if (end == NULL) - die("Malformed assignment, couldn't find terminating space\n"); - *end = '\0'; + end = strchr(class_title, ' '); } + if (end == NULL) + die("Malformed assignment, couldn't find terminating quote\n"); + *end = '\0'; /* Strip trailing whitespace */ while (strlen(value) > 0 && value[strlen(value)-1] == ' ') @@ -317,7 +321,7 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath, /* The target is the last argument separated by a space */ if ((target = strrchr(value, ' ')) == NULL) - die("Malformed assignment, couldn't find target\n"); + die("Malformed assignment, couldn't find target (\"%s\")\n", value); target++; if (strchr(target, '~') == NULL && (atoi(target) < 1 || atoi(target) > 10)) @@ -373,14 +377,13 @@ 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); + if (reload) + grab_all_keys(conn); fclose(handle); REQUIRED_OPTION(terminal); REQUIRED_OPTION(font); - while (!SLIST_EMPTY(&variables)) { struct Variable *v = SLIST_FIRST(&variables); SLIST_REMOVE_HEAD(&variables, variables); diff --git a/src/mainx.c b/src/mainx.c index 56b864e3..06330eb0 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -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,false); + 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); -- 2.39.5