From c3f3d37bc80f16180a68765f4ba64188b227f19e Mon Sep 17 00:00:00 2001
From: c4pp4
Date: Wed, 24 Apr 2024 22:30:48 +0200
Subject: [PATCH 1/1] Prevent multiple ibus_init call

Signed-off-by: c4pp4
---
 panels/region/gnome-region-panel-input.c | 35 ++++--------------------
 shell/gnome-control-center.c             |  9 ++++++
 2 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/panels/region/gnome-region-panel-input.c b/panels/region/gnome-region-panel-input.c
index 4547167..c5e0910 100644
--- a/panels/region/gnome-region-panel-input.c
+++ b/panels/region/gnome-region-panel-input.c
@@ -76,7 +76,7 @@
 #define IBUS_CUSTOM_FONT_KEY     "custom-font"
 
 #define LEGACY_IBUS_XML_DIR   "/usr/share/ibus/component"
-#define LEGACY_IBUS_SETUP_DIR "/usr/lib/ibus"
+#define LEGACY_IBUS_SETUP_DIR "/usr/libexec"
 #define LEGACY_IBUS_SETUP_FMT "ibus-setup-%s"
 
 #define LANGSELECTOR_PANEL  "langselector"
@@ -207,7 +207,7 @@ setup_app_info_for_id (const gchar *id)
   gchar **strv;
 
   strv = g_strsplit (id, ":", 2);
-  desktop_file_name = g_strdup_printf ("ibus-setup-%s.desktop", strv[0]);
+  desktop_file_name = g_strdup_printf ("org.freedesktop.IBus.Setup-%s.desktop", strv[0]);
   g_strfreev (strv);
 
   app_info = g_desktop_app_info_new (desktop_file_name);
@@ -553,21 +553,6 @@ fetch_ibus_engines (GtkBuilder *builder)
                                builder);
 }
 
-static void
-maybe_start_ibus (void)
-{
-  /* IBus doesn't export API in the session bus. The only thing
-   * we have there is a well known name which we can use as a
-   * sure-fire way to activate it. */
-  g_bus_unwatch_name (g_bus_watch_name (G_BUS_TYPE_SESSION,
-                                        IBUS_SERVICE_IBUS,
-                                        G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
-                                        NULL,
-                                        NULL,
-                                        NULL,
-                                        NULL));
-}
-
 static void
 update_source_radios (GtkBuilder *builder)
 {
@@ -1838,20 +1823,10 @@ setup_input_tabs (GtkBuilder    *builder_,
   module = g_getenv (ENV_GTK_IM_MODULE);
 
 #ifdef HAVE_IBUS
-  is_ibus_active = g_strcmp0 (module, GTK_IM_MODULE_IBUS) == 0;
-
-  if (is_ibus_active)
+  if (g_strcmp0 (module, GTK_IM_MODULE_IBUS) == 0 && !ibus)
     {
-      ibus_init ();
-      if (!ibus)
-        {
-          ibus = ibus_bus_new_async ();
-          if (ibus_bus_is_connected (ibus))
-            ibus_connected (ibus, builder);
-          else
-            g_signal_connect (ibus, "connected", G_CALLBACK (ibus_connected), builder);
-        }
-      maybe_start_ibus ();
+      ibus = ibus_bus_new_async ();
+      g_signal_connect (ibus, "connected", G_CALLBACK (ibus_connected), builder);
     }
 #endif
 
diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c
index a4c8ab6..4ca81f7 100644
--- a/shell/gnome-control-center.c
+++ b/shell/gnome-control-center.c
@@ -34,6 +34,10 @@
 #define GMENU_I_KNOW_THIS_IS_UNSTABLE
 #include <gmenu-tree.h>
 
+#ifdef HAVE_IBUS
+#include <ibus.h>
+#endif
+
 #include "cc-panel.h"
 #include "cc-shell.h"
 #include "cc-shell-category-view.h"
@@ -1574,6 +1578,11 @@ gnome_control_center_init (GnomeControlCenter *self)
       return;
     }
 
+#ifdef HAVE_IBUS
+  if (g_strcmp0 (module, GTK_IM_MODULE_IBUS) == 0)
+    ibus_init ();
+#endif
+
   /* connect various signals */
   priv->window = W (priv->builder, "main-window");
   gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (priv->window), TRUE);
-- 
2.43.2

