void gmpv_inputctl_connect_signals(GmpvApplication *app) { GmpvMainWindow *wnd = gmpv_application_get_main_window(app); GmpvVideoArea *video_area = gmpv_main_window_get_video_area(wnd); g_signal_connect( wnd, "key-press-event", G_CALLBACK(key_press_handler), app ); g_signal_connect( wnd, "key-release-event", G_CALLBACK(key_release_handler), app ); g_signal_connect( video_area, "button-press-event", G_CALLBACK(mouse_button_handler), app ); g_signal_connect( video_area, "button-release-event", G_CALLBACK(mouse_button_handler), app ); g_signal_connect( video_area, "motion-notify-event", G_CALLBACK(mouse_move_handler), app ); g_signal_connect( video_area, "scroll-event", G_CALLBACK(scroll_handler), app ); }
gboolean update_seek_bar(gpointer data) { GmpvApplication *app = data; GmpvMpv *mpv = gmpv_application_get_mpv(app); mpv_handle *mpv_ctx = gmpv_mpv_get_mpv_handle(mpv); gdouble time_pos = -1; gint rc = -1; if(gmpv_mpv_get_state(mpv)->loaded) { rc = gmpv_mpv_get_property( mpv, "time-pos", MPV_FORMAT_DOUBLE, &time_pos ); } if(rc >= 0) { GmpvMainWindow *wnd; GmpvControlBox *control_box; wnd = gmpv_application_get_main_window(app); control_box = gmpv_main_window_get_control_box(wnd); gmpv_control_box_set_seek_bar_pos(control_box, time_pos); } return !!mpv_ctx; }
static void fullscreen_handler(GtkWidget *widget, gpointer data) { GmpvMainWindow *wnd = gmpv_application_get_main_window (GMPV_APPLICATION(data)); gmpv_main_window_toggle_fullscreen(wnd); }
void show_error_dialog(GmpvApplication *app, const gchar *prefix, const gchar *msg) { GmpvMainWindow *wnd; GtkWidget *dialog; GtkWidget *msg_area; GList *iter; wnd = gmpv_application_get_main_window(app); dialog = gtk_message_dialog_new ( GTK_WINDOW(wnd), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error") ); msg_area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG(dialog)); iter = gtk_container_get_children(GTK_CONTAINER(msg_area)); while(iter) { if(GTK_IS_LABEL(iter->data)) { GtkLabel *label = iter->data; gtk_label_set_line_wrap_mode (label, PANGO_WRAP_WORD_CHAR); } iter = g_list_next(iter); } g_list_free(iter); if(prefix) { gchar *prefix_escaped = g_markup_printf_escaped("%s", prefix); gchar *msg_escaped = g_markup_printf_escaped("%s", msg); gtk_message_dialog_format_secondary_markup ( GTK_MESSAGE_DIALOG(dialog), "<b>[%s]</b> %s", prefix_escaped, msg_escaped ); g_free(prefix_escaped); g_free(msg_escaped); } else { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog), "%s", msg); } gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); }
static gboolean delete_handler( GtkWidget *widget, GdkEvent *event, gpointer data ) { gmpv_mpris *inst = data; GmpvMainWindow *wnd = gmpv_application_get_main_window(inst->gmpv_ctx); g_signal_handler_disconnect(wnd, inst->shutdown_sig_id); unregister(inst); g_bus_unown_name(inst->name_id); g_free(inst); return FALSE; }
void gmpv_mpris_init(GmpvApplication *gmpv_ctx) { gmpv_mpris *inst; GmpvMainWindow* main_window; gchar *name; inst = g_malloc(sizeof(gmpv_mpris)); main_window = gmpv_application_get_main_window(gmpv_ctx); /* sizeof(pid_t) can theoretically be larger than sizeof(gint64), but * even then the chance of collision would be minimal. */ name = g_strdup_printf ( MPRIS_BUS_NAME ".instance%" G_GINT64_FORMAT, ABS((gint64)getpid()) ); inst->gmpv_ctx = gmpv_ctx; inst->name_id = 0; inst->base_reg_id = 0; inst->player_reg_id = 0; inst->shutdown_sig_id = 0; inst->base_sig_id_list = NULL; inst->player_sig_id_list = NULL; inst->pending_seek = -1; inst->base_prop_table = NULL; inst->player_prop_table = NULL; inst->session_bus_conn = NULL; inst->shutdown_sig_id = g_signal_connect ( main_window, "delete-event", G_CALLBACK(delete_handler), inst ); inst->name_id = g_bus_own_name( G_BUS_TYPE_SESSION, name, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, (GBusNameAcquiredCallback) name_acquired_handler, (GBusNameLostCallback) name_lost_handler, inst, NULL ); g_free(name); }
void resize_window_to_fit(GmpvApplication *app, gdouble multiplier) { GmpvMpv *mpv = gmpv_application_get_mpv(app); gchar *video = gmpv_mpv_get_property_string(mpv, "video"); gint64 width; gint64 height; gint mpv_width_rc; gint mpv_height_rc; mpv_width_rc = gmpv_mpv_get_property( mpv, "dwidth", MPV_FORMAT_INT64, &width ); mpv_height_rc = gmpv_mpv_get_property( mpv, "dheight", MPV_FORMAT_INT64, &height ); if(video && strncmp(video, "no", 3) != 0 && mpv_width_rc >= 0 && mpv_height_rc >= 0) { GmpvMainWindow *wnd; gint new_width; gint new_height; wnd = gmpv_application_get_main_window(app); new_width = (gint)(multiplier*(gdouble)width); new_height = (gint)(multiplier*(gdouble)height); g_debug("Resizing window to %dx%d", new_width, new_height); gmpv_main_window_resize_video_area(wnd, new_width, new_height); } gmpv_mpv_free(video); }
void gmpv_playbackctl_connect_signals(GmpvApplication *app) { GmpvMainWindow *wnd = gmpv_application_get_main_window(app); GmpvControlBox *control_box = gmpv_main_window_get_control_box(wnd); const struct { const gchar *name; GCallback handler; } signals_map[] = { {"play-button-clicked", G_CALLBACK(play_handler)}, {"stop-button-clicked", G_CALLBACK(stop_handler)}, {"forward-button-clicked", G_CALLBACK(forward_handler)}, {"rewind-button-clicked", G_CALLBACK(rewind_handler)}, {"previous-button-clicked", G_CALLBACK(chapter_previous_handler)}, {"next-button-clicked", G_CALLBACK(chapter_next_handler)}, {"fullscreen-button-clicked", G_CALLBACK(fullscreen_handler)}, {"seek", G_CALLBACK(seek_handler)}, {"volume-changed", G_CALLBACK(volume_handler)}, {NULL, NULL} }; for(gint i = 0; signals_map[i].name; i++) { g_signal_connect( control_box, signals_map[i].name, signals_map[i].handler, app ); } }
static void show_open_dialog_handler( GSimpleAction *action, GVariant *param, gpointer data ) { const gchar *pl_exts[] = PLAYLIST_EXTS; GmpvApplication *app = data; GmpvMainWindow *wnd = NULL; GSettings *main_config = NULL; GSettings *win_config = NULL; GtkFileChooser *file_chooser = NULL; GtkFileFilter *filter = NULL; GmpvFileChooser *open_dialog = NULL; gboolean last_folder_enable = FALSE; gboolean append = FALSE; g_variant_get(param, "b", &append); wnd = gmpv_application_get_main_window(app); open_dialog = gmpv_file_chooser_new( append? _("Add File to Playlist"): _("Open File"), GTK_WINDOW(wnd), GTK_FILE_CHOOSER_ACTION_OPEN, _("_Open"), _("_Cancel")); main_config = g_settings_new(CONFIG_ROOT); file_chooser = GTK_FILE_CHOOSER(open_dialog); last_folder_enable = g_settings_get_boolean (main_config, "last-folder-enable"); filter = gtk_file_filter_new(); gtk_file_filter_add_mime_type(filter, "video/*"); gtk_file_filter_add_mime_type(filter, "audio/*"); gtk_file_filter_add_mime_type(filter, "image/*"); for(gint i = 0; pl_exts[i]; i++) { gchar *pattern = g_strdup_printf("*.%s", pl_exts[i]); gtk_file_filter_add_pattern(filter, pattern); g_free(pattern); } gtk_file_chooser_set_filter(file_chooser, filter); if(last_folder_enable) { gchar *last_folder_uri; win_config = g_settings_new(CONFIG_WIN_STATE); last_folder_uri = g_settings_get_string (win_config, "last-folder-uri"); if(last_folder_uri && strlen(last_folder_uri) > 0) { gtk_file_chooser_set_current_folder_uri (file_chooser, last_folder_uri); } g_free(last_folder_uri); } gtk_file_chooser_set_select_multiple(file_chooser, TRUE); if(gmpv_file_chooser_run(open_dialog) == GTK_RESPONSE_ACCEPT) { GSList *uri_slist = gtk_file_chooser_get_filenames(file_chooser); GSList *uri = uri_slist; gsize uri_list_size = sizeof(gchar **)* (g_slist_length(uri_slist)+1); const gchar **uri_list = g_malloc(uri_list_size); gint i; for(i = 0; uri; i++) { uri_list[i] = uri->data; uri = g_slist_next(uri); } uri_list[i] = NULL; if(uri_slist) { GmpvMpvObj *mpv = gmpv_application_get_mpv_obj(app); gmpv_mpv_obj_load_list(mpv, uri_list, append, TRUE); } if(last_folder_enable) { gchar *last_folder_uri = gtk_file_chooser_get_current_folder_uri (file_chooser); g_settings_set_string( win_config, "last-folder-uri", last_folder_uri?:"" ); g_free(last_folder_uri); } g_free(uri_list); g_slist_free_full(uri_slist, g_free); }