Commit 4e451268 authored by Alexander Larsson's avatar Alexander Larsson
Browse files

widget: Track when the window scale factor changes and notify

The scale-factor property on the widgets will be notified, and the
scale will change on the style property, causing us to pick up
new css assets.
parent 536a6676
......@@ -9994,10 +9994,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);
......@@ -10011,7 +10034,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;
}
/**
......
......@@ -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);
......
......@@ -147,6 +147,8 @@ struct _GtkWindowPrivate
guint mnemonics_display_timeout_id;
gint scale;
gint title_height;
GtkWidget *title_box;
GtkWidget *title_icon;
......@@ -1320,6 +1322,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
......@@ -5651,6 +5655,7 @@ gtk_window_realize (GtkWidget *widget)
gint attributes_mask;
GtkWindowPrivate *priv;
gint i;
int old_scale;
window = GTK_WINDOW (widget);
priv = window->priv;
......@@ -5880,6 +5885,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
......@@ -6477,6 +6487,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)))
{
......@@ -9643,6 +9659,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));
......@@ -9690,6 +9707,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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment