[gtk+/wip/hires-icons: 1/8] quartz: add gdk_screen_ and gdk_window_get_scale_factor()



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

    quartz: add gdk_screen_ and gdk_window_get_scale_factor()
    
    which return 1.0 normally and 2.0 on retina displays.

 gdk/gdkscreen.c               |   18 ++++++++++++++++++
 gdk/gdkscreen.h               |    3 +++
 gdk/gdkscreenprivate.h        |    3 ++-
 gdk/gdkwindow.c               |   19 +++++++++++++++++++
 gdk/gdkwindow.h               |    3 +++
 gdk/gdkwindowimpl.h           |    2 ++
 gdk/quartz/gdkscreen-quartz.c |   30 ++++++++++++++++++++++++++++++
 gdk/quartz/gdkwindow-quartz.c |   22 ++++++++++++++++++++++
 8 files changed, 99 insertions(+), 1 deletions(-)
---
diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c
index 93fef6d..2c026fc 100644
--- a/gdk/gdkscreen.c
+++ b/gdk/gdkscreen.c
@@ -1048,3 +1048,21 @@ gdk_screen_get_setting (GdkScreen   *screen,
 
   return GDK_SCREEN_GET_CLASS (screen)->get_setting (screen, name, value);
 }
+
+gdouble
+gdk_screen_get_monitor_scale_factor (GdkScreen *screen,
+                                     gint       monitor_num)
+{
+  GdkScreenClass *screen_class;
+
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), 1.0);
+  g_return_val_if_fail (monitor_num >= 0, 1.0);
+  g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), 1.0);
+
+  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..c9f1036 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
+gdouble       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..eb551b9 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);
-
+  gdouble      (* 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 f4f1440..44a51b3 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -10550,3 +10550,22 @@ gdk_window_get_frame_clock (GdkWindow *window)
 
   return toplevel->frame_clock;
 }
+
+gdouble
+gdk_window_get_scale_factor (GdkWindow *window)
+{
+  GdkWindowImplClass *impl_class;
+
+  g_return_val_if_fail (GDK_IS_WINDOW (window), 1.0);
+
+  if (GDK_WINDOW_DESTROYED (window))
+    return 1.0;
+
+  window = gdk_window_get_toplevel (window);
+  impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
+
+  if (impl_class->get_scale_factor)
+    return impl_class->get_scale_factor (window);
+
+  return 1.0;
+}
diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h
index ddc8e70..4a1ed60 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
+gdouble       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..9eeec3c 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);
+
+  gdouble      (* get_scale_factor)       (GdkWindow      *window);
 };
 
 /* Interface Functions */
diff --git a/gdk/quartz/gdkscreen-quartz.c b/gdk/quartz/gdkscreen-quartz.c
index 84269f5..4b19afc 100644
--- a/gdk/quartz/gdkscreen-quartz.c
+++ b/gdk/quartz/gdkscreen-quartz.c
@@ -427,6 +427,35 @@ gdk_quartz_screen_get_monitor_workarea (GdkScreen    *screen,
   GDK_QUARTZ_RELEASE_POOL;
 }
 
+/* Protocol to build cleanly for OSX < 10.7 */
+ protocol ScaleFactor
+- (CGFloat) backingScaleFactor;
+ end
+
+gdouble
+_gdk_quartz_screen_get_monitor_scale_factor (GdkScreen *screen,
+                                             gint       monitor_num)
+{
+  GdkScreenQuartz *quartz_screen;
+  NSArray *array;
+  NSScreen *nsscreen;
+  gdouble scale_factor = 1.0;
+
+  quartz_screen = GDK_SCREEN_QUARTZ (screen);
+
+  GDK_QUARTZ_ALLOC_POOL;
+
+  array = [NSScreen screens];
+  nsscreen = [array objectAtIndex:monitor_num];
+
+  if (gdk_quartz_osx_version() >= GDK_OSX_LION)
+    scale_factor = [(id <ScaleFactor>) nsscreen backingScaleFactor];
+
+  GDK_QUARTZ_RELEASE_POOL;
+
+  return scale_factor;
+}
+
 static gchar *
 gdk_quartz_screen_make_display_name (GdkScreen *screen)
 {
@@ -491,4 +520,5 @@ gdk_quartz_screen_class_init (GdkQuartzScreenClass *klass)
   screen_class->query_depths = _gdk_quartz_screen_query_depths;
   screen_class->query_visual_types = _gdk_quartz_screen_query_visual_types;
   screen_class->list_visuals = _gdk_quartz_screen_list_visuals;
+  screen_class->get_monitor_scale_factor = _gdk_quartz_screen_get_monitor_scale_factor;
 }
diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c
index 2403b04..7443a36 100644
--- a/gdk/quartz/gdkwindow-quartz.c
+++ b/gdk/quartz/gdkwindow-quartz.c
@@ -2997,6 +2997,26 @@ gdk_quartz_window_get_input_shape (GdkWindow *window)
   return NULL;
 }
 
+/* Protocol to build cleanly for OSX < 10.7 */
+ protocol ScaleFactor
+- (CGFloat) backingScaleFactor;
+ end
+
+static gdouble
+gdk_quartz_window_get_scale_factor (GdkWindow *window)
+{
+  GdkWindowImplQuartz *impl;
+
+  if (GDK_WINDOW_DESTROYED (window))
+    return 1.0;
+
+  impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);
+
+  if (gdk_quartz_osx_version() >= GDK_OSX_LION)
+    return [(id <ScaleFactor>) impl->toplevel backingScaleFactor];
+
+  return 1.0;
+}
 
 static void
 gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
@@ -3036,6 +3056,7 @@ gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
   impl_class->get_input_shape = gdk_quartz_window_get_input_shape;
   impl_class->begin_paint_region = gdk_window_impl_quartz_begin_paint_region;
   impl_class->end_paint = gdk_window_impl_quartz_end_paint;
+  impl_class->get_scale_factor = gdk_quartz_window_get_scale_factor;
 
   impl_class->focus = gdk_quartz_window_focus;
   impl_class->set_type_hint = gdk_quartz_window_set_type_hint;
@@ -3089,6 +3110,7 @@ gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
 
   impl_quartz_class->get_context = gdk_window_impl_quartz_get_context;
   impl_quartz_class->release_context = gdk_window_impl_quartz_release_context;
+
 }
 
 GType


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