# HG changeset patch # User Tomasz Mon # Date 1186577387 -7200 # Node ID 5f40f7d2887f54dcf924bd1d62cb69073aacf628 # Parent 30ed2878807f988fe309889ce86feb669f92ea8b better way to show fileinfopopup diff -r 30ed2878807f -r 5f40f7d2887f src/audacious/ui_playlist.c --- a/src/audacious/ui_playlist.c Tue Aug 07 18:07:37 2007 -0700 +++ b/src/audacious/ui_playlist.c Wed Aug 08 14:49:47 2007 +0200 @@ -50,7 +50,6 @@ #include "strings.h" #include "ui_equalizer.h" #include "ui_fileopener.h" -#include "ui_fileinfopopup.h" #include "ui_main.h" #include "ui_manager.h" #include "util.h" @@ -75,9 +74,6 @@ static gboolean playlistwin_hint_flag = FALSE; -static GtkWidget *playlistwin_infopopup = NULL; -static guint playlistwin_infopopup_sid = 0; - static GtkWidget *playlistwin_slider = NULL; static GtkWidget *playlistwin_time_min, *playlistwin_time_sec; static GtkWidget *playlistwin_info, *playlistwin_sinfo; @@ -91,8 +87,6 @@ static gboolean playlistwin_select_search_kp_cb( GtkWidget *entry , GdkEventKey *event , gpointer searchdlg_win ); -static gboolean playlistwin_fileinfopopup_probe(gpointer * filepopup_win); - static gboolean playlistwin_resizing = FALSE; static gint playlistwin_resize_x, playlistwin_resize_y; @@ -1597,8 +1591,6 @@ playlistwin_create_widgets(); playlistwin_update_info(playlist_get_active()); - playlistwin_infopopup = audacious_fileinfopopup_create(); - gtk_window_add_accel_group(GTK_WINDOW(playlistwin), ui_manager_get_accel_group()); } @@ -1617,10 +1609,6 @@ playlistwin_set_toprow(0); playlist_check_pos_current(playlist_get_active()); - if ( playlistwin_infopopup_sid == 0 ) - playlistwin_infopopup_sid = g_timeout_add( - 50 , (GSourceFunc)playlistwin_fileinfopopup_probe , playlistwin_infopopup ); - gtk_widget_show_all(playlistwin); if (!cfg.playlist_shaded) gtk_widget_hide(playlistwin_sinfo); @@ -1640,13 +1628,6 @@ UI_SKINNED_BUTTON(mainwin_pl)->inside = FALSE; gtk_widget_queue_draw(mainwin_pl); - /* no point in probing for playlistwin_infopopup trigger when the playlistwin is hidden */ - if ( playlistwin_infopopup_sid != 0 ) - { - g_source_remove( playlistwin_infopopup_sid ); - playlistwin_infopopup_sid = 0; - } - if ( cfg.player_visible ) { gtk_window_present(GTK_WINDOW(mainwin)); @@ -1975,74 +1956,3 @@ return FALSE; } } - - -/* fileinfopopup callback for playlistwin */ -static gboolean -playlistwin_fileinfopopup_probe(gpointer * filepopup_win) -{ - gint x, y, pos; - TitleInput *tuple; - static gint prev_x = 0, prev_y = 0, ctr = 0, prev_pos = -1; - static gint shaded_pos = -1, shaded_prev_pos = -1; - gboolean skip = FALSE; - GdkWindow *win; - Playlist *playlist = playlist_get_active(); - - win = gdk_window_at_pointer(NULL, NULL); - gdk_window_get_pointer(GDK_WINDOW(playlistwin->window), &x, &y, NULL); - pos = ui_skinned_playlist_get_position(playlistwin_list, x - 12, y - 20); - - if (win == NULL - || cfg.show_filepopup_for_tuple == FALSE - || UI_SKINNED_PLAYLIST(playlistwin_list)->tooltips == FALSE - || pos != prev_pos - || win != playlistwin_list->window) - { - prev_pos = pos; - ctr = 0; - audacious_fileinfopopup_hide(GTK_WIDGET(filepopup_win), NULL); - return TRUE; - } - - if (prev_x == x && prev_y == y) - ctr++; - else - { - ctr = 0; - prev_x = x; - prev_y = y; - audacious_fileinfopopup_hide(GTK_WIDGET(filepopup_win), NULL); - return TRUE; - } - - if (playlistwin_is_shaded()) - { - shaded_pos = playlist_get_position(playlist); - if (shaded_prev_pos != shaded_pos) - skip = TRUE; - } - - if (ctr >= cfg.filepopup_delay && (skip == TRUE || GTK_WIDGET_VISIBLE(GTK_WIDGET(filepopup_win)) != TRUE)) { - if (pos == -1 && !playlistwin_is_shaded()) - { - audacious_fileinfopopup_hide(GTK_WIDGET(filepopup_win), NULL); - return TRUE; - } - /* shaded mode */ - else - { - tuple = playlist_get_tuple(playlist, shaded_pos); - audacious_fileinfopopup_hide(GTK_WIDGET(filepopup_win), NULL); - audacious_fileinfopopup_show_from_tuple(GTK_WIDGET(filepopup_win), tuple); - shaded_prev_pos = shaded_pos; - } - - prev_pos = pos; - - tuple = playlist_get_tuple(playlist, pos); - audacious_fileinfopopup_show_from_tuple(GTK_WIDGET(filepopup_win), tuple); - } - - return TRUE; -} diff -r 30ed2878807f -r 5f40f7d2887f src/audacious/ui_skinned_playlist.c --- a/src/audacious/ui_skinned_playlist.c Tue Aug 07 18:07:37 2007 -0700 +++ b/src/audacious/ui_skinned_playlist.c Wed Aug 08 14:49:47 2007 +0200 @@ -50,6 +50,7 @@ #include "playback.h" #include "playlist.h" #include "ui_manager.h" +#include "ui_fileinfopopup.h" #include "debug.h" static PangoFontDescription *playlist_list_font = NULL; @@ -90,7 +91,12 @@ static gboolean ui_skinned_playlist_button_press (GtkWidget *widget, GdkEventButton *event); static gboolean ui_skinned_playlist_button_release (GtkWidget *widget, GdkEventButton *event); static gboolean ui_skinned_playlist_motion_notify (GtkWidget *widget, GdkEventMotion *event); +static gboolean ui_skinned_playlist_leave_notify (GtkWidget *widget, GdkEventCrossing *event); static void ui_skinned_playlist_redraw (UiSkinnedPlaylist *playlist); +static gboolean ui_skinned_playlist_popup_show (gpointer data); +static void ui_skinned_playlist_popup_hide (GtkWidget *widget); +static void ui_skinned_playlist_popup_timer_start (GtkWidget *widget); +static void ui_skinned_playlist_popup_timer_stop (GtkWidget *widget); static GtkWidgetClass *parent_class = NULL; static guint playlist_signals[LAST_SIGNAL] = { 0 }; @@ -134,6 +140,7 @@ widget_class->button_press_event = ui_skinned_playlist_button_press; widget_class->button_release_event = ui_skinned_playlist_button_release; widget_class->motion_notify_event = ui_skinned_playlist_motion_notify; + widget_class->leave_notify_event = ui_skinned_playlist_leave_notify; klass->redraw = ui_skinned_playlist_redraw; @@ -154,6 +161,14 @@ playlist->prev_min = -1; playlist->prev_max = -1; playlist->tooltips = TRUE; + + g_object_set_data(G_OBJECT(playlist), "timer_id", GINT_TO_POINTER(0)); + g_object_set_data(G_OBJECT(playlist), "timer_active", GINT_TO_POINTER(0)); + + GtkWidget *popup = audacious_fileinfopopup_create(); + g_object_set_data(G_OBJECT(playlist), "popup", popup); + g_object_set_data(G_OBJECT(playlist), "popup_active", GINT_TO_POINTER(0)); + g_object_set_data(G_OBJECT(playlist), "popup_position", GINT_TO_POINTER(-1)); } GtkWidget* ui_skinned_playlist_new(GtkWidget *fixed, gint x, gint y, gint w, gint h) { @@ -204,7 +219,7 @@ attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events(widget); attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; + GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; attributes.visual = gtk_widget_get_visual(widget); attributes.colormap = gtk_widget_get_colormap(widget); @@ -906,10 +921,28 @@ playlistwin_update_list(playlist_get_active()); } priv->drag_pos = nr; + } else { + gint pos = ui_skinned_playlist_get_position(widget, event->x, event->y); + gint cur_pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "popup_position")); + if (pos != cur_pos) { + g_object_set_data(G_OBJECT(widget), "popup_position", GINT_TO_POINTER(pos)); + ui_skinned_playlist_popup_hide(widget); + ui_skinned_playlist_popup_timer_stop(widget); + if (pos != -1) + ui_skinned_playlist_popup_timer_start(widget); + } } + return TRUE; } +static gboolean ui_skinned_playlist_leave_notify(GtkWidget *widget, GdkEventCrossing *event) { + ui_skinned_playlist_popup_hide(widget); + ui_skinned_playlist_popup_timer_stop(widget); + + return FALSE; +} + static void ui_skinned_playlist_redraw(UiSkinnedPlaylist *playlist) { UiSkinnedPlaylistPrivate *priv = UI_SKINNED_PLAYLIST_GET_PRIVATE(playlist); @@ -972,3 +1005,49 @@ priv->resize_width += w; priv->resize_height += h; } + +static gboolean ui_skinned_playlist_popup_show(gpointer data) { + GtkWidget *widget = data; + gint pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "popup_position")); + + if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "timer_active")) == 1 && pos != -1) { + TitleInput *tuple; + Playlist *pl_active = playlist_get_active(); + GtkWidget *popup = g_object_get_data(G_OBJECT(widget), "popup"); + + tuple = playlist_get_tuple(pl_active, pos); + if ((tuple == NULL) || (tuple->length < 1)) { + gchar *title = playlist_get_songtitle(pl_active, pos); + audacious_fileinfopopup_show_from_title(popup, title); + g_free(title); + } else { + audacious_fileinfopopup_show_from_tuple(popup , tuple); + } + g_object_set_data(G_OBJECT(widget), "popup_active" , GINT_TO_POINTER(1)); + } + + ui_skinned_playlist_popup_timer_stop(widget); + return FALSE; +} + +static void ui_skinned_playlist_popup_hide(GtkWidget *widget) { + if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "popup_active")) == 1) { + GtkWidget *popup = g_object_get_data(G_OBJECT(widget), "popup"); + g_object_set_data(G_OBJECT(widget), "popup_active", GINT_TO_POINTER(0)); + audacious_fileinfopopup_hide(popup, NULL); + } +} + +static void ui_skinned_playlist_popup_timer_start(GtkWidget *widget) { + gint timer_id = g_timeout_add(cfg.filepopup_delay*100, ui_skinned_playlist_popup_show, widget); + g_object_set_data(G_OBJECT(widget), "timer_id", GINT_TO_POINTER(timer_id)); + g_object_set_data(G_OBJECT(widget), "timer_active", GINT_TO_POINTER(1)); +} + +static void ui_skinned_playlist_popup_timer_stop(GtkWidget *widget) { + if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "timer_active")) == 1) + g_source_remove(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "timer_id"))); + + g_object_set_data(G_OBJECT(widget), "timer_id", GINT_TO_POINTER(0)); + g_object_set_data(G_OBJECT(widget), "timer_active", GINT_TO_POINTER(0)); +}