[gtk+/wip/window-scales2: 6/40] gtk: add gtk_widget_get_scale_factor()



commit c0ea0b5aadbde2be83997fb7e8006c161f209d02
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 |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkwidget.h |    2 ++
 2 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f5d7d0e..36718e1 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -641,7 +641,8 @@ enum {
   PROP_VEXPAND,
   PROP_HEXPAND_SET,
   PROP_VEXPAND_SET,
-  PROP_EXPAND
+  PROP_EXPAND,
+  PROP_SCALE_FACTOR
 };
 
 typedef        struct  _GtkStateData    GtkStateData;
@@ -1607,6 +1608,25 @@ G_GNUC_END_IGNORE_DEPRECATIONS
                                                        1.0,
                                                        1.0,
                                                        GTK_PARAM_READWRITE));
+
+  /**
+   * GtkWidget:scale-factor:
+   *
+   * The scale factor of the widget. See gtk_widget_get_scale_factor() for
+   * more details about widget scaling.
+   *
+   * Since: 3.10
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SCALE_FACTOR,
+                                   g_param_spec_int ("scale-factor",
+                                                     P_("Scale factor"),
+                                                     P_("The scaling factor of the window"),
+                                                     1,
+                                                     G_MAXINT,
+                                                     1,
+                                                     GTK_PARAM_READABLE));
+
   /**
    * GtkWidget::show:
    * @widget: the object which received the signal.
@@ -3883,6 +3903,9 @@ gtk_widget_get_property (GObject         *object,
     case PROP_OPACITY:
       g_value_set_double (value, gtk_widget_get_opacity (widget));
       break;
+    case PROP_SCALE_FACTOR:
+      g_value_set_int (value, gtk_widget_get_scale_factor (widget));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -9969,6 +9992,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..72082b0 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -848,6 +848,8 @@ GDK_AVAILABLE_IN_ALL
 GdkScreen *   gtk_widget_get_screen      (GtkWidget *widget);
 GDK_AVAILABLE_IN_ALL
 gboolean      gtk_widget_has_screen      (GtkWidget *widget);
+GDK_AVAILABLE_IN_3_10
+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]