Commit e600cf6e authored by Guido Gunther's avatar Guido Gunther
Browse files

Add keybindings

Add keybindings for play / pause, seek, show / hide controls and quit
parent b6c19943
......@@ -139,9 +139,8 @@ on_slider_value_changed (LiviWindow *self, GtkScrollType scroll, double value)
return TRUE;
}
static void
on_img_clicked (LiviWindow *self)
toggle_controls (LiviWindow *self)
{
gboolean revealed;
......@@ -154,9 +153,23 @@ on_img_clicked (LiviWindow *self)
static void
on_btn_play_clicked (LiviWindow *self)
on_img_clicked (LiviWindow *self)
{
g_assert (LIVI_IS_WINDOW (self));
toggle_controls (self);
}
static void
on_toggle_controls_activated (GtkWidget *widget, const char *action_name, GVariant *unused)
{
toggle_controls (LIVI_WINDOW (widget));
}
static void
on_toggle_play_activated (GtkWidget *widget, const char *action_name, GVariant *unused)
{
LiviWindow *self = LIVI_WINDOW (widget);
if (self->state == GST_PLAYER_STATE_PLAYING)
gst_player_pause (self->player);
......@@ -165,6 +178,22 @@ on_btn_play_clicked (LiviWindow *self)
}
static void
on_ff_rev_activated (GtkWidget *widget, const char *action_name, GVariant *unused)
{
LiviWindow *self = LIVI_WINDOW (widget);
GstClockTime pos;
pos = gst_player_get_position (self->player);
if (g_strcmp0 (action_name, "win.ff") == 0)
pos += GST_SECOND * 30;
else
pos -= GST_SECOND * 10;
gst_player_seek (self->player, pos);
}
static void
on_player_error (GstPlayer *player, GError *error, LiviWindow *self)
{
......@@ -424,13 +453,16 @@ livi_window_class_init (LiviWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, LiviWindow, revealer_controls);
gtk_widget_class_bind_template_child (widget_class, LiviWindow, revealer_info);
gtk_widget_class_bind_template_child (widget_class, LiviWindow, stack_content);
gtk_widget_class_bind_template_callback (widget_class, on_btn_play_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_fullscreen);
gtk_widget_class_bind_template_callback (widget_class, on_realize);
gtk_widget_class_bind_template_callback (widget_class, on_slider_value_changed);
gtk_widget_class_install_property_action (widget_class, "win.fullscreen", "fullscreened");
gtk_widget_class_install_property_action (widget_class, "win.mute", "muted");
gtk_widget_class_install_action (widget_class, "win.toggle-controls", NULL, on_toggle_controls_activated);
gtk_widget_class_install_action (widget_class, "win.ff", NULL, on_ff_rev_activated);
gtk_widget_class_install_action (widget_class, "win.rev", NULL, on_ff_rev_activated);
gtk_widget_class_install_action (widget_class, "win.toggle-play", NULL, on_toggle_play_activated);
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_resource (provider, "/org/sigxcpu/Livi/style.css");
......
......@@ -82,7 +82,7 @@
<property name="tooltip-text" translatable="yes">Play/Pause</property>
<property name="halign">start</property>
<property name="valign">center</property>
<signal name="clicked" handler="on_btn_play_clicked" swapped="yes"/>
<property name="action-name">win.toggle-play</property>
<child>
<object class="GtkImage" id="img_play">
<property name="icon-name">media-playback-pause-symbolic</property>
......
......@@ -44,10 +44,30 @@ on_activate (GtkApplication *app)
}
static void
on_quit_activated (GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
g_application_quit (G_APPLICATION (user_data));
}
static GActionEntry app_entries[] =
{
{ "quit", on_quit_activated, NULL, NULL, NULL }
};
static void
on_startup (GApplication *app)
{
GtkWindow *window;
static const char *fullscreen_accels[] = { "f", NULL };
static const char *mute_accels[] = { "m", NULL };
static const char *ff_accels[] = { "Right", NULL };
static const char *rev_accels[] = { "Left", NULL };
static const char *toggle_controls_accels[] = { "Escape", NULL };
static const char *toggle_play_accels[] = { "space", NULL };
static const char *quit_accels[] = { "q", NULL };
g_assert (GTK_IS_APPLICATION (app));
......@@ -62,6 +82,25 @@ on_startup (GApplication *app)
"default-width", 600,
"default-height", 300,
NULL);
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries, G_N_ELEMENTS (app_entries),
app);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"win.fullscreen", fullscreen_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"win.mute", mute_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"win.ff", ff_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"win.rev", rev_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"win.toggle-controls", toggle_controls_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"win.toggle-play", toggle_play_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"app.quit", quit_accels);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment