[gtk/wip/chergert/inspector-im-module] inspector: add im-module




commit 6be352f4468b4dbbb1d71f427948dda154b9a658
Author: Christian Hergert <chergert redhat com>
Date:   Fri Dec 3 12:11:25 2021 -0800

    inspector: add im-module
    
    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

 gtk/inspector/general.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 gtk/inspector/general.ui | 26 ++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
---
diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c
index 4c486c60dc..2eee163a1e 100644
--- a/gtk/inspector/general.c
+++ b/gtk/inspector/general.c
@@ -33,6 +33,7 @@
 #include "gtkbox.h"
 #include "gtkbinlayout.h"
 #include "gtkmediafileprivate.h"
+#include "gtkimmoduleprivate.h"
 
 #include "gdk/gdkdebug.h"
 
@@ -87,6 +88,7 @@ struct _GtkInspectorGeneral
   GtkWidget *gsk_renderer;
   GtkWidget *pango_fontmap;
   GtkWidget *media_backend;
+  GtkWidget *im_module;
   GtkWidget *gl_version;
   GtkWidget *gl_error;
   GtkWidget *gl_error_row;
@@ -742,6 +744,42 @@ init_media (GtkInspectorGeneral *gen)
   gtk_label_set_label (GTK_LABEL (gen->media_backend), name);
 }
 
+static void
+im_module_changed (GtkSettings         *settings,
+                   GParamSpec          *pspec,
+                   GtkInspectorGeneral *gen)
+{
+  if (!gen->display)
+    return;
+
+  gtk_label_set_label (GTK_LABEL (gen->im_module),
+                       _gtk_im_module_get_default_context_id (gen->display));
+}
+
+static void
+init_im_module (GtkInspectorGeneral *gen)
+{
+  GtkSettings *settings = gtk_settings_get_for_display (gen->display);
+  const char *default_context_id = _gtk_im_module_get_default_context_id (gen->display);
+
+  gtk_label_set_label (GTK_LABEL (gen->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->im_module,
+                                   _("IM Context is hardcoded by GTK_IM_MODULE"));
+      gtk_widget_set_sensitive (gen->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
@@ -1065,6 +1103,7 @@ gtk_inspector_general_class_init (GtkInspectorGeneralClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorGeneral, gsk_renderer);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorGeneral, pango_fontmap);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorGeneral, media_backend);
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorGeneral, im_module);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorGeneral, gl_version);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorGeneral, gl_error);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorGeneral, gl_error_row);
@@ -1103,6 +1142,7 @@ gtk_inspector_general_set_display (GtkInspectorGeneral *gen,
   init_gl (gen);
   init_vulkan (gen);
   init_device (gen);
+  init_im_module (gen);
 }
 
 // vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/general.ui b/gtk/inspector/general.ui
index e9aeb49a69..9a7369e362 100644
--- a/gtk/inspector/general.ui
+++ b/gtk/inspector/general.ui
@@ -151,6 +151,32 @@
                         </child>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkListBoxRow">
+                        <property name="activatable">0</property>
+                        <child>
+                          <object class="GtkBox">
+                            <property name="spacing">40</property>
+                            <child>
+                              <object class="GtkLabel" id="input_method_label">
+                                <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="selectable">1</property>
+                                <property name="halign">end</property>
+                                <property name="valign">baseline</property>
+                                <property name="hexpand">1</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]