[gtk+/wip/window-scales: 54/84] gtk: add gtk_widget_get_scale_factor()



commit cf91dba7638b0cf85c34f408150c5275f1b6f135
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 c0cb526..a1c8cf7 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -9976,6 +9976,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 b17a15d..c2a224d 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]