Only launch i3-nagbar for parse errors
This commit is contained in:
parent
40b12c0a4d
commit
8abd1c48f7
|
@ -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) {
|
struct CommandResult *parse_command(const char *input) {
|
||||||
DLOG("COMMAND: *%s*\n", input);
|
DLOG("COMMAND: *%s*\n", input);
|
||||||
state = INITIAL;
|
state = INITIAL;
|
||||||
|
@ -386,6 +385,11 @@ struct CommandResult *parse_command(const char *input) {
|
||||||
y(map_open);
|
y(map_open);
|
||||||
ystr("success");
|
ystr("success");
|
||||||
y(bool, false);
|
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("error");
|
||||||
ystr(errormessage);
|
ystr(errormessage);
|
||||||
ystr("input");
|
ystr("input");
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "all.h"
|
#include "all.h"
|
||||||
|
|
||||||
static int current_nesting_level;
|
static int current_nesting_level;
|
||||||
static bool success_key;
|
static bool parse_error_key;
|
||||||
static bool command_failed;
|
static bool command_failed;
|
||||||
|
|
||||||
/* XXX: I don’t want to touch too much of the nagbar code at once, but we
|
/* 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) {
|
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;
|
command_failed = true;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -197,8 +197,8 @@ static int json_map_key(void *ctx, const unsigned char *stringval, size_t string
|
||||||
#else
|
#else
|
||||||
static int json_map_key(void *ctx, const unsigned char *stringval, unsigned int stringlen) {
|
static int json_map_key(void *ctx, const unsigned char *stringval, unsigned int stringlen) {
|
||||||
#endif
|
#endif
|
||||||
success_key = (stringlen >= strlen("success") &&
|
parse_error_key = (stringlen >= strlen("parse_error") &&
|
||||||
strncmp((const char*)stringval, "success", strlen("success")) == 0);
|
strncmp((const char*)stringval, "parse_error", strlen("parse_error")) == 0);
|
||||||
return 1;
|
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);
|
yajl_gen_get_buf(command_output->json_gen, &reply, &length);
|
||||||
|
|
||||||
current_nesting_level = 0;
|
current_nesting_level = 0;
|
||||||
success_key = false;
|
parse_error_key = false;
|
||||||
command_failed = false;
|
command_failed = false;
|
||||||
yajl_status state = yajl_parse(handle, reply, length);
|
yajl_status state = yajl_parse(handle, reply, length);
|
||||||
if (state != yajl_status_ok) {
|
if (state != yajl_status_ok) {
|
||||||
|
|
Loading…
Reference in New Issue