Blob Blame History Raw
From a7afe74af90b2bdd24052844c36236d2ba031354 Mon Sep 17 00:00:00 2001
From: Daniel Kamil Kozar <dkk089@gmail.com>
Date: Wed, 20 Sep 2017 01:38:28 +0200
Subject: [PATCH 1/3] Rework tray icon blinking

Imported from https://developer.pidgin.im/ticket/17174 , authored by
Zephaniah E. Loss-Cutler-Hull .

--HG--
branch : trac-17174
---
 pidgin/gtkdocklet-gtk.c         | 17 +++++++----------
 pidgin/gtkdocklet.c             | 20 ++++++++++++--------
 pidgin/gtkdocklet.h             |  4 ++--
 pidgin/win32/gtkdocklet-win32.c |  2 +-
 4 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/pidgin/gtkdocklet-gtk.c b/pidgin/gtkdocklet-gtk.c
index f70916bb5772..460d1c84739a 100644
--- a/pidgin/gtkdocklet-gtk.c
+++ b/pidgin/gtkdocklet-gtk.c
@@ -134,7 +134,7 @@ docklet_gtk_status_clicked_cb(GtkStatusIcon *status_icon, guint button, guint ac
 }
 
 static void
-docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending)
+docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending, gboolean blinked)
 {
 	const gchar *icon_name = NULL;
 
@@ -159,19 +159,16 @@ docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting
 			break;
 	}
 
-	if (pending)
-		icon_name = PIDGIN_STOCK_TRAY_PENDING;
-	if (connecting)
+	if (connecting) {
 		icon_name = PIDGIN_STOCK_TRAY_CONNECT;
+	}
 
-	if (icon_name) {
-		gtk_status_icon_set_from_icon_name(docklet, icon_name);
+	if (!blinked && pending) {
+		icon_name = PIDGIN_STOCK_TRAY_PENDING;
 	}
 
-	if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink")) {
-		gtk_status_icon_set_blinking(docklet, (pending && !connecting));
-	} else if (gtk_status_icon_get_blinking(docklet)) {
-		gtk_status_icon_set_blinking(docklet, FALSE);
+	if (icon_name) {
+		gtk_status_icon_set_from_icon_name(docklet, icon_name);
 	}
 }
 
diff --git a/pidgin/gtkdocklet.c b/pidgin/gtkdocklet.c
index bbf997bc6380..2d8955fa9c8e 100644
--- a/pidgin/gtkdocklet.c
+++ b/pidgin/gtkdocklet.c
@@ -69,17 +69,21 @@ docklet_blink_icon(gpointer data)
 
 	blinked = !blinked;
 
-	if(pending && !connecting) {
-		if (blinked) {
-			if (ui_ops && ui_ops->blank_icon)
+	if (pending) {
+		if (ui_ops && ui_ops->blank_icon) {
+			if (blinked) {
 				ui_ops->blank_icon();
+			} else {
+				pidgin_docklet_update_icon(blinked);
+			}
 		} else {
-			pidgin_docklet_update_icon();
+			pidgin_docklet_update_icon(blinked);
 		}
 		ret = TRUE; /* keep blinking */
 	} else {
 		docklet_blinking_timer = 0;
 		blinked = FALSE;
+		pidgin_docklet_update_icon(FALSE);
 	}
 
 	return ret;
@@ -207,7 +211,7 @@ docklet_update_status(void)
 		pending = newpending;
 		connecting = newconnecting;
 
-		pidgin_docklet_update_icon();
+		pidgin_docklet_update_icon(FALSE);
 
 		/* and schedule the blinker function if messages are pending */
 		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink")
@@ -758,10 +762,10 @@ docklet_menu(void)
  * public api for ui_ops
  **************************************************************************/
 void
-pidgin_docklet_update_icon()
+pidgin_docklet_update_icon(gboolean blinked)
 {
 	if (ui_ops && ui_ops->update_icon)
-		ui_ops->update_icon(status, connecting, pending);
+		ui_ops->update_icon(status, connecting, pending, blinked);
 }
 
 void
@@ -795,7 +799,7 @@ pidgin_docklet_embedded()
 	}
 	visible = TRUE;
 	docklet_update_status();
-	pidgin_docklet_update_icon();
+	pidgin_docklet_update_icon(FALSE);
 }
 
 void
diff --git a/pidgin/gtkdocklet.h b/pidgin/gtkdocklet.h
index 34f88a14f5c4..7f188b92a204 100644
--- a/pidgin/gtkdocklet.h
+++ b/pidgin/gtkdocklet.h
@@ -31,7 +31,7 @@ struct docklet_ui_ops
 {
 	void (*create)(void);
 	void (*destroy)(void);
-	void (*update_icon)(PurpleStatusPrimitive, gboolean, gboolean);
+	void (*update_icon)(PurpleStatusPrimitive, gboolean, gboolean, gboolean);
 	void (*blank_icon)(void);
 	void (*set_tooltip)(gchar *);
 	GtkMenuPositionFunc position_menu;
@@ -39,7 +39,7 @@ struct docklet_ui_ops
 
 
 /* functions in gtkdocklet.c */
-void pidgin_docklet_update_icon(void);
+void pidgin_docklet_update_icon(gboolean blinked);
 void pidgin_docklet_clicked(int);
 void pidgin_docklet_embedded(void);
 void pidgin_docklet_remove(void);
diff --git a/pidgin/win32/gtkdocklet-win32.c b/pidgin/win32/gtkdocklet-win32.c
index b02666078e49..84609f111d64 100644
--- a/pidgin/win32/gtkdocklet-win32.c
+++ b/pidgin/win32/gtkdocklet-win32.c
@@ -497,7 +497,7 @@ static void systray_remove_nid(void) {
 }
 
 static void winpidgin_tray_update_icon(PurpleStatusPrimitive status,
-		gboolean connecting, gboolean pending) {
+		gboolean connecting, gboolean pending, gboolean blinked) {
 
 	int icon_index;
 	g_return_if_fail(image != NULL);
-- 
2.14.4


From 3d2c01f1a472670ca7b8960fabbf4e6b4e41cc02 Mon Sep 17 00:00:00 2001
From: Daniel Kamil Kozar <dkk089@gmail.com>
Date: Wed, 29 Nov 2017 21:13:54 +0100
Subject: [PATCH 2/3] Use gtk_status_icon_get_icon_name instead of a new
 boolean variable

--HG--
branch : trac-17174
---
 pidgin/gtkdocklet-gtk.c         |  7 ++++---
 pidgin/gtkdocklet.c             | 14 +++++++-------
 pidgin/gtkdocklet.h             |  4 ++--
 pidgin/win32/gtkdocklet-win32.c |  2 +-
 4 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/pidgin/gtkdocklet-gtk.c b/pidgin/gtkdocklet-gtk.c
index 460d1c84739a..a948a0d7d5d8 100644
--- a/pidgin/gtkdocklet-gtk.c
+++ b/pidgin/gtkdocklet-gtk.c
@@ -134,9 +134,10 @@ docklet_gtk_status_clicked_cb(GtkStatusIcon *status_icon, guint button, guint ac
 }
 
 static void
-docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending, gboolean blinked)
+docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending)
 {
 	const gchar *icon_name = NULL;
+	const gchar *current_icon_name = gtk_status_icon_get_icon_name(docklet);
 
 	switch (status) {
 		case PURPLE_STATUS_OFFLINE:
@@ -159,11 +160,11 @@ docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting
 			break;
 	}
 
-	if (connecting) {
+	if (connecting && strcmp(current_icon_name, PIDGIN_STOCK_TRAY_CONNECT) != 0) {
 		icon_name = PIDGIN_STOCK_TRAY_CONNECT;
 	}
 
-	if (!blinked && pending) {
+	if (pending && strcmp(current_icon_name, PIDGIN_STOCK_TRAY_PENDING) != 0) {
 		icon_name = PIDGIN_STOCK_TRAY_PENDING;
 	}
 
diff --git a/pidgin/gtkdocklet.c b/pidgin/gtkdocklet.c
index 2d8955fa9c8e..9614dcc76d12 100644
--- a/pidgin/gtkdocklet.c
+++ b/pidgin/gtkdocklet.c
@@ -74,16 +74,16 @@ docklet_blink_icon(gpointer data)
 			if (blinked) {
 				ui_ops->blank_icon();
 			} else {
-				pidgin_docklet_update_icon(blinked);
+				pidgin_docklet_update_icon();
 			}
 		} else {
-			pidgin_docklet_update_icon(blinked);
+			pidgin_docklet_update_icon();
 		}
 		ret = TRUE; /* keep blinking */
 	} else {
 		docklet_blinking_timer = 0;
 		blinked = FALSE;
-		pidgin_docklet_update_icon(FALSE);
+		pidgin_docklet_update_icon();
 	}
 
 	return ret;
@@ -211,7 +211,7 @@ docklet_update_status(void)
 		pending = newpending;
 		connecting = newconnecting;
 
-		pidgin_docklet_update_icon(FALSE);
+		pidgin_docklet_update_icon();
 
 		/* and schedule the blinker function if messages are pending */
 		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink")
@@ -762,10 +762,10 @@ docklet_menu(void)
  * public api for ui_ops
  **************************************************************************/
 void
-pidgin_docklet_update_icon(gboolean blinked)
+pidgin_docklet_update_icon()
 {
 	if (ui_ops && ui_ops->update_icon)
-		ui_ops->update_icon(status, connecting, pending, blinked);
+		ui_ops->update_icon(status, connecting, pending);
 }
 
 void
@@ -799,7 +799,7 @@ pidgin_docklet_embedded()
 	}
 	visible = TRUE;
 	docklet_update_status();
-	pidgin_docklet_update_icon(FALSE);
+	pidgin_docklet_update_icon();
 }
 
 void
diff --git a/pidgin/gtkdocklet.h b/pidgin/gtkdocklet.h
index 7f188b92a204..34f88a14f5c4 100644
--- a/pidgin/gtkdocklet.h
+++ b/pidgin/gtkdocklet.h
@@ -31,7 +31,7 @@ struct docklet_ui_ops
 {
 	void (*create)(void);
 	void (*destroy)(void);
-	void (*update_icon)(PurpleStatusPrimitive, gboolean, gboolean, gboolean);
+	void (*update_icon)(PurpleStatusPrimitive, gboolean, gboolean);
 	void (*blank_icon)(void);
 	void (*set_tooltip)(gchar *);
 	GtkMenuPositionFunc position_menu;
@@ -39,7 +39,7 @@ struct docklet_ui_ops
 
 
 /* functions in gtkdocklet.c */
-void pidgin_docklet_update_icon(gboolean blinked);
+void pidgin_docklet_update_icon(void);
 void pidgin_docklet_clicked(int);
 void pidgin_docklet_embedded(void);
 void pidgin_docklet_remove(void);
diff --git a/pidgin/win32/gtkdocklet-win32.c b/pidgin/win32/gtkdocklet-win32.c
index 84609f111d64..b02666078e49 100644
--- a/pidgin/win32/gtkdocklet-win32.c
+++ b/pidgin/win32/gtkdocklet-win32.c
@@ -497,7 +497,7 @@ static void systray_remove_nid(void) {
 }
 
 static void winpidgin_tray_update_icon(PurpleStatusPrimitive status,
-		gboolean connecting, gboolean pending, gboolean blinked) {
+		gboolean connecting, gboolean pending) {
 
 	int icon_index;
 	g_return_if_fail(image != NULL);
-- 
2.14.4


From 158cc7bfb197be31401b01393f3a17522da16537 Mon Sep 17 00:00:00 2001
From: Daniel Kamil Kozar <dkk089@gmail.com>
Date: Sun, 10 Dec 2017 20:34:19 +0100
Subject: [PATCH 3/3] Use purple_strequal instead of strcmp

--HG--
branch : trac-17174
---
 pidgin/gtkdocklet-gtk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pidgin/gtkdocklet-gtk.c b/pidgin/gtkdocklet-gtk.c
index a948a0d7d5d8..4771e1e51483 100644
--- a/pidgin/gtkdocklet-gtk.c
+++ b/pidgin/gtkdocklet-gtk.c
@@ -160,11 +160,11 @@ docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting
 			break;
 	}
 
-	if (connecting && strcmp(current_icon_name, PIDGIN_STOCK_TRAY_CONNECT) != 0) {
+	if (connecting && !purple_strequal(current_icon_name, PIDGIN_STOCK_TRAY_CONNECT)) {
 		icon_name = PIDGIN_STOCK_TRAY_CONNECT;
 	}
 
-	if (pending && strcmp(current_icon_name, PIDGIN_STOCK_TRAY_PENDING) != 0) {
+	if (pending && !purple_strequal(current_icon_name, PIDGIN_STOCK_TRAY_PENDING)) {
 		icon_name = PIDGIN_STOCK_TRAY_PENDING;
 	}
 
-- 
2.14.4