[gtk+/wip/window-scales: 4/16] gtk: add gtk_widget_get_scale_factor()



commit 66492f1d672505ea05418613b0649e550e362e96
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 9626c80..58914c2 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -9974,6 +9974,26 @@ gtk_widget_has_screen (GtkWidget *widget)
   return (gtk_widget_get_screen_unchecked (widget) != NULL);
 }
 
+gint
+gtk_widget_get_scale_factor (GtkWidget *widget)
+{
+  GtkWidget *toplevel;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 1);
+
+  if (gtk_widget_get_realized (widget))
+    return gdk_window_get_scale_factor (gtk_widget_get_window (widget));
+
+  toplevel = gtk_widget_get_toplevel (widget);
+  if (toplevel && toplevel != widget)
+    return gtk_widget_get_scale_factor (toplevel);
+
+  /* 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);
+}
+
 /**
  * gtk_widget_get_display:
  * @widget: a #GtkWidget
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 49008cf..19d8a0f 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -848,6 +848,7 @@ GDK_AVAILABLE_IN_ALL
 GdkScreen *   gtk_widget_get_screen      (GtkWidget *widget);
 GDK_AVAILABLE_IN_ALL
 gboolean      gtk_widget_has_screen      (GtkWidget *widget);
+gint          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]