From 8abd1c48f73add24b8c935e5ea5fdaef778b8bee Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 11 Sep 2012 13:17:36 +0200 Subject: [PATCH] Only launch i3-nagbar for parse errors --- src/commands_parser.c | 6 +++++- src/key_press.c | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/commands_parser.c b/src/commands_parser.c index 20a7d67a..d739f4e1 100644 --- a/src/commands_parser.c +++ b/src/commands_parser.c @@ -204,7 +204,6 @@ static void next_state(const cmdp_token *token) { } } -/* TODO: Return parsing errors via JSON. */ struct CommandResult *parse_command(const char *input) { DLOG("COMMAND: *%s*\n", input); state = INITIAL; @@ -386,6 +385,11 @@ struct CommandResult *parse_command(const char *input) { y(map_open); ystr("success"); y(bool, false); + /* We set parse_error to true to distinguish this from other + * errors. i3-nagbar is spawned upon keypresses only for parser + * errors. */ + ystr("parse_error"); + y(bool, true); ystr("error"); ystr(errormessage); ystr("input"); diff --git a/src/key_press.c b/src/key_press.c index 3f466a2e..5919e64c 100644 --- a/src/key_press.c +++ b/src/key_press.c @@ -16,7 +16,7 @@ #include "all.h" static int current_nesting_level; -static bool success_key; +static bool parse_error_key; static bool command_failed; /* XXX: I don’t want to touch too much of the nagbar code at once, but we @@ -184,9 +184,9 @@ void kill_commanderror_nagbar(bool wait_for_it) { } static int json_boolean(void *ctx, int boolval) { - DLOG("Got bool: %d, success_key %d, nesting_level %d\n", boolval, success_key, current_nesting_level); + DLOG("Got bool: %d, parse_error_key %d, nesting_level %d\n", boolval, parse_error_key, current_nesting_level); - if (success_key && current_nesting_level == 1 && !boolval) + if (parse_error_key && current_nesting_level == 1 && boolval) command_failed = true; return 1; @@ -197,8 +197,8 @@ static int json_map_key(void *ctx, const unsigned char *stringval, size_t string #else static int json_map_key(void *ctx, const unsigned char *stringval, unsigned int stringlen) { #endif - success_key = (stringlen >= strlen("success") && - strncmp((const char*)stringval, "success", strlen("success")) == 0); + parse_error_key = (stringlen >= strlen("parse_error") && + strncmp((const char*)stringval, "parse_error", strlen("parse_error")) == 0); return 1; } @@ -296,7 +296,7 @@ void handle_key_press(xcb_key_press_event_t *event) { yajl_gen_get_buf(command_output->json_gen, &reply, &length); current_nesting_level = 0; - success_key = false; + parse_error_key = false; command_failed = false; yajl_status state = yajl_parse(handle, reply, length); if (state != yajl_status_ok) { -- 2.39.5