* Scaling stuff for high dpi screens
@ 2014-04-19 21:37 Adam Sjøgren
2014-04-21 1:58 ` Katsumi Yamaoka
0 siblings, 1 reply; 16+ messages in thread
From: Adam Sjøgren @ 2014-04-19 21:37 UTC (permalink / raw)
To: ding
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
asjo@koldfront.dk
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2014-04-19 21:37 Scaling stuff for high dpi screens Adam Sjøgren
@ 2014-04-21 1:58 ` Katsumi Yamaoka
2014-04-21 17:56 ` Adam Sjøgren
0 siblings, 1 reply; 16+ messages in thread
From: Katsumi Yamaoka @ 2014-04-21 1:58 UTC (permalink / raw)
To: ding
[-- Attachment #1: Type: text/plain, Size: 729 bytes --]
On Sat, 19 Apr 2014 23:37:23 +0200, Adam Sjøgren wrote:
> 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).
[-- Attachment #2: Type: application/emacs-lisp, Size: 912 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2014-04-21 1:58 ` Katsumi Yamaoka
@ 2014-04-21 17:56 ` Adam Sjøgren
2014-05-01 21:18 ` Adam Sjøgren
0 siblings, 1 reply; 16+ messages in thread
From: Adam Sjøgren @ 2014-04-21 17:56 UTC (permalink / raw)
To: ding
Katsumi Yamaoka <yamaoka@jpl.org> writes:
> 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 asjo@koldfront.dk
can understand."
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2014-04-21 17:56 ` Adam Sjøgren
@ 2014-05-01 21:18 ` Adam Sjøgren
2015-01-28 6:23 ` Lars Ingebrigtsen
2015-01-28 9:39 ` Andreas Schwab
0 siblings, 2 replies; 16+ messages in thread
From: Adam Sjøgren @ 2014-05-01 21:18 UTC (permalink / raw)
To: ding
asjo@koldfront.dk (Adam Sjøgren) writes:
> 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
asjo@koldfront.dk
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2014-05-01 21:18 ` Adam Sjøgren
@ 2015-01-28 6:23 ` Lars Ingebrigtsen
2015-01-28 8:46 ` David Kastrup
2015-01-28 9:39 ` Andreas Schwab
1 sibling, 1 reply; 16+ messages in thread
From: Lars Ingebrigtsen @ 2015-01-28 6:23 UTC (permalink / raw)
To: Adam Sjøgren; +Cc: ding, emacs-devel
asjo@koldfront.dk (Adam Sjøgren) writes:
> (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/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-28 6:23 ` Lars Ingebrigtsen
@ 2015-01-28 8:46 ` David Kastrup
2015-01-29 1:02 ` Lars Ingebrigtsen
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: David Kastrup @ 2015-01-28 8:46 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Adam Sjøgren, ding, emacs-devel
Lars Ingebrigtsen <larsi@gnus.org> writes:
> asjo@koldfront.dk (Adam Sjøgren) writes:
>
>> (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
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2014-05-01 21:18 ` Adam Sjøgren
2015-01-28 6:23 ` Lars Ingebrigtsen
@ 2015-01-28 9:39 ` Andreas Schwab
2015-01-29 22:28 ` Adam Sjøgren
1 sibling, 1 reply; 16+ messages in thread
From: Andreas Schwab @ 2015-01-28 9:39 UTC (permalink / raw)
To: Adam Sjøgren; +Cc: ding
asjo@koldfront.dk (Adam Sjøgren) writes:
> (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, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-28 8:46 ` David Kastrup
@ 2015-01-29 1:02 ` Lars Ingebrigtsen
2015-01-29 22:26 ` Adam Sjøgren
2015-01-29 23:57 ` Adam Sjøgren
2 siblings, 0 replies; 16+ messages in thread
From: Lars Ingebrigtsen @ 2015-01-29 1:02 UTC (permalink / raw)
To: David Kastrup; +Cc: Adam Sjøgren, ding, emacs-devel
David Kastrup <dak@gnu.org> writes:
>> 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/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-28 8:46 ` David Kastrup
2015-01-29 1:02 ` Lars Ingebrigtsen
@ 2015-01-29 22:26 ` Adam Sjøgren
2015-01-29 23:57 ` Adam Sjøgren
2 siblings, 0 replies; 16+ messages in thread
From: Adam Sjøgren @ 2015-01-29 22:26 UTC (permalink / raw)
To: emacs-devel; +Cc: ding
David writes:
> Lars Ingebrigtsen <larsi@gnus.org> writes:
>> 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))
Perfect, thanks!
Best regards,
Adam
--
"I skal gå tre skridt væk fra mig Adam Sjøgren
For jeg har fundet en som rammer" asjo@koldfront.dk
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-28 9:39 ` Andreas Schwab
@ 2015-01-29 22:28 ` Adam Sjøgren
0 siblings, 0 replies; 16+ messages in thread
From: Adam Sjøgren @ 2015-01-29 22:28 UTC (permalink / raw)
To: ding
Andreas writes:
> asjo@koldfront.dk (Adam Sjøgren) writes:
>> (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 asjo@koldfront.dk
För vi dansar och du har så mjuka läppar"
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-28 8:46 ` David Kastrup
2015-01-29 1:02 ` Lars Ingebrigtsen
2015-01-29 22:26 ` Adam Sjøgren
@ 2015-01-29 23:57 ` Adam Sjøgren
2015-01-30 6:26 ` Eli Zaretskii
2015-01-30 10:05 ` David Kastrup
2 siblings, 2 replies; 16+ messages in thread
From: Adam Sjøgren @ 2015-01-29 23:57 UTC (permalink / raw)
To: emacs-devel; +Cc: ding
David writes:
> (/ (display-pixel-width) (/ (display-mm-width) 25.4))
Here are my observations so far:
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.
This is what I have been playing around with in my init.el:
(defun get-x11-dpi ()
(let ((pixel-width (display-pixel-width))
(mm-width (display-mm-width)))
(message "display-pixel-width: %s" pixel-width)
(message "display-mm-width: %s" mm-width)
(if (and pixel-width mm-width)
(round (/ (display-pixel-width) (/ (display-mm-width) 25.4)))
100)))
; Activate scaling:
(defun asjo-new-frame-setup-scaling (new-frame)
(set-frame-parameter new-frame 'image-dpi-scale-magnitude (if (> (get-x11-dpi) 100) 2.0 1.0)))
; This does not work for the first emacsclient frame, but it does for
; subsequent frames, it is not run for first emacs frame either:
(add-hook 'after-make-frame-functions 'asjo-new-frame-setup-scaling)
; This is for non-emacsclient startup:
(asjo-new-frame-setup-scaling nil)
Best regards,
Adam
--
"I think I've learned by now Adam Sjøgren
There's never an easy way" asjo@koldfront.dk
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-29 23:57 ` Adam Sjøgren
@ 2015-01-30 6:26 ` Eli Zaretskii
2015-01-30 10:05 ` David Kastrup
1 sibling, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2015-01-30 6:26 UTC (permalink / raw)
To: Adam Sjøgren; +Cc: ding, emacs-devel
> From: asjo@koldfront.dk (Adam Sjøgren)
> Date: Fri, 30 Jan 2015 00:57:14 +0100
> Cc: ding@gnus.org
>
> 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.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-29 23:57 ` Adam Sjøgren
2015-01-30 6:26 ` Eli Zaretskii
@ 2015-01-30 10:05 ` David Kastrup
2015-01-30 15:19 ` Vincent Bernat
1 sibling, 1 reply; 16+ messages in thread
From: David Kastrup @ 2015-01-30 10:05 UTC (permalink / raw)
To: Adam Sjøgren; +Cc: ding, emacs-devel
asjo@koldfront.dk (Adam Sjøgren) writes:
> David writes:
>
>> (/ (display-pixel-width) (/ (display-mm-width) 25.4))
>
> Here are my observations so far:
>
> 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-30 10:05 ` David Kastrup
@ 2015-01-30 15:19 ` Vincent Bernat
2015-01-30 23:38 ` Adam Sjøgren
0 siblings, 1 reply; 16+ messages in thread
From: Vincent Bernat @ 2015-01-30 15:19 UTC (permalink / raw)
To: David Kastrup; +Cc: Adam Sjøgren, emacs-devel, ding
❦ 30 janvier 2015 11:05 +0100, David Kastrup <dak@gnu.org> :
>>> (/ (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)
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-30 15:19 ` Vincent Bernat
@ 2015-01-30 23:38 ` Adam Sjøgren
2015-01-31 15:59 ` Vincent Bernat
0 siblings, 1 reply; 16+ messages in thread
From: Adam Sjøgren @ 2015-01-30 23:38 UTC (permalink / raw)
To: ding; +Cc: emacs-devel
Vincent writes:
> 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.
> 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, asjo@koldfront.dk
you're a renaissance man."
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Scaling stuff for high dpi screens
2015-01-30 23:38 ` Adam Sjøgren
@ 2015-01-31 15:59 ` Vincent Bernat
0 siblings, 0 replies; 16+ messages in thread
From: Vincent Bernat @ 2015-01-31 15:59 UTC (permalink / raw)
To: Adam Sjøgren; +Cc: ding, emacs-devel
❦ 31 janvier 2015 00:38 +0100, asjo@koldfront.dk (Adam Sjøgren) :
>> 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
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2015-01-31 15:59 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-19 21:37 Scaling stuff for high dpi screens Adam Sjøgren
2014-04-21 1:58 ` Katsumi Yamaoka
2014-04-21 17:56 ` Adam Sjøgren
2014-05-01 21:18 ` Adam Sjøgren
2015-01-28 6:23 ` Lars Ingebrigtsen
2015-01-28 8:46 ` David Kastrup
2015-01-29 1:02 ` Lars Ingebrigtsen
2015-01-29 22:26 ` Adam Sjøgren
2015-01-29 23:57 ` Adam Sjøgren
2015-01-30 6:26 ` Eli Zaretskii
2015-01-30 10:05 ` David Kastrup
2015-01-30 15:19 ` Vincent Bernat
2015-01-30 23:38 ` Adam Sjøgren
2015-01-31 15:59 ` Vincent Bernat
2015-01-28 9:39 ` Andreas Schwab
2015-01-29 22:28 ` Adam Sjøgren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).