Pressing a key with no modifier which is bound with a modifier will now correctly focus the search box
This commit is contained in:
parent
7cdc682a6d
commit
a6735a38cb
28
src/wofi.c
28
src/wofi.c
@ -1016,15 +1016,18 @@ static void do_exit(void) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_key_action(GdkEvent* event, char* mod, void (*action)(void)) {
|
static bool do_key_action(GdkEvent* event, char* mod, void (*action)(void)) {
|
||||||
if(mod != NULL) {
|
if(mod != NULL) {
|
||||||
GdkModifierType mask = get_mask_from_name(mod);
|
GdkModifierType mask = get_mask_from_name(mod);
|
||||||
if((event->key.state & mask) == mask) {
|
if((event->key.state & mask) == mask) {
|
||||||
event->key.state &= ~mask;
|
event->key.state &= ~mask;
|
||||||
action();
|
action();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
action();
|
action();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1093,18 +1096,19 @@ static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool key_success = true;
|
||||||
if(event->key.keyval == gdk_keyval_from_name(key_up)) {
|
if(event->key.keyval == gdk_keyval_from_name(key_up)) {
|
||||||
do_key_action(event, mod_up, move_up);
|
key_success = do_key_action(event, mod_up, move_up);
|
||||||
} else if(event->key.keyval == gdk_keyval_from_name(key_down)) {
|
} else if(event->key.keyval == gdk_keyval_from_name(key_down)) {
|
||||||
do_key_action(event, mod_down, move_down);
|
key_success = do_key_action(event, mod_down, move_down);
|
||||||
} else if(event->key.keyval == gdk_keyval_from_name(key_left)) {
|
} else if(event->key.keyval == gdk_keyval_from_name(key_left)) {
|
||||||
do_key_action(event, mod_left, move_left);
|
key_success = do_key_action(event, mod_left, move_left);
|
||||||
} else if(event->key.keyval == gdk_keyval_from_name(key_right)) {
|
} else if(event->key.keyval == gdk_keyval_from_name(key_right)) {
|
||||||
do_key_action(event, mod_right, move_right);
|
key_success = do_key_action(event, mod_right, move_right);
|
||||||
} else if(event->key.keyval == gdk_keyval_from_name(key_forward)) {
|
} else if(event->key.keyval == gdk_keyval_from_name(key_forward)) {
|
||||||
do_key_action(event, mod_forward, move_forward);
|
key_success = do_key_action(event, mod_forward, move_forward);
|
||||||
} else if(event->key.keyval == gdk_keyval_from_name(key_backward)) {
|
} else if(event->key.keyval == gdk_keyval_from_name(key_backward)) {
|
||||||
do_key_action(event, mod_backward, move_backward);
|
key_success = do_key_action(event, mod_backward, move_backward);
|
||||||
} else if(event->key.keyval == gdk_keyval_from_name(key_submit)) {
|
} else if(event->key.keyval == gdk_keyval_from_name(key_submit)) {
|
||||||
mod_shift = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
|
mod_shift = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
|
||||||
mod_ctrl = (event->key.state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
|
mod_ctrl = (event->key.state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
|
||||||
@ -1127,17 +1131,21 @@ static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
|||||||
}
|
}
|
||||||
g_list_free(children);
|
g_list_free(children);
|
||||||
} else if(event->key.keyval == gdk_keyval_from_name(key_exit)) {
|
} else if(event->key.keyval == gdk_keyval_from_name(key_exit)) {
|
||||||
do_key_action(event, mod_exit, do_exit);
|
key_success = do_key_action(event, mod_exit, do_exit);
|
||||||
} else if(event->key.keyval == GDK_KEY_Shift_L || event->key.keyval == GDK_KEY_Control_L) {
|
} else if(event->key.keyval == GDK_KEY_Shift_L || event->key.keyval == GDK_KEY_Control_L) {
|
||||||
} else if(event->key.keyval == GDK_KEY_Shift_R || event->key.keyval == GDK_KEY_Control_R) {
|
} else if(event->key.keyval == GDK_KEY_Shift_R || event->key.keyval == GDK_KEY_Control_R) {
|
||||||
} else {
|
} else {
|
||||||
|
key_success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key_success) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
if(!gtk_widget_has_focus(entry)) {
|
if(!gtk_widget_has_focus(entry)) {
|
||||||
gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
|
gtk_entry_grab_focus_without_selecting(GTK_ENTRY(entry));
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean focus(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
static gboolean focus(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
||||||
(void) data;
|
(void) data;
|
||||||
|
Loading…
Reference in New Issue
Block a user