summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gplay.c33
-rw-r--r--gplay.desktop2
2 files changed, 24 insertions, 11 deletions
diff --git a/gplay.c b/gplay.c
index cc70bec..f531414 100644
--- a/gplay.c
+++ b/gplay.c
@@ -27,16 +27,11 @@ static gulong position_update_source = 0;
static void play_media()
{
- if (!playbin) {
- g_debug("nothing to play");
- return;
- }
gst_element_set_state(playbin, GST_STATE_PLAYING);
}
static void pause_media()
{
- g_return_if_fail(playbin);
gst_element_set_state(playbin, GST_STATE_PAUSED);
}
@@ -54,6 +49,8 @@ static void seek_relative_media(gdouble seconds)
return;
}
+ if (target < 0) target = 0;
+
gst_element_seek_simple(playbin, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
target);
@@ -148,6 +145,7 @@ static void open_media(const char *uri)
g_object_set(playbin, "uri", uri, NULL);
+ // Set window title from uri
gchar *filename = g_filename_from_uri(uri, NULL, NULL);
if (filename) {
gchar *basename = g_filename_display_basename(filename);
@@ -158,6 +156,7 @@ static void open_media(const char *uri)
gtk_window_set_title(main_win, g_get_application_name());
}
+ // Set window icon from file
GFile *file = g_file_new_for_uri(uri);
icon_cancellable = g_cancellable_new();
@@ -166,6 +165,10 @@ static void open_media(const char *uri)
open_icon_ready, NULL);
g_object_unref(file);
+ // Add to recent manager
+ GtkRecentManager *recents = gtk_recent_manager_get_default();
+ gtk_recent_manager_add_item(recents, uri);
+
gst_element_set_state(playbin, GST_STATE_PAUSED);
}
@@ -221,6 +224,18 @@ static void video_widget_handle_realize(GtkWidget *widget, gpointer user_data)
GDK_WINDOW_XID(window));
}
+static gboolean video_widget_handle_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
+{
+ GdkWindow *window = gtk_widget_get_window(widget);
+ g_return_if_fail(window);
+
+ if (video_width == 0 || video_height == 0) {
+ gdk_window_clear(window);
+ }
+
+ return TRUE;
+}
+
static gboolean second_tick(gpointer user_data)
{
update_position_ui();
@@ -448,6 +463,8 @@ static void create_ui()
gtk_widget_set_double_buffered(GTK_WIDGET(video_widget), FALSE);
g_signal_connect(video_widget, "realize",
G_CALLBACK(video_widget_handle_realize), NULL);
+ g_signal_connect(video_widget, "expose-event",
+ G_CALLBACK(video_widget_handle_expose), NULL);
gtk_box_pack_start(vbox, video_widget, TRUE, TRUE, 0);
GtkToolbar *toolbar = GTK_TOOLBAR(gtk_toolbar_new());
@@ -504,9 +521,7 @@ int main(int argc, char **argv)
{
GOptionContext *ctx = g_option_context_new(_(" - simple gtk media player"));
gchar **filenames = NULL;
- gboolean start_playing = FALSE;
const GOptionEntry entries[] = {
- { "play", 'p', 0, G_OPTION_ARG_NONE, &start_playing, "Start playing immediately", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL },
{ NULL }
};
@@ -544,9 +559,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
}
- if (start_playing) {
- play_media();
- }
+ play_media();
}
gtk_widget_show(GTK_WIDGET(main_win));
diff --git a/gplay.desktop b/gplay.desktop
index e590fe6..7d87a4a 100644
--- a/gplay.desktop
+++ b/gplay.desktop
@@ -3,7 +3,7 @@ Version=1.0
Name=Gplay
GenericName=Media player
Comment=Play media files
-Exec=/usr/bin/gplay --play %U
+Exec=/usr/bin/gplay %U
TryExec=/usr/bin/gplay
Icon=applications-multimedia
Terminal=false