init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
allhaileris
2026-02-16 15:50:16 +03:00
commit afb81b8278
13816 changed files with 3689732 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
SUBDIRS = gtk
if HAVE_QT5
SUBDIRS += qt5
endif
if HAVE_QT6
SUBDIRS += qt6
endif
DISTCLEANFILES = Makefile.in

View File

@@ -0,0 +1,42 @@
gsettings_SCHEMAS = org.nimf.clients.gtk.gschema.xml
@GSETTINGS_RULES@
AM_CFLAGS = \
$(EXTRA_CFLAGS) \
-I$(top_srcdir)/libnimf \
-DG_LOG_DOMAIN=\"nimf\"
# for gtk3
gtk3_im_moduledir = $(GTK3_LIBDIR)/gtk-3.0/$(GTK3_BINARY_VERSION)/immodules
gtk3_im_module_LTLIBRARIES = im-nimf-gtk3.la
im_nimf_gtk3_la_SOURCES = im-nimf.c
im_nimf_gtk3_la_CFLAGS = $(IM_NIMF_GTK3_DEPS_CFLAGS) $(AM_CFLAGS)
im_nimf_gtk3_la_LDFLAGS = $(IM_NIMF_GTK3_DEPS_LIBS) -avoid-version -module
im_nimf_gtk3_la_LIBADD = $(top_builddir)/libnimf/libnimf.la
# for gtk2
gtk2_im_moduledir = $(GTK2_LIBDIR)/gtk-2.0/$(GTK2_BINARY_VERSION)/immodules
gtk2_im_module_LTLIBRARIES = im-nimf-gtk2.la
im_nimf_gtk2_la_SOURCES = im-nimf.c
im_nimf_gtk2_la_CFLAGS = $(IM_NIMF_GTK2_DEPS_CFLAGS) $(AM_CFLAGS) \
-Wno-error=deprecated-declarations
im_nimf_gtk2_la_LDFLAGS = $(IM_NIMF_GTK2_DEPS_LIBS) -avoid-version -module
im_nimf_gtk2_la_LIBADD = $(top_builddir)/libnimf/libnimf.la
DISTCLEANFILES = Makefile.in
install-data-hook:
chmod -x $(DESTDIR)$(gtk3_im_moduledir)/im-nimf-gtk3.so
chmod -x $(DESTDIR)$(gtk2_im_moduledir)/im-nimf-gtk2.so
rm -f $(DESTDIR)$(gtk3_im_moduledir)/im-nimf-gtk3.la
rm -f $(DESTDIR)$(gtk2_im_moduledir)/im-nimf-gtk2.la
uninstall-hook:
rm -f $(DESTDIR)$(gtk3_im_moduledir)/im-nimf-gtk3.so
rm -f $(DESTDIR)$(gtk2_im_moduledir)/im-nimf-gtk2.so
$(GTK_QUERY_IMMODULES2) --update-cache
$(GTK_QUERY_IMMODULES3) --update-cache

View File

@@ -0,0 +1,592 @@
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/*
* im-nimf.c
* This file is part of Nimf.
*
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
*
* Nimf 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 3 of the License, or
* (at your option) any later version.
*
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtk.h>
#include <gtk/gtkimmodule.h>
#include <glib/gi18n.h>
#include <nimf.h>
#include <X11/XKBlib.h>
#if GTK_CHECK_VERSION (3, 6, 0)
#include <gdk/gdkx.h>
#endif
#define NIMF_GTK_TYPE_IM_CONTEXT (nimf_gtk_im_context_get_type ())
#define NIMF_GTK_IM_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NIMF_GTK_TYPE_IM_CONTEXT, NimfGtkIMContext))
typedef struct _NimfGtkIMContext NimfGtkIMContext;
typedef struct _NimfGtkIMContextClass NimfGtkIMContextClass;
struct _NimfGtkIMContext
{
GtkIMContext parent_instance;
NimfIM *im;
GtkIMContext *simple;
GdkWindow *client_window;
GSettings *settings;
gboolean is_reset_on_gdk_button_press_event;
gboolean is_hook_gdk_event_key;
gboolean has_focus;
gboolean has_event_filter;
};
struct _NimfGtkIMContextClass
{
GtkIMContextClass parent_class;
};
G_DEFINE_DYNAMIC_TYPE (NimfGtkIMContext, nimf_gtk_im_context, GTK_TYPE_IM_CONTEXT);
static NimfEvent *
translate_gdk_event_key (GdkEventKey *event)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
NimfEvent *nimf_event = nimf_event_new (NIMF_EVENT_NOTHING);
if (event->type == GDK_KEY_PRESS)
nimf_event->key.type = NIMF_EVENT_KEY_PRESS;
else
nimf_event->key.type = NIMF_EVENT_KEY_RELEASE;
nimf_event->key.state = event->state;
nimf_event->key.keyval = event->keyval;
nimf_event->key.hardware_keycode = event->hardware_keycode;
return nimf_event;
}
static NimfEvent *
translate_xkey_event (XEvent *xevent)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
GdkKeymap *keymap = gdk_keymap_get_for_display (gdk_display_get_default ());
GdkModifierType consumed, state;
NimfEvent *nimf_event = nimf_event_new (NIMF_EVENT_NOTHING);
if (xevent->type == KeyPress)
nimf_event->key.type = NIMF_EVENT_KEY_PRESS;
else
nimf_event->key.type = NIMF_EVENT_KEY_RELEASE;
nimf_event->key.state = (NimfModifierType) xevent->xkey.state;
#if GTK_CHECK_VERSION (3, 6, 0)
gint group = gdk_x11_keymap_get_group_for_state (keymap, xevent->xkey.state);
#else
gint group = XkbGroupForCoreState (xevent->xkey.state);
#endif
nimf_event->key.hardware_keycode = xevent->xkey.keycode;
nimf_event->key.keyval = NIMF_KEY_VoidSymbol;
gdk_keymap_translate_keyboard_state (keymap,
nimf_event->key.hardware_keycode,
nimf_event->key.state,
group,
&nimf_event->key.keyval,
NULL, NULL, &consumed);
state = nimf_event->key.state & ~consumed;
nimf_event->key.state |= (NimfModifierType) state;
return nimf_event;
}
static gboolean
nimf_gtk_im_context_filter_keypress (GtkIMContext *context,
GdkEventKey *event)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
gboolean retval;
NimfEvent *nimf_event;
nimf_event = translate_gdk_event_key (event);
retval = nimf_im_filter_event (NIMF_GTK_IM_CONTEXT (context)->im, nimf_event);
nimf_event_free (nimf_event);
if (retval == FALSE)
return gtk_im_context_filter_keypress (NIMF_GTK_IM_CONTEXT (context)->simple, event);
return retval;
}
static void
nimf_gtk_im_context_reset (GtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_im_reset (NIMF_GTK_IM_CONTEXT (context)->im);
gtk_im_context_reset (NIMF_GTK_IM_CONTEXT (context)->simple);
}
static GdkFilterReturn
on_gdk_x_event (XEvent *xevent,
GdkEvent *event,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s: %p, %" G_GINT64_FORMAT, G_STRFUNC, context,
g_get_real_time ());
gboolean retval = FALSE;
if (context->has_focus == FALSE || context->client_window == NULL)
return GDK_FILTER_CONTINUE;
switch (xevent->type)
{
case KeyPress:
case KeyRelease:
if (context->is_hook_gdk_event_key)
{
NimfEvent *nimf_event = translate_xkey_event (xevent);
retval = nimf_im_filter_event (context->im, nimf_event);
nimf_event_free (nimf_event);
}
break;
case ButtonPress:
if (context->is_reset_on_gdk_button_press_event)
nimf_im_reset (context->im);
break;
default:
break;
}
if (retval == FALSE)
return GDK_FILTER_CONTINUE;
else
return GDK_FILTER_REMOVE;
}
static void
nimf_gtk_im_context_set_client_window (GtkIMContext *context,
GdkWindow *window)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
NimfGtkIMContext *a_context = NIMF_GTK_IM_CONTEXT (context);
if (a_context->client_window)
{
g_object_unref (a_context->client_window);
a_context->client_window = NULL;
}
if (window)
a_context->client_window = g_object_ref (window);
}
static void
nimf_gtk_im_context_get_preedit_string (GtkIMContext *context,
gchar **str,
PangoAttrList **attrs,
gint *cursor_pos)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
NimfPreeditAttr **preedit_attrs;
gchar *preedit_str;
nimf_im_get_preedit_string (NIMF_GTK_IM_CONTEXT (context)->im,
&preedit_str, &preedit_attrs, cursor_pos);
if (str)
*str = preedit_str;
if (attrs)
{
PangoAttribute *attr;
gchar *ptr1;
gchar *ptr2;
gint i;
*attrs = pango_attr_list_new ();
for (i = 0; preedit_attrs[i] != NULL; i++)
{
ptr1 = g_utf8_offset_to_pointer (preedit_str, preedit_attrs[i]->start_index);
ptr2 = g_utf8_offset_to_pointer (preedit_str, preedit_attrs[i]->end_index);
switch (preedit_attrs[i]->type)
{
case NIMF_PREEDIT_ATTR_UNDERLINE:
attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
break;
case NIMF_PREEDIT_ATTR_HIGHLIGHT:
attr = pango_attr_background_new (0, 0xffff, 0);
attr->start_index = ptr1 - preedit_str;
attr->end_index = ptr2 - preedit_str;
pango_attr_list_insert (*attrs, attr);
attr = pango_attr_foreground_new (0, 0, 0);
break;
default:
attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
break;
}
attr->start_index = ptr1 - preedit_str;
attr->end_index = ptr2 - preedit_str;
pango_attr_list_insert (*attrs, attr);
}
}
nimf_preedit_attr_freev (preedit_attrs);
}
static void
nimf_gtk_im_context_focus_in (GtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
NimfGtkIMContext *a_context = NIMF_GTK_IM_CONTEXT (context);
a_context->has_focus = TRUE;
nimf_im_focus_in (a_context->im);
}
static void
nimf_gtk_im_context_focus_out (GtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
NimfGtkIMContext *a_context = NIMF_GTK_IM_CONTEXT (context);
nimf_im_focus_out (a_context->im);
a_context->has_focus = FALSE;
}
static void
nimf_gtk_im_context_set_cursor_location (GtkIMContext *context,
GdkRectangle *area)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
NimfGtkIMContext *nimf_context = NIMF_GTK_IM_CONTEXT (context);
GdkRectangle root_area = *area;
if (nimf_context->client_window)
gdk_window_get_root_coords (nimf_context->client_window,
area->x,
area->y,
&root_area.x,
&root_area.y);
nimf_im_set_cursor_location (NIMF_GTK_IM_CONTEXT (context)->im,
(const NimfRectangle *) &root_area);
}
static void
nimf_gtk_im_context_set_use_preedit (GtkIMContext *context,
gboolean use_preedit)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_im_set_use_preedit (NIMF_GTK_IM_CONTEXT (context)->im, use_preedit);
}
static void
nimf_gtk_im_context_set_surrounding (GtkIMContext *context,
const char *text,
gint len,
gint cursor_index)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_im_set_surrounding (NIMF_GTK_IM_CONTEXT (context)->im,
text, len, g_utf8_strlen (text, cursor_index));
}
GtkIMContext *
nimf_gtk_im_context_new (void)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
return g_object_new (NIMF_GTK_TYPE_IM_CONTEXT, NULL);
}
static void
on_commit (NimfIM *im,
const gchar *text,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
g_signal_emit_by_name (context, "commit", text);
}
static gboolean
on_delete_surrounding (NimfIM *im,
gint offset,
gint n_chars,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
gboolean retval;
g_signal_emit_by_name (context,
"delete-surrounding", offset, n_chars, &retval);
return retval;
}
static void
on_preedit_changed (NimfIM *im,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
g_signal_emit_by_name (context, "preedit-changed");
}
static void
on_preedit_end (NimfIM *im,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
g_signal_emit_by_name (context, "preedit-end");
}
static void
on_preedit_start (NimfIM *im,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
g_signal_emit_by_name (context, "preedit-start");
}
static gboolean
on_retrieve_surrounding (NimfIM *im,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
gboolean retval;
g_signal_emit_by_name (context, "retrieve-surrounding", &retval);
return retval;
}
static void
on_beep (NimfIM *im,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
gdk_display_beep (gdk_display_get_default ());
}
static void
nimf_gtk_im_context_update_event_filter (NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
if (context->is_reset_on_gdk_button_press_event ||
context->is_hook_gdk_event_key)
{
if (context->has_event_filter == FALSE)
{
context->has_event_filter = TRUE;
gdk_window_add_filter (NULL, (GdkFilterFunc) on_gdk_x_event, context);
}
}
else
{
if (context->has_event_filter == TRUE)
{
context->has_event_filter = FALSE;
gdk_window_remove_filter (NULL, (GdkFilterFunc) on_gdk_x_event, context);
}
}
}
static void
on_changed_reset_on_gdk_button_press_event (GSettings *settings,
gchar *key,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
context->is_reset_on_gdk_button_press_event =
g_settings_get_boolean (context->settings, key);
nimf_gtk_im_context_update_event_filter (context);
}
static void
on_changed_hook_gdk_event_key (GSettings *settings,
gchar *key,
NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
context->is_hook_gdk_event_key =
g_settings_get_boolean (context->settings, key);
nimf_gtk_im_context_update_event_filter (context);
}
static void
nimf_gtk_im_context_init (NimfGtkIMContext *context)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
context->im = nimf_im_new ();
context->simple = gtk_im_context_simple_new ();
g_signal_connect (context->im, "commit",
G_CALLBACK (on_commit), context);
g_signal_connect (context->im, "delete-surrounding",
G_CALLBACK (on_delete_surrounding), context);
g_signal_connect (context->im, "preedit-changed",
G_CALLBACK (on_preedit_changed), context);
g_signal_connect (context->im, "preedit-end",
G_CALLBACK (on_preedit_end), context);
g_signal_connect (context->im, "preedit-start",
G_CALLBACK (on_preedit_start), context);
g_signal_connect (context->im, "retrieve-surrounding",
G_CALLBACK (on_retrieve_surrounding), context);
g_signal_connect (context->im, "beep",
G_CALLBACK (on_beep), context);
g_signal_connect (context->simple, "commit",
G_CALLBACK (on_commit), context);
g_signal_connect (context->simple, "delete-surrounding",
G_CALLBACK (on_delete_surrounding), context);
g_signal_connect (context->simple, "preedit-changed",
G_CALLBACK (on_preedit_changed), context);
g_signal_connect (context->simple, "preedit-end",
G_CALLBACK (on_preedit_end), context);
g_signal_connect (context->simple, "preedit-start",
G_CALLBACK (on_preedit_start), context);
g_signal_connect (context->simple, "retrieve-surrounding",
G_CALLBACK (on_retrieve_surrounding), context);
context->settings = g_settings_new ("org.nimf.clients.gtk");
context->is_reset_on_gdk_button_press_event =
g_settings_get_boolean (context->settings,
"reset-on-gdk-button-press-event");
context->is_hook_gdk_event_key =
g_settings_get_boolean (context->settings, "hook-gdk-event-key");
nimf_gtk_im_context_update_event_filter (context);
g_signal_connect (context->settings,
"changed::reset-on-gdk-button-press-event",
G_CALLBACK (on_changed_reset_on_gdk_button_press_event),
context);
g_signal_connect (context->settings, "changed::hook-gdk-event-key",
G_CALLBACK (on_changed_hook_gdk_event_key), context);
}
static void
nimf_gtk_im_context_finalize (GObject *object)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
NimfGtkIMContext *context = NIMF_GTK_IM_CONTEXT (object);
if (context->has_event_filter)
gdk_window_remove_filter (NULL, (GdkFilterFunc) on_gdk_x_event, context);
g_object_unref (context->im);
g_object_unref (context->simple);
g_object_unref (context->settings);
if (context->client_window)
g_object_unref (context->client_window);
G_OBJECT_CLASS (nimf_gtk_im_context_parent_class)->finalize (object);
}
static void
nimf_gtk_im_context_class_init (NimfGtkIMContextClass *class)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
im_context_class->set_client_window = nimf_gtk_im_context_set_client_window;
im_context_class->get_preedit_string = nimf_gtk_im_context_get_preedit_string;
im_context_class->filter_keypress = nimf_gtk_im_context_filter_keypress;
im_context_class->focus_in = nimf_gtk_im_context_focus_in;
im_context_class->focus_out = nimf_gtk_im_context_focus_out;
im_context_class->reset = nimf_gtk_im_context_reset;
im_context_class->set_cursor_location = nimf_gtk_im_context_set_cursor_location;
im_context_class->set_use_preedit = nimf_gtk_im_context_set_use_preedit;
im_context_class->set_surrounding = nimf_gtk_im_context_set_surrounding;
object_class->finalize = nimf_gtk_im_context_finalize;
}
static void
nimf_gtk_im_context_class_finalize (NimfGtkIMContextClass *class)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
}
static const GtkIMContextInfo nimf_info = {
PACKAGE, /* ID */
N_("Nimf"), /* Human readable name */
GETTEXT_PACKAGE, /* Translation domain */
NIMF_LOCALE_DIR, /* Directory for bindtextdomain */
"ko:ja:zh" /* Languages for which this module is the default */
};
static const GtkIMContextInfo *info_list[] = {
&nimf_info
};
G_MODULE_EXPORT void im_module_init (GTypeModule *type_module)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_gtk_im_context_register_type (type_module);
}
G_MODULE_EXPORT void im_module_exit (void)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
}
G_MODULE_EXPORT void im_module_list (const GtkIMContextInfo ***contexts,
int *n_contexts)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
*contexts = info_list;
*n_contexts = G_N_ELEMENTS (info_list);
}
G_MODULE_EXPORT GtkIMContext *im_module_create (const gchar *context_id)
{
g_debug (G_STRLOC ": %s", G_STRFUNC);
if (g_strcmp0 (context_id, PACKAGE) == 0)
return nimf_gtk_im_context_new ();
else
return NULL;
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.nimf.clients.gtk"
path="/org/nimf/clients/gtk/" gettext-domain="nimf">
<key type="s" name="hidden-schema-name">
<default l10n="messages">'GTK+'</default>
<summary>schema name for nimf-settings</summary>
<description>This key is intended for nimf-settings.</description>
</key>
<key type="b" name="hook-gdk-event-key">
<default>false</default>
<summary>Hooking GDK key events</summary>
<description>Filter all key events before delivering them normally, which avoids bugs of many applications</description>
</key>
<key type="b" name="reset-on-gdk-button-press-event">
<default>false</default>
<summary>Reset when clicking the mouse button</summary>
<description>Reset when clicking the mouse button</description>
</key>
</schema>
</schemalist>

View File

@@ -0,0 +1,41 @@
gsettings_SCHEMAS = org.nimf.clients.qt5.gschema.xml
@GSETTINGS_RULES@
qt5_im_moduledir = $(QT5_IM_MODULE_DIR)
qt5_im_module_LTLIBRARIES = libqt5im-nimf.la
BUILT_SOURCES = im-nimf-qt5.moc
libqt5im_nimf_la_SOURCES = im-nimf-qt5.cpp $(BUILT_SOURCES)
libqt5im_nimf_la_CXXFLAGS = \
$(EXTRA_CFLAGS) \
$(LIBNIMF_DEPS_CFLAGS) \
-I$(top_srcdir)/libnimf \
-DG_LOG_DOMAIN=\"nimf\" \
-DNIMF_COMPILATION \
$(IM_NIMF_QT5_DEPS_CFLAGS) \
-I$(QT5_CORE_PRIVATE_INCLUDE_PATH) \
-I$(QT5_GUI_PRIVATE_INCLUDE_PATH) \
-DQT_NO_KEYWORDS \
-fPIC \
-std=c++11
libqt5im_nimf_la_LDFLAGS = -avoid-version -module \
$(IM_NIMF_QT5_DEPS_LIBS) \
$(LIBNIMF_DEPS_LIBS)
libqt5im_nimf_la_LIBADD = $(top_builddir)/libnimf/libnimf.la
im-nimf-qt5.moc: im-nimf-qt5.cpp
$(AM_V_GEN) $(QT5_MOC) -I $(QT5_CORE_PRIVATE_INCLUDE_PATH) \
-I $(QT5_GUI_PRIVATE_INCLUDE_PATH) im-nimf-qt5.cpp \
-o im-nimf-qt5.moc
install-data-hook:
chmod -x $(DESTDIR)$(qt5_im_moduledir)/libqt5im-nimf.so
rm -f $(DESTDIR)$(qt5_im_moduledir)/libqt5im-nimf.la
uninstall-hook:
rm -f $(DESTDIR)$(qt5_im_moduledir)/libqt5im-nimf.so
-rmdir -p $(DESTDIR)$(qt5_im_moduledir)
DISTCLEANFILES = Makefile.in $(BUILT_SOURCES)

View File

@@ -0,0 +1,868 @@
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/*
* im-nimf-qt5.cpp
* This file is part of Nimf.
*
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
*
* Nimf 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 3 of the License, or
* (at your option) any later version.
*
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
*/
#include <QTextFormat>
#include <QInputMethodEvent>
#include <QtGui/qpa/qplatforminputcontext.h>
#include <QtGui/qpa/qplatforminputcontextplugin_p.h>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include "nimf-im.h"
#include <gio/gio.h>
#ifdef USE_DLFCN
#include <dlfcn.h>
typedef struct
{
NimfIM * (* im_new) (void);
void (* im_focus_in) (NimfIM *im);
void (* im_focus_out) (NimfIM *im);
void (* im_reset) (NimfIM *im);
gboolean (* im_filter_event) (NimfIM *im,
NimfEvent *event);
void (* im_get_preedit_string) (NimfIM *im,
gchar **str,
NimfPreeditAttr ***attrs,
gint *cursor_pos);
void (* im_set_cursor_location) (NimfIM *im,
const NimfRectangle *area);
void (* im_set_use_preedit) (NimfIM *im,
gboolean use_preedit);
void (* im_set_surrounding) (NimfIM *im,
const char *text,
gint len,
gint cursor_index);
NimfEvent * (* event_new) (NimfEventType type);
void (* event_free) (NimfEvent *event);
void (* preedit_attr_freev) (NimfPreeditAttr **attrs);
} NimfAPI;
typedef struct
{
void (* free) (gpointer mem);
} GLibAPI;
typedef struct
{
gulong (* signal_connect_data) (gpointer instance,
const gchar *detailed_signal,
GCallback c_handler,
gpointer data,
GClosureNotify destroy_data,
GConnectFlags connect_flags);
void (* signal_emit_by_name) (gpointer instance,
const gchar *detailed_signal,
...);
void (* object_unref) (gpointer object);
} GObjectAPI;
typedef struct
{
GSettings * (* settings_new) (const gchar *schema_id);
gboolean (* settings_get_boolean) (GSettings *settings,
const gchar *key);
GSettingsSchemaSource *
(* settings_schema_source_get_default) (void);
GSettingsSchema *
(* settings_schema_source_lookup)
(GSettingsSchemaSource *source,
const gchar *schema_id,
gboolean recursive);
void (* settings_schema_unref) (GSettingsSchema *schema);
} GIOAPI;
void *libnimf = NULL;
void *libglib = NULL;
void *libgobject = NULL;
void *libgio = NULL;
NimfAPI *nimf_api = NULL;
GLibAPI *glib_api = NULL;
GObjectAPI *gobject_api = NULL;
GIOAPI *gio_api = NULL;
#endif
class NimfEventHandler : public QObject
{
Q_OBJECT
public:
NimfEventHandler(NimfIM *im)
{
m_im = im;
};
~NimfEventHandler()
{};
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
NimfIM *m_im;
};
bool NimfEventHandler::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress)
#ifndef USE_DLFCN
nimf_im_reset (m_im);
#else
nimf_api->im_reset (m_im);
#endif
return QObject::eventFilter(obj, event);
}
class NimfInputContext : public QPlatformInputContext
{
Q_OBJECT
public:
NimfInputContext ();
~NimfInputContext ();
virtual bool isValid () const;
virtual void reset ();
virtual void commit ();
virtual void update (Qt::InputMethodQueries);
virtual void invokeAction (QInputMethod::Action, int cursorPosition);
virtual bool filterEvent (const QEvent *event);
virtual QRectF keyboardRect () const;
virtual bool isAnimating () const;
virtual void showInputPanel ();
virtual void hideInputPanel ();
virtual bool isInputPanelVisible () const;
virtual QLocale locale () const;
virtual Qt::LayoutDirection inputDirection() const;
virtual void setFocusObject (QObject *object);
// nimf signal callbacks
static void on_preedit_start (NimfIM *im,
gpointer user_data);
static void on_preedit_end (NimfIM *im,
gpointer user_data);
static void on_preedit_changed (NimfIM *im,
gpointer user_data);
static void on_commit (NimfIM *im,
const gchar *text,
gpointer user_data);
static gboolean on_retrieve_surrounding (NimfIM *im,
gpointer user_data);
static gboolean on_delete_surrounding (NimfIM *im,
gint offset,
gint n_chars,
gpointer user_data);
static void on_beep (NimfIM *im,
gpointer user_data);
// settings
static void on_changed_reset_on_mouse_button_press (GSettings *settings,
gchar *key,
gpointer user_data);
private:
NimfIM *m_im;
GSettings *m_settings;
NimfEventHandler *m_handler;
NimfRectangle m_cursor_area;
};
/* nimf signal callbacks */
void
NimfInputContext::on_preedit_start (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
void
NimfInputContext::on_preedit_end (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
void
NimfInputContext::on_preedit_changed (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
NimfPreeditAttr **preedit_attrs;
gchar *str;
gint cursor_pos;
gint offset = 0;
guint i, j, len;
#ifndef USE_DLFCN
nimf_im_get_preedit_string (im, &str, &preedit_attrs, &cursor_pos);
#else
nimf_api->im_get_preedit_string (im, &str, &preedit_attrs, &cursor_pos);
#endif
QString preeditText = QString::fromUtf8 (str);
#ifndef USE_DLFCN
g_free (str);
#else
glib_api->free (str);
#endif
QList <QInputMethodEvent::Attribute> attrs;
for (i = 0; i < (guint) preeditText.size(); i++)
{
if (preeditText.at(i).isLowSurrogate())
{
offset++;
continue;
}
QTextCharFormat format;
for (j = 0; preedit_attrs[j]; j++)
{
switch (preedit_attrs[j]->type)
{
case NIMF_PREEDIT_ATTR_HIGHLIGHT:
if (preedit_attrs[j]->start_index <= i - offset &&
preedit_attrs[j]->end_index > i - offset)
{
format.setBackground(Qt::green);
format.setForeground(Qt::black);
}
break;
case NIMF_PREEDIT_ATTR_UNDERLINE:
if (preedit_attrs[j]->start_index <= i - offset &&
preedit_attrs[j]->end_index > i - offset)
format.setUnderlineStyle(QTextCharFormat::DashUnderline);
break;
default:
break;
}
}
preeditText.at(i).isHighSurrogate() ? len = 2 : len = 1;
QInputMethodEvent::Attribute attr (QInputMethodEvent::TextFormat,
i, len, format);
attrs << attr;
}
#ifndef USE_DLFCN
nimf_preedit_attr_freev (preedit_attrs);
#else
nimf_api->preedit_attr_freev (preedit_attrs);
#endif
// cursor attribute
attrs << QInputMethodEvent::Attribute (QInputMethodEvent::Cursor,
cursor_pos + offset, true, 0);
QInputMethodEvent event (preeditText, attrs);
QObject *object = qApp->focusObject ();
if (!object)
return;
QCoreApplication::sendEvent (object, &event);
}
void
NimfInputContext::on_commit (NimfIM *im,
const gchar *text,
gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QString str = QString::fromUtf8 (text);
QInputMethodEvent event;
event.setCommitString (str);
QObject *obj = qApp->focusObject();
if (!obj)
return;
QCoreApplication::sendEvent (obj, &event);
}
gboolean
NimfInputContext::on_retrieve_surrounding (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QObject *object = qApp->focusObject();
if (!object)
return FALSE;
NimfInputContext *context = static_cast<NimfInputContext *>(user_data);
QInputMethodQueryEvent surrounding_query (Qt::ImSurroundingText);
QInputMethodQueryEvent position_query (Qt::ImCursorPosition);
QCoreApplication::sendEvent (object, &surrounding_query);
QCoreApplication::sendEvent (object, &position_query);
QString string = surrounding_query.value (Qt::ImSurroundingText).toString();
uint pos = position_query.value (Qt::ImCursorPosition).toUInt();
#ifndef USE_DLFCN
nimf_im_set_surrounding (context->m_im,
string.toUtf8().constData(), -1, pos);
#else
nimf_api->im_set_surrounding (context->m_im,
string.toUtf8().constData(), -1, pos);
#endif
return TRUE;
}
gboolean
NimfInputContext::on_delete_surrounding (NimfIM *im,
gint offset,
gint n_chars,
gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QObject *object = qApp->focusObject();
if (!object)
return FALSE;
QInputMethodEvent event;
event.setCommitString ("", offset, n_chars);
QCoreApplication::sendEvent (object, &event);
return TRUE;
}
void
NimfInputContext::on_beep (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QApplication::beep();
}
void
NimfInputContext::on_changed_reset_on_mouse_button_press (GSettings *settings,
gchar *key,
gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
NimfInputContext *context = static_cast<NimfInputContext *>(user_data);
#ifndef USE_DLFCN
if (g_settings_get_boolean (settings, key))
#else
if (gio_api->settings_get_boolean (settings, key))
#endif
{
if (context->m_handler == NULL)
{
context->m_handler = new NimfEventHandler(context->m_im);
qApp->installEventFilter(context->m_handler);
}
}
else
{
if (context->m_handler)
{
qApp->removeEventFilter(context->m_handler);
delete context->m_handler;
context->m_handler = NULL;
}
}
}
NimfInputContext::NimfInputContext ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
m_im = NULL;
m_settings = NULL;
m_handler = NULL;
m_cursor_area.x = 0;
m_cursor_area.y = 0;
m_cursor_area.width = 0;
m_cursor_area.height = 0;
#ifndef USE_DLFCN
m_im = nimf_im_new ();
m_settings = g_settings_new ("org.nimf.clients.qt5");
g_signal_connect (m_im, "preedit-start",
G_CALLBACK (NimfInputContext::on_preedit_start), this);
g_signal_connect (m_im, "preedit-end",
G_CALLBACK (NimfInputContext::on_preedit_end), this);
g_signal_connect (m_im, "preedit-changed",
G_CALLBACK (NimfInputContext::on_preedit_changed), this);
g_signal_connect (m_im, "commit",
G_CALLBACK (NimfInputContext::on_commit), this);
g_signal_connect (m_im, "retrieve-surrounding",
G_CALLBACK (NimfInputContext::on_retrieve_surrounding),
this);
g_signal_connect (m_im, "delete-surrounding",
G_CALLBACK (NimfInputContext::on_delete_surrounding),
this);
g_signal_connect (m_im, "beep",
G_CALLBACK (NimfInputContext::on_beep), this);
g_signal_connect (m_settings, "changed::reset-on-mouse-button-press",
G_CALLBACK (NimfInputContext::on_changed_reset_on_mouse_button_press), this);
g_signal_emit_by_name (m_settings, "changed::reset-on-mouse-button-press",
"reset-on-mouse-button-press");
#else
if (!nimf_api || !glib_api || !gobject_api || !gio_api)
{
qWarning("The libraries for nimf are not ready.");
return;
}
GSettingsSchemaSource *source;
GSettingsSchema *schema;
source = gio_api->settings_schema_source_get_default ();
schema = gio_api->settings_schema_source_lookup (source, "org.nimf.clients.qt5", TRUE);
if (schema == NULL)
{
qWarning("org.nimf.clients.qt5 schema is not found.");
return;
}
gio_api->settings_schema_unref (schema);
m_im = nimf_api->im_new ();
m_settings = gio_api->settings_new ("org.nimf.clients.qt5");
gobject_api->signal_connect_data (m_im, "preedit-start",
G_CALLBACK (NimfInputContext::on_preedit_start), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "preedit-end",
G_CALLBACK (NimfInputContext::on_preedit_end), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "preedit-changed",
G_CALLBACK (NimfInputContext::on_preedit_changed), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "commit",
G_CALLBACK (NimfInputContext::on_commit), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "retrieve-surrounding",
G_CALLBACK (NimfInputContext::on_retrieve_surrounding),
this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "delete-surrounding",
G_CALLBACK (NimfInputContext::on_delete_surrounding),
this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "beep",
G_CALLBACK (NimfInputContext::on_beep), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_settings, "changed::reset-on-mouse-button-press",
G_CALLBACK (NimfInputContext::on_changed_reset_on_mouse_button_press), this, NULL, (GConnectFlags) 0);
gobject_api->signal_emit_by_name (m_settings, "changed::reset-on-mouse-button-press",
"reset-on-mouse-button-press");
#endif
}
NimfInputContext::~NimfInputContext ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (m_handler)
delete m_handler;
if (m_im)
#ifndef USE_DLFCN
g_object_unref (m_im);
#else
gobject_api->object_unref (m_im);
#endif
if (m_settings)
#ifndef USE_DLFCN
g_object_unref (m_settings);
#else
gobject_api->object_unref (m_settings);
#endif
}
bool
NimfInputContext::isValid () const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (m_im == NULL)
return false;
return true;
}
void
NimfInputContext::reset ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_im_reset (m_im);
#else
nimf_api->im_reset (m_im);
#endif
}
void
NimfInputContext::commit ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_im_reset (m_im);
#else
nimf_api->im_reset (m_im);
#endif
}
void
NimfInputContext::update (Qt::InputMethodQueries queries)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (queries & Qt::ImCursorRectangle)
{
QWidget *widget = qApp->focusWidget ();
if (widget == NULL)
return;
QRect rect = widget->inputMethodQuery(Qt::ImCursorRectangle).toRect();
QPoint point = widget->mapToGlobal (QPoint (0, 0));
rect.translate (point);
if (m_cursor_area.x != rect.x () ||
m_cursor_area.y != rect.y () ||
m_cursor_area.width != rect.width () ||
m_cursor_area.height != rect.height ())
{
m_cursor_area.x = rect.x ();
m_cursor_area.y = rect.y ();
m_cursor_area.width = rect.width ();
m_cursor_area.height = rect.height ();
#ifndef USE_DLFCN
nimf_im_set_cursor_location (m_im, &m_cursor_area);
#else
nimf_api->im_set_cursor_location (m_im, &m_cursor_area);
#endif
}
}
}
void
NimfInputContext::invokeAction(QInputMethod::Action, int cursorPosition)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
bool
NimfInputContext::filterEvent (const QEvent *event)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (G_UNLIKELY (!qApp->focusObject() || !inputMethodAccepted()))
return false;
gboolean retval;
const QKeyEvent *key_event = static_cast<const QKeyEvent *>( event );
NimfEvent *nimf_event;
NimfEventType type = NIMF_EVENT_NOTHING;
switch (event->type ())
{
#undef KeyPress
case QEvent::KeyPress:
type = NIMF_EVENT_KEY_PRESS;
break;
#undef KeyRelease
case QEvent::KeyRelease:
type = NIMF_EVENT_KEY_RELEASE;
break;
default:
return false;
}
#ifndef USE_DLFCN
nimf_event = nimf_event_new (type);
#else
nimf_event = nimf_api->event_new (type);
#endif
nimf_event->key.state = key_event->nativeModifiers ();
nimf_event->key.keyval = key_event->nativeVirtualKey ();
nimf_event->key.hardware_keycode = key_event->nativeScanCode ();
#ifndef USE_DLFCN
retval = nimf_im_filter_event (m_im, nimf_event);
nimf_event_free (nimf_event);
#else
retval = nimf_api->im_filter_event (m_im, nimf_event);
nimf_api->event_free (nimf_event);
#endif
return retval;
}
QRectF
NimfInputContext::keyboardRect() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return QRectF ();
}
bool
NimfInputContext::isAnimating() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return false;
}
void
NimfInputContext::showInputPanel()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
void
NimfInputContext::hideInputPanel()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
bool
NimfInputContext::isInputPanelVisible() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return false;
}
QLocale
NimfInputContext::locale() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return QLocale ();
}
Qt::LayoutDirection
NimfInputContext::inputDirection() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return Qt::LayoutDirection ();
}
void
NimfInputContext::setFocusObject (QObject *object)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (!object || !inputMethodAccepted())
#ifndef USE_DLFCN
nimf_im_focus_out (m_im);
#else
nimf_api->im_focus_out (m_im);
#endif
QPlatformInputContext::setFocusObject (object);
if (object && inputMethodAccepted())
#ifndef USE_DLFCN
nimf_im_focus_in (m_im);
#else
nimf_api->im_focus_in (m_im);
#endif
update (Qt::ImCursorRectangle);
}
/*
* class NimfInputContextPlugin
*/
class NimfInputContextPlugin : public QPlatformInputContextPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID
QPlatformInputContextFactoryInterface_iid
FILE "./nimf.json")
public:
NimfInputContextPlugin ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
#ifdef USE_DLFCN
libnimf = dlopen ("libnimf.so.1", RTLD_LAZY);
libglib = dlopen ("libglib-2.0.so.0", RTLD_LAZY);
libgobject = dlopen ("libgobject-2.0.so.0", RTLD_LAZY);
libgio = dlopen ("libgio-2.0.so.0", RTLD_LAZY);
if (libnimf)
{
nimf_api = new NimfAPI;
nimf_api->im_new = reinterpret_cast<NimfIM* (*) ()> (dlsym (libnimf, "nimf_im_new"));
nimf_api->im_focus_in = reinterpret_cast<void (*) (NimfIM*)> (dlsym (libnimf, "nimf_im_focus_in"));
nimf_api->im_focus_out = reinterpret_cast<void (*) (NimfIM*)> (dlsym (libnimf, "nimf_im_focus_out"));
nimf_api->im_reset = reinterpret_cast<void (*) (NimfIM*)> (dlsym (libnimf, "nimf_im_reset"));
nimf_api->im_filter_event = reinterpret_cast<gboolean (*) (NimfIM*, NimfEvent*)> (dlsym (libnimf, "nimf_im_filter_event"));
nimf_api->im_get_preedit_string = reinterpret_cast<void (*) (NimfIM*, gchar**, NimfPreeditAttr***, gint*)> (dlsym (libnimf, "nimf_im_get_preedit_string"));
nimf_api->im_set_cursor_location = reinterpret_cast<void (*) (NimfIM*, const NimfRectangle*)> (dlsym (libnimf, "nimf_im_set_cursor_location"));
nimf_api->im_set_use_preedit = reinterpret_cast<void (*) (NimfIM*, gboolean)> (dlsym (libnimf, "nimf_im_set_use_preedit"));
nimf_api->im_set_surrounding = reinterpret_cast<void (*) (NimfIM*, const char*, gint, gint)> (dlsym (libnimf, "nimf_im_set_surrounding"));
nimf_api->event_new = reinterpret_cast<NimfEvent * (*) (NimfEventType)> (dlsym (libnimf, "nimf_event_new"));
nimf_api->event_free = reinterpret_cast<void (*) (NimfEvent*)> (dlsym (libnimf, "nimf_event_free"));
nimf_api->preedit_attr_freev = reinterpret_cast<void (*) (NimfPreeditAttr**)> (dlsym (libnimf, "nimf_preedit_attr_freev"));
}
if (libglib)
{
glib_api = new GLibAPI;
glib_api->free = reinterpret_cast<void (*) (gpointer)> (dlsym (libglib, "g_free"));
}
if (libgobject)
{
gobject_api = new GObjectAPI;
gobject_api->signal_connect_data = reinterpret_cast<gulong (*) (gpointer, const gchar*, GCallback, gpointer, GClosureNotify, GConnectFlags)> (dlsym (libgobject, "g_signal_connect_data"));
gobject_api->signal_emit_by_name = reinterpret_cast<void (*) (gpointer, const gchar*, ...)> (dlsym (libgobject, "g_signal_emit_by_name"));
gobject_api->object_unref = reinterpret_cast<void (*) (gpointer)> (dlsym (libgobject, "g_object_unref"));
}
if (libgio)
{
gio_api = new GIOAPI;
gio_api->settings_new = reinterpret_cast<GSettings* (*) (const gchar*)> (dlsym (libgio, "g_settings_new"));
gio_api->settings_get_boolean = reinterpret_cast<gboolean (*) (GSettings*, const gchar*)> (dlsym (libgio, "g_settings_get_boolean"));
gio_api->settings_schema_source_get_default
= reinterpret_cast<GSettingsSchemaSource* (*) ()> (dlsym (libgio, "g_settings_schema_source_get_default"));
gio_api->settings_schema_source_lookup
= reinterpret_cast<GSettingsSchema* (*) (GSettingsSchemaSource *, const gchar*, gboolean)> (dlsym (libgio, "g_settings_schema_source_lookup"));
gio_api->settings_schema_unref = reinterpret_cast<void (*) (GSettingsSchema*)> (dlsym (libgio, "g_settings_schema_unref"));
}
#endif
}
~NimfInputContextPlugin ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
#ifdef USE_DLFCN
delete nimf_api;
delete glib_api;
delete gobject_api;
delete gio_api;
nimf_api = NULL;
glib_api = NULL;
gobject_api = NULL;
gio_api = NULL;
if (libnimf)
{
dlclose (libnimf);
libnimf = NULL;
}
if (libglib)
{
dlclose (libglib);
libglib = NULL;
}
if (libgobject)
{
dlclose (libgobject);
libgobject = NULL;
}
if (libgio)
{
dlclose (libgio);
libgio = NULL;
}
#endif
}
virtual QStringList keys () const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return QStringList () << "nimf";
}
virtual QPlatformInputContext *create (const QString &key,
const QStringList &paramList)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return new NimfInputContext ();
}
};
#include "im-nimf-qt5.moc"

View File

@@ -0,0 +1,3 @@
{
"Keys": [ "nimf" ]
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.nimf.clients.qt5"
path="/org/nimf/clients/qt5/" gettext-domain="nimf">
<key type="s" name="hidden-schema-name">
<default l10n="messages">'Qt5'</default>
<summary>schema name for nimf-settings</summary>
<description>This key is intended for nimf-settings.</description>
</key>
<key type="b" name="reset-on-mouse-button-press">
<default>true</default>
<summary>Reset when clicking the mouse button</summary>
<description>Reset when clicking the mouse button</description>
</key>
</schema>
</schemalist>

View File

@@ -0,0 +1,42 @@
gsettings_SCHEMAS = org.nimf.clients.qt6.gschema.xml
@GSETTINGS_RULES@
qt6_im_moduledir = $(QT6_IM_MODULE_DIR)
qt6_im_module_LTLIBRARIES = libqt6im-nimf.la
BUILT_SOURCES = im-nimf-qt6.moc
libqt6im_nimf_la_SOURCES = im-nimf-qt6.cpp $(BUILT_SOURCES)
libqt6im_nimf_la_CXXFLAGS = \
$(EXTRA_CFLAGS) \
$(LIBNIMF_DEPS_CFLAGS) \
-I$(top_srcdir)/libnimf \
-DG_LOG_DOMAIN=\"nimf\" \
-DNIMF_COMPILATION \
$(IM_NIMF_QT6_DEPS_CFLAGS) \
-I$(QT6_CORE_PRIVATE_INCLUDE_PATH) \
-I$(QT6_GUI_PRIVATE_INCLUDE_PATH) \
-I/usr/include/x86_64-linux-gnu/qt6/QtGui/6.4.2/QtGui/qpa \
-DQT_NO_KEYWORDS \
-fPIC \
-std=c++17
libqt6im_nimf_la_LDFLAGS = -avoid-version -module \
$(IM_NIMF_QT6_DEPS_LIBS) \
$(LIBNIMF_DEPS_LIBS)
libqt6im_nimf_la_LIBADD = $(top_builddir)/libnimf/libnimf.la
im-nimf-qt6.moc: im-nimf-qt6.cpp
$(AM_V_GEN) $(QT6_MOC) -I $(QT6_CORE_PRIVATE_INCLUDE_PATH) \
-I $(QT6_GUI_PRIVATE_INCLUDE_PATH) im-nimf-qt6.cpp \
-o im-nimf-qt6.moc
install-data-hook:
chmod -x $(DESTDIR)$(qt6_im_moduledir)/libqt6im-nimf.so
rm -f $(DESTDIR)$(qt6_im_moduledir)/libqt6im-nimf.la
uninstall-hook:
rm -f $(DESTDIR)$(qt6_im_moduledir)/libqt6im-nimf.so
-rmdir -p $(DESTDIR)$(qt6_im_moduledir)
DISTCLEANFILES = Makefile.in $(BUILT_SOURCES)

View File

@@ -0,0 +1,868 @@
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/*
* im-nimf-qt6.cpp
* This file is part of Nimf.
*
* Copyright (C) 2024 Kevin Kim <chaeya@gmail.com>
*
* Nimf 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 3 of the License, or
* (at your option) any later version.
*
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
*/
#include <QTextFormat>
#include <QInputMethodEvent>
#include <QtGui/qpa/qplatforminputcontext.h>
#include <QtGui/qpa/qplatforminputcontextplugin_p.h>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include "nimf-im.h"
#include <gio/gio.h>
#ifdef USE_DLFCN
#include <dlfcn.h>
typedef struct
{
NimfIM * (* im_new) (void);
void (* im_focus_in) (NimfIM *im);
void (* im_focus_out) (NimfIM *im);
void (* im_reset) (NimfIM *im);
gboolean (* im_filter_event) (NimfIM *im,
NimfEvent *event);
void (* im_get_preedit_string) (NimfIM *im,
gchar **str,
NimfPreeditAttr ***attrs,
gint *cursor_pos);
void (* im_set_cursor_location) (NimfIM *im,
const NimfRectangle *area);
void (* im_set_use_preedit) (NimfIM *im,
gboolean use_preedit);
void (* im_set_surrounding) (NimfIM *im,
const char *text,
gint len,
gint cursor_index);
NimfEvent * (* event_new) (NimfEventType type);
void (* event_free) (NimfEvent *event);
void (* preedit_attr_freev) (NimfPreeditAttr **attrs);
} NimfAPI;
typedef struct
{
void (* free) (gpointer mem);
} GLibAPI;
typedef struct
{
gulong (* signal_connect_data) (gpointer instance,
const gchar *detailed_signal,
GCallback c_handler,
gpointer data,
GClosureNotify destroy_data,
GConnectFlags connect_flags);
void (* signal_emit_by_name) (gpointer instance,
const gchar *detailed_signal,
...);
void (* object_unref) (gpointer object);
} GObjectAPI;
typedef struct
{
GSettings * (* settings_new) (const gchar *schema_id);
gboolean (* settings_get_boolean) (GSettings *settings,
const gchar *key);
GSettingsSchemaSource *
(* settings_schema_source_get_default) (void);
GSettingsSchema *
(* settings_schema_source_lookup)
(GSettingsSchemaSource *source,
const gchar *schema_id,
gboolean recursive);
void (* settings_schema_unref) (GSettingsSchema *schema);
} GIOAPI;
void *libnimf = NULL;
void *libglib = NULL;
void *libgobject = NULL;
void *libgio = NULL;
NimfAPI *nimf_api = NULL;
GLibAPI *glib_api = NULL;
GObjectAPI *gobject_api = NULL;
GIOAPI *gio_api = NULL;
#endif
class NimfEventHandler : public QObject
{
Q_OBJECT
public:
NimfEventHandler(NimfIM *im)
{
m_im = im;
};
~NimfEventHandler()
{};
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
NimfIM *m_im;
};
bool NimfEventHandler::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress)
#ifndef USE_DLFCN
nimf_im_reset (m_im);
#else
nimf_api->im_reset (m_im);
#endif
return QObject::eventFilter(obj, event);
}
class NimfInputContext : public QPlatformInputContext
{
Q_OBJECT
public:
NimfInputContext ();
~NimfInputContext ();
virtual bool isValid () const;
virtual void reset ();
virtual void commit ();
virtual void update (Qt::InputMethodQueries);
virtual void invokeAction (QInputMethod::Action, int cursorPosition);
virtual bool filterEvent (const QEvent *event);
virtual QRectF keyboardRect () const;
virtual bool isAnimating () const;
virtual void showInputPanel ();
virtual void hideInputPanel ();
virtual bool isInputPanelVisible () const;
virtual QLocale locale () const;
virtual Qt::LayoutDirection inputDirection() const;
virtual void setFocusObject (QObject *object);
// nimf signal callbacks
static void on_preedit_start (NimfIM *im,
gpointer user_data);
static void on_preedit_end (NimfIM *im,
gpointer user_data);
static void on_preedit_changed (NimfIM *im,
gpointer user_data);
static void on_commit (NimfIM *im,
const gchar *text,
gpointer user_data);
static gboolean on_retrieve_surrounding (NimfIM *im,
gpointer user_data);
static gboolean on_delete_surrounding (NimfIM *im,
gint offset,
gint n_chars,
gpointer user_data);
static void on_beep (NimfIM *im,
gpointer user_data);
// settings
static void on_changed_reset_on_mouse_button_press (GSettings *settings,
gchar *key,
gpointer user_data);
private:
NimfIM *m_im;
GSettings *m_settings;
NimfEventHandler *m_handler;
NimfRectangle m_cursor_area;
};
/* nimf signal callbacks */
void
NimfInputContext::on_preedit_start (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
void
NimfInputContext::on_preedit_end (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
void
NimfInputContext::on_preedit_changed (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
NimfPreeditAttr **preedit_attrs;
gchar *str;
gint cursor_pos;
gint offset = 0;
guint i, j, len;
#ifndef USE_DLFCN
nimf_im_get_preedit_string (im, &str, &preedit_attrs, &cursor_pos);
#else
nimf_api->im_get_preedit_string (im, &str, &preedit_attrs, &cursor_pos);
#endif
QString preeditText = QString::fromUtf8 (str);
#ifndef USE_DLFCN
g_free (str);
#else
glib_api->free (str);
#endif
QList <QInputMethodEvent::Attribute> attrs;
for (i = 0; i < (guint) preeditText.size(); i++)
{
if (preeditText.at(i).isLowSurrogate())
{
offset++;
continue;
}
QTextCharFormat format;
for (j = 0; preedit_attrs[j]; j++)
{
switch (preedit_attrs[j]->type)
{
case NIMF_PREEDIT_ATTR_HIGHLIGHT:
if (preedit_attrs[j]->start_index <= i - offset &&
preedit_attrs[j]->end_index > i - offset)
{
format.setBackground(Qt::green);
format.setForeground(Qt::black);
}
break;
case NIMF_PREEDIT_ATTR_UNDERLINE:
if (preedit_attrs[j]->start_index <= i - offset &&
preedit_attrs[j]->end_index > i - offset)
format.setUnderlineStyle(QTextCharFormat::DashUnderline);
break;
default:
break;
}
}
preeditText.at(i).isHighSurrogate() ? len = 2 : len = 1;
QInputMethodEvent::Attribute attr (QInputMethodEvent::TextFormat,
i, len, format);
attrs << attr;
}
#ifndef USE_DLFCN
nimf_preedit_attr_freev (preedit_attrs);
#else
nimf_api->preedit_attr_freev (preedit_attrs);
#endif
// cursor attribute
attrs << QInputMethodEvent::Attribute (QInputMethodEvent::Cursor,
cursor_pos + offset, true, 0);
QInputMethodEvent event (preeditText, attrs);
QObject *object = qApp->focusObject ();
if (!object)
return;
QCoreApplication::sendEvent (object, &event);
}
void
NimfInputContext::on_commit (NimfIM *im,
const gchar *text,
gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QString str = QString::fromUtf8 (text);
QInputMethodEvent event;
event.setCommitString (str);
QObject *obj = qApp->focusObject();
if (!obj)
return;
QCoreApplication::sendEvent (obj, &event);
}
gboolean
NimfInputContext::on_retrieve_surrounding (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QObject *object = qApp->focusObject();
if (!object)
return FALSE;
NimfInputContext *context = static_cast<NimfInputContext *>(user_data);
QInputMethodQueryEvent surrounding_query (Qt::ImSurroundingText);
QInputMethodQueryEvent position_query (Qt::ImCursorPosition);
QCoreApplication::sendEvent (object, &surrounding_query);
QCoreApplication::sendEvent (object, &position_query);
QString string = surrounding_query.value (Qt::ImSurroundingText).toString();
uint pos = position_query.value (Qt::ImCursorPosition).toUInt();
#ifndef USE_DLFCN
nimf_im_set_surrounding (context->m_im,
string.toUtf8().constData(), -1, pos);
#else
nimf_api->im_set_surrounding (context->m_im,
string.toUtf8().constData(), -1, pos);
#endif
return TRUE;
}
gboolean
NimfInputContext::on_delete_surrounding (NimfIM *im,
gint offset,
gint n_chars,
gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QObject *object = qApp->focusObject();
if (!object)
return FALSE;
QInputMethodEvent event;
event.setCommitString ("", offset, n_chars);
QCoreApplication::sendEvent (object, &event);
return TRUE;
}
void
NimfInputContext::on_beep (NimfIM *im, gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
QApplication::beep();
}
void
NimfInputContext::on_changed_reset_on_mouse_button_press (GSettings *settings,
gchar *key,
gpointer user_data)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
NimfInputContext *context = static_cast<NimfInputContext *>(user_data);
#ifndef USE_DLFCN
if (g_settings_get_boolean (settings, key))
#else
if (gio_api->settings_get_boolean (settings, key))
#endif
{
if (context->m_handler == NULL)
{
context->m_handler = new NimfEventHandler(context->m_im);
qApp->installEventFilter(context->m_handler);
}
}
else
{
if (context->m_handler)
{
qApp->removeEventFilter(context->m_handler);
delete context->m_handler;
context->m_handler = NULL;
}
}
}
NimfInputContext::NimfInputContext ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
m_im = NULL;
m_settings = NULL;
m_handler = NULL;
m_cursor_area.x = 0;
m_cursor_area.y = 0;
m_cursor_area.width = 0;
m_cursor_area.height = 0;
#ifndef USE_DLFCN
m_im = nimf_im_new ();
m_settings = g_settings_new ("org.nimf.clients.qt6");
g_signal_connect (m_im, "preedit-start",
G_CALLBACK (NimfInputContext::on_preedit_start), this);
g_signal_connect (m_im, "preedit-end",
G_CALLBACK (NimfInputContext::on_preedit_end), this);
g_signal_connect (m_im, "preedit-changed",
G_CALLBACK (NimfInputContext::on_preedit_changed), this);
g_signal_connect (m_im, "commit",
G_CALLBACK (NimfInputContext::on_commit), this);
g_signal_connect (m_im, "retrieve-surrounding",
G_CALLBACK (NimfInputContext::on_retrieve_surrounding),
this);
g_signal_connect (m_im, "delete-surrounding",
G_CALLBACK (NimfInputContext::on_delete_surrounding),
this);
g_signal_connect (m_im, "beep",
G_CALLBACK (NimfInputContext::on_beep), this);
g_signal_connect (m_settings, "changed::reset-on-mouse-button-press",
G_CALLBACK (NimfInputContext::on_changed_reset_on_mouse_button_press), this);
g_signal_emit_by_name (m_settings, "changed::reset-on-mouse-button-press",
"reset-on-mouse-button-press");
#else
if (!nimf_api || !glib_api || !gobject_api || !gio_api)
{
qWarning("The libraries for nimf are not ready.");
return;
}
GSettingsSchemaSource *source;
GSettingsSchema *schema;
source = gio_api->settings_schema_source_get_default ();
schema = gio_api->settings_schema_source_lookup (source, "org.nimf.clients.qt6", TRUE);
if (schema == NULL)
{
qWarning("org.nimf.clients.qt6 schema is not found.");
return;
}
gio_api->settings_schema_unref (schema);
m_im = nimf_api->im_new ();
m_settings = gio_api->settings_new ("org.nimf.clients.qt6");
gobject_api->signal_connect_data (m_im, "preedit-start",
G_CALLBACK (NimfInputContext::on_preedit_start), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "preedit-end",
G_CALLBACK (NimfInputContext::on_preedit_end), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "preedit-changed",
G_CALLBACK (NimfInputContext::on_preedit_changed), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "commit",
G_CALLBACK (NimfInputContext::on_commit), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "retrieve-surrounding",
G_CALLBACK (NimfInputContext::on_retrieve_surrounding),
this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "delete-surrounding",
G_CALLBACK (NimfInputContext::on_delete_surrounding),
this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_im, "beep",
G_CALLBACK (NimfInputContext::on_beep), this, NULL, (GConnectFlags) 0);
gobject_api->signal_connect_data (m_settings, "changed::reset-on-mouse-button-press",
G_CALLBACK (NimfInputContext::on_changed_reset_on_mouse_button_press), this, NULL, (GConnectFlags) 0);
gobject_api->signal_emit_by_name (m_settings, "changed::reset-on-mouse-button-press",
"reset-on-mouse-button-press");
#endif
}
NimfInputContext::~NimfInputContext ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (m_handler)
delete m_handler;
if (m_im)
#ifndef USE_DLFCN
g_object_unref (m_im);
#else
gobject_api->object_unref (m_im);
#endif
if (m_settings)
#ifndef USE_DLFCN
g_object_unref (m_settings);
#else
gobject_api->object_unref (m_settings);
#endif
}
bool
NimfInputContext::isValid () const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (m_im == NULL)
return false;
return true;
}
void
NimfInputContext::reset ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_im_reset (m_im);
#else
nimf_api->im_reset (m_im);
#endif
}
void
NimfInputContext::commit ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
nimf_im_reset (m_im);
#else
nimf_api->im_reset (m_im);
#endif
}
void
NimfInputContext::update (Qt::InputMethodQueries queries)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (queries & Qt::ImCursorRectangle)
{
QWidget *widget = qApp->focusWidget ();
if (widget == NULL)
return;
QRect rect = widget->inputMethodQuery(Qt::ImCursorRectangle).toRect();
QPoint point = widget->mapToGlobal (QPoint (0, 0));
rect.translate (point);
if (m_cursor_area.x != rect.x () ||
m_cursor_area.y != rect.y () ||
m_cursor_area.width != rect.width () ||
m_cursor_area.height != rect.height ())
{
m_cursor_area.x = rect.x ();
m_cursor_area.y = rect.y ();
m_cursor_area.width = rect.width ();
m_cursor_area.height = rect.height ();
#ifndef USE_DLFCN
nimf_im_set_cursor_location (m_im, &m_cursor_area);
#else
nimf_api->im_set_cursor_location (m_im, &m_cursor_area);
#endif
}
}
}
void
NimfInputContext::invokeAction(QInputMethod::Action, int cursorPosition)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
bool
NimfInputContext::filterEvent (const QEvent *event)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (G_UNLIKELY (!qApp->focusObject() || !inputMethodAccepted()))
return false;
gboolean retval;
const QKeyEvent *key_event = static_cast<const QKeyEvent *>( event );
NimfEvent *nimf_event;
NimfEventType type = NIMF_EVENT_NOTHING;
switch (event->type ())
{
#undef KeyPress
case QEvent::KeyPress:
type = NIMF_EVENT_KEY_PRESS;
break;
#undef KeyRelease
case QEvent::KeyRelease:
type = NIMF_EVENT_KEY_RELEASE;
break;
default:
return false;
}
#ifndef USE_DLFCN
nimf_event = nimf_event_new (type);
#else
nimf_event = nimf_api->event_new (type);
#endif
nimf_event->key.state = key_event->nativeModifiers ();
nimf_event->key.keyval = key_event->nativeVirtualKey ();
nimf_event->key.hardware_keycode = key_event->nativeScanCode ();
#ifndef USE_DLFCN
retval = nimf_im_filter_event (m_im, nimf_event);
nimf_event_free (nimf_event);
#else
retval = nimf_api->im_filter_event (m_im, nimf_event);
nimf_api->event_free (nimf_event);
#endif
return retval;
}
QRectF
NimfInputContext::keyboardRect() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return QRectF ();
}
bool
NimfInputContext::isAnimating() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return false;
}
void
NimfInputContext::showInputPanel()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
void
NimfInputContext::hideInputPanel()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
}
bool
NimfInputContext::isInputPanelVisible() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return false;
}
QLocale
NimfInputContext::locale() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return QLocale ();
}
Qt::LayoutDirection
NimfInputContext::inputDirection() const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return Qt::LayoutDirection ();
}
void
NimfInputContext::setFocusObject (QObject *object)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
if (!object || !inputMethodAccepted())
#ifndef USE_DLFCN
nimf_im_focus_out (m_im);
#else
nimf_api->im_focus_out (m_im);
#endif
QPlatformInputContext::setFocusObject (object);
if (object && inputMethodAccepted())
#ifndef USE_DLFCN
nimf_im_focus_in (m_im);
#else
nimf_api->im_focus_in (m_im);
#endif
update (Qt::ImCursorRectangle);
}
/*
* class NimfInputContextPlugin
*/
class NimfInputContextPlugin : public QPlatformInputContextPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID
QPlatformInputContextFactoryInterface_iid
FILE "./nimf.json")
public:
NimfInputContextPlugin ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
#ifdef USE_DLFCN
libnimf = dlopen ("libnimf.so.1", RTLD_LAZY);
libglib = dlopen ("libglib-2.0.so.0", RTLD_LAZY);
libgobject = dlopen ("libgobject-2.0.so.0", RTLD_LAZY);
libgio = dlopen ("libgio-2.0.so.0", RTLD_LAZY);
if (libnimf)
{
nimf_api = new NimfAPI;
nimf_api->im_new = reinterpret_cast<NimfIM* (*) ()> (dlsym (libnimf, "nimf_im_new"));
nimf_api->im_focus_in = reinterpret_cast<void (*) (NimfIM*)> (dlsym (libnimf, "nimf_im_focus_in"));
nimf_api->im_focus_out = reinterpret_cast<void (*) (NimfIM*)> (dlsym (libnimf, "nimf_im_focus_out"));
nimf_api->im_reset = reinterpret_cast<void (*) (NimfIM*)> (dlsym (libnimf, "nimf_im_reset"));
nimf_api->im_filter_event = reinterpret_cast<gboolean (*) (NimfIM*, NimfEvent*)> (dlsym (libnimf, "nimf_im_filter_event"));
nimf_api->im_get_preedit_string = reinterpret_cast<void (*) (NimfIM*, gchar**, NimfPreeditAttr***, gint*)> (dlsym (libnimf, "nimf_im_get_preedit_string"));
nimf_api->im_set_cursor_location = reinterpret_cast<void (*) (NimfIM*, const NimfRectangle*)> (dlsym (libnimf, "nimf_im_set_cursor_location"));
nimf_api->im_set_use_preedit = reinterpret_cast<void (*) (NimfIM*, gboolean)> (dlsym (libnimf, "nimf_im_set_use_preedit"));
nimf_api->im_set_surrounding = reinterpret_cast<void (*) (NimfIM*, const char*, gint, gint)> (dlsym (libnimf, "nimf_im_set_surrounding"));
nimf_api->event_new = reinterpret_cast<NimfEvent * (*) (NimfEventType)> (dlsym (libnimf, "nimf_event_new"));
nimf_api->event_free = reinterpret_cast<void (*) (NimfEvent*)> (dlsym (libnimf, "nimf_event_free"));
nimf_api->preedit_attr_freev = reinterpret_cast<void (*) (NimfPreeditAttr**)> (dlsym (libnimf, "nimf_preedit_attr_freev"));
}
if (libglib)
{
glib_api = new GLibAPI;
glib_api->free = reinterpret_cast<void (*) (gpointer)> (dlsym (libglib, "g_free"));
}
if (libgobject)
{
gobject_api = new GObjectAPI;
gobject_api->signal_connect_data = reinterpret_cast<gulong (*) (gpointer, const gchar*, GCallback, gpointer, GClosureNotify, GConnectFlags)> (dlsym (libgobject, "g_signal_connect_data"));
gobject_api->signal_emit_by_name = reinterpret_cast<void (*) (gpointer, const gchar*, ...)> (dlsym (libgobject, "g_signal_emit_by_name"));
gobject_api->object_unref = reinterpret_cast<void (*) (gpointer)> (dlsym (libgobject, "g_object_unref"));
}
if (libgio)
{
gio_api = new GIOAPI;
gio_api->settings_new = reinterpret_cast<GSettings* (*) (const gchar*)> (dlsym (libgio, "g_settings_new"));
gio_api->settings_get_boolean = reinterpret_cast<gboolean (*) (GSettings*, const gchar*)> (dlsym (libgio, "g_settings_get_boolean"));
gio_api->settings_schema_source_get_default
= reinterpret_cast<GSettingsSchemaSource* (*) ()> (dlsym (libgio, "g_settings_schema_source_get_default"));
gio_api->settings_schema_source_lookup
= reinterpret_cast<GSettingsSchema* (*) (GSettingsSchemaSource *, const gchar*, gboolean)> (dlsym (libgio, "g_settings_schema_source_lookup"));
gio_api->settings_schema_unref = reinterpret_cast<void (*) (GSettingsSchema*)> (dlsym (libgio, "g_settings_schema_unref"));
}
#endif
}
~NimfInputContextPlugin ()
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
#ifdef USE_DLFCN
delete nimf_api;
delete glib_api;
delete gobject_api;
delete gio_api;
nimf_api = NULL;
glib_api = NULL;
gobject_api = NULL;
gio_api = NULL;
if (libnimf)
{
dlclose (libnimf);
libnimf = NULL;
}
if (libglib)
{
dlclose (libglib);
libglib = NULL;
}
if (libgobject)
{
dlclose (libgobject);
libgobject = NULL;
}
if (libgio)
{
dlclose (libgio);
libgio = NULL;
}
#endif
}
virtual QStringList keys () const
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return QStringList () << "nimf";
}
virtual QPlatformInputContext *create (const QString &key,
const QStringList &paramList)
{
#ifndef USE_DLFCN
g_debug (G_STRLOC ": %s", G_STRFUNC);
#endif
return new NimfInputContext ();
}
};
#include "im-nimf-qt6.moc"

View File

@@ -0,0 +1,3 @@
{
"Keys": [ "nimf" ]
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.nimf.clients.qt6"
path="/org/nimf/clients/qt6/" gettext-domain="nimf">
<key type="s" name="hidden-schema-name">
<default l10n="messages">'Qt6'</default>
<summary>schema name for nimf-settings</summary>
<description>This key is intended for nimf-settings.</description>
</key>
<key type="b" name="reset-on-mouse-button-press">
<default>true</default>
<summary>Reset when clicking the mouse button</summary>
<description>Reset when clicking the mouse button</description>
</key>
</schema>
</schemalist>