Skip to content

Commit

Permalink
Add vi-style key bindings, usable in place of arrow keys.
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
alarixnia committed Dec 14, 2019
1 parent e7ae393 commit 342ee95
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions aiomixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ add_directional_binds(struct aiomixer *x, EObjectType type, void *object, BINDFN
bindCDKObject(type, object, KEY_DOWN, fn, x);
bindCDKObject(type, object, KEY_LEFT, fn, x);
bindCDKObject(type, object, KEY_RIGHT, fn, x);
bindCDKObject(type, object, 'h', fn, x);
bindCDKObject(type, object, 'j', fn, x);
bindCDKObject(type, object, 'k', fn, x);
bindCDKObject(type, object, 'l', fn, x);
}

static void
Expand Down Expand Up @@ -682,6 +686,7 @@ static int key_callback_slider(EObjectType cdktype ,

(void)cdktype; /* unused */
switch (key) {
case 'k':
case KEY_UP:
if (control->current_chan > 0) {
control->current_chan--;
Expand All @@ -691,6 +696,7 @@ static int key_callback_slider(EObjectType cdktype ,
select_class_widget(x, x->control_index - 1);
}
break;
case 'j':
case KEY_DOWN:
if (control->current_chan < (control->v.num_channels - 1)) {
control->current_chan++;
Expand All @@ -700,13 +706,15 @@ static int key_callback_slider(EObjectType cdktype ,
select_class_widget(x, x->control_index + 1);
}
break;
case 'h':
case KEY_LEFT:
new_value = getCDKSliderValue(widget) - control->v.delta;
if (new_value < getCDKSliderLowValue(widget)) {
new_value = getCDKSliderLowValue(widget);
}
set_level(x->fd, control, new_value, control->current_chan);
break;
case 'l':
case KEY_RIGHT:
new_value = getCDKSliderValue(widget) + control->v.delta;
if (new_value > getCDKSliderHighValue(widget)) {
Expand Down Expand Up @@ -735,20 +743,30 @@ static int key_callback_class_buttons(EObjectType cdktype,
case 0x1b: /* escape */
quit(x);
break;
case 'k':
case KEY_UP:
return true;
case 'j':
case KEY_DOWN:
select_class_widget(x, 0);
break;
case 'h':
case KEY_LEFT:
destroy_class_widgets(x);
x->class_index = (getCDKButtonboxCurrentButton(x->class_buttons) - 1) % x->nclasses;
create_class_widgets(x, 3);
if (key != KEY_LEFT) {
setCDKButtonboxCurrentButton(x->class_buttons, x->class_index);
}
break;
case 'l':
case KEY_RIGHT:
destroy_class_widgets(x);
x->class_index = (getCDKButtonboxCurrentButton(x->class_buttons) + 1) % x->nclasses;
create_class_widgets(x, 3);
if (key != KEY_RIGHT) {
setCDKButtonboxCurrentButton(x->class_buttons, x->class_index);
}
break;
}
return false;
Expand All @@ -766,27 +784,37 @@ static int key_callback_control_buttons(EObjectType cdktype,
(void)cdktype; /* unused */
current = getCDKButtonboxCurrentButton(widget);
switch (key) {
case 'k':
case KEY_UP:
select_class_widget(x, x->control_index - 1);
break;
case 'j':
case KEY_DOWN:
select_class_widget(x, x->control_index + 1);
break;
case 'h':
case KEY_LEFT:
current = (current - 1) % getCDKButtonboxButtonCount(widget);
if (control->type == AUDIO_MIXER_SET) {
set_set(x->fd, control->dev, control->s.member[current].mask);
} else if (control->type == AUDIO_MIXER_ENUM) {
set_enum(x->fd, control->dev, control->e.member[current].ord);
}
if (key != KEY_LEFT) {
setCDKButtonboxCurrentButton(widget, current);
}
break;
case 'l':
case KEY_RIGHT:
current = (current + 1) % getCDKButtonboxButtonCount(widget);
if (control->type == AUDIO_MIXER_SET) {
set_set(x->fd, control->dev, control->s.member[current].mask);
} else if (control->type == AUDIO_MIXER_ENUM) {
set_enum(x->fd, control->dev, control->e.member[current].ord);
}
if (key != KEY_RIGHT) {
setCDKButtonboxCurrentButton(widget, current);
}
break;
}
return false;
Expand Down

0 comments on commit 342ee95

Please sign in to comment.