fix: adapt app for gnome environments that have no tray

This commit is contained in:
noise 2026-03-01 04:02:14 +03:00
parent a566b78721
commit c8c147901e
3 changed files with 35 additions and 6 deletions

View File

@ -35,7 +35,7 @@
</screenshots> </screenshots>
<releases> <releases>
<release version="0.1.0" date="2026-02-28"> <release version="0.1.0" date="2026-03-01">
<description> <description>
<p>Initial release.</p> <p>Initial release.</p>
</description> </description>

View File

@ -93,10 +93,13 @@ static void toggle_window(MoeMojiApplication *self) {
} }
} }
static gboolean on_close_request(GtkWindow *window, static gboolean on_close_request(GtkWindow *window, gpointer user_data) {
G_GNUC_UNUSED gpointer user_data) { MoeMojiApplication *self = MOEMOJI_APPLICATION(user_data);
gtk_widget_set_visible(GTK_WIDGET(window), FALSE); if (self->has_tray) {
return TRUE; gtk_widget_set_visible(GTK_WIDGET(window), FALSE);
return TRUE;
}
return FALSE;
} }
static void dbusmenu_method_call(G_GNUC_UNUSED GDBusConnection *connection, static void dbusmenu_method_call(G_GNUC_UNUSED GDBusConnection *connection,
@ -291,8 +294,33 @@ static void setup_sni(MoeMojiApplication *self) {
if (self->dbus_conn == NULL) { if (self->dbus_conn == NULL) {
g_warning("session bus: %s", error->message); g_warning("session bus: %s", error->message);
g_clear_error(&error); g_clear_error(&error);
self->has_tray = FALSE;
return; return;
} }
GVariant *result = g_dbus_connection_call_sync(
self->dbus_conn, "org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", "NameHasOwner",
g_variant_new("(s)", "org.kde.StatusNotifierWatcher"), G_VARIANT_TYPE("(b)"),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (result == NULL) {
g_warning("NameHasOwner check failed: %s", error->message);
g_clear_error(&error);
self->has_tray = FALSE;
return;
}
gboolean watcher_exists = FALSE;
g_variant_get(result, "(b)", &watcher_exists);
g_variant_unref(result);
if (!watcher_exists) {
g_info("No StatusNotifierWatcher found, skipping tray setup");
self->has_tray = FALSE;
return;
}
self->has_tray = TRUE;
GDBusNodeInfo *sni_node = GDBusNodeInfo *sni_node =
g_dbus_node_info_new_for_xml(sni_introspection_xml, &error); g_dbus_node_info_new_for_xml(sni_introspection_xml, &error);
if (sni_node == NULL) { if (sni_node == NULL) {
@ -532,7 +560,7 @@ static void moemoji_application_activate(GApplication *app) {
self->window = g_object_new(MOEMOJI_TYPE_WINDOW, "application", self->window = g_object_new(MOEMOJI_TYPE_WINDOW, "application",
GTK_APPLICATION(self), NULL); GTK_APPLICATION(self), NULL);
g_signal_connect(self->window, "close-request", g_signal_connect(self->window, "close-request",
G_CALLBACK(on_close_request), NULL); G_CALLBACK(on_close_request), self);
self->window_created = TRUE; self->window_created = TRUE;
} else { } else {
toggle_window(self); toggle_window(self);

View File

@ -16,6 +16,7 @@ struct _MoeMojiApplication {
const gchar *tray_icon_name; const gchar *tray_icon_name;
GDBusProxy *shortcuts_proxy; GDBusProxy *shortcuts_proxy;
gchar *shortcuts_session_path; gchar *shortcuts_session_path;
gboolean has_tray;
}; };
G_BEGIN_DECLS G_BEGIN_DECLS