From: Lars Ingebrigtsen Date: Sun, 16 Jul 2017 14:42:26 +0000 (+0200) Subject: Get positions of menus and tooltips right on HiDPI X-Git-Tag: emacs-26.0.90~518^2~74 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4198b4d985db77ad6ae372fa048250e93de5013c;p=emacs.git Get positions of menus and tooltips right on HiDPI * src/gtkutil.c (xg_get_scale): New function. (xg_show_tooltip): Use it. * src/xmenu.c (create_and_show_popup_menu): Put menus in the right place. --- diff --git a/src/gtkutil.c b/src/gtkutil.c index 2d4abefa969..255091559e9 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -204,6 +204,14 @@ xg_display_open (char *display_name, Display **dpy) *dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL; } +/* Scaling/HiDPI functions. */ +int +xg_get_scale (struct frame *f) +{ + if (FRAME_VISIBLE_P (f) && FRAME_GTK_WIDGET (f)) + return gtk_widget_get_scale_factor (FRAME_GTK_WIDGET (f)); + return 1; +} /* Close display DPY. */ @@ -724,7 +732,8 @@ xg_show_tooltip (struct frame *f, int root_x, int root_y) if (x->ttip_window) { block_input (); - gtk_window_move (x->ttip_window, root_x, root_y); + gtk_window_move (x->ttip_window, root_x / xg_get_scale (f), + root_y / xg_get_scale (f)); gtk_widget_show_all (GTK_WIDGET (x->ttip_window)); unblock_input (); } diff --git a/src/gtkutil.h b/src/gtkutil.h index 0abcb06bc71..a252cbef99c 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h @@ -156,6 +156,7 @@ extern void xg_frame_resized (struct frame *f, extern void xg_frame_set_char_size (struct frame *f, int width, int height); extern GtkWidget * xg_win_to_widget (Display *dpy, Window wdesc); +extern int xg_get_scale (struct frame *f); extern void xg_display_open (char *display_name, Display **dpy); extern void xg_display_close (Display *dpy); extern GdkCursor * xg_create_default_cursor (Display *dpy); diff --git a/src/xmenu.c b/src/xmenu.c index 6c8a0c506cc..64df151b289 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -1271,6 +1271,11 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv, /* Child of win. */ &dummy_window); +#ifdef HAVE_GTK3 + /* Use window scaling factor to adjust position for hidpi screens. */ + x /= xg_get_scale (f); + y /= xg_get_scale (f); +#endif unblock_input (); popup_x_y.x = x; popup_x_y.y = y;