]> git.sur5r.net Git - i3/i3/commitdiff
Beautify handle_key_press
authorMichael Stapelberg <michael+git@stapelberg.de>
Mon, 23 Feb 2009 01:55:10 +0000 (02:55 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Mon, 23 Feb 2009 01:55:10 +0000 (02:55 +0100)
src/handlers.c
src/layout.c

index 9332bfbf8ba52a770e9ec71c697044d4d4ab9885..ea28549271aecae2955f64a69a2b8c4070146464 100644 (file)
@@ -41,10 +41,8 @@ int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_ev
 }
 
 /*
- * There was a key press. We lookup the key symbol and see if there are any bindings
- * on that. This allows to do things like binding special characters (think of ä) to
- * functions to get one more modifier while not losing AltGr :-)
- * TODO: this description needs to be more understandable
+ * There was a key press. We compare this key code with our bindings table and pass
+ * the bound action to parse_command().
  *
  */
 int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) {
@@ -59,36 +57,29 @@ int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_
 
         printf("state %d\n", event->state);
 
+        /* Remove the numlock bit, all other bits are modifiers we can bind to */
+        uint16_t state_filtered = event->state & ~XCB_MOD_MASK_LOCK;
+
         /* Find the binding */
-        /* TODO: event->state durch eine bitmask filtern und dann direkt vergleichen */
-        Binding *bind, *best_match = TAILQ_END(&bindings);
-        TAILQ_FOREACH(bind, &bindings, bindings) {
-                if (bind->keycode == event->detail &&
-                        (bind->mods & event->state) == bind->mods) {
-                        if (best_match == TAILQ_END(&bindings) ||
-                                bind->mods > best_match->mods)
-                                best_match = bind;
-                }
-        }
+        Binding *bind;
+        TAILQ_FOREACH(bind, &bindings, bindings)
+                if (bind->keycode == event->detail && bind->mods == state_filtered)
+                        break;
 
         /* No match? Then it was an actively grabbed key, that is with Mode_switch, and
            the user did not press Mode_switch, so just pass it… */
-        if (best_match == TAILQ_END(&bindings)) {
+        if (bind == TAILQ_END(&bindings)) {
                 xcb_allow_events(conn, ReplayKeyboard, event->time);
                 xcb_flush(conn);
                 return 1;
         }
 
+        parse_command(conn, bind->command);
         if (event->state & 0x2) {
-                printf("that's mode_switch\n");
-                parse_command(conn, best_match->command);
-                printf("ok, hiding this event.\n");
+                printf("Mode_switch -> allow_events(SyncKeyboard)\n");
                 xcb_allow_events(conn, SyncKeyboard, event->time);
                 xcb_flush(conn);
-                return 1;
         }
-
-        parse_command(conn, best_match->command);
         return 1;
 }
 
index 153f835abc11039a05f71b2af164b2c5a8bf097e..b1e5951f3e37fbbd3806223f1377ede934121bfb 100644 (file)
@@ -252,16 +252,12 @@ void render_layout(xcb_connection_t *connection) {
                 int width = r_ws->rect.width;
                 int height = r_ws->rect.height;
 
+                /* Reserve space for dock clients */
                 Client *client;
-                SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) {
-                        printf("got dock client: %p\n", client);
-                        printf("it wants to be this height: %d\n", client->desired_height);
+                SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients)
                         height -= client->desired_height;
-                }
 
                 printf("got %d rows and %d cols\n", r_ws->rows, r_ws->cols);
-                printf("each of them therefore is %d px width and %d px height\n",
-                                width / r_ws->cols, height / r_ws->rows);
 
                 int xoffset[r_ws->rows];
                 int yoffset[r_ws->cols];