1
0
forked from aniani/vim

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 #3268)
This commit is contained in:
Bram Moolenaar 2018-08-19 22:58:45 +02:00
parent d8f0cef2bd
commit 3f6a16f022
5 changed files with 40 additions and 22 deletions

View File

@ -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)

View File

@ -5008,27 +5008,35 @@ gui_mch_set_shellsize(int width, int height,
}
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);
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 *wid, int *width, int *height)
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). */

View File

@ -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);
}

View File

@ -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);

View File

@ -794,6 +794,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
301,
/**/
300,
/**/