← Back to Pull requests

typing-break: Force dependency on appindicator3-0.1 and remove deprecated GtkStatusIcon #732

Merged
zhuyaliang merged 5 files (393 lines) on Oct 24, 2023 16:11 UTC
View on GitHub
zhuyaliang zhuyaliang commented on Oct 18, 2023 08:32 UTC
Author

gsettings set org.mate.typing-break enabled true

Diff: 393 lines (+61 / -332) across 5 files Reviewer: lukefromdc Review duration: 9098m
All Vouch review confidence checks passed
Residual risk 0.07 = Change Risk (0.45) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 393 lines diff across 5 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.74 · 5 substantive comment(s)
0.74
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
84%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.358
Real PR Conversation Timeline
34 items
cwendling cwendling commented on code on Oct 18, 2023 09:54 UTC
Code Review
configure.ac:1
@@ -193,6 +168,38 @@ fi
 
 AM_CONDITIONAL([HAVE_ACCOUNTSSERVICE], [test "x$have_accountsservice" = xyes])
 
+AYATANA_APPINDICATOR_PKG=ayatana-appindicator3-0.1
+UBUNTU_APPINDICATOR_PKG=appindicator3-0.1
+
+PKG_CHECK_EXISTS($AYATANA_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED,
+         [have_appindicator_ayatana="yes"],
+         [have_appindicator_ayatana="no"])
+PKG_CHECK_EXISTS($UBUNTU_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED,
+         [have_appindicator_ubuntu="yes"],
+         [have_appindicator_ubuntu="no"])
+
+AC_ARG_ENABLE([appindicator],
+          AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators]),
+          [enable_appindicator=$enableval],
+          [enable_appindicator="auto"])

This doesn't seem to be respected?

cwendling cwendling commented on code on Oct 18, 2023 09:55 UTC
Code Review
configure.ac:1
@@ -193,6 +168,38 @@ fi
 
 AM_CONDITIONAL([HAVE_ACCOUNTSSERVICE], [test "x$have_accountsservice" = xyes])
 
+AYATANA_APPINDICATOR_PKG=ayatana-appindicator3-0.1
+UBUNTU_APPINDICATOR_PKG=appindicator3-0.1
+
+PKG_CHECK_EXISTS($AYATANA_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED,
+         [have_appindicator_ayatana="yes"],
+         [have_appindicator_ayatana="no"])
+PKG_CHECK_EXISTS($UBUNTU_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED,
+         [have_appindicator_ubuntu="yes"],
+         [have_appindicator_ubuntu="no"])
+
+AC_ARG_ENABLE([appindicator],
+          AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators]),
+          [enable_appindicator=$enableval],
+          [enable_appindicator="auto"])
+
+if test "x$have_appindicator_ayatana" == "xyes"; then
+    AC_MSG_NOTICE([Buidling against Ayatana AppIndicator.])
+    PKG_CHECK_MODULES(AYATANA_APPINDICATOR,
+              [$AYATANA_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
+              [AC_DEFINE(HAVE_AYATANA_APPINDICATOR, 1, [Have Ayatana AppIndicator])])
+    AC_SUBST(AYATANA_APPINDICATOR_CFLAGS)
+    AC_SUBST(AYATANA_APPINDICATOR_LIBS)

No need to SC_SUBST the result of PKG_CHECK_MODULES, it does it already.

cwendling cwendling commented on code on Oct 18, 2023 09:55 UTC
Code Review
configure.ac:1
@@ -193,6 +168,38 @@ fi
 
 AM_CONDITIONAL([HAVE_ACCOUNTSSERVICE], [test "x$have_accountsservice" = xyes])
 
+AYATANA_APPINDICATOR_PKG=ayatana-appindicator3-0.1
+UBUNTU_APPINDICATOR_PKG=appindicator3-0.1
+
+PKG_CHECK_EXISTS($AYATANA_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED,
+         [have_appindicator_ayatana="yes"],
+         [have_appindicator_ayatana="no"])
+PKG_CHECK_EXISTS($UBUNTU_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED,
+         [have_appindicator_ubuntu="yes"],
+         [have_appindicator_ubuntu="no"])
+
+AC_ARG_ENABLE([appindicator],
+          AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators]),
+          [enable_appindicator=$enableval],
+          [enable_appindicator="auto"])
+
+if test "x$have_appindicator_ayatana" == "xyes"; then
+    AC_MSG_NOTICE([Buidling against Ayatana AppIndicator.])
+    PKG_CHECK_MODULES(AYATANA_APPINDICATOR,
+              [$AYATANA_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
+              [AC_DEFINE(HAVE_AYATANA_APPINDICATOR, 1, [Have Ayatana AppIndicator])])
+    AC_SUBST(AYATANA_APPINDICATOR_CFLAGS)
+    AC_SUBST(AYATANA_APPINDICATOR_LIBS)
+elif test "x$have_appindicator_ubuntu" == "xyes"; then
+    AC_MSG_NOTICE([Buidling against Ubuntu AppIndicator.])
+    PKG_CHECK_MODULES(UBUNTU_APPINDICATOR,
+              [$UBUNTU_APPINDICATOR_PKG >= $APPINDICATOR_REQUIRED],
+              [AC_DEFINE(HAVE_UBUNTU_APPINDICATOR, 1, [Have Ubuntu AppIndicator])])
+    AC_SUBST(UBUNTU_APPINDICATOR_CFLAGS)
+    AC_SUBST(UBUNTU_APPINDICATOR_LIBS)

Ditto

cwendling cwendling commented on code on Oct 18, 2023 09:57 UTC
Code Review
typing-break/Makefile.am:1
@@ -32,11 +32,6 @@ if HAVE_LIBCANBERRA_GTK
   mate_typing_monitor_LDADD += @LIBCANBERRA_GTK_LIBS@
 endif
 
-if HAVE_APP_INDICATOR
-  mate_typing_monitor_CFLAGS += -DHAVE_APP_INDICATOR @APP_INDICATOR_CFLAGS@
-  mate_typing_monitor_LDADD += @APP_INDICATOR_LIBS@

You still need to add the flags to mate_typing_monitor_*

cwendling cwendling commented on code on Oct 18, 2023 10:34 UTC
Code Review
typing-break/drwright.c:1
@@ -30,9 +30,7 @@
 #include <gtk/gtk.h>
 #include <gio/gio.h>
 
-#ifdef HAVE_APP_INDICATOR
 #include <libappindicator/app-indicator.h>

The ayatana-appindicator include is libayatana-appindicator/app-indicator

cwendling cwendling commented on Oct 18, 2023 10:38 UTC
Reviewer

Doesn't work yet with ayatana-appindicator (and probably not with appindicator either though), but I guess the cleanup is cool.

Here is a proposed patch to cleanup and fix ayatana-appindicator support: https://github.com/mate-desktop/mate-control-center/commit/2103e55ee1c5b26d9d81606615be07f68483f9e0 (branch of the same name as this PR on my fork if you want to fetch it)

cwendling cwendling commented on code on Oct 18, 2023 13:02 UTC
Code Review
typing-break/main.c:1
@@ -98,26 +77,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-#ifndef HAVE_APP_INDICATOR
-	if (!no_check && !have_tray ()) {

should we have something similar for appindicator? It should be doable checking whether there's a status notifier host registered. Not saying it's needed, just a thought.

cwendling cwendling commented on Oct 18, 2023 13:03 UTC
Reviewer

Seems to work from very basic testing with Ayatana AppIndicator

zhuyaliang zhuyaliang commented on code on Oct 18, 2023 13:47 UTC
Code Review
typing-break/main.c:1
@@ -98,26 +77,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-#ifndef HAVE_APP_INDICATOR
-	if (!no_check && !have_tray ()) {

done

lukefromdc lukefromdc commented on Oct 19, 2023 07:04 UTC
Reviewer

Builds fine and solves the issue with an "empty" grey hatched icon showing up when first setting a test work interval of one or two minutes. Instead of being delayed by one minute, the green time lapse bar icon showed up immediately.

However, the icon does not update, instead staying a full height green bar right up until the screen locks. I do not normally use this feature but recall the icon's green bar dropping with time and flashing in the last minute or so before the "take a break" screen lock renders.

Postponing breaks does not work and that button is greyed out but that's been true in master for a while

Tested with ayatana indicators, a 4K monitor, and window-scaling = 2, icon renders clear and sharp.

cwendling cwendling commented on code on Oct 19, 2023 07:38 UTC
Code Review
typing-break/main.c:1
@@ -98,26 +77,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-#ifndef HAVE_APP_INDICATOR
-	if (!no_check && !have_tray ()) {

Do you think checking for a tray makes sense? For us it does because the notification area does both SN host and system tray (on x11, on Wyaland there won't be a system tray I guess), but a better check would be whether there's the right DBus thingy at the right place -- not that I can tell you how to do that, but some inspiration from the SN host in notification-area might possibly help.

Then again, I'm not entirely sure how important that warning is in real life.

zhuyaliang zhuyaliang commented on code on Oct 19, 2023 11:39 UTC
Code Review
typing-break/main.c:1
@@ -98,26 +77,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-#ifndef HAVE_APP_INDICATOR
-	if (!no_check && !have_tray ()) {

I plan to use Dbus to check if the notification area exists, but I have encountered a problem,I'm not sure if it's my usage issue

dbus-send --session --print-reply=literal --dest=org.kde.StatusNotifierWatcher  /StatusNotifierWatcher org.freedesktop.DBus.Introspectable.Introspect

https://gitlab.gnome.org/GNOME/glib/-/issues/3150

cwendling cwendling commented on code on Oct 19, 2023 13:16 UTC
Code Review
typing-break/main.c:1
@@ -98,26 +77,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-#ifndef HAVE_APP_INDICATOR
-	if (!no_check && !have_tray ()) {

I barely know anything about DBus, let alone GDbus, but this seems to work (indeed g_dbus_proxy_new_for_bus_sync() don't seem to want to fail, but it's not necessarily a problem here):

#include <stdio.h>
#include <glib.h>
#include <gio/gio.h>

static gboolean
is_status_notifier_host_available (void)
{
    const gchar *service = "org.kde.StatusNotifierWatcher";
    const gchar *path = "/StatusNotifierWatcher";
    const gchar *interface = "org.kde.StatusNotifierWatcher";
    const gchar *property = "IsStatusNotifierHostRegistered";

    g_autoptr (GDBusProxy) proxy = NULL;
    g_autoptr (GError) error = NULL;

    proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                           G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
                                           G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
                                           NULL, service, path, interface,
                                           NULL, &error);

    if (proxy == NULL || error)
    {
        g_warning ("g_dbus_proxy_new_for_bus_sync() failed: %s", error->message);
        return FALSE;
    }

    g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, property);
    if (! variant)
    {
        g_warning ("Property %s.%s not found!", interface, property);
        return FALSE;
    }
    if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))
    {
        g_warning ("Property %s.%s is invalid", interface, property);
        return FALSE;
    }
    
    return g_variant_get_boolean(variant);
}

int main(void)
{
    fprintf (stderr, "Status Notifier host available? %s\n",
             is_status_notifier_host_available () ? "yes" : "no");

    return 0;
}

Checking IsStatusNotifierHostRegistered property sounds to me like a good thing to do, as I'd think it not only says there's a watcher, but also an actual host.
Anyway, take this with a grain of salt, again I'm not very knowledgeable about this stuff.

zhuyaliang zhuyaliang commented on code on Oct 19, 2023 14:53 UTC
Code Review
typing-break/main.c:1
@@ -98,26 +77,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-#ifndef HAVE_APP_INDICATOR
-	if (!no_check && !have_tray ()) {

work well

lukefromdc lukefromdc commented on Oct 19, 2023 16:34 UTC
Contributor

Latest force-pushed worked same as my last test, icon does not change. One difference that is harmless: with the status icon the tooltip shows time to next break, the menu shows it with the indicator.

lukefromdc lukefromdc approved these changes on Oct 19, 2023 16:49 UTC
Approved Reviewer

Icon updating isn't working properly here on the status icon with master either. In fact, the status icon seems to show the countdown backwards: the grey "empty" bar-png icon
renders FIRST, and bar-green.png gradually fills it from the bottom up-instead of emptying it from the top down. Flashing red for last few seconds works for the status icon only.
Everything else works, and the menu catches the actual time remaining.

If there is an easy fix for the icon behavior we can do it here (maybe we are not getting gdbus working properly here?), if not we can leave that for a later PR as the indicator behavior (a constant unchanging icon) isn't as counterintuitive as what the status icon is doing is.

zhuyaliang zhuyaliang commented on Oct 20, 2023 06:37 UTC
Author

@lukefromdc Leave this issue to future PR for resolution

lukefromdc lukefromdc commented on Oct 20, 2023 06:52 UTC
Contributor

No problem, I've approved this PR and am fine with merging it. We'll deal with the icon updating later

raveit65 raveit65 commented on code on Oct 20, 2023 14:16 UTC
Code Review
typing-break/main.c:1
@@ -29,28 +29,44 @@
 #include "drw-selection.h"
 #include "drwright.h"
 
+#define NOTIFIERAREA_NAME          "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PATH          "/StatusNotifierWatcher"
+#define NOTIFIERAREA_INTERFACE     "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PROPERTY      "IsStatusNotifierHostRegistered"
+
 gboolean debug = FALSE;
 
-#ifndef HAVE_APP_INDICATOR
 static gboolean
-have_tray (void)
+is_status_notifier_host_available (void)
 {
-	Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
-	Atom    selection_atom;
-	char   *selection_atom_name;
-
-	selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
-					       XScreenNumberOfScreen (xscreen));
-	selection_atom = gdk_x11_get_xatom_by_name (selection_atom_name);
-	g_free (selection_atom_name);
-
-	if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
-		return TRUE;
-	} else {
+	g_autoptr (GDBusProxy) proxy = NULL;
+	g_autoptr (GError) error = NULL;
+
+	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+	                                       NULL,
+	                                       NOTIFIERAREA_NAME,
+	                                       NOTIFIERAREA_PATH,
+	                                       NOTIFIERAREA_INTERFACE,
+	                                       NULL, &error);
+
+	if (proxy == NULL || error)
+	{
+		return FALSE;
+	}
+	g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, NOTIFIERAREA_PROPERTY);
+	if (! variant)
+	{
 		return FALSE;
 	}
+	if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))

Build warning in CI.
debian
https://app.travis-ci.com/github/mate-desktop/mate-control-center/jobs/611885988#L6843
fedora (normal compiler warn level)
https://app.travis-ci.com/github/mate-desktop/mate-control-center/jobs/611885989#L3087

main.c:63:39: warning: Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption [alpha.core.CastToStruct]

        if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))

                                             ^~~~~~~~~~~~~~~~~~~~~~

/usr/include/glib-2.0/glib/gvarianttype.h:50:46: note: expanded from macro 'G_VARIANT_TYPE_BOOLEAN'

#define G_VARIANT_TYPE_BOOLEAN              ((const GVariantType *) "b")

                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~

raveit65 raveit65 commented on Oct 20, 2023 15:01 UTC
Contributor

Beside from the build warning applet works same as before in fedora with UBUNTU_APPINDICATOR support.

zhuyaliang zhuyaliang commented on code on Oct 21, 2023 15:24 UTC
Code Review
typing-break/main.c:1
@@ -29,28 +29,44 @@
 #include "drw-selection.h"
 #include "drwright.h"
 
+#define NOTIFIERAREA_NAME          "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PATH          "/StatusNotifierWatcher"
+#define NOTIFIERAREA_INTERFACE     "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PROPERTY      "IsStatusNotifierHostRegistered"
+
 gboolean debug = FALSE;
 
-#ifndef HAVE_APP_INDICATOR
 static gboolean
-have_tray (void)
+is_status_notifier_host_available (void)
 {
-	Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
-	Atom    selection_atom;
-	char   *selection_atom_name;
-
-	selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
-					       XScreenNumberOfScreen (xscreen));
-	selection_atom = gdk_x11_get_xatom_by_name (selection_atom_name);
-	g_free (selection_atom_name);
-
-	if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
-		return TRUE;
-	} else {
+	g_autoptr (GDBusProxy) proxy = NULL;
+	g_autoptr (GError) error = NULL;
+
+	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+	                                       NULL,
+	                                       NOTIFIERAREA_NAME,
+	                                       NOTIFIERAREA_PATH,
+	                                       NOTIFIERAREA_INTERFACE,
+	                                       NULL, &error);
+
+	if (proxy == NULL || error)
+	{
+		return FALSE;
+	}
+	g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, NOTIFIERAREA_PROPERTY);
+	if (! variant)
+	{
 		return FALSE;
 	}
+	if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))

done

raveit65 raveit65 approved these changes on Oct 21, 2023 17:14 UTC
Approved Reviewer

LGTM

raveit65 raveit65 commented on Oct 21, 2023 17:15 UTC
Contributor

@cwendling
We have unresolved conversations?

zhuyaliang zhuyaliang commented on code on Oct 22, 2023 13:24 UTC
Code Review
typing-break/main.c:1
@@ -98,26 +77,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-#ifndef HAVE_APP_INDICATOR
-	if (!no_check && !have_tray ()) {

@cwendling Can I merge? I will delete libslab for the next PR and need to complete it on this basis

lukefromdc lukefromdc commented on Oct 23, 2023 19:19 UTC
Contributor

@cwendling, is this ready to go or should we wait?

cwendling cwendling commented on code on Oct 24, 2023 08:41 UTC
Code Review
typing-break/main.c:1
@@ -29,28 +29,44 @@
 #include "drw-selection.h"
 #include "drwright.h"
 
+#define NOTIFIERAREA_NAME          "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PATH          "/StatusNotifierWatcher"
+#define NOTIFIERAREA_INTERFACE     "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PROPERTY      "IsStatusNotifierHostRegistered"
+
 gboolean debug = FALSE;
 
-#ifndef HAVE_APP_INDICATOR
 static gboolean
-have_tray (void)
+is_status_notifier_host_available (void)
 {
-	Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
-	Atom    selection_atom;
-	char   *selection_atom_name;
-
-	selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
-					       XScreenNumberOfScreen (xscreen));
-	selection_atom = gdk_x11_get_xatom_by_name (selection_atom_name);
-	g_free (selection_atom_name);
-
-	if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
-		return TRUE;
-	} else {
+	g_autoptr (GDBusProxy) proxy = NULL;
+	g_autoptr (GError) error = NULL;
+
+	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+	                                       NULL,
+	                                       NOTIFIERAREA_NAME,
+	                                       NOTIFIERAREA_PATH,
+	                                       NOTIFIERAREA_INTERFACE,
+	                                       NULL, &error);
+
+	if (proxy == NULL || error)
+	{
+		return FALSE;
+	}
+	g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, NOTIFIERAREA_PROPERTY);
+	if (! variant)
+	{
 		return FALSE;
 	}
+	if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))

IMO this should be restored. Yes, GVariantType is kind of weird, but it's actually just strings. I guess the use of a virtual structure is to have a dedicated type and do some type validation, or room for future expansion maybe.
At any rate, the code was correct and not actually dangerous. If newer (?) compilers produce a warning, it might be interesting to report that to upstream GLib to see if they can come up with a clever trick to hide the spurious ones, or whatever they can do to silence this.

If we don't check the variant type, and it's not actually a boolean, the following g_variant_get_boolean() might warn, give unexpected results, or potentially crash in the future. The current implementation look pretty safe, but the documentation is clear that it's not supported.

cwendling cwendling commented on Oct 24, 2023 08:46 UTC
Reviewer

Apart from possibly the inline comment, LGTM

zhuyaliang zhuyaliang commented on code on Oct 24, 2023 09:22 UTC
Code Review
typing-break/main.c:1
@@ -29,28 +29,44 @@
 #include "drw-selection.h"
 #include "drwright.h"
 
+#define NOTIFIERAREA_NAME          "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PATH          "/StatusNotifierWatcher"
+#define NOTIFIERAREA_INTERFACE     "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PROPERTY      "IsStatusNotifierHostRegistered"
+
 gboolean debug = FALSE;
 
-#ifndef HAVE_APP_INDICATOR
 static gboolean
-have_tray (void)
+is_status_notifier_host_available (void)
 {
-	Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
-	Atom    selection_atom;
-	char   *selection_atom_name;
-
-	selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
-					       XScreenNumberOfScreen (xscreen));
-	selection_atom = gdk_x11_get_xatom_by_name (selection_atom_name);
-	g_free (selection_atom_name);
-
-	if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
-		return TRUE;
-	} else {
+	g_autoptr (GDBusProxy) proxy = NULL;
+	g_autoptr (GError) error = NULL;
+
+	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+	                                       NULL,
+	                                       NOTIFIERAREA_NAME,
+	                                       NOTIFIERAREA_PATH,
+	                                       NOTIFIERAREA_INTERFACE,
+	                                       NULL, &error);
+
+	if (proxy == NULL || error)
+	{
+		return FALSE;
+	}
+	g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, NOTIFIERAREA_PROPERTY);
+	if (! variant)
+	{
 		return FALSE;
 	}
+	if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))

``g_variant_get_boolean` checks the type, so can remove additional type checks `g_variant_is_of_type ``
https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gvariant.c?ref_type=heads#L369

raveit65 raveit65 commented on Oct 24, 2023 09:24 UTC
Contributor

If we really should produce build warnings this should be commented in code.
Otherwise this can be removed in future again by mistake because we forgot why we accept a warning.
Ihmo, i would prefer to leave code warnings free and wait for bugreport if it really produce a crash.

cwendling cwendling commented on code on Oct 24, 2023 10:15 UTC
Code Review
typing-break/main.c:1
@@ -29,28 +29,44 @@
 #include "drw-selection.h"
 #include "drwright.h"
 
+#define NOTIFIERAREA_NAME          "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PATH          "/StatusNotifierWatcher"
+#define NOTIFIERAREA_INTERFACE     "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PROPERTY      "IsStatusNotifierHostRegistered"
+
 gboolean debug = FALSE;
 
-#ifndef HAVE_APP_INDICATOR
 static gboolean
-have_tray (void)
+is_status_notifier_host_available (void)
 {
-	Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
-	Atom    selection_atom;
-	char   *selection_atom_name;
-
-	selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
-					       XScreenNumberOfScreen (xscreen));
-	selection_atom = gdk_x11_get_xatom_by_name (selection_atom_name);
-	g_free (selection_atom_name);
-
-	if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
-		return TRUE;
-	} else {
+	g_autoptr (GDBusProxy) proxy = NULL;
+	g_autoptr (GError) error = NULL;
+
+	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+	                                       NULL,
+	                                       NOTIFIERAREA_NAME,
+	                                       NOTIFIERAREA_PATH,
+	                                       NOTIFIERAREA_INTERFACE,
+	                                       NULL, &error);
+
+	if (proxy == NULL || error)
+	{
+		return FALSE;
+	}
+	g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, NOTIFIERAREA_PROPERTY);
+	if (! variant)
+	{
 		return FALSE;
 	}
+	if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))

TYPE_CHECK() is calling g_return_val_if_fail(), which might be disabled at build time (although I guess nobody does that). And either way, it'll produce a fairly nasty warning.

cwendling cwendling commented on Oct 24, 2023 10:20 UTC
Contributor

If we really should produce build warnings this should be commented in code. Otherwise this can be removed in future again by mistake because we forgot why we accept a warning.

Fair enough. But it's actually none of our own code, it's just using GLib API as intended… so we could add a comment about that API being broken in that regard, but that'd look a tad odd :)

Ihmo, i would prefer to leave code warnings free and wait for bugreport if it really produce a crash.

Fair enough. But I'd rather not have crashes in the first place, because that's way nastier than a warning. Either way, in practice this probably doesn't actually matter because the property is gonna be of the right type, and currently g_variant_get_boolean() is safe enough.

So just as you guys like best, I don't mind.

zhuyaliang zhuyaliang commented on code on Oct 24, 2023 11:25 UTC
Code Review
typing-break/main.c:1
@@ -29,28 +29,44 @@
 #include "drw-selection.h"
 #include "drwright.h"
 
+#define NOTIFIERAREA_NAME          "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PATH          "/StatusNotifierWatcher"
+#define NOTIFIERAREA_INTERFACE     "org.kde.StatusNotifierWatcher"
+#define NOTIFIERAREA_PROPERTY      "IsStatusNotifierHostRegistered"
+
 gboolean debug = FALSE;
 
-#ifndef HAVE_APP_INDICATOR
 static gboolean
-have_tray (void)
+is_status_notifier_host_available (void)
 {
-	Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
-	Atom    selection_atom;
-	char   *selection_atom_name;
-
-	selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
-					       XScreenNumberOfScreen (xscreen));
-	selection_atom = gdk_x11_get_xatom_by_name (selection_atom_name);
-	g_free (selection_atom_name);
-
-	if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
-		return TRUE;
-	} else {
+	g_autoptr (GDBusProxy) proxy = NULL;
+	g_autoptr (GError) error = NULL;
+
+	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+	                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+	                                       NULL,
+	                                       NOTIFIERAREA_NAME,
+	                                       NOTIFIERAREA_PATH,
+	                                       NOTIFIERAREA_INTERFACE,
+	                                       NULL, &error);
+
+	if (proxy == NULL || error)
+	{
+		return FALSE;
+	}
+	g_autoptr (GVariant) variant = g_dbus_proxy_get_cached_property (proxy, NOTIFIERAREA_PROPERTY);
+	if (! variant)
+	{
 		return FALSE;
 	}
+	if (! g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))

It's right to be careful, but ``g_variant_get_boolean()` is secure enough, and the `IsStatusNotifierHostRegistered` type is known and controllable, so `g_variant_get_boolean()`` will not fail,type check can be removed

raveit65 raveit65 commented on Oct 24, 2023 16:10 UTC
Contributor

Good, than let us merge PR like it is :)

Reviewers
Assignees
zhuyaliang zhuyaliang
Labels
risk: low confidence: 84.3% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 44.6% (MEDIUM) · Higher = larger blast radius
44.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 84.3% · Lower = rushed or shallow review
84.3%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 7% · Safe to merge
7%