Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package fcitx5-gtk for openSUSE:Factory 
checked in at 2026-11-28 23:24:57
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/fcitx5-gtk (Old)
 and      /work/SRC/openSUSE:Factory/.fcitx5-gtk.new.1340718 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "fcitx5-gtk"

Sat Nov 28 23:24:57 2026 rev:17 rq:1401230 version:5.1.8

Changes:
--------
--- /work/SRC/openSUSE:Factory/fcitx5-gtk/fcitx5-gtk.changes    2026-10-22 
15:50:13.508924215 +0200
+++ /work/SRC/openSUSE:Factory/.fcitx5-gtk.new.1340718/fcitx5-gtk.changes       
2026-11-28 23:26:02.975558300 +0100
@@ -1,0 +2,10 @@
+Sat Nov 28 04:04:49 UTC 2026 - Marguerite Su <[email protected]>
+
+- Update to 5.1.8
+  * Add stronger reference-counting protection and fix a memory leak
+  * Avoid use-after-free when removing the last reference after g_source_remove
+  * Use the well-known D-Bus name for CreateInputContext/Version
+    requests to satisfy current AppArmor rules
+  * Fix GIR warning
+
+-------------------------------------------------------------------

Old:
----
  fcitx5-gtk-5.1.7.tar.zst

New:
----
  fcitx5-gtk-5.1.8.tar.zst

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ fcitx5-gtk.spec ++++++
--- /var/tmp/diff_new_pack.pjRcP7/_old  2026-11-28 23:26:03.621585283 +0100
+++ /var/tmp/diff_new_pack.pjRcP7/_new  2026-11-28 23:26:03.623585366 +0100
@@ -17,7 +17,7 @@
 
 
 Name:           fcitx5-gtk
-Version:        5.1.7
+Version:        5.1.8
 Release:        0
 Summary:        Gtk im module for fcitx5 and glib based dbus client library
 License:        LGPL-2.1-or-later

++++++ fcitx5-gtk-5.1.7.tar.zst -> fcitx5-gtk-5.1.8.tar.zst ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/fcitx5-gtk-5.1.7/CMakeLists.txt 
new/fcitx5-gtk-5.1.8/CMakeLists.txt
--- old/fcitx5-gtk-5.1.7/CMakeLists.txt 2026-06-20 06:19:08.000000000 +0200
+++ new/fcitx5-gtk-5.1.8/CMakeLists.txt 2026-11-27 20:21:47.000000000 +0100
@@ -1,5 +1,5 @@
-cmake_minimum_required(VERSION 3.6)
-project(fcitx5-gtk VERSION 5.1.7)
+cmake_minimum_required(VERSION 3.13)
+project(fcitx5-gtk VERSION 5.1.8)
 
 find_package(ECM REQUIRED 1.0.0)
 set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 
${CMAKE_MODULE_PATH})
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/fcitx5-gtk-5.1.7/fcitx-gclient/fcitxgclient.c 
new/fcitx5-gtk-5.1.8/fcitx-gclient/fcitxgclient.c
--- old/fcitx5-gtk-5.1.7/fcitx-gclient/fcitxgclient.c   2026-06-20 
06:19:08.000000000 +0200
+++ new/fcitx5-gtk-5.1.8/fcitx-gclient/fcitxgclient.c   2026-11-27 
20:21:47.000000000 +0100
@@ -7,6 +7,15 @@
 #include "fcitxgwatcher.h"
 #include "marshall.h"
 
+#define FCITX_MAIN_SERVICE_NAME "org.fcitx.Fcitx5"
+#define FCITX_PORTAL_SERVICE_NAME "org.freedesktop.portal.Fcitx"
+
+typedef enum {
+    FCITX_SERVICE_NONE = 0,
+    FCITX_SERVICE_MAIN,
+    FCITX_SERVICE_PORTAL,
+} FcitxServiceType;
+
 typedef struct _ProcessKeyStruct ProcessKeyStruct;
 
 /**
@@ -41,35 +50,22 @@
 };
 
 struct _FcitxGClientPrivate {
-    GDBusProxy *improxy;
+    FcitxGWatcher *watcher;
+    gboolean main_available;
+    gboolean portal_available;
+    FcitxServiceType current_service;
+    GCancellable *cancellable;
+    guint recheck_timeout_id;
+
     GDBusProxy *icproxy;
-    gchar *icname;
     guint8 uuid[16];
     gchar *display;
     gchar *program;
 
-    GCancellable *cancellable;
-    FcitxGWatcher *watcher;
-    guint watch_id;
-
     guint32 version;
     gboolean batch;
 };
 
-static const gchar introspection_xml[] =
-    "<node>"
-    "  <interface name=\"org.fcitx.Fcitx.InputMethod1\">"
-    "    <method name=\"CreateInputContext\">\n"
-    "      <arg direction=\"in\" type=\"a(ss)\"/>\n"
-    "      <arg direction=\"out\" type=\"o\"/>\n"
-    "      <arg direction=\"out\" type=\"ay\"/>\n"
-    "    </method>\n"
-    "    <method name=\"Version\">\n"
-    "      <arg direction=\"out\" type=\"u\"/>\n"
-    "    </method>\n"
-    "  </interface>"
-    "</node>";
-
 static const gchar ic_introspection_xml[] =
     "<node>\n"
     "  <interface name=\"org.fcitx.Fcitx.InputContext1\">\n"
@@ -191,20 +187,16 @@
 
 static guint signals[LAST_SIGNAL] = {0};
 
-static GDBusInterfaceInfo *_fcitx_g_client_get_interface_info(void);
 static GDBusInterfaceInfo *_fcitx_g_client_get_clientic_info(void);
 
-static void _fcitx_g_client_update_availability(FcitxGClient *self);
-static void _fcitx_g_client_availability_changed(FcitxGWatcher *connection,
-                                                 gboolean avail,
-                                                 gpointer user_data);
-static void _fcitx_g_client_service_vanished(GDBusConnection *conn,
-                                             const gchar *name,
-                                             gpointer user_data);
-static void _fcitx_g_client_create_ic(FcitxGClient *self);
-static void _fcitx_g_client_create_ic_phase1_finished(GObject *source_object,
-                                                      GAsyncResult *res,
+static void _fcitx_g_client_delayed_recheck(FcitxGClient *self);
+static void _fcitx_g_client_main_availability_changed(FcitxGWatcher *watcher,
+                                                      gboolean avail,
                                                       gpointer user_data);
+static void _fcitx_g_client_portal_availability_changed(FcitxGWatcher *watcher,
+                                                        gboolean avail,
+                                                        gpointer user_data);
+static void _fcitx_g_client_create_ic(FcitxGClient *self);
 static void _fcitx_g_client_version_cb(GObject *source_object,
                                        GAsyncResult *res, gpointer user_data);
 static void _fcitx_g_client_create_ic_cb(GObject *source_object,
@@ -247,7 +239,6 @@
         return info;                                                           
\
     }
 
-STATIC_INTERFACE_INFO(_fcitx_g_client_get_interface_info, introspection_xml)
 STATIC_INTERFACE_INFO(_fcitx_g_client_get_clientic_info, ic_introspection_xml)
 
 static void fcitx_g_client_class_init(FcitxGClientClass *klass) {
@@ -381,13 +372,14 @@
     self->priv = fcitx_g_client_get_instance_private(self);
 
     self->priv->watcher = NULL;
+    self->priv->main_available = FALSE;
+    self->priv->portal_available = FALSE;
+    self->priv->current_service = FCITX_SERVICE_NONE;
     self->priv->cancellable = NULL;
-    self->priv->improxy = NULL;
+    self->priv->recheck_timeout_id = 0;
     self->priv->icproxy = NULL;
-    self->priv->icname = NULL;
     self->priv->display = NULL;
     self->priv->program = NULL;
-    self->priv->watch_id = 0;
     self->priv->version = 0;
     self->priv->batch = TRUE;
 }
@@ -397,14 +389,21 @@
     G_OBJECT_CLASS(fcitx_g_client_parent_class)->constructed(object);
     if (!self->priv->watcher) {
         self->priv->watcher = fcitx_g_watcher_new();
-        g_object_ref_sink(self->priv->watcher);
         fcitx_g_watcher_watch(self->priv->watcher);
     }
-    g_signal_connect(self->priv->watcher, "availability-changed",
-                     (GCallback)_fcitx_g_client_availability_changed, self);
-    _fcitx_g_client_availability_changed(
-        self->priv->watcher,
-        fcitx_g_watcher_is_service_available(self->priv->watcher), self);
+    g_signal_connect(self->priv->watcher, "main-service-availability-changed",
+                     (GCallback)_fcitx_g_client_main_availability_changed,
+                     self);
+    g_signal_connect(self->priv->watcher, 
"portal-service-availability-changed",
+                     (GCallback)_fcitx_g_client_portal_availability_changed,
+                     self);
+    self->priv->main_available =
+        fcitx_g_watcher_get_main_service_name(self->priv->watcher) != NULL;
+    self->priv->portal_available =
+        fcitx_g_watcher_get_portal_service_name(self->priv->watcher) != NULL;
+    if (self->priv->main_available || self->priv->portal_available) {
+        _fcitx_g_client_delayed_recheck(self);
+    }
 }
 
 static void fcitx_g_client_finalize(GObject *object) {
@@ -416,12 +415,17 @@
 static void fcitx_g_client_dispose(GObject *object) {
     FcitxGClient *self = FCITX_G_CLIENT(object);
 
+    g_clear_handle_id(&self->priv->recheck_timeout_id, g_source_remove);
+
     if (self->priv->icproxy) {
         g_dbus_proxy_call(self->priv->icproxy, "DestroyIC", NULL,
                           G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
     }
 
-    g_signal_handlers_disconnect_by_data(self->priv->watcher, self);
+    if (self->priv->watcher) {
+        g_signal_handlers_disconnect_by_data(self->priv->watcher, self);
+        g_clear_object(&self->priv->watcher);
+    }
     _fcitx_g_client_clean_up(self);
 
     g_clear_pointer(&self->priv->display, g_free);
@@ -596,11 +600,12 @@
 
     gboolean ret = FALSE;
     if (self->priv->version > 0 && self->priv->batch) {
+        g_object_ref(self);
         g_autoptr(GVariantIter) iter = NULL;
         g_variant_get(result, "(a(uv)b)", &iter, &ret);
         GVariant *event;
         while ((event = g_variant_iter_next_value(iter))) {
-            GVariant *data;
+            g_autoptr(GVariant) data = NULL;
             guint32 type;
             g_variant_get(event, "(uv)", &type, &data);
             switch (type) {
@@ -621,6 +626,7 @@
             }
             g_variant_unref(event);
         }
+        g_object_unref(self);
     } else {
         g_variant_get(result, "(b)", &ret);
     }
@@ -673,7 +679,7 @@
  * @timeout_msec: timeout in millisecond
  * @cancellable: cancellable
  * @callback: (scope async) (closure user_data): callback
- * @user_data: (closure): user data
+ * @user_data: user data
  *
  * use this function with #fcitx_g_client_process_key_finish
  **/
@@ -731,110 +737,190 @@
     return ret;
 }
 
-static void
-_fcitx_g_client_availability_changed(G_GNUC_UNUSED FcitxGWatcher *connection,
-                                     G_GNUC_UNUSED gboolean avail,
-                                     gpointer user_data) {
-    FcitxGClient *self = user_data;
-    _fcitx_g_client_update_availability(self);
+static const gchar *
+_fcitx_g_client_get_well_known_service_name(FcitxServiceType service) {
+    switch (service) {
+    case FCITX_SERVICE_MAIN:
+        return FCITX_MAIN_SERVICE_NAME;
+    case FCITX_SERVICE_PORTAL:
+        return FCITX_PORTAL_SERVICE_NAME;
+    default:
+        return NULL;
+    }
 }
 
-static void _fcitx_g_client_update_availability(FcitxGClient *self) {
-    g_timeout_add_full(G_PRIORITY_DEFAULT, 100, _fcitx_g_client_recheck,
-                       g_object_ref(self), g_object_unref);
+static const gchar *
+_fcitx_g_client_get_service_owner(FcitxGClient *self,
+                                  FcitxServiceType service) {
+    if (!self->priv->watcher) {
+        return NULL;
+    }
+    if (service == FCITX_SERVICE_MAIN) {
+        return self->priv->main_available
+                   ? fcitx_g_watcher_get_main_service_name(self->priv->watcher)
+                   : NULL;
+    }
+    if (service == FCITX_SERVICE_PORTAL) {
+        return self->priv->portal_available
+                   ? fcitx_g_watcher_get_portal_service_name(
+                         self->priv->watcher)
+                   : NULL;
+    }
+    return NULL;
 }
 
-static gboolean _fcitx_g_client_recheck(gpointer user_data) {
-    FcitxGClient *self = user_data;
-    // Check we are not valid or in the process of create ic.
-    if (!fcitx_g_client_is_valid(self) && self->priv->cancellable == NULL &&
-        fcitx_g_watcher_is_service_available(self->priv->watcher)) {
-        _fcitx_g_client_create_ic(self);
+static FcitxServiceType
+_fcitx_g_client_get_available_service(FcitxGClient *self) {
+    if (_fcitx_g_client_get_service_owner(self, FCITX_SERVICE_MAIN)) {
+        return FCITX_SERVICE_MAIN;
     }
-    if (!fcitx_g_watcher_is_service_available(self->priv->watcher)) {
-        _fcitx_g_client_clean_up(self);
+    if (_fcitx_g_client_get_service_owner(self, FCITX_SERVICE_PORTAL)) {
+        return FCITX_SERVICE_PORTAL;
     }
-    return FALSE;
+    return FCITX_SERVICE_NONE;
 }
 
-static void _fcitx_g_client_create_ic(FcitxGClient *self) {
-    
g_return_if_fail(fcitx_g_watcher_is_service_available(self->priv->watcher));
-
-    _fcitx_g_client_clean_up(self);
+static gboolean _fcitx_g_client_is_icproxy_available(FcitxGClient *self) {
+    if (!self->priv->icproxy) {
+        return FALSE;
+    }
+    const gchar *ic_owner = g_dbus_proxy_get_name(self->priv->icproxy);
+    const gchar *main_owner =
+        _fcitx_g_client_get_service_owner(self, FCITX_SERVICE_MAIN);
+    const gchar *portal_owner =
+        _fcitx_g_client_get_service_owner(self, FCITX_SERVICE_PORTAL);
+    return (main_owner && g_strcmp0(ic_owner, main_owner) == 0) ||
+           (portal_owner && g_strcmp0(ic_owner, portal_owner) == 0);
+}
 
-    const gchar *service_name =
-        fcitx_g_watcher_get_service_name(self->priv->watcher);
-    GDBusConnection *connection =
-        fcitx_g_watcher_get_connection(self->priv->watcher);
-    self->priv->watch_id = g_bus_watch_name_on_connection(
-        connection, service_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL,
-        _fcitx_g_client_service_vanished, self, NULL);
+static void _fcitx_g_client_handle_availability_changed(FcitxGClient *self) {
+    if (self->priv->icproxy) {
+        if (_fcitx_g_client_is_icproxy_available(self)) {
+            return;
+        }
+        _fcitx_g_client_clean_up(self);
+    } else if (self->priv->cancellable) {
+        if (_fcitx_g_client_get_service_owner(
+                self, self->priv->current_service) != NULL) {
+            return;
+        }
+        _fcitx_g_client_clean_up(self);
+    }
 
-    self->priv->cancellable = g_cancellable_new();
-    g_dbus_proxy_new(connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
-                     _fcitx_g_client_get_interface_info(), service_name,
-                     "/org/freedesktop/portal/inputmethod",
-                     "org.fcitx.Fcitx.InputMethod1", self->priv->cancellable,
-                     _fcitx_g_client_create_ic_phase1_finished,
-                     g_object_ref(self));
+    if (_fcitx_g_client_get_available_service(self) != FCITX_SERVICE_NONE) {
+        _fcitx_g_client_delayed_recheck(self);
+    }
 }
 
 static void
-_fcitx_g_client_service_vanished(G_GNUC_UNUSED GDBusConnection *conn,
-                                 G_GNUC_UNUSED const gchar *name,
-                                 gpointer user_data) {
+_fcitx_g_client_main_availability_changed(G_GNUC_UNUSED FcitxGWatcher *watcher,
+                                          gboolean avail, gpointer user_data) {
     FcitxGClient *self = user_data;
-    _fcitx_g_client_clean_up(self);
-    _fcitx_g_client_update_availability(self);
+    avail = !!avail;
+    if (self->priv->main_available == avail) {
+        return;
+    }
+    self->priv->main_available = avail;
+    _fcitx_g_client_handle_availability_changed(self);
 }
 
-static void
-_fcitx_g_client_create_ic_phase1_finished(G_GNUC_UNUSED GObject *source_object,
-                                          GAsyncResult *res,
-                                          gpointer user_data) {
+static void _fcitx_g_client_portal_availability_changed(
+    G_GNUC_UNUSED FcitxGWatcher *watcher, gboolean avail, gpointer user_data) {
     FcitxGClient *self = user_data;
-    g_return_if_fail(user_data != NULL);
-    g_return_if_fail(FCITX_G_IS_CLIENT(user_data));
+    avail = !!avail;
+    if (self->priv->portal_available == avail) {
+        return;
+    }
+    self->priv->portal_available = avail;
+    _fcitx_g_client_handle_availability_changed(self);
+}
 
-    g_clear_object(&self->priv->cancellable);
-    g_clear_object(&self->priv->improxy);
+static void _fcitx_g_client_delayed_recheck(FcitxGClient *self) {
+    g_object_ref(self);
+    g_clear_handle_id(&self->priv->recheck_timeout_id, g_source_remove);
+    self->priv->recheck_timeout_id = g_timeout_add_full(
+        G_PRIORITY_DEFAULT, 100, _fcitx_g_client_recheck, self, 
g_object_unref);
+}
 
-    self->priv->improxy = g_dbus_proxy_new_finish(res, NULL);
-    if (!self->priv->improxy) {
-        _fcitx_g_client_clean_up(self);
-        g_object_unref(self);
+static gboolean _fcitx_g_client_recheck(gpointer user_data) {
+    FcitxGClient *self = user_data;
+    self->priv->recheck_timeout_id = 0;
+    if (!fcitx_g_client_is_valid(self) && self->priv->cancellable == NULL &&
+        _fcitx_g_client_get_available_service(self) != FCITX_SERVICE_NONE) {
+        _fcitx_g_client_create_ic(self);
+    }
+    return FALSE;
+}
+
+static void _fcitx_g_client_create_ic(FcitxGClient *self) {
+    if (!self->priv->watcher) {
         return;
     }
+    GDBusConnection *connection =
+        fcitx_g_watcher_get_connection(self->priv->watcher);
+    FcitxServiceType service = _fcitx_g_client_get_available_service(self);
+    const gchar *service_name =
+        _fcitx_g_client_get_well_known_service_name(service);
+    if (!connection || !service_name) {
+        return;
+    }
+
+    _fcitx_g_client_clean_up(self);
 
+    self->priv->current_service = service;
     self->priv->cancellable = g_cancellable_new();
+    g_dbus_connection_call(
+        connection, service_name, "/org/freedesktop/portal/inputmethod",
+        "org.fcitx.Fcitx.InputMethod1", "Version", NULL, G_VARIANT_TYPE("(u)"),
+        G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout */
+        self->priv->cancellable, _fcitx_g_client_version_cb,
+        g_object_ref(self));
+}
 
-    g_dbus_proxy_call(self->priv->improxy, "Version", NULL,
-                      G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */
-                      self->priv->cancellable, _fcitx_g_client_version_cb,
-                      self);
+static void _fcitx_g_client_handle_create_ic_error(FcitxGClient *self) {
+    if (self->priv->current_service == FCITX_SERVICE_MAIN) {
+        self->priv->main_available = FALSE;
+    } else if (self->priv->current_service == FCITX_SERVICE_PORTAL) {
+        self->priv->portal_available = FALSE;
+    }
+    _fcitx_g_client_clean_up(self);
+    _fcitx_g_client_create_ic(self);
 }
 
-static void _fcitx_g_client_version_cb(G_GNUC_UNUSED GObject *source_object,
+static void _fcitx_g_client_version_cb(GObject *source_object,
                                        GAsyncResult *res, gpointer user_data) {
     FcitxGClient *self = (FcitxGClient *)user_data;
-    g_clear_object(&self->priv->cancellable);
 
     g_autoptr(GError) error = NULL;
-    g_autoptr(GVariant) result =
-        g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error);
+    g_autoptr(GVariant) result = g_dbus_connection_call_finish(
+        G_DBUS_CONNECTION(source_object), res, &error);
+    if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+        self->priv->current_service == FCITX_SERVICE_NONE) {
+        g_object_unref(self);
+        return;
+    }
+
+    GDBusConnection *connection =
+        fcitx_g_watcher_get_connection(self->priv->watcher);
+    const gchar *service_name = _fcitx_g_client_get_well_known_service_name(
+        self->priv->current_service);
+    if (!connection || !service_name) {
+        _fcitx_g_client_handle_create_ic_error(self);
+        g_object_unref(self);
+        return;
+    }
 
-    if (error && g_dbus_error_is_remote_error(error) &&
-        g_strcmp0(g_dbus_error_get_remote_error(error),
-                  "org.freedesktop.DBus.Error.UnknownMethod") == 0) {
+    if (g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
         self->priv->version = 0;
     } else if (result) {
         g_variant_get(result, "(u)", &self->priv->version);
     } else {
-        _fcitx_g_client_clean_up(self);
+        _fcitx_g_client_handle_create_ic_error(self);
         g_object_unref(self);
         return;
     }
 
+    g_clear_object(&self->priv->cancellable);
     self->priv->cancellable = g_cancellable_new();
 
     GVariantBuilder builder;
@@ -845,24 +931,34 @@
     if (self->priv->program) {
         g_variant_builder_add(&builder, "(ss)", "program", 
self->priv->program);
     }
-    g_dbus_proxy_call(self->priv->improxy, "CreateInputContext",
-                      g_variant_new("(a(ss))", &builder),
-                      G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */
-                      self->priv->cancellable, _fcitx_g_client_create_ic_cb,
-                      self);
+    g_dbus_connection_call(
+        connection, service_name, "/org/freedesktop/portal/inputmethod",
+        "org.fcitx.Fcitx.InputMethod1", "CreateInputContext",
+        g_variant_new("(a(ss))", &builder), G_VARIANT_TYPE("(oay)"),
+        G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout */
+        self->priv->cancellable, _fcitx_g_client_create_ic_cb, self);
 }
 
 static void _fcitx_g_client_create_ic_cb(GObject *source_object,
                                          GAsyncResult *res,
                                          gpointer user_data) {
     FcitxGClient *self = (FcitxGClient *)user_data;
-    g_clear_object(&self->priv->cancellable);
 
-    g_autoptr(GVariant) result =
-        g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, NULL);
+    g_autoptr(GError) error = NULL;
+    g_autoptr(GVariant) result = g_dbus_connection_call_finish(
+        G_DBUS_CONNECTION(source_object), res, &error);
+    if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+        self->priv->current_service == FCITX_SERVICE_NONE) {
+        g_object_unref(self);
+        return;
+    }
 
-    if (!result) {
-        _fcitx_g_client_clean_up(self);
+    const gchar *unique_name =
+        _fcitx_g_client_get_service_owner(self, self->priv->current_service);
+    GDBusConnection *connection =
+        fcitx_g_watcher_get_connection(self->priv->watcher);
+    if (!result || !unique_name || !connection) {
+        _fcitx_g_client_handle_create_ic_error(self);
         g_object_unref(self);
         return;
     }
@@ -884,14 +980,12 @@
         }
     }
 
-    self->priv->icname = g_strdup(path);
+    g_clear_object(&self->priv->cancellable);
     self->priv->cancellable = g_cancellable_new();
-    g_dbus_proxy_new(
-        g_dbus_proxy_get_connection(self->priv->improxy),
-        G_DBUS_PROXY_FLAGS_NONE, _fcitx_g_client_get_clientic_info(),
-        g_dbus_proxy_get_name(self->priv->improxy), self->priv->icname,
-        "org.fcitx.Fcitx.InputContext1", self->priv->cancellable,
-        _fcitx_g_client_create_ic_phase2_finished, self);
+    g_dbus_proxy_new(connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+                     _fcitx_g_client_get_clientic_info(), unique_name, path,
+                     "org.fcitx.Fcitx.InputContext1", self->priv->cancellable,
+                     _fcitx_g_client_create_ic_phase2_finished, self);
 }
 
 static void
@@ -901,10 +995,25 @@
     g_return_if_fail(user_data != NULL);
     g_return_if_fail(FCITX_G_IS_CLIENT(user_data));
     FcitxGClient *self = (FcitxGClient *)user_data;
+    g_autoptr(GError) error = NULL;
+    GDBusProxy *icproxy = g_dbus_proxy_new_finish(res, &error);
+    if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+        self->priv->current_service == FCITX_SERVICE_NONE) {
+        g_clear_object(&icproxy);
+        g_object_unref(self);
+        return;
+    }
+    if (!icproxy) {
+        _fcitx_g_client_handle_create_ic_error(self);
+        g_object_unref(self);
+        return;
+    }
+
     g_clear_object(&self->priv->cancellable);
+    self->priv->current_service = FCITX_SERVICE_NONE;
     g_clear_object(&self->priv->icproxy);
-    self->priv->icproxy = g_dbus_proxy_new_finish(res, NULL);
-    if (!self->priv->icproxy) {
+    self->priv->icproxy = icproxy;
+    if (!_fcitx_g_client_is_icproxy_available(self)) {
         _fcitx_g_client_clean_up(self);
         g_object_unref(self);
         return;
@@ -914,7 +1023,7 @@
                      G_CALLBACK(_fcitx_g_client_g_signal), self);
     g_signal_emit(self, signals[CONNECTED_SIGNAL], 0);
 
-    /* unref for _fcitx_g_client_create_ic_cb */
+    /* unref for _fcitx_g_client_create_ic */
     g_object_unref(self);
 }
 
@@ -1173,8 +1282,7 @@
     case PROP_WATCHER:
         watcher = g_value_get_object(value);
         if (watcher) {
-            self->priv->watcher = watcher;
-            g_object_ref_sink(self->priv->watcher);
+            self->priv->watcher = g_object_ref(watcher);
         }
         break;
     default:
@@ -1189,18 +1297,13 @@
     }
 
     g_clear_object(&self->priv->cancellable);
-    g_clear_object(&self->priv->improxy);
-    g_clear_pointer(&self->priv->icname, g_free);
+    self->priv->current_service = FCITX_SERVICE_NONE;
 
     if (self->priv->icproxy) {
         g_signal_handlers_disconnect_by_func(
             self->priv->icproxy, G_CALLBACK(_fcitx_g_client_g_signal), self);
     }
     g_clear_object(&self->priv->icproxy);
-    if (self->priv->watch_id) {
-        g_bus_unwatch_name(self->priv->watch_id);
-        self->priv->watch_id = 0;
-    }
     self->priv->version = 0;
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/fcitx5-gtk-5.1.7/fcitx-gclient/fcitxgwatcher.c 
new/fcitx5-gtk-5.1.8/fcitx-gclient/fcitxgwatcher.c
--- old/fcitx5-gtk-5.1.7/fcitx-gclient/fcitxgwatcher.c  2026-06-20 
06:19:08.000000000 +0200
+++ new/fcitx5-gtk-5.1.8/fcitx-gclient/fcitxgwatcher.c  2026-11-27 
20:21:47.000000000 +0100
@@ -36,7 +36,12 @@
 
 G_DEFINE_TYPE_WITH_PRIVATE(FcitxGWatcher, fcitx_g_watcher, G_TYPE_OBJECT);
 
-enum { AVAILABLITY_CHANGED_SIGNAL, LAST_SIGNAL };
+enum {
+    AVAILABLITY_CHANGED_SIGNAL,
+    MAIN_SERVICE_AVAILABILITY_CHANGED_SIGNAL,
+    PORTAL_SERVICE_AVAILABILITY_CHANGED_SIGNAL,
+    LAST_SIGNAL
+};
 
 static guint signals[LAST_SIGNAL] = {0};
 
@@ -44,7 +49,9 @@
 static void _fcitx_g_watcher_get_bus_finished(GObject *source_object,
                                               GAsyncResult *res,
                                               gpointer user_data);
-static void _fcitx_g_watcher_update_availability(FcitxGWatcher *self);
+static void _fcitx_g_watcher_set_service_owner(FcitxGWatcher *self,
+                                               const gchar *name,
+                                               const gchar *name_owner);
 
 static void fcitx_g_watcher_finalize(GObject *object);
 static void fcitx_g_watcher_dispose(GObject *object);
@@ -68,6 +75,30 @@
         "availability-changed", FCITX_G_TYPE_WATCHER, G_SIGNAL_RUN_LAST, 0,
         NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1,
         G_TYPE_BOOLEAN);
+
+    /**
+     * FcitxGWatcher::main-service-availability-changed:
+     * @watcher: A #FcitxGWatcher
+     * @available: whether main fcitx service is available.
+     *
+     * Emit when main fcitx service availability changed.
+     */
+    signals[MAIN_SERVICE_AVAILABILITY_CHANGED_SIGNAL] = g_signal_new(
+        "main-service-availability-changed", FCITX_G_TYPE_WATCHER,
+        G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
+        G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+    /**
+     * FcitxGWatcher::portal-service-availability-changed:
+     * @watcher: A #FcitxGWatcher
+     * @available: whether portal fcitx service is available.
+     *
+     * Emit when portal fcitx service availability changed.
+     */
+    signals[PORTAL_SERVICE_AVAILABILITY_CHANGED_SIGNAL] = g_signal_new(
+        "portal-service-availability-changed", FCITX_G_TYPE_WATCHER,
+        G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
+        G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 }
 
 static void fcitx_g_watcher_init(FcitxGWatcher *self) {
@@ -79,6 +110,7 @@
     self->priv->portal_watch_id = 0;
     self->priv->main_owner = NULL;
     self->priv->portal_owner = NULL;
+    self->priv->available = FALSE;
     self->priv->watched = FALSE;
 }
 
@@ -104,14 +136,7 @@
     g_return_if_fail(FCITX_G_IS_WATCHER(user_data));
 
     FcitxGWatcher *self = FCITX_G_WATCHER(user_data);
-    if (g_strcmp0(name, FCITX_MAIN_SERVICE_NAME) == 0) {
-        g_free(self->priv->main_owner);
-        self->priv->main_owner = g_strdup(name_owner);
-    } else if (g_strcmp0(name, FCITX_PORTAL_SERVICE_NAME) == 0) {
-        g_free(self->priv->portal_owner);
-        self->priv->portal_owner = g_strdup(name_owner);
-    }
-    _fcitx_g_watcher_update_availability(self);
+    _fcitx_g_watcher_set_service_owner(self, name, name_owner);
 }
 
 static void _fcitx_g_watcher_vanish(G_GNUC_UNUSED GDBusConnection *conn,
@@ -119,14 +144,7 @@
     g_return_if_fail(FCITX_G_IS_WATCHER(user_data));
 
     FcitxGWatcher *self = FCITX_G_WATCHER(user_data);
-    if (g_strcmp0(name, FCITX_MAIN_SERVICE_NAME) == 0) {
-        g_free(self->priv->main_owner);
-        self->priv->main_owner = NULL;
-    } else if (g_strcmp0(name, FCITX_PORTAL_SERVICE_NAME) == 0) {
-        g_free(self->priv->portal_owner);
-        self->priv->portal_owner = NULL;
-    }
-    _fcitx_g_watcher_update_availability(self);
+    _fcitx_g_watcher_set_service_owner(self, name, NULL);
 }
 
 static void _fcitx_g_watcher_start_watch(FcitxGWatcher *self) {
@@ -180,13 +198,34 @@
     g_return_if_fail(FCITX_G_IS_WATCHER(user_data));
 
     FcitxGWatcher *self = FCITX_G_WATCHER(user_data);
+    g_object_ref(self);
+    gboolean had_main = self->priv->main_owner != NULL;
+    gboolean had_portal = self->priv->portal_owner != NULL;
     _fcitx_g_watcher_clean_up(self);
     if (self->priv->watched) {
-        _fcitx_g_watcher_update_availability(self);
-
-        g_timeout_add_full(G_PRIORITY_DEFAULT, 100, _fcitx_g_watcher_recheck,
-                           g_object_ref(self), g_object_unref);
+        gboolean avail_changed = self->priv->available;
+        self->priv->available = FALSE;
+        if (had_main) {
+            g_signal_emit(self,
+                          signals[MAIN_SERVICE_AVAILABILITY_CHANGED_SIGNAL], 0,
+                          FALSE);
+        }
+        if (had_portal) {
+            g_signal_emit(self,
+                          signals[PORTAL_SERVICE_AVAILABILITY_CHANGED_SIGNAL],
+                          0, FALSE);
+        }
+        if (avail_changed) {
+            g_signal_emit(self, signals[AVAILABLITY_CHANGED_SIGNAL], 0, FALSE);
+        }
+
+        if (self->priv->watched) {
+            g_timeout_add_full(G_PRIORITY_DEFAULT, 100,
+                               _fcitx_g_watcher_recheck, g_object_ref(self),
+                               g_object_unref);
+        }
     }
+    g_object_unref(self);
 }
 
 static void
@@ -210,20 +249,18 @@
     g_signal_connect(self->priv->connection, "closed",
                      (GCallback)_fcitx_g_watcher_connection_closed, self);
 
-    self->priv->watch_id =
-        g_bus_watch_name(G_BUS_TYPE_SESSION, FCITX_MAIN_SERVICE_NAME,
-                         G_BUS_NAME_WATCHER_FLAGS_NONE, 
_fcitx_g_watcher_appear,
-                         _fcitx_g_watcher_vanish, self, NULL);
+    self->priv->watch_id = g_bus_watch_name_on_connection(
+        self->priv->connection, FCITX_MAIN_SERVICE_NAME,
+        G_BUS_NAME_WATCHER_FLAGS_NONE, _fcitx_g_watcher_appear,
+        _fcitx_g_watcher_vanish, self, NULL);
 
     if (self->priv->watch_portal) {
-        self->priv->portal_watch_id = g_bus_watch_name(
-            G_BUS_TYPE_SESSION, FCITX_PORTAL_SERVICE_NAME,
+        self->priv->portal_watch_id = g_bus_watch_name_on_connection(
+            self->priv->connection, FCITX_PORTAL_SERVICE_NAME,
             G_BUS_NAME_WATCHER_FLAGS_NONE, _fcitx_g_watcher_appear,
             _fcitx_g_watcher_vanish, self, NULL);
     }
 
-    _fcitx_g_watcher_update_availability(self);
-
     /* unref for _fcitx_g_watcher_start_watch */
     g_object_unref(self);
 }
@@ -239,6 +276,7 @@
     g_return_if_fail(self->priv->watched);
     self->priv->watched = FALSE;
     _fcitx_g_watcher_clean_up(self);
+    self->priv->available = FALSE;
 }
 
 /**
@@ -254,8 +292,8 @@
 }
 
 /**
- * fcitx_g_watcher_is_valid:
- * @connection: A #FcitxGWatcher
+ * fcitx_g_watcher_is_service_available:
+ * @self: A #FcitxGWatcher
  *
  * Check #FcitxGWatcher is valid to communicate with Fcitx
  *
@@ -310,13 +348,44 @@
     self->priv->watch_portal = watch;
 }
 
-void _fcitx_g_watcher_update_availability(FcitxGWatcher *self) {
-    gboolean available = self->priv->connection &&
-                         (self->priv->main_owner || self->priv->portal_owner);
-    if (available != self->priv->available) {
-        self->priv->available = available;
-        g_signal_emit(self, signals[AVAILABLITY_CHANGED_SIGNAL], 0);
+static void _fcitx_g_watcher_set_service_owner(FcitxGWatcher *self,
+                                               const gchar *name,
+                                               const gchar *name_owner) {
+    gboolean main_changed = FALSE;
+    gboolean portal_changed = FALSE;
+    if (g_strcmp0(name, FCITX_MAIN_SERVICE_NAME) == 0) {
+        if (g_strcmp0(self->priv->main_owner, name_owner) != 0) {
+            g_free(self->priv->main_owner);
+            self->priv->main_owner = g_strdup(name_owner);
+            main_changed = TRUE;
+        }
+    } else if (g_strcmp0(name, FCITX_PORTAL_SERVICE_NAME) == 0) {
+        if (g_strcmp0(self->priv->portal_owner, name_owner) != 0) {
+            g_free(self->priv->portal_owner);
+            self->priv->portal_owner = g_strdup(name_owner);
+            portal_changed = TRUE;
+        }
+    }
+
+    gboolean main_avail = self->priv->main_owner != NULL;
+    gboolean portal_avail = self->priv->portal_owner != NULL;
+    gboolean available = self->priv->connection && (main_avail || 
portal_avail);
+    gboolean avail_changed = (available != self->priv->available);
+    self->priv->available = available;
+
+    g_object_ref(self);
+    if (main_changed) {
+        g_signal_emit(self, signals[MAIN_SERVICE_AVAILABILITY_CHANGED_SIGNAL],
+                      0, main_avail);
+    }
+    if (portal_changed) {
+        g_signal_emit(self, 
signals[PORTAL_SERVICE_AVAILABILITY_CHANGED_SIGNAL],
+                      0, portal_avail);
+    }
+    if (avail_changed) {
+        g_signal_emit(self, signals[AVAILABLITY_CHANGED_SIGNAL], 0, available);
     }
+    g_object_unref(self);
 }
 
 /**
@@ -335,3 +404,25 @@
     }
     return NULL;
 }
+
+/**
+ * fcitx_g_watcher_get_main_service_name:
+ * @self: A #FcitxGWatcher
+ *
+ * Returns: (transfer none) (nullable): unique D-Bus name of the main service
+ * owner, or %NULL if unavailable.
+ **/
+const gchar *fcitx_g_watcher_get_main_service_name(FcitxGWatcher *self) {
+    return self->priv->connection ? self->priv->main_owner : NULL;
+}
+
+/**
+ * fcitx_g_watcher_get_portal_service_name:
+ * @self: A #FcitxGWatcher
+ *
+ * Returns: (transfer none) (nullable): unique D-Bus name of the portal service
+ * owner, or %NULL if unavailable.
+ **/
+const gchar *fcitx_g_watcher_get_portal_service_name(FcitxGWatcher *self) {
+    return self->priv->connection ? self->priv->portal_owner : NULL;
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/fcitx5-gtk-5.1.7/fcitx-gclient/fcitxgwatcher.h 
new/fcitx5-gtk-5.1.8/fcitx-gclient/fcitxgwatcher.h
--- old/fcitx5-gtk-5.1.7/fcitx-gclient/fcitxgwatcher.h  2026-06-20 
06:19:08.000000000 +0200
+++ new/fcitx5-gtk-5.1.8/fcitx-gclient/fcitxgwatcher.h  2026-11-27 
20:21:47.000000000 +0100
@@ -27,6 +27,8 @@
 void fcitx_g_watcher_set_watch_portal(FcitxGWatcher *self, gboolean watch);
 gboolean fcitx_g_watcher_is_service_available(FcitxGWatcher *self);
 const gchar *fcitx_g_watcher_get_service_name(FcitxGWatcher *self);
+const gchar *fcitx_g_watcher_get_main_service_name(FcitxGWatcher *self);
+const gchar *fcitx_g_watcher_get_portal_service_name(FcitxGWatcher *self);
 GDBusConnection *fcitx_g_watcher_get_connection(FcitxGWatcher *self);
 
 G_END_DECLS

Reply via email to