[gtk+/wip/hires-icons: 2/9] gtk: add gtk_widget_get_scale_factor()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/hires-icons: 2/9] gtk: add gtk_widget_get_scale_factor()
- Date: Fri, 10 May 2013 16:44:54 +0000 (UTC)
commit 06ac8109a0f1309151ab5494ef044507c03b3e2c
Author: Michael Natterer <mitch gimp org>
Date: Fri Feb 15 15:35:13 2013 +0100
gtk: add gtk_widget_get_scale_factor()
gtk/gtkwidget.c | 20 ++++++++++++++++++++
gtk/gtkwidget.h | 1 +
2 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 6ab93eb..b5ce4e5 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -9925,6 +9925,26 @@ gtk_widget_has_screen (GtkWidget *widget)
return (gtk_widget_get_screen_unchecked (widget) != NULL);
}
+gdouble
+gtk_widget_get_scale_factor (GtkWidget *widget)
+{
+ GtkWidget *toplevel;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 1.0);
+
+ toplevel = gtk_widget_get_toplevel (widget);
+ if (toplevel && toplevel != widget)
+ return gtk_widget_get_scale_factor (toplevel);
+
+ if (gtk_widget_get_realized (widget))
+ return gdk_window_get_scale_factor (gtk_widget_get_window (widget));
+
+ /* else fall back to something that is more likely to be right than
+ * just returning 1.0:
+ */
+ return gdk_screen_get_monitor_scale_factor (gtk_widget_get_screen (widget), 0);
+}
+
/**
* gtk_widget_get_display:
* @widget: a #GtkWidget
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 25247d5..d6d49f7 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -854,6 +854,7 @@ GDK_AVAILABLE_IN_ALL
GdkScreen * gtk_widget_get_screen (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_has_screen (GtkWidget *widget);
+gdouble gtk_widget_get_scale_factor (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
GdkDisplay * gtk_widget_get_display (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]