Some fixes/reformatting for bapt’s patch

This commit is contained in:
Michael Stapelberg 2009-07-23 20:36:48 +02:00
parent 40750e227d
commit ce501c9de9
3 changed files with 43 additions and 40 deletions

View File

@ -908,10 +908,10 @@ void parse_command(xcb_connection_t *conn, const char *command) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
/* Is it <reload */ /* Is it a <reload>? */
if (STARTS_WITH(command, "reload")) { if (STARTS_WITH(command, "reload")) {
load_configuration(conn,NULL,true); load_configuration(conn, NULL, true);
return; return;
} }
/* Is it <restart>? Then restart in place. */ /* Is it <restart>? Then restart in place. */

View File

@ -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) { void ungrab_all_keys(xcb_connection_t *conn) {
Binding *bind; Binding *bind;
TAILQ_FOREACH(bind, &bindings, bindings) { TAILQ_FOREACH(bind, &bindings, bindings) {
LOG("UnGrabbing %d\n", bind->keycode); LOG("Ungrabbing %d\n", bind->keycode);
#define UNGRAB_KEY(modifier) xcb_ungrab_key(conn,bind->keycode,root,modifier); xcb_ungrab_key(conn, bind->keycode, root, bind->keycode);
UNGRAB_KEY(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) { void grab_all_keys(xcb_connection_t *conn) {
Binding *bind; Binding *bind;
TAILQ_FOREACH(bind, &bindings, bindings) { TAILQ_FOREACH(bind, &bindings, bindings) {
LOG("Grabbing %d\n", bind->keycode); LOG("Grabbing %d\n", bind->keycode);
if ( bind->mods & BIND_MODE_SWITCH ) if ((bind->mods & BIND_MODE_SWITCH) != 0)
xcb_grab_key(conn, 0, root, 0, bind->keycode, xcb_grab_key(conn, 0, root, 0, bind->keycode,
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC); XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC);
else { else {
/* Grab the key in all combinations */ /* Grab the key in all combinations */
@ -94,28 +98,29 @@ void grab_all_keys(xcb_connection_t *conn) {
* configuration file. * configuration file.
* *
*/ */
void load_configuration(xcb_connection_t *conn, const char *override_configpath,bool reload) { void load_configuration(xcb_connection_t *conn, const char *override_configpath, bool reload) {
if (reload) {
if(reload) {
/* First ungrab the keys */ /* First ungrab the keys */
ungrab_all_keys(conn); ungrab_all_keys(conn);
/* clean up lists */
/* Clear the old binding and assignment lists */
Binding *bind; Binding *bind;
TAILQ_FOREACH(bind,&bindings,bindings) { while (!TAILQ_EMPTY(&bindings)) {
TAILQ_REMOVE(&bindings,bind,bindings); bind = TAILQ_FIRST(&bindings);
free(bind->command); TAILQ_REMOVE(&bindings, bind, bindings);
free(bind); FREE(bind->command);
FREE(bind);
} }
struct Assignment *assign; struct Assignment *assign;
TAILQ_FOREACH(assign,&assignments,assignments) { while (!TAILQ_EMPTY(&assignments)) {
TAILQ_REMOVE(&assignments,assign,assignments); assign = TAILQ_FIRST(&assignments);
free(assign->windowclass_title); FREE(assign->windowclass_title);
free(assign) TAILQ_REMOVE(&assignments, assign, assignments);
FREE(assign);
} }
} }
SLIST_HEAD(variables_head, Variable) variables; SLIST_HEAD(variables_head, Variable) variables;
#define OPTION_STRING(name) \ #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 */ /* assign window class[/window title] → workspace */
if (strcasecmp(key, "assign") == 0) { if (strcasecmp(key, "assign") == 0) {
LOG("assign: \"%s\"\n", value); LOG("assign: \"%s\"\n", value);
char *class_title = sstrdup(value); char *class_title;
char *target; char *target;
char *end;
/* If the window class/title is quoted we skip quotes */ /* If the window class/title is quoted we skip quotes */
if (class_title[0] == '"') { if (value[0] == '"') {
class_title++; class_title = sstrdup(value+1);
char *end = strchr(class_title, '"'); end = strchr(class_title, '"');
if (end == NULL)
die("Malformed assignment, couldn't find terminating quote\n");
*end = '\0';
} else { } else {
class_title = sstrdup(value);
/* If it is not quoted, we terminate it at the first space */ /* If it is not quoted, we terminate it at the first space */
char *end = strchr(class_title, ' '); end = strchr(class_title, ' ');
if (end == NULL)
die("Malformed assignment, couldn't find terminating space\n");
*end = '\0';
} }
if (end == NULL)
die("Malformed assignment, couldn't find terminating quote\n");
*end = '\0';
/* Strip trailing whitespace */ /* Strip trailing whitespace */
while (strlen(value) > 0 && value[strlen(value)-1] == ' ') 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 */ /* The target is the last argument separated by a space */
if ((target = strrchr(value, ' ')) == NULL) if ((target = strrchr(value, ' ')) == NULL)
die("Malformed assignment, couldn't find target\n"); die("Malformed assignment, couldn't find target (\"%s\")\n", value);
target++; target++;
if (strchr(target, '~') == NULL && (atoi(target) < 1 || atoi(target) > 10)) 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); die("Unknown configfile option: %s\n", key);
} }
/* now grab all keys again */ /* now grab all keys again */
if(reload) if (reload)
grab_all_keys(conn); grab_all_keys(conn);
fclose(handle); fclose(handle);
REQUIRED_OPTION(terminal); REQUIRED_OPTION(terminal);
REQUIRED_OPTION(font); REQUIRED_OPTION(font);
while (!SLIST_EMPTY(&variables)) { while (!SLIST_EMPTY(&variables)) {
struct Variable *v = SLIST_FIRST(&variables); struct Variable *v = SLIST_FIRST(&variables);
SLIST_REMOVE_HEAD(&variables, variables); SLIST_REMOVE_HEAD(&variables, variables);

View File

@ -153,7 +153,7 @@ int main(int argc, char *argv[], char *env[]) {
if (xcb_connection_has_error(conn)) if (xcb_connection_has_error(conn))
die("Cannot open display\n"); 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 */ /* 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); #define REQUEST_ATOM(name) atom_cookies[name] = xcb_intern_atom(conn, 0, strlen(#name), #name);