diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 36718e1070..c1f9bb4dab 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -9992,10 +9992,33 @@ gtk_widget_has_screen (GtkWidget *widget) return (gtk_widget_get_screen_unchecked (widget) != NULL); } +void +_gtk_widget_scale_changed (GtkWidget *widget) +{ + GtkWidgetPrivate *priv; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + + priv = widget->priv; + + if (priv->context) + gtk_style_context_set_scale (priv->context, gtk_widget_get_scale_factor (widget)); + + g_object_notify (G_OBJECT (widget), "scale-factor"); + + gtk_widget_queue_draw (widget); + + if (GTK_IS_CONTAINER (widget)) + gtk_container_forall (GTK_CONTAINER (widget), + (GtkCallback) _gtk_widget_scale_changed, + NULL); +} + gint gtk_widget_get_scale_factor (GtkWidget *widget) { GtkWidget *toplevel; + GdkScreen *screen; g_return_val_if_fail (GTK_IS_WIDGET (widget), 1); @@ -10009,7 +10032,11 @@ gtk_widget_get_scale_factor (GtkWidget *widget) /* else fall back to something that is more likely to be right than * just returning 1: */ - return gdk_screen_get_monitor_scale_factor (gtk_widget_get_screen (widget), 0); + screen = gtk_widget_get_screen (widget); + if (screen) + return gdk_screen_get_monitor_scale_factor (screen, 0); + + return 1; } /** diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index 045c08a20e..7cf15f8e55 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -47,6 +47,8 @@ void _gtk_widget_set_alloc_needed (GtkWidget *widget, gboolean alloc_needed); void _gtk_widget_draw (GtkWidget *widget, cairo_t *cr); +void _gtk_widget_scale_changed (GtkWidget *widget); + void _gtk_widget_add_sizegroup (GtkWidget *widget, gpointer group); diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index eb2a12f0c8..f4b30081a1 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -147,6 +147,8 @@ struct _GtkWindowPrivate guint mnemonics_display_timeout_id; + gint scale; + gint title_height; GtkWidget *title_box; GtkWidget *title_icon; @@ -1335,6 +1337,8 @@ gtk_window_init (GtkWindow *window) context = gtk_widget_get_style_context (GTK_WIDGET (window)); gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND); + + priv->scale = gtk_widget_get_scale_factor (GTK_WIDGET (window)); } static void @@ -5689,6 +5693,7 @@ gtk_window_realize (GtkWidget *widget) gint attributes_mask; GtkWindowPrivate *priv; gint i; + int old_scale; window = GTK_WINDOW (widget); priv = window->priv; @@ -5918,6 +5923,11 @@ gtk_window_realize (GtkWidget *widget) if (priv->has_resize_grip) resize_grip_create_window (window); + + old_scale = priv->scale; + priv->scale = gtk_widget_get_scale_factor (widget); + if (old_scale != priv->scale) + _gtk_widget_scale_changed (widget); } static void @@ -6515,6 +6525,12 @@ gtk_window_configure_event (GtkWidget *widget, GtkWindow *window = GTK_WINDOW (widget); GtkWindowPrivate *priv = window->priv; gboolean expected_reply = priv->configure_request_count > 0; + int old_scale; + + old_scale = priv->scale; + priv->scale = gtk_widget_get_scale_factor (widget); + if (old_scale != priv->scale) + _gtk_widget_scale_changed (widget); if (!gtk_widget_is_toplevel (GTK_WIDGET (widget))) { @@ -9681,6 +9697,7 @@ gtk_window_set_screen (GtkWindow *window, GtkWidget *widget; GdkScreen *previous_screen; gboolean was_mapped; + int old_scale; g_return_if_fail (GTK_IS_WINDOW (window)); g_return_if_fail (GDK_IS_SCREEN (screen)); @@ -9728,6 +9745,11 @@ gtk_window_set_screen (GtkWindow *window, if (was_mapped) gtk_widget_map (widget); + + old_scale = priv->scale; + priv->scale = gtk_widget_get_scale_factor (widget); + if (old_scale != priv->scale) + _gtk_widget_scale_changed (widget); } static void