Add ibus im-module command
This commit is contained in:
parent
81284633cc
commit
f85987315d
377
ibus-HEAD.patch
377
ibus-HEAD.patch
@ -2335,3 +2335,380 @@ index f8dced6b..92464234 100755
|
||||
--
|
||||
2.35.3
|
||||
|
||||
From 65a70a49416a5a2f0fe75815cafce68ca39ee1f1 Mon Sep 17 00:00:00 2001
|
||||
From: fujiwarat <takao.fujiwara1@gmail.com>
|
||||
Date: Wed, 29 Jun 2022 15:36:12 +0900
|
||||
Subject: [PATCH] tools: Add ibus im-module command
|
||||
|
||||
ibus im-module command can retrive gtk-im-module value from an
|
||||
instance of GtkIMMultiContext.
|
||||
The GTK version can be specified by --type option and the default
|
||||
is --type=gtk3 and GTK3 im-ibus.so is dlopened.
|
||||
---
|
||||
client/gtk2/ibusim.c | 20 +++++++
|
||||
client/gtk4/ibusim.c | 20 +++++++
|
||||
tools/IBusIMModule-1.0.metadata | 1 +
|
||||
tools/Makefile.am | 92 ++++++++++++++++++++++++++++++---
|
||||
tools/ibusimmodule.c | 84 ++++++++++++++++++++++++++++++
|
||||
tools/ibusimmodule.h | 36 +++++++++++++
|
||||
tools/main.vala | 15 ++++++
|
||||
7 files changed, 262 insertions(+), 6 deletions(-)
|
||||
create mode 100644 tools/IBusIMModule-1.0.metadata
|
||||
create mode 100644 tools/ibusimmodule.c
|
||||
create mode 100644 tools/ibusimmodule.h
|
||||
|
||||
diff --git a/client/gtk2/ibusim.c b/client/gtk2/ibusim.c
|
||||
index 55609ce7..e196d536 100644
|
||||
--- a/client/gtk2/ibusim.c
|
||||
+++ b/client/gtk2/ibusim.c
|
||||
@@ -77,3 +77,23 @@ im_module_list (const GtkIMContextInfo ***contexts,
|
||||
*n_contexts = G_N_ELEMENTS (info_list);
|
||||
}
|
||||
|
||||
+G_MODULE_EXPORT const char *
|
||||
+im_get_context_id (int *argc,
|
||||
+ char ***argv)
|
||||
+{
|
||||
+ GtkIMContext *context;
|
||||
+ char *preedit_string = NULL;
|
||||
+ PangoAttrList *preedit_attrs = NULL;
|
||||
+ const char *context_id;
|
||||
+
|
||||
+ gtk_init (argc, argv);
|
||||
+ context = gtk_im_multicontext_new ();
|
||||
+ gtk_im_context_get_preedit_string (context,
|
||||
+ &preedit_string,
|
||||
+ &preedit_attrs,
|
||||
+ 0);
|
||||
+ context_id = gtk_im_multicontext_get_context_id (
|
||||
+ GTK_IM_MULTICONTEXT (context));
|
||||
+ return context_id;
|
||||
+}
|
||||
+
|
||||
diff --git a/client/gtk4/ibusim.c b/client/gtk4/ibusim.c
|
||||
index 5ecf9778..562bdf2d 100644
|
||||
--- a/client/gtk4/ibusim.c
|
||||
+++ b/client/gtk4/ibusim.c
|
||||
@@ -50,3 +50,23 @@ g_io_im_ibus_unload (GTypeModule *type_module)
|
||||
g_type_module_unuse (type_module);
|
||||
}
|
||||
|
||||
+G_MODULE_EXPORT const char *
|
||||
+im_get_context_id (int *argc,
|
||||
+ char ***argv)
|
||||
+{
|
||||
+ GtkIMContext *context;
|
||||
+ char *preedit_string = NULL;
|
||||
+ PangoAttrList *preedit_attrs = NULL;
|
||||
+ const char *context_id;
|
||||
+
|
||||
+ gtk_init ();
|
||||
+ context = gtk_im_multicontext_new ();
|
||||
+ gtk_im_context_get_preedit_string (context,
|
||||
+ &preedit_string,
|
||||
+ &preedit_attrs,
|
||||
+ 0);
|
||||
+ context_id = gtk_im_multicontext_get_context_id (
|
||||
+ GTK_IM_MULTICONTEXT (context));
|
||||
+ return context_id;
|
||||
+}
|
||||
+
|
||||
diff --git a/tools/IBusIMModule-1.0.metadata b/tools/IBusIMModule-1.0.metadata
|
||||
new file mode 100644
|
||||
index 00000000..14adc9ee
|
||||
--- /dev/null
|
||||
+++ b/tools/IBusIMModule-1.0.metadata
|
||||
@@ -0,0 +1 @@
|
||||
+IBusIMModule cheader_filename="ibusimmodule.h" name="IBusIMModule"
|
||||
diff --git a/tools/Makefile.am b/tools/Makefile.am
|
||||
index e380a9aa..f96f2ba2 100644
|
||||
--- a/tools/Makefile.am
|
||||
+++ b/tools/Makefile.am
|
||||
@@ -22,6 +22,12 @@
|
||||
# USA
|
||||
|
||||
NULL =
|
||||
+noinst_LTLIBRARIES =
|
||||
+noinst_DATA =
|
||||
+INTROSPECTION_GIRS =
|
||||
+MAINTAINERCLEANFILES =
|
||||
+DISTCLEANFILES =
|
||||
+VAPIGEN_VAPIS =
|
||||
|
||||
libibus = $(top_builddir)/src/libibus-@IBUS_API_VERSION@.la
|
||||
libibus_emoji_dialog = \
|
||||
@@ -57,6 +63,8 @@ AM_LDADD = \
|
||||
AM_VALAFLAGS = \
|
||||
--vapidir=$(top_builddir)/bindings/vala \
|
||||
--vapidir=$(top_srcdir)/bindings/vala \
|
||||
+ --vapidir=$(builddir) \
|
||||
+ --vapidir=$(srcdir) \
|
||||
--pkg=gio-2.0 \
|
||||
--pkg=ibus-1.0 \
|
||||
--pkg=posix \
|
||||
@@ -91,14 +99,17 @@ man_onedir = $(mandir)/man1
|
||||
$(AM_V_GEN) gzip -c $< > $@.tmp && mv $@.tmp $@
|
||||
|
||||
EXTRA_DIST = \
|
||||
- $(man_one_in_files) \
|
||||
- ibus.bash \
|
||||
- $(NULL)
|
||||
+ $(man_one_in_files) \
|
||||
+ ibus.bash \
|
||||
+ ibusimmodule.c \
|
||||
+ ibusimmodule.h \
|
||||
+ IBusIMModule-1.0.metadata \
|
||||
+ $(NULL)
|
||||
|
||||
CLEANFILES = \
|
||||
- $(man_one_DATA) \
|
||||
- $(man_one_files) \
|
||||
- $(NULL)
|
||||
+ $(man_one_DATA) \
|
||||
+ $(man_one_files) \
|
||||
+ $(NULL)
|
||||
|
||||
if ENABLE_EMOJI_DICT
|
||||
if ENABLE_UI
|
||||
@@ -108,4 +119,73 @@ AM_VALAFLAGS += \
|
||||
endif
|
||||
endif
|
||||
|
||||
+if HAVE_INTROSPECTION
|
||||
+BUILT_SOURCES = $(INTROSPECTION_GIRS) $(VAPIGEN_VAPIS)
|
||||
+libibusimmodule = libibusimmodule.la
|
||||
+noinst_LTLIBRARIES += $(libibusimmodule)
|
||||
+
|
||||
+AM_LDADD += $(libibusimmodule)
|
||||
+AM_VALAFLAGS += \
|
||||
+ --define=LIB_IBUS_MODULE \
|
||||
+ --pkg=ibus-immodule-1.0 \
|
||||
+ $(NULL)
|
||||
+
|
||||
+libibusimmodule_la_SOURCES = \
|
||||
+ ibusimmodule.c \
|
||||
+ ibusimmodule.h \
|
||||
+ $(NULL)
|
||||
+libibusimmodule_la_CFLAGS = \
|
||||
+ @GLIB2_CFLAGS@ \
|
||||
+ -DGTK2_IM_MODULEDIR=\"$(GTK2_IM_MODULEDIR)\" \
|
||||
+ -DGTK3_IM_MODULEDIR=\"$(GTK3_IM_MODULEDIR)\" \
|
||||
+ -DGTK4_IM_MODULEDIR=\"$(GTK4_IM_MODULEDIR)\" \
|
||||
+ $(NULL)
|
||||
+libibusimmodule_la_LIBADD = \
|
||||
+ @GLIB2_LIBS@ \
|
||||
+ $(NULL)
|
||||
+libibusimmodule_la_LDFLAGS = \
|
||||
+ -no-undefined \
|
||||
+ -export-symbols-regex "ibus_.*" \
|
||||
+ $(NULL)
|
||||
+
|
||||
+-include $(INTROSPECTION_MAKEFILE)
|
||||
+INTROSPECTION_SCANNER_ARGS =
|
||||
+INTROSPECTION_COMPILER_ARGS = \
|
||||
+ --includedir=$(srcdir) \
|
||||
+ --includedir=. \
|
||||
+ $(NULL)
|
||||
+
|
||||
+IBusIMModule-1.0.gir: $(libibusimmodule) Makefile
|
||||
+IBusIMModule_1_0_gir_SCANNERFLAGS = \
|
||||
+ --pkg=glib-2.0 \
|
||||
+ $(IBUS_GIR_SCANNERFLAGS) \
|
||||
+ $(NULL)
|
||||
+IBusIMModule_1_0_gir_INCLUDES = GLib-2.0
|
||||
+IBusIMModule_1_0_gir_LIBS = $(libibusimmodule)
|
||||
+IBusIMModule_1_0_gir_FILES = ibusimmodule.h
|
||||
+IBusIMModule_1_0_gir_CFLAGS = \
|
||||
+ -I$(srcdir) \
|
||||
+ -I$(builddir) \
|
||||
+ $(NULL)
|
||||
+
|
||||
+ibusimmodule_gir = IBusIMModule-1.0.gir
|
||||
+INTROSPECTION_GIRS += $(ibusimmodule_gir)
|
||||
+noinst_DATA += $(ibusimmodule_gir)
|
||||
+EXTRA_DIST += $(ibusimmodule_gir)
|
||||
+MAINTAINERCLEANFILES += $(ibusimmodule_gir)
|
||||
+DISTCLEANFILES += $(ibusimmodule_gir)
|
||||
+
|
||||
+-include $(VAPIGEN_MAKEFILE)
|
||||
+ibus-immodule-1.0.vapi: $(ibusimmodule_gir) IBusIMModule-1.0.metadata
|
||||
+ibus_immodule_vapi = ibus-immodule-1.0.vapi
|
||||
+ibus_immodule_1_0_vapi_DEPS = glib-2.0
|
||||
+ibus_immodule_1_0_vapi_METADATADIRS = $(srcdir)
|
||||
+ibus_immodule_1_0_vapi_FILES = IBusIMModule-1.0.gir
|
||||
+VAPIGEN_VAPIS += $(ibus_immodule_vapi)
|
||||
+noinst_DATA += $(ibus_immodule_vapi)
|
||||
+EXTRA_DIST += $(ibus_immodule_vapi)
|
||||
+MAINTAINERCLEANFILES += $(ibus_immodule_vapi)
|
||||
+DISTCLEANFILES += $(ibus_immodule_vapi)
|
||||
+
|
||||
+endif
|
||||
-include $(top_srcdir)/git.mk
|
||||
diff --git a/tools/ibusimmodule.c b/tools/ibusimmodule.c
|
||||
new file mode 100644
|
||||
index 00000000..1587af3d
|
||||
--- /dev/null
|
||||
+++ b/tools/ibusimmodule.c
|
||||
@@ -0,0 +1,84 @@
|
||||
+#include <glib.h>
|
||||
+#include <glib/gi18n-lib.h>
|
||||
+#include <dlfcn.h>
|
||||
+
|
||||
+#ifndef DEFAULT_IM_MODULE_TYPE
|
||||
+#define DEFAULT_IM_MODULE_TYPE "gtk3"
|
||||
+#endif
|
||||
+
|
||||
+typedef const char * (* IBusIMGetContextIdFunc) (int *argc, char ***argv);
|
||||
+
|
||||
+static char *im_module_type;
|
||||
+
|
||||
+
|
||||
+char *
|
||||
+ibus_im_module_get_id (int argc, char *argv[])
|
||||
+{
|
||||
+ static const GOptionEntry options[3] = {
|
||||
+ { "type", (char)0, (int)0, G_OPTION_ARG_STRING, &im_module_type,
|
||||
+ N_ ("Type im-module TYPE = \"gtk2\", \"gtk3\", \"gtk4\". " \
|
||||
+ "Default is \"" DEFAULT_IM_MODULE_TYPE "\"."),
|
||||
+ "TYPE"},
|
||||
+ { NULL }
|
||||
+ };
|
||||
+ GOptionContext *option;
|
||||
+ GError *error = NULL;
|
||||
+ void *module;
|
||||
+ char *im_context_id;
|
||||
+ IBusIMGetContextIdFunc im_get_context_id;
|
||||
+
|
||||
+ if (!(option = g_option_context_new (NULL))) {
|
||||
+ g_critical ("malloc GOptionContext is failed.");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ g_option_context_add_main_entries (option, options, GETTEXT_PACKAGE);
|
||||
+ g_option_context_parse (option, &argc, &argv, &error);
|
||||
+ if (error) {
|
||||
+ g_critical ("%s", error->message);
|
||||
+ g_clear_error (&error);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ g_option_context_free (option);
|
||||
+ if (!im_module_type)
|
||||
+ im_module_type = g_strdup (DEFAULT_IM_MODULE_TYPE);
|
||||
+
|
||||
+ if (G_LIKELY (!g_strcmp0 (im_module_type, "gtk3"))) {
|
||||
+ module = dlopen (GTK3_IM_MODULEDIR "/im-ibus.so",
|
||||
+ RTLD_LAZY);
|
||||
+ } else if (!g_strcmp0 (im_module_type, "gtk4")) {
|
||||
+ const char *module_path_env = g_getenv ("GTK_PATH");
|
||||
+ char *module_path;
|
||||
+ if (module_path_env) {
|
||||
+ module_path = g_build_filename (module_path_env,
|
||||
+ GTK4_IM_MODULEDIR "/libim-ibus.so",
|
||||
+ NULL);
|
||||
+ } else {
|
||||
+ module_path = g_strdup (GTK4_IM_MODULEDIR "/libim-ibus.so");
|
||||
+ }
|
||||
+ module = dlopen (module_path, RTLD_LAZY);
|
||||
+ g_free (module_path);
|
||||
+ } else if (!g_strcmp0 (im_module_type, "gtk2")) {
|
||||
+ module = dlopen (GTK2_IM_MODULEDIR "/im-ibus.so",
|
||||
+ RTLD_LAZY);
|
||||
+ } else {
|
||||
+ module = dlopen (im_module_type, RTLD_LAZY);
|
||||
+ }
|
||||
+ if (!module) {
|
||||
+ g_warning ("Not found module: %s", dlerror ());
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ im_get_context_id = dlsym (module, "im_get_context_id");
|
||||
+ if (!im_get_context_id) {
|
||||
+ g_warning ("Not found im_get_context_id: %s", dlerror ());
|
||||
+ dlclose (module);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ im_context_id = strdup (im_get_context_id (&argc, &argv));
|
||||
+ dlclose (module);
|
||||
+ return im_context_id;
|
||||
+}
|
||||
+
|
||||
+#undef DEFAULT_IM_MODULE_TYPE
|
||||
+
|
||||
diff --git a/tools/ibusimmodule.h b/tools/ibusimmodule.h
|
||||
new file mode 100644
|
||||
index 00000000..e762a747
|
||||
--- /dev/null
|
||||
+++ b/tools/ibusimmodule.h
|
||||
@@ -0,0 +1,36 @@
|
||||
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
||||
+/* vim:set et sts=4: */
|
||||
+/* ibus - The Input Bus
|
||||
+ * Copyright (C) 2022 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
||||
+ *
|
||||
+ * This library is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU Lesser General Public
|
||||
+ * License as published by the Free Software Foundation; either
|
||||
+ * version 2.1 of the License, or (at your option) any later version.
|
||||
+ *
|
||||
+ * This library is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ * Lesser General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU Lesser General Public
|
||||
+ * License along with this library; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
+ * USA
|
||||
+ */
|
||||
+
|
||||
+#ifndef __IBUS_IM_MODULE_CONTEXT_H_
|
||||
+#define __IBUS_IM_MODULE_CONTEXT_H_
|
||||
+
|
||||
+/**
|
||||
+ * ibus_im_module_get_id:
|
||||
+ * @argc: The length of argv
|
||||
+ * @argv: (array length=argc) (element-type utf8): argv from main()
|
||||
+ *
|
||||
+ * Retrieve im-module value from GTK instance.
|
||||
+ *
|
||||
+ * Returns: (nullable): im-module value.
|
||||
+ */
|
||||
+char * ibus_im_module_get_id (int argc, char *argv[]);
|
||||
+
|
||||
+#endif
|
||||
diff --git a/tools/main.vala b/tools/main.vala
|
||||
index 71134334..587f3a09 100644
|
||||
--- a/tools/main.vala
|
||||
+++ b/tools/main.vala
|
||||
@@ -641,6 +641,19 @@ int emoji_dialog(string[] argv) {
|
||||
#endif
|
||||
|
||||
|
||||
+int read_im_module(string[] argv) {
|
||||
+#if LIB_IBUS_MODULE
|
||||
+ string? im_module = IBusIMModule.im_module_get_id(argv);
|
||||
+ if (im_module == null)
|
||||
+ return Posix.EXIT_FAILURE;
|
||||
+ print("%s\n".printf(im_module));
|
||||
+#else
|
||||
+ print("%s\n".printf(_("Not supported in your system.")));
|
||||
+#endif
|
||||
+ return Posix.EXIT_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+
|
||||
int print_help(string[] argv) {
|
||||
print_usage(stdout);
|
||||
return Posix.EXIT_SUCCESS;
|
||||
@@ -672,6 +685,8 @@ const CommandEntry commands[] = {
|
||||
#if EMOJI_DICT
|
||||
{ "emoji", N_("Save emoji on dialog to clipboard"), emoji_dialog },
|
||||
#endif
|
||||
+ { "im-module", N_("Retrieve im-module value from GTK instance"),
|
||||
+ read_im_module },
|
||||
{ "help", N_("Show this information"), print_help }
|
||||
};
|
||||
|
||||
--
|
||||
2.35.3
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
Name: ibus
|
||||
Version: 1.5.26
|
||||
Release: 11%{?dist}
|
||||
Release: 12%{?dist}
|
||||
Summary: Intelligent Input Bus for Linux OS
|
||||
License: LGPLv2+
|
||||
URL: https://github.com/ibus/%name/wiki
|
||||
@ -279,6 +279,7 @@ the functionality of the installed %{name} package.
|
||||
# cp client/gtk2/ibusimcontext.c client/gtk4/ibusimcontext.c || :
|
||||
cp client/gtk2/ibusimcontext.c client/gtk3/ibusimcontext.c || :
|
||||
cp client/gtk2/ibusimcontext.c client/gtk4/ibusimcontext.c || :
|
||||
cp client/gtk2/ibusim.c client/gtk3/ibusim.c || :
|
||||
|
||||
|
||||
# prep test
|
||||
@ -323,6 +324,7 @@ autoreconf -f -i -v
|
||||
%{nil}
|
||||
|
||||
make -C ui/gtk3 maintainer-clean-generic
|
||||
make -C tools maintainer-clean-generic
|
||||
%make_build
|
||||
|
||||
%install
|
||||
@ -522,6 +524,9 @@ dconf update || :
|
||||
%{_datadir}/installed-tests/ibus
|
||||
|
||||
%changelog
|
||||
* Wed Jun 29 2022 Takao Fujiwara <tfujiwar@redhat.com> - 1.5.26-12
|
||||
- Add ibus im-module command
|
||||
|
||||
* Sat Jun 25 2022 Takao Fujiwara <tfujiwar@redhat.com> - 1.5.26-11
|
||||
- Enable custome theme
|
||||
- Fix ibus restart for GNOME desktop
|
||||
|
Loading…
Reference in New Issue
Block a user