diff -r da1d08d50e9c -r 592be5c74b68 pidgin/gtkconv.c --- a/pidgin/gtkconv.c Sun Jan 12 00:58:07 2014 +0530 +++ b/pidgin/gtkconv.c Sun Jan 12 16:15:59 2014 +0530 @@ -206,7 +206,6 @@ static void pidgin_conv_updated(PurpleConversation *conv, PurpleConversationUpdateType type); static void conv_set_unseen(PurpleConversation *gtkconv, PidginUnseenState state); static void gtkconv_set_unseen(PidginConversation *gtkconv, PidginUnseenState state); -static void update_typing_state(PidginConversation *gtkconv, gboolean deleting); static void update_typing_icon(PidginConversation *gtkconv); static void update_typing_message(PidginConversation *gtkconv, const char *message); gboolean pidgin_conv_has_focus(PurpleConversation *conv); @@ -1944,6 +1943,58 @@ return !!next; } +static void +update_typing_inserting(PidginConversation *gtkconv) +{ + gchar *text; + + g_return_if_fail(gtkconv != NULL); + + text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry)); + + got_typing_keypress(gtkconv, text[0] == '\0' || !strcmp(text, "\n")); + + g_free(text); +} + +static gboolean +update_typing_deleting_cb(PidginConversation *gtkconv) +{ + PurpleIMConversation *im = PURPLE_IM_CONVERSATION(gtkconv->active_conv); + gchar *text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry)); + + if (!*text || !strcmp(text, "\n")) { + /* We deleted all the text, so turn off typing. */ + purple_im_conversation_stop_send_typed_timeout(im); + + serv_send_typing(purple_conversation_get_connection(gtkconv->active_conv), + purple_conversation_get_name(gtkconv->active_conv), + PURPLE_IM_NOT_TYPING); + } + else { + /* We're deleting, but not all of it, so it counts as typing. */ + got_typing_keypress(gtkconv, FALSE); + } + g_free(text); + + return FALSE; +} + +static void +update_typing_deleting(PidginConversation *gtkconv) +{ + gchar *text; + + g_return_val_if_fail(gtkconv != NULL, FALSE); + + text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry)); + + if (*text && strcmp(text, "\n")) + purple_timeout_add(0, (GSourceFunc)update_typing_deleting_cb, gtkconv); + + g_free(text); +} + static gboolean conv_keypress_common(PidginConversation *gtkconv, GdkEventKey *event) { @@ -2199,17 +2250,18 @@ } } - if (PURPLE_IS_IM_CONVERSATION(conv)) { - gboolean deleting = FALSE; + if (PURPLE_IS_IM_CONVERSATION(conv) && + purple_prefs_get_bool("/purple/conversations/im/send_typing")) { switch (event->keyval) { case GDK_KEY_BackSpace: case GDK_KEY_Delete: case GDK_KEY_KP_Delete: - deleting = TRUE; - } - - update_typing_state(gtkconv, deleting); + update_typing_deleting(gtkconv); + break; + default: + update_typing_inserting(gtkconv); + } } return FALSE; @@ -2423,35 +2475,6 @@ pidgin_conv_switch_active_conversation(PURPLE_CONVERSATION(im)); } -static void -update_typing_state(PidginConversation *gtkconv, gboolean deleting) -{ - PurpleIMConversation *im; - gchar *text; - - g_return_if_fail(gtkconv != NULL); - - if (!purple_prefs_get_bool("/purple/conversations/im/send_typing")) - return; - - im = PURPLE_IM_CONVERSATION(gtkconv->active_conv); - - text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry)); - - if (!*text) { - - /* We deleted all the text, so turn off typing. */ - purple_im_conversation_stop_send_typed_timeout(im); - - serv_send_typing(purple_conversation_get_connection(gtkconv->active_conv), - purple_conversation_get_name(gtkconv->active_conv), - PURPLE_IM_NOT_TYPING); - } - else { - got_typing_keypress(gtkconv, !deleting && text[1] == '\0'); - } -} - /************************************************************************** * A bunch of buddy icon functions **************************************************************************/