Discussion:
Scaling stuff for high dpi screens
Adam Sjøgren
2014-04-19 21:37:23 UTC
Permalink
I have a bad habit of procrastinating by buying new stuff, and easter
was coming up.

Anyway, that is neither here nor there, so: when you have a ~280 dpi
laptop screen (3200x1800 pixels on 13"), things need to be scaled to be
readable.

Fonts are handled by telling X what dpi you would like to use. And
fonts, oh my, do look very nice on a high dpi display, I must say.

But the Gnus logo at startup, the Gnus logo in the modeline, smileys,
and images displayed by shr are all very small.

For the logos, I think something ought to be able to happen
automatically, as they are vector-based (.svg, right)?

If someone drew smileys in .svg, the same thing should be possible for
those.

But how about shr - is there an easy way to say "my screen is silly high
on dpi, please try to double the size of all images displayed"?

(Firefox has a couple of about:config variables you can twiddle, called
layout.css.devPixelsPerPx and layout.css.dpi.)


Best regards,

Adam
--
"Tell them to give it to Donovan." Adam Sjøgren
***@koldfront.dk
Katsumi Yamaoka
2014-04-21 01:58:09 UTC
Permalink
Post by Adam Sjøgren
I have a bad habit of procrastinating by buying new stuff, and easter
was coming up.
Anyway, that is neither here nor there, so: when you have a ~280 dpi
laptop screen (3200x1800 pixels on 13"), things need to be scaled to be
readable.
How about the following ones?
Note that there are some incompletenesses:
- Emacs has to have been built with ImageMagick.
- Specifying colors to an image, e.g. Gnus logo, doesn't work.
- Not effective to some images that a program doesn't use
`create-image' nor `find-image'.
- Emacs' startup screen won't be splashed if an initial frame is
not big enough for the image (but `emacs --maximized' works).
Adam Sjøgren
2014-04-21 17:56:05 UTC
Permalink
Post by Katsumi Yamaoka
How about the following ones?
Brilliant!

Thanks a bunch - now I just need to figure out how to extract the
current dpi from X, and adjust the magnitude value on the fly.

Sweet!


:-),

Adam
--
"Any fool can write programs that a computer can Adam Sjøgren
understand. Good programmers write code that humans ***@koldfront.dk
can understand."
Adam Sjøgren
2014-05-01 21:18:59 UTC
Permalink
Post by Adam Sjøgren
Thanks a bunch - now I just need to figure out how to extract the
current dpi from X, and adjust the magnitude value on the fly.
I stole some code from from
https://github.com/bodil/emacs.d/blob/master/bodil-theme.el and adapted
it a little; so this calls xrandr to find the dpi by grabbing the
vertical pixels and the vertical mm size from the output:

(defun get-x11-dpi ()
(let ((xrandr
(with-output-to-string
(call-process "xrandr" nil standard-output))))
(string-match "\\(.+\\) connected primary \\(.+\\)x.+ (.+) \\(.+\\)mm x .+mm" xrandr)
(when (not (match-string 2 xrandr))
(string-match "\\(.+\\) connected \\(.+\\)x.+ (.+) \\(.+\\)mm x .+mm" xrandr))
(if (match-string 2 xrandr)
(let ((pixels (string-to-number (match-string 2 xrandr)))
(phys (string-to-number (match-string 3 xrandr))))
(round (/ pixels (/ phys 25.6))))
96)))

And I use this in a hook, to set a frame parameter with the
magnification I want - I am going simple here - if the dpi is above 100,
I want double up:

(add-hook 'after-make-frame-hook
'(lambda (new-frame)
(set-frame-parameter new-frame 'image-dpi-scale-magnitude (if (> (get-x11-dpi) 100) 2.0 1.0))))

I then use Katsumi-san's two defadvices, where I have changed the
magnitude line to grab the frame parameter, like this:

(let* ((magnitude (frame-parameter nil 'image-dpi-scale-magnitude))

For some reason I don't quite understand, it seems that the
hook/get-x11-dpi works inconsistently, so basically I have to evaluate
the set-frame-paremeter part manually a couple of times for it to work,
which I don't understand, but other than that, it is a good step
forward.

Thanks again for the advice!


:-),

Adam
--
"Tell them to give it to Donovan." Adam Sjøgren
***@koldfront.dk
Lars Ingebrigtsen
2015-01-28 06:23:00 UTC
Permalink
Post by Adam Sjøgren
(defun get-x11-dpi ()
(let ((xrandr
(with-output-to-string
(call-process "xrandr" nil standard-output))))
Hm. Doesn't Emacs have a way of determining the DPI of the screen? If
not, it should have.

I've Cc'd emacs-devel in case somebody there knows.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog http://lars.ingebrigtsen.no/
David Kastrup
2015-01-28 08:46:56 UTC
Permalink
Post by Lars Ingebrigtsen
Post by Adam Sjøgren
(defun get-x11-dpi ()
(let ((xrandr
(with-output-to-string
(call-process "xrandr" nil standard-output))))
Hm. Doesn't Emacs have a way of determining the DPI of the screen? If
not, it should have.
Sure.

(/ (display-pixel-width) (/ (display-mm-width) 25.4))
--
David Kastrup
Lars Ingebrigtsen
2015-01-29 01:02:04 UTC
Permalink
Post by David Kastrup
Post by Lars Ingebrigtsen
Hm. Doesn't Emacs have a way of determining the DPI of the screen? If
not, it should have.
Sure.
(/ (display-pixel-width) (/ (display-mm-width) 25.4))
Cool.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog http://lars.ingebrigtsen.no/
Eli Zaretskii
2015-01-30 06:26:28 UTC
Permalink
Date: Fri, 30 Jan 2015 00:57:14 +0100
c) If I use 'emacsclient --create-frame --alternate-editor=""' to start
Emacs, then after-make-frame-functions are called, but when I call
display-pixel-width and display-mm-width in such a function, I get
(10, nil) back.
Those functions accept a 'frame' argument, so perhaps the default they
try using (see the doc string) misfires in this particular scenario.
David Kastrup
2015-01-30 10:05:55 UTC
Permalink
Post by David Kastrup
(/ (display-pixel-width) (/ (display-mm-width) 25.4))
a) When starting Emacs by using "emacs" on the command line,
display-pixel-width and display-mm-width returns what I expect
(3200, 406).
b) after-make-frame-functions are not called when I start Emacs using
"emacs" on the command line and the first frame appears.
If I subsequently create a new frame with C-x 5 2, or emacsclient
--create-frame --alternate-editor="", they are called, and the
widths are as expected.
c) If I use 'emacsclient --create-frame --alternate-editor=""' to start
Emacs, then after-make-frame-functions are called, but when I call
display-pixel-width and display-mm-width in such a function, I get
(10, nil) back.
If I subsequently make a new frame with C-x 5 2, or emacsclient
--create-frame --alternate-editor="", then the expected values are
returned.
I don't understand b), but don't mind much, as it is easy to call my
function on the first frame created in my init.el.
I don't understand c) either, but it is quite annoying, because I can't
find a suitable way/hook in which to call display-pixel/mm-width at a
time where they give the results I expect.
You might have to provide the functions with explicit display arguments
if the "selected frame" does not correspond to a graphical display.

display-pixel-width is a compiled Lisp function in `frame.el'.

(display-pixel-width &optional DISPLAY)

Return the width of DISPLAY's screen in pixels.
DISPLAY can be a display name or a frame.
If DISPLAY is omitted or nil, it defaults to the selected frame's display.

For character terminals, each character counts as a single pixel.

For graphical terminals, note that on "multi-monitor" setups this
refers to the pixel width for all physical monitors associated
with DISPLAY. To get information for each physical monitor, use
`display-monitor-attributes-list'.
--
David Kastrup
Vincent Bernat
2015-01-30 15:19:43 UTC
Permalink
Post by David Kastrup
(/ (display-pixel-width) (/ (display-mm-width) 25.4))
[...]
I don't understand c) either, but it is quite annoying, because I can't
find a suitable way/hook in which to call display-pixel/mm-width at a
time where they give the results I expect.
For some reason, I didn't get the original message and I don't have the
whole thread either. Sorry if it has already been told.

If you use GTK as a toolkit for your Emacs, DPI changes are
automatically handled. I was previously using Lucid and switched to GTK
for this reason. This works automatically in Gnome or likewise
environments.

If you have a more "basic" environment, you need something like
xsettingsd with the target DPI*1024:

Xft/DPI 98304

I generate one with this snippet:

#+BEGIN_SRC sh
sed +Xft/DPI+d ~/.xsettingsd
dpi=$(xdpyinfo | awk '$1 ~ /resolution:/ { print $2 }' | sed 's/x.*//')
echo Xft/DPI $(( $dpi * 1024 )) >> ~/.xsettingsd
pid=$(xprop -name xsettingsd _NET_WM_PID 2> /dev/null | awk '{print $NF}')
if [ x"$pid" = x ]; then
xsettingsd -c ~/.xsettingsd &
else
kill -HUP $pid
fi

# Also use xrdb for very old stuff (you know, LibreOffice)
echo Xft.dpi: $dpi | xrdb -merge
#+END_SRC sh

However, note that the GTK version of Emacs can kill itself if a display
becomes unavailable because of some limitation of GTK.
--
Use library functions.
- The Elements of Programming Style (Kernighan & Plauger)
Adam Sjøgren
2015-01-30 23:38:28 UTC
Permalink
Post by Vincent Bernat
If you use GTK as a toolkit for your Emacs, DPI changes are
automatically handled.
Images are automatically rescaled for you on high dpi screens? They
aren't for me.
Post by Vincent Bernat
However, note that the GTK version of Emacs can kill itself if a
display becomes unavailable because of some limitation of GTK.
Yes, it is a shame that this has not been resolved yet. I never quite
understood what exactly it is in GTK that still needs fixing, even when
I did try digging.

Unfortunately the "killing itself" was introduced because I reported my
disk filling up with error messages from Emacs+GTK once. I feel somewhat
guilty.


Best regards,

Adam
--
"Sadly, these days, if you know the difference Adam Sjøgren
between a phillips- and a flat head screwdriver, ***@koldfront.dk
you're a renaissance man."
Vincent Bernat
2015-01-31 15:59:14 UTC
Permalink
Post by Adam Sjøgren
Post by Vincent Bernat
If you use GTK as a toolkit for your Emacs, DPI changes are
automatically handled.
Images are automatically rescaled for you on high dpi screens? They
aren't for me.
Not for me either. My screen is only 144 dpi so this is bearable.
--
Too much is just enough.
-- Mark Twain, on whiskey
Andreas Schwab
2015-01-28 09:39:50 UTC
Permalink
Post by Adam Sjøgren
(defun get-x11-dpi ()
(let ((xrandr
(with-output-to-string
(call-process "xrandr" nil standard-output))))
What's wrong with xdpyinfo?

Andreas.
--
Andreas Schwab, SUSE Labs, ***@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Adam Sjøgren
2015-01-29 22:28:32 UTC
Permalink
Post by Andreas Schwab
Post by Adam Sjøgren
(defun get-x11-dpi ()
(let ((xrandr
(with-output-to-string
(call-process "xrandr" nil standard-output))))
What's wrong with xdpyinfo?
Nothing, I guess. I stole the code from an Emacs configuration I came by
online, without much thought, as you do...


Best regards,

Adam
--
"Och jag vet att allt är falskt och bedrageri Adam Sjøgren
Men det struntar jag i ***@koldfront.dk
För vi dansar och du har så mjuka läppar"
Continue reading on narkive:
Loading...