How to get the physical dimension (or DPI) of a widget?
Hi,
Is there a way to get the physical dimensions of a widget in mm? Or a plan to provide such API?
Alternatively, an API to query the logical widget size for a given physical dimension?
I tried a naive approach, but it gives wrong results, because monitor/compositor scaling:
GdkMonitor *monitor =
gdk_display_get_monitor_at_window(gtk_widget_get_display(widget),
gtk_widget_get_window(widget));
int height_mm = gdk_monitor_get_height_mm(monitor);
int width_mm = gdk_monitor_get_width_mm(monitor);
GdkRectangle geometry;
gdk_monitor_get_geometry(monitor, &geometry);
width_mm = (width_mm * window_width / geometry.width);
height_mm = (height_mm * window_height / geometry.height);
(I understand the widget may be transformed or projected in various ways by toolkit/compositor/hw, but in "simple" circumstances, with an application on a primary monitor, there are legitimate reasons to want this information, ranging from graphics/CAD/printer preview etc)
Edit: assuming square pixels, DPI information would work too.
Edited by Marc-André Lureau