[gtk: 1/2] macos: fix the position of curosr of input method for macos.




commit 1dbb5188ba2dbb852d494c97b01b45865a23aacb
Author: Zhi <yfwz100 yeah net>
Date:   Tue Jun 22 07:20:53 2021 +0800

    macos: fix the position of curosr of input method for macos.
    
    In the refactoring from GdkWindow to GdkSurface, GtkWidget no longer
    corresponds to a GdkSurface. We have to calculate the relative position
    from GtkWidget to the GdkSurface.
    
    Closes #4063.

 gtk/gtkimcontextquartz.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkimcontextquartz.c b/gtk/gtkimcontextquartz.c
index 62ca2c4e56..fc1e1ff3a8 100644
--- a/gtk/gtkimcontextquartz.c
+++ b/gtk/gtkimcontextquartz.c
@@ -41,6 +41,7 @@ typedef struct _GtkIMContextQuartz
   GtkIMContext parent;
   GtkIMContext *helper;
   GdkSurface *client_surface;
+  GtkWidget *client_widget;
   char *preedit_str;
   unsigned int cursor_index;
   unsigned int selected_len;
@@ -266,6 +267,7 @@ quartz_set_client_surface (GtkIMContext *context,
 
   GTK_NOTE (MODULES, g_print ("quartz_set_client_surface: %p\n", widget));
 
+  qc->client_widget = widget;
   qc->client_surface = NULL;
 
   if (widget != NULL)
@@ -302,26 +304,25 @@ static void
 quartz_set_cursor_location (GtkIMContext *context, GdkRectangle *area)
 {
   GtkIMContextQuartz *qc = GTK_IM_CONTEXT_QUARTZ (context);
-  int x, y;
+  int sx, sy;
+  double wx, wy;
 
   GTK_NOTE (MODULES, g_print ("quartz_set_cursor_location\n"));
 
-  if (!qc->client_surface)
+  if (!qc->client_surface || !qc->client_widget)
     return;
 
   if (!qc->focused)
     return;
 
-  qc->cursor_rect->x = area->x;
-  qc->cursor_rect->y = area->y;
+  gdk_surface_get_origin (qc->client_surface, &sx, &sy);
+  gtk_widget_translate_coordinates(qc->client_widget, qc->client_surface->widget, area->x, area->y, &wx, 
&wy);
+  
+  qc->cursor_rect->x = sx + (int) wx;
+  qc->cursor_rect->y = sy + (int) wy;
   qc->cursor_rect->width = area->width;
   qc->cursor_rect->height = area->height;
 
-  gdk_surface_get_origin (qc->client_surface, &x, &y);
-
-  qc->cursor_rect->x = area->x + x;
-  qc->cursor_rect->y = area->y + y;
-
   if (!GDK_IS_MACOS_SURFACE (qc->client_surface))
     return;
 


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