changeset 14575:f8cd07a1cbb5 v8.1.0301

patch 8.1.0301: GTK: input method popup displayed on wrong screen. commit https://github.com/vim/vim/commit/3f6a16f022c437eccaeb683640b25a972cb1b376 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 19 22:58:45 2018 +0200 patch 8.1.0301: GTK: input method popup displayed on wrong screen. Problem: GTK: Input method popup displayed on wrong screen. Solution: Add the screen position offset. (Ken Takata, closes https://github.com/vim/vim/issues/3268)
author Christian Brabandt <cb@256bit.org>
date Sun, 19 Aug 2018 23:00:06 +0200
parents 4ba20935ebe7
children 8aadb6d4e92c
files src/gui_beval.c src/gui_gtk_x11.c src/mbyte.c src/proto/gui_gtk_x11.pro src/version.c
diffstat 5 files changed, 42 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/gui_beval.c
+++ b/src/gui_beval.c
@@ -944,6 +944,8 @@ drawBalloon(BalloonEval *beval)
 	GtkRequisition	requisition;
 	int		screen_w;
 	int		screen_h;
+	int		screen_x;
+	int		screen_y;
 	int		x;
 	int		y;
 	int		x_offset = EVAL_OFFSET_X;
@@ -956,8 +958,8 @@ drawBalloon(BalloonEval *beval)
 	screen = gtk_widget_get_screen(beval->target);
 	gtk_window_set_screen(GTK_WINDOW(beval->balloonShell), screen);
 # endif
-	gui_gtk_get_screen_size_of_win(beval->balloonShell,
-							 &screen_w, &screen_h);
+	gui_gtk_get_screen_geom_of_win(beval->balloonShell,
+				    &screen_x, &screen_y, &screen_w, &screen_h);
 # if !GTK_CHECK_VERSION(3,0,0)
 	gtk_widget_ensure_style(beval->balloonShell);
 	gtk_widget_ensure_style(beval->balloonLabel);
@@ -998,14 +1000,16 @@ drawBalloon(BalloonEval *beval)
 	y += beval->y;
 
 	/* Get out of the way of the mouse pointer */
-	if (x + x_offset + requisition.width > screen_w)
+	if (x + x_offset + requisition.width > screen_x + screen_w)
 	    y_offset += 15;
-	if (y + y_offset + requisition.height > screen_h)
+	if (y + y_offset + requisition.height > screen_y + screen_h)
 	    y_offset = -requisition.height - EVAL_OFFSET_Y;
 
 	/* Sanitize values */
-	x = CLAMP(x + x_offset, 0, MAX(0, screen_w - requisition.width));
-	y = CLAMP(y + y_offset, 0, MAX(0, screen_h - requisition.height));
+	x = CLAMP(x + x_offset, 0,
+			    MAX(0, screen_x + screen_w - requisition.width));
+	y = CLAMP(y + y_offset, 0,
+			    MAX(0, screen_y + screen_h - requisition.height));
 
 	/* Show the balloon */
 # if GTK_CHECK_VERSION(3,0,0)
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -5008,27 +5008,35 @@ gui_mch_set_shellsize(int width, int hei
 }
 
     void
-gui_gtk_get_screen_size_of_win(GtkWidget *wid, int *width, int *height)
-{
+gui_gtk_get_screen_geom_of_win(
+	GtkWidget *wid,
+	int *screen_x,
+	int *screen_y,
+	int *width,
+	int *height)
+{
+    GdkRectangle geometry;
+    GdkWindow *win = gtk_widget_get_window(wid);
 #if GTK_CHECK_VERSION(3,22,0)
     GdkDisplay *dpy = gtk_widget_get_display(wid);
-    GdkWindow *win = gtk_widget_get_window(wid);
     GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
-    GdkRectangle geometry;
 
     gdk_monitor_get_geometry(monitor, &geometry);
-    *width = geometry.width;
-    *height = geometry.height;
 #else
     GdkScreen* screen;
+    int monitor;
 
     if (wid != NULL && gtk_widget_has_screen(wid))
 	screen = gtk_widget_get_screen(wid);
     else
 	screen = gdk_screen_get_default();
-    *width = gdk_screen_get_width(screen);
-    *height = gdk_screen_get_height(screen);
-#endif
+    monitor = gdk_screen_get_monitor_at_window(screen, win);
+    gdk_screen_get_monitor_geometry(screen, monitor, &geometry);
+#endif
+    *screen_x = geometry.x;
+    *screen_y = geometry.y;
+    *width = geometry.width;
+    *height = geometry.height;
 }
 
 /*
@@ -5039,7 +5047,9 @@ gui_gtk_get_screen_size_of_win(GtkWidget
     void
 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
 {
-    gui_gtk_get_screen_size_of_win(gui.mainwin, screen_w, screen_h);
+    int	    x, y;
+
+    gui_gtk_get_screen_geom_of_win(gui.mainwin, &x, &y, screen_w, screen_h);
 
     /* Subtract 'guiheadroom' from the height to allow some room for the
      * window manager (task list and window title bar). */
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -4951,24 +4951,26 @@ im_add_to_input(char_u *str, int len)
      static void
 im_preedit_window_set_position(void)
 {
-    int x, y, w, h, sw, sh;
+    int x, y, width, height;
+    int screen_x, screen_y, screen_width, screen_height;
 
     if (preedit_window == NULL)
 	return;
 
-    gui_gtk_get_screen_size_of_win(preedit_window, &sw, &sh);
+    gui_gtk_get_screen_geom_of_win(gui.drawarea,
+			  &screen_x, &screen_y, &screen_width, &screen_height);
 #if GTK_CHECK_VERSION(3,0,0)
     gdk_window_get_origin(gtk_widget_get_window(gui.drawarea), &x, &y);
 #else
     gdk_window_get_origin(gui.drawarea->window, &x, &y);
 #endif
-    gtk_window_get_size(GTK_WINDOW(preedit_window), &w, &h);
+    gtk_window_get_size(GTK_WINDOW(preedit_window), &width, &height);
     x = x + FILL_X(gui.col);
     y = y + FILL_Y(gui.row);
-    if (x + w > sw)
-	x = sw - w;
-    if (y + h > sh)
-	y = sh - h;
+    if (x + width > screen_x + screen_width)
+	x = screen_x + screen_width - width;
+    if (y + height > screen_y + screen_height)
+	y = screen_y + screen_height - height;
     gtk_window_move(GTK_WINDOW(preedit_window), x, y);
 }
 
--- a/src/proto/gui_gtk_x11.pro
+++ b/src/proto/gui_gtk_x11.pro
@@ -25,7 +25,7 @@ int gui_mch_maximized(void);
 void gui_mch_unmaximize(void);
 void gui_mch_newfont(void);
 void gui_mch_set_shellsize(int width, int height, int min_width, int min_height, int base_width, int base_height, int direction);
-void gui_gtk_get_screen_size_of_win(GtkWidget *wid, int *width, int *height);
+void gui_gtk_get_screen_geom_of_win(GtkWidget *wid, int *screen_x, int *screen_y, int *width, int *height);
 void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h);
 void gui_mch_settitle(char_u *title, char_u *icon);
 void gui_mch_enable_menu(int showit);
--- a/src/version.c
+++ b/src/version.c
@@ -795,6 +795,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    301,
+/**/
     300,
 /**/
     299,