How to set up fixed screen DPI in Linux using environment vars? Maybe using Xorg envvars
- User
How to set up fixed screen DPI in Linux using environment vars? Maybe using Xorg envvars
- Assistant
How to set up fixed screen DPI in Linux using environment vars? Maybe using Xorg envvars
Certainly! Setting a fixed DPI (Dots Per Inch) for your display in a Linux environment using environment variables can be done by configuring the Xorg settings. You can manually set the DPI by modifying or creating the appropriate configuration files for Xorg.
Here’s a step-by-step guide on how to do this:
First, decide on the DPI value that you want to set. Common values are 96, 120, etc.
You need to create or edit an Xorg configuration file to set the DPI. Xorg configuration files usually reside in /etc/X11/xorg.conf.d/ or sometimes directly in /etc/X11/.
90-monitor.conf:sudo nano /etc/X11/xorg.conf.d/90-monitor.conf
Section "Monitor"
Identifier "Configured Monitor"
DisplaySize 346 194 # In millimeters, adjust according to your screen size
EndSection
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Device"
EndSection
Section "Device"
Identifier "Configured Device"
EndSection
The DisplaySize keyword specifies the physical width and height of the screen in millimeters. You can adjust these values according to your screen to control the DPI. The DPI is calculated as (width in pixels * 25.4) / DisplaySize width and (height in pixels * 25.4) / DisplaySize height.
You can also set the DPI using xrandr in your .xprofile, .xinitrc, or display manager’s startup scripts.
~/.xprofile:nano ~/.xprofile
xrandr --dpi 96
XRESOURCE Environment VariableAdditionally, you can set the DPI through the XRESOURCE environment variable in your .Xresources file.
~/.Xresources:nano ~/.Xresources
Xft.dpi: 96
After making the changes, you need to restart the X server or log out and log back in for the changes to take effect. If you used .Xresources, you can load the settings without rebooting by running:
xrdb -merge ~/.Xresources
For quick reference, here are the commands and files you would typically use:
Create/Edit Xorg configuration file:
sudo nano /etc/X11/xorg.conf.d/90-monitor.conf
Content:
Section "Monitor"
Identifier "Configured Monitor"
DisplaySize 346 194 # Adjust to your screen size
EndSection
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Device"
EndSection
Section "Device"
Identifier "Configured Device"
EndSection
Set DPI with xrandr in ~/.xprofile:
nano ~/.xprofile
Content:
xrandr --dpi 96
Set DPI in .Xresources:
nano ~/.Xresources
xrdb -merge ~/.Xresources
Content:
Xft.dpi: 96
Feel free to adjust the DPI value and the DisplaySize settings accordingly for optimal results.
Not yet included in a published release.