emacs-diffs
[Top][All Lists]
Advanced

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

feature/pgtk 563a0d9: Add support for setting cursor location using Gtk


From: Yuuki Harano
Subject: feature/pgtk 563a0d9: Add support for setting cursor location using Gtk IM Context
Date: Sat, 30 Jan 2021 09:27:24 -0500 (EST)

branch: feature/pgtk
commit 563a0d94c379292bd88e83f18560ed21c497cea9
Author: Yichao Yu <yyc1992@gmail.com>
Commit: Yuuki Harano <masm+github@masm11.me>

    Add support for setting cursor location using Gtk IM Context
    
    The existing XIC implementation doesn't work when using Gtk IM Context.
    Instead, `gtk_im_context_set_cursor_location` should be used
    to update the cursor information for the input method.
    
    * src/pgtkim.c (pgtk_im_set_cursor_location): New function to tell gtk
    cursor location.
    * src/pgtkterm.c (pgtk_draw_window_cursor): Remove invalid code and
    add new code to call the function.
    * src/pgtkterm.h: Add the function declaration.
---
 src/pgtkim.c   | 12 ++++++++++++
 src/pgtkterm.c | 13 +++++++++----
 src/pgtkterm.h |  2 ++
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/pgtkim.c b/src/pgtkim.c
index 68f83d2..ba69a27 100644
--- a/src/pgtkim.c
+++ b/src/pgtkim.c
@@ -210,6 +210,18 @@ pgtk_im_filter_keypress (struct frame *f, GdkEventKey * ev)
   return false;
 }
 
+void
+pgtk_im_set_cursor_location (struct frame *f, int x, int y, int width,
+                            int height)
+{
+  struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
+  if (dpyinfo->im.context != NULL && dpyinfo->im.focused_frame == f)
+    {
+      GdkRectangle area = { x, y, width, height };
+      gtk_im_context_set_cursor_location (dpyinfo->im.context, &area);
+    }
+}
+
 static void
 pgtk_im_use_context (struct pgtk_display_info *dpyinfo, bool use_p)
 {
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 44e1f3e..5d1716a 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -2878,6 +2878,7 @@ pgtk_draw_window_cursor (struct window *w, struct 
glyph_row *glyph_row, int x,
                         int y, enum text_cursor_kinds cursor_type,
                         int cursor_width, bool on_p, bool active_p)
 {
+  struct frame *f = XFRAME (w->frame);
   PGTK_TRACE ("draw_window_cursor: %d, %d, %d, %d, %d, %d.",
              x, y, cursor_type, cursor_width, on_p, active_p);
   if (on_p)
@@ -2922,11 +2923,15 @@ pgtk_draw_window_cursor (struct window *w, struct 
glyph_row *glyph_row, int x,
            }
        }
 
-#ifdef HAVE_X_I18N
       if (w == XWINDOW (f->selected_window))
-       if (FRAME_XIC (f) && (FRAME_XIC_STYLE (f) & XIMPreeditPosition))
-         xic_set_preeditarea (w, x, y);
-#endif
+       {
+         int frame_x =
+           WINDOW_TO_FRAME_PIXEL_X (w, x) + WINDOW_LEFT_FRINGE_WIDTH (w);
+         int frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, y);
+         pgtk_im_set_cursor_location (f, frame_x, frame_y,
+                                      w->phys_cursor_width,
+                                      w->phys_cursor_height);
+       }
     }
 
 }
diff --git a/src/pgtkterm.h b/src/pgtkterm.h
index 5e71f93..07d7fc1 100644
--- a/src/pgtkterm.h
+++ b/src/pgtkterm.h
@@ -653,6 +653,8 @@ extern void pgtk_enqueue_preedit (struct frame *f, 
Lisp_Object image_data);
 extern void pgtk_im_focus_in (struct frame *f);
 extern void pgtk_im_focus_out (struct frame *f);
 extern bool pgtk_im_filter_keypress (struct frame *f, GdkEventKey * ev);
+extern void pgtk_im_set_cursor_location (struct frame *f, int x, int y,
+                                        int width, int height);
 extern void pgtk_im_init (struct pgtk_display_info *dpyinfo);
 extern void pgtk_im_finish (struct pgtk_display_info *dpyinfo);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]