]> git.mdlowis.com Git - proto/labwc.git/commitdiff
osd: refactor to eliminate usage of g_strcmp0()
authorJohan Malm <jgm323@gmail.com>
Wed, 27 Dec 2023 22:36:20 +0000 (22:36 +0000)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Thu, 28 Dec 2023 19:41:49 +0000 (20:41 +0100)
...to allow inclusion of ./scripts/find-banned in CI

No functional change intended.

src/osd.c

index e367b97d1ee7cdff38c3f934196a53984a5a5c75..cff3b429a35be02c4259ea819189be595ecbc825 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
 #include "window-rules.h"
 #include "workspaces.h"
 
-/* is title different from app_id/class? */
-static int
-is_title_different(struct view *view)
-{
-       switch (view->type) {
-       case LAB_XDG_SHELL_VIEW:
-               return g_strcmp0(view_get_string_prop(view, "title"),
-                       view_get_string_prop(view, "app_id"));
-#if HAVE_XWAYLAND
-       case LAB_XWAYLAND_VIEW:
-               return g_strcmp0(view_get_string_prop(view, "title"),
-                       view_get_string_prop(view, "class"));
-#endif
-       }
-       return 1;
-}
-
 static const char *
 get_formatted_app_id(struct view *view)
 {
@@ -256,13 +239,18 @@ get_app_id(struct view *view)
 }
 
 static const char *
-get_title(struct view *view)
+get_title_if_different(struct view *view)
 {
-       if (is_title_different(view)) {
-               return view_get_string_prop(view, "title");
-       } else {
-               return "";
+       /*
+        * XWayland clients return WM_CLASS for 'app_id' so we don't need a
+        * special case for that here.
+        */
+       const char *identifier = view_get_string_prop(view, "app_id");
+       const char *title = view_get_string_prop(view, "title");
+       if (!identifier) {
+               return title;
        }
+       return (!title || !strcmp(identifier, title)) ? NULL : title;
 }
 
 static void
@@ -371,7 +359,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
                                        break;
                                }
                        case LAB_FIELD_TITLE:
-                               buf_add(&buf, get_title(*view));
+                               buf_add(&buf, get_title_if_different(*view));
                                break;
                        default:
                                break;