From 77dc4e95951666591a9e9a636450a6f5fd1709b1 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <fourdan@xfce.org>
Date: Sat, 14 Mar 2015 22:12:29 +0100
Subject: [PATCH] Check class hint name for same applications

Bug: 11685

There was some confusion in the definition of "same application" when
cycling through windows of the same application.

Same application meant windows which share a common leader or from the
same group, which basically means the same running application, not
two different instances of the same program.

Widen the search criteria to the WM class "resource name" which
contains the application name so that multiple different  instances of
the same program/application can be included.

Signed-off-by: Olivier Fourdan <fourdan@xfce.org>
---
 src/transients.c | 15 +++++++++++++++
 src/transients.h |  4 +++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/transients.c b/src/transients.c
index 3cd21058d..a337ab081 100644
--- a/src/transients.c
+++ b/src/transients.c
@@ -112,6 +112,20 @@ clientSameLeader (Client * c1, Client * c2)
              (c2->client_leader == c1->window)));
 }
 
+gboolean
+clientSameName (Client * c1, Client * c2)
+{
+    g_return_val_if_fail (c1 != NULL, FALSE);
+    g_return_val_if_fail (c2 != NULL, FALSE);
+
+    TRACE ("entering clientSameName");
+
+    return ((c1 != c2) &&
+            (c1->class.res_class != NULL) &&
+            (c2->class.res_class != NULL) &&
+            (strcmp (c1->class.res_name, c2->class.res_name) == 0));
+}
+
 gboolean
 clientIsTransientFor (Client * c1, Client * c2)
 {
@@ -445,6 +459,7 @@ clientSameApplication (Client *c1, Client *c2)
             clientIsTransientOrModalFor (c2, c1) ||
             clientSameGroup (c1, c2) ||
             clientSameLeader (c1, c2) ||
+            clientSameName (c1, c2) ||
             (c1->pid != 0 && c1->pid == c2->pid &&
              c1->hostname && c2->hostname &&
              !g_ascii_strcasecmp (c1->hostname, c2->hostname)));
diff --git a/src/transients.h b/src/transients.h
index 702fe79a2..029e25dcb 100644
--- a/src/transients.h
+++ b/src/transients.h
@@ -37,7 +37,9 @@ gboolean                 clientIsTransientOrModal               (Client *);
 gboolean                 clientIsValidTransientOrModal          (Client *);
 gboolean                 clientSameGroup                        (Client *,
                                                                  Client *);
-gboolean                 clientSameLeader                        (Client *,
+gboolean                 clientSameLeader                       (Client *,
+                                                                 Client *);
+gboolean                 clientSameName                         (Client *,
                                                                  Client *);
 gboolean                 clientSameApplication                  (Client *,
                                                                  Client *);
-- 
GitLab