Beautify handle_key_press

This commit is contained in:
Michael Stapelberg 2009-02-23 02:55:10 +01:00
parent 656bdc5090
commit 404f19a376
2 changed files with 14 additions and 27 deletions

View 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 * There was a key press. We compare this key code with our bindings table and pass
* on that. This allows to do things like binding special characters (think of ä) to * the bound action to parse_command().
* functions to get one more modifier while not losing AltGr :-)
* TODO: this description needs to be more understandable
* *
*/ */
int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) { 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); 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 */ /* Find the binding */
/* TODO: event->state durch eine bitmask filtern und dann direkt vergleichen */ Binding *bind;
Binding *bind, *best_match = TAILQ_END(&bindings); TAILQ_FOREACH(bind, &bindings, bindings)
TAILQ_FOREACH(bind, &bindings, bindings) { if (bind->keycode == event->detail && bind->mods == state_filtered)
if (bind->keycode == event->detail && break;
(bind->mods & event->state) == bind->mods) {
if (best_match == TAILQ_END(&bindings) ||
bind->mods > best_match->mods)
best_match = bind;
}
}
/* No match? Then it was an actively grabbed key, that is with Mode_switch, and /* 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 */ 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_allow_events(conn, ReplayKeyboard, event->time);
xcb_flush(conn); xcb_flush(conn);
return 1; return 1;
} }
parse_command(conn, bind->command);
if (event->state & 0x2) { if (event->state & 0x2) {
printf("that's mode_switch\n"); printf("Mode_switch -> allow_events(SyncKeyboard)\n");
parse_command(conn, best_match->command);
printf("ok, hiding this event.\n");
xcb_allow_events(conn, SyncKeyboard, event->time); xcb_allow_events(conn, SyncKeyboard, event->time);
xcb_flush(conn); xcb_flush(conn);
return 1;
} }
parse_command(conn, best_match->command);
return 1; return 1;
} }

View File

@ -252,16 +252,12 @@ void render_layout(xcb_connection_t *connection) {
int width = r_ws->rect.width; int width = r_ws->rect.width;
int height = r_ws->rect.height; int height = r_ws->rect.height;
/* Reserve space for dock clients */
Client *client; Client *client;
SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) { 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);
height -= client->desired_height; height -= client->desired_height;
}
printf("got %d rows and %d cols\n", r_ws->rows, r_ws->cols); 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 xoffset[r_ws->rows];
int yoffset[r_ws->cols]; int yoffset[r_ws->cols];