How to get dpi using program on Xfce Desktop environment?

982 Views Asked by At

Xfce supports HiDPI scaling which can be enabled using the settings manager:

1.Go to Settings Manager > Appearance > Settings > Window Scaling and select 2 as the scaling factor.

I wonder to know if we adjust 'Window Scaling' is '2X', at this point, what is the value of DPI ? And how get the DPI value using program(C/C++)?

enter image description here

1

There are 1 best solutions below

0
On

Scaling and DPI can be tricky, if possible just leave it to Gtk to handle them. It would be nice if you could explain why do you need their values.

Here is a sample of one way to query them:

gint dpi, scale;
GtkSettings *settings;

settings = gtk_settings_get_default ();

g_object_get (settings, "gtk-xft-dpi", &dpi, NULL);
scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());

g_print("Scale is %d\n", scale);
g_print("DPI is %d\n", dpi / 1024);

Alternatively, both values can be queried using xfconf_channel_get_int, see xfce4-settings code as reference.