+/*
+ * Due to bindings like Mode_switch + <a>, we need to bind some keys in XCB_GRAB_MODE_SYNC.
+ * Therefore, we just replay all key presses.
+ *
+ */
+static int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_event_t *event) {
+ printf("got key release, just passing\n");
+ xcb_allow_events(conn, ReplayKeyboard, event->time);
+ xcb_flush(conn);
+ return 1;
+}
+
+/*
+ * Parses a command, see file CMDMODE for more information
+ *
+ */
+static void parse_command(xcb_connection_t *conn, const char *command) {
+ printf("--- parsing command \"%s\" ---\n", command);
+ /* Hmm, just to be sure */
+ if (command[0] == '\0')
+ return;
+
+ /* Is it an <exec>? */
+ if (strncmp(command, "exec ", strlen("exec ")) == 0) {
+ printf("starting \"%s\"\n", command + strlen("exec "));
+ start_application(command+strlen("exec "), NULL);
+ return;
+ }
+
+ /* Is it a <with>? */
+ if (command[0] == 'w') {
+ /* TODO: implement */
+ printf("not yet implemented.\n");
+ return;
+ }
+
+ /* It's a normal <cmd> */
+ int times;
+ char *rest = NULL;
+ enum { ACTION_FOCUS, ACTION_MOVE, ACTION_SNAP } action = ACTION_FOCUS;
+ direction_t direction;
+ times = strtol(command, &rest, 10);
+ if (rest == NULL) {
+ printf("Invalid command: Consists only of a movement\n");
+ return;
+ }
+ if (*rest == 'm' || *rest == 's') {
+ action = (*rest == 'm' ? ACTION_MOVE : ACTION_SNAP);
+ rest++;
+ }
+
+ /* Now perform action to <where> */
+ while (*rest != '\0') {
+ /* TODO: tags */
+ if (*rest == 'h')
+ direction = D_LEFT;
+ else if (*rest == 'j')
+ direction = D_DOWN;
+ else if (*rest == 'k')
+ direction = D_UP;
+ else if (*rest == 'l')
+ direction = D_RIGHT;
+ else {
+ printf("unknown direction: %c\n", *rest);
+ return;
+ }
+
+ if (action == ACTION_FOCUS)
+ focus_window(conn, direction);
+ else if (action == ACTION_MOVE)
+ move_current_window(conn, direction);
+ else if (action == ACTION_SNAP)
+ /* TODO: implement */
+ printf("snap not yet implemented\n");
+
+ rest++;
+
+ }
+
+ printf("--- done ---\n");
+}
+