Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multikey handling #16

Merged
merged 7 commits into from
Aug 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 39 additions & 11 deletions sway/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,66 @@ void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* ge
// deny that shit
}


bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers
*modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) {
// TODO: handle keybindings with more than 1 non-modifier key involved
// Note: reminder to check conflicts with mod+q+a versus mod+q

enum { QSIZE = 32 };
static uint8_t head = 0;
static uint32_t array[QSIZE];
bool cmd_success = true;
struct sway_mode *mode = config->current_mode;

struct sway_mode *mode = config->current_mode;
// Lowercase if necessary
sym = tolower(sym);

//Find key, if it has been pressed
int mid = 0;
while (mid < head && array[mid] != sym) {
++mid;
}
if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) {
array[head++] = sym;
} else if (state == WLC_KEY_STATE_RELEASED && mid < head) {
memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid));
}
sway_log(L_INFO,"%d", head);
// TODO: reminder to check conflicts with mod+q+a versus mod+q
int i;
for (i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = mode->bindings->items[i];

if ((modifiers->mods & binding->modifiers) == binding->modifiers) {
bool match = true;
bool match;
int j;
for (j = 0; j < binding->keys->length; ++j) {
xkb_keysym_t *k = binding->keys->items[j];
if (sym != *k) {
match = false;
match = false;
xkb_keysym_t *key = binding->keys->items[j];
uint8_t k;
for (k = 0; k < head; ++k) {
if (array[k] == *key) {
match = true;
break;
}
}
if (match == false) {
break;
}
}

if (match) {
// TODO: --released
//Remove matched keys from array
int j;
for (j = 0; j < binding->keys->length; ++j) {
uint8_t k;
for (k = 0; k < head; ++k) {
memmove(array + k, array + k + 1, sizeof*array * (--head - k));
break;
}
}
if (state == WLC_KEY_STATE_PRESSED) {
cmd_success = !handle_command(config, binding->command);
} else {
cmd_success = true;
} else if (state == WLC_KEY_STATE_RELEASED) {
// TODO: --released
}
}
}
Expand Down