2 #define I3__FILE__ "key_press.c"
12 #include <sys/types.h>
34 ev_child_stop(EV_A_ watcher);
39 if (!WIFEXITED(watcher->rstatus)) {
40 fprintf(stderr,
"ERROR: i3-nagbar did not exit normally.\n");
44 int exitcode = WEXITSTATUS(watcher->rstatus);
45 printf(
"i3-nagbar process exited with status %d\n", exitcode);
47 fprintf(stderr,
"ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
56 #if EV_VERSION_MAJOR >= 4
62 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher,
int revent) {
64 LOG(
"Sending SIGKILL (%d) to i3-nagbar with PID %d\n", SIGKILL,
nagbar_pid);
76 int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IXUSR);
78 warn(
"Could not create temporary script to store the nagbar command");
81 write(fd,
"#!/bin/sh\n", strlen(
"#!/bin/sh\n"));
82 write(fd, command, strlen(command));
96 DLOG(
"i3-nagbar for command error already running, not starting again.\n");
100 DLOG(
"Starting i3-nagbar due to command error\n");
114 warn(
"Could not fork()");
132 "The configured command for this shortcut could not be run successfully.",
143 ev_child *child =
smalloc(
sizeof(ev_child));
150 #if EV_VERSION_MAJOR >= 4
153 ev_cleanup *cleanup =
smalloc(
sizeof(ev_cleanup));
154 ev_cleanup_init(cleanup, nagbar_cleanup);
174 warn(
"kill(configerror_nagbar) failed");
196 static int json_map_key(
void *ctx,
const unsigned char *stringval,
size_t stringlen) {
198 static int json_map_key(
void *ctx,
const unsigned char *stringval,
unsigned int stringlen) {
201 strncmp((
const char*)stringval,
"parse_error", strlen(
"parse_error")) == 0);
236 bool key_release = (
event->response_type == XCB_KEY_RELEASE);
240 DLOG(
"%s %d, state raw = %d\n", (key_release ?
"KeyRelease" :
"KeyPress"), event->detail, event->state);
243 uint16_t state_filtered =
event->state & ~(
xcb_numlock_mask | XCB_MOD_MASK_LOCK);
244 DLOG(
"(removed numlock, state = %d)\n", state_filtered);
247 state_filtered &= 0xFF;
248 DLOG(
"(removed upper 8 bits, state = %d)\n", state_filtered);
253 DLOG(
"(checked mode_switch, state %d)\n", state_filtered);
264 DLOG(
"no match, new state_filtered = %d\n", state_filtered);
265 if ((bind =
get_binding(state_filtered, key_release, event->detail)) == NULL) {
271 DLOG(
"Could not lookup key binding (modifiers %d, keycode %d)\n",
272 state_filtered, event->detail);
286 const unsigned char *reply;
289 yajl_handle handle = yajl_alloc(&command_error_callbacks, NULL, NULL);
292 yajl_parser_config parse_conf = { 0, 0 };
294 yajl_handle handle = yajl_alloc(&command_error_callbacks, &parse_conf, NULL, NULL);
296 yajl_gen_get_buf(command_output->
json_gen, &reply, &length);
301 yajl_status
state = yajl_parse(handle, reply, length);
302 if (state != yajl_status_ok) {
303 ELOG(
"Could not parse my own reply. That's weird. reply is %.*s\n", (
int)length, reply);
311 yajl_gen_free(command_output->
json_gen);