[gtk+/wip/window-scales2: 3/40] add gdk_screen_ and gdk_window_get_scale_factor()



commit 8ad851f7251dabf217378235ebb9f3ec0e72e93d
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jan 18 15:47:29 2013 +0100

    add gdk_screen_ and gdk_window_get_scale_factor()
    
    These report the internal scaling factor, mapping from UI pixels
    to hardware pixels.

 gdk/gdkscreen.c        |   34 ++++++++++++++++++++++++++++++++++
 gdk/gdkscreen.h        |    3 +++
 gdk/gdkscreenprivate.h |    3 ++-
 gdk/gdkwindow.c        |   38 ++++++++++++++++++++++++++++++++++++++
 gdk/gdkwindow.h        |    3 +++
 gdk/gdkwindowimpl.h    |    2 ++
 6 files changed, 82 insertions(+), 1 deletions(-)
---
diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c
index 93fef6d..9a71b98 100644
--- a/gdk/gdkscreen.c
+++ b/gdk/gdkscreen.c
@@ -1048,3 +1048,37 @@ gdk_screen_get_setting (GdkScreen   *screen,
 
   return GDK_SCREEN_GET_CLASS (screen)->get_setting (screen, name, value);
 }
+
+/**
+ * gdk_screen_get_monitor_scale_factor:
+ * @screen: screen to get scale factor for
+ * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
+ *
+ * Returns the internal scale factor that maps from monitor coordiantes
+ * to the actual device pixels. On traditional systems this is 1, but
+ * on very high density outputs this can be a higher value (often 2).
+ *
+ * This can be used if you want to create pixel based data for a
+ * particula monitor, but most of the time you're drawing to a window
+ * where it is better to use gdk_window_get_scale_factor() instead.
+ *
+ * Since: 3.10
+ * Return value: the scale factor
+ */
+gint
+gdk_screen_get_monitor_scale_factor (GdkScreen *screen,
+                                     gint       monitor_num)
+{
+  GdkScreenClass *screen_class;
+
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), 1);
+  g_return_val_if_fail (monitor_num >= 0, 1);
+  g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), 1);
+
+  screen_class = GDK_SCREEN_GET_CLASS (screen);
+
+  if (screen_class->get_monitor_scale_factor)
+    return screen_class->get_monitor_scale_factor (screen, monitor_num);
+
+  return 1.0;
+}
diff --git a/gdk/gdkscreen.h b/gdk/gdkscreen.h
index e01e1a9..dde5524 100644
--- a/gdk/gdkscreen.h
+++ b/gdk/gdkscreen.h
@@ -99,6 +99,9 @@ gint          gdk_screen_get_monitor_height_mm (GdkScreen *screen,
 GDK_AVAILABLE_IN_ALL
 gchar *       gdk_screen_get_monitor_plug_name (GdkScreen *screen,
                                                 gint       monitor_num);
+GDK_AVAILABLE_IN_3_10
+gint          gdk_screen_get_monitor_scale_factor (GdkScreen *screen,
+                                                   gint       monitor_num);
 
 GDK_AVAILABLE_IN_ALL
 GdkScreen *gdk_screen_get_default (void);
diff --git a/gdk/gdkscreenprivate.h b/gdk/gdkscreenprivate.h
index 75ab140..23cf1bd 100644
--- a/gdk/gdkscreenprivate.h
+++ b/gdk/gdkscreenprivate.h
@@ -91,7 +91,8 @@ struct _GdkScreenClass
   void         (* query_visual_types)    (GdkScreen   *screen,
                                           GdkVisualType **visual_types,
                                           gint           *count);
-
+  gint         (* get_monitor_scale_factor) (GdkScreen *screen,
+                                             gint       monitor_num);
 
   /* Signals: */
   void (*size_changed) (GdkScreen *screen);
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index ea7542f..99fed9b 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -10621,3 +10621,41 @@ gdk_window_get_frame_clock (GdkWindow *window)
 
   return toplevel->frame_clock;
 }
+
+/**
+ * gdk_window_get_scale_factor:
+ * @window: window to get scale factor for
+ *
+ * Returns the internal scale factor that maps from window coordiantes
+ * to the actual device pixels. On traditional systems this is 1, but
+ * on very high density outputs this can be a higher value (often 2).
+ *
+ * A higher value means that drawing is automatically scaled up to
+ * a higher resolution, so any code doing drawing will automatically look
+ * nicer. However, if you are supplying pixel-based data the scale
+ * value can be used to determine whether to use a pixel resource
+ * with higher resolution data.
+ *
+ * The scale of a window may change during runtime, if this happens
+ * a configure event will be sent to the toplevel window.
+ *
+ * Since: 3.10
+ * Return value: the scale factor
+ */
+gint
+gdk_window_get_scale_factor (GdkWindow *window)
+{
+  GdkWindowImplClass *impl_class;
+
+  g_return_val_if_fail (GDK_IS_WINDOW (window), 1);
+
+  if (GDK_WINDOW_DESTROYED (window))
+    return 1;
+
+  impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
+
+  if (impl_class->get_scale_factor)
+    return impl_class->get_scale_factor (window);
+
+  return 1;
+}
diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h
index f2ce2aa..7840c6e 100644
--- a/gdk/gdkwindow.h
+++ b/gdk/gdkwindow.h
@@ -829,6 +829,9 @@ GDK_AVAILABLE_IN_ALL
 void          gdk_window_get_frame_extents (GdkWindow     *window,
                                             GdkRectangle  *rect);
 
+GDK_AVAILABLE_IN_3_10
+gint          gdk_window_get_scale_factor  (GdkWindow     *window);
+
 #ifndef GDK_MULTIDEVICE_SAFE
 GDK_DEPRECATED_IN_3_0_FOR(gdk_window_get_device_position)
 GdkWindow *   gdk_window_get_pointer     (GdkWindow       *window,
diff --git a/gdk/gdkwindowimpl.h b/gdk/gdkwindowimpl.h
index 38008e5..7f136a5 100644
--- a/gdk/gdkwindowimpl.h
+++ b/gdk/gdkwindowimpl.h
@@ -285,6 +285,8 @@ struct _GdkWindowImplClass
                                            gint            n_elements);
   void         (*delete_property)         (GdkWindow      *window,
                                            GdkAtom         property);
+
+  gint         (* get_scale_factor)       (GdkWindow      *window);
 };
 
 /* Interface Functions */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]