From: Richard L. <rl...@us...> - 2006-03-07 05:49:00
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10540/src Modified Files: gtkblist.c gtkconv.c gtkdialogs.c gtklog.c gtkplugin.c gtkrequest.c gtkutils.c gtkutils.h Log Message: Cleanup the busy cursor handling code to eliminate a bunch of these loops: while (gtk_events_pending()) gtk_main_iteration(); They seem like a race condition waiting to happen. This code is also simpler, and more generic. This leaves only one such loop, in src/gtkblist.c's gaim_gtk_blist_expand_contact_cb(). Index: gtkblist.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkblist.c,v retrieving revision 1.420 retrieving revision 1.421 diff -u -d -p -r1.420 -r1.421 --- gtkblist.c 2 Mar 2006 13:40:52 -0000 1.420 +++ gtkblist.c 7 Mar 2006 05:48:54 -0000 1.421 @@ -387,10 +387,7 @@ static void gtk_blist_menu_showlog_cb(Gt GaimAccount *account; char *name = NULL; - gdk_window_set_cursor(gtkblist->window->window, cursor); - gdk_cursor_unref(cursor); - while (gtk_events_pending()) - gtk_main_iteration(); + gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH); if (GAIM_BLIST_NODE_IS_BUDDY(node)) { GaimBuddy *b = (GaimBuddy*) node; @@ -408,10 +405,10 @@ static void gtk_blist_menu_showlog_cb(Gt } } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) { gaim_gtk_log_show_contact((GaimContact *)node); - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); return; } else { - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); /* This callback should not have been registered for a node * that doesn't match the type of one of the blocks above. */ @@ -422,7 +419,7 @@ static void gtk_blist_menu_showlog_cb(Gt gaim_gtk_log_show(type, name, account); g_free(name); - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); } } @@ -1330,75 +1327,43 @@ gaim_gtk_blist_popup_menu_cb(GtkWidget * static void gaim_gtk_blist_buddy_details_cb(gpointer data, guint action, GtkWidget *item) { - if (gtkblist->window->window) - { - GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(gtkblist->window->window, cursor); - while (gtk_events_pending()) - gtk_main_iteration(); - gdk_cursor_unref(cursor); - } + gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH); gaim_prefs_set_bool("/gaim/gtk/blist/show_buddy_icons", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))); - if (gtkblist->window->window) - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); } static void gaim_gtk_blist_show_idle_time_cb(gpointer data, guint action, GtkWidget *item) { - if (gtkblist->window->window) - { - GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(gtkblist->window->window, cursor); - while (gtk_events_pending()) - gtk_main_iteration(); - gdk_cursor_unref(cursor); - } + gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH); gaim_prefs_set_bool("/gaim/gtk/blist/show_idle_time", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))); - if (gtkblist->window->window) - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); } static void gaim_gtk_blist_show_empty_groups_cb(gpointer data, guint action, GtkWidget *item) { - if (gtkblist->window->window) - { - GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(gtkblist->window->window, cursor); - while (gtk_events_pending()) - gtk_main_iteration(); - gdk_cursor_unref(cursor); - } + gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH); gaim_prefs_set_bool("/gaim/gtk/blist/show_empty_groups", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))); - if (gtkblist->window->window) - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); } static void gaim_gtk_blist_edit_mode_cb(gpointer callback_data, guint callback_action, GtkWidget *checkitem) { - if (gtkblist->window->window) - { - GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(gtkblist->window->window, cursor); - while (gtk_events_pending()) - gtk_main_iteration(); - gdk_cursor_unref(cursor); - } + gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH); gaim_prefs_set_bool("/gaim/gtk/blist/show_offline_buddies", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkitem))); - if (gtkblist->window->window) - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); } static void gaim_gtk_blist_mute_sounds_cb(gpointer data, guint action, GtkWidget *item) @@ -5766,21 +5731,12 @@ sortmethod_act(GtkCheckMenuItem *checkme { if (gtk_check_menu_item_get_active(checkmenuitem)) { - if (gtkblist->window->window != NULL) - { - GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(gtkblist->window->window, cursor); - gdk_cursor_unref(cursor); - } - - while (gtk_events_pending()) - gtk_main_iteration(); + gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH); gaim_gtk_blist_sort_method_set(id); gaim_prefs_set_string("/gaim/gtk/blist/sort_type", id); - if (gtkblist->window->window != NULL) - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); } } Index: gtkconv.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkconv.c,v retrieving revision 1.752 retrieving revision 1.753 diff -u -d -p -r1.752 -r1.753 --- gtkconv.c 7 Mar 2006 04:16:13 -0000 1.752 +++ gtkconv.c 7 Mar 2006 05:48:54 -0000 1.753 @@ -1002,13 +1002,16 @@ menu_view_log_cb(gpointer data, guint ac return; gtkblist = gaim_gtk_blist_get_default_gtk_blist(); - cursor = gdk_cursor_new(GDK_WATCH); + cursor = gdk_cursor_new(GDK_WATCH); gdk_window_set_cursor(gtkblist->window->window, cursor); gdk_window_set_cursor(win->window->window, cursor); gdk_cursor_unref(cursor); - while (gtk_events_pending()) - gtk_main_iteration(); +#if GTK_CHECK_VERSION(2,4,0) + gdk_display_flush(gdk_drawable_get_display(GDK_DRAWABLE(widget->window))); +#else + gdk_flush(); +#endif name = gaim_conversation_get_name(conv); account = gaim_conversation_get_account(conv); Index: gtkdialogs.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkdialogs.c,v retrieving revision 1.106 retrieving revision 1.107 diff -u -d -p -r1.106 -r1.107 --- gtkdialogs.c 2 Mar 2006 21:38:28 -0000 1.106 +++ gtkdialogs.c 7 Mar 2006 05:48:54 -0000 1.107 @@ -737,16 +737,12 @@ gaim_gtkdialogs_log_cb(gpointer data, Ga if (username != NULL && *username != '\0' && account != NULL) { GaimGtkBuddyList *gtkblist = gaim_gtk_blist_get_default_gtk_blist(); - GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(gtkblist->window->window, cursor); - gdk_cursor_unref(cursor); - while (gtk_events_pending()) - gtk_main_iteration(); + gaim_gtk_set_cursor(gtkblist->window, GDK_WATCH); gaim_gtk_log_show(GAIM_LOG_IM, username, account); - gdk_window_set_cursor(gtkblist->window->window, NULL); + gaim_gtk_clear_cursor(gtkblist->window); } g_free(username); Index: gtklog.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtklog.c,v retrieving revision 1.48 retrieving revision 1.49 diff -u -d -p -r1.48 -r1.49 --- gtklog.c 14 Feb 2006 05:43:43 -0000 1.48 +++ gtklog.c 7 Mar 2006 05:48:54 -0000 1.49 @@ -87,7 +87,6 @@ static void search_cb(GtkWidget *button, { const char *search_term = gtk_entry_get_text(GTK_ENTRY(lv->entry)); GList *logs; - GdkCursor *cursor; if (lv->search != NULL) g_free(lv->search); @@ -103,11 +102,7 @@ static void search_cb(GtkWidget *button, lv->search = g_strdup(search_term); - cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(lv->window->window, cursor); - gdk_cursor_unref(cursor); - while (gtk_events_pending()) - gtk_main_iteration(); + gaim_gtk_set_cursor(lv->window, GDK_WATCH); for (logs = lv->logs; logs != NULL; logs = logs->next) { char *read = gaim_log_read((GaimLog*)logs->data, NULL); @@ -123,7 +118,7 @@ static void search_cb(GtkWidget *button, g_free(read); } - gdk_window_set_cursor(lv->window->window, NULL); + gaim_gtk_clear_cursor(lv->window); } static gboolean destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) { @@ -171,7 +166,6 @@ static void log_select_cb(GtkTreeSelecti GValue val; GtkTreeModel *model = GTK_TREE_MODEL(viewer->treestore); GaimLog *log = NULL; - GdkCursor *cursor; GaimLogReadFlags flags; char *read = NULL; @@ -186,15 +180,7 @@ static void log_select_cb(GtkTreeSelecti if (log == NULL) return; - /* When we set the initial log, this gets called and the window is still NULL. */ - if (viewer->window->window != NULL) - { - cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(viewer->window->window, cursor); - gdk_cursor_unref(cursor); - while (gtk_events_pending()) - gtk_main_iteration(); - } + gaim_gtk_set_cursor(viewer->window, GDK_WATCH); if (log->type != GAIM_LOG_SYSTEM) { char *title; @@ -232,9 +218,7 @@ static void log_select_cb(GtkTreeSelecti gtk_imhtml_search_find(GTK_IMHTML(viewer->imhtml), viewer->search); } - /* When we set the initial log, this gets called and the window is still NULL. */ - if (viewer->window->window != NULL) - gdk_window_set_cursor(viewer->window->window, NULL); + gaim_gtk_clear_cursor(viewer->window); } /* I want to make this smarter, but haven't come up with a cool algorithm to do so, yet. Index: gtkplugin.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkplugin.c,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -p -r1.43 -r1.44 --- gtkplugin.c 2 Mar 2006 19:00:55 -0000 1.43 +++ gtkplugin.c 7 Mar 2006 05:48:54 -0000 1.44 @@ -255,14 +255,12 @@ static void plugin_toggled(GtkCellRender if (!gaim_plugin_is_loaded(plug)) { - GdkCursor *wait = gdk_cursor_new (GDK_WATCH); - gdk_window_set_cursor(plugin_dialog->window, wait); - gdk_cursor_unref(wait); + gaim_gtk_set_cursor(plugin_dialog, GDK_WATCH); gaim_plugin_load(plug); plugin_toggled_stage_two(plug, model, iter, FALSE); - gdk_window_set_cursor(plugin_dialog->window, NULL); + gaim_gtk_clear_cursor(plugin_dialog); } else { @@ -309,13 +307,11 @@ static void plugin_toggled_stage_two(Gai if (unload) { - GdkCursor *wait = gdk_cursor_new (GDK_WATCH); - gdk_window_set_cursor(plugin_dialog->window, wait); - gdk_cursor_unref(wait); + gaim_gtk_set_cursor(plugin_dialog, GDK_WATCH); gaim_plugin_unload(plug); - gdk_window_set_cursor(plugin_dialog->window, NULL); + gaim_gtk_clear_cursor(plugin_dialog); } gtk_widget_set_sensitive(pref_button, Index: gtkrequest.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkrequest.c,v retrieving revision 1.125 retrieving revision 1.126 diff -u -d -p -r1.125 -r1.126 --- gtkrequest.c 2 Mar 2006 02:12:43 -0000 1.125 +++ gtkrequest.c 7 Mar 2006 05:48:54 -0000 1.126 @@ -81,16 +81,12 @@ typedef struct static void generic_response_start(GaimGtkRequestData *data) { - GdkWindow *window = GTK_WIDGET(data->dialog)->window; GdkCursor *cursor; - /* Tell the user we're doing something. */ - cursor = gdk_cursor_new(GDK_WATCH); - gdk_window_set_cursor(window, cursor); - gdk_cursor_unref(cursor); - while (gtk_events_pending()) - gtk_main_iteration(); + g_return_if_fail(data != NULL); + /* Tell the user we're doing something. */ + gaim_gtk_set_cursor(GTK_WIDGET(data->dialog), GDK_WATCH); } static void @@ -1396,7 +1392,7 @@ file_yes_no_cb(GaimGtkRequestData *data, ((GaimRequestFileCb)data->cbs[1])(data->user_data, data->u.file.name); gaim_request_close(data->type, data); } else { - gdk_window_set_cursor(GTK_WIDGET(data->dialog)->window, NULL); + gaim_gtk_clear_cursor(GTK_WIDGET(data->dialog)); } } Index: gtkutils.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkutils.c,v retrieving revision 1.148 retrieving revision 1.149 diff -u -d -p -r1.148 -r1.149 --- gtkutils.c 1 Mar 2006 13:23:35 -0000 1.148 +++ gtkutils.c 7 Mar 2006 05:48:54 -0000 1.149 @@ -2180,3 +2180,29 @@ gaim_gtk_setup_screenname_autocomplete(G g_signal_connect(G_OBJECT(entry), "destroy", G_CALLBACK(screenname_autocomplete_destroyed_cb), NULL); } +void gaim_gtk_set_cursor(GtkWidget *widget, GdkCursorType cursor_type) +{ + GdkCursor *cursor; + + if (widget == NULL) + return; + + cursor = gdk_cursor_new(GDK_WATCH); + gdk_window_set_cursor(widget->window, cursor); + gdk_cursor_unref(cursor); + +#if GTK_CHECK_VERSION(2,4,0) + gdk_display_flush(gdk_drawable_get_display(GDK_DRAWABLE(widget->window))); +#else + gdk_flush(); +#endif +} + +void gaim_gtk_clear_cursor(GtkWidget *widget) +{ + if (widget == NULL) + return; + + gdk_window_set_cursor(widget->window, NULL); +} + Index: gtkutils.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkutils.h,v retrieving revision 1.60 retrieving revision 1.61 diff -u -d -p -r1.60 -r1.61 --- gtkutils.h 1 Mar 2006 06:10:41 -0000 1.60 +++ gtkutils.h 7 Mar 2006 05:48:54 -0000 1.61 @@ -438,4 +438,28 @@ GdkPixbuf *gaim_gtk_create_gaim_icon_wit void gaim_gtk_append_menu_action(GtkWidget *menu, GaimMenuAction *act, gpointer gobject); +/** + * Sets the mouse pointer for a GtkWidget. + * + * After setting the cursor, the display is flushed, so the change will + * take effect immediately. + * + * If @a widget is @c NULL, this function simply returns. + * + * @param widget The widget for which to set the mouse pointer + * @param cursor_type The type of cursor to set + */ +void gaim_gtk_set_cursor(GtkWidget *widget, GdkCursorType cursor_type); + +/** + * Sets the mouse point for a GtkWidget back to that of its parent window. + * + * If @a widget is @c NULL, this function simply returns. + * + * @param widget The widget for which to clear the cursor + * + * @note The display is not flushed from this function. + */ +void gaim_gtk_clear_cursor(GtkWidget *widget); + #endif /* _GAIM_GTKUTILS_H_ */ |