DPI cheatcode

Technical issues/questions of an intermediate or advanced nature.
rych
Warlord
Warlord
Posts: 621
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

DPI cheatcode

Post#1 by rych » 06 May 2022, 08:49

There doesn't seem to be a method to change DPI without restarting so I wish I could decide my DPI settings from the boot menu. There isn't a "dpi" cheatcode, is there. What's the best advice then: do I switch DPI-setting modules with load=module cheatcode?

I'm going to need several versions of modules containing .Xresources with e.g.

Code: Select all

Xft.dpi: 120
and .bash_profile with

Code: Select all

export QT_FONT_DPI=140
Particularly I'll be trying a machine with a 4K monitor sometimes -- hopefully OpenBoX will scale up nicely. But first I'd better figure out how to choose the DPI option at boot. Right?

rych
Warlord
Warlord
Posts: 621
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

DPI cheatcode

Post#2 by rych » 13 May 2023, 09:06

Just collecting here links to some previous discussions setting DPI in LXDE and Mouse cursor size and theme

... and to the very comprehensive https://wiki.archlinux.org/title/HiDPI

Also some other variables (for Gtk3, Qt) to play with in your .profile

Code: Select all

export GDK_SCALE=2
export GDK_DPI_SCALE=0.5
export QT_AUTO_SCREEN_SCALE_FACTOR=0
export QT_SCALE_FACTOR=2

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

DPI cheatcode

Post#3 by fulalas » 13 May 2023, 22:22

@rych, I'm very interested in this project. I wrote a simple script to change the DPI for Xfce, since the native scaling method in 4.16+ is basically useless (i.e. everything gets blurry). I have never tested it with a real hidpi display and tbh I can't remember why the last lines are commented, but maybe you can use it is as a starting point -- I'm willing to help you:

Code: Select all

#!/bin/bash
xfceVersion=`xfce4-session -V | cut -d '(' -f2`
xfceVersion=`echo $xfceVersion | cut -d ')' -f1`
xfceVersion=`echo $xfceVersion | cut -d ' ' -f2`

if [[ $1 == "100" ]] || [[ $1 == "" ]]; then
	xfconf-query -c xsettings -p /Xft/DPI -s 96
	xfconf-query -c xsettings -p /Xft/HintStyle -s "hintfull"
	xfconf-query -c xsettings -p /Xft/RGBA -s "rgb"
	xfconf-query -c xfce4-panel -p /panels/panel-1/size -s 31
	xfconf-query -c xfce4-desktop -p /desktop-icons/icon-size -s 42
	xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s 16
	xfconf-query -c xfwm4 -p /general/theme -s "Porteus-dark"
	
	if [[ $xfceVersion == "4.12" ]]; then
		xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_SMALLER"
		xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_SMALLER"
		xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_SMALLER"
		xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_NORMAL"
	else
		xfconf-query -c xsettings --create -p /Gdk/WindowScalingFactor -t int -s 1
		xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_24"
		xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_16"
		xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_38_PERCENT"
		xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_75_PERCENT"
	fi	
elif [[ $1 == "125" ]]; then
	xfconf-query -c xsettings -p /Xft/DPI -s 120
	xfconf-query -c xsettings -p /Xft/HintStyle -s "hintfull"
	xfconf-query -c xsettings -p /Xft/RGBA -s "rgb"
	xfconf-query -c xfce4-panel -p /panels/panel-1/size -s 39
	xfconf-query -c xfce4-desktop -p /desktop-icons/icon-size -s 53
	xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s 24
	xfconf-query -c xfwm4 -p /general/theme -s "Porteus-dark"
	
	if [[ $xfceVersion == "4.12" ]]; then
		xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_SMALL"
		xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_SMALL"
		xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_SMALL"
		xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_NORMAL"
	else
		xfconf-query -c xsettings --create -p /Gdk/WindowScalingFactor -t int -s 1
		xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_32"
		xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_24"
		xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_50_PERCENT"
		xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_100_PERCENT"
	fi
elif [[ $1 == "150" ]]; then
	xfconf-query -c xsettings -p /Xft/DPI -s 144
	xfconf-query -c xsettings -p /Xft/HintStyle -s "hintslight"
	xfconf-query -c xsettings -p /Xft/RGBA -s "rgb"
	xfconf-query -c xfce4-panel -p /panels/panel-1/size -s 47
	xfconf-query -c xfce4-desktop -p /desktop-icons/icon-size -s 63
	xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s 32
	xfconf-query -c xfwm4 -p /general/theme -s "Default-hdpi"
		
	if [[ $xfceVersion == "4.12" ]]; then
		xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_NORMAL"
		xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_NORMAL"
		xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_NORMAL"
		xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_LARGER"	
	else
		xfconf-query -c xsettings --create -p /Gdk/WindowScalingFactor -t int -s 1
		xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_48"
		xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_24"
		xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_75_PERCENT"
		xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_113_PERCENT"
	fi
elif [[ $1 == "200" ]]; then
	xfconf-query -c xsettings -p /Xft/HintStyle -s "hintnone"
	xfconf-query -c xsettings -p /Xft/RGBA -s "none"
	xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s 64
	xfconf-query -c xfwm4 -p /general/theme -s "Default-hdpi"
	
	if [[ $xfceVersion == "4.12" ]]; then
		xfconf-query -c xsettings -p /Xft/DPI -s 192
		xfconf-query -c xfce4-panel -p /panels/panel-1/size -s 62
		xfconf-query -c xfce4-desktop -p /desktop-icons/icon-size -s 84
		xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_NORMAL"
		xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_LARGER"
		xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_LARGER"
		xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_LARGER"
	else
		xfconf-query -c xsettings --create -p /Gdk/WindowScalingFactor -t int -s 2
		#xfconf-query -c thunar --create -p /shortcuts-icon-size -t string -s "THUNAR_ICON_SIZE_48"
		#xfconf-query -c thunar --create -p /tree-icon-size -t string -s "THUNAR_ICON_SIZE_32"
		#xfconf-query -c thunar -p /last-details-view-zoom-level -s "THUNAR_ZOOM_LEVEL_75_PERCENT"
		#xfconf-query -c thunar -p /last-icon-view-zoom-level -s "THUNAR_ZOOM_LEVEL_150_PERCENT"
	fi
fi

xfce4-panel -r

rych
Warlord
Warlord
Posts: 621
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

DPI cheatcode

Post#4 by rych » 14 May 2023, 08:33

fulalas, It's a part of a little project of mine too. I'm preparing a new NVMe SSD USB enclosure booting the new PorteuX on my new 4K computer which also has an Nvidia GPU. So the nVidia driver coming with PorteuX will also get tested.

If/when it boots at all, I know I'm going to need a magnifying glass to see anything on the screen. So I'm thinking of first trying a KDE desktop because I heard it can maybe recognize a monitor native resolution and scale up everything (except GTK2 apps?) appropriately. I'm willing to give your script a try then, even though I don't usually use Xfce.

My preferred desktop has been OpenBox (maybe LXDE) but it might prove to be too difficult to scale everything. Previously I have tried a boot screen menu option to boot with 4k settings:

Code: Select all

export QT_FONT_DPI=200
Xft.dpi: 200
and it works for many Apps but the taskbar and other things stay tiny.

Anyway, I'm going to report here when I actually start playing with it

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

DPI cheatcode

Post#5 by fulalas » 15 May 2023, 02:41

The good news in your case is that you're getting a 4k resolution display, which means you won't need fractional scaling. And, well, the worst case scenario you can always change to 1080p before having a decent scaling solution :P

I forgot to mention that the Xfce script I gave to you needs a parameter which is the percentage of scaling: 100, 125, 150 or 200. If you're testing it on PorteuX you need to change the lines that mention porteus-dark theme and change to porteux-dark theme.

EDIT: I was playing a bit with the script and now I see why the last lines are commented; they're useless indeed. This line makes the magic on Xfce 4.16+:

Code: Select all

xfconf-query -c xsettings --create -p /Gdk/WindowScalingFactor -t int -s 2
The only things missing that I could tell are the tray icons (close to the clock) and the applications menu icons. Apart from that everything seems scaled to 2x (which is going to be your case), including VirtualBox, which is a Qt application -- don't ask me who is doing the voodoo, but it works!

rych
Warlord
Warlord
Posts: 621
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

DPI cheatcode

Post#6 by rych » 29 Jun 2023, 06:30

fulalas, I'm thinking of trying the KDE 5.27.5 DE on my PorteuX for the purpose and hope of out-of-box correct scaling across all GUI monitor-specific, and easy multi-monitor handling too. Since I won't be using my familiar albeit difficult OpenBox, and LXDE or another slim DEs would always be time consuming, I thought I would give KDE Plasma a try. Hope I'm not going to be disappointed. Will save my old /changes folder in case I have to fall back to LXDE. Might have a try later tonight and will report here. The PorteuX comes with an Nvidia driver and my 4K machine has that GPU. Realize the move from stable to current too if I'm to use the new KDE 5.27.5. So a lot of stars will have to align tonight :) And are ready to align. Must align.

https://wiki.archlinux.org/title/HiDPI#KDE_Plasma
https://bugs.kde.org/show_bug.cgi?id=466463

Font rendering
https://wiki.archlinux.org/title/font_configuration
https://forum.salixos.org/viewtopic.php?t=8275
Last edited by rych on 01 Jul 2023, 10:47, edited 3 times in total.

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

DPI cheatcode

Post#7 by fulalas » 29 Jun 2023, 10:55

I think it's going to work out of the box and chances are you don't need current to achieve that. :)

I believe things start getting complicated when you try to set fractional scaling and/or use old fashion DEs, like LXDE and Xfce.

rych
Warlord
Warlord
Posts: 621
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

DPI cheatcode

Post#8 by rych » 30 Jun 2023, 10:32

fulalas, I think I'll always try to get the most current KDE because they are fixing monitor and DPI related things. Indeed it's not quite working as good as on Windows. Some elements of GUI don't pick up the change in the scaling and I have to log out / log in, and manually replace Global theme back and forth each time. Cursor scaling is also a separate setting.

While KDE allow to handle multiple monitors easily, but can only apply a uniform scaling across all monitors, unlike Windows 11. I have 4K, 1080, 1650 monitors connected. Also, it of course doesn't allow for the Porteus way of plugging into different machines with different monitors. So, when I plug it at work everything is huge and I need to scale down etc. I wonder when I go back home will I have to align multiple monitors again too?

So, anyway I'm back to figuring out which config files KDE keeps the DPI and monitor related settings in (I don't see the .Xresources file for example) and apply different versions of those at the boot time via cheat codes in the separate boot loader menu entries for 4k and normal monitor etc.

I'll keep testing it. Will test the Nvidia driver next. Please keep upgrading KDE on the current PorteuX, KDE looks like the most mature Linux DE and appears to be under active development.

UPDATE. Found this dated python script addressing this problems: "Manually changing DPI settings, panel height/width, clock font or other settings for widgets each time the computer is connected to a different display is tedious" https://github.com/maldoinc/plasma-dpi-switcher
Last edited by rych on 30 Jun 2023, 16:21, edited 1 time in total.

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

DPI cheatcode

Post#9 by fulalas » 30 Jun 2023, 13:21

@rych, another option could be testing the new Cinnamon 5.8.0, available in PorteuX 0.5 RC1:

PorteuX 0.5 RC1 (current only)

BTW, I'm not sure where KDE stores the DPI settings, but usually all settings are in ~/.config main folder as text files, so saving all of them is a good start. :)

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

DPI cheatcode

Post#10 by fulalas » 04 Oct 2023, 22:56

@rych, I have a 4k monitor now to test and I managed to put 200% scaling to work flawlessly on Xfce 4.16 and 4.18.

What I did:

1: created /rootcopy/home/guest/.config/autostart/hidpi file and pasted this:

Code: Select all

#!/bin/bash
export GDK_SCALE=2
export QT_SCALE_FACTOR=2
xfconf-query -c xsettings -p /Xft/HintStyle -s "hintnone"
xfconf-query -c xsettings -p /Xft/RGBA -s "none"
xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s 64
xfconf-query -c xfwm4 -p /general/theme -s "Default-xhdpi"
xfconf-query -c xsettings --create -p /Gdk/WindowScalingFactor -t int -s 2
2: created /rootcopy/home/guest/.config/autostart/hidpi.desktop file and pasted this:

Code: Select all

[Desktop Entry]
Exec=/home/guest/.config/autostart/hidpi
Name=HiDPI
Then rebooted and set my display resolution to 4k. Note that GDK_SCALE doesn't support fractional scaling.

There were heaps of low resolution icons on Xfce, so I had to upgrade the icon package. But apart from that, all good. I still haven't looked at how to make AppImage applications respect these settings.

Now, for GNOME it's even easier. Just use the display settings to scale to 200%. Nothing else :)

For KDE, LXDE LXQt and MATE it's also easy and very similar (no need to run the xfconf-query commands, of course). But I haven't found a way to scale py-gtk applications (our xzm activation popups, for example).

Let me know how this is going for you :)

Post Reply