inspector: add im-module
authorChristian Hergert <chergert@redhat.com>
Fri, 3 Dec 2021 20:11:25 +0000 (12:11 -0800)
committerJan Tojnar <jtojnar@gmail.com>
Thu, 23 Mar 2023 20:26:33 +0000 (21:26 +0100)
This adds a new row to the Global/Information section which displays the
GTK im-module that is likely to be in use unless changed by an application.
It responds to updates of GtkSettings:gtk-im-module unless the
GTK_IM_MODULE environment variable is set.

Fixes #4512

(cherry picked from commit 6be352f4468b4dbbb1d71f427948dda154b9a658)

gtk/inspector/general.c
gtk/inspector/general.ui

index 3c2c7056ee6f083a27530c16027b419f384ac6f8..a3a341956bc5be4e1d938a7856e7ca426a4bad5d 100644 (file)
 #include "gtkswitch.h"
 #include "gtklistbox.h"
 #include "gtkprivate.h"
+#include "gtksettings.h"
 #include "gtksizegroup.h"
 #include "gtkimage.h"
 #include "gtkadjustment.h"
 #include "gtkbox.h"
+#include "gtkimmoduleprivate.h"
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"
@@ -66,6 +68,7 @@ struct _GtkInspectorGeneralPrivate
   GtkWidget *app_id_frame;
   GtkWidget *app_id;
   GtkWidget *resource_path;
+  GtkWidget *im_module;
   GtkWidget *gl_version;
   GtkWidget *gl_vendor;
   GtkWidget *prefix;
@@ -522,6 +525,39 @@ init_pango (GtkInspectorGeneral *gen)
   gtk_label_set_label (GTK_LABEL (gen->priv->pango_fontmap), name);
 }
 
+static void
+im_module_changed (GtkSettings         *settings,
+                   GParamSpec          *pspec,
+                   GtkInspectorGeneral *gen)
+{
+  gtk_label_set_label (GTK_LABEL (gen->priv->im_module),
+                       _gtk_im_module_get_default_context_id ());
+}
+
+static void
+init_im_module (GtkInspectorGeneral *gen)
+{
+  GdkScreen *screen = gdk_screen_get_default ();
+  GtkSettings *settings = gtk_settings_get_for_screen (screen);
+  const char *default_context_id = _gtk_im_module_get_default_context_id ();
+
+  gtk_label_set_label (GTK_LABEL (gen->priv->im_module), default_context_id);
+
+  if (g_getenv ("GTK_IM_MODULE") != NULL)
+    {
+      /* This can't update if GTK_IM_MODULE envvar is set */
+      gtk_widget_set_tooltip_text (gen->priv->im_module,
+                                   _("IM Context is hardcoded by GTK_IM_MODULE"));
+      gtk_widget_set_sensitive (gen->priv->im_module, FALSE);
+      return;
+    }
+
+  g_signal_connect_object (settings,
+                           "notify::gtk-im-module",
+                           G_CALLBACK (im_module_changed),
+                           gen, 0);
+}
+
 static void populate_seats (GtkInspectorGeneral *gen);
 
 static void
@@ -693,6 +729,7 @@ gtk_inspector_general_init (GtkInspectorGeneral *gen)
   init_env (gen);
   init_display (gen);
   init_pango (gen);
+  init_im_module (gen);
   init_gl (gen);
   init_device (gen);
 }
@@ -781,6 +818,7 @@ gtk_inspector_general_class_init (GtkInspectorGeneralClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gtk_version);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, gdk_backend);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, pango_fontmap);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, im_module);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, app_id_frame);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, app_id);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, resource_path);
index bd5e9c09d397b2f573bd578e5e859c8cd02fe90e..649d60ae03973123fbaf940009c2e08869924c43 100644 (file)
                     </child>
                   </object>
                 </child>
+                <child>
+                  <object class="GtkListBoxRow">
+                    <property name="visible">True</property>
+                    <property name="activatable">False</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">True</property>
+                        <property name="orientation">horizontal</property>
+                        <property name="margin">10</property>
+                        <property name="spacing">40</property>
+                        <child>
+                          <object class="GtkLabel" id="input_method_label">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Input Method</property>
+                            <property name="halign">start</property>
+                            <property name="valign">baseline</property>
+                            <property name="xalign">0.0</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="im_module">
+                            <property name="visible">True</property>
+                            <property name="selectable">True</property>
+                            <property name="halign">end</property>
+                            <property name="valign">baseline</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
       <widget name="gtk_version_label"/>
       <widget name="gdk_backend_label"/>
       <widget name="pango_fontmap_label"/>
+      <widget name="input_method_label"/>
       <widget name="app_id_label"/>
       <widget name="resource_path_label"/>
       <widget name="gl_version_label"/>