Commit 8ad851f7 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Alexander Larsson

add gdk_screen_ and gdk_window_get_scale_factor()

These report the internal scaling factor, mapping from UI pixels
to hardware pixels.
parent 995a7e95
......@@ -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;
}
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......@@ -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,
......
......@@ -285,6 +285,8 @@ struct _GdkWindowImplClass
gint n_elements);
void (*delete_property) (GdkWindow *window,
GdkAtom property);
gint (* get_scale_factor) (GdkWindow *window);
};
/* Interface Functions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment