31e3c61
From 59944ddbfe915f195e757c509246b597048116cf Mon Sep 17 00:00:00 2001
ec611b2
From: fujiwarat <takao.fujiwara1@gmail.com>
31e3c61
Date: Sat, 25 Nov 2023 13:42:31 +0900
52531c0
Subject: [PATCH] client/wayland: Implement preedit color in Plasma Wayland
52531c0
52531c0
Wayland input-method protocol version 1 supports the preedit style
52531c0
with text-input protocol version 1 in Plasma Wayland.
52531c0
GNOME Wayland uses text-input version 3 which deletes the preedit style.
52531c0
52531c0
Now IBus supports the preedit color for anthy, hangul, table,
52531c0
typing-booster.
52531c0
52531c0
This change now also supports
52531c0
ibus_engine_update_preedit_text_with_mode()
52531c0
52531c0
Rf. https://github.com/ibus/ibus/wiki/Wayland-Colors
52531c0
52531c0
BUG=rhbz#2237486
52531c0
---
52531c0
 client/wayland/Makefile.am                    |   1 +
31e3c61
 client/wayland/ibuswaylandim.c                | 204 ++++-
52531c0
 .../text-input-unstable-v1-client-protocol.h  | 847 ++++++++++++++++++
52531c0
 src/ibusattribute.h                           |  52 +-
31e3c61
 4 files changed, 1101 insertions(+), 3 deletions(-)
52531c0
 create mode 100644 client/wayland/text-input-unstable-v1-client-protocol.h
52531c0
52531c0
diff --git a/client/wayland/Makefile.am b/client/wayland/Makefile.am
52531c0
index 7e8d18af..94e357b4 100644
52531c0
--- a/client/wayland/Makefile.am
52531c0
+++ b/client/wayland/Makefile.am
52531c0
@@ -31,6 +31,7 @@ DISTCLEANFILES =
52531c0
 protocol_sources = \
52531c0
     input-method-unstable-v1-client-protocol.h \
52531c0
     input-method-unstable-v1-protocol.c \
52531c0
+    text-input-unstable-v1-client-protocol.h \
52531c0
     $(NULL)
52531c0
 
52531c0
 ibus_wayland_SOURCES = \
52531c0
diff --git a/client/wayland/ibuswaylandim.c b/client/wayland/ibuswaylandim.c
31e3c61
index 8f938288..9e8f651e 100644
52531c0
--- a/client/wayland/ibuswaylandim.c
52531c0
+++ b/client/wayland/ibuswaylandim.c
52531c0
@@ -32,6 +32,7 @@
52531c0
 #include <xkbcommon/xkbcommon.h>
52531c0
 
52531c0
 #include "input-method-unstable-v1-client-protocol.h"
52531c0
+#include "text-input-unstable-v1-client-protocol.h"
52531c0
 #include "ibuswaylandim.h"
52531c0
 
52531c0
 enum {
52531c0
@@ -58,6 +59,7 @@ struct _IBusWaylandIMPrivate
52531c0
     IBusInputContext *ibuscontext;
52531c0
     IBusText *preedit_text;
52531c0
     guint preedit_cursor_pos;
52531c0
+    guint preedit_mode;
52531c0
     IBusModifierType modifiers;
52531c0
 
52531c0
     struct xkb_context *xkb_context;
31e3c61
@@ -266,12 +268,204 @@ _context_forward_key_event_cb (IBusInputContext *context,
52531c0
 }
52531c0
 
52531c0
 
52531c0
+/**
52531c0
+ * ibus_wayland_im_update_preedit_style:
52531c0
+ * @wlim: An #IBusWaylandIM
52531c0
+ *
52531c0
+ * Convert RGB values to IBusAttrPreedit at first.
52531c0
+ * Convert IBusAttrPreedit to zwp_text_input_v1_preedit_style at second.
52531c0
+ *
52531c0
+ * RF. https://github.com/ibus/ibus/wiki/Wayland-Colors
52531c0
+ */
52531c0
+static void
52531c0
+ibus_wayland_im_update_preedit_style (IBusWaylandIM *wlim)
52531c0
+{
52531c0
+    IBusWaylandIMPrivate *priv;
52531c0
+    IBusAttrList *attrs;
52531c0
+    guint i;
52531c0
+    const char *str;
52531c0
+    uint32_t whole_wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_DEFAULT;
31e3c61
+    uint32_t prev_start = 0;
31e3c61
+    uint32_t prev_end = 0;
52531c0
+
52531c0
+    g_return_if_fail (IBUS_IS_WAYLAND_IM (wlim));
52531c0
+    priv = ibus_wayland_im_get_instance_private (wlim);
52531c0
+    if (!priv->preedit_text)
52531c0
+        return;
52531c0
+    attrs = priv->preedit_text->attrs;
52531c0
+    if (!attrs)
52531c0
+        return;
52531c0
+    for (i = 0; ; i++) {
52531c0
+        IBusAttribute *attr = ibus_attr_list_get (attrs, i);
52531c0
+        IBusAttrPreedit istyle = IBUS_ATTR_PREEDIT_DEFAULT;
52531c0
+        uint32_t wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_DEFAULT;
52531c0
+        uint32_t start, end;
52531c0
+        if (attr == NULL)
52531c0
+                break;
52531c0
+        switch (attr->type) {
52531c0
+        case IBUS_ATTR_TYPE_UNDERLINE:
52531c0
+            istyle = IBUS_ATTR_PREEDIT_WHOLE;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_TYPE_FOREGROUND:
52531c0
+            switch (attr->value) {
52531c0
+            case 0x7F7F7F: /* typing-booster */
52531c0
+                istyle = IBUS_ATTR_PREEDIT_PREDICTION;
52531c0
+                break;
52531c0
+            case 0xF90F0F: /* table */
52531c0
+                istyle = IBUS_ATTR_PREEDIT_PREFIX;
52531c0
+                break;
52531c0
+            case 0x1EDC1A: /* table */
52531c0
+                istyle = IBUS_ATTR_PREEDIT_SUFFIX;
52531c0
+                break;
52531c0
+            case 0xA40000: /* typing-booster, table */
52531c0
+                istyle = IBUS_ATTR_PREEDIT_ERROR_SPELLING;
52531c0
+                break;
52531c0
+            case 0xFF00FF: /* typing-booster */
52531c0
+                istyle = IBUS_ATTR_PREEDIT_ERROR_COMPOSE;
52531c0
+                break;
52531c0
+            case 0x0: /* Japanese */
52531c0
+            case 0xFF000000:
52531c0
+                break;
52531c0
+            case 0xFFFFFF: /* hangul */
52531c0
+            case 0xFFFFFFFF:
52531c0
+                istyle = IBUS_ATTR_PREEDIT_SELECTION;
52531c0
+                break;
52531c0
+            default: /* Custom */
52531c0
+                istyle = IBUS_ATTR_PREEDIT_NONE;
52531c0
+            }
52531c0
+            break;
52531c0
+        case IBUS_ATTR_TYPE_BACKGROUND:
52531c0
+            switch (attr->value) {
52531c0
+            case 0xC8C8F0: /* Japanese */
52531c0
+            case 0xFFC8C8F0:
52531c0
+                istyle = IBUS_ATTR_PREEDIT_SELECTION;
52531c0
+                break;
52531c0
+            default:; /* Custom */
52531c0
+            }
52531c0
+            break;
52531c0
+        default:
52531c0
+            istyle = IBUS_ATTR_PREEDIT_NONE;
52531c0
+        }
52531c0
+        switch (istyle) {
52531c0
+        case IBUS_ATTR_PREEDIT_NONE:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_NONE;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_PREEDIT_WHOLE:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_UNDERLINE;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_PREEDIT_SELECTION:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_SELECTION;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_PREEDIT_PREDICTION:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_INACTIVE;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_PREEDIT_PREFIX:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_PREEDIT_SUFFIX:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_INACTIVE;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_PREEDIT_ERROR_SPELLING:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_INCORRECT;
52531c0
+            break;
52531c0
+        case IBUS_ATTR_PREEDIT_ERROR_COMPOSE:
52531c0
+            wstyle = ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_INCORRECT;
52531c0
+            break;
52531c0
+        default:;
52531c0
+        }
52531c0
+        if (wstyle == ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_DEFAULT)
52531c0
+            continue;
52531c0
+        str = priv->preedit_text->text;
52531c0
+        start = g_utf8_offset_to_pointer (str, attr->start_index) - str;
52531c0
+        end = g_utf8_offset_to_pointer (str, attr->end_index) - str;
52531c0
+        /* Double styles cannot be applied likes the underline and
52531c0
+         * preedit color. */
52531c0
+        if (start == 0 && strlen (str) == end &&
52531c0
+            (i > 0 || ibus_attr_list_get (attrs, i + 1))) {
52531c0
+            whole_wstyle = wstyle;
52531c0
+            continue;
52531c0
+        }
31e3c61
+        if (end < prev_start) {
31e3c61
+            if (priv->log) {
31e3c61
+                fprintf (priv->log,
31e3c61
+                         "Reverse order is not supported in end %d for %s "
31e3c61
+                         "against start %d.\n", end, str, prev_start);
31e3c61
+                fflush (priv->log);
31e3c61
+            }
31e3c61
+            continue;
31e3c61
+        }
31e3c61
+        if (prev_end > end) {
31e3c61
+            if (priv->log) {
31e3c61
+                fprintf (priv->log,
31e3c61
+                         "Nested styles are not supported in end %d for %s "
31e3c61
+                         "against end %d.\n", end, str, prev_end);
31e3c61
+                fflush (priv->log);
31e3c61
+            }
31e3c61
+            continue;
31e3c61
+        }
31e3c61
+        if (prev_end > start && prev_start >= start)
31e3c61
+            start = prev_end;
31e3c61
+        if (start >= end) {
31e3c61
+            if (priv->log) {
31e3c61
+                fprintf (priv->log, "Wrong start %d and end %d for %s.\n",
31e3c61
+                         start, end, str);
31e3c61
+                fflush (priv->log);
31e3c61
+            }
52531c0
+            return;
52531c0
+        }
52531c0
+        zwp_input_method_context_v1_preedit_styling (priv->context,
52531c0
+                                                     start,
52531c0
+                                                     end - start,
52531c0
+                                                     wstyle);
31e3c61
+        prev_start = start;
31e3c61
+        prev_end = end;
52531c0
+    }
52531c0
+    if (whole_wstyle != ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_DEFAULT) {
52531c0
+        uint32_t whole_start = 0;
52531c0
+        uint32_t whole_end = strlen (str);
52531c0
+        uint32_t start, end;
52531c0
+        for (i = 0; ; i++) {
52531c0
+            IBusAttribute *attr = ibus_attr_list_get (attrs, i);
52531c0
+            if (!attr)
52531c0
+                break;
52531c0
+            start = g_utf8_offset_to_pointer (str, attr->start_index) - str;
52531c0
+            end = g_utf8_offset_to_pointer (str, attr->end_index) - str;
52531c0
+            if (start == 0 && strlen (str) == end)
52531c0
+                continue;
52531c0
+            if (start == 0) {
52531c0
+                whole_start = end;
52531c0
+            } else if (strlen (str) == end) {
52531c0
+                whole_end = start;
52531c0
+            } else {
ec611b2
+                whole_end = start;
ec611b2
+                if (whole_start < whole_end) {
ec611b2
+                    zwp_input_method_context_v1_preedit_styling (
ec611b2
+                            priv->context,
ec611b2
+                            whole_start,
ec611b2
+                            whole_end - whole_start,
ec611b2
+                            whole_wstyle);
ec611b2
+                }
ec611b2
+                whole_start = end;
ec611b2
+                whole_end = strlen (str);
52531c0
+            }
52531c0
+        }
ec611b2
+        if (whole_start < whole_end) {
52531c0
+            zwp_input_method_context_v1_preedit_styling (
52531c0
+                priv->context,
52531c0
+                whole_start,
52531c0
+                whole_end - whole_start,
52531c0
+                whole_wstyle);
52531c0
+        }
52531c0
+    }
52531c0
+}
52531c0
+
52531c0
 static void
52531c0
 _context_show_preedit_text_cb (IBusInputContext *context,
52531c0
                                IBusWaylandIM    *wlim)
52531c0
 {
52531c0
     IBusWaylandIMPrivate *priv;
52531c0
     uint32_t cursor;
52531c0
+    const char *commit = "";
52531c0
     g_return_if_fail (IBUS_IS_WAYLAND_IM (wlim));
52531c0
     priv = ibus_wayland_im_get_instance_private (wlim);
52531c0
     /* CURSOR is byte offset.  */
31e3c61
@@ -282,10 +476,13 @@ _context_show_preedit_text_cb (IBusInputContext *context,
52531c0
 
52531c0
     zwp_input_method_context_v1_preedit_cursor (priv->context,
52531c0
                                                 cursor);
52531c0
+    ibus_wayland_im_update_preedit_style (wlim);
52531c0
+    if (priv->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT)
52531c0
+        commit = priv->preedit_text->text;
52531c0
     zwp_input_method_context_v1_preedit_string (priv->context,
52531c0
                                                 priv->serial,
52531c0
                                                 priv->preedit_text->text,
52531c0
-                                                priv->preedit_text->text);
52531c0
+                                                commit);
52531c0
 }
52531c0
 
52531c0
 
31e3c61
@@ -308,6 +505,7 @@ _context_update_preedit_text_cb (IBusInputContext *context,
52531c0
                                  IBusText         *text,
52531c0
                                  gint              cursor_pos,
52531c0
                                  gboolean          visible,
52531c0
+                                 guint             mode,
52531c0
                                  IBusWaylandIM    *wlim)
52531c0
 {
52531c0
     IBusWaylandIMPrivate *priv;
31e3c61
@@ -317,6 +515,7 @@ _context_update_preedit_text_cb (IBusInputContext *context,
52531c0
         g_object_unref (priv->preedit_text);
52531c0
     priv->preedit_text = g_object_ref_sink (text);
52531c0
     priv->preedit_cursor_pos = cursor_pos;
52531c0
+    priv->preedit_mode = mode;
52531c0
 
52531c0
     if (visible)
52531c0
         _context_show_preedit_text_cb (context, wlim);
31e3c61
@@ -971,7 +1170,7 @@ _create_input_context_done (GObject      *object,
52531c0
                           G_CALLBACK (_context_forward_key_event_cb),
52531c0
                           wlim);
52531c0
 
52531c0
-        g_signal_connect (priv->ibuscontext, "update-preedit-text",
52531c0
+        g_signal_connect (priv->ibuscontext, "update-preedit-text-with-mode",
52531c0
                           G_CALLBACK (_context_update_preedit_text_cb),
52531c0
                           wlim);
52531c0
         g_signal_connect (priv->ibuscontext, "show-preedit-text",
31e3c61
@@ -988,6 +1187,7 @@ _create_input_context_done (GObject      *object,
52531c0
             capabilities |= IBUS_CAP_SYNC_PROCESS_KEY_V2;
52531c0
         ibus_input_context_set_capabilities (priv->ibuscontext,
52531c0
                                              capabilities);
52531c0
+        ibus_input_context_set_client_commit_preedit (priv->ibuscontext, TRUE);
52531c0
         if (_use_sync_mode == 1) {
52531c0
             ibus_input_context_set_post_process_key_event (priv->ibuscontext,
52531c0
                                                            TRUE);
52531c0
diff --git a/client/wayland/text-input-unstable-v1-client-protocol.h b/client/wayland/text-input-unstable-v1-client-protocol.h
52531c0
new file mode 100644
52531c0
index 00000000..71069ec7
52531c0
--- /dev/null
52531c0
+++ b/client/wayland/text-input-unstable-v1-client-protocol.h
52531c0
@@ -0,0 +1,847 @@
52531c0
+/* Generated by wayland-scanner 1.22.0 */
52531c0
+
52531c0
+#ifndef TEXT_INPUT_UNSTABLE_V1_CLIENT_PROTOCOL_H
52531c0
+#define TEXT_INPUT_UNSTABLE_V1_CLIENT_PROTOCOL_H
52531c0
+
52531c0
+#include <stdint.h>
52531c0
+#include <stddef.h>
52531c0
+#include "wayland-client.h"
52531c0
+
52531c0
+#ifdef  __cplusplus
52531c0
+extern "C" {
52531c0
+#endif
52531c0
+
52531c0
+/**
52531c0
+ * @page page_text_input_unstable_v1 The text_input_unstable_v1 protocol
52531c0
+ * @section page_ifaces_text_input_unstable_v1 Interfaces
52531c0
+ * - @subpage page_iface_zwp_text_input_v1 - text input
52531c0
+ * - @subpage page_iface_zwp_text_input_manager_v1 - text input manager
52531c0
+ * @section page_copyright_text_input_unstable_v1 Copyright
52531c0
+ * 
52531c0
+ *
52531c0
+ * Copyright © 2012, 2013 Intel Corporation
52531c0
+ *
52531c0
+ * Permission is hereby granted, free of charge, to any person obtaining a
52531c0
+ * copy of this software and associated documentation files (the "Software"),
52531c0
+ * to deal in the Software without restriction, including without limitation
52531c0
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
52531c0
+ * and/or sell copies of the Software, and to permit persons to whom the
52531c0
+ * Software is furnished to do so, subject to the following conditions:
52531c0
+ *
52531c0
+ * The above copyright notice and this permission notice (including the next
52531c0
+ * paragraph) shall be included in all copies or substantial portions of the
52531c0
+ * Software.
52531c0
+ *
52531c0
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52531c0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52531c0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
52531c0
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52531c0
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
52531c0
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
52531c0
+ * DEALINGS IN THE SOFTWARE.
52531c0
+ * 
52531c0
+ */
52531c0
+struct wl_seat;
52531c0
+struct wl_surface;
52531c0
+struct zwp_text_input_manager_v1;
52531c0
+struct zwp_text_input_v1;
52531c0
+
52531c0
+#ifndef ZWP_TEXT_INPUT_V1_INTERFACE
52531c0
+#define ZWP_TEXT_INPUT_V1_INTERFACE
52531c0
+/**
52531c0
+ * @page page_iface_zwp_text_input_v1 zwp_text_input_v1
52531c0
+ * @section page_iface_zwp_text_input_v1_desc Description
52531c0
+ *
52531c0
+ * An object used for text input. Adds support for text input and input
52531c0
+ * methods to applications. A text_input object is created from a
52531c0
+ * wl_text_input_manager and corresponds typically to a text entry in an
52531c0
+ * application.
52531c0
+ *
52531c0
+ * Requests are used to activate/deactivate the text_input object and set
52531c0
+ * state information like surrounding and selected text or the content type.
52531c0
+ * The information about entered text is sent to the text_input object via
52531c0
+ * the pre-edit and commit events. Using this interface removes the need
52531c0
+ * for applications to directly process hardware key events and compose text
52531c0
+ * out of them.
52531c0
+ *
52531c0
+ * Text is generally UTF-8 encoded, indices and lengths are in bytes.
52531c0
+ *
52531c0
+ * Serials are used to synchronize the state between the text input and
52531c0
+ * an input method. New serials are sent by the text input in the
52531c0
+ * commit_state request and are used by the input method to indicate
52531c0
+ * the known text input state in events like preedit_string, commit_string,
52531c0
+ * and keysym. The text input can then ignore events from the input method
52531c0
+ * which are based on an outdated state (for example after a reset).
52531c0
+ *
52531c0
+ * Warning! The protocol described in this file is experimental and
52531c0
+ * backward incompatible changes may be made. Backward compatible changes
52531c0
+ * may be added together with the corresponding interface version bump.
52531c0
+ * Backward incompatible changes are done by bumping the version number in
52531c0
+ * the protocol and interface names and resetting the interface version.
52531c0
+ * Once the protocol is to be declared stable, the 'z' prefix and the
52531c0
+ * version number in the protocol and interface names are removed and the
52531c0
+ * interface version number is reset.
52531c0
+ * @section page_iface_zwp_text_input_v1_api API
52531c0
+ * See @ref iface_zwp_text_input_v1.
52531c0
+ */
52531c0
+/**
52531c0
+ * @defgroup iface_zwp_text_input_v1 The zwp_text_input_v1 interface
52531c0
+ *
52531c0
+ * An object used for text input. Adds support for text input and input
52531c0
+ * methods to applications. A text_input object is created from a
52531c0
+ * wl_text_input_manager and corresponds typically to a text entry in an
52531c0
+ * application.
52531c0
+ *
52531c0
+ * Requests are used to activate/deactivate the text_input object and set
52531c0
+ * state information like surrounding and selected text or the content type.
52531c0
+ * The information about entered text is sent to the text_input object via
52531c0
+ * the pre-edit and commit events. Using this interface removes the need
52531c0
+ * for applications to directly process hardware key events and compose text
52531c0
+ * out of them.
52531c0
+ *
52531c0
+ * Text is generally UTF-8 encoded, indices and lengths are in bytes.
52531c0
+ *
52531c0
+ * Serials are used to synchronize the state between the text input and
52531c0
+ * an input method. New serials are sent by the text input in the
52531c0
+ * commit_state request and are used by the input method to indicate
52531c0
+ * the known text input state in events like preedit_string, commit_string,
52531c0
+ * and keysym. The text input can then ignore events from the input method
52531c0
+ * which are based on an outdated state (for example after a reset).
52531c0
+ *
52531c0
+ * Warning! The protocol described in this file is experimental and
52531c0
+ * backward incompatible changes may be made. Backward compatible changes
52531c0
+ * may be added together with the corresponding interface version bump.
52531c0
+ * Backward incompatible changes are done by bumping the version number in
52531c0
+ * the protocol and interface names and resetting the interface version.
52531c0
+ * Once the protocol is to be declared stable, the 'z' prefix and the
52531c0
+ * version number in the protocol and interface names are removed and the
52531c0
+ * interface version number is reset.
52531c0
+ */
52531c0
+extern const struct wl_interface zwp_text_input_v1_interface;
52531c0
+#endif
52531c0
+#ifndef ZWP_TEXT_INPUT_MANAGER_V1_INTERFACE
52531c0
+#define ZWP_TEXT_INPUT_MANAGER_V1_INTERFACE
52531c0
+/**
52531c0
+ * @page page_iface_zwp_text_input_manager_v1 zwp_text_input_manager_v1
52531c0
+ * @section page_iface_zwp_text_input_manager_v1_desc Description
52531c0
+ *
52531c0
+ * A factory for text_input objects. This object is a global singleton.
52531c0
+ * @section page_iface_zwp_text_input_manager_v1_api API
52531c0
+ * See @ref iface_zwp_text_input_manager_v1.
52531c0
+ */
52531c0
+/**
52531c0
+ * @defgroup iface_zwp_text_input_manager_v1 The zwp_text_input_manager_v1 interface
52531c0
+ *
52531c0
+ * A factory for text_input objects. This object is a global singleton.
52531c0
+ */
52531c0
+extern const struct wl_interface zwp_text_input_manager_v1_interface;
52531c0
+#endif
52531c0
+
52531c0
+#ifndef ZWP_TEXT_INPUT_V1_CONTENT_HINT_ENUM
52531c0
+#define ZWP_TEXT_INPUT_V1_CONTENT_HINT_ENUM
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ * content hint
52531c0
+ *
52531c0
+ * Content hint is a bitmask to allow to modify the behavior of the text
52531c0
+ * input.
52531c0
+ */
52531c0
+enum zwp_text_input_v1_content_hint {
52531c0
+	/**
52531c0
+	 * no special behaviour
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_NONE = 0x0,
52531c0
+	/**
52531c0
+	 * auto completion, correction and capitalization
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_DEFAULT = 0x7,
52531c0
+	/**
52531c0
+	 * hidden and sensitive text
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_PASSWORD = 0xc0,
52531c0
+	/**
52531c0
+	 * suggest word completions
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_AUTO_COMPLETION = 0x1,
52531c0
+	/**
52531c0
+	 * suggest word corrections
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_AUTO_CORRECTION = 0x2,
52531c0
+	/**
52531c0
+	 * switch to uppercase letters at the start of a sentence
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_AUTO_CAPITALIZATION = 0x4,
52531c0
+	/**
52531c0
+	 * prefer lowercase letters
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_LOWERCASE = 0x8,
52531c0
+	/**
52531c0
+	 * prefer uppercase letters
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_UPPERCASE = 0x10,
52531c0
+	/**
52531c0
+	 * prefer casing for titles and headings (can be language dependent)
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_TITLECASE = 0x20,
52531c0
+	/**
52531c0
+	 * characters should be hidden
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_HIDDEN_TEXT = 0x40,
52531c0
+	/**
52531c0
+	 * typed text should not be stored
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_SENSITIVE_DATA = 0x80,
52531c0
+	/**
52531c0
+	 * just latin characters should be entered
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_LATIN = 0x100,
52531c0
+	/**
52531c0
+	 * the text input is multiline
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_HINT_MULTILINE = 0x200,
52531c0
+};
52531c0
+#endif /* ZWP_TEXT_INPUT_V1_CONTENT_HINT_ENUM */
52531c0
+
52531c0
+#ifndef ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_ENUM
52531c0
+#define ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_ENUM
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ * content purpose
52531c0
+ *
52531c0
+ * The content purpose allows to specify the primary purpose of a text
52531c0
+ * input.
52531c0
+ *
52531c0
+ * This allows an input method to show special purpose input panels with
52531c0
+ * extra characters or to disallow some characters.
52531c0
+ */
52531c0
+enum zwp_text_input_v1_content_purpose {
52531c0
+	/**
52531c0
+	 * default input, allowing all characters
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL = 0,
52531c0
+	/**
52531c0
+	 * allow only alphabetic characters
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_ALPHA = 1,
52531c0
+	/**
52531c0
+	 * allow only digits
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DIGITS = 2,
52531c0
+	/**
52531c0
+	 * input a number (including decimal separator and sign)
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NUMBER = 3,
52531c0
+	/**
52531c0
+	 * input a phone number
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PHONE = 4,
52531c0
+	/**
52531c0
+	 * input an URL
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_URL = 5,
52531c0
+	/**
52531c0
+	 * input an email address
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_EMAIL = 6,
52531c0
+	/**
52531c0
+	 * input a name of a person
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NAME = 7,
52531c0
+	/**
52531c0
+	 * input a password (combine with password or sensitive_data hint)
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PASSWORD = 8,
52531c0
+	/**
52531c0
+	 * input a date
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATE = 9,
52531c0
+	/**
52531c0
+	 * input a time
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_TIME = 10,
52531c0
+	/**
52531c0
+	 * input a date and time
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATETIME = 11,
52531c0
+	/**
52531c0
+	 * input for a terminal
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_TERMINAL = 12,
52531c0
+};
52531c0
+#endif /* ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_ENUM */
52531c0
+
52531c0
+#ifndef ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_ENUM
52531c0
+#define ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_ENUM
52531c0
+enum zwp_text_input_v1_preedit_style {
52531c0
+	/**
52531c0
+	 * default style for composing text
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_DEFAULT = 0,
52531c0
+	/**
52531c0
+	 * style should be the same as in non-composing text
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_NONE = 1,
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_ACTIVE = 2,
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_INACTIVE = 3,
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT = 4,
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_UNDERLINE = 5,
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_SELECTION = 6,
52531c0
+	ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_INCORRECT = 7,
52531c0
+};
52531c0
+#endif /* ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_ENUM */
52531c0
+
52531c0
+#ifndef ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_ENUM
52531c0
+#define ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_ENUM
52531c0
+enum zwp_text_input_v1_text_direction {
52531c0
+	/**
52531c0
+	 * automatic text direction based on text and language
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_AUTO = 0,
52531c0
+	/**
52531c0
+	 * left-to-right
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_LTR = 1,
52531c0
+	/**
52531c0
+	 * right-to-left
52531c0
+	 */
52531c0
+	ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_RTL = 2,
52531c0
+};
52531c0
+#endif /* ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_ENUM */
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ * @struct zwp_text_input_v1_listener
52531c0
+ */
52531c0
+struct zwp_text_input_v1_listener {
52531c0
+	/**
52531c0
+	 * enter event
52531c0
+	 *
52531c0
+	 * Notify the text_input object when it received focus. Typically
52531c0
+	 * in response to an activate request.
52531c0
+	 */
52531c0
+	void (*enter)(void *data,
52531c0
+		      struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+		      struct wl_surface *surface);
52531c0
+	/**
52531c0
+	 * leave event
52531c0
+	 *
52531c0
+	 * Notify the text_input object when it lost focus. Either in
52531c0
+	 * response to a deactivate request or when the assigned surface
52531c0
+	 * lost focus or was destroyed.
52531c0
+	 */
52531c0
+	void (*leave)(void *data,
52531c0
+		      struct zwp_text_input_v1 *zwp_text_input_v1);
52531c0
+	/**
52531c0
+	 * modifiers map
52531c0
+	 *
52531c0
+	 * Transfer an array of 0-terminated modifier names. The position
52531c0
+	 * in the array is the index of the modifier as used in the
52531c0
+	 * modifiers bitmask in the keysym event.
52531c0
+	 */
52531c0
+	void (*modifiers_map)(void *data,
52531c0
+			      struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+			      struct wl_array *map);
52531c0
+	/**
52531c0
+	 * state of the input panel
52531c0
+	 *
52531c0
+	 * Notify when the visibility state of the input panel changed.
52531c0
+	 */
52531c0
+	void (*input_panel_state)(void *data,
52531c0
+				  struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+				  uint32_t state);
52531c0
+	/**
52531c0
+	 * pre-edit
52531c0
+	 *
52531c0
+	 * Notify when a new composing text (pre-edit) should be set
52531c0
+	 * around the current cursor position. Any previously set composing
52531c0
+	 * text should be removed.
52531c0
+	 *
52531c0
+	 * The commit text can be used to replace the preedit text on reset
52531c0
+	 * (for example on unfocus).
52531c0
+	 *
52531c0
+	 * The text input should also handle all preedit_style and
52531c0
+	 * preedit_cursor events occurring directly before preedit_string.
52531c0
+	 * @param serial serial of the latest known text input state
52531c0
+	 */
52531c0
+	void (*preedit_string)(void *data,
52531c0
+			       struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+			       uint32_t serial,
52531c0
+			       const char *text,
52531c0
+			       const char *commit);
52531c0
+	/**
52531c0
+	 * pre-edit styling
52531c0
+	 *
52531c0
+	 * Sets styling information on composing text. The style is
52531c0
+	 * applied for length bytes from index relative to the beginning of
52531c0
+	 * the composing text (as byte offset). Multiple styles can be
52531c0
+	 * applied to a composing text by sending multiple preedit_styling
52531c0
+	 * events.
52531c0
+	 *
52531c0
+	 * This event is handled as part of a following preedit_string
52531c0
+	 * event.
52531c0
+	 */
52531c0
+	void (*preedit_styling)(void *data,
52531c0
+				struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+				uint32_t index,
52531c0
+				uint32_t length,
52531c0
+				uint32_t style);
52531c0
+	/**
52531c0
+	 * pre-edit cursor
52531c0
+	 *
52531c0
+	 * Sets the cursor position inside the composing text (as byte
52531c0
+	 * offset) relative to the start of the composing text. When index
52531c0
+	 * is a negative number no cursor is shown.
52531c0
+	 *
52531c0
+	 * This event is handled as part of a following preedit_string
52531c0
+	 * event.
52531c0
+	 */
52531c0
+	void (*preedit_cursor)(void *data,
52531c0
+			       struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+			       int32_t index);
52531c0
+	/**
52531c0
+	 * commit
52531c0
+	 *
52531c0
+	 * Notify when text should be inserted into the editor widget.
52531c0
+	 * The text to commit could be either just a single character after
52531c0
+	 * a key press or the result of some composing (pre-edit). It could
52531c0
+	 * also be an empty text when some text should be removed (see
52531c0
+	 * delete_surrounding_text) or when the input cursor should be
52531c0
+	 * moved (see cursor_position).
52531c0
+	 *
52531c0
+	 * Any previously set composing text should be removed.
52531c0
+	 * @param serial serial of the latest known text input state
52531c0
+	 */
52531c0
+	void (*commit_string)(void *data,
52531c0
+			      struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+			      uint32_t serial,
52531c0
+			      const char *text);
52531c0
+	/**
52531c0
+	 * set cursor to new position
52531c0
+	 *
52531c0
+	 * Notify when the cursor or anchor position should be modified.
52531c0
+	 *
52531c0
+	 * This event should be handled as part of a following
52531c0
+	 * commit_string event.
52531c0
+	 */
52531c0
+	void (*cursor_position)(void *data,
52531c0
+				struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+				int32_t index,
52531c0
+				int32_t anchor);
52531c0
+	/**
52531c0
+	 * delete surrounding text
52531c0
+	 *
52531c0
+	 * Notify when the text around the current cursor position should
52531c0
+	 * be deleted.
52531c0
+	 *
52531c0
+	 * Index is relative to the current cursor (in bytes). Length is
52531c0
+	 * the length of deleted text (in bytes).
52531c0
+	 *
52531c0
+	 * This event should be handled as part of a following
52531c0
+	 * commit_string event.
52531c0
+	 */
52531c0
+	void (*delete_surrounding_text)(void *data,
52531c0
+					struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+					int32_t index,
52531c0
+					uint32_t length);
52531c0
+	/**
52531c0
+	 * keysym
52531c0
+	 *
52531c0
+	 * Notify when a key event was sent. Key events should not be
52531c0
+	 * used for normal text input operations, which should be done with
52531c0
+	 * commit_string, delete_surrounding_text, etc. The key event
52531c0
+	 * follows the wl_keyboard key event convention. Sym is an XKB
52531c0
+	 * keysym, state a wl_keyboard key_state. Modifiers are a mask for
52531c0
+	 * effective modifiers (where the modifier indices are set by the
52531c0
+	 * modifiers_map event)
52531c0
+	 * @param serial serial of the latest known text input state
52531c0
+	 */
52531c0
+	void (*keysym)(void *data,
52531c0
+		       struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+		       uint32_t serial,
52531c0
+		       uint32_t time,
52531c0
+		       uint32_t sym,
52531c0
+		       uint32_t state,
52531c0
+		       uint32_t modifiers);
52531c0
+	/**
52531c0
+	 * language
52531c0
+	 *
52531c0
+	 * Sets the language of the input text. The "language" argument
52531c0
+	 * is an RFC-3066 format language tag.
52531c0
+	 * @param serial serial of the latest known text input state
52531c0
+	 */
52531c0
+	void (*language)(void *data,
52531c0
+			 struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+			 uint32_t serial,
52531c0
+			 const char *language);
52531c0
+	/**
52531c0
+	 * text direction
52531c0
+	 *
52531c0
+	 * Sets the text direction of input text.
52531c0
+	 *
52531c0
+	 * It is mainly needed for showing an input cursor on the correct
52531c0
+	 * side of the editor when there is no input done yet and making
52531c0
+	 * sure neutral direction text is laid out properly.
52531c0
+	 * @param serial serial of the latest known text input state
52531c0
+	 */
52531c0
+	void (*text_direction)(void *data,
52531c0
+			       struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+			       uint32_t serial,
52531c0
+			       uint32_t direction);
52531c0
+};
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+static inline int
52531c0
+zwp_text_input_v1_add_listener(struct zwp_text_input_v1 *zwp_text_input_v1,
52531c0
+			       const struct zwp_text_input_v1_listener *listener, void *data)
52531c0
+{
52531c0
+	return wl_proxy_add_listener((struct wl_proxy *) zwp_text_input_v1,
52531c0
+				     (void (**)(void)) listener, data);
52531c0
+}
52531c0
+
52531c0
+#define ZWP_TEXT_INPUT_V1_ACTIVATE 0
52531c0
+#define ZWP_TEXT_INPUT_V1_DEACTIVATE 1
52531c0
+#define ZWP_TEXT_INPUT_V1_SHOW_INPUT_PANEL 2
52531c0
+#define ZWP_TEXT_INPUT_V1_HIDE_INPUT_PANEL 3
52531c0
+#define ZWP_TEXT_INPUT_V1_RESET 4
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_SURROUNDING_TEXT 5
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_CONTENT_TYPE 6
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_CURSOR_RECTANGLE 7
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_PREFERRED_LANGUAGE 8
52531c0
+#define ZWP_TEXT_INPUT_V1_COMMIT_STATE 9
52531c0
+#define ZWP_TEXT_INPUT_V1_INVOKE_ACTION 10
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_ENTER_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_LEAVE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_MODIFIERS_MAP_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_INPUT_PANEL_STATE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_PREEDIT_STRING_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_PREEDIT_STYLING_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_PREEDIT_CURSOR_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_COMMIT_STRING_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_CURSOR_POSITION_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_DELETE_SURROUNDING_TEXT_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_KEYSYM_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_LANGUAGE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_SINCE_VERSION 1
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_ACTIVATE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_DEACTIVATE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_SHOW_INPUT_PANEL_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_HIDE_INPUT_PANEL_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_RESET_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_SURROUNDING_TEXT_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_CONTENT_TYPE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_CURSOR_RECTANGLE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_SET_PREFERRED_LANGUAGE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_COMMIT_STATE_SINCE_VERSION 1
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_V1_INVOKE_ACTION_SINCE_VERSION 1
52531c0
+
52531c0
+/** @ingroup iface_zwp_text_input_v1 */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_set_user_data(struct zwp_text_input_v1 *zwp_text_input_v1, void *user_data)
52531c0
+{
52531c0
+	wl_proxy_set_user_data((struct wl_proxy *) zwp_text_input_v1, user_data);
52531c0
+}
52531c0
+
52531c0
+/** @ingroup iface_zwp_text_input_v1 */
52531c0
+static inline void *
52531c0
+zwp_text_input_v1_get_user_data(struct zwp_text_input_v1 *zwp_text_input_v1)
52531c0
+{
52531c0
+	return wl_proxy_get_user_data((struct wl_proxy *) zwp_text_input_v1);
52531c0
+}
52531c0
+
52531c0
+static inline uint32_t
52531c0
+zwp_text_input_v1_get_version(struct zwp_text_input_v1 *zwp_text_input_v1)
52531c0
+{
52531c0
+	return wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1);
52531c0
+}
52531c0
+
52531c0
+/** @ingroup iface_zwp_text_input_v1 */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_destroy(struct zwp_text_input_v1 *zwp_text_input_v1)
52531c0
+{
52531c0
+	wl_proxy_destroy((struct wl_proxy *) zwp_text_input_v1);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Requests the text_input object to be activated (typically when the
52531c0
+ * text entry gets focus).
52531c0
+ *
52531c0
+ * The seat argument is a wl_seat which maintains the focus for this
52531c0
+ * activation. The surface argument is a wl_surface assigned to the
52531c0
+ * text_input object and tracked for focus lost. The enter event
52531c0
+ * is emitted on successful activation.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_activate(struct zwp_text_input_v1 *zwp_text_input_v1, struct wl_seat *seat, struct wl_surface *surface)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_ACTIVATE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, seat, surface);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Requests the text_input object to be deactivated (typically when the
52531c0
+ * text entry lost focus). The seat argument is a wl_seat which was used
52531c0
+ * for activation.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_deactivate(struct zwp_text_input_v1 *zwp_text_input_v1, struct wl_seat *seat)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_DEACTIVATE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, seat);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Requests input panels (virtual keyboard) to show.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_show_input_panel(struct zwp_text_input_v1 *zwp_text_input_v1)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_SHOW_INPUT_PANEL, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Requests input panels (virtual keyboard) to hide.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_hide_input_panel(struct zwp_text_input_v1 *zwp_text_input_v1)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_HIDE_INPUT_PANEL, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Should be called by an editor widget when the input state should be
52531c0
+ * reset, for example after the text was changed outside of the normal
52531c0
+ * input method flow.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_reset(struct zwp_text_input_v1 *zwp_text_input_v1)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_RESET, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Sets the plain surrounding text around the input position. Text is
52531c0
+ * UTF-8 encoded. Cursor is the byte offset within the
52531c0
+ * surrounding text. Anchor is the byte offset of the
52531c0
+ * selection anchor within the surrounding text. If there is no selected
52531c0
+ * text anchor, then it is the same as cursor.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_set_surrounding_text(struct zwp_text_input_v1 *zwp_text_input_v1, const char *text, uint32_t cursor, uint32_t anchor)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_SET_SURROUNDING_TEXT, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, text, cursor, anchor);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Sets the content purpose and content hint. While the purpose is the
52531c0
+ * basic purpose of an input field, the hint flags allow to modify some
52531c0
+ * of the behavior.
52531c0
+ *
52531c0
+ * When no content type is explicitly set, a normal content purpose with
52531c0
+ * default hints (auto completion, auto correction, auto capitalization)
52531c0
+ * should be assumed.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_set_content_type(struct zwp_text_input_v1 *zwp_text_input_v1, uint32_t hint, uint32_t purpose)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_SET_CONTENT_TYPE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, hint, purpose);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_set_cursor_rectangle(struct zwp_text_input_v1 *zwp_text_input_v1, int32_t x, int32_t y, int32_t width, int32_t height)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_SET_CURSOR_RECTANGLE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, x, y, width, height);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ *
52531c0
+ * Sets a specific language. This allows for example a virtual keyboard to
52531c0
+ * show a language specific layout. The "language" argument is an RFC-3066
52531c0
+ * format language tag.
52531c0
+ *
52531c0
+ * It could be used for example in a word processor to indicate the
52531c0
+ * language of the currently edited document or in an instant message
52531c0
+ * application which tracks languages of contacts.
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_set_preferred_language(struct zwp_text_input_v1 *zwp_text_input_v1, const char *language)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_SET_PREFERRED_LANGUAGE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, language);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_commit_state(struct zwp_text_input_v1 *zwp_text_input_v1, uint32_t serial)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_COMMIT_STATE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, serial);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_v1
52531c0
+ */
52531c0
+static inline void
52531c0
+zwp_text_input_v1_invoke_action(struct zwp_text_input_v1 *zwp_text_input_v1, uint32_t button, uint32_t index)
52531c0
+{
52531c0
+	wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_v1,
52531c0
+			 ZWP_TEXT_INPUT_V1_INVOKE_ACTION, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_v1), 0, button, index);
52531c0
+}
52531c0
+
52531c0
+#define ZWP_TEXT_INPUT_MANAGER_V1_CREATE_TEXT_INPUT 0
52531c0
+
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_manager_v1
52531c0
+ */
52531c0
+#define ZWP_TEXT_INPUT_MANAGER_V1_CREATE_TEXT_INPUT_SINCE_VERSION 1
52531c0
+
52531c0
+/** @ingroup iface_zwp_text_input_manager_v1 */
52531c0
+static inline void
52531c0
+zwp_text_input_manager_v1_set_user_data(struct zwp_text_input_manager_v1 *zwp_text_input_manager_v1, void *user_data)
52531c0
+{
52531c0
+	wl_proxy_set_user_data((struct wl_proxy *) zwp_text_input_manager_v1, user_data);
52531c0
+}
52531c0
+
52531c0
+/** @ingroup iface_zwp_text_input_manager_v1 */
52531c0
+static inline void *
52531c0
+zwp_text_input_manager_v1_get_user_data(struct zwp_text_input_manager_v1 *zwp_text_input_manager_v1)
52531c0
+{
52531c0
+	return wl_proxy_get_user_data((struct wl_proxy *) zwp_text_input_manager_v1);
52531c0
+}
52531c0
+
52531c0
+static inline uint32_t
52531c0
+zwp_text_input_manager_v1_get_version(struct zwp_text_input_manager_v1 *zwp_text_input_manager_v1)
52531c0
+{
52531c0
+	return wl_proxy_get_version((struct wl_proxy *) zwp_text_input_manager_v1);
52531c0
+}
52531c0
+
52531c0
+/** @ingroup iface_zwp_text_input_manager_v1 */
52531c0
+static inline void
52531c0
+zwp_text_input_manager_v1_destroy(struct zwp_text_input_manager_v1 *zwp_text_input_manager_v1)
52531c0
+{
52531c0
+	wl_proxy_destroy((struct wl_proxy *) zwp_text_input_manager_v1);
52531c0
+}
52531c0
+
52531c0
+/**
52531c0
+ * @ingroup iface_zwp_text_input_manager_v1
52531c0
+ *
52531c0
+ * Creates a new text_input object.
52531c0
+ */
52531c0
+static inline struct zwp_text_input_v1 *
52531c0
+zwp_text_input_manager_v1_create_text_input(struct zwp_text_input_manager_v1 *zwp_text_input_manager_v1)
52531c0
+{
52531c0
+	struct wl_proxy *id;
52531c0
+
52531c0
+	id = wl_proxy_marshal_flags((struct wl_proxy *) zwp_text_input_manager_v1,
52531c0
+			 ZWP_TEXT_INPUT_MANAGER_V1_CREATE_TEXT_INPUT, &zwp_text_input_v1_interface, wl_proxy_get_version((struct wl_proxy *) zwp_text_input_manager_v1), 0, NULL);
52531c0
+
52531c0
+	return (struct zwp_text_input_v1 *) id;
52531c0
+}
52531c0
+
52531c0
+#ifdef  __cplusplus
52531c0
+}
52531c0
+#endif
52531c0
+
52531c0
+#endif
52531c0
diff --git a/src/ibusattribute.h b/src/ibusattribute.h
ec611b2
index fe4cab45..10190921 100644
52531c0
--- a/src/ibusattribute.h
52531c0
+++ b/src/ibusattribute.h
52531c0
@@ -2,7 +2,8 @@
52531c0
 /* vim:set et sts=4: */
52531c0
 /* IBus - The Input Bus
52531c0
  * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
52531c0
- * Copyright (C) 2008-2013 Red Hat, Inc.
52531c0
+ * Copyright (C) 2011-2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
52531c0
+ * Copyright (C) 2008-2023 Red Hat, Inc.
52531c0
  *
52531c0
  * This library is free software; you can redistribute it and/or
52531c0
  * modify it under the terms of the GNU Lesser General Public
52531c0
@@ -91,6 +92,55 @@ typedef enum {
52531c0
     IBUS_ATTR_UNDERLINE_ERROR   = 4,
52531c0
 } IBusAttrUnderline;
52531c0
 
52531c0
+
52531c0
+/**
52531c0
+ * IBusAttrPreedit:
52531c0
+ * @IBUS_ATTR_PREEDIT_DEFAULT: Default style for composing text.
52531c0
+ * @IBUS_ATTR_PREEDIT_NONE: Style should be the same as in non-composing text.
52531c0
+ * @IBUS_ATTR_PREEDIT_WHOLE: Most language engines wish to draw underline in
52531c0
+ *                           the typed whole preedit string except for the
52531c0
+ *                           prediction string. (Chinese, Japanese,
52531c0
+ *                           Typing-booster)
52531c0
+ * @IBUS_ATTR_PREEDIT_SELECTION: Modifying an active segment is distinguished
52531c0
+ *                               against whole the preedit text. (Hangul,
52531c0
+ *                               Japanese)
52531c0
+ * @IBUS_ATTR_PREEDIT_PREDICTION: A prediction string can be appended after the
52531c0
+ *                                typed string. (Typing-booster)
52531c0
+ * @IBUS_ATTR_PREEDIT_PREFIX: A prefix string can be an informative color.
52531c0
+ *                            (Table)
52531c0
+ * @IBUS_ATTR_PREEDIT_SUFFIX: A suffix string can be an informative color.
52531c0
+ *                            (Table)
52531c0
+ * @IBUS_ATTR_PREEDIT_ERROR_SPELLING: An detected typo could be an error color
52531c0
+ *                                    with a spelling check or the word could
52531c0
+ *                                    not be found in a dictionary. The
52531c0
+ *                                    underline color also might be more
52531c0
+ *                                    visible. (Typing-booster, Table)
52531c0
+ * @IBUS_ATTR_PREEDIT_ERROR_COMPOSE: A wrong compose key could be an error
52531c0
+ *                                   color. (Typing-booster)
52531c0
+ *
ec611b2
+ * Type of Pre-edit style as the semantic name.
52531c0
+ * The Wayland specs prefers to express the semantic values rather than RGB
52531c0
+ * values and text-input protocol version 1 defines some values:
52531c0
+ * https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/unstable/text-input/text-input-unstable-v1.xml?ref_type=heads#L251
52531c0
+ *
52531c0
+ * IBus compiled the values for major input method engines:
52531c0
+ * https://github.com/ibus/ibus/wiki/Wayland-Colors
52531c0
+ *
52531c0
+ * Since: 1.5.29
52531c0
+ * Stability: Unstable
52531c0
+ */
52531c0
+typedef enum {
52531c0
+    IBUS_ATTR_PREEDIT_DEFAULT = 0,
52531c0
+    IBUS_ATTR_PREEDIT_NONE,
52531c0
+    IBUS_ATTR_PREEDIT_WHOLE,
52531c0
+    IBUS_ATTR_PREEDIT_SELECTION,
52531c0
+    IBUS_ATTR_PREEDIT_PREDICTION,
52531c0
+    IBUS_ATTR_PREEDIT_PREFIX,
52531c0
+    IBUS_ATTR_PREEDIT_SUFFIX,
52531c0
+    IBUS_ATTR_PREEDIT_ERROR_SPELLING,
52531c0
+    IBUS_ATTR_PREEDIT_ERROR_COMPOSE,
52531c0
+} IBusAttrPreedit;
52531c0
+
52531c0
 typedef struct _IBusAttribute IBusAttribute;
52531c0
 typedef struct _IBusAttributeClass IBusAttributeClass;
52531c0
 
52531c0
-- 
52531c0
2.41.0
52531c0
5206f63
From 1be3e2f79b384a374b2a69a31c88a4f36e1dd868 Mon Sep 17 00:00:00 2001
5206f63
From: fujiwarat <takao.fujiwara1@gmail.com>
5206f63
Date: Wed, 15 Nov 2023 17:19:02 +0900
5206f63
Subject: [PATCH] client/gtk2: Call strdup() after g_return_if_fail()
5206f63
5206f63
---
5206f63
 client/gtk2/ibusimcontext.c | 3 ++-
5206f63
 1 file changed, 2 insertions(+), 1 deletion(-)
5206f63
5206f63
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
5206f63
index b5a44da0..cfc08c20 100644
5206f63
--- a/client/gtk2/ibusimcontext.c
5206f63
+++ b/client/gtk2/ibusimcontext.c
5206f63
@@ -2417,7 +2417,7 @@ _create_input_context_done (IBusBus       *bus,
5206f63
 static void
5206f63
 _create_input_context (IBusIMContext *ibusimcontext)
5206f63
 {
5206f63
-    gchar *prgname = g_strdup (g_get_prgname());
5206f63
+    gchar *prgname;
5206f63
     gchar *client_name;
5206f63
     IDEBUG ("%s", __FUNCTION__);
5206f63
 
5206f63
@@ -2425,6 +2425,7 @@ _create_input_context (IBusIMContext *ibusimcontext)
5206f63
 
5206f63
     g_return_if_fail (ibusimcontext->cancellable == NULL);
5206f63
 
5206f63
+    prgname = g_strdup (g_get_prgname());
5206f63
     ibusimcontext->cancellable = g_cancellable_new ();
5206f63
 
5206f63
     if (!prgname)
5206f63
-- 
5206f63
2.41.0
5206f63
31e3c61
From 0a7a4d1dfa580dfcc65d76a697f40094085e55a2 Mon Sep 17 00:00:00 2001
31e3c61
From: fujiwarat <takao.fujiwara1@gmail.com>
31e3c61
Date: Sat, 25 Nov 2023 13:42:07 +0900
31e3c61
Subject: [PATCH] ui/gtk3: Error handling with display == null
31e3c61
31e3c61
BUG=rhbz#2188800
31e3c61
---
31e3c61
 ui/gtk3/bindingcommon.vala |  6 +++++-
31e3c61
 ui/gtk3/panel.vala         | 14 ++++++++++----
31e3c61
 2 files changed, 15 insertions(+), 5 deletions(-)
31e3c61
31e3c61
diff --git a/ui/gtk3/bindingcommon.vala b/ui/gtk3/bindingcommon.vala
31e3c61
index da324f70..588be17a 100644
31e3c61
--- a/ui/gtk3/bindingcommon.vala
31e3c61
+++ b/ui/gtk3/bindingcommon.vala
31e3c61
@@ -263,10 +263,14 @@ class BindingCommon {
31e3c61
         return m_default_is_xdisplay;
31e3c61
     }
31e3c61
 
31e3c61
-    public static Gdk.X11.Display get_xdisplay() {
31e3c61
+    public static Gdk.X11.Display? get_xdisplay() {
31e3c61
         if (m_xdisplay != null)
31e3c61
             return m_xdisplay;
31e3c61
         var display = Gdk.Display.get_default();
31e3c61
+        if (display == null) {
31e3c61
+            error("You should open a display for IBus panel.");
31e3c61
+            return null;
31e3c61
+        }
31e3c61
         Type instance_type = display.get_type();
31e3c61
         Type x11_type = typeof(Gdk.X11.Display);
31e3c61
         if (instance_type.is_a(x11_type)) {
31e3c61
diff --git a/ui/gtk3/panel.vala b/ui/gtk3/panel.vala
31e3c61
index f1bbd720..783ec842 100644
31e3c61
--- a/ui/gtk3/panel.vala
31e3c61
+++ b/ui/gtk3/panel.vala
31e3c61
@@ -1422,9 +1422,12 @@ class Panel : IBus.PanelService {
31e3c61
 
31e3c61
         Gdk.Display display_backup = null;
31e3c61
         if (use_x11 && !BindingCommon.default_is_xdisplay()) {
31e3c61
+            var display = BindingCommon.get_xdisplay();
31e3c61
             display_backup = Gdk.Display.get_default();
31e3c61
-            Gdk.DisplayManager.get().set_default_display(
31e3c61
-                    (Gdk.Display)BindingCommon.get_xdisplay());
31e3c61
+            if (display != null) {
31e3c61
+                Gdk.DisplayManager.get().set_default_display(
31e3c61
+                        (Gdk.Display)display);
31e3c61
+            }
31e3c61
         }
31e3c61
 
31e3c61
         // Show system menu
31e3c61
@@ -1476,9 +1479,12 @@ class Panel : IBus.PanelService {
31e3c61
     private Gtk.Menu create_activate_menu(bool use_x11 = false) {
31e3c61
         Gdk.Display display_backup = null;
31e3c61
         if (use_x11 && !BindingCommon.default_is_xdisplay()) {
31e3c61
+            var display = BindingCommon.get_xdisplay();
31e3c61
             display_backup = Gdk.Display.get_default();
31e3c61
-            Gdk.DisplayManager.get().set_default_display(
31e3c61
-                    (Gdk.Display)BindingCommon.get_xdisplay());
31e3c61
+            if (display != null) {
31e3c61
+                Gdk.DisplayManager.get().set_default_display(
31e3c61
+                        (Gdk.Display)display);
31e3c61
+            }
31e3c61
         }
31e3c61
         m_ime_menu = new Gtk.Menu();
31e3c61
 
31e3c61
-- 
31e3c61
2.41.0
31e3c61