diff options
| author | Lars Ingebrigtsen | 2017-07-16 16:42:26 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2017-07-17 16:58:57 +0200 |
| commit | 4198b4d985db77ad6ae372fa048250e93de5013c (patch) | |
| tree | 7f2744d0b5cac4d4e1915c1c8abaa0bfa5a2c7fb /src | |
| parent | 8729634c511cd564353ff17eb6dc06e87d081035 (diff) | |
| download | emacs-4198b4d985db77ad6ae372fa048250e93de5013c.tar.gz emacs-4198b4d985db77ad6ae372fa048250e93de5013c.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gtkutil.c | 11 | ||||
| -rw-r--r-- | src/gtkutil.h | 1 | ||||
| -rw-r--r-- | src/xmenu.c | 5 |
3 files changed, 16 insertions, 1 deletions
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) | |||
| 204 | *dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL; | 204 | *dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL; |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | /* Scaling/HiDPI functions. */ | ||
| 208 | int | ||
| 209 | xg_get_scale (struct frame *f) | ||
| 210 | { | ||
| 211 | if (FRAME_VISIBLE_P (f) && FRAME_GTK_WIDGET (f)) | ||
| 212 | return gtk_widget_get_scale_factor (FRAME_GTK_WIDGET (f)); | ||
| 213 | return 1; | ||
| 214 | } | ||
| 207 | 215 | ||
| 208 | /* Close display DPY. */ | 216 | /* Close display DPY. */ |
| 209 | 217 | ||
| @@ -724,7 +732,8 @@ xg_show_tooltip (struct frame *f, int root_x, int root_y) | |||
| 724 | if (x->ttip_window) | 732 | if (x->ttip_window) |
| 725 | { | 733 | { |
| 726 | block_input (); | 734 | block_input (); |
| 727 | gtk_window_move (x->ttip_window, root_x, root_y); | 735 | gtk_window_move (x->ttip_window, root_x / xg_get_scale (f), |
| 736 | root_y / xg_get_scale (f)); | ||
| 728 | gtk_widget_show_all (GTK_WIDGET (x->ttip_window)); | 737 | gtk_widget_show_all (GTK_WIDGET (x->ttip_window)); |
| 729 | unblock_input (); | 738 | unblock_input (); |
| 730 | } | 739 | } |
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, | |||
| 156 | extern void xg_frame_set_char_size (struct frame *f, int width, int height); | 156 | extern void xg_frame_set_char_size (struct frame *f, int width, int height); |
| 157 | extern GtkWidget * xg_win_to_widget (Display *dpy, Window wdesc); | 157 | extern GtkWidget * xg_win_to_widget (Display *dpy, Window wdesc); |
| 158 | 158 | ||
| 159 | extern int xg_get_scale (struct frame *f); | ||
| 159 | extern void xg_display_open (char *display_name, Display **dpy); | 160 | extern void xg_display_open (char *display_name, Display **dpy); |
| 160 | extern void xg_display_close (Display *dpy); | 161 | extern void xg_display_close (Display *dpy); |
| 161 | extern GdkCursor * xg_create_default_cursor (Display *dpy); | 162 | 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, | |||
| 1271 | 1271 | ||
| 1272 | /* Child of win. */ | 1272 | /* Child of win. */ |
| 1273 | &dummy_window); | 1273 | &dummy_window); |
| 1274 | #ifdef HAVE_GTK3 | ||
| 1275 | /* Use window scaling factor to adjust position for hidpi screens. */ | ||
| 1276 | x /= xg_get_scale (f); | ||
| 1277 | y /= xg_get_scale (f); | ||
| 1278 | #endif | ||
| 1274 | unblock_input (); | 1279 | unblock_input (); |
| 1275 | popup_x_y.x = x; | 1280 | popup_x_y.x = x; |
| 1276 | popup_x_y.y = y; | 1281 | popup_x_y.y = y; |