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.
This commit is contained in:
Alexander Larsson 2013-06-28 10:39:52 +02:00
parent c0ea0b5aad
commit 6bf32999b1
3 changed files with 52 additions and 1 deletions

View File

@ -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;
}
/**

View File

@ -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);

View File

@ -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