ocarina: Pass key presses directly to the playlist
This lets me remove the "if treeview is focused" special cases that keep popping up in the window keypress handler. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
88ea380f9c
commit
ba9ecd258b
|
@ -46,6 +46,7 @@ string run_chooser(const string &);
|
|||
|
||||
/* playlist.cpp */
|
||||
void update_playlist(notify_t, libsaria::PlaylistNotification *);
|
||||
bool playlist_key_pressed(GtkTreeView *treeview, string &);
|
||||
void setup_widgets(struct PlaylistWidgets *, libsaria::Playlist *);
|
||||
void setup_playlist_page(struct PlaylistWidgets *, int);
|
||||
|
||||
|
@ -64,7 +65,7 @@ struct PlaylistWidgets *find_playlist_widgets(libsaria::Playlist *);
|
|||
libsaria::Playlist *current_playlist();
|
||||
bool playlist_entry_focused();
|
||||
void playlist_focus_entry();
|
||||
bool playlist_treeview_focused();
|
||||
bool playlist_key_press(string &);
|
||||
void playlist_focus_treeview();
|
||||
void playlist_switch_to(string &);
|
||||
void playlist_switch_to_n(unsigned int);
|
||||
|
|
|
@ -205,30 +205,31 @@ static void add_to_playlist(GtkTreeView *treeview, int n)
|
|||
playlist->add_tracks(tracks);
|
||||
}
|
||||
|
||||
static void on_escape_key(GtkTreeView *treeview)
|
||||
static bool on_escape_key(GtkTreeView *treeview)
|
||||
{
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
if (gtk_tree_selection_count_selected_rows(selection) == 0)
|
||||
return false;
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void on_return_key(GtkTreeView *treeview)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
if (gtk_tree_selection_count_selected_rows(selection) == 0)
|
||||
return;
|
||||
gtk_tree_view_get_cursor(treeview, &path, NULL);
|
||||
gtk_tree_view_row_activated(treeview, path, NULL);
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
static gboolean key_pressed(GtkTreeView *treeview, GdkEvent *event, gpointer data)
|
||||
bool playlist_key_pressed(GtkTreeView *treeview, string &key)
|
||||
{
|
||||
string key = gdk_keyval_name(event->key.keyval);
|
||||
|
||||
if (key.substr(0, 3) == "KP_")
|
||||
key = key.substr(3);
|
||||
|
||||
if (key == "j" || key == "k")
|
||||
move_cursor(treeview, key);
|
||||
if (key == "s" || key == "q")
|
||||
else if (key == "s" || key == "q")
|
||||
new_playlist(key, treeview, false);
|
||||
else if (key == "S" || key == "Q")
|
||||
new_playlist(key, treeview, true);
|
||||
|
@ -237,10 +238,10 @@ static gboolean key_pressed(GtkTreeView *treeview, GdkEvent *event, gpointer dat
|
|||
else if (key == "Return")
|
||||
on_return_key(treeview);
|
||||
else if (key == "Escape")
|
||||
on_escape_key(treeview);
|
||||
return on_escape_key(treeview);
|
||||
else
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static gboolean entry_keypress(GtkEntry *entry, GdkEvent *event, gpointer data)
|
||||
|
@ -292,7 +293,6 @@ void setup_widgets(struct PlaylistWidgets *widgets, libsaria::Playlist *playlist
|
|||
is_visible, widgets->playlist, NULL);
|
||||
|
||||
g_signal_connect(widgets->treeview, "row-activated", G_CALLBACK(track_selected), NULL);
|
||||
g_signal_connect(widgets->treeview, "key-press-event", G_CALLBACK(key_pressed), widgets);
|
||||
g_signal_connect(widgets->entry, "changed", G_CALLBACK(do_filter), widgets);
|
||||
g_signal_connect(widgets->entry, "key-press-event", G_CALLBACK(entry_keypress), widgets);
|
||||
}
|
||||
|
|
|
@ -103,12 +103,11 @@ void playlist_focus_entry()
|
|||
gtk_widget_grab_focus(GTK_WIDGET(current_widgets()->entry));
|
||||
}
|
||||
|
||||
bool playlist_treeview_focused()
|
||||
bool playlist_key_press(string &key)
|
||||
{
|
||||
GtkTreeView *treeview = current_widgets()->treeview;
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
if (gtk_widget_is_focus(GTK_WIDGET(treeview)))
|
||||
return gtk_tree_selection_count_selected_rows(selection) > 0;
|
||||
return playlist_key_pressed(treeview, key);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,10 +48,13 @@ static void window_state(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|||
static gboolean key_pressed(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
string key = gdk_keyval_name(event->key.keyval);
|
||||
if (key.substr(0, 3) == "KP_")
|
||||
key = key.substr(3);
|
||||
|
||||
if (playlist_key_press(key))
|
||||
return TRUE;
|
||||
|
||||
if (key == "Escape") {
|
||||
if (playlist_treeview_focused())
|
||||
return FALSE;
|
||||
gtk_window_set_focus(GTK_WINDOW(widget), NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -59,20 +62,15 @@ static gboolean key_pressed(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|||
if (playlist_entry_focused())
|
||||
return FALSE;
|
||||
|
||||
if (key.substr(0, 3) == "KP_")
|
||||
key = key.substr(3);
|
||||
|
||||
/*
|
||||
* TODO: something for banning / unbanning songs
|
||||
* something for incrementing / decrementing the pause after N count
|
||||
*/
|
||||
if (key == "b" || key == "l" || key == "r")
|
||||
playlist_switch_to(key);
|
||||
else if (key >= "0" && key <= "9") {
|
||||
if (playlist_treeview_focused())
|
||||
return FALSE;
|
||||
else if (key >= "0" && key <= "9")
|
||||
playlist_switch_to_n(atoi(key.c_str()));
|
||||
} else if (key == "n")
|
||||
else if (key == "n")
|
||||
libsaria::deck::next();
|
||||
else if (key == "N")
|
||||
libsaria::deck::prev();
|
||||
|
@ -80,12 +78,10 @@ static gboolean key_pressed(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|||
playlist_focus_entry();
|
||||
else if (key == "space")
|
||||
libsaria::audio::toggle_play();
|
||||
else if (key == "Return") {
|
||||
if (playlist_treeview_focused())
|
||||
return FALSE;
|
||||
else if (key == "Return")
|
||||
playlist_focus_treeview();
|
||||
} else {
|
||||
//println("Unhandled key: " + key);
|
||||
else {
|
||||
println("Unhandled key: " + key);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in New Issue