diff options
Diffstat (limited to 'src/gtkutil.c')
| -rw-r--r-- | src/gtkutil.c | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c index d7340ba797e..5d28b0221af 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c | |||
| @@ -869,6 +869,21 @@ xg_clear_under_internal_border (struct frame *f) | |||
| 869 | } | 869 | } |
| 870 | } | 870 | } |
| 871 | 871 | ||
| 872 | static int | ||
| 873 | xg_get_gdk_scale (void) | ||
| 874 | { | ||
| 875 | const char *sscale = getenv ("GDK_SCALE"); | ||
| 876 | |||
| 877 | if (sscale) | ||
| 878 | { | ||
| 879 | long scale = atol (sscale); | ||
| 880 | if (0 < scale) | ||
| 881 | return min (scale, INT_MAX); | ||
| 882 | } | ||
| 883 | |||
| 884 | return 1; | ||
| 885 | } | ||
| 886 | |||
| 872 | /* Function to handle resize of our frame. As we have a Gtk+ tool bar | 887 | /* Function to handle resize of our frame. As we have a Gtk+ tool bar |
| 873 | and a Gtk+ menu bar, we get resize events for the edit part of the | 888 | and a Gtk+ menu bar, we get resize events for the edit part of the |
| 874 | frame only. We let Gtk+ deal with the Gtk+ parts. | 889 | frame only. We let Gtk+ deal with the Gtk+ parts. |
| @@ -919,6 +934,9 @@ xg_frame_set_char_size (struct frame *f, int width, int height) | |||
| 919 | int pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); | 934 | int pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); |
| 920 | Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); | 935 | Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); |
| 921 | gint gwidth, gheight; | 936 | gint gwidth, gheight; |
| 937 | int totalheight | ||
| 938 | = pixelheight + FRAME_TOOLBAR_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f); | ||
| 939 | int totalwidth = pixelwidth + FRAME_TOOLBAR_WIDTH (f); | ||
| 922 | 940 | ||
| 923 | if (FRAME_PIXEL_HEIGHT (f) == 0) | 941 | if (FRAME_PIXEL_HEIGHT (f) == 0) |
| 924 | return; | 942 | return; |
| @@ -929,6 +947,13 @@ xg_frame_set_char_size (struct frame *f, int width, int height) | |||
| 929 | /* Do this before resize, as we don't know yet if we will be resized. */ | 947 | /* Do this before resize, as we don't know yet if we will be resized. */ |
| 930 | xg_clear_under_internal_border (f); | 948 | xg_clear_under_internal_border (f); |
| 931 | 949 | ||
| 950 | if (FRAME_VISIBLE_P (f)) | ||
| 951 | { | ||
| 952 | int scale = xg_get_gdk_scale (); | ||
| 953 | totalheight /= scale; | ||
| 954 | totalwidth /= scale; | ||
| 955 | } | ||
| 956 | |||
| 932 | /* Resize the top level widget so rows and columns remain constant. | 957 | /* Resize the top level widget so rows and columns remain constant. |
| 933 | 958 | ||
| 934 | When the frame is fullheight and we only want to change the width | 959 | When the frame is fullheight and we only want to change the width |
| @@ -943,38 +968,33 @@ xg_frame_set_char_size (struct frame *f, int width, int height) | |||
| 943 | frame_size_history_add | 968 | frame_size_history_add |
| 944 | (f, Qxg_frame_set_char_size_1, width, height, | 969 | (f, Qxg_frame_set_char_size_1, width, height, |
| 945 | list2 (make_number (gheight), | 970 | list2 (make_number (gheight), |
| 946 | make_number (pixelheight + FRAME_TOOLBAR_HEIGHT (f) | 971 | make_number (totalheight))); |
| 947 | + FRAME_MENUBAR_HEIGHT (f)))); | ||
| 948 | 972 | ||
| 949 | gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | 973 | gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), |
| 950 | gwidth, | 974 | gwidth, |
| 951 | pixelheight + FRAME_TOOLBAR_HEIGHT (f) | 975 | totalheight); |
| 952 | + FRAME_MENUBAR_HEIGHT (f)); | ||
| 953 | } | 976 | } |
| 954 | else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f)) | 977 | else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f)) |
| 955 | { | 978 | { |
| 956 | frame_size_history_add | 979 | frame_size_history_add |
| 957 | (f, Qxg_frame_set_char_size_2, width, height, | 980 | (f, Qxg_frame_set_char_size_2, width, height, |
| 958 | list2 (make_number (gwidth), | 981 | list2 (make_number (gwidth), |
| 959 | make_number (pixelwidth + FRAME_TOOLBAR_WIDTH (f)))); | 982 | make_number (totalwidth))); |
| 960 | 983 | ||
| 961 | gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | 984 | gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), |
| 962 | pixelwidth + FRAME_TOOLBAR_WIDTH (f), | 985 | totalwidth, |
| 963 | gheight); | 986 | gheight); |
| 964 | } | 987 | } |
| 965 | |||
| 966 | else | 988 | else |
| 967 | { | 989 | { |
| 968 | frame_size_history_add | 990 | frame_size_history_add |
| 969 | (f, Qxg_frame_set_char_size_3, width, height, | 991 | (f, Qxg_frame_set_char_size_3, width, height, |
| 970 | list2 (make_number (pixelwidth + FRAME_TOOLBAR_WIDTH (f)), | 992 | list2 (make_number (totalwidth), |
| 971 | make_number (pixelheight + FRAME_TOOLBAR_HEIGHT (f) | 993 | make_number (totalheight))); |
| 972 | + FRAME_MENUBAR_HEIGHT (f)))); | ||
| 973 | 994 | ||
| 974 | gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | 995 | gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), |
| 975 | pixelwidth + FRAME_TOOLBAR_WIDTH (f), | 996 | totalwidth, |
| 976 | pixelheight + FRAME_TOOLBAR_HEIGHT (f) | 997 | totalheight); |
| 977 | + FRAME_MENUBAR_HEIGHT (f)); | ||
| 978 | fullscreen = Qnil; | 998 | fullscreen = Qnil; |
| 979 | } | 999 | } |
| 980 | 1000 | ||
| @@ -1126,18 +1146,6 @@ delete_cb (GtkWidget *widget, | |||
| 1126 | GdkEvent *event, | 1146 | GdkEvent *event, |
| 1127 | gpointer user_data) | 1147 | gpointer user_data) |
| 1128 | { | 1148 | { |
| 1129 | #ifdef HAVE_GTK3 | ||
| 1130 | /* The event doesn't arrive in the normal event loop. Send event | ||
| 1131 | here. */ | ||
| 1132 | struct frame *f = user_data; | ||
| 1133 | struct input_event ie; | ||
| 1134 | |||
| 1135 | EVENT_INIT (ie); | ||
| 1136 | ie.kind = DELETE_WINDOW_EVENT; | ||
| 1137 | XSETFRAME (ie.frame_or_window, f); | ||
| 1138 | kbd_buffer_store_event (&ie); | ||
| 1139 | #endif | ||
| 1140 | |||
| 1141 | return TRUE; | 1149 | return TRUE; |
| 1142 | } | 1150 | } |
| 1143 | 1151 | ||
| @@ -1356,6 +1364,7 @@ x_wm_set_size_hint (struct frame *f, long int flags, bool user_position) | |||
| 1356 | int min_rows = 0, min_cols = 0; | 1364 | int min_rows = 0, min_cols = 0; |
| 1357 | int win_gravity = f->win_gravity; | 1365 | int win_gravity = f->win_gravity; |
| 1358 | Lisp_Object fs_state, frame; | 1366 | Lisp_Object fs_state, frame; |
| 1367 | int scale = xg_get_gdk_scale (); | ||
| 1359 | 1368 | ||
| 1360 | /* Don't set size hints during initialization; that apparently leads | 1369 | /* Don't set size hints during initialization; that apparently leads |
| 1361 | to a race condition. See the thread at | 1370 | to a race condition. See the thread at |
| @@ -1435,6 +1444,11 @@ x_wm_set_size_hint (struct frame *f, long int flags, bool user_position) | |||
| 1435 | hint_flags |= GDK_HINT_USER_POS; | 1444 | hint_flags |= GDK_HINT_USER_POS; |
| 1436 | } | 1445 | } |
| 1437 | 1446 | ||
| 1447 | size_hints.base_width /= scale; | ||
| 1448 | size_hints.base_height /= scale; | ||
| 1449 | size_hints.width_inc /= scale; | ||
| 1450 | size_hints.height_inc /= scale; | ||
| 1451 | |||
| 1438 | if (hint_flags != f->output_data.x->hint_flags | 1452 | if (hint_flags != f->output_data.x->hint_flags |
| 1439 | || memcmp (&size_hints, | 1453 | || memcmp (&size_hints, |
| 1440 | &f->output_data.x->size_hints, | 1454 | &f->output_data.x->size_hints, |
| @@ -3556,14 +3570,14 @@ update_theme_scrollbar_height (void) | |||
| 3556 | int | 3570 | int |
| 3557 | xg_get_default_scrollbar_width (void) | 3571 | xg_get_default_scrollbar_width (void) |
| 3558 | { | 3572 | { |
| 3559 | return scroll_bar_width_for_theme; | 3573 | return scroll_bar_width_for_theme * xg_get_gdk_scale (); |
| 3560 | } | 3574 | } |
| 3561 | 3575 | ||
| 3562 | int | 3576 | int |
| 3563 | xg_get_default_scrollbar_height (void) | 3577 | xg_get_default_scrollbar_height (void) |
| 3564 | { | 3578 | { |
| 3565 | /* Apparently there's no default height for themes. */ | 3579 | /* Apparently there's no default height for themes. */ |
| 3566 | return scroll_bar_width_for_theme; | 3580 | return scroll_bar_width_for_theme * xg_get_gdk_scale (); |
| 3567 | } | 3581 | } |
| 3568 | 3582 | ||
| 3569 | /* Return the scrollbar id for X Window WID on display DPY. | 3583 | /* Return the scrollbar id for X Window WID on display DPY. |
| @@ -3762,14 +3776,18 @@ xg_update_scrollbar_pos (struct frame *f, | |||
| 3762 | int width, | 3776 | int width, |
| 3763 | int height) | 3777 | int height) |
| 3764 | { | 3778 | { |
| 3765 | |||
| 3766 | GtkWidget *wscroll = xg_get_widget_from_map (scrollbar_id); | 3779 | GtkWidget *wscroll = xg_get_widget_from_map (scrollbar_id); |
| 3767 | |||
| 3768 | if (wscroll) | 3780 | if (wscroll) |
| 3769 | { | 3781 | { |
| 3770 | GtkWidget *wfixed = f->output_data.x->edit_widget; | 3782 | GtkWidget *wfixed = f->output_data.x->edit_widget; |
| 3771 | GtkWidget *wparent = gtk_widget_get_parent (wscroll); | 3783 | GtkWidget *wparent = gtk_widget_get_parent (wscroll); |
| 3772 | gint msl; | 3784 | gint msl; |
| 3785 | int scale = xg_get_gdk_scale (); | ||
| 3786 | |||
| 3787 | top /= scale; | ||
| 3788 | left /= scale; | ||
| 3789 | height /= scale; | ||
| 3790 | left -= (scale - 1) * ((width / scale) >> 1); | ||
| 3773 | 3791 | ||
| 3774 | /* Clear out old position. */ | 3792 | /* Clear out old position. */ |
| 3775 | int oldx = -1, oldy = -1, oldw, oldh; | 3793 | int oldx = -1, oldy = -1, oldw, oldh; |
| @@ -3800,11 +3818,15 @@ xg_update_scrollbar_pos (struct frame *f, | |||
| 3800 | gdk_window_process_all_updates (); | 3818 | gdk_window_process_all_updates (); |
| 3801 | #endif | 3819 | #endif |
| 3802 | if (oldx != -1 && oldw > 0 && oldh > 0) | 3820 | if (oldx != -1 && oldw > 0 && oldh > 0) |
| 3803 | /* Clear under old scroll bar position. This must be done after | 3821 | { |
| 3804 | the gtk_widget_queue_draw and gdk_window_process_all_updates | 3822 | /* Clear under old scroll bar position. This must be done after |
| 3805 | above. */ | 3823 | the gtk_widget_queue_draw and gdk_window_process_all_updates |
| 3806 | x_clear_area (f, | 3824 | above. */ |
| 3807 | oldx, oldy, oldw, oldh); | 3825 | oldw += (scale - 1) * oldw; |
| 3826 | oldx -= (scale - 1) * oldw; | ||
| 3827 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | ||
| 3828 | oldx, oldy, oldw, oldh); | ||
| 3829 | } | ||
| 3808 | 3830 | ||
| 3809 | /* GTK does not redraw until the main loop is entered again, but | 3831 | /* GTK does not redraw until the main loop is entered again, but |
| 3810 | if there are no X events pending we will not enter it. So we sync | 3832 | if there are no X events pending we will not enter it. So we sync |